• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

XOOPS Cube Legacy base repository


Commit MetaInfo

Revisioncbb9194336a57e133f6f049874286708186e2586 (tree)
Zeit2011-11-10 01:27:55
Autornbuy <nbuy@704c...>
Commiternbuy

Log Message

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

Ändern Zusammenfassung

Diff

--- a/html/kernel/block.php
+++ b/html/kernel/block.php
@@ -169,19 +169,19 @@ class XoopsBlock extends XoopsObject
169169
170170 $block = array();
171171 // 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' ) {
173173 // get block display function
174- $show_func = $this->getVar('show_func');
174+ $show_func = $this->getVar('show_func', 'N');
175175 if ( !$show_func ) {
176176 return $ret;
177177 }
178178 // 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')) ) {
180180 $root=&XCube_Root::getSingleton();
181- $root->mLanguageManager->loadBlockMessageCatalog($this->getVar('dirname'));
181+ $root->mLanguageManager->loadBlockMessageCatalog($dirname);
182182
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'));
185185 if ( function_exists($show_func) ) {
186186 // execute the function
187187 $block = $show_func($options);
@@ -196,7 +196,7 @@ class XoopsBlock extends XoopsObject
196196 }
197197 } else {
198198 // 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'));
200200 if (empty($block['content'])) {
201201 return $ret;
202202 }
@@ -233,7 +233,7 @@ class XoopsBlock extends XoopsObject
233233
234234 function isCustom()
235235 {
236- if ( $this->getVar('block_type') == 'C' ) {
236+ if ( $this->getVar('block_type','N') == 'C' ) {
237237 return true;
238238 }
239239 return false;
@@ -246,17 +246,17 @@ class XoopsBlock extends XoopsObject
246246 **/
247247 function getOptions()
248248 {
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');
251251 if (!$edit_func) {
252252 return false;
253253 }
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'))) {
255255 $root =& XCube_Root::getSingleton();
256256 $root->mLanguageManager->loadBlockMessageCatalog($this->getVar('dirname'));
257257
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'));
260260 $edit_form = $edit_func($options);
261261 if (!$edit_form) {
262262 return false;
@@ -287,7 +287,7 @@ class XoopsBlock extends XoopsObject
287287 {
288288 $handler =& xoops_gethandler('block');
289289 if($handler->insert($this)) {
290- return $this->getVar('bid');
290+ return $this->getVar('bid', 'N');
291291
292292 } else {
293293 return false;
@@ -492,7 +492,7 @@ class XoopsBlockHandler extends XoopsObjectHandler
492492 if (strtolower(get_class($block)) != 'xoopsblock') {
493493 return false;
494494 }
495- $id = $block->getVar('bid');
495+ $id = $block->getVar('bid', 'N');
496496 $sql = sprintf("DELETE FROM %s WHERE bid = %u", $this->db->prefix('newblocks'), $id);
497497 if (!$result = $this->db->query($sql)) {
498498 return false;
@@ -574,7 +574,7 @@ class XoopsBlockHandler extends XoopsObjectHandler
574574 $blocks =& $this->getObjects($criteria, true);
575575 $ret = array();
576576 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');
578578 $ret[$i] = $name;
579579 }
580580 return $ret;
@@ -670,8 +670,8 @@ class XoopsBlockHandler extends XoopsObjectHandler
670670 }
671671 $where_query .= " ORDER BY ".addslashes($orderby);
672672 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;
675675 $result = $this->db->query($sql);
676676 while ( $myrow = $this->db->fetchArray($result) ) {
677677 $block =& $this->create(false);
@@ -679,19 +679,19 @@ class XoopsBlockHandler extends XoopsObjectHandler
679679 $ret[] =& $block;
680680 }
681681 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;
684684 $result = $this->db->query($sql);
685685 while ( $myrow = $this->db->fetchArray($result) ) {
686686 $block =& $this->create(false);
687687 $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;
690690 unset($block);
691691 }
692692 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;
695695 $result = $this->db->query($sql);
696696 while ( $myrow = $this->db->fetchArray($result) ) {
697697 $ret[] = $myrow['bid'];
@@ -706,9 +706,9 @@ class XoopsBlockHandler extends XoopsObjectHandler
706706 {
707707 $moduleid = (int)$moduleid;
708708 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;
710710 } 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;
712712 }
713713 $result = $this->db->query($sql);
714714 $ret = array();
--- a/html/kernel/configitem.php
+++ b/html/kernel/configitem.php
@@ -112,8 +112,6 @@ class XoopsConfigItem extends XoopsObject
112112 */
113113 function &getOptionItems()
114114 {
115- $optionArr = array();
116-
117115 $handler =& xoops_gethandler('config');
118116 $optionArr =& $handler->getConfigOptions(new Criteria('conf_id', $this->get('conf_id')));
119117
@@ -146,25 +144,23 @@ class XoopsConfigItem extends XoopsObject
146144 */
147145 function &getConfValueForOutput()
148146 {
149- $ret = null;
150- switch ($this->getVar('conf_valuetype')) {
147+ switch ($this->getVar('conf_valuetype', 'N')) {
151148 case 'int':
152149 $ret = (int)$this->getVar('conf_value', 'N');
153- break;
150+ return $ret;
154151 case 'array':
155152 $ret = unserialize($this->getVar('conf_value', 'N'));
156- break;
153+ return $ret;
157154 case 'float':
158155 $ret = (float)$this->getVar('conf_value', 'N');
159- break;
156+ return $ret;
160157 case 'textarea':
161- $ret = $this->getVar('conf_value');
162- break;
158+ return $this->getVar('conf_value');
163159 default:
164- $ret = $this->getVar('conf_value', 'N');
165- break;
160+ return $this->getVar('conf_value', 'N');
166161 }
167162
163+ $ret = null;
168164 return $ret;
169165 }
170166
--- a/html/kernel/object.php
+++ b/html/kernel/object.php
@@ -343,21 +343,16 @@ class XoopsObject extends AbstractXoopsObject
343343 case 'e':
344344 case 'edit':
345345 $ts =& MyTextSanitizer::getInstance();
346- $ret = $ts->htmlSpecialChars($ret);
347- break 1;
346+ return $ts->htmlSpecialChars($ret);
348347 case 'p':
349348 case 'preview':
350349 case 'f':
351350 case 'formpreview':
352351 $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));
357353 default:
358- break 1;
354+ return $ret;
359355 }
360- break;
361356 case XOBJ_DTYPE_TXTAREA:
362357 switch (strtolower($format)) {
363358 case 's':
@@ -369,12 +364,11 @@ class XoopsObject extends AbstractXoopsObject
369364 $smiley = (!isset($vars['dosmiley']['value']) || $vars['dosmiley']['value'] == 1) ? 1 : 0;
370365 $image = (!isset($vars['doimage']['value']) || $vars['doimage']['value'] == 1) ? 1 : 0;
371366 $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);
374368 case 'e':
375369 case 'edit':
376370 $ret = htmlspecialchars($ret, ENT_QUOTES);
377- break 1;
371+ return $ret;
378372 case 'p':
379373 case 'preview':
380374 $ts =& MyTextSanitizer::getInstance();
@@ -384,47 +378,33 @@ class XoopsObject extends AbstractXoopsObject
384378 $smiley = (!isset($vars['dosmiley']['value']) || $vars['dosmiley']['value'] == 1) ? 1 : 0;
385379 $image = (!isset($vars['doimage']['value']) || $vars['doimage']['value'] == 1) ? 1 : 0;
386380 $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);
389382 case 'f':
390383 case 'formpreview':
391384 $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);
396386 default:
397- break 1;
387+ return $ret;
398388 }
399- break;
400389 case XOBJ_DTYPE_ARRAY:
401- $ret = unserialize($ret);
402- break;
390+ return unserialize($ret);
403391 case XOBJ_DTYPE_SOURCE:
404392 switch (strtolower($format)) {
405- case 's':
406- case 'show':
407- break 1;
408393 case 'e':
409394 case 'edit':
410- $ret = htmlspecialchars($ret, ENT_QUOTES);
411- break 1;
395+ return htmlspecialchars($ret, ENT_QUOTES);
412396 case 'p':
413397 case 'preview':
414398 $ts =& MyTextSanitizer::getInstance();
415- $ret = $ts->stripSlashesGPC($ret);
416- break 1;
399+ return $ts->stripSlashesGPC($ret);
417400 case 'f':
418401 case 'formpreview':
419402 $ts =& MyTextSanitizer::getInstance();
420403 $ret = htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
421- break 1;
422- case 'n':
423- case 'none':
404+ return $ret;
424405 default:
425- break 1;
406+ return $ret;
426407 }
427- break;
428408 default:
429409 if ($var['options'] != '' && $ret != '') {
430410 switch (strtolower($format)) {
@@ -440,13 +420,12 @@ class XoopsObject extends AbstractXoopsObject
440420 }
441421 $i++;
442422 }
443- $ret = implode(', ', $ret);
423+ return implode(', ', $ret);
444424 case 'e':
445425 case 'edit':
446- $ret = explode('|', $ret);
447- break 1;
426+ return explode('|', $ret);
448427 default:
449- break 1;
428+ return $ret;
450429 }
451430
452431 }
@@ -518,8 +497,8 @@ class XoopsObject extends AbstractXoopsObject
518497 $this->setErrors("$k is required.");
519498 continue;
520499 }
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.");
523502 continue;
524503 }
525504 if (!$v['not_gpc']) {
@@ -548,11 +527,11 @@ class XoopsObject extends AbstractXoopsObject
548527 break;
549528
550529 case XOBJ_DTYPE_INT:
551- $cleanv = intval($cleanv);
530+ $cleanv = (int)$cleanv;
552531 break;
553532
554533 case XOBJ_DTYPE_FLOAT:
555- $cleanv = floatval($cleanv);
534+ $cleanv = (float)$cleanv;
556535 break;
557536
558537 case XOBJ_DTYPE_BOOL:
@@ -590,7 +569,7 @@ class XoopsObject extends AbstractXoopsObject
590569 case XOBJ_DTYPE_STIME:
591570 case XOBJ_DTYPE_MTIME:
592571 case XOBJ_DTYPE_LTIME:
593- $cleanv = !is_string($cleanv) ? intval($cleanv) : strtotime($cleanv);
572+ $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
594573 break;
595574 default:
596575 break;