XOOPS Cube Legacy base repository
Revision | cbb9194336a57e133f6f049874286708186e2586 (tree) |
---|---|
Zeit | 2011-11-10 01:27:55 |
Autor | nbuy <nbuy@704c...> |
Commiter | nbuy |
optimize XoopsObject->getVar() access for speedup
git-svn-id: https://xoopscube.svn.sourceforge.net/svnroot/xoopscube/Package_Legacy/trunk@1042 704cf05f-ae62-4b0e-a484-234ee0250e75
@@ -169,19 +169,19 @@ class XoopsBlock extends XoopsObject | ||
169 | 169 | |
170 | 170 | $block = array(); |
171 | 171 | // M for module block, S for system block C for Custom |
172 | - if ( $this->getVar('block_type') != 'C' ) { | |
172 | + if ( $this->getVar('block_type', 'N') != 'C' ) { | |
173 | 173 | // get block display function |
174 | - $show_func = $this->getVar('show_func'); | |
174 | + $show_func = $this->getVar('show_func', 'N'); | |
175 | 175 | if ( !$show_func ) { |
176 | 176 | return $ret; |
177 | 177 | } |
178 | 178 | // must get lang files b4 execution of the function |
179 | - if ( file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file')) ) { | |
179 | + if ( file_exists($path = XOOPS_ROOT_PATH.'/modules/'.($dirname = $this->getVar('dirname', 'N')).'/blocks/'.$this->getVar('func_file', 'N')) ) { | |
180 | 180 | $root=&XCube_Root::getSingleton(); |
181 | - $root->mLanguageManager->loadBlockMessageCatalog($this->getVar('dirname')); | |
181 | + $root->mLanguageManager->loadBlockMessageCatalog($dirname); | |
182 | 182 | |
183 | - require_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file'); | |
184 | - $options = explode('|', $this->getVar('options')); | |
183 | + require_once $path; | |
184 | + $options = explode('|', $this->getVar('options', 'N')); | |
185 | 185 | if ( function_exists($show_func) ) { |
186 | 186 | // execute the function |
187 | 187 | $block = $show_func($options); |
@@ -196,7 +196,7 @@ class XoopsBlock extends XoopsObject | ||
196 | 196 | } |
197 | 197 | } else { |
198 | 198 | // it is a custom block, so just return the contents |
199 | - $block['content'] = $this->getContent('S',$this->getVar('c_type')); | |
199 | + $block['content'] = $this->getContent('S',$this->getVar('c_type', 'N')); | |
200 | 200 | if (empty($block['content'])) { |
201 | 201 | return $ret; |
202 | 202 | } |
@@ -233,7 +233,7 @@ class XoopsBlock extends XoopsObject | ||
233 | 233 | |
234 | 234 | function isCustom() |
235 | 235 | { |
236 | - if ( $this->getVar('block_type') == 'C' ) { | |
236 | + if ( $this->getVar('block_type','N') == 'C' ) { | |
237 | 237 | return true; |
238 | 238 | } |
239 | 239 | return false; |
@@ -246,17 +246,17 @@ class XoopsBlock extends XoopsObject | ||
246 | 246 | **/ |
247 | 247 | function getOptions() |
248 | 248 | { |
249 | - if ($this->getVar('block_type') != 'C') { | |
250 | - $edit_func = $this->getVar('edit_func'); | |
249 | + if ($this->getVar('block_type', 'N') != 'C') { | |
250 | + $edit_func = $this->getVar('edit_func', 'N'); | |
251 | 251 | if (!$edit_func) { |
252 | 252 | return false; |
253 | 253 | } |
254 | - if (file_exists(XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file'))) { | |
254 | + if (file_exists($path = XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname', 'N').'/blocks/'.$this->getVar('func_file', 'N'))) { | |
255 | 255 | $root =& XCube_Root::getSingleton(); |
256 | 256 | $root->mLanguageManager->loadBlockMessageCatalog($this->getVar('dirname')); |
257 | 257 | |
258 | - include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file'); | |
259 | - $options = explode('|', $this->getVar('options')); | |
258 | + include_once $path; | |
259 | + $options = explode('|', $this->getVar('options', 'N')); | |
260 | 260 | $edit_form = $edit_func($options); |
261 | 261 | if (!$edit_form) { |
262 | 262 | return false; |
@@ -287,7 +287,7 @@ class XoopsBlock extends XoopsObject | ||
287 | 287 | { |
288 | 288 | $handler =& xoops_gethandler('block'); |
289 | 289 | if($handler->insert($this)) { |
290 | - return $this->getVar('bid'); | |
290 | + return $this->getVar('bid', 'N'); | |
291 | 291 | |
292 | 292 | } else { |
293 | 293 | return false; |
@@ -492,7 +492,7 @@ class XoopsBlockHandler extends XoopsObjectHandler | ||
492 | 492 | if (strtolower(get_class($block)) != 'xoopsblock') { |
493 | 493 | return false; |
494 | 494 | } |
495 | - $id = $block->getVar('bid'); | |
495 | + $id = $block->getVar('bid', 'N'); | |
496 | 496 | $sql = sprintf("DELETE FROM %s WHERE bid = %u", $this->db->prefix('newblocks'), $id); |
497 | 497 | if (!$result = $this->db->query($sql)) { |
498 | 498 | return false; |
@@ -574,7 +574,7 @@ class XoopsBlockHandler extends XoopsObjectHandler | ||
574 | 574 | $blocks =& $this->getObjects($criteria, true); |
575 | 575 | $ret = array(); |
576 | 576 | foreach (array_keys($blocks) as $i) { |
577 | - $name = ($blocks[$i]->getVar('block_type') != 'C') ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title'); | |
577 | + $name = ($blocks[$i]->getVar('block_type', 'N') != 'C') ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title'); | |
578 | 578 | $ret[$i] = $name; |
579 | 579 | } |
580 | 580 | return $ret; |
@@ -670,8 +670,8 @@ class XoopsBlockHandler extends XoopsObjectHandler | ||
670 | 670 | } |
671 | 671 | $where_query .= " ORDER BY ".addslashes($orderby); |
672 | 672 | switch ($rettype) { |
673 | - case "object": | |
674 | - $sql = "SELECT * FROM ".$this->db->prefix("newblocks")."".$where_query; | |
673 | + case 'object': | |
674 | + $sql = 'SELECT * FROM '.$this->db->prefix('newblocks').$where_query; | |
675 | 675 | $result = $this->db->query($sql); |
676 | 676 | while ( $myrow = $this->db->fetchArray($result) ) { |
677 | 677 | $block =& $this->create(false); |
@@ -679,19 +679,19 @@ class XoopsBlockHandler extends XoopsObjectHandler | ||
679 | 679 | $ret[] =& $block; |
680 | 680 | } |
681 | 681 | break; |
682 | - case "list": | |
683 | - $sql = "SELECT * FROM ".$this->db->prefix("newblocks")."".$where_query; | |
682 | + case 'list': | |
683 | + $sql = 'SELECT * FROM '.$this->db->prefix('newblocks').$where_query; | |
684 | 684 | $result = $this->db->query($sql); |
685 | 685 | while ( $myrow = $this->db->fetchArray($result) ) { |
686 | 686 | $block =& $this->create(false); |
687 | 687 | $block->assignVars($myrow); |
688 | - $name = ($block->getVar("block_type") != "C") ? $block->getVar("name") : $block->getVar("title"); | |
689 | - $ret[$block->getVar("bid")] = $name; | |
688 | + $name = ($block->getVar('block_type', 'N') != 'C') ? $block->getVar('name') : $block->getVar('title'); | |
689 | + $ret[$block->getVar('bid', 'N')] = $name; | |
690 | 690 | unset($block); |
691 | 691 | } |
692 | 692 | break; |
693 | - case "id": | |
694 | - $sql = "SELECT bid FROM ".$this->db->prefix("newblocks")."".$where_query; | |
693 | + case 'id': | |
694 | + $sql = 'SELECT bid FROM '.$this->db->prefix('newblocks').$where_query; | |
695 | 695 | $result = $this->db->query($sql); |
696 | 696 | while ( $myrow = $this->db->fetchArray($result) ) { |
697 | 697 | $ret[] = $myrow['bid']; |
@@ -706,9 +706,9 @@ class XoopsBlockHandler extends XoopsObjectHandler | ||
706 | 706 | { |
707 | 707 | $moduleid = (int)$moduleid; |
708 | 708 | if ( $asobject == true ) { |
709 | - $sql = $sql = "SELECT * FROM ".$this->db->prefix("newblocks")." WHERE mid=".$moduleid.""; | |
709 | + $sql = $sql = 'SELECT * FROM '.$this->db->prefix('newblocks').' WHERE mid='.$moduleid; | |
710 | 710 | } else { |
711 | - $sql = "SELECT bid FROM ".$this->db->prefix("newblocks")." WHERE mid=".$moduleid.""; | |
711 | + $sql = 'SELECT bid FROM '.$this->db->prefix('newblocks').' WHERE mid='.$moduleid; | |
712 | 712 | } |
713 | 713 | $result = $this->db->query($sql); |
714 | 714 | $ret = array(); |
@@ -112,8 +112,6 @@ class XoopsConfigItem extends XoopsObject | ||
112 | 112 | */ |
113 | 113 | function &getOptionItems() |
114 | 114 | { |
115 | - $optionArr = array(); | |
116 | - | |
117 | 115 | $handler =& xoops_gethandler('config'); |
118 | 116 | $optionArr =& $handler->getConfigOptions(new Criteria('conf_id', $this->get('conf_id'))); |
119 | 117 |
@@ -146,25 +144,23 @@ class XoopsConfigItem extends XoopsObject | ||
146 | 144 | */ |
147 | 145 | function &getConfValueForOutput() |
148 | 146 | { |
149 | - $ret = null; | |
150 | - switch ($this->getVar('conf_valuetype')) { | |
147 | + switch ($this->getVar('conf_valuetype', 'N')) { | |
151 | 148 | case 'int': |
152 | 149 | $ret = (int)$this->getVar('conf_value', 'N'); |
153 | - break; | |
150 | + return $ret; | |
154 | 151 | case 'array': |
155 | 152 | $ret = unserialize($this->getVar('conf_value', 'N')); |
156 | - break; | |
153 | + return $ret; | |
157 | 154 | case 'float': |
158 | 155 | $ret = (float)$this->getVar('conf_value', 'N'); |
159 | - break; | |
156 | + return $ret; | |
160 | 157 | case 'textarea': |
161 | - $ret = $this->getVar('conf_value'); | |
162 | - break; | |
158 | + return $this->getVar('conf_value'); | |
163 | 159 | default: |
164 | - $ret = $this->getVar('conf_value', 'N'); | |
165 | - break; | |
160 | + return $this->getVar('conf_value', 'N'); | |
166 | 161 | } |
167 | 162 | |
163 | + $ret = null; | |
168 | 164 | return $ret; |
169 | 165 | } |
170 | 166 |
@@ -343,21 +343,16 @@ class XoopsObject extends AbstractXoopsObject | ||
343 | 343 | case 'e': |
344 | 344 | case 'edit': |
345 | 345 | $ts =& MyTextSanitizer::getInstance(); |
346 | - $ret = $ts->htmlSpecialChars($ret); | |
347 | - break 1; | |
346 | + return $ts->htmlSpecialChars($ret); | |
348 | 347 | case 'p': |
349 | 348 | case 'preview': |
350 | 349 | case 'f': |
351 | 350 | case 'formpreview': |
352 | 351 | $ts =& MyTextSanitizer::getInstance(); |
353 | - $ret = $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); | |
354 | - break 1; | |
355 | - case 'n': | |
356 | - case 'none': | |
352 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); | |
357 | 353 | default: |
358 | - break 1; | |
354 | + return $ret; | |
359 | 355 | } |
360 | - break; | |
361 | 356 | case XOBJ_DTYPE_TXTAREA: |
362 | 357 | switch (strtolower($format)) { |
363 | 358 | case 's': |
@@ -369,12 +364,11 @@ class XoopsObject extends AbstractXoopsObject | ||
369 | 364 | $smiley = (!isset($vars['dosmiley']['value']) || $vars['dosmiley']['value'] == 1) ? 1 : 0; |
370 | 365 | $image = (!isset($vars['doimage']['value']) || $vars['doimage']['value'] == 1) ? 1 : 0; |
371 | 366 | $br = (!isset($vars['dobr']['value']) || $vars['dobr']['value'] == 1) ? 1 : 0; |
372 | - $ret = $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); | |
373 | - break 1; | |
367 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); | |
374 | 368 | case 'e': |
375 | 369 | case 'edit': |
376 | 370 | $ret = htmlspecialchars($ret, ENT_QUOTES); |
377 | - break 1; | |
371 | + return $ret; | |
378 | 372 | case 'p': |
379 | 373 | case 'preview': |
380 | 374 | $ts =& MyTextSanitizer::getInstance(); |
@@ -384,47 +378,33 @@ class XoopsObject extends AbstractXoopsObject | ||
384 | 378 | $smiley = (!isset($vars['dosmiley']['value']) || $vars['dosmiley']['value'] == 1) ? 1 : 0; |
385 | 379 | $image = (!isset($vars['doimage']['value']) || $vars['doimage']['value'] == 1) ? 1 : 0; |
386 | 380 | $br = (!isset($vars['dobr']['value']) || $vars['dobr']['value'] == 1) ? 1 : 0; |
387 | - $ret = $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); | |
388 | - break 1; | |
381 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); | |
389 | 382 | case 'f': |
390 | 383 | case 'formpreview': |
391 | 384 | $ts =& MyTextSanitizer::getInstance(); |
392 | - $ret = htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); | |
393 | - break 1; | |
394 | - case 'n': | |
395 | - case 'none': | |
385 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); | |
396 | 386 | default: |
397 | - break 1; | |
387 | + return $ret; | |
398 | 388 | } |
399 | - break; | |
400 | 389 | case XOBJ_DTYPE_ARRAY: |
401 | - $ret = unserialize($ret); | |
402 | - break; | |
390 | + return unserialize($ret); | |
403 | 391 | case XOBJ_DTYPE_SOURCE: |
404 | 392 | switch (strtolower($format)) { |
405 | - case 's': | |
406 | - case 'show': | |
407 | - break 1; | |
408 | 393 | case 'e': |
409 | 394 | case 'edit': |
410 | - $ret = htmlspecialchars($ret, ENT_QUOTES); | |
411 | - break 1; | |
395 | + return htmlspecialchars($ret, ENT_QUOTES); | |
412 | 396 | case 'p': |
413 | 397 | case 'preview': |
414 | 398 | $ts =& MyTextSanitizer::getInstance(); |
415 | - $ret = $ts->stripSlashesGPC($ret); | |
416 | - break 1; | |
399 | + return $ts->stripSlashesGPC($ret); | |
417 | 400 | case 'f': |
418 | 401 | case 'formpreview': |
419 | 402 | $ts =& MyTextSanitizer::getInstance(); |
420 | 403 | $ret = htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
421 | - break 1; | |
422 | - case 'n': | |
423 | - case 'none': | |
404 | + return $ret; | |
424 | 405 | default: |
425 | - break 1; | |
406 | + return $ret; | |
426 | 407 | } |
427 | - break; | |
428 | 408 | default: |
429 | 409 | if ($var['options'] != '' && $ret != '') { |
430 | 410 | switch (strtolower($format)) { |
@@ -440,13 +420,12 @@ class XoopsObject extends AbstractXoopsObject | ||
440 | 420 | } |
441 | 421 | $i++; |
442 | 422 | } |
443 | - $ret = implode(', ', $ret); | |
423 | + return implode(', ', $ret); | |
444 | 424 | case 'e': |
445 | 425 | case 'edit': |
446 | - $ret = explode('|', $ret); | |
447 | - break 1; | |
426 | + return explode('|', $ret); | |
448 | 427 | default: |
449 | - break 1; | |
428 | + return $ret; | |
450 | 429 | } |
451 | 430 | |
452 | 431 | } |
@@ -518,8 +497,8 @@ class XoopsObject extends AbstractXoopsObject | ||
518 | 497 | $this->setErrors("$k is required."); |
519 | 498 | continue; |
520 | 499 | } |
521 | - if (isset($v['maxlength']) && strlen($cleanv) > intval($v['maxlength'])) { | |
522 | - $this->setErrors("$k must be shorter than ".intval($v['maxlength'])." characters."); | |
500 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { | |
501 | + $this->setErrors("$k must be shorter than ".(int)$v['maxlength']." characters."); | |
523 | 502 | continue; |
524 | 503 | } |
525 | 504 | if (!$v['not_gpc']) { |
@@ -548,11 +527,11 @@ class XoopsObject extends AbstractXoopsObject | ||
548 | 527 | break; |
549 | 528 | |
550 | 529 | case XOBJ_DTYPE_INT: |
551 | - $cleanv = intval($cleanv); | |
530 | + $cleanv = (int)$cleanv; | |
552 | 531 | break; |
553 | 532 | |
554 | 533 | case XOBJ_DTYPE_FLOAT: |
555 | - $cleanv = floatval($cleanv); | |
534 | + $cleanv = (float)$cleanv; | |
556 | 535 | break; |
557 | 536 | |
558 | 537 | case XOBJ_DTYPE_BOOL: |
@@ -590,7 +569,7 @@ class XoopsObject extends AbstractXoopsObject | ||
590 | 569 | case XOBJ_DTYPE_STIME: |
591 | 570 | case XOBJ_DTYPE_MTIME: |
592 | 571 | case XOBJ_DTYPE_LTIME: |
593 | - $cleanv = !is_string($cleanv) ? intval($cleanv) : strtotime($cleanv); | |
572 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); | |
594 | 573 | break; |
595 | 574 | default: |
596 | 575 | break; |