Well check this out, i have been making a multixoops for uknaturalhealth.net this is the same xoops, have a look at the two..
http://www.uknaturalhealth.net/ &
http://uk-therapists.co.uk/Here are the steps to make a multixoops with 2.16 or 2.18 you will have to adapt the code.
First up you need to make a control table:
CREATE TABLE `prefix_domain_config` (
`id` int(8) unsigned NOT NULL auto_increment,
`area` varchar(128) default NULL,
`theme` varchar(128) default 'owdRefresh',
`title` varchar(255) default NULL,
`slogon` varchar(255) default NULL,
`meta_keywords` mediumtext,
`meta_description` mediumtext,
`tdl` tinyint(2) default '0',
`sub_tdl` tinyint(2) default '1',
PRIMARY KEY (`id`)
);
This will create the table prefix_domain_config
Next you will need the areas.php control class in /class
class control_areas {
var $domain;
var $area;
var $theme;
var $title;
var $website_slogon;
var $meta_keywords;
var $meta_description;
var $tdl;
var $sub_tdl;
function control_areas($xoops_url)
{
$xoops_url = basename($xoops_url);
$xoops_url = str_replace('http://','',$xoops_url);
$xoops_url = str_replace('https://','',$xoops_url);
$xoops_url = str_replace('www.','',$xoops_url);
$xoops_url = str_replace('/','',$xoops_url);
$this->domain = $xoops_url;
$this->area = $xoops_url;
return $this->domain;
}
function set_vars(){
global $xoopsDB;
if (isset($this->area)){
$mysql = mysql_connect(XOOPS_DB_HOST,XOOPS_DB_USER,XOOPS_DB_PASS);
$db = mysql_select_db(XOOPS_DB_NAME);
$sql = "SELECT * FROM ".XOOPS_DB_PREFIX.'_domain_config'.' where area = "'.$this->area.'"';
$ret = mysql_query($sql,$mysql);
$rt = mysql_fetch_assoc($ret);
}
$this->theme = $rt['theme'];
$this->title = $rt['title'];
$this->website_slogon = $rt['slogon'];
$this->meta_keywords = $rt['meta_keywords'];
$this->meta_description = $rt['meta_description'];
$this->tdl = $rt['tdl'];
$this->sub_tdl = $rt['sub_tdl'];
}
function getVar($var){
return $this->$var;
}
}
You will have to alter a couple of tables and add the following field in..
into:
* prefix_config you need to add a field
conf_area varchar(255)
* prefix_newblock you need to add a field
area varchar(255)
* prefix_modules you need to add a field
area varchar(255)
in this all the system module variables have to have the field set to 'default' otherwise area is the domain you want it to display on.
time to alter
mainfile.phpat the top below line 30 add
// Existing line
if ( !defined("XOOPS_MAINFILE_INCLUDED") ) {
define("XOOPS_MAINFILE_INCLUDED",1);
//new line
require('class/areas.php');
below
define('XOOPS_GROUP_ADMIN', '1');
define('XOOPS_GROUP_USERS', '2');
define('XOOPS_GROUP_ANONYMOUS', '3');
// Add this line in
$tmp = $_area->set_vars();
ok now we have to alter the object classes to select as a multiXoops these apart from one component of XoopsBlocks are found in /kernel
I have just done a code dump for this and commented the changes.
First Up:
module.php
<?php
// $Id: module.php 694 2006-09-04 11:33:22Z skalpa $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <https://xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://www.xoopscube.jp/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
/**
* A Module
*
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright (c) 2000-2003 The XOOPS Project - www.xoops.org
*/
class XoopsModule extends XoopsObject
{
/**
* @var string
*/
var $modinfo;
/**
* @var string
*/
var $adminmenu;
/**
* Constructor
*/
function XoopsModule()
{
global $_area;
$this->XoopsObject();
$this->initVar('mid', XOBJ_DTYPE_INT, null, false);
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150);
$this->initVar('version', XOBJ_DTYPE_INT, 100, false);
$this->initVar('last_update', XOBJ_DTYPE_INT, null, false);
$this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
$this->initVar('isactive', XOBJ_DTYPE_INT, 1, false);
$this->initVar('dirname', XOBJ_DTYPE_OTHER, null, true);
$this->initVar('hasmain', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hasadmin', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hassearch', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hasconfig', XOBJ_DTYPE_INT, 0, false);
$this->initVar('hascomments', XOBJ_DTYPE_INT, 0, false);
// RMV-NOTIFY
$this->initVar('hasnotification', XOBJ_DTYPE_INT, 0, false);
$this->initVar('area', XOBJ_DTYPE_TXTBOX, $_area->area, true, 255);
}
/**
* Load module info
*
* @param string $dirname Directory Name
* @param boolean $verbose
**/
function loadInfoAsVar($dirname, $verbose = true)
{
if ( !isset($this->modinfo) ) {
$this->loadInfo($dirname, $verbose);
}
$this->setVar('name', $this->modinfo['name'], true);
$this->setVar('version', intval(100 * ($this->modinfo['version']+0.001)), true);
$this->setVar('dirname', $this->modinfo['dirname'], true);
$hasmain = (isset($this->modinfo['hasMain']) && $this->modinfo['hasMain'] == 1) ? 1 : 0;
$hasadmin = (isset($this->modinfo['hasAdmin']) && $this->modinfo['hasAdmin'] == 1) ? 1 : 0;
$hassearch = (isset($this->modinfo['hasSearch']) && $this->modinfo['hasSearch'] == 1) ? 1 : 0;
$hasconfig = ((isset($this->modinfo['config']) && is_array($this->modinfo['config'])) || !empty($this->modinfo['hasComments'])) ? 1 : 0;
$hascomments = (isset($this->modinfo['hasComments']) && $this->modinfo['hasComments'] == 1) ? 1 : 0;
// RMV-NOTIFY
$hasnotification = (isset($this->modinfo['hasNotification']) && $this->modinfo['hasNotification'] == 1) ? 1 : 0;
$this->setVar('hasmain', $hasmain);
$this->setVar('hasadmin', $hasadmin);
$this->setVar('hassearch', $hassearch);
$this->setVar('hasconfig', $hasconfig);
$this->setVar('hascomments', $hascomments);
// RMV-NOTIFY
$this->setVar('hasnotification', $hasnotification);
}
/**
* Get module info
*
* @param string $name
* @return array|string Array of module information.
* If {@link $name} is set, returns a singel module information item as string.
**/
function &getInfo($name=null)
{
if ( !isset($this->modinfo) ) {
$this->loadInfo($this->getVar('dirname'));
}
if ( isset($name) ) {
if ( isset($this->modinfo[$name]) ) {
return $this->modinfo[$name];
}
$return = false;
return $return;
}
return $this->modinfo;
}
/**
* Get a link to the modules main page
*
* @return string FALSE on fail
*/
function mainLink()
{
if ( $this->getVar('hasmain') == 1 ) {
$ret = '<a href="'.XOOPS_URL.'/modules/'.$this->getVar('dirname').'/">'.$this->getVar('name').'</a>';
return $ret;
}
return false;
}
/**
* Get links to the subpages
*
* @return string
*/
function subLink()
{
$ret = array();
if ( $this->getInfo('sub') && is_array($this->getInfo('sub')) ) {
foreach ( $this->getInfo('sub') as $submenu ) {
$ret[] = array('name' => $submenu['name'], 'url' => $submenu['url']);
}
}
return $ret;
}
/**
* Load the admin menu for the module
*/
function loadAdminMenu()
{
if ($this->getInfo('adminmenu') && $this->getInfo('adminmenu') != '' && file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu'))) {
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$this->getInfo('adminmenu');
$this->adminmenu =& $adminmenu;
}
}
/**
* Get the admin menu for the module
*
* @return string
*/
function &getAdminMenu()
{
if ( !isset($this->adminmenu) ) {
$this->loadAdminMenu();
}
return $this->adminmenu;
}
/**
* Load the module info for this module
*
* @param string $dirname Module directory
* @param bool $verbose Give an error on fail?
*/
function loadInfo($dirname, $verbose = true)
{
global $xoopsConfig;
if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/'.$xoopsConfig['language'].'/modinfo.php')) {
include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/'.$xoopsConfig['language'].'/modinfo.php';
} elseif (file_exists(XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/english/modinfo.php')) {
include_once XOOPS_ROOT_PATH.'/modules/'.$dirname.'/language/english/modinfo.php';
}
if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$dirname.'/xoops_version.php')) {
include XOOPS_ROOT_PATH.'/modules/'.$dirname.'/xoops_version.php';
} else {
if (false != $verbose) {
echo "Module File for $dirname Not Found!";
}
return;
}
$this->modinfo =& $modversion;
}
/**
* Search contents within a module
*
* @param string $term
* @param string $andor 'AND' or 'OR'
* @param integer $limit
* @param integer $offset
* @param integer $userid
* @return mixed Search result.
**/
function search($term = '', $andor = 'AND', $limit = 0, $offset = 0, $userid = 0)
{
if ($this->getVar('hassearch') != 1) {
return false;
}
$search =& $this->getInfo('search');
if ($this->getVar('hassearch') != 1 || !isset($search['file']) || !isset($search['func']) || $search['func'] == '' || $search['file'] == '') {
return false;
}
if (file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname').'/'.$search['file'])) {
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/'.$search['file'];
} else {
return false;
}
if (function_exists($search['func'])) {
$func = $search['func'];
return $func($term, $andor, $limit, $offset, $userid);
}
return false;
}
/**#@+
* For backward compatibility only!
* @deprecated
*/
function mid()
{
return $this->getVar('mid');
}
function dirname()
{
return $this->getVar('dirname');
}
function name()
{
return $this->getVar('name');
}
function &getByDirName($dirname)
{
$modhandler =& xoops_gethandler('module');
$inst =& $modhandler->getByDirname($dirname);
return $inst;
}
/**#@-*/
}
/**
* XOOPS module handler class.
*
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS module class objects.
*
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright (c) 2000-2003 The XOOPS Project - www.xoops.org
*/
class XoopsModuleHandler extends XoopsObjectHandler
{
/**
* holds an array of cached module references, indexed by module id
*
* @var array
* @access private
*/
var $_cachedModule_mid = array();
/**
* holds an array of cached module references, indexed by module dirname
*
* @var array
* @access private
*/
var $_cachedModule_dirname = array();
/**
* Create a new {@link XoopsModule} object
*
* @param boolean $isNew Flag the new object as "new"
* @return object
**/
function &create($isNew = true)
{
$module = new XoopsModule();
if ($isNew) {
$module->setNew();
}
return $module;
}
/**
* Load a module from the database
*
* @param int $id ID of the module
*
* @return object FALSE on fail
*/
function &get($id)
{
static $_cachedModule_dirname;
static $_cachedModule_mid;
$id = intval($id);
$module = false;
if ($id > 0) {
if (!empty($_cachedModule_mid[$id])) {
return $_cachedModule_mid[$id];
} else {
$sql = 'SELECT * FROM '.$this->db->prefix('modules').' WHERE mid = '.$id;
if (!$result = $this->db->query($sql)) {
return $module;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$module = new XoopsModule();
$myrow = $this->db->fetchArray($result);
$module->assignVars($myrow);
$_cachedModule_mid[$id] =& $module;
$_cachedModule_dirname[$module->getVar('dirname')] =& $module;
return $module;
}
}
}
return $module;
}
/**
* Load a module by its dirname
*
* @param string $dirname
*
* @return object FALSE on fail
*/
function &getByDirname($dirname)
{
global $_area;
static $_cachedModule_mid;
static $_cachedModule_dirname;
if (!empty($_cachedModule_dirname[$dirname])) {
return $_cachedModule_dirname[$dirname];
} else {
$module = false;
// SQL CHANGED - wishcraft
$sql = "SELECT * FROM ".$this->db->prefix('modules')." WHERE dirname = '".trim($dirname)."' and area IN ('default','".$_area->area."')";
if (!$result = $this->db->query($sql)) {
return $module;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$module = new XoopsModule();
$myrow = $this->db->fetchArray($result);
$module->assignVars($myrow);
$_cachedModule_dirname[$dirname] =& $module;
$_cachedModule_mid[$module->getVar('mid')] =& $module;
}
return $module;
}
}
/**
* Write a module to the database
*
* @param object &$module reference to a {@link XoopsModule}
* @return bool
**/
function insert(&$module)
{
if (strtolower(get_class($module)) != 'xoopsmodule') {
return false;
}
if (!$module->isDirty()) {
return true;
}
if (!$module->cleanVars()) {
return false;
}
foreach ($module->cleanVars as $k => $v) {
${$k} = $v;
}
if ($module->isNew()) {
global $_area;
$mid = $this->db->genId('modules_mid_seq');
// SQL CHANGED - wishcraft
$sql = sprintf("INSERT INTO %s (mid, name, version, last_update, weight, isactive, dirname, hasmain, hasadmin, hassearch, hasconfig, hascomments, hasnotification, area) VALUES (%u, %s, %u, %u, %u, %u, %s, %u, %u, %u, %u, %u, %u, '%s')", $this->db->prefix('modules'), $mid, $this->db->quoteString($name), $version, time(), $weight, 1, $this->db->quoteString($dirname), $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification, $_area->area);
} else {
$sql = sprintf("UPDATE %s SET name = %s, dirname = %s, version = %u, last_update = %u, weight = %u, isactive = %u, hasmain = %u, hasadmin = %u, hassearch = %u, hasconfig = %u, hascomments = %u, hasnotification = %u WHERE mid = %u", $this->db->prefix('modules'), $this->db->quoteString($name), $this->db->quoteString($dirname), $version, time(), $weight, $isactive, $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification, $mid);
}
if (!$result = $this->db->query($sql)) {
return false;
}
if (empty($mid)) {
$mid = $this->db->getInsertId();
}
$module->assignVar('mid', $mid);
if (!empty($this->_cachedModule_dirname[$dirname])) {
unset ($this->_cachedModule_dirname[$dirname]);
}
if (!empty($this->_cachedModule_mid[$mid])) {
unset ($this->_cachedModule_mid[$mid]);
}
return true;
}
/**
* Delete a module from the database
*
* @param object &$module
* @return bool
**/
function delete(&$module)
{
if (strtolower(get_class($module)) != 'xoopsmodule') {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE mid = %u", $this->db->prefix('modules'), $module->getVar('mid'));
if ( !$result = $this->db->query($sql) ) {
return false;
}
// delete admin permissions assigned for this module
$sql = sprintf("DELETE FROM %s WHERE gperm_name = 'module_admin' AND gperm_itemid = %u", $this->db->prefix('group_permission'), $module->getVar('mid'));
$this->db->query($sql);
// delete read permissions assigned for this module
$sql = sprintf("DELETE FROM %s WHERE gperm_name = 'module_read' AND gperm_itemid = %u", $this->db->prefix('group_permission'), $module->getVar('mid'));
$this->db->query($sql);
$sql = sprintf("SELECT block_id FROM %s WHERE module_id = %u", $this->db->prefix('block_module_link'), $module->getVar('mid'));
if ($result = $this->db->query($sql)) {
$block_id_arr = array();
while ($myrow = $this->db->fetchArray($result))
{
array_push($block_id_arr, $myrow['block_id']);
}
}
// loop through block_id_arr
if (isset($block_id_arr)) {
foreach ($block_id_arr as $i) {
$sql = sprintf("SELECT block_id FROM %s WHERE module_id != %u AND block_id = %u", $this->db->prefix('block_module_link'), $module->getVar('mid'), $i);
if ($result2 = $this->db->query($sql)) {
if (0 < $this->db->getRowsNum($result2)) {
// this block has other entries, so delete the entry for this module
$sql = sprintf("DELETE FROM %s WHERE (module_id = %u) AND (block_id = %u)", $this->db->prefix('block_module_link'), $module->getVar('mid'), $i);
$this->db->query($sql);
} else {
// this block doesnt have other entries, so disable the block and let it show on top page only. otherwise, this block will not display anymore on block admin page!
$sql = sprintf("UPDATE %s SET visible = 0 WHERE bid = %u", $this->db->prefix('newblocks'), $i);
$this->db->query($sql);
$sql = sprintf("UPDATE %s SET module_id = -1 WHERE module_id = %u", $this->db->prefix('block_module_link'), $module->getVar('mid'));
$this->db->query($sql);
}
}
}
}
if (!empty($this->_cachedModule_dirname[$module->getVar('dirname')])) {
unset ($this->_cachedModule_dirname[$module->getVar('dirname')]);
}
if (!empty($this->_cachedModule_mid[$module->getVar('mid')])) {
unset ($this->_cachedModule_mid[$module->getVar('mid')]);
}
return true;
}
/**
* Load some modules
*
* @param object $criteria {@link CriteriaElement}
* @param boolean $id_as_key Use the ID as key into the array
* @return array
**/
function getObjects($criteria = null, $id_as_key = false)
{
$ret = array();
$limit = $start = 0;
$sql = 'SELECT * FROM '.$this->db->prefix('modules');
global $_area;
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
// SQL CHANGED - wishcraft
$sql .= ' '.$criteria->renderWhere()." AND area IN ('default','".$_area->area."')";
$sql .= ' ORDER BY weight '.$criteria->getOrder().', mid ASC';
$limit = $criteria->getLimit();
$start = $criteria->getStart();
} else {
// SQL CHANGED - wishcraft
$sql .= " WHERE area IN ('default','".$_area->area."')";
}
$result = $this->db->query($sql, $limit, $start);
if (!$result) {
return $ret;
}
while ($myrow = $this->db->fetchArray($result)) {
$module = new XoopsModule();
$module->assignVars($myrow);
if (!$id_as_key) {
$ret[] =& $module;
} else {
$ret[$myrow['mid']] =& $module;
}
unset($module);
}
return $ret;
}
/**
* Count some modules
*
* @param object $criteria {@link CriteriaElement}
* @return int
**/
function getCount($criteria = null)
{
$sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('modules');
global $_area;
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
// SQL CHANGED - wishcraft
$sql .= ' '.$criteria->renderWhere(). " AND area IN ('default','".$_area->area."')";
} else {
$sql .= " WHERE area IN ('default','".$_area->area."')";
}
if (!$result = $this->db->query($sql)) {
return 0;
}
list($count) = $this->db->fetchRow($result);
return $count;
}
/**
* returns an array of module names
*
* @param bool $criteria
* @param boolean $dirname_as_key
* if true, array keys will be module directory names
* if false, array keys will be module id
* @return array
**/
function getList($criteria = null, $dirname_as_key = false)
{
$ret = array();
$modules =& $this->getObjects($criteria, true);
foreach (array_keys($modules) as $i) {
if (!$dirname_as_key) {
$ret[$i] = $modules[$i]->getVar('name');
} else {
$ret[$modules[$i]->getVar('dirname')] = $modules[$i]->getVar('name');
}
}
return $ret;
}
}
?>
Secondarily:
config.php
<?php
// $Id: config.php 694 2006-09-04 11:33:22Z skalpa $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <https://xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://www.xoopscube.jp/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
require_once XOOPS_ROOT_PATH.'/kernel/configoption.php';
require_once XOOPS_ROOT_PATH.'/kernel/configitem.php';
/**
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
/**
* XOOPS configuration handling class.
* This class acts as an interface for handling general configurations of XOOPS
* and its modules.
*
*
* @author Kazumi Ono <webmaster@myweb.ne.jp>
* @todo Tests that need to be made:
* - error handling
* @access public
*/
class XoopsConfigHandler
{
/**
* holds reference to config item handler(DAO) class
*
* @var object
* @access private
*/
var $_cHandler;
/**
* holds reference to config option handler(DAO) class
*
* @var object
* @access private
*/
var $_oHandler;
/**
* holds an array of cached references to config value arrays,
* indexed on module id and category id
*
* @var array
* @access private
*/
var $_cachedConfigs = array();
/**
* Constructor
*
* @param object &$db reference to database object
*/
function XoopsConfigHandler(&$db)
{
$this->_cHandler = new XoopsConfigItemHandler($db);
$this->_oHandler = new XoopsConfigOptionHandler($db);
}
/**
* Create a config
*
* @see XoopsConfigItem
* @return object reference to the new {@link XoopsConfigItem}
*/
function &createConfig()
{
$instance =& $this->_cHandler->create();
return $instance;
}
/**
* Get a config
*
* @param int $id ID of the config
* @param bool $withoptions load the config's options now?
* @return object reference to the {@link XoopsConfig}
*/
function &getConfig($id, $withoptions = false)
{
$config =& $this->_cHandler->get($id);
if ($withoptions == true) {
$config->setConfOptions($this->getConfigOptions(new Criteria('conf_id', $id)));
}
return $config;
}
/**
* insert a new config in the database
*
* @param object &$config reference to the {@link XoopsConfigItem}
*/
function insertConfig(&$config)
{
if (!$this->_cHandler->insert($config)) {
return false;
}
$options =& $config->getConfOptions();
$count = count($options);
$conf_id = $config->getVar('conf_id');
for ($i = 0; $i < $count; $i++) {
$options[$i]->setVar('conf_id', $conf_id);
if (!$this->_oHandler->insert($options[$i])) {
foreach($options[$i]->getErrors() as $msg){
$config->setErrors($msg);
}
}
}
if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
unset ($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
}
return true;
}
/**
* Delete a config from the database
*
* @param object &$config reference to a {@link XoopsConfigItem}
*/
function deleteConfig(&$config)
{
if (!$this->_cHandler->delete($config)) {
return false;
}
$options =& $config->getConfOptions();
$count = count($options);
if ($count == 0) {
$options = $this->getConfigOptions(new Criteria('conf_id', $config->getVar('conf_id')));
$count = count($options);
}
if (is_array($options) && $count > 0) {
for ($i = 0; $i < $count; $i++) {
$this->_oHandler->delete($options[$i]);
}
}
if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
unset ($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
}
return true;
}
/**
* get one or more Configs
*
* @param object $criteria {@link CriteriaElement}
* @param bool $id_as_key Use the configs' ID as keys?
* @param bool $with_options get the options now?
*
* @return array Array of {@link XoopsConfigItem} objects
*/
function getConfigs($criteria = null, $id_as_key = false, $with_options = false)
{
return $this->_cHandler->getObjects($criteria, $id_as_key);
}
/**
* Count some configs
*
* @param object $criteria {@link CriteriaElement}
*/
function getConfigCount($criteria = null)
{
return $this->_cHandler->getCount($criteria);
}
/**
* Get configs from a certain category
*
* @param int $category ID of a category
* @param int $module ID of a module
*
* @return array array of {@link XoopsConfig}s
*/
function &getConfigsByCat($category, $module = 0)
{
static $_cachedConfigs;
if (!empty($_cachedConfigs[$module][$category])) {
return $_cachedConfigs[$module][$category];
} else {
$ret = array();
$criteria = new CriteriaCompo(new Criteria('conf_modid', intval($module)));
if (!empty($category)) {
$criteria->add(new Criteria('conf_catid', intval($category)));
}
// NEW CODE and SQL - wishcraft
global $_area;
if ($category == XOOPS_CONF){
$tmp=$_area->set_vars;
$configs = $this->getConfigs($criteria, true);
if (is_array($configs)) {
foreach (array_keys($configs) as $i) {
switch ($configs[$i]->getVar('conf_name')){
case "sitename":
$ret[$configs[$i]->getVar('conf_name')] = $_area->getVar('title');
break;
case "slogan":
$ret[$configs[$i]->getVar('conf_name')] = $_area->getVar('website_slogon');
break;
case "theme_set":
$ret[$configs[$i]->getVar('conf_name')] = $_area->getVar('theme');
break;
default:
$ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
}
}
}
} elseif ($category == XOOPS_CONF_METAFOOTER){
$tmp=$_area->set_vars;
$configs = $this->getConfigs($criteria, true);
if (is_array($configs)) {
foreach (array_keys($configs) as $i) {
switch ($configs[$i]->getVar('conf_name')){
case "meta_keywords":
$ret[$configs[$i]->getVar('conf_name')] = $_area->getVar('meta_keywords');
break;
case "meta_description":
$ret[$configs[$i]->getVar('conf_name')] = $_area->getVar('meta_description');
break;
default:
$ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
}
}
}
} else {
$configs = $this->getConfigs($criteria, true);
if (is_array($configs)) {
foreach (array_keys($configs) as $i) {
$ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
}
}
}
$_cachedConfigs[$module][$category] = $ret;
return $_cachedConfigs[$module][$category];
}
}
/**
* Make a new {@link XoopsConfigOption}
*
* @return object {@link XoopsConfigOption}
*/
function &createConfigOption() {
$inst =& $this->_oHandler->create();
return $inst;
}
/**
* Get a {@link XoopsConfigOption}
*
* @param int $id ID of the config option
*
* @return object {@link XoopsConfigOption}
*/
function &getConfigOption($id) {
$inst =& $this->_oHandler->get($id);
return $inst;
}
/**
* Get one or more {@link XoopsConfigOption}s
*
* @param object $criteria {@link CriteriaElement}
* @param bool $id_as_key Use IDs as keys in the array?
*
* @return array Array of {@link XoopsConfigOption}s
*/
function getConfigOptions($criteria = null, $id_as_key = false)
{
return $this->_oHandler->getObjects($criteria, $id_as_key);
}
/**
* Count some {@link XoopsConfigOption}s
*
* @param object $criteria {@link CriteriaElement}
*
* @return int Count of {@link XoopsConfigOption}s matching $criteria
*/
function getConfigOptionsCount($criteria = null)
{
return $this->_oHandler->getCount($criteria);
}
/**
* Get a list of configs
*
* @param int $conf_modid ID of the modules
* @param int $conf_catid ID of the category
*
* @return array Associative array of name=>value pairs.
*/
function getConfigList($conf_modid, $conf_catid = 0)
{
if (!empty($this->_cachedConfigs[$conf_modid][$conf_catid])) {
return $this->_cachedConfigs[$conf_modid][$conf_catid];
} else {
$criteria = new CriteriaCompo(new Criteria('conf_modid', $conf_modid));
if (empty($conf_catid)) {
$criteria->add(new Criteria('conf_catid', $conf_catid));
}
// NEW CODE and SQL - wishcraft
$criteria = new Criteria("conf_area","('default','".$_area->area."')","IN");
$configs =& $this->_cHandler->getObjects($criteria);
$confcount = count($configs);
$ret = array();
for ($i = 0; $i < $confcount; $i++) {
$ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
}
$this->_cachedConfigs[$conf_modid][$conf_catid] =& $ret;
return $ret;
}
}
}
?>
Thirdly:
configitem.php
<?php
// $Id: configitem.php 506 2006-05-26 23:10:37Z skalpa $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <https://xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://www.xoopscube.jp/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
/**
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
/**#@+
* Config type
*/
define('XOOPS_CONF', 1);
define('XOOPS_CONF_USER', 2);
define('XOOPS_CONF_METAFOOTER', 3);
define('XOOPS_CONF_CENSOR', 4);
define('XOOPS_CONF_SEARCH', 5);
define('XOOPS_CONF_MAILER', 6);
define('XOOPS_CONF_AUTH', 7);
/**#@-*/
/**
*
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
class XoopsConfigItem extends XoopsObject
{
/**
* Config options
*
* @var array
* @access private
*/
var $_confOptions = array();
/**
* Constructor
*/
function XoopsConfigItem()
{
global $_area;
$this->initVar('conf_id', XOBJ_DTYPE_INT, null, false);
$this->initVar('conf_modid', XOBJ_DTYPE_INT, null, false);
$this->initVar('conf_catid', XOBJ_DTYPE_INT, null, false);
$this->initVar('conf_name', XOBJ_DTYPE_OTHER);
$this->initVar('conf_title', XOBJ_DTYPE_TXTBOX);
$this->initVar('conf_value', XOBJ_DTYPE_TXTAREA);
$this->initVar('conf_desc', XOBJ_DTYPE_OTHER);
$this->initVar('conf_formtype', XOBJ_DTYPE_OTHER);
$this->initVar('conf_valuetype', XOBJ_DTYPE_OTHER);
$this->initVar('conf_order', XOBJ_DTYPE_INT);
// NEW VAR - wishcraft
$this->initVar('conf_area', XOBJ_DTYPE_TXTBOX, $_area->area, false);
}
/**
* Get a config value in a format ready for output
*
* @return string
*/
function getConfValueForOutput()
{
switch ($this->getVar('conf_valuetype')) {
case 'int':
return intval($this->getVar('conf_value', 'N'));
break;
case 'array':
return unserialize($this->getVar('conf_value', 'N'));
case 'float':
$value = $this->getVar('conf_value', 'N');
return (float)$value;
break;
case 'textarea':
return $this->getVar('conf_value');
default:
return $this->getVar('conf_value', 'N');
break;
}
}
/**
* Set a config value
*
* @param mixed &$value Value
* @param bool $force_slash
*/
function setConfValueForInput(&$value, $force_slash = false)
{
switch($this->getVar('conf_valuetype')) {
case 'array':
if (!is_array($value)) {
$value = explode('|', trim($value));
}
$this->setVar('conf_value', serialize($value), $force_slash);
break;
case 'text':
$this->setVar('conf_value', trim($value), $force_slash);
break;
default:
$this->setVar('conf_value', $value, $force_slash);
break;
}
}
/**
* Assign one or more {@link XoopsConfigItemOption}s
*
* @param mixed $option either a {@link XoopsConfigItemOption} object or an array of them
*/
function setConfOptions($option)
{
if (is_array($option)) {
$count = count($option);
for ($i = 0; $i < $count; $i++) {
$this->setConfOptions($option[$i]);
}
} else {
if(is_object($option)) {
$this->_confOptions[] =& $option;
}
}
}
/**
* Get the {@link XoopsConfigItemOption}s of this Config
*
* @return array array of {@link XoopsConfigItemOption}
*/
function &getConfOptions()
{
return $this->_confOptions;
}
}
/**
* XOOPS configuration handler class.
*
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS configuration class objects.
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
class XoopsConfigItemHandler extends XoopsObjectHandler
{
/**
* Create a new {@link XoopsConfigItem}
*
* @see XoopsConfigItem
* @param bool $isNew Flag the config as "new"?
* @return object reference to the new config
*/
function &create($isNew = true)
{
$config = new XoopsConfigItem();
if ($isNew) {
$config->setNew();
}
return $config;
}
/**
* Load a config from the database
*
* @param int $id ID of the config
* @return object reference to the config, FALSE on fail
*/
function &get($id)
{
$config = false;
$id = intval($id);
if ($id > 0) {
$sql = 'SELECT * FROM '.$this->db->prefix('config').' WHERE conf_id='.$id;
if (!$result = $this->db->query($sql)) {
return $config;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$myrow = $this->db->fetchArray($result);
$config = new XoopsConfigItem();
$config->assignVars($myrow);
}
}
return $config;
}
/**
* Write a config to the database
*
* @param object &$config {@link XoopsConfigItem} object
* @return mixed FALSE on fail.
*/
function insert(&$config)
{
if (strtolower(get_class($config)) != 'xoopsconfigitem') {
return false;
}
if (!$config->isDirty()) {
return true;
}
if (!$config->cleanVars()) {
return false;
}
foreach ($config->cleanVars as $k => $v) {
${$k} = $v;
}
if ($config->isNew()) {
global $_area;
$conf_id = $this->db->genId('config_conf_id_seq');
// SQL CHANGED - wishcraft
$sql = sprintf("INSERT INTO %s (conf_id, conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order, conf_area) VALUES (%u, %u, %u, %s, %s, %s, %s, %s, %s, %u, '%s')", $this->db->prefix('config'), $conf_id, $conf_modid, $conf_catid, $this->db->quoteString($conf_name), $this->db->quoteString($conf_title), $this->db->quoteString($conf_value), $this->db->quoteString($conf_desc), $this->db->quoteString($conf_formtype), $this->db->quoteString($conf_valuetype), $conf_order, $_area->area);
} else {
$sql = sprintf("UPDATE %s SET conf_modid = %u, conf_catid = %u, conf_name = %s, conf_title = %s, conf_value = %s, conf_desc = %s, conf_formtype = %s, conf_valuetype = %s, conf_order = %u WHERE conf_id = %u", $this->db->prefix('config'), $conf_modid, $conf_catid, $this->db->quoteString($conf_name), $this->db->quoteString($conf_title), $this->db->quoteString($conf_value), $this->db->quoteString($conf_desc), $this->db->quoteString($conf_formtype), $this->db->quoteString($conf_valuetype), $conf_order, $conf_id);
}
if (!$result = $this->db->query($sql)) {
return false;
}
if (empty($conf_id)) {
$conf_id = $this->db->getInsertId();
}
$config->assignVar('conf_id', $conf_id);
return true;
}
/**
* Delete a config from the database
*
* @param object &$config Config to delete
* @return bool Successful?
*/
function delete(&$config)
{
if (strtolower(get_class($config)) != 'xoopsconfigitem') {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE conf_id = %u", $this->db->prefix('config'), $config->getVar('conf_id'));
if (!$result = $this->db->query($sql)) {
return false;
}
return true;
}
/**
* Get configs from the database
*
* @param object $criteria {@link CriteriaElement}
* @param bool $id_as_key return the config's id as key?
* @return array Array of {@link XoopsConfigItem} objects
*/
function getObjects($criteria = null, $id_as_key = false)
{
$ret = array();
$limit = $start = 0;
$sql = 'SELECT * FROM '.$this->db->prefix('config');
global $_area;
// SQL CHANGED - wishcraft
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere(). " AND conf_area IN ('default','".$_area->area."')";
$sql .= ' ORDER BY conf_order ASC';
$limit = $criteria->getLimit();
$start = $criteria->getStart();
} else {
$sql .= " WHERE conf_area IN ('default','".$_area->area."')";
}
$result = $this->db->query($sql, $limit, $start);
if (!$result) {
return false;
}
while ($myrow = $this->db->fetchArray($result)) {
$config = new XoopsConfigItem();
$config->assignVars($myrow);
if (!$id_as_key) {
$ret[] =& $config;
} else {
$ret[$myrow['conf_id']] =& $config;
}
unset($config);
}
return $ret;
}
/**
* Count configs
*
* @param object $criteria {@link CriteriaElement}
* @return int Count of configs matching $criteria
*/
function getCount($criteria = null)
{
$ret = array();
$limit = $start = 0;
$sql = 'SELECT * FROM '.$this->db->prefix('config');
global $_area;
// SQL CHANGED - wishcraft
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere(). " AND conf_area IN ('default','".$_area->area."')";
} else {
require_once XOOPS_ROOT_PATH.'/class/criteria.php';
$sql .= " WHERE conf_area IN ('default','".$_area->area."')";
}
$result =& $this->db->query($sql);
if (!$result) {
return false;
}
list($count) = $this->db->fetchRow($result);
return $count;
}
}
?>
Forthly:
block.php
<?php
// $Id: block.php 506 2006-05-26 23:10:37Z skalpa $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <https://xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://www.xoopscube.jp/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
/**
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000 XOOPS.org
**/
/**
* A block
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000 XOOPS.org
*
* @package kernel
**/
class XoopsBlock extends XoopsObject
{
/**
* constructor
*
* @param mixed $id
**/
function XoopsBlock($id = null)
{
global $_area;
$this->initVar('bid', XOBJ_DTYPE_INT, null, false);
$this->initVar('mid', XOBJ_DTYPE_INT, 0, false);
$this->initVar('func_num', XOBJ_DTYPE_INT, 0, false);
$this->initVar('options', XOBJ_DTYPE_TXTBOX, null, false, 255);
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150);
//$this->initVar('position', XOBJ_DTYPE_INT, 0, false);
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 150);
$this->initVar('content', XOBJ_DTYPE_TXTAREA, null, false);
$this->initVar('side', XOBJ_DTYPE_INT, 0, false);
$this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
$this->initVar('visible', XOBJ_DTYPE_INT, 0, false);
$this->initVar('block_type', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('c_type', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('isactive', XOBJ_DTYPE_INT, null, false);
$this->initVar('dirname', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('func_file', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('show_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('edit_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('template', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('bcachetime', XOBJ_DTYPE_INT, 0, false);
$this->initVar('last_modified', XOBJ_DTYPE_INT, 0, false);
// NEW VAR - wishcraft
$this->initVar('area', XOBJ_DTYPE_TXTBOX, $_area->area, false, 255);
// for backward compatibility
if (isset($id)) {
if (is_array($id)) {
$this->assignVars($id);
} else {
$blkhandler =& xoops_gethandler('block');
$obj =& $blkhandler->get($id);
foreach (array_keys($obj->getVars() ) as $i) {
$this->assignVar($obj->getVar($i, 'n') );
}
}
}
}
/**
* return the content of the block for output
*
* @param string $format
* @param string $c_type type of content<br>
* Legal value for the type of content<br>
* <ul><li>H : custom HTML block
* <li>P : custom PHP block
* <li>S : use text sanitizater (smilies enabled)
* <li>T : use text sanitizater (smilies disabled)</ul>
* @return string content for output
**/
function getContent($format = 'S', $c_type = 'T')
{
switch ( $format ) {
case 'S':
if ( $c_type == 'H' ) {
return str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
} elseif ( $c_type == 'P' ) {
ob_start();
echo eval($this->getVar('content', 'N'));
$content = ob_get_contents();
ob_end_clean();
return str_replace('{X_SITEURL}', XOOPS_URL.'/', $content);
} elseif ( $c_type == 'S' ) {
$myts =& MyTextSanitizer::getInstance();
return str_replace('{X_SITEURL}', XOOPS_URL.'/', $myts->displayTarea($this->getVar('content', 'N'), 0, 1));
} else {
$myts =& MyTextSanitizer::getInstance();
return str_replace('{X_SITEURL}', XOOPS_URL.'/', $myts->displayTarea($this->getVar('content', 'N'), 0, 0));
}
break;
case 'E':
return $this->getVar('content', 'E');
break;
default:
return $this->getVar('content', 'N');
break;
}
}
/**
* (HTML-) form for setting the options of the block
*
* @return string HTML for the form, FALSE if not defined for this block
**/
function getOptions()
{
if ($this->getVar('block_type') != 'C') {
$edit_func = $this->getVar('edit_func');
if (!$edit_func) {
return false;
}
if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file'))) {
if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/'.$GLOBALS['xoopsConfig']['language'].'/blocks.php')) {
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/'.$GLOBALS['xoopsConfig']['language'].'/blocks.php';
} elseif (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/english/blocks.php')) {
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/language/english/blocks.php';
}
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file');
$options = explode('|', $this->getVar('options'));
$edit_form = $edit_func($options);
if (!$edit_form) {
return false;
}
return $edit_form;
} else {
return false;
}
} else {
return false;
}
}
}
/**
* XOOPS block handler class. (Singelton)
*
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS block class objects.
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000 XOOPS.org
* @package kernel
* @subpackage block
*/
class XoopsBlockHandler extends XoopsObjectHandler
{
/**
* create a new block
*
* @see XoopsBlock
* @param bool $isNew is the new block new??
* @return object XoopsBlock reference to the new block
**/
function &create($isNew = true)
{
$block = new XoopsBlock();
if ($isNew) {
$block->setNew();
}
return $block;
}
/**
* retrieve a specific {@link XoopsBlock}
*
* @see XoopsBlock
* @param int $id bid of the block to retrieve
* @return object XoopsBlock reference to the block
**/
function &get($id)
{
$block = false;
$id = intval($id);
if ($id > 0) {
$sql = 'SELECT * FROM '.$this->db->prefix('newblocks').' WHERE bid='.$id;
if ( $result = $this->db->query($sql) ) {
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$block = new XoopsBlock();
$block->assignVars($this->db->fetchArray($result));
}
}
}
return $block;
}
/**
* write a new block into the database
*
* @param object XoopsBlock $block reference to the block to insert
* @return bool TRUE if succesful
**/
function insert(&$block)
{
global $_area;
if (strtolower(get_class($block)) != 'xoopsblock') {
return false;
}
if (!$block->isDirty()) {
return true;
}
if (!$block->cleanVars()) {
return false;
}
foreach ($block->cleanVars as $k => $v) {
${$k} = $v;
}
if ($block->isNew()) {
$bid = $this->db->genId('newblocks_bid_seq');
// SQL CHANGE - wishcraft
$sql = sprintf("INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified, area) VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %u, %u, %u, '%s', '%s', %u, '%s', '%s', '%s', '%s', '%s', %u, %u, '%s')", $this->db->prefix('newblocks'), $bid, $mid, $func_num, $options, $name, $title, $content, $side, $weight, $visible, $block_type, $c_type, 1, $dirname, $func_file, $show_func, $edit_func, $template, $bcachetime, time(), $_area->area);
} else {
$sql = sprintf("UPDATE %s SET func_num = %u, options = '%s', name = '%s', title = '%s', content = '%s', side = %u, weight = %u, visible = %u, c_type = '%s', isactive = %u, func_file = '%s', show_func = '%s', edit_func = '%s', template = '%s', bcachetime = %u, last_modified = %u WHERE bid = %u", $this->db->prefix('newblocks'), $func_num, $options, $name, $title, $content, $side, $weight, $visible, $c_type, $isactive, $func_file, $show_func, $edit_func, $template, $bcachetime, time(), $bid);
}
if (!$result = $this->db->query($sql)) {
return false;
}
if (empty($bid)) {
$bid = $this->db->getInsertId();
}
$block->assignVar('bid', $bid);
return true;
}
/**
* delete a block from the database
*
* @param object XoopsBlock $block reference to the block to delete
* @return bool TRUE if succesful
**/
function delete(&$block)
{
if (strtolower(get_class($block)) != 'xoopsblock') {
return false;
}
$id = $block->getVar('bid');
$sql = sprintf("DELETE FROM %s WHERE bid = %u", $this->db->prefix('newblocks'), $id);
if (!$result = $this->db->query($sql)) {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE block_id = %u", $this->db->prefix('block_module_link'), $id);
$this->db->query($sql);
return true;
}
/**
* retrieve array of {@link XoopsBlock}s meeting certain conditions
* @param object $criteria {@link CriteriaElement} with conditions for the blocks
* @param bool $id_as_key should the blocks' bid be the key for the returned array?
* @return array {@link XoopsBlock}s matching the conditions
**/
function getObjects($criteria = null, $id_as_key = false)
{
global $_area;
$ret = array();
$limit = $start = 0;
$sql = 'SELECT DISTINCT(b.*) FROM '.$this->db->prefix('newblocks').' b LEFT JOIN '.$this->db->prefix('block_module_link').' l ON b.bid=l.block_id';
// SQL CHANGE - wishcraft
if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
$sql .= ' '.$criteria->renderWhere(). " AND area IN ('default','".$_area->area."')";
$limit = $criteria->getLimit();
$start = $criteria->getStart();
} else {
$sql .= " WHERE area IN ('default','".$_area->area."')";
}
$result = $this->db->query($sql, $limit, $start);
if (!$result) {
return $ret;
}
while ($myrow = $this->db->fetchArray($result)) {
$block = new XoopsBlock();
$block->assignVars($myrow);
if (!$id_as_key) {
$ret[] =& $block;
} else {
$ret[$myrow['bid']] =& $block;
}
unset($block);
}
return $ret;
}
/**
* get a list of blocks matchich certain conditions
*
* @param string $criteria conditions to match
* @return array array of blocks matching the conditions
**/
function getList($criteria = null)
{
$blocks =& $this->getObjects($criteria, true);
$ret = array();
foreach (array_keys($blocks) as $i) {
$name = ($blocks[$i]->getVar('block_type') != 'C') ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title');
$ret[$i] = $name;
}
return $ret;
}
}
?>