1
wishcraft
MultiXoops - Core Hack Step #1

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` (                     
                       `
idint(8unsigned NOT NULL auto_increment,          
                       `
areavarchar(128) default NULL,                      
                       `
themevarchar(128) default 'owdRefresh',             
                       `
titlevarchar(255) default NULL,                     
                       `
slogonvarchar(255) default NULL,                    
                       `
meta_keywordsmediumtext,                            
                       `
meta_descriptionmediumtext,                         
                       `
tdltinyint(2) default '0',                          
                       `
sub_tdltinyint(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.php

at 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_INTnullfalse);
        
$this->initVar('name'XOBJ_DTYPE_TXTBOXnulltrue150);
        
$this->initVar('version'XOBJ_DTYPE_INT100false);
        
$this->initVar('last_update'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('weight'XOBJ_DTYPE_INT0false);
        
$this->initVar('isactive'XOBJ_DTYPE_INT1false);
        
$this->initVar('dirname'XOBJ_DTYPE_OTHERnulltrue);
        
$this->initVar('hasmain'XOBJ_DTYPE_INT0false);
        
$this->initVar('hasadmin'XOBJ_DTYPE_INT0false);
        
$this->initVar('hassearch'XOBJ_DTYPE_INT0false);
        
$this->initVar('hasconfig'XOBJ_DTYPE_INT0false);
        
$this->initVar('hascomments'XOBJ_DTYPE_INT0false);
        
// RMV-NOTIFY
        
$this->initVar('hasnotification'XOBJ_DTYPE_INT0false);
        
$this->initVar('area'XOBJ_DTYPE_TXTBOX$_area->areatrue255);
    }

    
/**
     * 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) ? 0;
        
$hasadmin = (isset($this->modinfo['hasAdmin']) && $this->modinfo['hasAdmin'] == 1) ? 0;
        
$hassearch = (isset($this->modinfo['hasSearch']) && $this->modinfo['hasSearch'] == 1) ? 0;
        
$hasconfig = ((isset($this->modinfo['config']) && is_array($this->modinfo['config'])) || !empty($this->modinfo['hasComments'])) ? 0;
        
$hascomments = (isset($this->modinfo['hasComments']) && $this->modinfo['hasComments'] == 1) ? 0;
        
// RMV-NOTIFY
        
$hasnotification = (isset($this->modinfo['hasNotification']) && $this->modinfo['hasNotification'] == 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') == ) {
            
$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') != || !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), $versiontime(), $weight1$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), $versiontime(), $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 (
$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($criteriatrue);
        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($criteriatrue);
                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($criteriatrue);
                    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($criteriatrue);
                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_INTnullfalse);
        
$this->initVar('conf_modid'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('conf_catid'XOBJ_DTYPE_INTnullfalse);
        
$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->areafalse);
    }

    
/**
     * 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_INTnullfalse);
        
$this->initVar('mid'XOBJ_DTYPE_INT0false);
        
$this->initVar('func_num'XOBJ_DTYPE_INT0false);
        
$this->initVar('options'XOBJ_DTYPE_TXTBOXnullfalse255);
        
$this->initVar('name'XOBJ_DTYPE_TXTBOXnulltrue150);
        
//$this->initVar('position', XOBJ_DTYPE_INT, 0, false);
        
$this->initVar('title'XOBJ_DTYPE_TXTBOXnullfalse150);
        
$this->initVar('content'XOBJ_DTYPE_TXTAREAnullfalse);
        
$this->initVar('side'XOBJ_DTYPE_INT0false);
        
$this->initVar('weight'XOBJ_DTYPE_INT0false);
        
$this->initVar('visible'XOBJ_DTYPE_INT0false);
        
$this->initVar('block_type'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('c_type'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('isactive'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('dirname'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('func_file'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('show_func'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('edit_func'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('template'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('bcachetime'XOBJ_DTYPE_INT0false);
        
$this->initVar('last_modified'XOBJ_DTYPE_INT0false);
        
// NEW VAR - wishcraft
        
$this->initVar('area'XOBJ_DTYPE_TXTBOX$_area->areafalse255);
        
        
// 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'), 01));
            } else {
                
$myts =& MyTextSanitizer::getInstance();
                return 
str_replace('{X_SITEURL}'XOOPS_URL.'/'$myts->displayTarea($this->getVar('content''N'), 00));
            }
            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_type1$dirname$func_file$show_func$edit_func$template$bcachetimetime(), $_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$bcachetimetime(), $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($criteriatrue);
        
$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;
    }
}
?>
Resized Image
www.ohloh.net/accounts/226400

Follow, Like & Read:-

twitter.com/RegaltyFamily
github.com/Chronolabs-Cooperative
facebook.com/DrAntonyRoberts

2
wishcraft
MultiXoops - Core Hack Step #2

Now you have to alter one file on /class

Firstly: xoopsblock.php

<?php
// $Id: xoopsblock.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/object.php";

class 
XoopsBlock extends XoopsObject
{
    var 
$db;

    function 
XoopsBlock($id null)
    {
        
$this->db =& Database::getInstance();
        
$this->initVar('bid'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('mid'XOBJ_DTYPE_INT0false);
        
$this->initVar('func_num'XOBJ_DTYPE_INT0false);
        
$this->initVar('options'XOBJ_DTYPE_TXTBOXnullfalse255);
        
$this->initVar('name'XOBJ_DTYPE_TXTBOXnulltrue150);
        
//$this->initVar('position', XOBJ_DTYPE_INT, 0, false);
        
$this->initVar('title'XOBJ_DTYPE_TXTBOXnullfalse150);
        
$this->initVar('content'XOBJ_DTYPE_TXTAREAnullfalse);
        
$this->initVar('side'XOBJ_DTYPE_INT0false);
        
$this->initVar('weight'XOBJ_DTYPE_INT0false);
        
$this->initVar('visible'XOBJ_DTYPE_INT0false);
        
$this->initVar('block_type'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('c_type'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('isactive'XOBJ_DTYPE_INTnullfalse);

        
$this->initVar('dirname'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('func_file'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('show_func'XOBJ_DTYPE_TXTBOXnullfalse50);
        
$this->initVar('edit_func'XOBJ_DTYPE_TXTBOXnullfalse50);

        
$this->initVar('template'XOBJ_DTYPE_OTHERnullfalse);
        
$this->initVar('bcachetime'XOBJ_DTYPE_INT0false);
        
$this->initVar('last_modified'XOBJ_DTYPE_INT0false);
        global 
$_area;
        
// NEW VAR - wishcraft
        
$this->initVar('area'XOBJ_DTYPE_TXTBOX$_area->areafalse255);
        
        if ( !empty(
$id) ) {
            if ( 
is_array($id) ) {
                
$this->assignVars($id);
            } else {
                
$this->load(intval($id));
            }
        }
    }

    function 
load($id)
    {
        
$sql 'SELECT * FROM '.$this->db->prefix('newblocks').' WHERE bid = '.$id;
        
$arr $this->db->fetchArray($this->db->query($sql));
        
$this->assignVars($arr);
    }

    function 
store()
    {
        if ( !
$this->cleanVars() ) {
            return 
false;
        }
        foreach ( 
$this->cleanVars as $k=>$v ) {
            ${
$k} = $v;
        }
        if ( empty(
$bid) ) {
            global 
$_area;
            
$bid $this->db->genId($this->db->prefix("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$this->db->quoteString($options), $this->db->quoteString($name), $this->db->quoteString($title), $this->db->quoteString($content), $side$weight$visible$this->db->quoteString($block_type), $this->db->quoteString($c_type), 1$this->db->quoteString($dirname), $this->db->quoteString($func_file), $this->db->quoteString($show_func), $this->db->quoteString($edit_func), $this->db->quoteString($template), $bcachetimetime(), $_area->area);
        } else {
            
$sql "UPDATE ".$this->db->prefix("newblocks")." SET options=".$this->db->quoteString($options);
            
// a custom block needs its own name
            
if ( $block_type == "C" ) {
                
$sql .= ", name=".$this->db->quoteString($name);
            }
            
$sql .= ", isactive=".$isactive.", title=".$this->db->quoteString($title).", content=".$this->db->quoteString($content).", side=".$side.", weight=".$weight.", visible=".$visible.", c_type=".$this->db->quoteString($c_type).", template=".$this->db->quoteString($template).", bcachetime=".$bcachetime.", last_modified=".time()." WHERE bid=".$bid;
        }
        if ( !
$this->db->query($sql) ) {
            
$this->setErrors("Could not save block data into database");
            return 
false;
        }
        if ( empty(
$bid) ) {
            
$bid $this->db->getInsertId();
        }
        return 
$bid;
    }

    function 
delete()
    {
        
$sql sprintf("DELETE FROM %s WHERE bid = %u"$this->db->prefix('newblocks'), $this->getVar('bid'));
        if ( !
$this->db->query($sql) ) {
            return 
false;
        }
        
$sql sprintf("DELETE FROM %s WHERE gperm_name = 'block_read' AND gperm_itemid = %u AND gperm_modid = 1"$this->db->prefix('group_permission'), $this->getVar('bid'));
        
$this->db->query($sql);
        
$sql sprintf("DELETE FROM %s WHERE block_id = %u"$this->db->prefix('block_module_link'), $this->getVar('bid'));
        
$this->db->query($sql);
        return 
true;
    }

    
/**
    * do stripslashes/htmlspecialchars according to the needed output
    *
    * @param $format      output use: S for Show and E for Edit
    * @param $c_type    type of block content
    * @returns string
    */
    
function getContent($format 'S'$c_type 'T')
    {
        switch ( 
$format ) {
        case 
'S':
            
// check the type of content
            // H : custom HTML block
            // P : custom PHP block
            // S : use text sanitizater (smilies enabled)
            // T : use text sanitizater (smilies disabled)
            
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'), 11));
            } else {
                
$myts =& MyTextSanitizer::getInstance();
                return 
str_replace('{X_SITEURL}'XOOPS_URL.'/'$myts->displayTarea($this->getVar('content''N'), 10));
            }
            break;
        case 
'E':
            return 
$this->getVar('content''E');
            break;
        default:
            return 
$this->getVar('content''N');
            break;
        }
    }

    function 
