XPressME Integration Kit

Trac

source: trunk/class/check_blocks_class.php @ 151

Last change on this file since 151 was 151, checked in by toemon, 15 years ago

ブロックテーブルのチェックコード追加 #21
XOOPSモジュール管理メニューに「ブロック権限」と「ブロックチェック」メニューを追加

File size: 9.5 KB
Line 
1<?php
2
3//================================================================
4// check block table
5// 2007-10-10 K.OHWADA
6//================================================================
7
8//---------------------------------------------------------
9// this program works in XOOPS 2.0.16aJP, XOOPS Cube 2.1.2, XOOPS 2.0.17
10//
11// NOTE
12// xoops 2.0.16 JP  : class/xoopsblock.php and kernel/block.php are different
13// xoops cube 2.1.2 : class/xoopsblock.php and kernel/block.php are the same
14// xoops 2.0.17     : no token class
15//---------------------------------------------------------
16
17include_once dirname( __FILE__ ).'/../../../mainfile.php';
18include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
19
20//=========================================================
21// class xoops_block_check
22//=========================================================
23class xoops_block_check
24{
25        var $_TOKEN_NAME = 'block';
26        var $module_id        = 0;
27        var $_msg_array  = array();
28        var $_error_flag = false;
29        var $_xoops_version = '2.0';
30        var $_use_token     = false;
31        var $_blocks_check_array = array();
32        var $_all_ok_flag = true;
33        var $_module_dir = '';
34        var $module_name = '';
35        var $module_dirname = '';
36        var $remove_submit_form;
37        var $update_link;
38//---------------------------------------------------------
39// constructor
40//---------------------------------------------------------
41function xoops_block_check()
42{
43        $this->_detect_xoops_version();
44}
45
46function &getInstance()
47{
48        static $instance;
49        if (!isset($instance))
50        {
51                $instance = new xoops_block_check();
52        }
53        return $instance;
54}
55
56//--------------------------------------------------------
57// public
58//--------------------------------------------------------
59function get_message()
60{
61        return $this->_get_msg();
62}
63
64function get_op()
65{
66        $op  = '';
67        $mid = 0;
68        foreach ( $_POST as $k => $v )
69        {
70                if ( preg_match( "/^mid:/", $k ) )
71                {
72                        $op  = 'remove_block';
73                        $mid = intval( str_replace("mid:", "", $k) );
74                        break;
75                }
76        }
77        $this->module_id = $mid;
78        return $op;
79}
80
81function check_blocks($module_dir)
82{
83        $this->_all_ok_flag = true;
84        $this->_module_dir = $module_dir;
85        $this->module_dirname = $module_dir;
86
87        if ( $this->_use_token )
88        {
89                $text = $this->_create_token();
90        }
91
92        $objs =& $this->_get_module_objects();
93        $obj = $objs[0];
94        if (!empty($obj)){
95                $this->module_id = $obj->getVar('mid', 'n');
96                $url = $this->_build_url_module_update( $this->module_dirname );
97                $this->update_link = $this->_build_url_module_update( $this->module_dirname );
98                $this->remove_submit_form .= '<input type="submit" name="mid:'.$this->module_id.'" value="Remove Block: '.$this->module_name.'" />'."\n";
99
100                return $this->_check_block_by_module( $obj );
101
102        } else {
103                $this->_err( 'Modules Not Found' );
104                return false;
105        }
106}
107
108function remove_block()
109{
110        $text = "<h1>Remove xoops block table</h1>\n";
111
112
113/*
114        if( $this->_use_token && !$this->_validate_token() )
115        {
116                $text .= '<h3 style="color:#ff0000">Token Error</h3>'."\n";
117                $text .= '<a href="block_check.php">Check Bloks</a>';
118                return $text;
119        }
120*/
121        $module_obj =& $this->_get_module_object_bymodule_id( $this->module_id );
122        if( !is_object($module_obj) )
123        {
124                $text .= '<h3 style="color:#ff0000">"No Module: mid='. $this->module_id ."</h3>\n";
125                $text .= "<br />\n";
126                $text .= '<a href="check_blocks.php">Check Bloks</a>';
127                return $text;
128        }
129
130        $ret = $this->_remove_block_bymodule_id( $this->module_id );
131        if ( $ret ) {
132                $text .= '<h4 style="color:#0000ff">Success</h4>'."\n";
133        } else {
134                $text .= '<h4 style="color:#ff0000">Failed</h4>'."\n";
135        }
136
137        $url = $this->_build_url_module_update( $module_obj->getVar('dirname', 'n') );
138        $text .= '<a href="'.$url.'">GO to Module Update: '.$module_obj->getVar('name', 's')."</a><br /><br />\n";
139//      $text .= '<a href="check_blocks.php">Check xoops block table</a><br />'."\n";
140
141        return $text;
142}
143
144//--------------------------------------------------------
145// private
146//--------------------------------------------------------
147function _check_block_by_module( &$module_obj )
148{
149        $this->_msg_array = array();
150
151        $mid      =  $module_obj->getVar('mid', 'n');
152        $mod_name =  $module_obj->getVar('name', 's');
153        $dirname  =  $module_obj->getVar('dirname', 'n');
154        $infos    =& $module_obj->getInfo('blocks');
155
156        $this->module_name = $mod_name ;
157        $this->module_dirname = $dirname ;
158       
159
160        if ( !is_array($infos) || !count($infos) )
161        {
162                $this->_msg( 'No block' );
163                return $this->_get_msg();
164        }
165
166
167        $block_objs =& $this->_get_block_object_orber_num_bymodule_id( $mid );
168
169        foreach ( $infos as $num => $info )
170        {
171                if ( !isset( $block_objs[ $num ] ) )
172                {
173                        $this->_err( htmlspecialchars( $info['name'] ).': not exist in block table' );
174                        $this->_all_ok_flag = false;
175
176                        continue;
177                }
178
179                $this->_check_block_by_obj( $info, $block_objs[ $num ] );
180        }
181
182        if ($this->_all_ok_flag){
183        } else {               
184        }
185
186        return $this->_all_ok_flag;
187}
188
189function _check_block_by_obj( &$info, &$block_obj )
190{
191        $this->_error_flag = false;
192
193        $name = htmlspecialchars( $info['name'] );
194
195        if ( isset($info['file']) && ( $info['file'] != $block_obj->getVar('func_file', 'n') ) )
196        {
197                $this->_err( $name.': file unmatch' );
198        }
199
200        if ( isset($info['show_func']) && ( $info['show_func'] != $block_obj->getVar('show_func', 'n') ) )
201        {
202                $this->_err( $name.': show_func unmatch' );
203        }
204
205        if ( isset($info['edit_func']) && ( $info['edit_func'] != $block_obj->getVar('edit_func', 'n') ) )
206        {
207                $this->_err( $name.': edit_func unmatch' );
208        }
209
210        if ( isset($info['template']) && ( $info['template'] != $block_obj->getVar('template', 'n') ) )
211        {
212                $this->_err( $name.': template unmatch' );
213        }
214
215        if ( isset($info['options']) )
216        {
217                $option_arr_1 = explode( '|', $info['options'] );
218                $option_arr_2 = explode( '|', $block_obj->getVar('options', 'n') );
219
220                if ( count($option_arr_1) != count($option_arr_2) )
221                {
222                        $this->_err( $name.': options count unmatch' );
223                }
224        }
225
226        if ( !$this->_error_flag )
227        {
228                $this->_msg( $name.': OK' );
229        } else {
230                $this->_all_ok_flag = false;
231        }
232
233}
234
235function _remove_block_bymodule_id( $mid )
236{
237        $error = false;
238        $objs =& $this->_get_block_object_bymodule_id( $mid );
239        foreach ( $objs as $obj )
240        {
241                $ret = $this->_delete_block( $obj );
242                if ( !$ret )
243                {       $error = true;  }
244        }
245        if ( $error )
246        {       return false;   }
247        return true;
248}
249
250function _msg( $msg )
251{
252        $this->_msg_array[] = '&emsp;' .$msg;
253}
254
255function _err( $msg )
256{
257        $this->_msg_array[] = '&emsp;' . $this->_highlight( $msg );
258        $this->_error_flag  = true;
259}
260
261function _get_msg()
262{
263        $msg = implode( "<br />\n", $this->_msg_array );
264        return $msg;
265}
266
267
268function _highlight( $msg )
269{
270        $text = null;
271        if ( $msg )
272        {
273                $text = '<span style="color: #ff0000;">'.$msg.'</span>';
274        }
275        return $text;
276}
277
278function _build_url_module_update( $dirname )
279{
280        if ( $this->_xoops_version == '2.1' ) {
281                $url = XOOPS_URL.'/modules/legacy/admin/index.php?action=ModuleUpdate&dirname='.$dirname;
282        } else {
283                $url = XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&op=update&module='.$dirname;
284        }
285        return $url;
286}
287
288//--------------------------------------------------------
289// user handler
290//--------------------------------------------------------
291function is_admin()
292{
293        global $xoopsUser;
294        if ( is_object($xoopsUser) && $xoopsUser->isAdmin() )
295        {       return true;    }
296        return false;
297}
298
299//--------------------------------------------------------
300// module handler
301//--------------------------------------------------------
302function &_get_module_objects()
303{
304        $criteria = new CriteriaCompo();
305        $criteria->add( new Criteria('isactive', '1', '=') );
306        $criteria->add( new Criteria('dirname', $this->_module_dir, '=') );
307
308        $module_handler =& xoops_gethandler('module');
309        $objs           =& $module_handler->getObjects( $criteria );
310        return $objs;
311}
312
313function &_get_module_object_bymodule_id( $mid )
314{
315        $module_handler =& xoops_gethandler('module');
316        $obj            =& $module_handler->get( $mid );
317        return $obj;
318}
319
320//--------------------------------------------------------
321// block handler
322//--------------------------------------------------------
323function &_get_block_object_orber_num_bymodule_id( $mid )
324{
325        $arr  = array();
326        $objs =& $this->_get_block_object_bymodule_id( $mid );
327        foreach ( $objs as $obj )
328        {
329                $arr[ $obj->getVar('func_num', 'n') ] = $obj;
330        }
331        return $arr;
332}
333
334function &_get_block_object_bymodule_id( $mid, $asobject=true )
335{
336        $objs =& xoopsBlock::getByModule( $mid, $asobject );
337        return $objs;
338}
339
340function _delete_block( &$obj )
341{
342// NOT use xoops_gethandler in xoops 2.0.16jp
343        return $obj->delete();
344}
345
346//--------------------------------------------------------
347// token handler
348//--------------------------------------------------------
349function _create_token()
350{
351        $token_handler =& xoops_gethandler('SingleToken');
352        $obj =& $token_handler->quickCreate( $this->_TOKEN_NAME );
353        return $obj->getHtml();
354}
355
356function _validate_token()
357{
358        $token_handler =& xoops_gethandler('SingleToken');
359        return $token_handler->quickValidate( $this->_TOKEN_NAME );
360}
361
362//--------------------------------------------------------
363// xoops version
364//--------------------------------------------------------
365function get_xoops_version()
366{
367        return $this->_xoops_version;
368}
369
370function _detect_xoops_version()
371{
372// very easy way
373        if ( preg_match("/XOOPS[\s+]Cube.*[\s+]2\.1/i", XOOPS_VERSION) )
374        {
375                $this->_xoops_version = '2.1';
376        }
377
378// xoops 2.0.17 has no token class
379        if ( file_exists( XOOPS_ROOT_PATH.'/class/token.php' ) )
380        {
381                $this->_use_token = true;
382        }
383}
384
385// --- class end ---
386}
387
388?>
Note: See TracBrowser for help on using the repository browser.