dbh =& $dbh; $this->plugdir = $plugdir; $this->cachedir = $cachedir; } /** Return the path of the cache file * * @param $barrel */ function cacheFile($barrel) { $cachefile = $this->cachedir . "/" . ($barrel ? $barrel : "__diogenes__") . ".plugins"; return $cachefile; } /** Return the cache entry for specified plugin * * @param $cache * @param $barrel * @param $page * @param $plugin */ function cacheGet($cache, $barrel, $page, $plugin) { foreach ($cache as $plugentry) { if (($plugentry['plugin'] == $plugin) && ($plugentry['page'] == $page)) { return $plugentry; } } return; } /** Return the cache entry for a plugin at a specified position * * @param $cache * @param $barrel * @param $page * @param $pos */ function cacheGetAtPos($cache, $barrel, $page, $pos) { foreach ($cache as $plugentry) { if (($plugentry['pos'] == $pos) && ($plugentry['page'] == $page)) { return $plugentry; } } } /** List the plugins that are active in a given context * * @param $cache * @param $barrel * @param $page */ function cachedActive($cache, $barrel, $page) { $plugins = array(); foreach ($cache as $plug) { if ($plug['page'] == $page) { array_push($plugins, $plug); } } return $plugins; } /** Returns an array of cache entries representing the available plugins * in a given context * * @param $cache * @param $barrel * @param $page */ function cachedAvailable($cache, $barrel, $page) { $available = array(); foreach ($cache as $plugentry) { $plugfile = $this->plugdir."/".$plugentry['plugin'].".php"; if (file_exists($plugfile) and ($plugentry['page'] == 0) and (!$page or $plugentry['active'])) { array_push($available, $plugentry['plugin']); } } return $available; } /** Remove database references to plugins that are not available. */ function clean_database(&$page) { /* $res = $this->dbh->query("select distinct plugin from diogenes_plugin"); while (list($plugname) = mysql_fetch_row($res)) { $page->info("examining $plugname.."); $plug = $this->load($plugname); if (!is_object($plug)) { $page->info("plugin $plugname is broken, removing"); $this->dbh->query("delete from diogenes_plugin where plugin='$plugname'"); } } mysql_free_result($res); */ } /** Compile plugin cache. * * @param $cachefile * @param $barrel */ function compileCache($cachefile, $barrel) { if (!$fp = fopen($cachefile, "w")) { trigger_error("failed to open '$cachefile' for writing", E_USER_ERROR); } // get the list of available plugins $available = array(); if (!$barrel) { $plugfiles = System::find($this->plugdir.' -type f -name *.php'); foreach ($plugfiles as $file) { $name = basename($file); $name = substr($name, 0, -4); array_push($available, $name); } } else { $sql = "select plugin from diogenes_plugin where page=0 AND barrel=''"; $res = $this->dbh->query($sql); while (list($plugin) = mysql_fetch_row($res)) { array_push($available, $plugin); } mysql_free_result($res); } /* echo "compile : available
"; print_r($available); echo ""; */ // get active plugins $sql = "select page, pos, plugin, params from diogenes_plugin where barrel='{$barrel}' order by page, pos"; $res = $this->dbh->query($sql); $active = array(); while ($row = mysql_fetch_row($res)) { $plugin = $row[2]; if (in_array($plugin, $available)) { array_unshift($row, 1); fputs($fp, join("\t", $row) . "\n"); if (!$row[1]) { array_push($active, $plugin); //echo "compileCache : adding active plugin $plugin
'.$key.' v'.$val->version.' | |
---|---|
position | '.$val->pos.' |
type | '.$val->type.' |
description | '.$val->description.' |
parameters | |
$skey | $sval |