buildBlock()
    {
        global 
$xoopsConfig$xoopsOption;
        
$block = array();
        
// M for module block, S for system block C for Custom
        
if ( $this->getVar("block_type") != "C" ) {
            
// get block display function
            
$show_func $this->getVar('show_func');
            if ( !
$show_func ) {
                return 
false;
            }
            
// must get lang files b4 execution of the function
            
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/".$xoopsConfig['language']."/blocks.php") ) {
                    include_once 
XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/".$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"));
                if ( 
function_exists($show_func) ) {
                    
// execute the function
                    
$block $show_func($options);
                    if ( !
$block ) {
                        return 
false;
                    }
                } else {
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            
// it is a custom block, so just return the contents
            
$block['content'] = $this->getContent("S",$this->getVar("c_type"));
            if (empty(
$block['content'])) {
                return 
false;
            }
        }
        return 
$block;
    }

    
/*
    * Aligns the content of a block
    * If position is 0, content in DB is positioned
    * before the original content
    * If position is 1, content in DB is positioned
    * after the original content
    */
    
function buildContent($position,$content="",$contentdb="")
    {
        if ( 
$position == ) {
            
$ret $contentdb.$content;
        } elseif ( 
$position == ) {
            
$ret $content.$contentdb;
        }
        return 
$ret;
    }

    function 
