From 0c8416f5dff8a5c6c8a765b0ee6ee618c920bc36 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Fri, 23 Dec 2016 10:14:27 +0100 Subject: [PATCH] Allow setting a default category. Needs some testing, I am not sure how to solve the case now where "no category" shall be used. It will always fall back to the default category. Probably if someone uses a default category, that's the intended behaviour? --- include/functions_entries.inc.php | 12 +++++++++++- include/functions_entries_admin.inc.php | 2 ++ include/tpl/config_personal.inc.php | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index f68d2339..45453c80 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -627,7 +627,7 @@ function &serendipity_fetchEntryProperties($id) { * @param string The ACL artifact condition. If set to "write" only categories will be shown that the author can write to. If set to "read", only categories will be show that the author can read or write to. * @return array Returns the array of categories */ -function &serendipity_fetchCategories($authorid = null, $name = null, $order = null, $artifact_mode = 'write') { +function &serendipity_fetchCategories($authorid = null, $name = null, $order = null, $artifact_mode = 'write', $flat = false) { global $serendipity; if ($name === null) { @@ -716,6 +716,16 @@ function &serendipity_fetchCategories($authorid = null, $name = null, $order = n $ret =& serendipity_db_query($querystring); if (is_string($ret)) { echo "Query failed: $ret"; + } else { + if ($flat) { + $cats = serendipity_walkRecursive($ret, 'categoryid', 'parentid', VIEWMODE_THREADED); + $flat_cats = array(); + $flat_cats[0] = NO_CATEGORY; + foreach($cats AS $catidx => $catdata) { + $flat_cats[$catdata['categoryid']] = str_repeat(' ', $catdata['depth']*2) . serendipity_specialchars($catdata['category_name']); + } + return $flat_cats; + } } return $ret; } diff --git a/include/functions_entries_admin.inc.php b/include/functions_entries_admin.inc.php index ace4c5f1..fd1091c8 100644 --- a/include/functions_entries_admin.inc.php +++ b/include/functions_entries_admin.inc.php @@ -83,6 +83,8 @@ function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = arr foreach ($entry['categories'] as $cat) { $selected[] = $cat['categoryid']; } + } elseif ($serendipity['categoryDefault'] > 0) { + $selected[] = $serendipity['categoryDefault']; } if (count($selected) > 1 || diff --git a/include/tpl/config_personal.inc.php b/include/tpl/config_personal.inc.php index 8d86a17d..70baaf93 100644 --- a/include/tpl/config_personal.inc.php +++ b/include/tpl/config_personal.inc.php @@ -191,6 +191,14 @@ 'permission' => 'personalConfiguration', 'flags' => array('config')), + array('var' => 'categoryDefault', + 'title' => CATEGORY, + 'description' => '', + 'type' => 'list', + 'default' => serendipity_fetchCategories(null, null, null, 'write', true), + 'permission' => 'personalConfiguration', + 'flags' => array('config')), + array('var' => 'use_autosave', 'title' => CONF_USE_AUTOSAVE, 'description' => CONF_USE_AUTOSAVE_DESC,