/** * Traverse a specific directory and search if a serendipity plugin exists there. * * @access public * @param string The path to start from (usually '.') * @param array A referenced array of currently found classes * @param boolean If true, only event plugins will be searched. If false, only sidebar plugins will be searched. * @param string The maindir where we started searching from [for recursive use] * @return */ function traverse_plugin_dir($ppath, &$classes, $event_only, $maindir = '') { $d = @opendir($ppath); if ($d) { while (($f = readdir($d)) !== false) { if ($f[0] == '.' || $f == 'CVS' || !is_dir($ppath . '/' . $f) || !is_readable($ppath . '/' . $f)) { continue; } $subd = opendir($ppath . '/' . $f); if (!$subd) { continue; } // Instead of only looking for directories, search for files within subdirectories $final_loop = false; while (($subf = readdir($subd)) !== false) { if ($subf[0] == '.' || $subf == 'CVS') { continue; } if (!$final_loop && is_dir($ppath . '/' . $f . '/' . $subf) && $maindir != $ppath . '/' . $f) { // Search for another level of subdirectories serendipity_plugin_api::traverse_plugin_dir($ppath . '/' . $f, $classes, $event_only, $f . '/'); // We can break after that operation because the current directory has been fully checked already. $final_loop = true; } if (!preg_match('@^[^_]+_(event|plugin)_.+\\.php$@i', $subf)) { continue; } $class_name = str_replace('.php', '', $subf); // If an external plugin/event already exists as internal, remove the internal reference because its redundant if (isset($classes['@' . $class_name])) { unset($classes['@' . $class_name]); } // A local plugin will be preferred over general plugins [used when calling this function the second time] if (isset($classes[$class_name])) { unset($classes[$class_name]); } if (!is_null($event_only) && $event_only && !serendipity_plugin_api::is_event_plugin($subf)) { continue; } if (!is_null($event_only) && !$event_only && serendipity_plugin_api::is_event_plugin($subf)) { continue; } $classes[$class_name] = array('name' => $class_name, 'true_name' => $class_name, 'type' => 'additional_plugin', 'pluginPath' => $maindir . $f); } closedir($subd); } closedir($d); } }
function get_plugins() { global $serendipity; serendipity_plugin_api::traverse_plugin_dir($this->pluginpath, $this->plugins['event'], true); serendipity_plugin_api::traverse_plugin_dir($this->pluginpath, $this->plugins['sidebar'], false); $this->load_plugin($this->plugins['event']); $this->load_plugin($this->plugins['sidebar']); }