buildTitle($originaltitle$newtitle="")
    {
        if (
$newtitle != "") {
            
$ret $newtitle;
        } else {
            
$ret $originaltitle;
        }
        return 
$ret;
    }

    function 
isCustom()
    {
        if ( 
$this->getVar("block_type") == "C" ) {
            return 
true;
        }
        return 
false;
    }

    
/**
    * gets html form for editting block options
    *
    */
    
function getOptions()
    {
        global 
$xoopsConfig;
        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/".$xoopsConfig['language']."/blocks.php") ) {
                    include_once 
XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/".$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;
        }
    }

    
/**
    * get all the blocks that match the supplied parameters
    * @param $side   0: sideblock - left
    *        1: sideblock - right
    *        2: sideblock - left and right
    *        3: centerblock - left
    *        4: centerblock - right
    *        5: centerblock - center
    *        6: centerblock - left, right, center
    * @param $groupid   groupid (can be an array)
    * @param $visible   0: not visible 1: visible
    * @param $orderby   order of the blocks
    * @returns array of block objects
    */
    
function getAllBlocksByGroup($groupid$asobject=true$side=null$visible=null$orderby="b.weight,b.bid"$isactive=1)
    {
        
$db =& Database::getInstance();
        
$ret = array();
        if ( !
$asobject ) {
            
$sql "SELECT b.bid ";
        } else {
            
$sql "SELECT b.* ";
        }
        
$sql .= "FROM ".$db->prefix("newblocks")." b LEFT JOIN ".$db->prefix("group_permission")." l ON l.gperm_itemid=b.bid WHERE gperm_name = 'block_read' AND gperm_modid = 1";
        if ( 
is_array($groupid) ) {
            
$sql .= " AND (l.gperm_groupid=".$groupid[0]."";
            
$size count($groupid);
            if ( 
$size  ) {
                for ( 
$i 1$i $size$i++ ) {
                    
$sql .= " OR l.gperm_groupid=".$groupid[$i]."";
                }
            }
            
$sql .= ")";
        } else {
            
$sql .= " AND l.gperm_groupid=".$groupid."";
        }
        
$sql .= " AND b.isactive=".$isactive;
        if ( isset(
$side) ) {
            
// get both sides in sidebox? (some themes need this)
            
if ( $side == XOOPS_SIDEBLOCK_BOTH ) {
                
$side "(b.side=0 OR b.side=1)";
            } elseif ( 
$side == XOOPS_CENTERBLOCK_ALL ) {
                
$side "(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )";
            } else {
                
$side "b.side=".$side;
            }
            
$sql .= " AND ".$side;
        }
        if ( isset(
$visible) ) {
            
$sql .= " AND b.visible=$visible";
        }
        global 
$_area;
        
// SQL CHANGE - wishcraft
        
$sql .= " AND area IN ('default','".$_area->area."')";
        
$sql .= " ORDER BY $orderby";
        
$result $db->query($sql);
        
$added = array();
        while ( 
$myrow $db->fetchArray($result) ) {
            if ( !
in_array($myrow['bid'], $added) ) {
                if (!
$asobject) {
                    
$ret[] = $myrow['bid'];
                } else {
                    
$ret[] = new XoopsBlock($myrow);
                }
                
array_push($added$myrow['bid']);
            }
        }
        
//echo $sql;
        
return $ret;
    }

    function 
