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