* Name of the feature. See plugin documentation for more info\r
* 'SqlTablePrefix' -> if the plugin uses the sql_table() method to get table names\r
* 'HelpPage' -> if the plugin provides a helppage\r
- * 'SqlApi' -> if the plugin uses the complete sql_* api (must also require nucleuscms 3.5)\r
+ * 'SqlApi' -> if the plugin uses the complete sql_* or DB::* api (must also require nucleuscms 3.5)\r
*/\r
public function supportsFeature($feature)\r
{\r
\r
$query = "SELECT d.oname as name, o.ovalue as value FROM %s o, %s d WHERE d.opid=%d AND d.oid=o.oid;";\r
$query = sprintf($query, sql_table('plugin_option'), sql_table('plugin_option_desc'), (integer) $this->plugid);\r
- $result = sql_query($query);\r
- while ( $row = sql_fetch_object($result) )\r
+ $result = DB::getResult($query);\r
+ foreach ( $result as $row )\r
{\r
- $this->plugin_options[strtolower($row->name)] = $row->value;\r
+ $this->plugin_options[strtolower($row['name'])] = $row['value'];\r
}\r
}\r
if ( isset($this->plugin_options[strtolower($name)]) )\r
// retrieve the data and return\r
$query = "SELECT otype, oextra FROM %s WHERE oid = %d;";\r
$query = sprintf($query, sql_table('plugin_option_desc'), $oid);\r
- $result = sql_query($query);\r
+ $row = DB::getRow($query);\r
\r
- $o = sql_fetch_array($result);\r
- \r
- if ( ($this->optionCanBeNumeric($o['otype'])) && ($o['oextra'] == 'number' ) )\r
+ if ( ($this->optionCanBeNumeric($row['otype'])) && ($row['oextra'] == 'number' ) )\r
{\r
$orderby = 'CAST(ovalue AS SIGNED)';\r
}\r
}\r
$query = "SELECT ovalue value, ocontextid id FROM %s WHERE oid = %d ORDER BY %s %s LIMIT 0,%d;";\r
$query = sprintf($query, sql_table('plugin_option'), $oid, $orderby, $sort, (integer) $amount);\r
- $result = sql_query($query);\r
+ $result = DB::getResult($query);\r
\r
// create the array\r
$i = 0;\r
$top = array();\r
- while( $row = sql_fetch_array($result) )\r
+ foreach( $result as $row )\r
{\r
$top[$i++] = $row;\r
}\r
$query = 'INSERT INTO ' . sql_table('plugin_option_desc')\r
.' (opid, oname, ocontext, odesc, otype, odef, oextra)'\r
.' VALUES ('.intval($this->plugid)\r
- .', \''.sql_real_escape_string($name).'\''\r
- .', \''.sql_real_escape_string($context).'\''\r
- .', \''.sql_real_escape_string($desc).'\''\r
- .', \''.sql_real_escape_string($type).'\''\r
- .', \''.sql_real_escape_string($defValue).'\''\r
- .', \''.sql_real_escape_string($typeExtras).'\');';\r
- sql_query($query);\r
- $oid = sql_insert_id();\r
+ .', '.DB::quoteValue($name)\r
+ .', '.DB::quoteValue($context)\r
+ .', '.DB::quoteValue($desc)\r
+ .', '.DB::quoteValue($type)\r
+ .', '.DB::quoteValue($defValue)\r
+ .', '.DB::quoteValue($typeExtras).')';\r
+ DB::execute($query);\r
+ $oid = DB::getInsertId();\r
\r
$key = $context . '_' . $name;\r
$this->option_info[$key] = array('oid' => $oid, 'default' => $defValue);\r
// delete all things from plugin_option\r
$query = "DELETE FROM %s WHERE oid=%d;";\r
$query = sprintf($query, sql_table('plugin_option'), (integer) $oid);\r
- sql_query($query);\r
+ DB::execute($query);\r
\r
// delete entry from plugin_option_desc\r
$query = "DELETE FROM %s WHERE oid=%d;";\r
$query = sprintf($query, sql_table('plugin_option_desc'), $oid);\r
- sql_query($query);\r
+ DB::execute($query);\r
\r
// clear from cache\r
unset($this->option_info["{$context}_{$name}"]);\r
// update plugin_option\r
$query = "DELETE FROM %s WHERE oid=%d and ocontextid=%d;";\r
$query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid);\r
- sql_query($query);\r
+ DB::execute($query);\r
\r
- $query = "INSERT INTO %s (ovalue, oid, ocontextid) VALUES ('%s', %d, %d);";\r
- $query = sprintf($query, sql_table('plugin_option'), sql_real_escape_string($value), $oid, $contextid);\r
- sql_query($query);\r
+ $query = "INSERT INTO %s (ovalue, oid, ocontextid) VALUES (%s, %d, %d);";\r
+ $query = sprintf($query, sql_table('plugin_option'), DB::quoteValue($value), $oid, $contextid);\r
+ DB::execute($query);\r
\r
// update cache\r
$this->option_values["{$oid}_{$contextid}"] = $value;\r
// get from DB\r
$query = "SELECT ovalue FROM %s WHERE oid=%d and ocontextid=%d;";\r
$query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid);\r
- $result = sql_query($query);\r
+ $result = DB::getResult($query);\r
\r
- if ( !$result || (sql_num_rows($result) == 0) )\r
+ if ( !$result || ($result->rowCount() == 0) )\r
{\r
// fill DB with default value\r
$this->option_values[$key] = $this->get_default_value($context, $name);\r
- $query = "INSERT INTO %s (oid, ocontextid, ovalue) VALUES (%d, %d, '%s');";\r
- $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid, sql_real_escape_string($defVal));\r
- sql_query($query);\r
+ $query = "INSERT INTO %s (oid, ocontextid, ovalue) VALUES (%d, %d, %s);";\r
+ $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid, DB::quoteValue($this->option_values[$key]));\r
+ DB::execute($query);\r
}\r
else\r
{\r
- $o = sql_fetch_object($result);\r
- $this->option_values[$key] = $o->ovalue;\r
+ $row = $result->fetch();\r
+ $this->option_values[$key] = $row['ovalue'];\r
}\r
\r
return $this->option_values[$key];\r
break;\r
}\r
\r
- $result = sql_query($query);\r
+ $result = DB::getResult($query);\r
if ( $result )\r
{\r
- while ( $o = sql_fetch_object($r) )\r
+ foreach ( $result as $row )\r
{\r
- $options[$o->contextid] = $default_value;\r
+ $options[$row['contextid']] = $default_value;\r
}\r
}\r
\r
$query = "SELECT ocontextid, ovalue FROM %s WHERE oid=%d;";\r
$query = sprintf($query, sql_table('plugin_option'), $oid);\r
- $result = sql_query($query);\r
- while ( $o = sql_fetch_object($result) )\r
+ $result = DB::getResult($query);\r
+ foreach ( $result as $row )\r
{\r
- $options[$o->ocontextid] = $o->ovalue;\r
+ $options[$row['ocontextid']] = $row['ovalue'];\r
}\r
\r
return $options;\r
$this->option_info = array();\r
$query = "SELECT oid, oname, ocontext, odef FROM %s WHERE opid=%d;";\r
$query = sprintf($query, sql_table('plugin_option_desc'), $this->plugid);\r
- $result = sql_query($query);\r
- while ( $o = sql_fetch_object($result) )\r
+ $result = DB::getResult($query);\r
+ foreach ( $result as $row )\r
{\r
- $k = $o->ocontext . '_' . $o->oname;\r
- $this->option_info[$k] = array('oid' => $o->oid, 'default' => $o->odef);\r
+ $k = $row['ocontext'] . '_' . $row['oname'];\r
+ $this->option_info[$k] = array('oid' => $row['oid'], 'default' => $row['odef']);\r
}\r
- sql_free_result($result);\r
+ $result->closeCursor();\r
\r
return $this->option_info[$key]['oid'];\r
}\r
// delete all associated plugin options\r
$aOIDs = array();\r
// find ids\r
- $query = "SELECT oid FROM %s WHERE ocontext='%s';";\r
- $query = sprintf($query, sql_table('plugin_option_desc'), sql_real_escape_string($context));\r
+ $query = "SELECT oid FROM %s WHERE ocontext=%s;";\r
+ $query = sprintf($query, sql_table('plugin_option_desc'), DB::quoteValue($context));\r
\r
- $result = sql_query($query);\r
- while ( $o = sql_fetch_object($result) )\r
+ $result = DB::getResult($query);\r
+ foreach ( $result as $row )\r
{\r
- array_push($aOIDs, $o->oid);\r
+ array_push($aOIDs, $row['oid']);\r
}\r
- sql_free_result($result);\r
+ $result->closeCursor();\r
// delete those options. go go go\r
if ( count($aOIDs) > 0 )\r
{\r
$query = "DELETE FROM %s WHERE oid in (%s) and ocontextid=%d;";\r
$query = sprintf($query, sql_table('plugin_option'), implode(',',$aOIDs), (integer) $contextid);\r
- sql_query($query);\r
+ DB::execute($query);\r
}\r
return;\r
}\r
*/\r
public function subscribtionListIsUptodate()\r
{\r
- $res = sql_query('SELECT event FROM '.sql_table('plugin_event').' WHERE pid = '.$this->plugid);\r
+ $res = DB::getResult('SELECT event FROM '.sql_table('plugin_event').' WHERE pid = '.$this->plugid);\r
$ev = array();\r
- while( $a = sql_fetch_array($res) )\r
+ foreach ( $res as $row )\r
{\r
- array_push($ev, $a['event']);\r
+ array_push($ev, $row['event']);\r
}\r
if ( count($ev) != count($this->getEventList()) )\r
{\r
// get option type info\r
$query = "SELECT opid, oname, ocontext, otype, oextra, odef FROM %s WHERE oid=%d;";\r
$query = sprintf($query, sql_table('plugin_option_desc'), (integer) $oid);\r
- $result = sql_query($query);\r
- if ( $info = sql_fetch_object($result) )\r
+ $result = DB::getRow($query);\r
+ if ( $result )\r
{\r
foreach ( $values as $id => $value )\r
{\r
}\r
\r
// retreive any metadata\r
- $meta = NucleusPlugin::getOptionMeta($info->oextra);\r
+ $meta = NucleusPlugin::getOptionMeta($result['oextra']);\r
\r
// if the option is readonly or hidden it may not be saved\r
if ( array_key_exists('access', $meta)\r
$value = undoMagic($value);\r
\r
/* validation the value according to its type */\r
- switch ( $info->otype )\r
+ switch ( $result['otype'] )\r
{\r
case 'yesno':\r
if ( ($value != 'yes') && ($value != 'no') )\r
if ( array_key_exists('datatype', $meta)\r
&& ($meta['datatype'] == 'numerical') && ($value != (integer) $value) )\r
{\r
- $value = (integer) $info->odef;\r
+ $value = (integer) $result['odef'];\r
}\r
break;\r
case 'password':\r
* possibility to change/validate the new value for the option\r
*/\r
$data = array(\r
- 'context' => $info->ocontext,\r
- 'plugid' => $info->opid,\r
- 'optionname' => $info->oname,\r
- 'contextid' => $contextid,\r
- 'value' => &$value);\r
+ 'context' => $result['ocontext'],\r
+ 'plugid' => $result['opid'],\r
+ 'optionname' => $result['oname'],\r
+ 'contextid' => $contextid,\r
+ 'value' => &$value);\r
$manager->notify('PrePluginOptionsUpdate', $data);\r
\r
// delete and insert its fields of table in database\r
$query = "DELETE FROM %s WHERE oid=%d AND ocontextid=%d;";\r
$query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid);\r
- sql_query($query);\r
- $query = "INSERT INTO %s (oid, ocontextid, ovalue) VALUES (%d, %d, '%s');";\r
- $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid, sql_real_escape_string($value));\r
- sql_query($query);\r
- }\r
- }\r
- // clear option value cache if the plugin object is already loaded\r
- if ( is_object($info) )\r
- {\r
- $plugin=& $manager->pidLoaded($info->opid);\r
- if ( $plugin )\r
- {\r
- $plugin->clearOptionValueCache();\r
+ DB::execute($query);\r
+ $query = "INSERT INTO %s (oid, ocontextid, ovalue) VALUES (%d, %d, %s);";\r
+ $query = sprintf($query, sql_table('plugin_option'), (integer) $oid, (integer) $contextid, DB::quoteValue($value));\r
+ DB::execute($query);\r
+ \r
+ // clear option value cache if the plugin object is already loaded\r
+ $plugin=& $manager->pidLoaded($result['opid']);\r
+ if ( $plugin )\r
+ {\r
+ $plugin->clearOptionValueCache();\r
+ }\r
+ \r
+ continue;\r
}\r
}\r
+ continue;\r
}\r
return;\r
}\r