]> git.mjollnir.org Git - s9y.git/commitdiff
New config item "multiselect".
authorgarvinhicking <garvinhicking>
Tue, 10 Jan 2006 15:25:22 +0000 (15:25 +0000)
committergarvinhicking <garvinhicking>
Tue, 10 Jan 2006 15:25:22 +0000 (15:25 +0000)
docs/NEWS
include/admin/plugins.inc.php
include/functions_entries.inc.php
include/plugin_api.inc.php
plugins/serendipity_plugin_recententries/serendipity_plugin_recententries.php

index 0bf460180e4c44476596cdca53d2f7a914b0f12d..339df3ca8fa219cd568ee627fd6cfa8f4849ee9a 100644 (file)
--- 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)
 
index d96a31dce93b409e2e1c456dbecc21f3d6199abe..35f4fbd9b8b9a2f802c3a19a43cda362e2560e88 100644 (file)
@@ -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'])) {
 <?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>
@@ -430,12 +456,12 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) {
             </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
index d258e5afd369cba92ed9590dd450878f3ba6c02f..9e71f79fd442400c682bd5f0ce25450b74300036 100644 (file)
@@ -1222,9 +1222,10 @@ function serendipity_deleteEntry($id) {
 * @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) )
@@ -1268,10 +1269,10 @@ function serendipity_generateCategoryList($cats, $select = array(0), $type = 0,
                     }
                     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;
index 3dd4d4ebd09fd1cbd9058340db02cd4a37234533..a5985410a142b3425334114cae1ded4869ae1887 100644 (file)
@@ -1300,13 +1300,21 @@ class serendipity_plugin {
  * @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);
     }
 
 /**
index a3c67f4b32011bd95f403f29b6699b4aba4b22aa..8a1143bda6eb193dc6668885f080789a4f7f9c5b 100644 (file)
@@ -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) {