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?
This commit is contained in:
Garvin Hicking 2016-12-23 10:14:27 +01:00
parent 6b1348a7f1
commit 0c8416f5df
3 changed files with 21 additions and 1 deletions

View File

@ -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;
}

View File

@ -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 ||

View File

@ -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,