getAllBlocks($rettype="object"$side=null$visible=null$orderby="side,weight,bid"$isactive=1)
    {
        
$db =& Database::getInstance();
        
$ret = array();
        
$where_query " WHERE isactive=".$isactive;
        if ( isset(
$side) ) {
            
// get both sides in sidebox? (some themes need this)
            
if ( $side == ) {
                
$side "(side=0 OR side=1)";
            } elseif ( 
$side == ) {
                
$side "(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)";
            } else {
                
$side "side=".$side;
            }
            
$where_query .= " AND ".$side;
        }
        if ( isset(
$visible) ) {
            
$where_query .= " AND visible=$visible";
        }
        global 
$_area;
        
// SQL CHANGE - wishcraft
        
$where_query .= " AND area IN ('default','".$_area->area."')";

        
$where_query .= " ORDER BY $orderby";
        switch (
$rettype) {
        case 
"object":
            
$sql "SELECT * FROM ".$db->prefix("newblocks")."".$where_query;
            
$result $db->query($sql);
            while ( 
$myrow $db->fetchArray($result) ) {
                
$ret[] = new XoopsBlock($myrow);
            }
            break;
        case 
"list":
            
$sql "SELECT * FROM ".$db->prefix("newblocks")."".$where_query;
            
$result $db->query($sql);
            while ( 
$myrow $db->fetchArray($result) ) {
                
$block = new XoopsBlock($myrow);
                
$name = ($block->getVar("block_type") != "C") ? $block->getVar("name") : $block->getVar("title");
                
$ret[$block->getVar("bid")] = $name;
            }
            break;
        case 
"id":
            
$sql "SELECT bid FROM ".$db->prefix("newblocks")."".$where_query;
            
$result $db->query($sql);
            while ( 
$myrow $db->fetchArray($result) ) {
                
$ret[] = $myrow['bid'];
            }
            break;
        }
        
//echo $sql;
        
return $ret;
    }

    function 
