/** * Prepares a cache of all event plugins and load them in queue so that they can be fetched * * @access public * @param mixed If set to a string, a certain event plugin cache object will be returned by this function * @param boolean If set to true, the list of cached event plugins will be refreshed * @return mixed Either returns the whole list of event plugins, or only a specific instance */ function &get_event_plugins($getInstance = false, $refresh = false) { static $event_plugins; static $false = false; if (!$refresh && isset($event_plugins) && is_array($event_plugins)) { if ($getInstance) { if (isset($event_plugins[$getInstance]['p'])) { return $event_plugins[$getInstance]['p']; } return $false; } return $event_plugins; } $plugins = serendipity_plugin_api::enum_plugins('event'); if (!is_array($plugins)) { return $false; } $event_plugins = array(); foreach ($plugins as $plugin_data) { if ($event_plugins[$plugin_data['name']]['p'] =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'], $plugin_data['path'])) { /* query for its name, description and configuration data */ $event_plugins[$plugin_data['name']]['b'] = new serendipity_property_bag(); $event_plugins[$plugin_data['name']]['p']->introspect($event_plugins[$plugin_data['name']]['b']); $event_plugins[$plugin_data['name']]['t'] = serendipity_plugin_api::get_plugin_title($event_plugins[$plugin_data['name']]['p']); } else { unset($event_plugins[$plugin_data['name']]); // Unset failed plugins } } if ($getInstance) { if (isset($event_plugins[$getInstance]['p'])) { return $event_plugins[$getInstance]['p']; } return $false; } return $event_plugins; }
/** * Show the list of plugins * * Shows a HTML list of all installed plugins, complete with config/delete/sort order options * * @access public * @param boolean Indicates if event plugins (TRUE) or sidebar plugins (FALSE) shall be shown * @return null */ function show_plugins($event_only = false, $sidebars = null) { global $serendipity; $sql_filter = ''; if (is_array($sidebars)) { foreach ($sidebars as $sidebar) { $up = strtoupper($sidebar); if ($sidebar == 'hide') { $opts[$sidebar] = HIDDEN; } elseif (defined('SIDEBAR_' . $up)) { $opts[$sidebar] = constant('SIDEBAR_' . $up); } elseif (defined($up)) { $opts[$sidebar] = constant($up); } else { $opts[$sidebar] = $up; } $sql_filter .= "AND placement != '" . serendipity_db_escape_string($sidebar) . "' "; } } if (!$event_only) { $sql = "SELECT * from {$serendipity['dbPrefix']}plugins\n WHERE placement != 'event'\n AND placement != 'eventh'\n " . $sql_filter; $invisible_plugins = serendipity_db_query($sql); if (is_array($invisible_plugins)) { $sidebars[] = 'NONE'; $opts['NONE'] = NONE; } } $opts['event'] = PLUGIN_ACTIVE; $opts['eventh'] = PLUGIN_INACTIVE; $data['event_only'] = $event_only; if (!$event_only) { $data['is_first'] = true; } $data['serendipity_setFormToken'] = serendipity_setFormToken(); $data['serendipity_setFormTokenUrl'] = serendipity_setFormToken('url'); /* Block display the plugins per placement location. */ if ($event_only) { $plugin_placements = array('event', 'eventh'); } else { $plugin_placements = $sidebars; } $data['plugin_placements'] = $plugin_placements; static $users = array(); if (empty($users)) { $users = serendipity_fetchUsers('', 'hidden'); } $data['users'] = $users; $i = 0; foreach ($plugin_placements as $plugin_placement) { if (!$event_only && $plugin_placement == 'NONE') { $is_invisible = true; } else { $is_invisible = false; } $data['placement'][$plugin_placement]['ptitle'] = $ptitle = $opts[$plugin_placement]; $data['placement'][$plugin_placement]['pid'] = $pid = $plugin_placement; if ($is_invisible) { $plugins = $invisible_plugins; } else { $plugins = serendipity_plugin_api::enum_plugins($plugin_placement); } if (!is_array($plugins)) { continue; } $sort_idx = 0; foreach ($plugins as $plugin_data) { $i++; $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']); $key = urlencode($plugin_data['name']); $css_key = 's9ycid' . str_replace('%', '-', $key); $is_plugin_owner = $plugin_data['authorid'] == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers'); $is_plugin_editable = $is_plugin_owner || $plugin_data['authorid'] == '0'; $cname = explode(':', $plugin_data['name']); if (!is_object($plugin)) { $name = $title = ERROR . '!'; $desc = ERROR . ': ' . $plugin_data['name']; $can_configure = false; } else { /* query for its name, description and configuration data */ $bag = new serendipity_property_bag(); $plugin->introspect($bag); $name = serendipity_specialchars($bag->get('name')); $desc = '<details class="plugin_data">'; $desc .= '<summary><var class="perm_name">' . $cname[0] . '</var></summary>'; $desc .= '<div class="plugin_desc clearfix">' . serendipity_specialchars($bag->get('description')) . '</div>'; $desc .= '<span class="block_level">' . VERSION . ': ' . $bag->get('version') . '</span>'; $desc .= '</details>'; $title = serendipity_plugin_api::get_plugin_title($plugin, '[' . $name . ']'); if ($bag->is_set('configuration') && ($plugin->protected === FALSE || $plugin_data['authorid'] == '0' || $plugin_data['authorid'] == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers'))) { $can_configure = true; } else { $can_configure = false; } } if ($opts === null) { $opts = array('left' => LEFT, 'right' => RIGHT, 'hide' => HIDDEN); } $event_opts = array('event' => PLUGIN_ACTIVE, 'eventh' => PLUGIN_INACTIVE); if ($event_only) { $gopts = $event_opts; } else { $gopts = $opts; } $data['placement'][$plugin_placement]['plugin_data'][$i]['sort_idx'] = $sort_idx; $data['placement'][$plugin_placement]['plugin_data'][$i]['css_key'] = $css_key; $data['placement'][$plugin_placement]['plugin_data'][$i]['is_plugin_editable'] = $is_plugin_editable; $data['placement'][$plugin_placement]['plugin_data'][$i]['is_plugin_owner'] = $is_plugin_owner; $data['placement'][$plugin_placement]['plugin_data'][$i]['name'] = $plugin_data['name']; $data['placement'][$plugin_placement]['plugin_data'][$i]['authorid'] = $plugin_data['authorid']; $data['placement'][$plugin_placement]['plugin_data'][$i]['can_configure'] = $can_configure; $data['placement'][$plugin_placement]['plugin_data'][$i]['key'] = $key; $data['placement'][$plugin_placement]['plugin_data'][$i]['title'] = $title; $data['placement'][$plugin_placement]['plugin_data'][$i]['desc'] = $desc; $data['placement'][$plugin_placement]['plugin_data'][$i]['placement'] = $plugin_data['placement']; $data['placement'][$plugin_placement]['plugin_data'][$i]['gopts'] = $gopts; $sort_idx++; } } $data['total'] = $i; return serendipity_smarty_show('admin/show_plugins.fnc.tpl', $data); }
/** * Show the list of plugins * * Shows a HTML list of all installed plugins, complete with config/delete/sort order options * * @access public * @param boolean Indicates if event plugins (TRUE) or sidebar plugins (FALSE) shall be shown * @return null */ function show_plugins($event_only = false, $sidebars = null) { static $opts = array('event' => PLUGIN_ACTIVE, 'eventh' => PLUGIN_INACTIVE); global $serendipity; $sql_filter = ''; if (is_array($sidebars)) { foreach ($sidebars as $sidebar) { $up = strtoupper($sidebar); if ($sidebar == 'hide') { $opts[$sidebar] = HIDDEN; } elseif (defined('SIDEBAR_' . $up)) { $opts[$sidebar] = constant('SIDEBAR_' . $up); } elseif (defined($up)) { $opts[$sidebar] = constant($up); } else { $opts[$sidebar] = $up; } $sql_filter .= "AND placement != '" . serendipity_db_escape_string($sidebar) . "' "; } } if (!$event_only) { $sql = "SELECT * from {$serendipity['dbPrefix']}plugins\n WHERE placement != 'event'\n AND placement != 'eventh'\n " . $sql_filter; $invisible_plugins = serendipity_db_query($sql); if (is_array($invisible_plugins)) { $sidebars[] = 'NONE'; $opts['NONE'] = NONE; } } $eyecandy = !isset($serendipity['eyecandy']) || serendipity_db_bool($serendipity['eyecandy']); if (!$eyecandy) { echo ' <form action="?serendipity[adminModule]=plugins" method="post">'; } elseif (!$event_only) { echo '<script type="text/javascript"> function templatePluginMoverInit() { '; $is_first = true; foreach ($sidebars as $sidebar) { ?> <?php echo $is_first ? 'var ' : ''; ?> list = document.getElementById("<?php echo $sidebar; ?> _col"); DragDrop.makeListContainer(list, 'g1'); list.onDragOver = function() { this.style["border"] = "1px solid #4d759b"; }; list.onDragOut = function() { this.style["border"] = "none"; }; <?php $is_first = false; } echo ' } addLoadEvent(templatePluginMoverInit);</script>'; echo ' <form action="?serendipity[adminModule]=plugins" method="post" onsubmit="pluginMovergetSort(); return true">'; echo ' <input type="hidden" name="serendipity[pluginorder]" id="order" value="" />'; } else { echo '<script type="text/javascript">addLoadEvent(pluginMoverInitEvent);</script>'; echo ' <form action="?serendipity[adminModule]=plugins" method="post" onsubmit="pluginMovergetSortEvent(); return true">'; echo ' <input type="hidden" name="serendipity[pluginorder]" id="eventorder" value="" />'; } echo serendipity_setFormToken(); ?> <table class="pluginmanager" border="0" cellpadding="5" cellspacing="3" width="100%"> <tr> <?php $errors = array(); /* Block display the plugins per placement location. */ if ($event_only) { $plugin_placements = array('event', 'eventh'); } else { $plugin_placements = $sidebars; } $total = 0; foreach ($plugin_placements as $plugin_placement) { if (!$event_only && $plugin_placement == 'NONE') { $is_invisible = true; } else { $is_invisible = false; } $ptitle = $opts[$plugin_placement]; $pid = $plugin_placement; echo '<td class="pluginmanager_side pluginmanager_' . ($event_only ? 'event' : 'sidebar') . '">'; echo '<div class="heading">' . $ptitle . '</div>'; echo '<ol id="' . $pid . '_col" class="pluginmanager_container">'; if ($is_invisible) { $plugins = $invisible_plugins; } else { $plugins = serendipity_plugin_api::enum_plugins($plugin_placement); } if (!is_array($plugins)) { continue; } $sort_idx = 0; foreach ($plugins as $plugin_data) { $total++; $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']); $key = urlencode($plugin_data['name']); $css_key = 's9ycid' . str_replace('%', '-', $key); $is_plugin_owner = $plugin_data['authorid'] == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers'); $is_plugin_editable = $is_plugin_owner || $plugin_data['authorid'] == '0'; if (!is_object($plugin)) { $name = $title = ERROR . '!'; $desc = ERROR . ': ' . $plugin_data['name']; $can_configure = false; } else { /* query for its name, description and configuration data */ $bag = new serendipity_property_bag(); $plugin->introspect($bag); $name = htmlspecialchars($bag->get('name')); $desc = htmlspecialchars($bag->get('description')); $desc .= '<br />' . VERSION . ': <em>' . $bag->get('version') . '</em>'; $title = serendipity_plugin_api::get_plugin_title($plugin, '[' . $name . ']'); if ($bag->is_set('configuration') && ($plugin->protected === FALSE || $plugin_data['authorid'] == '0' || $plugin_data['authorid'] == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers'))) { $can_configure = true; } else { $can_configure = false; } } if ($event_only) { $place = placement_box('serendipity[placement][' . $plugin_data['name'] . ']', $plugin_data['placement'], $is_plugin_editable, true, $opts); $event_only_uri = '&serendipity[event_plugin]=true'; } else { $place = placement_box('serendipity[placement][' . $plugin_data['name'] . ']', $plugin_data['placement'], $is_plugin_editable, false, $opts); $event_only_uri = ''; } /* Only display UP/DOWN links if there's somewhere for the plugin to go */ if ($sort_idx == 0) { $moveup = ' '; } else { $moveup = '<a href="?' . serendipity_setFormToken('url') . '&serendipity[adminModule]=plugins&submit=move+up&serendipity[plugin_to_move]=' . $key . $event_only_uri . '" style="border: 0"><img src="' . serendipity_getTemplateFile('admin/img/uparrow.png') . '" height="16" width="16" border="0" alt="' . UP . '" /></a>'; } if ($sort_idx == count($plugins) - 1) { $movedown = ' '; } else { $movedown = ($moveup != '' ? ' ' : '') . '<a href="?' . serendipity_setFormToken('url') . '&serendipity[adminModule]=plugins&submit=move+down&serendipity[plugin_to_move]=' . $key . $event_only_uri . '" style="border: 0"><img src="' . serendipity_getTemplateFile('admin/img/downarrow.png') . '" height="16" width="16" alt="' . DOWN . '" border="0" /></a>'; } ?> <li class="pluginmanager_item_<?php echo $sort_idx % 2 ? 'even' : 'uneven'; ?> " id="<?php echo $css_key; ?> "> <div id="g<?php echo $css_key; ?> " class="pluginmanager_grablet"> <a href="#" id="grab<?php echo $css_key; ?> "></a> </div> <?php if ($is_plugin_editable) { ?> <input class="input_checkbox" type="checkbox" name="serendipity[plugin_to_remove][]" value="<?php echo $plugin_data['name']; ?> " /> <?php } ?> <?php if ($can_configure) { ?> <a class="pluginmanager_configure" href="?serendipity[adminModule]=plugins&serendipity[plugin_to_conf]=<?php echo $key; ?> "><img src="<?php echo serendipity_getTemplateFile('admin/img/configure.png'); ?> " style="border: 0; vertical-align: bottom;" alt="[C]" /></a> <?php } ?> <span class="pluginmanager_title"> <?php if ($can_configure) { ?> <a title="<?php echo $plugin_data['name']; ?> " href="?serendipity[adminModule]=plugins&serendipity[plugin_to_conf]=<?php echo $key; ?> "><?php echo $title; ?> </a> <?php } else { ?> <?php echo $title; ?> <?php } ?> </span><br /> <div class="pluginmanager_description" style="font-size: 8pt"><?php echo $desc; ?> </div> <div class="pluginmanager_ownership"><?php ownership($plugin_data['authorid'], $plugin_data['name'], $is_plugin_owner); ?> </div> <?php echo $eyecandy ? '<noscript>' : ''; ?> <div class="pluginmanager_place"><?php echo $place; ?> </div> <div class="pluginmanager_move"><?php echo $moveup; ?> <?php echo $movedown; ?> </div> <?php echo $eyecandy ? '</noscript>' : ''; ?> </li> <?php $sort_idx++; } echo '</ol></td>'; } ?> </tr> <tr> <td colspan="3" align="right"><?php printf(PLUGIN_AVAILABLE_COUNT, $total); ?> </td> </tr> </table> <br /> <div> <input type="submit" name="REMOVE" title="<?php echo DELETE; ?> " value="<?php echo REMOVE_TICKED_PLUGINS; ?> " class="serendipityPrettyButton input_button" /> <input type="submit" name="SAVE" title="<?php echo SAVE_CHANGES_TO_LAYOUT; ?> " value="<?php echo SAVE; ?> " class="serendipityPrettyButton input_button" /> </div> </form> <?php }