XPressME Integration Kit

Trac

source: branches/Ver2.0/xpressme_integration_kit/class/check_blocks_class.php @ 301

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

ブロックチェック時のオプション数エラーバグ修正 fixes #162
最近の投稿、最近の投稿内容、最近のコメント、人気投稿、ウィジェットなどのブロックはオプション数チェック対象から外す

File size: 9.9 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                $excludes_block = array('widget_block.php','popular_posts_block.php','recent_comments_block.php','recent_posts_content_block.php','recent_posts_list_block.php');
221               
222                if (in_array($info['file'],$excludes_block)){
223                        if ( count($option_arr_1) > count($option_arr_2) )
224                        {
225                                $this->_err( $name.': options count unmatch' );
226                        }
227
228                } else {
229                        if ( count($option_arr_1) != count($option_arr_2) )
230                        {
231                                $this->_err( $name.': options count unmatch' );
232                        }
233                }
234        }
235
236        if ( !$this->_error_flag )
237        {
238                $this->_msg( $name.': OK' );
239        } else {
240                $this->_all_ok_flag = false;
241        }
242
243}
244
245function _remove_block_bymodule_id( $mid )
246{
247        $error = false;
248        $objs =& $this->_get_block_object_bymodule_id( $mid );
249        foreach ( $objs as $obj )
250        {
251                $ret = $this->_delete_block( $obj );
252                if ( !$ret )
253                {       $error = true;  }
254        }
255        if ( $error )
256        {       return false;   }
257        return true;
258}
259
260function _msg( $msg )
261{
262        $this->_msg_array[] = '&emsp;' .$msg;
263}
264
265function _err( $msg )
266{
267        $this->_msg_array[] = '&emsp;' . $this->_highlight( $msg );
268        $this->_error_flag  = true;
269}
270
271function _get_msg()
272{
273        $msg = implode( "<br />\n", $this->_msg_array );
274        return $msg;
275}
276
277
278function _highlight( $msg )
279{
280        $text = null;
281        if ( $msg )
282        {
283                $text = '<span style="color: #ff0000;">'.$msg.'</span>';
284        }
285        return $text;
286}
287
288function _build_url_module_update( $dirname )
289{
290        if ( $this->_xoops_version == '2.1' ) {
291                $url = XOOPS_URL.'/modules/legacy/admin/index.php?action=ModuleUpdate&dirname='.$dirname;
292        } else {
293                $url = XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&op=update&module='.$dirname;
294        }
295        return $url;
296}
297
298//--------------------------------------------------------
299// user handler
300//--------------------------------------------------------
301function is_admin()
302{
303        global $xoopsUser;
304        if ( is_object($xoopsUser) && $xoopsUser->isAdmin() )
305        {       return true;    }
306        return false;
307}
308
309//--------------------------------------------------------
310// module handler
311//--------------------------------------------------------
312function &_get_module_objects()
313{
314        $criteria = new CriteriaCompo();
315        $criteria->add( new Criteria('isactive', '1', '=') );
316        $criteria->add( new Criteria('dirname', $this->_module_dir, '=') );
317
318        $module_handler =& xoops_gethandler('module');
319        $objs           =& $module_handler->getObjects( $criteria );
320        return $objs;
321}
322
323function &_get_module_object_bymodule_id( $mid )
324{
325        $module_handler =& xoops_gethandler('module');
326        $obj            =& $module_handler->get( $mid );
327        return $obj;
328}
329
330//--------------------------------------------------------
331// block handler
332//--------------------------------------------------------
333function &_get_block_object_orber_num_bymodule_id( $mid )
334{
335        $arr  = array();
336        $objs =& $this->_get_block_object_bymodule_id( $mid );
337        foreach ( $objs as $obj )
338        {
339                $arr[ $obj->getVar('func_num', 'n') ] = $obj;
340        }
341        return $arr;
342}
343
344function &_get_block_object_bymodule_id( $mid, $asobject=true )
345{
346        $objs =& xoopsBlock::getByModule( $mid, $asobject );
347        return $objs;
348}
349
350function _delete_block( &$obj )
351{
352// NOT use xoops_gethandler in xoops 2.0.16jp
353        return $obj->delete();
354}
355
356//--------------------------------------------------------
357// token handler
358//--------------------------------------------------------
359function _create_token()
360{
361        $token_handler =& xoops_gethandler('SingleToken');
362        $obj =& $token_handler->quickCreate( $this->_TOKEN_NAME );
363        return $obj->getHtml();
364}
365
366function _validate_token()
367{
368        $token_handler =& xoops_gethandler('SingleToken');
369        return $token_handler->quickValidate( $this->_TOKEN_NAME );
370}
371
372//--------------------------------------------------------
373// xoops version
374//--------------------------------------------------------
375function get_xoops_version()
376{
377        return $this->_xoops_version;
378}
379
380function _detect_xoops_version()
381{
382// very easy way
383        if ( preg_match("/XOOPS[\s+]Cube.*[\s+]2\.1/i", XOOPS_VERSION) )
384        {
385                $this->_xoops_version = '2.1';
386        }
387
388// xoops 2.0.17 has no token class
389        if ( file_exists( XOOPS_ROOT_PATH.'/class/token.php' ) )
390        {
391                $this->_use_token = true;
392        }
393}
394
395// --- class end ---
396}
397
398?>
Note: See TracBrowser for help on using the repository browser.