Completed
Push — develop ( 494db2...f707aa )
by Dmytro
06:13
created
install/cli-install.php 1 patch
Braces   +101 added lines, -67 removed lines patch added patch discarded remove patch
@@ -57,10 +57,12 @@  discard block
 block discarded – undo
57 57
 
58 58
 $args = array_slice($argv, 1);
59 59
 
60
-if ( empty($args) ){
60
+if ( empty($args) ) {
61 61
     echo 'Install Evolution CMS?'.PHP_EOL;
62 62
     $installYes = readline("Type 'y' to continue: ");
63
-    if ($installYes != 'y') return;
63
+    if ($installYes != 'y') {
64
+        return;
65
+    }
64 66
 
65 67
     //set param manual
66 68
     $databasehost = readline($_lang['connection_screen_database_host']. ' [localhost] ');
@@ -76,7 +78,7 @@  discard block
 block discarded – undo
76 78
     $managerlanguage = readline('Мanager language:' . ' [en] ');
77 79
     $installData = readline('Instal demo-site (y/n):' . ' [n] ');
78 80
     
79
-}else{
81
+} else {
80 82
     
81 83
     $cli_variables = [];
82 84
     foreach ($args as $arg) {
@@ -130,21 +132,24 @@  discard block
 block discarded – undo
130 132
 }
131 133
 
132 134
 //////////////////////////////////////////////////////////////////////////////////////
133
-if( ! function_exists('f_owc')){
135
+if( ! function_exists('f_owc')) {
134 136
     /**
135 137
      * @param $path
136 138
      * @param $data
137 139
      * @param null|int $mode
138 140
      */
139
-    function f_owc($path, $data, $mode = null){
141
+    function f_owc($path, $data, $mode = null)
142
+    {
140 143
         try {
141 144
             // make an attempt to create the file
142 145
             $hnd = fopen($path, 'w');
143 146
             fwrite($hnd, $data);
144 147
             fclose($hnd);
145 148
 
146
-            if(null !== $mode) chmod($path, $mode);
147
-        }catch(Exception $e){
149
+            if(null !== $mode) {
150
+                chmod($path, $mode);
151
+            }
152
+        } catch(Exception $e) {
148 153
             // Nothing, this is NOT normal
149 154
             unset($e);
150 155
         }
@@ -210,7 +215,7 @@  discard block
 block discarded – undo
210 215
 
211 216
 // File Browser directories exists?
212 217
 echo strip_tags($_lang['checking_if_images_exist']);
213
-switch(true){
218
+switch(true) {
214 219
     case !file_exists($path."../assets/images"):
215 220
     case !file_exists($path."../assets/files"):
216 221
     case !file_exists($path."../assets/backup"):
@@ -225,7 +230,7 @@  discard block
 block discarded – undo
225 230
 
226 231
 // File Browser directories writable?
227 232
 echo strip_tags($_lang['checking_if_images_writable']);
228
-switch(true){
233
+switch(true) {
229 234
     case !is_writable($path."../assets/images"):
230 235
     case !is_writable($path."../assets/files"):
231 236
     case !is_writable($path."../assets/backup"):
@@ -361,7 +366,7 @@  discard block
 block discarded – undo
361 366
 if ($conn) {
362 367
     echo $_lang['checking_mysql_strict_mode'];
363 368
     $mysqlmode = mysqli_query($conn, "SELECT @@global.sql_mode");
364
-    if (mysqli_num_rows($mysqlmode) > 0){
369
+    if (mysqli_num_rows($mysqlmode) > 0) {
365 370
         $modes = mysqli_fetch_array($mysqlmode, MYSQLI_NUM);
366 371
         //$modes = array("STRICT_TRANS_TABLES"); // for testing
367 372
         // print_r($modes);
@@ -397,9 +402,9 @@  discard block
 block discarded – undo
397 402
 if ($errors > 0) {
398 403
     echo $_lang['setup_cannot_continue'] . ' ';
399 404
 
400
-    if($errors > 1){
405
+    if($errors > 1) {
401 406
         echo $errors . " " . $_lang['errors'] . $_lang['please_correct_errors'] . $_lang['and_try_again_plural'];
402
-    }else{
407
+    } else {
403 408
         echo $_lang['error'] . $_lang['please_correct_error'] . $_lang['and_try_again']. PHP_EOL;
404 409
     }
405 410
 
@@ -445,13 +450,15 @@  discard block
 block discarded – undo
445 450
 
446 451
 // get base path and url
447 452
 $a = explode("install", str_replace("\\", "/", dirname($_SERVER["PHP_SELF"])));
448
-if (count($a) > 1)
453
+if (count($a) > 1) {
449 454
     array_pop($a);
455
+}
450 456
 $url = implode("install", $a);
451 457
 reset($a);
452 458
 $a = explode("install", str_replace("\\", "/", realpath(dirname(__FILE__))));
453
-if (count($a) > 1)
459
+if (count($a) > 1) {
454 460
     array_pop($a);
461
+}
455 462
 $pth = implode("install", $a);
456 463
 unset ($a);
457 464
 $base_url = $url . (substr($url, -1) != "/" ? "/" : "");
@@ -472,7 +479,9 @@  discard block
 block discarded – undo
472 479
     echo $_lang['setup_database_selection_failed']." ".$_lang['setup_database_selection_failed_note'].PHP_EOL;
473 480
     $create = true;
474 481
 } else {
475
-    if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_charset);
482
+    if (function_exists('mysqli_set_charset')) {
483
+        mysqli_set_charset($conn, $database_charset);
484
+    }
476 485
     mysqli_query($conn, "{$database_connection_method} {$database_connection_charset}");
477 486
     echo $_lang['ok'].PHP_EOL;
478 487
 }
@@ -518,7 +527,8 @@  discard block
 block discarded – undo
518 527
      * @param string $propertyString
519 528
      * @return array
520 529
      */
521
-    function parseProperties($propertyString) {
530
+    function parseProperties($propertyString)
531
+    {
522 532
         $parameter= array ();
523 533
         if (!empty ($propertyString)) {
524 534
             $tmpParams= explode("&", $propertyString);
@@ -527,11 +537,14 @@  discard block
 block discarded – undo
527 537
                 if (strpos($tmpParams[$x], '=', 0)) {
528 538
                     $pTmp= explode("=", $tmpParams[$x]);
529 539
                     $pvTmp= explode(";", trim($pTmp[1]));
530
-                    if ($pvTmp[1] == 'list' && $pvTmp[3] != "")
531
-                        $parameter[trim($pTmp[0])]= $pvTmp[3]; //list default
540
+                    if ($pvTmp[1] == 'list' && $pvTmp[3] != "") {
541
+                                            $parameter[trim($pTmp[0])]= $pvTmp[3];
542
+                    }
543
+                    //list default
532 544
                     else
533
-                        if ($pvTmp[1] != 'list' && $pvTmp[2] != "")
534
-                            $parameter[trim($pTmp[0])]= $pvTmp[2];
545
+                        if ($pvTmp[1] != 'list' && $pvTmp[2] != "") {
546
+                                                    $parameter[trim($pTmp[0])]= $pvTmp[2];
547
+                        }
535 548
                 }
536 549
             }
537 550
         }
@@ -579,12 +592,12 @@  discard block
 block discarded – undo
579 592
 $mt = &$moduleTemplates;
580 593
 if(is_dir($templatePath) && is_readable($templatePath)) {
581 594
     $d = dir($templatePath);
582
-    while (false !== ($tplfile = $d->read()))
583
-    {
584
-        if(substr($tplfile, -4) != '.tpl') continue;
595
+    while (false !== ($tplfile = $d->read())) {
596
+        if(substr($tplfile, -4) != '.tpl') {
597
+            continue;
598
+        }
585 599
         $params = parse_docblock($templatePath, $tplfile);
586
-        if(is_array($params) && (count($params)>0))
587
-        {
600
+        if(is_array($params) && (count($params)>0)) {
588 601
             $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
589 602
             $mt[] = array
590 603
             (
@@ -608,7 +621,9 @@  discard block
 block discarded – undo
608 621
 if(is_dir($tvPath) && is_readable($tvPath)) {
609 622
     $d = dir($tvPath);
610 623
     while (false !== ($tplfile = $d->read())) {
611
-        if(substr($tplfile, -4) != '.tpl') continue;
624
+        if(substr($tplfile, -4) != '.tpl') {
625
+            continue;
626
+        }
612 627
         $params = parse_docblock($tvPath, $tplfile);
613 628
         if(is_array($params) && (count($params)>0)) {
614 629
             $description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}";
@@ -801,7 +816,8 @@  discard block
 block discarded – undo
801 816
 // setup callback function
802 817
 $callBackFnc = "clean_up";
803 818
 
804
-function clean_up($sqlParser) {
819
+function clean_up($sqlParser)
820
+{
805 821
     $ids = array();
806 822
 
807 823
     // secure web documents - privateweb
@@ -814,9 +830,10 @@  discard block
 block discarded – undo
814 830
     $ds = mysqli_query($sqlParser->conn,$sql);
815 831
     if(!$ds) {
816 832
         echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn);
817
-    }
818
-    else {
819
-        while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"];
833
+    } else {
834
+        while($r = mysqli_fetch_assoc($ds)) {
835
+            $ids[]=$r["id"];
836
+        }
820 837
         if(count($ids)>0) {
821 838
             mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 1 WHERE id IN (".implode(", ",$ids).")");
822 839
             unset($ids);
@@ -833,9 +850,10 @@  discard block
 block discarded – undo
833 850
     $ds = mysqli_query($sqlParser->conn,$sql);
834 851
     if(!$ds) {
835 852
         echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn);
836
-    }
837
-    else {
838
-        while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"];
853
+    } else {
854
+        while($r = mysqli_fetch_assoc($ds)) {
855
+            $ids[]=$r["id"];
856
+        }
839 857
         if(count($ids)>0) {
840 858
             mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 1 WHERE id IN (".implode(", ",$ids).")");
841 859
             unset($ids);
@@ -843,7 +861,8 @@  discard block
 block discarded – undo
843 861
     }
844 862
 }
845 863
 
846
-function parse_docblock($element_dir, $filename) {
864
+function parse_docblock($element_dir, $filename)
865
+{
847 866
     $params = array();
848 867
     $fullpath = $element_dir . '/' . $filename;
849 868
     if(is_readable($fullpath)) {
@@ -944,7 +963,7 @@  discard block
 block discarded – undo
944 963
 // custom or not
945 964
 if (file_exists($path."../assets/cache/siteManager.php")) {
946 965
     $mgrdir = 'include_once(dirname(__FILE__)."/../../assets/cache/siteManager.php");';
947
-}else{
966
+} else {
948 967
     $mgrdir = 'define(\'MGR_DIR\', \'manager\');';
949 968
 }
950 969
 
@@ -1084,7 +1103,9 @@  discard block
 block discarded – undo
1084 1103
                         echo mysqli_error($sqlParser->conn) . PHP_EOL;
1085 1104
                         die();
1086 1105
                     }
1087
-                    if(!is_null($save_sql_id_as)) $custom_placeholders[$save_sql_id_as] = @mysqli_insert_id($sqlParser->conn);
1106
+                    if(!is_null($save_sql_id_as)) {
1107
+                        $custom_placeholders[$save_sql_id_as] = @mysqli_insert_id($sqlParser->conn);
1108
+                    }
1088 1109
                     echo "  $name: " . $_lang['installed'] . PHP_EOL;
1089 1110
                 }
1090 1111
             }
@@ -1179,9 +1200,9 @@  discard block
 block discarded – undo
1179 1200
             $overwrite = mysqli_real_escape_string($conn, $moduleChunk[4]);
1180 1201
             $filecontent = $moduleChunk[2];
1181 1202
 
1182
-            if (!file_exists($filecontent))
1183
-                echo "  $name: " . $_lang['unable_install_chunk'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1184
-            else {
1203
+            if (!file_exists($filecontent)) {
1204
+                            echo "  $name: " . $_lang['unable_install_chunk'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1205
+            } else {
1185 1206
 
1186 1207
                 // Create the category if it does not already exist
1187 1208
                 $category_id = getCreateDbCategory($category, $sqlParser);
@@ -1234,9 +1255,9 @@  discard block
 block discarded – undo
1234 1255
             $guid = mysqli_real_escape_string($conn, $moduleModule[4]);
1235 1256
             $shared = mysqli_real_escape_string($conn, $moduleModule[5]);
1236 1257
             $category = mysqli_real_escape_string($conn, $moduleModule[6]);
1237
-            if (!file_exists($filecontent))
1238
-                echo "  $name: " . $_lang['unable_install_module'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1239
-            else {
1258
+            if (!file_exists($filecontent)) {
1259
+                            echo "  $name: " . $_lang['unable_install_module'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1260
+            } else {
1240 1261
 
1241 1262
                 // Create the category if it does not already exist
1242 1263
                 $category = getCreateDbCategory($category, $sqlParser);
@@ -1254,7 +1275,7 @@  discard block
 block discarded – undo
1254 1275
                     }
1255 1276
                     echo "  $name: " . $_lang['upgraded'] . PHP_EOL;
1256 1277
                 } else {
1257
-                    if ($properties != NULL ){
1278
+                    if ($properties != NULL ) {
1258 1279
                         $properties = mysqli_real_escape_string($conn, parseProperties($properties, true));
1259 1280
                     }
1260 1281
                     if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_modules` (name,description,modulecode,properties,guid,enable_sharedparams,category) VALUES('$name','$desc','$module','$properties','$guid','$shared', $category);")) {
@@ -1289,9 +1310,9 @@  discard block
 block discarded – undo
1289 1310
                 // parse comma-separated legacy names and prepare them for sql IN clause
1290 1311
                 $leg_names = "'" . implode("','", preg_split('/\s*,\s*/', mysqli_real_escape_string($conn, $modulePlugin[7]))) . "'";
1291 1312
             }
1292
-            if (!file_exists($filecontent))
1293
-                echo "  $name: " . $_lang['unable_install_plugin'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1294
-            else {
1313
+            if (!file_exists($filecontent)) {
1314
+                            echo "  $name: " . $_lang['unable_install_plugin'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1315
+            } else {
1295 1316
 
1296 1317
                 // disable legacy versions based on legacy_names provided
1297 1318
                 if(!empty($leg_names)) {
@@ -1310,7 +1331,7 @@  discard block
 block discarded – undo
1310 1331
                     $insert = true;
1311 1332
                     while($row = mysqli_fetch_assoc($rs)) {
1312 1333
                         $props = mysqli_real_escape_string($conn, propUpdate($properties,$row['properties']));
1313
-                        if($row['description'] == $desc){
1334
+                        if($row['description'] == $desc) {
1314 1335
                             if (! mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_plugins` SET plugincode='$plugin', description='$desc', properties='$props' WHERE id={$row['id']};")) {
1315 1336
                                 echo mysqli_error($sqlParser->conn) . PHP_EOL;
1316 1337
                                 return;
@@ -1332,7 +1353,7 @@  discard block
 block discarded – undo
1332 1353
                     }
1333 1354
                     echo "  $name: " . $_lang['upgraded'] . PHP_EOL;
1334 1355
                 } else {
1335
-                    if ($properties != NULL ){
1356
+                    if ($properties != NULL ) {
1336 1357
                         $properties = mysqli_real_escape_string($conn, parseProperties($properties, true));
1337 1358
                     }
1338 1359
                     if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_plugins` (name,description,plugincode,properties,moduleguid,category,disabled) VALUES('$name','$desc','$plugin','$properties','$guid',$category,$disabled);")) {
@@ -1371,9 +1392,9 @@  discard block
 block discarded – undo
1371 1392
             $filecontent = $moduleSnippet[2];
1372 1393
             $properties = $moduleSnippet[3];
1373 1394
             $category = mysqli_real_escape_string($conn, $moduleSnippet[4]);
1374
-            if (!file_exists($filecontent))
1375
-                echo "  $name: " . $_lang['unable_install_snippet'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1376
-            else {
1395
+            if (!file_exists($filecontent)) {
1396
+                            echo "  $name: " . $_lang['unable_install_snippet'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL;
1397
+            } else {
1377 1398
 
1378 1399
                 // Create the category if it does not already exist
1379 1400
                 $category = getCreateDbCategory($category, $sqlParser);
@@ -1391,7 +1412,7 @@  discard block
 block discarded – undo
1391 1412
                     }
1392 1413
                     echo "  $name: " . $_lang['upgraded'] . PHP_EOL;
1393 1414
                 } else {
1394
-                    if ($properties != NULL ){
1415
+                    if ($properties != NULL ) {
1395 1416
                         $properties = mysqli_real_escape_string($conn, parseProperties($properties, true));
1396 1417
                     }
1397 1418
                     if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_snippets` (name,description,snippet,properties,category) VALUES('$name','$desc','$snippet','$properties',$category);")) {
@@ -1484,11 +1505,14 @@  discard block
 block discarded – undo
1484 1505
 }
1485 1506
 
1486 1507
 // call back function
1487
-if ($callBackFnc != "")
1508
+if ($callBackFnc != "") {
1488 1509
     $callBackFnc ($sqlParser);
1510
+}
1489 1511
 
1490 1512
 // Setup the MODX API -- needed for the cache processor
1491
-if (!defined('MODX_MANAGER_PATH')) define('MODX_MANAGER_PATH', $base_path.MGR_DIR.'/');
1513
+if (!defined('MODX_MANAGER_PATH')) {
1514
+    define('MODX_MANAGER_PATH', $base_path.MGR_DIR.'/');
1515
+}
1492 1516
 $database_type = 'mysqli';
1493 1517
 // initiate a new document parser
1494 1518
 include_once($path.'../'.MGR_DIR.'/includes/document.parser.class.inc.php');
@@ -1527,7 +1551,7 @@  discard block
 block discarded – undo
1527 1551
 }
1528 1552
 
1529 1553
 
1530
-if ( empty($args) ){
1554
+if ( empty($args) ) {
1531 1555
     echo PHP_EOL . 'Remove install folder?'.PHP_EOL;
1532 1556
     $removeInstall = readline("Type 'y' or 'n' to continue: ");
1533 1557
 }
@@ -1543,11 +1567,12 @@  discard block
 block discarded – undo
1543 1567
  * @param string $old
1544 1568
  * @return string
1545 1569
  */
1546
-function propUpdate($new,$old){
1570
+function propUpdate($new,$old)
1571
+{
1547 1572
     $newArr = parseProperties($new);
1548 1573
     $oldArr = parseProperties($old);
1549
-    foreach ($oldArr as $k => $v){
1550
-        if (isset($v['0']['options'])){
1574
+    foreach ($oldArr as $k => $v) {
1575
+        if (isset($v['0']['options'])) {
1551 1576
             $oldArr[$k]['0']['options'] = $newArr[$k]['0']['options'];
1552 1577
         }
1553 1578
     }
@@ -1562,12 +1587,17 @@  discard block
 block discarded – undo
1562 1587
  * @param bool|mixed $json
1563 1588
  * @return string
1564 1589
  */
1565
-function parseProperties($propertyString, $json=false) {
1590
+function parseProperties($propertyString, $json=false)
1591
+{
1566 1592
     $propertyString = str_replace('{}', '', $propertyString );
1567 1593
     $propertyString = str_replace('} {', ',', $propertyString );
1568 1594
 
1569
-    if(empty($propertyString)) return array();
1570
-    if($propertyString=='{}' || $propertyString=='[]') return array();
1595
+    if(empty($propertyString)) {
1596
+        return array();
1597
+    }
1598
+    if($propertyString=='{}' || $propertyString=='[]') {
1599
+        return array();
1600
+    }
1571 1601
 
1572 1602
     $jsonFormat = isJson($propertyString, true);
1573 1603
     $property = array();
@@ -1609,7 +1639,7 @@  discard block
 block discarded – undo
1609 1639
 
1610 1640
         }
1611 1641
     // new json-format
1612
-    } else if(!empty($jsonFormat)){
1642
+    } else if(!empty($jsonFormat)) {
1613 1643
         $property = $jsonFormat;
1614 1644
     }
1615 1645
     if ($json) {
@@ -1624,7 +1654,8 @@  discard block
 block discarded – undo
1624 1654
  * @param bool $returnData
1625 1655
  * @return bool|mixed
1626 1656
  */
1627
-function isJson($string, $returnData=false) {
1657
+function isJson($string, $returnData=false)
1658
+{
1628 1659
     $data = json_decode($string, true);
1629 1660
     return (json_last_error() == JSON_ERROR_NONE) ? ($returnData ? $data : true) : false;
1630 1661
 }
@@ -1634,7 +1665,8 @@  discard block
 block discarded – undo
1634 1665
  * @param SqlParser $sqlParser
1635 1666
  * @return int
1636 1667
  */
1637
-function getCreateDbCategory($category, $sqlParser) {
1668
+function getCreateDbCategory($category, $sqlParser)
1669
+{
1638 1670
     $dbase = $sqlParser->dbname;
1639 1671
     $dbase = '`' . trim($dbase,'`') . '`';
1640 1672
     $table_prefix = $sqlParser->prefix;
@@ -1662,7 +1694,8 @@  discard block
 block discarded – undo
1662 1694
  * @param string $type
1663 1695
  * @return string
1664 1696
  */
1665
-function removeDocblock($code, $type) {
1697
+function removeDocblock($code, $type)
1698
+{
1666 1699
 
1667 1700
     $cleaned = preg_replace("/^.*?\/\*\*.*?\*\/\s+/s", '', $code, 1);
1668 1701
 
@@ -1683,8 +1716,9 @@  discard block
 block discarded – undo
1683 1716
         default:
1684 1717
             return $cleaned;
1685 1718
     };
1686
-    if(substr(trim($cleaned),0,$count) == $include.' MODX_BASE_PATH.\'assets/'.$elm_name.'/')
1687
-        return $cleaned;
1719
+    if(substr(trim($cleaned),0,$count) == $include.' MODX_BASE_PATH.\'assets/'.$elm_name.'/') {
1720
+            return $cleaned;
1721
+    }
1688 1722
 
1689 1723
     // fileBinding not found - return code incl docblock
1690 1724
     return $code;
Please login to merge, or discard this patch.