From f82f1990290feeaf48d16d8aa5f36c6a88702cfe Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Tue, 10 Jan 2006 15:25:22 +0000 Subject: [PATCH] New config item "multiselect". --- docs/NEWS | 8 +++++ include/admin/plugins.inc.php | 32 +++++++++++++++++-- include/functions_entries.inc.php | 7 ++-- include/plugin_api.inc.php | 12 +++++-- .../serendipity_plugin_recententries.php | 24 +++++++++++--- 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index 0bf4601..339df3c 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,14 @@ Version 1.0 () ------------------------------------------------------------------------ + * Recognize "multiselect" as new plugin item type. Calls to get_config() + will return a string, that needs exploding to convert it into the + array of multi-selected input values. + For the property bag object, you can set a new item "select_preselected" + to indicate which (if any) values shall be preselected. The item "select_size" + indicates the multi-select size. + (garvinhicking) + * Make spartacus plugin be able to filter comment bodies (garvinhicking) diff --git a/include/admin/plugins.inc.php b/include/admin/plugins.inc.php index d96a31d..35f4fbd 100644 --- a/include/admin/plugins.inc.php +++ b/include/admin/plugins.inc.php @@ -403,11 +403,24 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) { $value = $plugin->get_config($config_item, false, true); } } - $hvalue = (isset($_POST['serendipity']['plugin'][$config_item]) ? htmlspecialchars($_POST['serendipity']['plugin'][$config_item]) : htmlspecialchars($value)); + + if (isset($_POST['serendipity']['plugin'][$config_item])) { + if (is_array($_POST['serendipity']['plugin'][$config_item])) { + $hvalue = $_POST['serendipity']['plugin'][$config_item]; + array_walk($hvalue, 'htmlspecialchars'); + } else { + $hvalue = htmlspecialchars($_POST['serendipity']['plugin'][$config_item]); + } + } else { + $hvalue = htmlspecialchars($value); + } + $radio = array(); $select = array(); $per_row = null; + $is_multi_select = false; + switch ($cbag->get('type')) { case 'seperator': ?> @@ -417,7 +430,20 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) { $hvalue); + } + + $pre_selected = (array)$cbag->get('select_preselected'); + $select_size = $cbag->get('select_size'); $select = $cbag->get('select_values'); ?> @@ -430,12 +456,12 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) {
- 0 ? 'size="' . $select_size . '"' : ''); ?>> $select_desc) { $id = htmlspecialchars($config_item . $select_value); ?> - instance . '/' . $name; + + if (is_array($value)) { + $dbvalue = implode($implodekey, $value); + $_POST['serendipity']['plugin'][$name] = $dbvalue; + } else { + $dbvalue = $value; + } - return serendipity_set_config_var($name, $value); + return serendipity_set_config_var($name, $dbvalue); } /** diff --git a/plugins/serendipity_plugin_recententries/serendipity_plugin_recententries.php b/plugins/serendipity_plugin_recententries/serendipity_plugin_recententries.php index a3c67f4..8a1143b 100644 --- a/plugins/serendipity_plugin_recententries/serendipity_plugin_recententries.php +++ b/plugins/serendipity_plugin_recententries/serendipity_plugin_recententries.php @@ -20,7 +20,7 @@ class serendipity_plugin_recententries extends serendipity_plugin { $propbag->add('description', PLUGIN_RECENTENTRIES_BLAHBLAH); $propbag->add('stackable', true); $propbag->add('author', 'Christian Machmeier'); - $propbag->add('version', '1.3'); + $propbag->add('version', '1.4'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -70,7 +70,7 @@ class serendipity_plugin_recententries extends serendipity_plugin { return false; } - $catlist = serendipity_generateCategoryList($cats, array(0), 4); + $catlist = serendipity_generateCategoryList($cats, array(0), 4, 0, 0, '', ' . '); $tmp_select_cats = explode('@@@', $catlist); if (!is_array($tmp_select_cats)) { @@ -86,8 +86,9 @@ class serendipity_plugin_recententries extends serendipity_plugin { } } - $propbag->add('type', 'select'); + $propbag->add('type', 'multiselect'); $propbag->add('select_values', $select_cats); + $propbag->add('select_size', 5); $propbag->add('name', CATEGORY); $propbag->add('description', CATEGORIES_TO_FETCH); $propbag->add('default', 'none'); @@ -110,10 +111,23 @@ class serendipity_plugin_recententries extends serendipity_plugin { $sql_join = ''; $sql_where = ''; - if ($category != 'none' && is_numeric($category)) { + if ($category != 'none') { $sql_join = 'LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'entrycat AS ec ON id = ec.entryid LEFT OUTER JOIN ' . $serendipity['dbPrefix'] . 'category AS c ON ec.categoryid = c.categoryid'; - $sql_where = ' AND (c.category_left BETWEEN ' . implode(' AND ', serendipity_fetchCategoryRange($category)) . ')'; + + $sql_categories = array(); + if (is_numeric($category)) { + $sql_categories[] = $category; + } else { + $sql_categories = explode('^', $category); + } + + $category_parts = array(); + foreach($sql_categories AS $sql_category) { + $category_parts[] = "\n" . implode(' AND ', serendipity_fetchCategoryRange($sql_category)); + } + + $sql_where = ' AND (c.category_left BETWEEN ' . implode(' OR c.category_left BETWEEN ', $category_parts) . ')'; } if (!$number || !is_numeric($number) || $number < 1) { -- 2.39.5