getByModule($moduleid$asobject=true)
    {
        
$db =& Database::getInstance();
        if ( 
$asobject == true ) {
            
$sql $sql "SELECT * FROM ".$db->prefix("newblocks")." WHERE mid=".$moduleid."";
        } else {
            
$sql "SELECT bid FROM ".$db->prefix("newblocks")." WHERE mid=".$moduleid."";
        }
        global 
$_area;
        
// SQL CHANGE - wishcraft
        
$sql .= " AND area IN ('default','".$_area->area."')";
        
$result $db->query($sql);
        
$ret = array();
        while( 
$myrow $db->fetchArray($result) ) {
            if ( 
$asobject ) {
                
$ret[] = new XoopsBlock($myrow);
            } else {
                
$ret[] = $myrow['bid'];
            }
        }
        return 
$ret;
    }

    function 
getAllByGroupModule($groupid$module_id=0$toponlyblock=false$visible=null$orderby='b.weight,b.bid'$isactive=1)
    {
        
$db =& Database::getInstance();
        
$ret = array();
        
$sql "SELECT DISTINCT gperm_itemid FROM ".$db->prefix('group_permission')." WHERE gperm_name = 'block_read' AND gperm_modid = 1";
        if ( 
is_array($groupid) ) {
            
$sql .= ' AND gperm_groupid IN ('.implode(','$groupid).')';
        } else {
            if (
intval($groupid) > 0) {
                
$sql .= ' AND gperm_groupid='.$groupid;
            }
        }
        
$result $db->query($sql);
        
$blockids = array();
        while ( 
$myrow $db->fetchArray($result) ) {
            
$blockids[] = $myrow['gperm_itemid'];
        }
        if (!empty(
$blockids)) {
            
$sql 'SELECT b.* FROM '.$db->prefix('newblocks').' b, '.$db->prefix('block_module_link').' m WHERE m.block_id=b.bid';
            
$sql .= ' AND b.isactive='.$isactive;
            if (isset(
$visible)) {
                
$sql .= ' AND b.visible='.intval($visible);
            }
            
$module_id intval($module_id);
            if (!empty(
$module_id)) {
                
$sql .= ' AND m.module_id IN (0,'.$module_id;
                if (
$toponlyblock) {
                    
$sql .= ',-1';
                }
                
$sql .= ')';
            } else {
                if (
$toponlyblock) {
                    
$sql .= ' AND m.module_id IN (0,-1)';
                } else {
                    
$sql .= ' AND m.module_id=0';
                }
            }
            
$sql .= ' AND b.bid IN ('.implode(','$blockids).')';
            global 
$_area;
            
// SQL CHANGE - wishcraft
            
$sql .= " AND b.area IN ('default','".$_area->area."')";
            
$sql .= ' ORDER BY '.$orderby;
            
$result $db->query($sql);
            while ( 
$myrow $db->fetchArray($result) ) {
                
$block =& new XoopsBlock($myrow);
                
$ret[$myrow['bid']] =& $block;
                unset(
$block);
            }
        }
        return 
$ret;
    }

    function 
getNonGroupedBlocks($module_id=0$toponlyblock=false$visible=null$orderby='b.weight,b.bid'$isactive=1)
    {
        
$db =& Database::getInstance();
        
$ret = array();
        
$bids = array();
        
$sql "SELECT DISTINCT(bid) from ".$db->prefix('newblocks');
        if (
$result $db->query($sql)) {
            while ( 
$myrow $db->fetchArray($result) ) {
                
$bids[] = $myrow['bid'];
            }
        }
        
$sql "SELECT DISTINCT(p.gperm_itemid) from ".$db->prefix('group_permission')." p, ".$db->prefix('groups')." g WHERE g.groupid=p.gperm_groupid AND p.gperm_name='block_read'";
        
$grouped = array();
        if (
$result $db->query($sql)) {
            while ( 
$myrow $db->fetchArray($result) ) {
                
$grouped[] = $myrow['gperm_itemid'];
            }
        }
        
$non_grouped array_diff($bids$grouped);
        if (!empty(
$non_grouped)) {
            
$sql 'SELECT b.* FROM '.$db->prefix('newblocks').' b, '.$db->prefix('block_module_link').' m WHERE m.block_id=b.bid';
            
$sql .= ' AND b.isactive='.$isactive;
            if (isset(
$visible)) {
                
$sql .= ' AND b.visible='.intval($visible);
            }
            
$module_id intval($module_id);
            if (!empty(
$module_id)) {
                
$sql .= ' AND m.module_id IN (0,'.$module_id;
                if (
$toponlyblock) {
                    
$sql .= ',-1';
                }
                
$sql .= ')';
            } else {
                if (
$toponlyblock) {
                    
$sql .= ' AND m.module_id IN (0,-1)';
                } else {
                    
$sql .= ' AND m.module_id=0';
                }
            }
            
$sql .= ' AND b.bid IN ('.implode(','$non_grouped).')';
            global 
$_area;
            
// SQL CHANGE - wishcraft
            
$sql .= " AND b.area IN ('default','".$_area->area."')";            
            
$sql .= ' ORDER BY '.$orderby;
            
$result $db->query($sql);
            while ( 
$myrow $db->fetchArray($result) ) {
                
$block =& new XoopsBlock($myrow);
                
$ret[$myrow['bid']] =& $block;
                unset(
$block);
            }
        }
        return 
$ret;
    }

    function 
