<?php
/*
* Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2006 The Nucleus Group
+ * Copyright (C) 2002-2007 The Nucleus Group
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* plugins.html file that is included with the Nucleus documenation
*
* @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2006 The Nucleus Group
- * @version $Id: PLUGIN.php,v 1.6 2006-12-07 03:18:33 kmorimatsu Exp $
- * $NucleusJP: PLUGIN.php,v 1.5 2006/07/12 07:11:47 kimitake Exp $
+ * @copyright Copyright (C) 2002-2007 The Nucleus Group
+ * @version $Id: PLUGIN.php,v 1.13 2008-02-08 09:31:22 kimitake Exp $
+ * $NucleusJP: PLUGIN.php,v 1.12.2.3 2007/12/03 02:22:42 kmorimatsu Exp $
*/
class NucleusPlugin {
}
function doAction($type) { return 'No Such Action'; }
function doIf($key,$value) { return false; }
+ function doItemVar () {}
/**
* Checks if a plugin supports a certain feature.
/**
* Retrieves the current value for an option
*/
- function getOption($name) {
- return $this->_getOption('global', 0, $name);
+ function getOption($name)
+ {
+ // only request the options the very first time. On subsequent requests
+ // the static collection is used to save SQL queries.
+ if ($this->plugin_options == 0)
+ {
+ $this->plugin_options = array();
+ $query = sql_query(
+ 'SELECT d.oname as name, o.ovalue as value '.
+ 'FROM '.
+ sql_table('plugin_option').' o, '.
+ sql_table('plugin_option_desc').' d '.
+ 'WHERE d.opid='. intval($this->getID()).' AND d.oid=o.oid'
+ );
+ while ($row = mysql_fetch_object($query))
+ $this->plugin_options[strtolower($row->name)] = $row->value;
+ }
+ if (isset($this->plugin_options[strtolower($name)]))
+ return $this->plugin_options[strtolower($name)];
+ else
+ return $this->_getOption('global', 0, $name);
}
+
function getBlogOption($blogid, $name) {
return $this->_getOption('blog', $blogid, $name);
}
// retrieve the data and return
$q = 'SELECT otype, oextra FROM '.sql_table('plugin_option_desc').' WHERE oid = '.$oid;
- $query = mysql_query($q);
+ $query = sql_query($q);
$o = mysql_fetch_array($query);
} else {
$orderby = 'ovalue';
}
- $q = 'SELECT ovalue value, ocontextid id FROM '.sql_table('plugin_option').' WHERE oid = '.$oid.' ORDER BY '.$orderby.' '.$sort.' LIMIT 0,'.$amount;
- $query = mysql_query($q);
+ $q = 'SELECT ovalue value, ocontextid id FROM '.sql_table('plugin_option').' WHERE oid = '.$oid.' ORDER BY '.$orderby.' '.$sort.' LIMIT 0,'.intval($amount);
+ $query = sql_query($q);
// create the array
$i = 0;
var $_aOptionValues; // oid_contextid => value
var $_aOptionToInfo; // context_name => array('oid' => ..., 'default' => ...)
+ var $plugin_options; // see getOption()
var $plugid; // plugin id
function NucleusPlugin() {
$this->_aOptionValues = array(); // oid_contextid => value
$this->_aOptionToInfo = array(); // context_name => array('oid' => ..., 'default' => ...)
+ $this->plugin_options = 0;
+ }
+
+ function clearOptionValueCache(){
+ $this->_aOptionValues = array();
}
// private
case 'member':
$r = sql_query('SELECT mnumber as contextid FROM ' . sql_table('member'));
break;
+ case 'item':
+ $r = sql_query('SELECT inumber as contextid FROM ' . sql_table('item'));
+ break;
}
if ($r) {
while ($o = mysql_fetch_object($r))
*/
function _getOID($context, $name) {
$key = $context . '_' . $name;
- $info = $this->_aOptionToInfo[$key];
+ $info = @$this->_aOptionToInfo[$key];
if (is_array($info)) return $info['oid'];
// load all OIDs for this plugin from the database
}
mysql_free_result($res);
- return $this->_aOptionToInfo[$key]['oid'];
+ return @$this->_aOptionToInfo[$key]['oid'];
}
function _getDefVal($context, $name) {
$key = $context . '_' . $name;
$res = sql_query($query);
if ($o = mysql_fetch_object($res))
{
- foreach ($values as $contextid => $value) {
+ foreach ($values as $key => $value) {
+ // avoid overriding the key used by foreach statement
+ $contextid=$key;
+
// retreive any metadata
$meta = NucleusPlugin::getOptionMeta($o->oextra);
// if the option is readonly or hidden it may not be saved
- if (($meta['access'] != 'readonly') && ($meta['access'] != 'hidden')) {
+ if ((@$meta['access'] != 'readonly') && (@$meta['access'] != 'hidden')) {
$value = undoMagic($value); // value comes from request
}
// check the validity of numerical options
- if (($meta['datatype'] == 'numerical') && (!is_numeric($value))) {
+ if ((@$meta['datatype'] == 'numerical') && (!is_numeric($value))) {
//the option must be numeric, but the it isn't
//use the default for this option
$value = $o->odef;
}
}
}
+ // clear option value cache if the plugin object is already loaded
+ if (is_object($o)) {
+ $plugin=& $manager->pidLoaded($o->opid);
+ if ($plugin) $plugin->clearOptionValueCache();
+ }
}
}
-
}
?>