$rentry) { if (preg_match('/_gregarius_plugin.([a-zA-Z0-9_\/\-]+).php/',$rkey,$matches)) { $active_plugins[] = ($matches[1] .".php"); } } $value = serialize($active_plugins); $sql = "update " . getTable('config') . " set value_='$value' where key_='rss.config.plugins'"; rss_query($sql); rss_invalidate_cache(); // deactivate $to_deactivate = array_diff($old_active_plugins, $active_plugins); foreach($to_deactivate as $deactivatethis) { rss_load_plugin($deactivatethis); rss_plugin_hook("rss.plugins.admin.deactivate", "", $deactivatethis); } //activate $to_activate = array_diff($active_plugins, $old_active_plugins); foreach($to_activate as $activatethis) { rss_load_plugin($activatethis); rss_plugin_hook("rss.plugins.admin.activate", "", $activatethis); } } else { $active_plugins = getConfig('rss.config.plugins'); } // Check for updates $doUpdates = false; $updates = array(); if (isset($_POST['admin_plugin_check_for_updates'])) { $updates = plugins_check_for_updates(); $doUpdates = true; } // Rendering echo "

".__('Plugins')."

\n" ."
\n"; echo __('

Plugins are third-party scripts that offer extended functionalities. More plugins can be downloaded at the Plugin Repository.

'); echo "
\n"; echo "

\n"; echo "\n\n\n" ."\n" ."\n" ."\n" ."\n" ."\n" ."\n"; if ($doUpdates) { echo "\n"; } echo "\n"; $rss_plugins = getPlugins(); $cntr = 0; if ($rss_plugins) { foreach($rss_plugins as $entry => $info ) { $active= in_array($entry,$active_plugins); if (count($info)) { $updateDl = null; if (is_array($updates) && array_key_exists($info['file'],$updates)) { $lastV = $updates[$info['file']][0]; $thisV = $info['version']; if ($lastV > $thisV) { $updateDl = str_replace("&","&",$updates[$info['file']][1]); } } $class = (($cntr++ % 2 == 0)?"even":"odd") . ($updateDl? " hilite":($active?" active":"")); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // output the column to call a plugin's config page. echo "\n"; if ($doUpdates && $updateDl) { echo ""; } elseif($doUpdates) { echo ""; } echo "\n"; } } } echo "
".__('Active')."".__('Name')."".__('Version')."".__('Author')."".__('Description')."".__('Options')."".__('Update Available')."
" ."\n" ."" .(array_key_exists('version',$info)?$info['version']:" "). "" .(array_key_exists('author',$info)?$info['author']:" "). "" .(array_key_exists('description',$info)?$info['description']:" "). ""; if(array_key_exists('configuration',$info)) { $escaped_plugin_name = str_replace("/", "%2F", $entry); echo "" . __('edit') .""; } else { echo " "; } echo ""; echo "$lastV"; echo " 
\n"; echo "

\n"; echo "\n"; echo "

\n"; echo "
"; } function plugin_options() { if (!array_key_exists('plugin_name',$_REQUEST) || array_key_exists('admin_plugin_options_cancel_changes', $_REQUEST)) { plugins(); return; } // TBD $plugin_filename = $_REQUEST['plugin_name']; $plugin_filename = str_replace("%2F", "/", $plugin_filename); $plugin_output = ""; if (preg_match('/([a-zA-Z0-9_\/\-]+).php/',$plugin_filename,$matches)) { $plugin_filename = $matches[1] .".php"; // sanitize input $plugin_info = getPluginInfo($plugin_filename); if($plugin_info && array_key_exists('configuration', $plugin_info)) { $plugin_config_func = $plugin_info['configuration']; ob_start(); rss_load_plugin($plugin_filename); if(function_exists($plugin_config_func)) { call_user_func($plugin_config_func); // Are you happy now? $plugin_output = ob_get_contents(); } ob_end_clean(); rss_invalidate_cache(); } if ($plugin_output) { // Let us set up a form echo "

".__('Plugin Options')." ".TITLE_SEP." ". $plugin_info['name']. "

\n" ."
\n"; echo "
\n"; echo "

\n"; echo $plugin_output; echo "

\n"; echo "

