Conditions | 394 |
Paths | 891 |
Total Lines | 684 |
Code Lines | 628 |
Lines | 33 |
Ratio | 4.82 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php namespace EvolutionCMS\Legacy; |
||
297 | public function getValueFromPreset($key, $value, $cmd, $opt) |
||
298 | { |
||
299 | $modx = evolutionCMS(); |
||
300 | |||
301 | if($this->isEmpty($cmd,$value)) return ''; |
||
302 | |||
303 | $this->key = $key; |
||
304 | $this->value = $value; |
||
305 | $this->opt = $opt; |
||
306 | |||
307 | switch ($cmd) |
||
308 | { |
||
309 | ##### Conditional Modifiers |
||
310 | case 'input': |
||
311 | case 'if': |
||
312 | if(!$opt) return $value; |
||
313 | return $opt; |
||
314 | case '=': |
||
315 | case 'eq': |
||
316 | case 'is': |
||
317 | case 'equals': |
||
318 | $this->condition[] = (int)($value == $opt); break; |
||
319 | case 'neq': |
||
320 | case 'ne': |
||
321 | case 'notequals': |
||
322 | case 'isnot': |
||
323 | case 'isnt': |
||
324 | case 'not': |
||
325 | $this->condition[] = (int)($value != $opt);break; |
||
326 | case '%': |
||
327 | $this->condition[] = (int)($value%$opt==0);break; |
||
328 | case 'isempty': |
||
329 | $this->condition[] = (int)(empty($value)); break; |
||
330 | case 'isntempty': |
||
331 | case 'isnotempty': |
||
332 | $this->condition[] = (int)(!empty($value)); break; |
||
333 | case '>=': |
||
334 | case 'gte': |
||
335 | case 'eg': |
||
336 | case 'isgte': |
||
337 | $this->condition[] = (int)($value >= $opt);break; |
||
338 | case '<=': |
||
339 | case 'lte': |
||
340 | case 'el': |
||
341 | case 'islte': |
||
342 | $this->condition[] = (int)($value <= $opt);break; |
||
343 | case '>': |
||
344 | case 'gt': |
||
345 | case 'greaterthan': |
||
346 | case 'isgreaterthan': |
||
347 | case 'isgt': |
||
348 | $this->condition[] = (int)($value > $opt);break; |
||
349 | case '<': |
||
350 | case 'lt': |
||
351 | case 'lowerthan': |
||
352 | case 'islowerthan': |
||
353 | case 'islt': |
||
354 | $this->condition[] = (int)($value < $opt);break; |
||
355 | case 'find': |
||
356 | $this->condition[] = (int)(strpos($value, $opt)!==false);break; |
||
357 | case 'inarray': |
||
358 | case 'in_array': |
||
359 | case 'in': |
||
360 | $opt = explode(',', $opt); |
||
361 | $this->condition[] = (int)(in_array($value, $opt)!==false);break; |
||
362 | case 'wildcard_match': |
||
363 | case 'wcard_match': |
||
364 | case 'wildcard': |
||
365 | case 'wcard': |
||
366 | case 'fnmatch': |
||
367 | $this->condition[] = (int)(fnmatch($opt, $value)!==false);break; |
||
368 | case 'is_file': |
||
369 | case 'is_dir': |
||
370 | case 'file_exists': |
||
371 | case 'is_readable': |
||
372 | case 'is_writable': |
||
373 | if(!$opt) $path = $value; |
||
374 | else $path = $opt; |
||
375 | if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
||
376 | if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
||
377 | $this->condition[] = (int)($cmd($path)!==false);break; |
||
378 | case 'is_image': |
||
379 | if(!$opt) $path = $value; |
||
380 | else $path = $opt; |
||
381 | if(!is_file($path)) {$this->condition[]='0';break;} |
||
382 | $_ = getimagesize($path); |
||
383 | $this->condition[] = (int)($_[0]);break; |
||
384 | case 'regex': |
||
385 | case 'preg': |
||
386 | case 'preg_match': |
||
387 | case 'isinrole': |
||
388 | $this->condition[] = (int)(preg_match($opt,$value));break; |
||
389 | case 'ir': |
||
390 | case 'memberof': |
||
391 | case 'mo': |
||
392 | // Is Member Of (same as inrole but this one can be stringed as a conditional) |
||
393 | $this->condition[] = $this->includeMdfFile('memberof'); |
||
394 | break; |
||
395 | case 'or': |
||
396 | $this->condition[] = '||';break; |
||
397 | case 'and': |
||
398 | $this->condition[] = '&&';break; |
||
399 | case 'show': |
||
400 | View Code Duplication | case 'this': |
|
401 | $conditional = implode(' ',$this->condition); |
||
402 | $isvalid = (int)(eval("return ({$conditional});")); |
||
403 | if ($isvalid) return $this->srcValue; |
||
404 | return NULL; |
||
405 | View Code Duplication | case 'then': |
|
406 | $conditional = implode(' ',$this->condition); |
||
407 | $isvalid = (int)eval("return ({$conditional});"); |
||
408 | if ($isvalid) return $opt; |
||
409 | return null; |
||
410 | View Code Duplication | case 'else': |
|
411 | $conditional = implode(' ',$this->condition); |
||
412 | $isvalid = (int)eval("return ({$conditional});"); |
||
413 | if (!$isvalid) return $opt; |
||
414 | break; |
||
415 | case 'select': |
||
416 | case 'switch': |
||
417 | $raw = explode('&',$opt); |
||
418 | $map = array(); |
||
419 | $c = count($raw); |
||
420 | for($m=0; $m<$c; $m++) { |
||
421 | $mi = explode('=',$raw[$m],2); |
||
422 | $map[$mi[0]] = $mi[1]; |
||
423 | } |
||
424 | if(isset($map[$value])) return $map[$value]; |
||
425 | else return ''; |
||
426 | ##### End of Conditional Modifiers |
||
427 | |||
428 | ##### Encode / Decode / Hash / Escape |
||
429 | case 'htmlent': |
||
430 | case 'htmlentities': |
||
431 | return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']); |
||
432 | case 'html_entity_decode': |
||
433 | case 'decode_html': |
||
434 | case 'html_decode': |
||
435 | return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']); |
||
436 | case 'esc': |
||
437 | case 'escape': |
||
438 | $value = preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
||
439 | return str_replace(array('[', ']', '`'),array('[', ']', '`'),$value); |
||
440 | case 'sql_escape': |
||
441 | case 'encode_js': |
||
442 | return $modx->getDatabase()->escape($value); |
||
443 | case 'htmlspecialchars': |
||
444 | case 'hsc': |
||
445 | case 'encode_html': |
||
446 | case 'html_encode': |
||
447 | return preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
||
448 | case 'spam_protect': |
||
449 | return str_replace(array('@','.'),array('@','.'),$value); |
||
450 | case 'strip': |
||
451 | if($opt==='') $opt = ' '; |
||
452 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
||
453 | case 'strip_linefeeds': |
||
454 | return str_replace(array("\n","\r"), '', $value); |
||
455 | case 'notags': |
||
456 | case 'strip_tags': |
||
457 | case 'remove_html': |
||
458 | if($opt!=='') |
||
459 | { |
||
460 | $param = array(); |
||
461 | foreach(explode(',',$opt) as $v) |
||
462 | { |
||
463 | $v = trim($v,'</> '); |
||
464 | $param[] = "<{$v}>"; |
||
465 | } |
||
466 | $params = implode(',',$param); |
||
467 | } |
||
468 | else $params = ''; |
||
469 | View Code Duplication | if(!strpos($params,'<br>')===false) { |
|
470 | $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
||
471 | $value = preg_replace('@<br[ /]*>@',"\n",$value); |
||
472 | } |
||
473 | return $this->strip_tags($value,$params); |
||
474 | case 'urlencode': |
||
475 | case 'url_encode': |
||
476 | case 'encode_url': |
||
477 | return urlencode($value); |
||
478 | case 'base64_decode': |
||
479 | if($opt!=='false') $opt = true; |
||
480 | else $opt = false; |
||
481 | return base64_decode($value,$opt); |
||
482 | case 'encode_sha1': $cmd = 'sha1'; |
||
483 | case 'addslashes': |
||
484 | case 'urldecode': |
||
485 | case 'url_decode': |
||
486 | case 'rawurlencode': |
||
487 | case 'rawurldecode': |
||
488 | case 'base64_encode': |
||
489 | case 'md5': |
||
490 | case 'sha1': |
||
491 | case 'json_encode': |
||
492 | case 'json_decode': |
||
493 | return $cmd($value); |
||
494 | |||
495 | ##### String Modifiers |
||
496 | case 'lcase': |
||
497 | case 'strtolower': |
||
498 | case 'lower_case': |
||
499 | return $this->strtolower($value); |
||
500 | case 'ucase': |
||
501 | case 'strtoupper': |
||
502 | case 'upper_case': |
||
503 | return $this->strtoupper($value); |
||
504 | case 'capitalize': |
||
505 | $_ = explode(' ',$value); |
||
506 | foreach($_ as $i=>$v) |
||
507 | { |
||
508 | $_[$i] = ucfirst($v); |
||
509 | } |
||
510 | return implode(' ',$_); |
||
511 | View Code Duplication | case 'zenhan': |
|
512 | if(empty($opt)) $opt='VKas'; |
||
513 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
||
514 | View Code Duplication | case 'hanzen': |
|
515 | if(empty($opt)) $opt='VKAS'; |
||
516 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
||
517 | case 'str_shuffle': |
||
518 | case 'shuffle': |
||
519 | return $this->str_shuffle($value); |
||
520 | case 'reverse': |
||
521 | case 'strrev': |
||
522 | return $this->strrev($value); |
||
523 | case 'length': |
||
524 | case 'len': |
||
525 | case 'strlen': |
||
526 | case 'count_characters': |
||
527 | return $this->strlen($value); |
||
528 | case 'count_words': |
||
529 | $value = trim($value); |
||
530 | return count(preg_split('/\s+/',$value)); |
||
531 | case 'str_word_count': |
||
532 | case 'word_count': |
||
533 | case 'wordcount': |
||
534 | return $this->str_word_count($value); |
||
535 | case 'count_paragraphs': |
||
536 | $value = trim($value); |
||
537 | $value = preg_replace('/\r/', '', $value); |
||
538 | return count(preg_split('/\n+/',$value)); |
||
539 | case 'strpos': |
||
540 | if($opt!=0&&empty($opt)) return $value; |
||
541 | return $this->strpos($value,$opt); |
||
542 | case 'wordwrap': |
||
543 | // default: 70 |
||
544 | $wrapat = (int)$opt > 0 ? (int)$opt : 70; |
||
545 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
||
546 | else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
||
547 | case 'wrap_text': |
||
548 | $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
||
549 | if($modx->config['manager_language']==='japanese-utf8') { |
||
550 | $chunk = array(); |
||
551 | $bt=''; |
||
552 | while($bt!=$value) { |
||
553 | $bt = $value; |
||
554 | if($this->strlen($value)<$width) { |
||
555 | $chunk[] = $value; |
||
556 | break; |
||
557 | } |
||
558 | $chunk[] = $this->substr($value,0,$width); |
||
559 | $value = $this->substr($value,$width); |
||
560 | } |
||
561 | return implode("\n",$chunk); |
||
562 | } |
||
563 | else |
||
564 | return wordwrap($value,$width,"\n",true); |
||
565 | case 'substr': |
||
566 | if(empty($opt)) break; |
||
567 | if(strpos($opt,',')!==false) { |
||
568 | list($b,$e) = explode(',',$opt,2); |
||
569 | return $this->substr($value,$b,(int)$e); |
||
570 | } |
||
571 | else return $this->substr($value,$opt); |
||
572 | case 'limit': |
||
573 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
||
574 | View Code Duplication | if(strpos($opt,'+')!==false) |
|
575 | list($len,$str) = explode('+',$opt,2); |
||
576 | else { |
||
577 | $len = $opt; |
||
578 | $str = ''; |
||
579 | } |
||
580 | if($len==='') $len = 100; |
||
581 | if(abs($len) > $this->strlen($value)) $str =''; |
||
582 | if(preg_match('/^[1-9][0-9]*$/',$len)) { |
||
583 | return $this->substr($value,0,$len) . $str; |
||
584 | } |
||
585 | elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
||
586 | return $str . $this->substr($value,$len); |
||
587 | } |
||
588 | break; |
||
589 | case 'summary': |
||
590 | case 'smart_description': |
||
591 | case 'smart_desc': |
||
592 | return $this->includeMdfFile('summary'); |
||
593 | case 'replace': |
||
594 | case 'str_replace': |
||
595 | if(empty($opt) || strpos($opt,',')===false) break; |
||
596 | if (substr_count($opt, ',') ==1) $delim = ','; |
||
597 | elseif(substr_count($opt, '|') ==1) $delim = '|'; |
||
598 | elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
||
599 | elseif(substr_count($opt, '/') ==1) $delim = '/'; |
||
600 | else break; |
||
601 | list($s,$r) = explode($delim,$opt); |
||
602 | if($value!=='') return str_replace($s,$r,$value); |
||
603 | break; |
||
604 | case 'replace_to': |
||
605 | case 'tpl': |
||
606 | View Code Duplication | if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
607 | break; |
||
608 | case 'eachtpl': |
||
609 | $value = explode('||',$value); |
||
610 | $_ = array(); |
||
611 | foreach($value as $v) { |
||
612 | $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt); |
||
613 | } |
||
614 | return implode("\n", $_); |
||
615 | case 'array_pop': |
||
616 | case 'array_shift': |
||
617 | if(strpos($value,'||')!==false) $delim = '||'; |
||
618 | else $delim = ','; |
||
619 | return $cmd(explode($delim,$value)); |
||
620 | case 'preg_replace': |
||
621 | case 'regex_replace': |
||
622 | if(empty($opt) || strpos($opt,',')===false) break; |
||
623 | list($s,$r) = explode(',',$opt,2); |
||
624 | if($value!=='') return preg_replace($s,$r,$value); |
||
625 | break; |
||
626 | case 'cat': |
||
627 | case 'concatenate': |
||
628 | case '.': |
||
629 | if($value!=='') return $value . $opt; |
||
630 | break; |
||
631 | case 'sprintf': |
||
632 | case 'string_format': |
||
633 | if($value!=='') return sprintf($opt,$value); |
||
634 | break; |
||
635 | case 'number_format': |
||
636 | if($opt=='') $opt = 0; |
||
637 | return number_format($value,$opt); |
||
638 | case 'money_format': |
||
639 | setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
||
640 | if($value!=='') return money_format($opt,(double)$value); |
||
641 | break; |
||
642 | case 'tobool': |
||
643 | return boolval($value); |
||
644 | case 'nl2lf': |
||
645 | View Code Duplication | if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
646 | break; |
||
647 | case 'br2nl': |
||
648 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
||
649 | case 'nl2br': |
||
650 | if (version_compare(PHP_VERSION, '5.3.0', '<')) |
||
651 | return nl2br($value); |
||
652 | if($opt!=='') |
||
653 | { |
||
654 | $opt = trim($opt); |
||
655 | $opt = strtolower($opt); |
||
656 | if($opt==='false') $opt = false; |
||
657 | elseif($opt==='0') $opt = false; |
||
658 | else $opt = true; |
||
659 | } |
||
660 | elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
||
661 | $opt = false; |
||
662 | else $opt = true; |
||
663 | return nl2br($value,$opt); |
||
664 | case 'ltrim': |
||
665 | case 'rtrim': |
||
666 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
||
667 | if($opt==='') |
||
668 | return $cmd($value); |
||
669 | else return $cmd($value,$opt); |
||
670 | // These are all straight wrappers for PHP functions |
||
671 | case 'ucfirst': |
||
672 | case 'lcfirst': |
||
673 | case 'ucwords': |
||
674 | return $cmd($value); |
||
675 | |||
676 | ##### Date time format |
||
677 | case 'strftime': |
||
678 | case 'date': |
||
679 | case 'dateformat': |
||
680 | if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
||
681 | if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
||
682 | if(strpos($opt,'%')!==false) |
||
683 | return strftime($opt,0+$value); |
||
684 | else |
||
685 | return date($opt,0+$value); |
||
686 | case 'time': |
||
687 | if(empty($opt)) $opt = '%H:%M'; |
||
688 | if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
||
689 | return strftime($opt,0+$value); |
||
690 | case 'strtotime': |
||
691 | return strtotime($value); |
||
692 | ##### mathematical function |
||
693 | case 'toint': |
||
694 | return (int)$value; |
||
695 | case 'tofloat': |
||
696 | return floatval($value); |
||
697 | case 'round': |
||
698 | if(!$opt) $opt = 0; |
||
699 | return $cmd($value,$opt); |
||
700 | case 'max': |
||
701 | case 'min': |
||
702 | return $cmd(explode(',',$value)); |
||
703 | case 'floor': |
||
704 | case 'ceil': |
||
705 | case 'abs': |
||
706 | return $cmd($value); |
||
707 | case 'math': |
||
708 | case 'calc': |
||
709 | $value = (int)$value; |
||
710 | if(empty($value)) $value = '0'; |
||
711 | $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
||
712 | $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
||
713 | if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
||
714 | $filter = str_replace('?',$value,$filter); |
||
715 | return eval("return {$filter};"); |
||
716 | case 'count': |
||
717 | if($value=='') return 0; |
||
718 | $value = explode(',',$value); |
||
719 | return count($value); |
||
720 | case 'sort': |
||
721 | case 'rsort': |
||
722 | if(strpos($value,"\n")!==false) $delim="\n"; |
||
723 | else $delim = ','; |
||
724 | $swap = explode($delim,$value); |
||
725 | if(!$opt) $opt = SORT_REGULAR; |
||
726 | else $opt = constant($opt); |
||
727 | $cmd($swap,$opt); |
||
728 | return implode($delim,$swap); |
||
729 | ##### Resource fields |
||
730 | case 'id': |
||
731 | if($opt) return $this->getDocumentObject($opt,$key); |
||
732 | break; |
||
733 | case 'type': |
||
734 | case 'contenttype': |
||
735 | case 'pagetitle': |
||
736 | case 'longtitle': |
||
737 | case 'description': |
||
738 | case 'alias': |
||
739 | case 'introtext': |
||
740 | case 'link_attributes': |
||
741 | case 'published': |
||
742 | case 'pub_date': |
||
743 | case 'unpub_date': |
||
744 | case 'parent': |
||
745 | case 'isfolder': |
||
746 | case 'content': |
||
747 | case 'richtext': |
||
748 | case 'template': |
||
749 | case 'menuindex': |
||
750 | case 'searchable': |
||
751 | case 'cacheable': |
||
752 | case 'createdby': |
||
753 | case 'createdon': |
||
754 | case 'editedby': |
||
755 | case 'editedon': |
||
756 | case 'deleted': |
||
757 | case 'deletedon': |
||
758 | case 'deletedby': |
||
759 | case 'publishedon': |
||
760 | case 'publishedby': |
||
761 | case 'menutitle': |
||
762 | case 'donthit': |
||
763 | case 'haskeywords': |
||
764 | case 'privateweb': |
||
765 | case 'privatemgr': |
||
766 | case 'content_dispo': |
||
767 | case 'hidemenu': |
||
768 | if($cmd==='contenttype') $cmd = 'contentType'; |
||
769 | return $this->getDocumentObject($value,$cmd); |
||
770 | case 'title': |
||
771 | $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
||
772 | $longtitle = $this->getDocumentObject($value,'longtitle'); |
||
773 | return $longtitle ? $longtitle : $pagetitle; |
||
774 | case 'shorttitle': |
||
775 | $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
||
776 | $menutitle = $this->getDocumentObject($value,'menutitle'); |
||
777 | return $menutitle ? $menutitle : $pagetitle; |
||
778 | case 'templatename': |
||
779 | $rs = $modx->getDatabase()->select('templatename','[+prefix+]site_templates',"id='{$value}'"); |
||
780 | $templateName = $modx->getDatabase()->getValue($rs); |
||
781 | return !$templateName ? '(blank)' : $templateName; |
||
782 | case 'getfield': |
||
783 | if(!$opt) $opt = 'content'; |
||
784 | return $modx->getField($opt,$value); |
||
785 | case 'children': |
||
786 | case 'childids': |
||
787 | if($value=='') $value = 0; // 値がない場合はルートと見なす |
||
788 | $published = 1; |
||
789 | if($opt=='') $opt = 'page'; |
||
790 | $_ = explode(',',$opt); |
||
791 | $where = array(); |
||
792 | foreach($_ as $opt) { |
||
793 | switch(trim($opt)) { |
||
794 | case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break; |
||
795 | case 'folder'; case 'isfolder': $where[] = 'sc.isfolder=1'; break; |
||
796 | case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
||
797 | case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
||
798 | case 'published': $published = 1; break; |
||
799 | case '!published': $published = 0; break; |
||
800 | } |
||
801 | } |
||
802 | $where = implode(' AND ', $where); |
||
803 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
||
804 | $result = array(); |
||
805 | foreach((array)$children as $child){ |
||
806 | $result[] = $child['id']; |
||
807 | } |
||
808 | return implode(',', $result); |
||
809 | case 'fullurl': |
||
810 | if(!is_numeric($value)) return $value; |
||
811 | return $modx->makeUrl($value); |
||
812 | case 'makeurl': |
||
813 | if(!is_numeric($value)) return $value; |
||
814 | if(!$opt) $opt = 'full'; |
||
815 | return $modx->makeUrl($value,'','',$opt); |
||
816 | |||
817 | ##### File system |
||
818 | case 'getimageinfo': |
||
819 | case 'imageinfo': |
||
820 | if(!is_file($value)) return ''; |
||
821 | $_ = getimagesize($value); |
||
822 | if(!$_[0]) return ''; |
||
823 | $info['width'] = $_[0]; |
||
824 | $info['height'] = $_[1]; |
||
825 | if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
||
826 | elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
||
827 | else $info['aspect'] = 'square'; |
||
828 | switch($_[2]) { |
||
829 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
||
830 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
||
831 | case IMAGETYPE_PNG : $info['type'] = 'png'; break; |
||
832 | default : $info['type'] = 'unknown'; |
||
833 | } |
||
834 | $info['attrib'] = $_[3]; |
||
835 | switch($opt) { |
||
836 | case 'width' : return $info['width']; |
||
837 | case 'height': return $info['height']; |
||
838 | case 'aspect': return $info['aspect']; |
||
839 | case 'type' : return $info['type']; |
||
840 | case 'attrib': return $info['attrib']; |
||
841 | default : return print_r($info,true); |
||
842 | } |
||
843 | |||
844 | case 'file_get_contents': |
||
845 | case 'readfile': |
||
846 | if(!is_file($value)) return $value; |
||
847 | $value = realpath($value); |
||
848 | if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
||
849 | $ext = strtolower(substr($value,-4)); |
||
850 | if($ext==='.php') exit('Can not read php file'); |
||
851 | if($ext==='.cgi') exit('Can not read cgi file'); |
||
852 | return file_get_contents($value); |
||
853 | case 'filesize': |
||
854 | if($value == '') return ''; |
||
855 | $filename = $value; |
||
856 | |||
857 | $site_url = $modx->config['site_url']; |
||
858 | if(strpos($filename,$site_url) === 0) |
||
859 | $filename = substr($filename,0,strlen($site_url)); |
||
860 | $filename = trim($filename,'/'); |
||
861 | |||
862 | $opt = trim($opt,'/'); |
||
863 | if($opt!=='') $opt .= '/'; |
||
864 | |||
865 | $filename = MODX_BASE_PATH.$opt.$filename; |
||
866 | |||
867 | if(is_file($filename)){ |
||
868 | clearstatcache(); |
||
869 | $size = filesize($filename); |
||
870 | return $size; |
||
871 | } |
||
872 | else return ''; |
||
873 | ##### User info |
||
874 | case 'username': |
||
875 | case 'fullname': |
||
876 | case 'role': |
||
877 | case 'email': |
||
878 | case 'phone': |
||
879 | case 'mobilephone': |
||
880 | case 'blocked': |
||
881 | case 'blockeduntil': |
||
882 | case 'blockedafter': |
||
883 | case 'logincount': |
||
884 | case 'lastlogin': |
||
885 | case 'thislogin': |
||
886 | case 'failedlogincount': |
||
887 | case 'dob': |
||
888 | case 'gender': |
||
889 | case 'country': |
||
890 | case 'street': |
||
891 | case 'city': |
||
892 | case 'state': |
||
893 | case 'zip': |
||
894 | case 'fax': |
||
895 | case 'photo': |
||
896 | case 'comment': |
||
897 | $this->opt = $cmd; |
||
898 | return $this->includeMdfFile('moduser'); |
||
899 | case 'userinfo': |
||
900 | if(empty($opt)) $this->opt = 'username'; |
||
901 | return $this->includeMdfFile('moduser'); |
||
902 | case 'webuserinfo': |
||
903 | if(empty($opt)) $this->opt = 'username'; |
||
904 | $this->value = -$value; |
||
905 | return $this->includeMdfFile('moduser'); |
||
906 | ##### Special functions |
||
907 | case 'ifempty': |
||
908 | case '_default': |
||
909 | case 'default': |
||
910 | if (empty($value)) return $opt; break; |
||
911 | case 'ifnotempty': |
||
912 | if (!empty($value)) return $opt; break; |
||
913 | case 'datagrid': |
||
914 | include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
||
915 | $grd = new DataGrid(null, trim($value)); |
||
916 | $grd->itemStyle = ''; |
||
917 | $grd->altItemStyle = ''; |
||
918 | $pos = strpos($value,"\n"); |
||
919 | if($pos) $_ = substr($value,0,$pos); |
||
920 | else $_ = $pos; |
||
921 | $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
||
922 | return $grd->render(); |
||
923 | case 'rotate': |
||
924 | case 'evenodd': |
||
925 | if(strpos($opt,',')===false) $opt = 'odd,even'; |
||
926 | $_ = explode(',', $opt); |
||
927 | $c = count($_); |
||
928 | $i = $value + $c; |
||
929 | $i = $i % $c; |
||
930 | return $_[$i]; |
||
931 | case 'takeval': |
||
932 | $arr = explode(",",$opt); |
||
933 | $idx = $value; |
||
934 | if(!is_numeric($idx)) return $value; |
||
935 | return $arr[$idx]; |
||
936 | case 'getimage': |
||
937 | return $this->includeMdfFile('getimage'); |
||
938 | case 'nicesize': |
||
939 | return $modx->nicesize($value); |
||
940 | case 'googlemap': |
||
941 | case 'googlemaps': |
||
942 | if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
||
943 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
||
944 | $ph['style'] = $opt; |
||
945 | $ph['value'] = $value; |
||
946 | return $modx->parseText($tpl,$ph); |
||
947 | case 'youtube': |
||
948 | case 'youtube16x9': |
||
949 | if(empty($opt)) $opt = 560; |
||
950 | $h = round($opt*0.5625); |
||
951 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
||
952 | return sprintf($tpl,$opt,$h,$value); |
||
953 | //case 'youtube4x3':%s*0.75+25 |
||
954 | case 'setvar': |
||
955 | $modx->placeholders[$opt] = $value; |
||
956 | return ''; |
||
957 | case 'csstohead': |
||
958 | $modx->regClientCSS($value); |
||
959 | return ''; |
||
960 | case 'htmltohead': |
||
961 | $modx->regClientStartupHTMLBlock($value); |
||
962 | return ''; |
||
963 | case 'htmltobottom': |
||
964 | $modx->regClientHTMLBlock($value); |
||
965 | return ''; |
||
966 | case 'jstohead': |
||
967 | $modx->regClientStartupScript($value); |
||
968 | return ''; |
||
969 | case 'jstobottom': |
||
970 | $modx->regClientScript($value); |
||
971 | return ''; |
||
972 | case 'dummy': |
||
973 | return $value; |
||
974 | |||
975 | // If we haven't yet found the modifier, let's look elsewhere |
||
976 | default: |
||
977 | $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
||
978 | } |
||
979 | return $value; |
||
980 | } |
||
981 | |||
1211 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.