add('name', PLUGIN_ADVTYPES_TITLE); $propbag->add('description', PLUGIN_ADVTYPES_DESC); $propbag->add('requirements', array( 'serendipity' => '1.1', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('version', '0.6'); $propbag->add('author', 'Judebert (http://judebert.com/)'); $propbag->add('stackable', false); $propbag->add('event_hooks', array( 'backend_header' => true, 'backend_pluginconfig_media' => true, 'backend_pluginconfig_sequence' => true, )); //$propbag->add('configuration', array('unused')); $propbag->add('configuration', array('unused', 'sequence_tester', 'seqtest2')); $propbag->add('groups', array('BACKEND_TEMPLATES')); //$this->dependencies = array('serendipity_event_entryproperties' => 'keep'); } function introspect_config_item($name, &$propbag) { global $serendipity; switch($name) { case 'unused' : $propbag->add('type', 'string'); $propbag->add('name', 'unused'); $propbag->add('description', 'unused'); $propbag->add('default', 'unused'); break; case 'sequence_tester' : $propbag->add('type', 'sequence'); $propbag->add('name', 'Unused Sequence Widget'); $propbag->add('description', 'A sequence widget to test the sequence widget code.'); $propbag->add('values', array('1' => array('display' => 'This', 'img' => serendipity_getTemplateFile('img/emoticons/cool.png')), '2' => array('display' => 'That', 'img' => serendipity_getTemplateFile('img/emoticons/smile.png')), '3' => array('display' => 'The Other', 'img' => serendipity_getTEmplateFile('img/s9y_banner_small.png')), )); break; case 'seqtest2' : $propbag->add('type', 'sequence'); $propbag->add('name', 'Multiple Unused Sequence Widgets'); $propbag->add('description', 'A sequence widget to test the sequence widget code with multiple sequences.'); $propbag->add('values', array('First Item', 'Second Item' => array('display' => '2nd item'), 'Third Item', )); $propbag->add('default', 'Third Item,Second Item,First Item'); break; default: return false; } return true; } function generate_content(&$title) { $title = PLUGIN_ADVTYPES_TITLE; } function event_hook($event, &$bag, &$eventData, $addlData) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'backend_header': // Output the JavaScript, if we must $getModule = $serendipity['GET']['adminModule']; $postModule = $serendipity['POST']['adminModule']; if ($getModule == 'templates' || $postModule == 'templates' || $getModule == 'plugins' || $postModule == 'plugins') { // Includes copied from include/admin/plugins.inc.php echo ''; //echo '
' . PREFERENCE_USE_JS_WARNING . '
'; $media_js = serendipity_getTemplateFile('media_input.js'); print << EOS; } break; case 'backend_pluginconfig_media': // Print the HTML to display the popup media selector $postKey = $eventData['postKey']; $var = $eventData['config_item']; $savedValue = $eventData['value']; $cbag = $eventData['cbag']; $cname = $cbag->get('name'); $cdesc = $cbag->get('description'); $preview_width = $cbag->get('preview_width'); if (!$preview_width || $preview_width == "") { $preview_width = '400px'; } $preview_height = $cbag->get('preview_height'); if (!$preview_height || $preview_height == "") { $preview_height = '100px'; } $media_link_text = MEDIA_LIBRARY; print << $cname
$cdesc
 

$media_link_text EOS; return true; break; case 'backend_pluginconfig_sequence': // // Print the HTML to display the [drag-n-drop] orderable list // // For the drag-n-drop to work, the list must be included in // a container (probably an
    ) that JavaScript can access // (easiest by ID), with
  1. children that have unique IDs, // and handles with ids of 'g'.$li_id. // I can't get it to work unless there's a class of // pluginmanager_container on the ol, either. // The drag-n-drop returns the list of IDs in order. // // I want this generic sequence widget to hide the ID, but // display a name or description with an optional picture. // (This would allow users to identify choices by thumbnail.) // Therefore, I need an array with keys 'id', 'display', and // 'imgurl' (or similar) to generate each list item. // Data sent by include/functions_plugins_admin.inc.php // It also passes bag and plugin, but we don't need those $postKey = $eventData['postKey']; $var = $eventData['config_item']; $savedValue = $eventData['value']; $cbag = $eventData['cbag']; // Get the data we need to display the list if (!$savedValue) { $savedValue = $eventData['default']; } $cname = $cbag->get('name'); $cdesc = $cbag->get('description'); /** Unordered array of values */ $items = $cbag->get('values'); if (!is_array($items)) { $items = null; } /** Array specifying order to use values in $items */ $order = null; if ($savedValue) { $order = explode(',', $savedValue); } $uparrow_img = serendipity_getTemplateFile('admin/img/uparrow.png'); $downarrow_img = serendipity_getTemplateFile('admin/img/downarrow.png'); // $items is the list of things to sequence. It's not in // order, and reordering PHP arrays is problematic. So // we keep it unordered, and access its values according // to another array (appropriately named $order). if (is_array($items)) { // Allow simple value for any sequence item foreach ($items as $key => $item) { if (!is_array($item)) { // Replace this item with an empty array unset($items[$key]); $items[$item] = array(); } } // Make sure all the items are in the order list; new items // go on the end (new items could have been added in // introspect_config_items, but not been configured). // Also fill out thumbnails and display names foreach ($items as $id => $junk) { if ($order == null) { $order = array($id); } else if (!in_array($id, $order)) { $order[] = $id; } // If there's no defined display name, default to the ID if (!isset($items[$id]['display'])) { $items[$id]['display'] = $id; } // If there's no image, we just won't display anything. } // Make sure all the items to be ordered exist! Otherwise // we could try to sequence nothing. $filtered = array(); foreach ($order as $id) { if (array_key_exists($id, $items)) { $filtered[] = $id; } } $order = $filtered; } else { // If there's nothing to sequence, make the order to use // them in valid, but empty $order = array(); } // Start the row, add one cell for the name and description print << $cname
    $cdesc EOS; // Now add one cell for the list print << EOS; // Print the list print <<
      EOS; $sort_idx == 0; $last = count($order) - 1; foreach ($order as $id) { // Create the variables required to print this item if ($sort_idx > 0) { $swapping = $order; $temp = $swapping[(int)$sort_idx]; $swapping[(int)$sort_idx] = $swapping[(int)($sort_idx - 1)]; $swapping[(int)($sort_idx - 1)] = $temp; $oneup = implode(',' , $swapping); } if ($sort_idx < $last) { $swapping = $order; $temp = $swapping[(int)$sort_idx]; $swapping[(int)$sort_idx] = $swapping[(int)($sort_idx + 1)]; $swapping[(int)($sort_idx + 1)] = $temp; $onedown = implode(',' , $swapping); } // Print the HTML // // Set the item and its ID print '
    1. ' . "\n"; // Make a handle with ID 'g$id' print '
      ' . "\n"; // Add the item contents print ' '.$items[$id]['display'].'' . "\n"; if (isset($items[$id]['img'])) { print ' ' . "\n"; } // Luddite submit buttons (please, think of the scriptless!) print "\n"; // Close the item print '
    2. '."\n"; // Next, please $sort_idx++; } if (!is_array($items) or empty($order)) { // Print the empty message print(PLUGIN_ADVTYPES_NOTHING_TO_SEQUENCE); } // Print the Javascript to drag-n-drop the list print << function init_${var}_Sequence() { var lst = document.getElementById("${var}"); DragDrop.makeListContainer(lst, '${var}_group'); lst.onDragOut = function() { //var seq = DragDrop.serData('${var}_group', null); var seq = DragDrop.serData(null, '${var}'); var start = seq.indexOf("("); var end = seq.indexOf(")"); seq = seq.slice((start + 1), end); var order = document.getElementById("${var}_value"); order.value = seq; }; } addLoadEvent(init_${var}_Sequence); EOS; // Finish the row print << EOS; return true; break; } } return true; } } /* vim: set sw=4 sts=4 ts=4 expandtab : */