Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like MyBlocksAdmin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MyBlocksAdmin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
4 | class MyBlocksAdmin |
||
5 | { |
||
6 | |||
7 | public $db ; |
||
8 | public $lang ; |
||
9 | public $cachetime_options = array() ; |
||
10 | public $ctype_options = array() ; |
||
11 | public $type_options = array() ; |
||
12 | public $target_mid = 0 ; |
||
13 | public $target_dirname = '' ; |
||
14 | public $target_mname = '' ; |
||
15 | public $block_configs = array() ; |
||
16 | public $preview_request = array() ; |
||
17 | |||
18 | public function MyBlocksAadmin() |
||
21 | |||
22 | |||
23 | public function construct() |
||
24 | { |
||
25 | $this->db = XoopsDatabaseFactory::getDatabaseConnection() ; |
||
26 | $this->lang = @$GLOBALS['xoopsConfig']['language'] ; |
||
27 | |||
28 | $this->cachetime_options = array( |
||
29 | 0 => _NOCACHE , |
||
30 | 30 => sprintf(_SECONDS, 30) , |
||
31 | 60 => _MINUTE , |
||
32 | 300 => sprintf(_MINUTES, 5) , |
||
33 | 1800 => sprintf(_MINUTES, 30) , |
||
34 | 3600 => _HOUR , |
||
35 | 18000 => sprintf(_HOURS, 5) , |
||
36 | 86400 => _DAY , |
||
37 | 259200 => sprintf(_DAYS, 3) , |
||
38 | 604800 => _WEEK , |
||
39 | 2592000 => _MONTH |
||
40 | ); |
||
41 | |||
42 | $this->ctype_options = array( |
||
43 | 'H' => _MD_A_MYBLOCKSADMIN_CTYPE_HTML , |
||
44 | 'T' => _MD_A_MYBLOCKSADMIN_CTYPE_NOSMILE , |
||
45 | 'S' => _MD_A_MYBLOCKSADMIN_CTYPE_SMILE , |
||
46 | 'P' => _MD_A_MYBLOCKSADMIN_CTYPE_PHP |
||
47 | ) ; |
||
48 | |||
49 | $this->type_options = array( |
||
50 | 'C' => 'custom block' , |
||
51 | 'E' => 'cloned custom block' , |
||
52 | 'M' => 'module\'s block' , |
||
53 | 'D' => 'cloned module\'s block' , |
||
54 | 'S' => 'system block' |
||
55 | ) ; |
||
56 | } |
||
57 | |||
58 | //HACK by domifara for php5.3+ |
||
59 | //function &getInstance() |
||
60 | public static function &getInstance() |
||
69 | |||
70 | |||
71 | // virtual |
||
72 | public function checkPermission() |
||
73 | { |
||
74 | // only groups have 'module_admin' of 'altsys' can do that. |
||
75 | $module_handler = xoops_gethandler('module') ; |
||
76 | $module =& $module_handler->getByDirname('altsys') ; |
||
77 | $moduleperm_handler = xoops_gethandler('groupperm') ; |
||
78 | View Code Duplication | if (! is_object(@$GLOBALS['xoopsUser']) || ! $moduleperm_handler->checkRight('module_admin', $module->getVar('mid'), $GLOBALS['xoopsUser']->getGroups())) { |
|
79 | die('only admin of altsys can access this area') ; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | |||
84 | public function init($xoopsModule) |
||
85 | { |
||
86 | // altsys "module" MODE |
||
87 | if ($xoopsModule->getVar('dirname') == 'altsys') { |
||
88 | // set target_module if specified by $_GET['dirname'] |
||
89 | $module_handler = xoops_gethandler('module'); |
||
90 | View Code Duplication | if (! empty($_GET['dirname'])) { |
|
91 | $dirname = preg_replace('/[^0-9a-zA-Z_-]/', '', $_GET['dirname']) ; |
||
92 | $target_module =& $module_handler->getByDirname($dirname) ; |
||
93 | } |
||
94 | |||
95 | if (is_object(@$target_module)) { |
||
96 | // module's blocks |
||
97 | $this->target_mid = $target_module->getVar('mid') ; |
||
98 | $this->target_mname = $target_module->getVar('name') . ' ' . sprintf('(%2.2f)', $target_module->getVar('version') / 100.0) ; |
||
99 | $this->target_dirname = $target_module->getVar('dirname') ; |
||
100 | $modinfo = $target_module->getInfo() ; |
||
101 | // breadcrumbs |
||
102 | $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ; |
||
103 | $breadcrumbsObj->appendPath(XOOPS_URL.'/modules/altsys/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin', '_MI_ALTSYS_MENU_MYBLOCKSADMIN') ; |
||
104 | $breadcrumbsObj->appendPath(XOOPS_URL.'/modules/altsys/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin&dirname='.$this->target_dirname, $this->target_mname) ; |
||
105 | } else { |
||
106 | // custom blocks |
||
107 | $this->target_mid = 0 ; |
||
108 | $this->target_mname = _MI_ALTSYS_MENU_CUSTOMBLOCKS ; |
||
109 | $this->target_dirname = '__CustomBlocks__' ; |
||
110 | // breadcrumbs |
||
111 | $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ; |
||
112 | $breadcrumbsObj->appendPath(XOOPS_URL.'/modules/altsys/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin', '_MI_ALTSYS_MENU_MYBLOCKSADMIN') ; |
||
113 | $breadcrumbsObj->appendPath(XOOPS_URL.'/modules/altsys/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin&dirname='.$this->target_dirname, '_MI_ALTSYS_MENU_CUSTOMBLOCKS') ; |
||
114 | } |
||
115 | } else { |
||
116 | // myblocksadmin as a library |
||
117 | $this->target_mid = $xoopsModule->getVar('mid') ; |
||
118 | $this->target_mname = $xoopsModule->getVar('name') . ' ' . sprintf('(%2.2f)', $xoopsModule->getVar('version') / 100.0) ; |
||
119 | $this->target_dirname = $xoopsModule->getVar('dirname') ; |
||
120 | $mod_url = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname') ; |
||
121 | $modinfo = $xoopsModule->getInfo() ; |
||
122 | $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ; |
||
123 | $breadcrumbsObj->appendPath($mod_url.'/'.@$modinfo['adminindex'], $this->target_mname) ; |
||
124 | $breadcrumbsObj->appendPath($mod_url.'/admin/index.php?mode=admin&lib=altsys&page=myblocksadmin', _MD_A_MYBLOCKSADMIN_BLOCKADMIN) ; |
||
125 | } |
||
126 | |||
127 | // read xoops_version.php of the target |
||
128 | $this->block_configs = $this->get_block_configs() ; |
||
129 | } |
||
130 | |||
131 | |||
132 | // virtual |
||
133 | public function canEdit($block) |
||
137 | |||
138 | |||
139 | // virtual |
||
140 | public function canDelete($block) |
||
149 | |||
150 | |||
151 | // virtual |
||
152 | // ret 0 : cannot |
||
153 | // ret 1 : forced by altsys or system |
||
154 | // ret 2 : can_clone |
||
155 | public function canClone($block) |
||
156 | { |
||
157 | // can clone link if it is marked as cloneable block |
||
158 | if ($block->getVar('block_type') == 'D' || $block->getVar('block_type') == 'C') { |
||
159 | return 2 ; |
||
160 | } else { |
||
161 | // $modversion['blocks'][n]['can_clone'] |
||
162 | foreach ($this->block_configs as $bconf) { |
||
163 | if ($block->getVar('show_func') == @$bconf['show_func'] && $block->getVar('func_file') == @$bconf['file'] && (empty($bconf['template']) || $block->getVar('template') == @$bconf['template'])) { |
||
164 | if (! empty($bconf['can_clone'])) { |
||
165 | return 2 ; |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | |||
171 | if (! empty($GLOBALS['altsysModuleConfig']['enable_force_clone'])) { |
||
172 | return 1 ; |
||
173 | } |
||
174 | |||
175 | return 0 ; |
||
176 | } |
||
177 | |||
178 | |||
179 | // virtual |
||
180 | // options |
||
181 | public function renderCell4BlockOptions($block_data) |
||
195 | |||
196 | |||
197 | // virtual |
||
198 | // link blocks - modules |
||
199 | public function renderCell4BlockModuleLink($block_data) |
||
200 | { |
||
201 | $bid = (int)$block_data['bid']; |
||
202 | |||
203 | // get selected targets |
||
204 | if (is_array(@$block_data['bmodule'])) { |
||
205 | // bmodule origined from request (preview etc.) |
||
206 | $selected_mids = $block_data['bmodule'] ; |
||
207 | } else { |
||
208 | // origined from the table of `block_module_link` |
||
209 | $result = $this->db->query('SELECT module_id FROM ' . $this->db->prefix('block_module_link') . " WHERE block_id='$bid'") ; |
||
210 | $selected_mids = array(); |
||
211 | while (list($selected_mid) = $this->db->fetchRow($result)) { |
||
212 | $selected_mids[] = (int)$selected_mid; |
||
213 | } |
||
214 | if (empty($selected_mids)) { |
||
215 | $selected_mids = array( 0 ) ; |
||
216 | } // all pages |
||
217 | } |
||
218 | |||
219 | // get all targets |
||
220 | $module_handler = xoops_gethandler('module'); |
||
221 | $criteria = new CriteriaCompo(new Criteria('hasmain', 1)); |
||
222 | $criteria->add(new Criteria('isactive', 1)); |
||
223 | $module_list = $module_handler->getList($criteria); |
||
224 | $module_list= array( -1 => _MD_A_MYBLOCKSADMIN_TOPPAGE , 0 => _MD_A_MYBLOCKSADMIN_ALLPAGES ) + $module_list ; |
||
225 | |||
226 | // build options |
||
227 | $module_options = '' ; |
||
228 | foreach ($module_list as $mid => $mname) { |
||
229 | $mname = htmlspecialchars($mname) ; |
||
230 | if (in_array($mid, $selected_mids)) { |
||
231 | $module_options .= "<option value='$mid' selected='selected'>$mname</option>\n" ; |
||
232 | } else { |
||
233 | $module_options .= "<option value='$mid'>$mname</option>\n" ; |
||
234 | } |
||
235 | } |
||
236 | |||
237 | $ret = " |
||
238 | <select name='bmodules[$bid][]' size='5' multiple='multiple'> |
||
239 | $module_options |
||
240 | </select>" ; |
||
241 | |||
242 | return $ret ; |
||
243 | } |
||
244 | |||
245 | |||
246 | // virtual |
||
247 | // group_permission - 'block_read' |
||
248 | public function renderCell4BlockReadGroupPerm($block_data) |
||
249 | { |
||
250 | $bid = (int)$block_data['bid']; |
||
251 | |||
252 | // get selected targets |
||
253 | if (is_array(@$block_data['bgroup'])) { |
||
254 | // bgroup origined from request (preview etc.) |
||
255 | $selected_gids = $block_data['bgroup'] ; |
||
256 | } else { |
||
257 | // origined from the table of `group_perm` |
||
258 | $result = $this->db->query('SELECT gperm_groupid FROM ' . $this->db->prefix('group_permission') . " WHERE gperm_itemid='$bid' AND gperm_name='block_read'") ; |
||
259 | $selected_gids = array(); |
||
260 | while (list($selected_gid) = $this->db->fetchRow($result)) { |
||
261 | $selected_gids[] = (int)$selected_gid; |
||
262 | } |
||
263 | if ($bid == 0 && empty($selected_gids)) { |
||
264 | $selected_gids = $GLOBALS['xoopsUser']->getGroups() ; |
||
265 | } |
||
266 | } |
||
267 | |||
268 | // get all targets |
||
269 | $group_handler = xoops_gethandler('group'); |
||
270 | $groups = $group_handler->getObjects() ; |
||
271 | |||
272 | // build options |
||
273 | $group_options = '' ; |
||
274 | foreach ($groups as $group) { |
||
275 | $gid = $group->getVar('groupid') ; |
||
276 | $gname = $group->getVar('name', 's') ; |
||
277 | if (in_array($gid, $selected_gids)) { |
||
278 | $group_options .= "<option value='$gid' selected='selected'>$gname</option>\n" ; |
||
279 | } else { |
||
280 | $group_options .= "<option value='$gid'>$gname</option>\n" ; |
||
281 | } |
||
282 | } |
||
283 | |||
284 | $ret = " |
||
285 | <select name='bgroups[$bid][]' size='5' multiple='multiple'> |
||
286 | $group_options |
||
287 | </select>" ; |
||
288 | |||
289 | return $ret ; |
||
290 | } |
||
291 | |||
292 | |||
293 | // virtual |
||
294 | // visible and side |
||
295 | public function renderCell4BlockPosition($block_data) |
||
296 | { |
||
297 | $bid = (int)$block_data['bid']; |
||
298 | $side = (int)$block_data['side']; |
||
299 | $visible = (int)$block_data['visible']; |
||
300 | |||
301 | $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = ''; |
||
302 | $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = 'unselected'; |
||
303 | $stextbox = 'unselected'; |
||
304 | $value4extra_side = '' ; |
||
305 | |||
306 | if ($visible != 1) { |
||
307 | $sseln = " checked='checked'"; |
||
308 | $scoln = 'disabled'; |
||
309 | } else { |
||
310 | switch ($side) { |
||
311 | case XOOPS_SIDEBLOCK_LEFT : |
||
312 | $ssel0 = " checked='checked'"; |
||
313 | $scol0 = 'selected'; |
||
314 | break ; |
||
315 | case XOOPS_SIDEBLOCK_RIGHT : |
||
316 | $ssel1 = " checked='checked'"; |
||
317 | $scol1 = 'selected'; |
||
318 | break ; |
||
319 | case XOOPS_CENTERBLOCK_LEFT : |
||
320 | $ssel2 = " checked='checked'"; |
||
321 | $scol2 = 'selected'; |
||
322 | break ; |
||
323 | case XOOPS_CENTERBLOCK_RIGHT : |
||
324 | $ssel4 = " checked='checked'"; |
||
325 | $scol4 = 'selected'; |
||
326 | break ; |
||
327 | case XOOPS_CENTERBLOCK_CENTER : |
||
328 | $ssel3 = " checked='checked'"; |
||
329 | $scol3 = 'selected'; |
||
330 | break ; |
||
331 | default : |
||
332 | $value4extra_side = $side ; |
||
333 | $stextbox = 'selected'; |
||
334 | break ; |
||
335 | } |
||
336 | } |
||
337 | |||
338 | return " |
||
339 | <div class='blockposition $scol0'> |
||
340 | <input type='radio' name='sides[$bid]' value='".XOOPS_SIDEBLOCK_LEFT."' class='blockposition' $ssel0 onclick='document.getElementById(\"extra_side_$bid\").value=".XOOPS_SIDEBLOCK_LEFT.";' /> |
||
341 | </div> |
||
342 | <div style='float:"._GLOBAL_LEFT.";'>-</div> |
||
343 | <div class='blockposition $scol2'> |
||
344 | <input type='radio' name='sides[$bid]' value='".XOOPS_CENTERBLOCK_LEFT."' class='blockposition' $ssel2 onclick='document.getElementById(\"extra_side_$bid\").value=".XOOPS_CENTERBLOCK_LEFT.";' /> |
||
345 | </div> |
||
346 | <div class='blockposition $scol3'> |
||
347 | <input type='radio' name='sides[$bid]' value='".XOOPS_CENTERBLOCK_CENTER."' class='blockposition' $ssel3 onclick='document.getElementById(\"extra_side_$bid\").value=".XOOPS_CENTERBLOCK_CENTER.";' /> |
||
348 | </div> |
||
349 | <div class='blockposition $scol4'> |
||
350 | <input type='radio' name='sides[$bid]' value='".XOOPS_CENTERBLOCK_RIGHT."' class='blockposition' $ssel4 onclick='document.getElementById(\"extra_side_$bid\").value=".XOOPS_CENTERBLOCK_RIGHT.";' /> |
||
351 | </div> |
||
352 | <div style='float:"._GLOBAL_LEFT.";'>-</div> |
||
353 | <div class='blockposition $scol1'> |
||
354 | <input type='radio' name='sides[$bid]' value='".XOOPS_SIDEBLOCK_RIGHT."' class='blockposition' $ssel1 onclick='document.getElementById(\"extra_side_$bid\").value=".XOOPS_SIDEBLOCK_RIGHT.";' /> |
||
355 | </div> |
||
356 | <br /> |
||
357 | <br /> |
||
358 | <div style='float:"._GLOBAL_LEFT.";width:50px;' class='$stextbox'> |
||
359 | <input type='text' name='extra_sides[$bid]' value='".$value4extra_side."' style='width:20px;' id='extra_side_$bid' /> |
||
360 | </div> |
||
361 | <div class='blockposition $scoln'> |
||
362 | <input type='radio' name='sides[$bid]' value='-1' class='blockposition' $sseln onclick='document.getElementById(\"extra_side_$bid\").value=-1;' /> |
||
363 | </div> |
||
364 | <div style='float:"._GLOBAL_LEFT.";'>"._NONE . '</div> |
||
365 | '; |
||
366 | } |
||
367 | |||
368 | |||
369 | // public |
||
370 | public function list_blocks() |
||
371 | { |
||
372 | global $xoopsGTicket ; |
||
373 | |||
374 | // main query |
||
375 | $sql = 'SELECT * FROM ' . $this->db->prefix('newblocks') . " WHERE mid='$this->target_mid' ORDER BY visible DESC,side,weight" ; |
||
376 | $result = $this->db->query($sql) ; |
||
377 | $block_arr = array() ; |
||
378 | //HACK by domifara |
||
379 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
380 | $handler = xoops_gethandler('block');//add |
||
381 | } |
||
382 | View Code Duplication | while ($myrow = $this->db->fetchArray($result)) { |
|
383 | |||
384 | //HACK by domifara |
||
385 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
386 | $block_one =& $handler->create(false) ; |
||
387 | $block_one->assignVars($myrow); |
||
388 | $block_arr[] =& $block_one ; |
||
389 | } else { |
||
390 | $block_arr[] = new XoopsBlock($myrow) ; |
||
391 | } |
||
392 | } |
||
393 | if (empty($block_arr)) { |
||
394 | return ; |
||
395 | } |
||
396 | |||
397 | // blocks rendering loop |
||
398 | $blocks4assign = array() ; |
||
399 | foreach ($block_arr as $i => $block) { |
||
400 | $block_data = array( |
||
401 | 'bid' => (int)$block->getVar('bid'), |
||
402 | 'name' => $block->getVar('name', 'n') , |
||
403 | 'title' => $block->getVar('title', 'n') , |
||
404 | 'weight' => (int)$block->getVar('weight'), |
||
405 | 'bcachetime' => (int)$block->getVar('bcachetime'), |
||
406 | 'side' => (int)$block->getVar('side'), |
||
407 | 'visible' => (int)$block->getVar('visible'), |
||
408 | 'can_edit' => $this->canEdit($block) , |
||
409 | 'can_delete' => $this->canDelete($block) , |
||
410 | 'can_clone' => $this->canClone($block) |
||
411 | ) ; |
||
412 | $blocks4assign[] = array( |
||
413 | 'name_raw' => $block_data['name'] , |
||
414 | 'title_raw' => $block_data['title'] , |
||
415 | 'cell_position' => $this->renderCell4BlockPosition($block_data) , |
||
416 | 'cell_module_link' => $this->renderCell4BlockModuleLink($block_data) , |
||
417 | 'cell_group_perm' => $this->renderCell4BlockReadGroupPerm($block_data) |
||
418 | ) + $block_data ; |
||
419 | } |
||
420 | |||
421 | // display |
||
422 | require_once XOOPS_TRUST_PATH.'/libs/altsys/class/D3Tpl.class.php' ; |
||
423 | $tpl = new D3Tpl() ; |
||
424 | $tpl->assign(array( |
||
425 | 'target_mid' => $this->target_mid, |
||
426 | 'target_dirname' => $this->target_dirname, |
||
427 | 'target_mname' => $this->target_mname, |
||
428 | 'language' => $this->lang, |
||
429 | 'cachetime_options' => $this->cachetime_options, |
||
430 | 'blocks' => $blocks4assign, |
||
431 | 'gticket_hidden' => $xoopsGTicket->getTicketHtml(__LINE__, 1800, 'myblocksadmin') |
||
432 | )) ; |
||
433 | $tpl->display('db:altsys_main_myblocksadmin_list.html') ; |
||
434 | } |
||
435 | |||
436 | |||
437 | public function get_block_configs() |
||
450 | |||
451 | |||
452 | public function list_groups() |
||
453 | { |
||
454 | // query for getting blocks |
||
455 | $sql = 'SELECT * FROM ' . $this->db->prefix('newblocks') . " WHERE mid='$this->target_mid' ORDER BY visible DESC,side,weight" ; |
||
456 | $result = $this->db->query($sql) ; |
||
457 | $block_arr = array() ; |
||
458 | //HACK by domifara |
||
459 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
460 | $handler = xoops_gethandler('block');//add |
||
461 | } |
||
462 | View Code Duplication | while ($myrow = $this->db->fetchArray($result)) { |
|
463 | //HACK by domifara |
||
464 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
465 | $block_one =& $handler->create(false) ; |
||
466 | $block_one->assignVars($myrow); |
||
467 | $block_arr[] =& $block_one ; |
||
468 | } else { |
||
469 | $block_arr[] = new XoopsBlock($myrow) ; |
||
470 | } |
||
471 | } |
||
472 | |||
473 | $item_list = array() ; |
||
474 | foreach (array_keys($block_arr) as $i) { |
||
475 | $item_list[ $block_arr[$i]->getVar('bid') ] = $block_arr[$i]->getVar('title') ; |
||
476 | } |
||
477 | |||
478 | $form = new MyXoopsGroupPermForm(_MD_A_MYBLOCKSADMIN_PERMFORM, 1, 'block_read', '') ; |
||
479 | // skip system (TODO) |
||
480 | if ($this->target_mid > 1) { |
||
481 | $form->addAppendix('module_admin', $this->target_mid, $this->target_mname . ' ' . _MD_A_MYBLOCKSADMIN_PERM_MADMIN) ; |
||
482 | $form->addAppendix('module_read', $this->target_mid, $this->target_mname .' ' . _MD_A_MYBLOCKSADMIN_PERM_MREAD) ; |
||
483 | } |
||
484 | foreach ($item_list as $item_id => $item_name) { |
||
485 | $form->addItem($item_id, $item_name) ; |
||
486 | } |
||
487 | echo $form->render() ; |
||
488 | } |
||
489 | |||
490 | |||
491 | public function update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $options=array()) |
||
547 | |||
548 | |||
549 | // virtual |
||
550 | public function updateBlockModuleLink($bid, $bmodules) |
||
551 | { |
||
552 | $bid = (int)$bid; |
||
553 | $table = $this->db->prefix('block_module_link') ; |
||
554 | |||
555 | $sql = "DELETE FROM `$table` WHERE `block_id`=$bid" ; |
||
556 | $this->db->query($sql) ; |
||
557 | foreach ($bmodules as $mid) { |
||
558 | $mid = (int)$mid; |
||
559 | $sql = "INSERT INTO `$table` (`block_id`,`module_id`) VALUES ($bid,$mid)" ; |
||
560 | $this->db->query($sql) ; |
||
561 | } |
||
562 | } |
||
563 | |||
564 | |||
565 | // virtual |
||
566 | public function updateBlockReadGroupPerm($bid, $req_gids) |
||
567 | { |
||
568 | $bid = (int)$bid; |
||
569 | $table = $this->db->prefix('group_permission') ; |
||
570 | $req_gids = array_map('intval', $req_gids) ; |
||
571 | sort($req_gids) ; |
||
572 | |||
573 | // compare group ids from request and the records. |
||
574 | $sql = "SELECT `gperm_groupid` FROM `$table` WHERE gperm_name='block_read' AND `gperm_itemid`=$bid" ; |
||
575 | $result = $this->db->query($sql) ; |
||
576 | $db_gids = array() ; |
||
577 | while (list($gid) = $this->db->fetchRow($result)) { |
||
578 | $db_gids[] = $gid ; |
||
579 | } |
||
580 | $db_gids = array_map('intval', $db_gids) ; |
||
581 | sort($db_gids) ; |
||
582 | |||
583 | // if they are identical, just return (prevent increase of gperm_id) |
||
584 | if (serialize($req_gids) == serialize($db_gids)) { |
||
585 | return ; |
||
586 | } |
||
587 | |||
588 | $sql = "DELETE FROM `$table` WHERE gperm_name='block_read' AND `gperm_itemid`=$bid" ; |
||
589 | $this->db->query($sql) ; |
||
590 | foreach ($req_gids as $gid) { |
||
591 | $gid = (int)$gid; |
||
592 | $sql = "INSERT INTO `$table` (`gperm_groupid`,`gperm_itemid`,`gperm_modid`,`gperm_name`) VALUES ($gid,$bid,1,'block_read')" ; |
||
593 | $this->db->query($sql) ; |
||
594 | } |
||
595 | } |
||
596 | |||
597 | |||
598 | public function do_order() |
||
615 | |||
616 | |||
617 | View Code Duplication | public function fetchRequest4Block($bid) |
|
618 | { |
||
619 | $bid = (int)$bid; |
||
620 | (method_exists('MyTextSanitizer', 'sGetInstance') and $myts =& MyTextSanitizer::sGetInstance()) || $myts = MyTextSanitizer::getInstance() ; |
||
621 | |||
622 | if (@$_POST['extra_sides'][$bid] > 0) { |
||
623 | $_POST['sides'][$bid] = (int)$_POST['extra_sides'][$bid]; |
||
624 | } |
||
625 | |||
626 | if (@$_POST['sides'][$bid] < 0) { |
||
627 | $visible = 0 ; |
||
628 | $_POST['sides'][$bid] = -1 ; |
||
629 | } else { |
||
630 | $visible = 1 ; |
||
631 | } |
||
632 | |||
633 | return array( |
||
634 | 'bid' => $bid , |
||
635 | 'side' => (int)(@$_POST['sides'][$bid]), |
||
636 | 'weight' => (int)(@$_POST['weights'][$bid]), |
||
637 | 'visible' => $visible , |
||
638 | 'title' => $myts->stripSlashesGPC(@$_POST['titles'][$bid]) , |
||
639 | 'content' => $myts->stripSlashesGPC(@$_POST['contents'][$bid]) , |
||
640 | 'ctype' => preg_replace('/[^A-Z]/', '', @$_POST['ctypes'][$bid]) , |
||
641 | 'bcachetime' => (int)(@$_POST['bcachetimes'][$bid]), |
||
642 | 'bmodule' => is_array(@$_POST['bmodules'][$bid]) ? $_POST['bmodules'][$bid] : array( 0 ) , |
||
643 | 'bgroup' => is_array(@$_POST['bgroups'][$bid]) ? $_POST['bgroups'][$bid] : array() , |
||
644 | 'options' => is_array(@$_POST['options'][$bid]) ? $_POST['options'][$bid] : array() |
||
645 | ) ; |
||
646 | } |
||
647 | |||
648 | |||
649 | public function do_delete($bid) |
||
672 | |||
673 | //HACK add by domifara |
||
674 | public function do_deleteBlockReadGroupPerm($bid) |
||
681 | |||
682 | public function form_delete($bid) |
||
709 | |||
710 | |||
711 | public function do_clone($bid) |
||
775 | |||
776 | |||
777 | public function find_func_num_vacancy($mid) |
||
787 | |||
788 | |||
789 | public function do_edit($bid) |
||
830 | |||
831 | |||
832 | public function form_edit($bid, $mode = 'edit') |
||
833 | { |
||
834 | $bid = (int)$bid; |
||
835 | |||
836 | //HACK by domifara |
||
837 | View Code Duplication | if (defined('XOOPS_CUBE_LEGACY')) { |
|
838 | $handler = xoops_gethandler('block'); |
||
839 | $block =& $handler->create(false) ; |
||
840 | $block->load($bid) ; |
||
841 | } else { |
||
842 | $block = new XoopsBlock($bid) ; |
||
843 | } |
||
844 | |||
845 | View Code Duplication | if (! $block->getVar('bid')) { |
|
846 | // new defaults |
||
847 | $bid = 0 ; |
||
848 | $mode = 'new' ; |
||
849 | $block->setVar('mid', 0) ; |
||
850 | $block->setVar('block_type', 'C') ; |
||
851 | } |
||
852 | |||
853 | View Code Duplication | switch ($mode) { |
|
854 | case 'clone' : |
||
855 | $form_title = _MD_A_MYBLOCKSADMIN_CLONEFORM ; |
||
856 | $button_value = _MD_A_MYBLOCKSADMIN_BTN_CLONE ; |
||
857 | $next_op = 'clone_ok' ; |
||
858 | // breadcrumbs |
||
859 | $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ; |
||
860 | $breadcrumbsObj->appendPath('', _MD_A_MYBLOCKSADMIN_CLONEFORM) ; |
||
861 | break ; |
||
862 | case 'new' : |
||
863 | $form_title = _MD_A_MYBLOCKSADMIN_NEWFORM ; |
||
864 | $button_value = _MD_A_MYBLOCKSADMIN_BTN_NEW ; |
||
865 | $next_op = 'new_ok' ; |
||
866 | // breadcrumbs |
||
867 | $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ; |
||
868 | $breadcrumbsObj->appendPath('', _MD_A_MYBLOCKSADMIN_NEWFORM) ; |
||
869 | break ; |
||
870 | case 'edit' : |
||
871 | default : |
||
872 | $form_title = _MD_A_MYBLOCKSADMIN_EDITFORM ; |
||
873 | $button_value = _MD_A_MYBLOCKSADMIN_BTN_EDIT ; |
||
874 | $next_op = 'edit_ok' ; |
||
875 | // breadcrumbs |
||
876 | $breadcrumbsObj =& AltsysBreadcrumbs::getInstance() ; |
||
877 | $breadcrumbsObj->appendPath('', _MD_A_MYBLOCKSADMIN_EDITFORM) ; |
||
878 | break ; |
||
879 | } |
||
880 | |||
881 | $is_custom = in_array($block->getVar('block_type'), array( 'C', 'E' )) ? true : false ; |
||
882 | $block_template =& $block->getVar('template', 'n') ; |
||
883 | $block_template_tplset = '' ; |
||
884 | |||
885 | View Code Duplication | if (! $is_custom && $block_template) { |
|
886 | // find template of the block |
||
887 | $tplfile_handler = xoops_gethandler('tplfile'); |
||
888 | $found_templates = $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', null, null, $block_template) ; |
||
889 | $block_template_tplset = count($found_templates) > 0 ? $GLOBALS['xoopsConfig']['template_set'] : 'default' ; |
||
890 | } |
||
891 | //HACK by domifara |
||
892 | /* |
||
893 | if ( !($block->getVar('c_type')) ){ |
||
894 | $block->setVar('c_type','S'); |
||
895 | } |
||
896 | */ |
||
897 | $block_data = $this->preview_request + array( |
||
898 | 'bid' => $bid , |
||
899 | 'name' => $block->getVar('name', 'n') , |
||
900 | 'title' => $block->getVar('title', 'n') , |
||
901 | 'weight' => (int)$block->getVar('weight'), |
||
902 | 'bcachetime' => (int)$block->getVar('bcachetime'), |
||
903 | 'side' => (int)$block->getVar('side'), |
||
904 | 'visible' => (int)$block->getVar('visible'), |
||
905 | 'template' => $block_template , |
||
906 | 'template_tplset' => $block_template_tplset , |
||
907 | 'options' => $block->getVar('options') , |
||
908 | 'content' => $block->getVar('content', 'n') , |
||
909 | 'is_custom' => $is_custom , |
||
910 | 'type' => $block->getVar('block_type') , |
||
911 | 'ctype' => $block->getVar('c_type') |
||
912 | ) ; |
||
913 | |||
914 | $block4assign = array( |
||
915 | 'name_raw' => $block_data['name'] , |
||
916 | 'title_raw' => $block_data['title'] , |
||
917 | 'content_raw' => $block_data['content'] , |
||
918 | 'cell_position' => $this->renderCell4BlockPosition($block_data) , |
||
919 | 'cell_module_link' => $this->renderCell4BlockModuleLink($block_data) , |
||
920 | 'cell_group_perm' => $this->renderCell4BlockReadGroupPerm($block_data) , |
||
921 | 'cell_options' => $this->renderCell4BlockOptions($block_data) , |
||
922 | 'content_preview' => $this->previewContent($block_data) |
||
923 | ) + $block_data ; |
||
924 | |||
925 | // display |
||
926 | require_once XOOPS_TRUST_PATH.'/libs/altsys/class/D3Tpl.class.php' ; |
||
927 | $tpl = new D3Tpl() ; |
||
928 | |||
929 | //HACK by domifara |
||
930 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
931 | $tpl->assign('xoops_cube_legacy', true) ; |
||
932 | include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
||
933 | } else { |
||
934 | $tpl->assign('xoops_cube_legacy', false) ; |
||
935 | } |
||
936 | |||
937 | $tpl->assign(array( |
||
938 | 'target_dirname' => $this->target_dirname, |
||
939 | 'target_mname' => $this->target_mname, |
||
940 | 'language' => $this->lang, |
||
941 | 'cachetime_options' => $this->cachetime_options, |
||
942 | 'ctype_options' => $this->ctype_options, |
||
943 | 'block' => $block4assign, |
||
944 | 'op' => $next_op, |
||
945 | 'form_title' => $form_title, |
||
946 | 'submit_button' => $button_value, |
||
947 | 'common_fck_installed' => $this->checkFck(), |
||
948 | 'gticket_hidden' => $GLOBALS['xoopsGTicket']->getTicketHtml(__LINE__, 1800, 'myblocksadmin') |
||
949 | )) ; |
||
950 | |||
951 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
952 | $tpl->display('db:altsys_main_myblocksadmin_edit_4legacy.html') ; |
||
953 | } else { |
||
954 | $tpl->display('db:altsys_main_myblocksadmin_edit.html') ; |
||
955 | } |
||
956 | return ; |
||
957 | } |
||
958 | |||
959 | public function checkFck() |
||
963 | |||
964 | public function previewContent($block_data) |
||
998 | |||
999 | |||
1000 | public function get_blockname_from_ctype($bctype) |
||
1011 | |||
1012 | |||
1013 | public function processPost() |
||
1048 | |||
1049 | |||
1050 | public function processGet() |
||
1073 | } |
||
1074 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.