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)
$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':
?>
<?php
break;
+ case 'multiselect':
+ $is_multi_select = true;
+
case 'select':
+ if (is_array($hvalue)) {
+ $selected_options = $hvalue;
+ } elseif ($is_multi_select) {
+ $selected_options = explode('^', $hvalue);
+ } else {
+ $selected_options = array($hvalue => $hvalue);
+ }
+
+ $pre_selected = (array)$cbag->get('select_preselected');
+ $select_size = $cbag->get('select_size');
$select = $cbag->get('select_values');
?>
<tr>
</td>
<td style="border-bottom: 1px solid #000000; vertical-align: middle" width="250">
<div>
- <select class="direction_<?php echo $lang_direction; ?>" name="serendipity[plugin][<?php echo $config_item; ?>]">
+ <select class="direction_<?php echo $lang_direction; ?>" name="serendipity[plugin][<?php echo $config_item; ?>]<?php echo ($is_multi_select ? '[]' : ''); ?>" <?php echo ($is_multi_select ? 'multiple="multiple"' : ''); ?> <?php echo ($is_multi_select && $select_size > 0 ? 'size="' . $select_size . '"' : ''); ?>>
<?php
foreach($select AS $select_value => $select_desc) {
$id = htmlspecialchars($config_item . $select_value);
?>
- <option value="<?php echo $select_value; ?>" <?php echo ($select_value == $hvalue ? 'selected="selected"' : ''); ?> title="<?php echo htmlspecialchars($select_desc); ?>">
+ <option value="<?php echo $select_value; ?>" <?php echo ( (in_array($select_value, $selected_options) || in_array($select_value, $pre_selected) ) ? 'selected="selected"' : ''); ?> title="<?php echo htmlspecialchars($select_desc); ?>">
<?php echo htmlspecialchars($select_desc); ?>
</option>
<?php
* @param string Tells the function, whether or not to display the XML button for each category.
* If empty, no links to the xml feeds will be displayed; If you want to, you can
* pass an image here (this setting is only used, when type==3).
+* @param string The character to use for blank indenting
* @see serendipity_fetchCategories()
*/
-function serendipity_generateCategoryList($cats, $select = array(0), $type = 0, $id = 0, $level = 0, $xmlImg = '') {
+function serendipity_generateCategoryList($cats, $select = array(0), $type = 0, $id = 0, $level = 0, $xmlImg = '', $blank_char = ' ') {
global $serendipity;
if ( !is_array($cats) || !count($cats) )
}
break;
case 4:
- $ret .= $cat['categoryid'] . '|||' . str_repeat(' ', $level * 2) . $cat['category_name'] . '@@@';
+ $ret .= $cat['categoryid'] . '|||' . str_repeat($blank_char, $level * 2) . $cat['category_name'] . '@@@';
break;
}
- $ret .= serendipity_generateCategoryList($cats, $select, $type, $cat['categoryid'], $level + 1, $xmlImg);
+ $ret .= serendipity_generateCategoryList($cats, $select, $type, $cat['categoryid'], $level + 1, $xmlImg, $blank_char);
}
}
return $ret;
* @access public
* @param string Name of the plugin configuration item
* @param string Value of the plugin configuration item
+ * @param string A concatenation key for imploding arrays
* @return
*/
- function set_config($name, $value)
+ function set_config($name, $value, $implodekey = '^')
{
$name = $this->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);
}
/**
$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',
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)) {
}
}
- $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');
$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) {