\n"; echo "\n"; echo "

\n"; echo "
"; } else { plugins(); } } } /** * fetches information for the given plugin, * which should contain: * * /// Name: Url filter * /// Author: Marco Bonetti * /// Description: This plugin will try to make ugly URL links look better * /// Version: 1.0 * */ function getPluginInfo($file) { $info = array(); $path = "../".RSS_PLUGINS_DIR."/$file"; if (file_exists($path)) { $f = @fopen($path,'r'); $contents = ""; if ($f) { $contents .= fread($f, filesize($path)); @fclose($f); } else { $contents = ""; } if ($contents && preg_match_all("/\/\/\/\s?([^:]+):(.*)/",$contents,$matches,PREG_SET_ORDER)) { foreach($matches as $match) { $key = trim(strtolower($match[1])); $val = trim($match[2]); if ($key == 'version') { $val=preg_replace('/[^0-9\.]+/','',$val); } $info[$key] = $val; } } $info['file'] = preg_replace('/\..+$/','',$file); } return $info; } /** * This function returns an associative array with all the php files that are * plugins and their plugin info. * * Following the wordpress model (and code) we search for plugins in the plugins * directory and each subdirectory 1 level deep. */ function getPlugins() { $plugin_dir_files = array(); $rss_plugins = array(); $plugin_dir = '../' . RSS_PLUGINS_DIR; $d = @dir($plugin_dir); //Put all the *.php files in the plugin dir and 1 level below into $plugin_dir_files while (($file = $d->read()) !== false) { if ( $file != "CVS" && (substr($file,0,1) != ".")) { if(is_dir($plugin_dir . '/' . $file)) { $plugins_subdir = @dir($plugin_dir . '/' . $file); if ($plugins_subdir) { while(($subfile = $plugins_subdir->read()) !== false) { if ( preg_match('|^\.+$|', $subfile) ) { continue; } if ( preg_match('|\.php$|', $subfile) ) { $plugin_dir_files[] = "$file/$subfile"; } } } } else { if ( preg_match('|\.php$|', $file) ) { $plugin_dir_files[] = $file; } } } } // See which of the php files in $plugin_dir_files are really plugins foreach($plugin_dir_files as $plugin_dir_file) { $info = getPluginInfo($plugin_dir_file); // $info will have the filename in it. Does it have anything else? if (count($info) > 1) { $rss_plugins[$plugin_dir_file] = $info; } } ksort($rss_plugins); //return an associative array with the plugin files and their info return $rss_plugins; } function plugins_check_for_updates() { $pluginsxml = array(); global $pluginsxml; $xml = getUrl('http://plugins.gregarius.net/api.php'); $xml = str_replace("\r", '', $xml); $xml = str_replace("\n", '', $xml); $xp = xml_parser_create() or rss_error("couldn't create parser"); xml_set_element_handler($xp, 'plugins_xml_startElement', 'plugins_xml_endElement') or rss_error("couldnt set XML handlers"); xml_parse($xp, $xml, true) or rss_error("failed parsing xml"); xml_parser_free($xp) or rss_error("failed freeing the parser"); return $pluginsxml; } function plugins_xml_startElement($xp, $element, $attr) { global $pluginsxml; if ($element == 'PLUGIN' && array_key_exists('PID',$attr) && array_key_exists('URL',$attr) && array_key_exists('VERSION',$attr)) { $pluginsxml[$attr['PID']] = array($attr['VERSION'],$attr['URL']); } } function plugins_xml_endElement($xp, $element) { ///global $pluginsxml; return; } function rss_plugins_redirect_to_admin() { rss_redirect("/admin/index.php?" . CST_ADMIN_VIEW . "=" . CST_ADMIN_DOMAIN_PLUGINS); } function rss_plugins_redirect_to_plugin_config($filename) { rss_redirect("/admin/index.php" . "?".CST_ADMIN_DOMAIN."=". CST_ADMIN_DOMAIN_PLUGIN_OPTIONS ."&action=". CST_ADMIN_EDIT_ACTION. "&plugin_name=" . $filename); } function rss_plugins_is_submit() { return array_key_exists("admin_plugin_options_submit_changes", $_REQUEST); } ?>