countSimilarBlocks($moduleId$funcNum$showFunc null)
    {
        
$funcNum intval($funcNum);
        
$moduleId intval($moduleId);
        if (
$funcNum || $moduleId 1) {
            
// invalid query
            
return 0;
        }
        
$db =& Database::getInstance();
        global 
$_area;
        if (isset(
$showFunc)) {
            
// showFunc is set for more strict comparison
            
$sql sprintf("SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d AND  area IN ('default','".$_area->area."') AND show_func = %s"$db->prefix('newblocks'), $moduleId$funcNum$db->quoteString(trim($showFunc)));
        } else {
            
$sql sprintf("SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d and  area IN ('default','".$_area->area."')"$db->prefix('newblocks'), $moduleId$funcNum);
        }
        if (!
$result $db->query($sql)) {
            return 
0;
        }
        list(
$count) = $db->fetchRow($result);
        return 
$count;
    }
}
?>


Now you have to alter a file in the include path..

Firstly: cp_function.php
// ONLY THIS SUBROUTINE CHANGED - Wishcraft
function xoops_module_write_admin_menu($content)
{
    if (!
xoopsfwrite()) {
        return 
false;
    }
    global 
$_area;
    
$filename XOOPS_CACHE_PATH.'/adminmenu'.$_area->area.'.php';
    if ( !
$file fopen($filename"w") ) {
        echo 
'failed open file';
        return 
false;
    }
    if ( 
fwrite($file$content) == -) {
        echo 
'failed write file';
        return 
false;
    }
    
fclose($file);
    return 
true;
}


Now we have to alter one file in the root to ensure that there is possibility in getting into the XOOPS admin.

Line 53 to 59 should read in /admin.php
global $_area;
if (!
file_exists(XOOPS_CACHE_PATH.'/adminmenu'.$_area->area.'.php') && $op != 'generate') {
    
xoops_header();
    
xoops_confirm(array('op' => 'generate'), 'admin.php'_AD_PRESSGEN);
    
xoops_footer();
    exit();
}


the last change is to /modules/system/admin/modulesadmin/modulesadmin.php

below the } on line 197 add in the following code to make sure you don't delete any tables.

$error=false;


And thats to the customary of a MultiXoops Core hack
Resized Image
www.ohloh.net/accounts/226400

Follow, Like & Read:-

twitter.com/RegaltyFamily
github.com/Chronolabs-Cooperative
facebook.com/DrAntonyRoberts

3
xgarb
Re: MultiXoops - Core Hack Step #2
  • 2008/3/2 13:27

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


Thanks for documenting that. I've been following the multisite hack for a while but not really got my head round it yet...

Does is it work off one set of modified files with multiple databases for the other sites but with a centralised user table?

Can you login on one site and move through the others without having to re-login each time?

I thought about doing this myself by modifying the signup scripts to create accounts across several sites at once.

Wonder how XOOPS 3 will integrate multi-site?

4
maketravel
Re: MultiXoops - Core Hack Step #2
  • 2008/5/7 13:06

  • maketravel

  • Just popping in

  • Posts: 35

  • Since: 2008/3/20


under Xoops Multisite Modul you can download multisite as modul.

Login

Who's Online

183 user(s) are online (117 user(s) are browsing Support Forums)


Members: 0


Guests: 183


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits