C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RU7MSUA\html\kernel\blockinstance.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
// $Id: blockinstance.php,v 1.1.2.13.2.1 2005/09/18 13:15:21 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.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/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //

if (!defined('XOOPS_ROOT_PATH')) {
    exit();
}
require_once 
XOOPS_ROOT_PATH."/kernel/object.php";

class 
XoopsBlockInstance extends XoopsObject
{
    var 
$block;
    
    function 
XoopsBlockInstance()
    {
        
$this->initVar('instanceid'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('bid'XOBJ_DTYPE_INTnullfalse);
        
$this->initVar('options'XOBJ_DTYPE_ARRAYnullfalse);
        
$this->initVar('title'XOBJ_DTYPE_TXTBOXnullfalse150);
        
        
$this->initVar('side'XOBJ_DTYPE_INT0false);
        
$this->initVar('weight'XOBJ_DTYPE_INT0false);
        
$this->initVar('visible'XOBJ_DTYPE_INT0false);
        
$this->initVar('bcachetime'XOBJ_DTYPE_INT0false);
    }
    
    function 
setBlock(&$block) {
        
$this->block =& $block;
    }

    
/**
     * (HTML-) form for setting the options of the block
     * 
     * @return string HTML for the form, FALSE if not defined for this block 
     **/
    
function getOptions()
    {
        
$edit_func $this->block->getVar('edit_func');
        if (!
$edit_func) {
            return 
false;
        }
        if (
file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->block->getVar('dirname').'/blocks/'.$this->block->getVar('func_file'))) {
            if (
file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->block->getVar('dirname').'/language/'.$GLOBALS['xoopsConfig']['language'].'/blocks.php')) {
                include_once 
XOOPS_ROOT_PATH.'/modules/'.$this->block->getVar('dirname').'/language/'.$GLOBALS['xoopsConfig']['language'].'/blocks.php';
            } elseif (
file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->block->getVar('dirname').'/language/english/blocks.php')) {
                include_once 
XOOPS_ROOT_PATH.'/modules/'.$this->block->getVar('dirname').'/language/english/blocks.php';
            }
            include_once 
XOOPS_ROOT_PATH.'/modules/'.$this->block->getVar('dirname').'/blocks/'.$this->block->getVar('func_file');
            
$options $this->getVar('options');
            
$edit_form $edit_func($options);
            if (!
$edit_form) {
                return 
false;
            }
            return 
$edit_form;
        } else {
            return 
false;
        }
    }
    
    function &
buildBlock()
    {
        global 
$xoopsConfig$xoopsOption;
        
$block = array();

        
// get block display function
        
$show_func $this->block->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->block->getVar('dirname')."/blocks/".$this->block->getVar('func_file')) ) {
            if ( 
file_exists(XOOPS_ROOT_PATH."/modules/".$this->block->getVar('dirname')."/language/".$xoopsConfig['language']."/blocks.php") ) {
                include_once 
XOOPS_ROOT_PATH."/modules/".$this->block->getVar('dirname')."/language/".$xoopsConfig['language']."/blocks.php";
            } elseif ( 
file_exists(XOOPS_ROOT_PATH."/modules/".$this->block->getVar('dirname')."/language/english/blocks.php") ) {
                include_once 
XOOPS_ROOT_PATH."/modules/".$this->block->getVar('dirname')."/language/english/blocks.php";
            }
            include_once 
XOOPS_ROOT_PATH."/modules/".$this->block->getVar('dirname')."/blocks/".$this->block->getVar('func_file');
            
$options $this->getVar("options");
//            var_dump($this->getVar('title'), $this);
            
if ( function_exists($show_func) ) {
                
// execute the function
                
$block $show_func($options);
                if ( !
$block ) {
                    return 
false;
                }
            } else {
                return 
false;
            }
        } else {
            return 
false;
        }

        return 
$block;
    }
    
/**
    * Get module IDs this instance is visible in
    *
    * @return array
    **/
    
function getVisibleIn() {
        
$ret = array();
        if (!
$this->isNew()) {
            
$sql "SELECT module_id, pageid FROM ".$GLOBALS['xoopsDB']->prefix('block_module_link')." WHERE block_id=".$this->getVar('instanceid');
            
$result $GLOBALS['xoopsDB']->query($sql);
            while (list(
$mid$pageid) = $GLOBALS['xoopsDB']->fetchRow($result)) {
                
$ret[] = $mid."-".$pageid;
            }
        }
        return 
$ret;
    }
    
    function 
getVisibleGroups() {
        
$groupperm_handler =& xoops_gethandler('groupperm');
        return 
$groupperm_handler->getGroupIds('block_read'$this->getVar('instanceid'));
    }
}

class 
XoopsBlockInstanceHandler extends XoopsPersistableObjectHandler {
    function 
XoopsBlockInstanceHandler(&$db) {
        
$this->XoopsPersistableObjectHandler($db'block_instance''XoopsBlockInstance''instanceid''title');
    }
    
    function 
delete(&$obj$force false) {
        
$sql sprintf("DELETE FROM %s WHERE block_id = %u"$this->db->prefix('block_module_link'), $obj->getVar('instanceid'));
        if (
$this->db->query($sql)) {
            
$groupperm_handler =& xoops_gethandler('groupperm');
            
$criteria = new CriteriaCompo(new Criteria('gperm_modid'1));
            
$criteria->add(new Criteria('gperm_name''block_read'));
            
$criteria->add(new Criteria('gperm_itemid'$obj->getVar('instanceid')));
            if (
$groupperm_handler->deleteAll($criteria)) {
                return 
parent::delete($obj$force);
            }
        }
        
//@TODO: LOCALIZE
        
$obj->setErrors("Could not delete instance link");
        return 
false;
    }
    
    function 
getLinkedObjects($groupid$module_id=0$pageid=0$visible=null$orderby='i.weight,i.instanceid'$isactive=1) {
        
$ret = array();
        
$groupperm_handler =& xoops_gethandler('groupperm');
        
$instanceids =& $groupperm_handler->getItemIds('block_read'$groupid);
        if (!empty(
$instanceids)) {
            
$block_handler =& xoops_gethandler('block');
            
$sql 'SELECT DISTINCT i.instanceid, b.*, i.* FROM '.$this->table.' i, '.$block_handler->table.' b, '.$this->db->prefix('block_module_link').' m WHERE m.block_id=i.instanceid';
            
$sql .= ' AND i.instanceid IN ('.implode(','$instanceids).')';
            if (isset(
$visible)) {
                
$sql .= ' AND i.visible='.intval($visible);
            }
            
$sql .= ' AND i.bid=b.bid';
            
$sql .= ' AND b.isactive='.$isactive;
            if (!empty(
$module_id) && $module_id != 0) {
                
$sql .= ' AND ( (m.module_id=0 AND m.pageid=0) OR (m.module_id='.intval($module_id).' AND m.pageid IN (0,'.intval($pageid).')) )';
            } else {
                if (
$pageid == 2) {
                    
//adminside blocks
                    
$sql .= ' AND m.module_id=0 AND m.pageid=2';
                }
                else {
                    
$sql .= ' AND m.module_id=0 AND m.pageid IN (0, '.intval($pageid).')';
                }
            }
            
$sql .= ' ORDER BY '.$orderby;
            
$result $this->db->query($sql);
            while ( 
$myrow $this->db->fetchArray($result) ) {
                
$newblock false;
                if (!isset(
$blocks[$myrow['bid']])) {
                    
$blocks[$myrow['bid']] =& $block_handler->create(false);
                    
$newblock true;
                }
                
                
$instance =& $this->create(false);
                
$instance_vars array_keys($instance->getVars());
                foreach (
$myrow as $key => $value) {
                    if (
$newblock && !in_array($key$instance_vars)) {
                        
$blocks[$myrow['bid']]->assignVar($key$value);
                    }
                    else {
                        
$instance->assignVar($key$value);
                    }
                }
                
$blocks[$myrow['bid']]->assignVar('bid'$myrow['bid']); 
                
$instance->setBlock($blocks[$myrow['bid']]);
                
$ret[] = $instance;
                unset(
$instance);
            }
        }
        return 
$ret;
    }
}
?>