@@ -565,6 +565,9 @@ discard block |
||
| 565 | 565 | |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | +/** |
|
| 569 | + * @param string $file |
|
| 570 | + */ |
|
| 568 | 571 | function determineIcon($file, $selFile, $mode) |
| 569 | 572 | { |
| 570 | 573 | $icons = array( |
@@ -709,6 +712,9 @@ discard block |
||
| 709 | 712 | return $path; |
| 710 | 713 | } |
| 711 | 714 | |
| 715 | +/** |
|
| 716 | + * @param string $string |
|
| 717 | + */ |
|
| 712 | 718 | function getExtension($string) |
| 713 | 719 | { |
| 714 | 720 | $pos = strrpos($string, '.'); |
@@ -744,6 +750,9 @@ discard block |
||
| 744 | 750 | return @mkdir($strPath); |
| 745 | 751 | } |
| 746 | 752 | |
| 753 | +/** |
|
| 754 | + * @param string $type |
|
| 755 | + */ |
|
| 747 | 756 | function logFileChange($type, $filename) |
| 748 | 757 | { |
| 749 | 758 | //global $_lang; |
@@ -733,7 +733,8 @@ discard block |
||
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | function mkdirs($strPath, $mode) |
| 736 | -{ // recursive mkdir function |
|
| 736 | +{ |
|
| 737 | +// recursive mkdir function |
|
| 737 | 738 | if (is_dir($strPath)) { |
| 738 | 739 | return true; |
| 739 | 740 | } |
@@ -838,7 +839,9 @@ discard block |
||
| 838 | 839 | global $modx, $_lang, $startpath, $filemanager_path, $uploadablefiles, $new_file_permissions; |
| 839 | 840 | $msg = ''; |
| 840 | 841 | foreach ($_FILES['userfile']['name'] as $i => $name) { |
| 841 | - if (empty($_FILES['userfile']['tmp_name'][$i])) continue; |
|
| 842 | + if (empty($_FILES['userfile']['tmp_name'][$i])) { |
|
| 843 | + continue; |
|
| 844 | + } |
|
| 842 | 845 | $userfile= array(); |
| 843 | 846 | |
| 844 | 847 | $userfile['tmp_name'] = $_FILES['userfile']['tmp_name'][$i]; |
@@ -160,6 +160,11 @@ discard block |
||
| 160 | 160 | return $output; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | +/** |
|
| 164 | + * @param integer $parent |
|
| 165 | + * @param string $filedir |
|
| 166 | + * @param string $mode |
|
| 167 | + */ |
|
| 163 | 168 | function importFiles($parent, $filedir, $files, $mode) { |
| 164 | 169 | global $modx; |
| 165 | 170 | global $_lang, $allowedfiles; |
@@ -302,6 +307,9 @@ discard block |
||
| 302 | 307 | } |
| 303 | 308 | } |
| 304 | 309 | |
| 310 | +/** |
|
| 311 | + * @param string $directory |
|
| 312 | + */ |
|
| 305 | 313 | function getFiles($directory, $listing = array(), $count = 0) { |
| 306 | 314 | global $_lang; |
| 307 | 315 | global $filesfound; |
@@ -326,6 +334,9 @@ discard block |
||
| 326 | 334 | return ($listing); |
| 327 | 335 | } |
| 328 | 336 | |
| 337 | +/** |
|
| 338 | + * @param string $filepath |
|
| 339 | + */ |
|
| 329 | 340 | function getFileContent($filepath) { |
| 330 | 341 | global $_lang; |
| 331 | 342 | // get the file |
@@ -353,6 +364,9 @@ discard block |
||
| 353 | 364 | return $new_array; |
| 354 | 365 | } |
| 355 | 366 | |
| 367 | +/** |
|
| 368 | + * @param null|string $src |
|
| 369 | + */ |
|
| 356 | 370 | function treatContent($src, $filename, $alias) { |
| 357 | 371 | global $modx; |
| 358 | 372 | |
@@ -101,7 +101,8 @@ discard block |
||
| 101 | 101 | </div> |
| 102 | 102 | |
| 103 | 103 | <?php |
| 104 | -function run() { |
|
| 104 | +function run() |
|
| 105 | +{ |
|
| 105 | 106 | global $modx, $_lang; |
| 106 | 107 | |
| 107 | 108 | $tbl_site_content = $modx->getFullTableName('site_content'); |
@@ -162,7 +163,8 @@ discard block |
||
| 162 | 163 | return $output; |
| 163 | 164 | } |
| 164 | 165 | |
| 165 | -function importFiles($parent, $filedir, $files, $mode) { |
|
| 166 | +function importFiles($parent, $filedir, $files, $mode) |
|
| 167 | +{ |
|
| 166 | 168 | global $modx; |
| 167 | 169 | global $_lang, $allowedfiles; |
| 168 | 170 | global $search_default, $cache_default, $publish_default; |
@@ -303,7 +305,8 @@ discard block |
||
| 303 | 305 | } |
| 304 | 306 | } |
| 305 | 307 | |
| 306 | -function getFiles($directory, $listing = array(), $count = 0) { |
|
| 308 | +function getFiles($directory, $listing = array(), $count = 0) |
|
| 309 | +{ |
|
| 307 | 310 | global $_lang; |
| 308 | 311 | global $filesfound; |
| 309 | 312 | $dummy = $count; |
@@ -327,7 +330,8 @@ discard block |
||
| 327 | 330 | return ($listing); |
| 328 | 331 | } |
| 329 | 332 | |
| 330 | -function getFileContent($filepath) { |
|
| 333 | +function getFileContent($filepath) |
|
| 334 | +{ |
|
| 331 | 335 | global $_lang; |
| 332 | 336 | // get the file |
| 333 | 337 | if(!$buffer = file_get_contents($filepath)) { |
@@ -337,7 +341,8 @@ discard block |
||
| 337 | 341 | } |
| 338 | 342 | } |
| 339 | 343 | |
| 340 | -function pop_index($array) { |
|
| 344 | +function pop_index($array) |
|
| 345 | +{ |
|
| 341 | 346 | $new_array = array(); |
| 342 | 347 | foreach($array as $k => $v) { |
| 343 | 348 | if($v !== 'index.html' && $v !== 'index.htm') { |
@@ -354,7 +359,8 @@ discard block |
||
| 354 | 359 | return $new_array; |
| 355 | 360 | } |
| 356 | 361 | |
| 357 | -function treatContent($src, $filename, $alias) { |
|
| 362 | +function treatContent($src, $filename, $alias) |
|
| 363 | +{ |
|
| 358 | 364 | global $modx; |
| 359 | 365 | |
| 360 | 366 | $src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII'); |
@@ -395,7 +401,8 @@ discard block |
||
| 395 | 401 | ); |
| 396 | 402 | } |
| 397 | 403 | |
| 398 | -function convertLink() { |
|
| 404 | +function convertLink() |
|
| 405 | +{ |
|
| 399 | 406 | global $modx; |
| 400 | 407 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 401 | 408 | |
@@ -504,6 +504,9 @@ |
||
| 504 | 504 | return $iconsPrivate; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | +/** |
|
| 508 | + * @return string |
|
| 509 | + */ |
|
| 507 | 510 | function getNodeTitle($nodeNameSource, $row) { |
| 508 | 511 | global $modx; |
| 509 | 512 | |
@@ -10,7 +10,8 @@ discard block |
||
| 10 | 10 | * @param $theme |
| 11 | 11 | * @param string $hereid |
| 12 | 12 | */ |
| 13 | -function makeHTML($indent, $parent, $expandAll, $theme, $hereid = '') { |
|
| 13 | +function makeHTML($indent, $parent, $expandAll, $theme, $hereid = '') |
|
| 14 | +{ |
|
| 14 | 15 | global $modx; |
| 15 | 16 | global $icons, $iconsPrivate, $_style; |
| 16 | 17 | global $_lang, $opened, $opened2, $closed2; //added global vars |
@@ -450,7 +451,8 @@ discard block |
||
| 450 | 451 | return $output; |
| 451 | 452 | } |
| 452 | 453 | |
| 453 | -function getIconInfo($_style) { |
|
| 454 | +function getIconInfo($_style) |
|
| 455 | +{ |
|
| 454 | 456 | if(!isset($_style['tree_page_gif'])) { |
| 455 | 457 | $_style['tree_page_gif'] = $_style['tree_page']; |
| 456 | 458 | } |
@@ -477,7 +479,8 @@ discard block |
||
| 477 | 479 | return $icons; |
| 478 | 480 | } |
| 479 | 481 | |
| 480 | -function getPrivateIconInfo($_style) { |
|
| 482 | +function getPrivateIconInfo($_style) |
|
| 483 | +{ |
|
| 481 | 484 | if(!isset($_style['tree_page_gif_secure'])) { |
| 482 | 485 | $_style['tree_page_gif_secure'] = $_style['tree_page_secure']; |
| 483 | 486 | } |
@@ -504,7 +507,8 @@ discard block |
||
| 504 | 507 | return $iconsPrivate; |
| 505 | 508 | } |
| 506 | 509 | |
| 507 | -function getNodeTitle($nodeNameSource, $row) { |
|
| 510 | +function getNodeTitle($nodeNameSource, $row) |
|
| 511 | +{ |
|
| 508 | 512 | global $modx; |
| 509 | 513 | |
| 510 | 514 | switch($nodeNameSource) { |
@@ -550,7 +554,8 @@ discard block |
||
| 550 | 554 | return $nodetitle; |
| 551 | 555 | } |
| 552 | 556 | |
| 553 | -function isDateNode($nodeNameSource) { |
|
| 557 | +function isDateNode($nodeNameSource) |
|
| 558 | +{ |
|
| 554 | 559 | switch($nodeNameSource) { |
| 555 | 560 | case 'createdon': |
| 556 | 561 | case 'editedon': |
@@ -563,13 +568,15 @@ discard block |
||
| 563 | 568 | } |
| 564 | 569 | } |
| 565 | 570 | |
| 566 | -function checkIsFolder($parent = 0, $isfolder = 1) { |
|
| 571 | +function checkIsFolder($parent = 0, $isfolder = 1) |
|
| 572 | +{ |
|
| 567 | 573 | global $modx; |
| 568 | 574 | |
| 569 | 575 | return (int) $modx->db->getValue($modx->db->query('SELECT count(*) FROM ' . $modx->getFullTableName('site_content') . ' WHERE parent=' . $parent . ' AND isfolder=' . $isfolder . ' ')); |
| 570 | 576 | } |
| 571 | 577 | |
| 572 | -function _htmlentities($array) { |
|
| 578 | +function _htmlentities($array) |
|
| 579 | +{ |
|
| 573 | 580 | global $modx; |
| 574 | 581 | |
| 575 | 582 | $array = json_encode($array, JSON_UNESCAPED_UNICODE); |
@@ -578,7 +585,8 @@ discard block |
||
| 578 | 585 | return $array; |
| 579 | 586 | } |
| 580 | 587 | |
| 581 | -function getTplSingleNode() { |
|
| 588 | +function getTplSingleNode() |
|
| 589 | +{ |
|
| 582 | 590 | return '<div id="node[+id+]"><a class="[+treeNodeClass+]" |
| 583 | 591 | onclick="modx.tree.treeAction(event,[+id+]);" |
| 584 | 592 | oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');" |
@@ -602,7 +610,8 @@ discard block |
||
| 602 | 610 | title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a></div>'; |
| 603 | 611 | } |
| 604 | 612 | |
| 605 | -function getTplFolderNode() { |
|
| 613 | +function getTplFolderNode() |
|
| 614 | +{ |
|
| 606 | 615 | return '<div id="node[+id+]"><a class="[+treeNodeClass+]" |
| 607 | 616 | onclick="modx.tree.treeAction(event,[+id+]);" |
| 608 | 617 | oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');" |
@@ -638,7 +647,8 @@ discard block |
||
| 638 | 647 | title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a><div>'; |
| 639 | 648 | } |
| 640 | 649 | |
| 641 | -function getTplFolderNodeNotChildren() { |
|
| 650 | +function getTplFolderNodeNotChildren() |
|
| 651 | +{ |
|
| 642 | 652 | return '<div id="node[+id+]"><a class="[+treeNodeClass+]" |
| 643 | 653 | onclick="modx.tree.treeAction(event,[+id+]);" |
| 644 | 654 | oncontextmenu="modx.tree.showPopup(event,[+id+],\'[+nodetitle_esc+]\');" |
@@ -670,7 +680,8 @@ discard block |
||
| 670 | 680 | title="[+title+]">[+nodetitleDisplay+][+weblinkDisplay+]</span>[+pageIdDisplay+]</a><div>'; |
| 671 | 681 | } |
| 672 | 682 | |
| 673 | -function dbug($str, $flag = false) { |
|
| 683 | +function dbug($str, $flag = false) |
|
| 684 | +{ |
|
| 674 | 685 | print('<pre>'); |
| 675 | 686 | print_r($str); |
| 676 | 687 | print('</pre>'); |
@@ -3,6 +3,9 @@ |
||
| 3 | 3 | //Kyle Jaebker - 08/07/06 |
| 4 | 4 | |
| 5 | 5 | //Create a new category |
| 6 | +/** |
|
| 7 | + * @param string $newCat |
|
| 8 | + */ |
|
| 6 | 9 | function newCategory($newCat) { |
| 7 | 10 | global $modx; |
| 8 | 11 | $useTable = $modx->getFullTableName('categories'); |
@@ -3,18 +3,22 @@ discard block |
||
| 3 | 3 | //Kyle Jaebker - 08/07/06 |
| 4 | 4 | |
| 5 | 5 | //Create a new category |
| 6 | -function newCategory($newCat) { |
|
| 6 | +function newCategory($newCat) |
|
| 7 | +{ |
|
| 7 | 8 | global $modx; |
| 8 | 9 | $useTable = $modx->getFullTableName('categories'); |
| 9 | 10 | $categoryId = $modx->db->insert( |
| 10 | 11 | array( |
| 11 | 12 | 'category' => $modx->db->escape($newCat), |
| 12 | 13 | ), $useTable); |
| 13 | - if (!$categoryId) $categoryId = 0; |
|
| 14 | + if (!$categoryId) { |
|
| 15 | + $categoryId = 0; |
|
| 16 | + } |
|
| 14 | 17 | return $categoryId; |
| 15 | 18 | } |
| 16 | 19 | //check if new category already exists |
| 17 | -function checkCategory($newCat = '') { |
|
| 20 | +function checkCategory($newCat = '') |
|
| 21 | +{ |
|
| 18 | 22 | global $modx; |
| 19 | 23 | $useTable = $modx->getFullTableName('categories'); |
| 20 | 24 | $newCat = $modx->db->escape($newCat); |
@@ -25,13 +29,17 @@ discard block |
||
| 25 | 29 | return 0; |
| 26 | 30 | } |
| 27 | 31 | //Check for category, create new if not exists |
| 28 | -function getCategory($category='') { |
|
| 32 | +function getCategory($category='') |
|
| 33 | +{ |
|
| 29 | 34 | $categoryId = checkCategory($category); |
| 30 | - if(!$categoryId) $categoryId = newCategory($category); |
|
| 35 | + if(!$categoryId) { |
|
| 36 | + $categoryId = newCategory($category); |
|
| 37 | + } |
|
| 31 | 38 | return $categoryId; |
| 32 | 39 | } |
| 33 | 40 | //Get all categories |
| 34 | -function getCategories() { |
|
| 41 | +function getCategories() |
|
| 42 | +{ |
|
| 35 | 43 | global $modx; |
| 36 | 44 | $useTable = $modx->getFullTableName('categories'); |
| 37 | 45 | $cats = $modx->db->select('id, category', $modx->getFullTableName('categories'), '', 'category'); |
@@ -43,7 +51,8 @@ discard block |
||
| 43 | 51 | return $resourceArray; |
| 44 | 52 | } |
| 45 | 53 | //Delete category & associations |
| 46 | -function deleteCategory($catId=0) { |
|
| 54 | +function deleteCategory($catId=0) |
|
| 55 | +{ |
|
| 47 | 56 | global $modx; |
| 48 | 57 | if ($catId) { |
| 49 | 58 | $resetTables = array('site_plugins', 'site_snippets', 'site_htmlsnippets', 'site_templates', 'site_tmplvars', 'site_modules'); |
@@ -3968,7 +3968,7 @@ |
||
| 3968 | 3968 | * @param int|string $options Either a PATHINFO_* constant, |
| 3969 | 3969 | * or a string name to return only the specified piece |
| 3970 | 3970 | * |
| 3971 | - * @return string|array |
|
| 3971 | + * @return string |
|
| 3972 | 3972 | */ |
| 3973 | 3973 | public static function mb_pathinfo($path, $options = null) |
| 3974 | 3974 | { |
@@ -2059,7 +2059,8 @@ discard block |
||
| 2059 | 2059 | */ |
| 2060 | 2060 | public function addrFormat($addr) |
| 2061 | 2061 | { |
| 2062 | - if (empty($addr[1])) { // No name provided |
|
| 2062 | + if (empty($addr[1])) { |
|
| 2063 | +// No name provided |
|
| 2063 | 2064 | return $this->secureHeader($addr[0]); |
| 2064 | 2065 | } |
| 2065 | 2066 | |
@@ -3425,7 +3426,7 @@ discard block |
||
| 3425 | 3426 | { |
| 3426 | 3427 | $this->RecipientsQueue = array_filter( |
| 3427 | 3428 | $this->RecipientsQueue, |
| 3428 | - function ($params) use ($kind) { |
|
| 3429 | + function ($params) use ($kind){ |
|
| 3429 | 3430 | return $params[0] != $kind; |
| 3430 | 3431 | } |
| 3431 | 3432 | ); |
@@ -209,7 +209,7 @@ |
||
| 209 | 209 | * Connect to a POP3 server. |
| 210 | 210 | * |
| 211 | 211 | * @param string $host |
| 212 | - * @param int|bool $port |
|
| 212 | + * @param integer $port |
|
| 213 | 213 | * @param int $tval |
| 214 | 214 | * |
| 215 | 215 | * @return bool |
@@ -344,7 +344,8 @@ |
||
| 344 | 344 | protected function sendString($string) |
| 345 | 345 | { |
| 346 | 346 | if ($this->pop_conn) { |
| 347 | - if ($this->do_debug >= 2) { //Show client messages when debug >= 2 |
|
| 347 | + if ($this->do_debug >= 2) { |
|
| 348 | +//Show client messages when debug >= 2 |
|
| 348 | 349 | echo 'Client -> Server: ', $string; |
| 349 | 350 | } |
| 350 | 351 | |
@@ -1314,7 +1314,7 @@ |
||
| 1314 | 1314 | * If no reply has been received yet, it will return null. |
| 1315 | 1315 | * If no pattern was matched, it will return false. |
| 1316 | 1316 | * |
| 1317 | - * @return bool|null|string |
|
| 1317 | + * @return string |
|
| 1318 | 1318 | * |
| 1319 | 1319 | * @see recordLastTransactionID() |
| 1320 | 1320 | */ |
@@ -192,6 +192,9 @@ |
||
| 192 | 192 | return $_; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | + /** |
|
| 196 | + * @param string $checksum |
|
| 197 | + */ |
|
| 195 | 198 | function setSystemChecksum($checksum) { |
| 196 | 199 | global $modx; |
| 197 | 200 | $tbl_system_settings = $modx->getFullTableName('system_settings'); |
@@ -8,16 +8,19 @@ discard block |
||
| 8 | 8 | global $_PAGE; // page view state object. Usage $_PAGE['vs']['propertyname'] = $value; |
| 9 | 9 | |
| 10 | 10 | // Content manager wrapper class |
| 11 | -class ManagerAPI { |
|
| 11 | +class ManagerAPI |
|
| 12 | +{ |
|
| 12 | 13 | |
| 13 | 14 | var $action; // action directive |
| 14 | 15 | |
| 15 | - function __construct(){ |
|
| 16 | + function __construct() |
|
| 17 | + { |
|
| 16 | 18 | global $action; |
| 17 | 19 | $this->action = $action; // set action directive |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | - function initPageViewState($id=0){ |
|
| 22 | + function initPageViewState($id=0) |
|
| 23 | + { |
|
| 21 | 24 | global $_PAGE; |
| 22 | 25 | $vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : ''; |
| 23 | 26 | if($vsid!=$this->action) { |
@@ -28,33 +31,38 @@ discard block |
||
| 28 | 31 | } |
| 29 | 32 | |
| 30 | 33 | // save page view state - not really necessary, |
| 31 | - function savePageViewState($id=0){ |
|
| 34 | + function savePageViewState($id=0) |
|
| 35 | + { |
|
| 32 | 36 | global $_PAGE; |
| 33 | 37 | $_SESSION["mgrPageViewSDATA"] = $_PAGE['vs']; |
| 34 | 38 | $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | 41 | // check for saved form |
| 38 | - function hasFormValues() { |
|
| 39 | - if(isset($_SESSION["mgrFormValueId"])) { |
|
| 42 | + function hasFormValues() |
|
| 43 | + { |
|
| 44 | + if(isset($_SESSION["mgrFormValueId"])) { |
|
| 40 | 45 | if($this->action==$_SESSION["mgrFormValueId"]) { |
| 41 | 46 | return true; |
| 42 | - } |
|
| 43 | - else { |
|
| 47 | + } else { |
|
| 44 | 48 | $this->clearSavedFormValues(); |
| 45 | 49 | } |
| 46 | 50 | } |
| 47 | 51 | return false; |
| 48 | 52 | } |
| 49 | 53 | // saved form post from $_POST |
| 50 | - function saveFormValues($id=0){ |
|
| 54 | + function saveFormValues($id=0) |
|
| 55 | + { |
|
| 51 | 56 | $_SESSION["mgrFormValues"] = $_POST; |
| 52 | 57 | $_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action; |
| 53 | 58 | } |
| 54 | 59 | // load saved form values into $_POST |
| 55 | - function loadFormValues(){ |
|
| 60 | + function loadFormValues() |
|
| 61 | + { |
|
| 56 | 62 | |
| 57 | - if(!$this->hasFormValues()) return false; |
|
| 63 | + if(!$this->hasFormValues()) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 58 | 66 | |
| 59 | 67 | $p = $_SESSION["mgrFormValues"]; |
| 60 | 68 | $this->clearSavedFormValues(); |
@@ -64,31 +72,41 @@ discard block |
||
| 64 | 72 | return true; |
| 65 | 73 | } |
| 66 | 74 | // clear form post |
| 67 | - function clearSavedFormValues(){ |
|
| 75 | + function clearSavedFormValues() |
|
| 76 | + { |
|
| 68 | 77 | unset($_SESSION["mgrFormValues"]); |
| 69 | 78 | unset($_SESSION["mgrFormValueId"]); |
| 70 | 79 | } |
| 71 | 80 | |
| 72 | - function getHashType($db_value='') { // md5 | v1 | phpass |
|
| 81 | + function getHashType($db_value='') |
|
| 82 | + { |
|
| 83 | +// md5 | v1 | phpass |
|
| 73 | 84 | $c = substr($db_value,0,1); |
| 74 | - if($c==='$') return 'phpass'; |
|
| 75 | - elseif(strlen($db_value)===32) return 'md5'; |
|
| 76 | - elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1'; |
|
| 77 | - else return 'unknown'; |
|
| 85 | + if($c==='$') { |
|
| 86 | + return 'phpass'; |
|
| 87 | + } elseif(strlen($db_value)===32) { |
|
| 88 | + return 'md5'; |
|
| 89 | + } elseif($c!=='$' && strpos($db_value,'>')!==false) { |
|
| 90 | + return 'v1'; |
|
| 91 | + } else { |
|
| 92 | + return 'unknown'; |
|
| 93 | + } |
|
| 78 | 94 | } |
| 79 | 95 | |
| 80 | 96 | function genV1Hash($password, $seed='1') |
| 81 | - { // $seed is user_id basically |
|
| 97 | + { |
|
| 98 | +// $seed is user_id basically |
|
| 82 | 99 | global $modx; |
| 83 | 100 | |
| 84 | - if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) |
|
| 85 | - $algorithm = $modx->config['pwd_hash_algo']; |
|
| 86 | - else $algorithm = 'UNCRYPT'; |
|
| 101 | + if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) { |
|
| 102 | + $algorithm = $modx->config['pwd_hash_algo']; |
|
| 103 | + } else { |
|
| 104 | + $algorithm = 'UNCRYPT'; |
|
| 105 | + } |
|
| 87 | 106 | |
| 88 | 107 | $salt = md5($password . $seed); |
| 89 | 108 | |
| 90 | - switch($algorithm) |
|
| 91 | - { |
|
| 109 | + switch($algorithm) { |
|
| 92 | 110 | case 'BLOWFISH_Y': |
| 93 | 111 | $salt = '$2y$07$' . substr($salt,0,22); |
| 94 | 112 | break; |
@@ -106,11 +124,11 @@ discard block |
||
| 106 | 124 | break; |
| 107 | 125 | } |
| 108 | 126 | |
| 109 | - if($algorithm!=='UNCRYPT') |
|
| 110 | - { |
|
| 127 | + if($algorithm!=='UNCRYPT') { |
|
| 111 | 128 | $password = sha1($password) . crypt($password,$salt); |
| 129 | + } else { |
|
| 130 | + $password = sha1($salt.$password); |
|
| 112 | 131 | } |
| 113 | - else $password = sha1($salt.$password); |
|
| 114 | 132 | |
| 115 | 133 | $result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8); |
| 116 | 134 | |
@@ -124,9 +142,9 @@ discard block |
||
| 124 | 142 | $rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'"); |
| 125 | 143 | $password = $modx->db->getValue($rs); |
| 126 | 144 | |
| 127 | - if(strpos($password,'>')===false) $algo = 'NOSALT'; |
|
| 128 | - else |
|
| 129 | - { |
|
| 145 | + if(strpos($password,'>')===false) { |
|
| 146 | + $algo = 'NOSALT'; |
|
| 147 | + } else { |
|
| 130 | 148 | $algo = substr($password,0,strpos($password,'>')); |
| 131 | 149 | } |
| 132 | 150 | return strtoupper($algo); |
@@ -135,27 +153,34 @@ discard block |
||
| 135 | 153 | function checkHashAlgorithm($algorithm='') |
| 136 | 154 | { |
| 137 | 155 | $result = false; |
| 138 | - if (!empty($algorithm)) |
|
| 139 | - { |
|
| 140 | - switch ($algorithm) |
|
| 141 | - { |
|
| 156 | + if (!empty($algorithm)) { |
|
| 157 | + switch ($algorithm) { |
|
| 142 | 158 | case 'BLOWFISH_Y': |
| 143 | - if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
| 144 | - { |
|
| 145 | - if (version_compare('5.3.7', PHP_VERSION) <= 0) $result = true; |
|
| 159 | + if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) { |
|
| 160 | + if (version_compare('5.3.7', PHP_VERSION) <= 0) { |
|
| 161 | + $result = true; |
|
| 162 | + } |
|
| 146 | 163 | } |
| 147 | 164 | break; |
| 148 | 165 | case 'BLOWFISH_A': |
| 149 | - if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) $result = true; |
|
| 166 | + if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) { |
|
| 167 | + $result = true; |
|
| 168 | + } |
|
| 150 | 169 | break; |
| 151 | 170 | case 'SHA512': |
| 152 | - if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) $result = true; |
|
| 171 | + if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) { |
|
| 172 | + $result = true; |
|
| 173 | + } |
|
| 153 | 174 | break; |
| 154 | 175 | case 'SHA256': |
| 155 | - if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) $result = true; |
|
| 176 | + if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) { |
|
| 177 | + $result = true; |
|
| 178 | + } |
|
| 156 | 179 | break; |
| 157 | 180 | case 'MD5': |
| 158 | - if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') $result = true; |
|
| 181 | + if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') { |
|
| 182 | + $result = true; |
|
| 183 | + } |
|
| 159 | 184 | break; |
| 160 | 185 | case 'UNCRYPT': |
| 161 | 186 | $result = true; |
@@ -165,20 +190,24 @@ discard block |
||
| 165 | 190 | return $result; |
| 166 | 191 | } |
| 167 | 192 | |
| 168 | - function getSystemChecksum($check_files) { |
|
| 193 | + function getSystemChecksum($check_files) |
|
| 194 | + { |
|
| 169 | 195 | $_ = array(); |
| 170 | 196 | $check_files = trim($check_files); |
| 171 | 197 | $check_files = explode("\n", $check_files); |
| 172 | 198 | foreach($check_files as $file) { |
| 173 | 199 | $file = trim($file); |
| 174 | 200 | $file = MODX_BASE_PATH . $file; |
| 175 | - if(!is_file($file)) continue; |
|
| 201 | + if(!is_file($file)) { |
|
| 202 | + continue; |
|
| 203 | + } |
|
| 176 | 204 | $_[$file]= md5_file($file); |
| 177 | 205 | } |
| 178 | 206 | return serialize($_); |
| 179 | 207 | } |
| 180 | 208 | |
| 181 | - function getModifiedSystemFilesList($check_files, $checksum) { |
|
| 209 | + function getModifiedSystemFilesList($check_files, $checksum) |
|
| 210 | + { |
|
| 182 | 211 | $_ = array(); |
| 183 | 212 | $check_files = trim($check_files); |
| 184 | 213 | $check_files = explode("\n", $check_files); |
@@ -186,41 +215,52 @@ discard block |
||
| 186 | 215 | foreach($check_files as $file) { |
| 187 | 216 | $file = trim($file); |
| 188 | 217 | $filePath = MODX_BASE_PATH . $file; |
| 189 | - if(!is_file($filePath)) continue; |
|
| 190 | - if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file; |
|
| 218 | + if(!is_file($filePath)) { |
|
| 219 | + continue; |
|
| 220 | + } |
|
| 221 | + if(md5_file($filePath) != $checksum[$filePath]) { |
|
| 222 | + $_[] = $file; |
|
| 223 | + } |
|
| 191 | 224 | } |
| 192 | 225 | return $_; |
| 193 | 226 | } |
| 194 | 227 | |
| 195 | - function setSystemChecksum($checksum) { |
|
| 228 | + function setSystemChecksum($checksum) |
|
| 229 | + { |
|
| 196 | 230 | global $modx; |
| 197 | 231 | $tbl_system_settings = $modx->getFullTableName('system_settings'); |
| 198 | 232 | $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')"; |
| 199 | 233 | $modx->db->query($sql); |
| 200 | 234 | } |
| 201 | 235 | |
| 202 | - function checkSystemChecksum() { |
|
| 236 | + function checkSystemChecksum() |
|
| 237 | + { |
|
| 203 | 238 | global $modx; |
| 204 | 239 | |
| 205 | - if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0'; |
|
| 240 | + if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) { |
|
| 241 | + return '0'; |
|
| 242 | + } |
|
| 206 | 243 | |
| 207 | 244 | $current = $this->getSystemChecksum($modx->config['check_files_onlogin']); |
| 208 | - if(empty($current)) return '0'; |
|
| 245 | + if(empty($current)) { |
|
| 246 | + return '0'; |
|
| 247 | + } |
|
| 209 | 248 | |
| 210 | - if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) |
|
| 211 | - { |
|
| 249 | + if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) { |
|
| 212 | 250 | $this->setSystemChecksum($current); |
| 213 | 251 | return '0'; |
| 214 | 252 | } |
| 215 | - if($current===$modx->config['sys_files_checksum']) $result = '0'; |
|
| 216 | - else { |
|
| 253 | + if($current===$modx->config['sys_files_checksum']) { |
|
| 254 | + $result = '0'; |
|
| 255 | + } else { |
|
| 217 | 256 | $result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']); |
| 218 | 257 | } |
| 219 | 258 | |
| 220 | 259 | return $result; |
| 221 | 260 | } |
| 222 | 261 | |
| 223 | - function getLastUserSetting($key=false) { |
|
| 262 | + function getLastUserSetting($key=false) |
|
| 263 | + { |
|
| 224 | 264 | global $modx; |
| 225 | 265 | |
| 226 | 266 | $rs = $modx->db->select('*', $modx->getFullTableName('user_settings'), "user = '{$_SESSION['mgrInternalKey']}'"); |
@@ -233,15 +273,21 @@ discard block |
||
| 233 | 273 | } |
| 234 | 274 | } |
| 235 | 275 | |
| 236 | - if(!$key) return $usersettings; |
|
| 237 | - else return isset($usersettings[$key]) ? $usersettings[$key] : NULL; |
|
| 276 | + if(!$key) { |
|
| 277 | + return $usersettings; |
|
| 278 | + } else { |
|
| 279 | + return isset($usersettings[$key]) ? $usersettings[$key] : NULL; |
|
| 280 | + } |
|
| 238 | 281 | } |
| 239 | 282 | |
| 240 | - function saveLastUserSetting($settings, $val='') { |
|
| 283 | + function saveLastUserSetting($settings, $val='') |
|
| 284 | + { |
|
| 241 | 285 | global $modx; |
| 242 | 286 | |
| 243 | 287 | if(!empty($settings)) { |
| 244 | - if(!is_array($settings)) $settings = array($settings=>$val); |
|
| 288 | + if(!is_array($settings)) { |
|
| 289 | + $settings = array($settings=>$val); |
|
| 290 | + } |
|
| 245 | 291 | |
| 246 | 292 | foreach ($settings as $key => $val) { |
| 247 | 293 | $f = array(); |
@@ -256,7 +302,8 @@ discard block |
||
| 256 | 302 | } |
| 257 | 303 | } |
| 258 | 304 | |
| 259 | - function loadDatePicker($path) { |
|
| 305 | + function loadDatePicker($path) |
|
| 306 | + { |
|
| 260 | 307 | global $modx; |
| 261 | 308 | include_once($path); |
| 262 | 309 | $dp = new DATEPICKER(); |
@@ -43,6 +43,9 @@ discard block |
||
| 43 | 43 | $this->random_state = microtime() . uniqid(mt_rand(), TRUE); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | + /** |
|
| 47 | + * @param integer $count |
|
| 48 | + */ |
|
| 46 | 49 | function get_random_bytes($count) |
| 47 | 50 | { |
| 48 | 51 | $output = ''; |
@@ -66,6 +69,9 @@ discard block |
||
| 66 | 69 | return $output; |
| 67 | 70 | } |
| 68 | 71 | |
| 72 | + /** |
|
| 73 | + * @param integer $count |
|
| 74 | + */ |
|
| 69 | 75 | function encode64($input, $count) |
| 70 | 76 | { |
| 71 | 77 | $output = ''; |
@@ -89,6 +95,9 @@ discard block |
||
| 89 | 95 | return $output; |
| 90 | 96 | } |
| 91 | 97 | |
| 98 | + /** |
|
| 99 | + * @param string $input |
|
| 100 | + */ |
|
| 92 | 101 | function gensalt_private($input) |
| 93 | 102 | { |
| 94 | 103 | $output = '$P$'; |
@@ -137,6 +146,9 @@ discard block |
||
| 137 | 146 | return $output; |
| 138 | 147 | } |
| 139 | 148 | |
| 149 | + /** |
|
| 150 | + * @param string $input |
|
| 151 | + */ |
|
| 140 | 152 | function gensalt_extended($input) |
| 141 | 153 | { |
| 142 | 154 | $count_log2 = min($this->iteration_count_log2 + 8, 24); |
@@ -155,6 +167,9 @@ discard block |
||
| 155 | 167 | return $output; |
| 156 | 168 | } |
| 157 | 169 | |
| 170 | + /** |
|
| 171 | + * @param string $input |
|
| 172 | + */ |
|
| 158 | 173 | function gensalt_blowfish($input) |
| 159 | 174 | { |
| 160 | 175 | // This one needs to use a different order of characters and a |
@@ -24,7 +24,8 @@ discard block |
||
| 24 | 24 | // Obviously, since this code is in the public domain, the above are not |
| 25 | 25 | // requirements (there can be none), but merely suggestions. |
| 26 | 26 | // |
| 27 | -class PasswordHash { |
|
| 27 | +class PasswordHash |
|
| 28 | +{ |
|
| 28 | 29 | var $itoa64; |
| 29 | 30 | var $iteration_count_log2; |
| 30 | 31 | var $portable_hashes; |
@@ -34,8 +35,9 @@ discard block |
||
| 34 | 35 | { |
| 35 | 36 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 36 | 37 | |
| 37 | - if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) |
|
| 38 | - $iteration_count_log2 = 8; |
|
| 38 | + if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) { |
|
| 39 | + $iteration_count_log2 = 8; |
|
| 40 | + } |
|
| 39 | 41 | $this->iteration_count_log2 = $iteration_count_log2; |
| 40 | 42 | |
| 41 | 43 | $this->portable_hashes = $portable_hashes; |
@@ -73,16 +75,20 @@ discard block |
||
| 73 | 75 | do { |
| 74 | 76 | $value = ord($input[$i++]); |
| 75 | 77 | $output .= $this->itoa64[$value & 0x3f]; |
| 76 | - if ($i < $count) |
|
| 77 | - $value |= ord($input[$i]) << 8; |
|
| 78 | + if ($i < $count) { |
|
| 79 | + $value |= ord($input[$i]) << 8; |
|
| 80 | + } |
|
| 78 | 81 | $output .= $this->itoa64[($value >> 6) & 0x3f]; |
| 79 | - if ($i++ >= $count) |
|
| 80 | - break; |
|
| 81 | - if ($i < $count) |
|
| 82 | - $value |= ord($input[$i]) << 16; |
|
| 82 | + if ($i++ >= $count) { |
|
| 83 | + break; |
|
| 84 | + } |
|
| 85 | + if ($i < $count) { |
|
| 86 | + $value |= ord($input[$i]) << 16; |
|
| 87 | + } |
|
| 83 | 88 | $output .= $this->itoa64[($value >> 12) & 0x3f]; |
| 84 | - if ($i++ >= $count) |
|
| 85 | - break; |
|
| 89 | + if ($i++ >= $count) { |
|
| 90 | + break; |
|
| 91 | + } |
|
| 86 | 92 | $output .= $this->itoa64[($value >> 18) & 0x3f]; |
| 87 | 93 | } while ($i < $count); |
| 88 | 94 | |
@@ -101,23 +107,27 @@ discard block |
||
| 101 | 107 | function crypt_private($password, $setting) |
| 102 | 108 | { |
| 103 | 109 | $output = '*0'; |
| 104 | - if (substr($setting, 0, 2) == $output) |
|
| 105 | - $output = '*1'; |
|
| 110 | + if (substr($setting, 0, 2) == $output) { |
|
| 111 | + $output = '*1'; |
|
| 112 | + } |
|
| 106 | 113 | |
| 107 | 114 | $id = substr($setting, 0, 3); |
| 108 | 115 | // We use "$P$", phpBB3 uses "$H$" for the same thing |
| 109 | - if ($id != '$P$' && $id != '$H$') |
|
| 110 | - return $output; |
|
| 116 | + if ($id != '$P$' && $id != '$H$') { |
|
| 117 | + return $output; |
|
| 118 | + } |
|
| 111 | 119 | |
| 112 | 120 | $count_log2 = strpos($this->itoa64, $setting[3]); |
| 113 | - if ($count_log2 < 7 || $count_log2 > 30) |
|
| 114 | - return $output; |
|
| 121 | + if ($count_log2 < 7 || $count_log2 > 30) { |
|
| 122 | + return $output; |
|
| 123 | + } |
|
| 115 | 124 | |
| 116 | 125 | $count = 1 << $count_log2; |
| 117 | 126 | |
| 118 | 127 | $salt = substr($setting, 4, 8); |
| 119 | - if (strlen($salt) != 8) |
|
| 120 | - return $output; |
|
| 128 | + if (strlen($salt) != 8) { |
|
| 129 | + return $output; |
|
| 130 | + } |
|
| 121 | 131 | |
| 122 | 132 | // We're kind of forced to use MD5 here since it's the only |
| 123 | 133 | // cryptographic primitive available in all versions of PHP |
@@ -208,26 +218,31 @@ discard block |
||
| 208 | 218 | $random = $this->get_random_bytes(16); |
| 209 | 219 | $hash = |
| 210 | 220 | crypt($password, $this->gensalt_blowfish($random)); |
| 211 | - if (strlen($hash) == 60) |
|
| 212 | - return $hash; |
|
| 221 | + if (strlen($hash) == 60) { |
|
| 222 | + return $hash; |
|
| 223 | + } |
|
| 213 | 224 | } |
| 214 | 225 | |
| 215 | 226 | if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
| 216 | - if (strlen($random) < 3) |
|
| 217 | - $random = $this->get_random_bytes(3); |
|
| 227 | + if (strlen($random) < 3) { |
|
| 228 | + $random = $this->get_random_bytes(3); |
|
| 229 | + } |
|
| 218 | 230 | $hash = |
| 219 | 231 | crypt($password, $this->gensalt_extended($random)); |
| 220 | - if (strlen($hash) == 20) |
|
| 221 | - return $hash; |
|
| 232 | + if (strlen($hash) == 20) { |
|
| 233 | + return $hash; |
|
| 234 | + } |
|
| 222 | 235 | } |
| 223 | 236 | |
| 224 | - if (strlen($random) < 6) |
|
| 225 | - $random = $this->get_random_bytes(6); |
|
| 237 | + if (strlen($random) < 6) { |
|
| 238 | + $random = $this->get_random_bytes(6); |
|
| 239 | + } |
|
| 226 | 240 | $hash = |
| 227 | 241 | $this->crypt_private($password, |
| 228 | 242 | $this->gensalt_private($random)); |
| 229 | - if (strlen($hash) == 34) |
|
| 230 | - return $hash; |
|
| 243 | + if (strlen($hash) == 34) { |
|
| 244 | + return $hash; |
|
| 245 | + } |
|
| 231 | 246 | |
| 232 | 247 | // Returning '*' on error is safe here, but would _not_ be safe |
| 233 | 248 | // in a crypt(3)-like function used _both_ for generating new |
@@ -242,8 +257,9 @@ discard block |
||
| 242 | 257 | } |
| 243 | 258 | |
| 244 | 259 | $hash = $this->crypt_private($password, $stored_hash); |
| 245 | - if (substr($hash,0,1) === '*') |
|
| 246 | - $hash = crypt($password, $stored_hash); |
|
| 260 | + if (substr($hash,0,1) === '*') { |
|
| 261 | + $hash = crypt($password, $stored_hash); |
|
| 262 | + } |
|
| 247 | 263 | |
| 248 | 264 | return ($hash===$stored_hash) ? true : false; |
| 249 | 265 | } |