Completed
Push — develop ( 4a4b5c...62a102 )
by Maxim
16s
created
install/actions/action_connection.php 1 patch
Braces   +12 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,21 +9,24 @@
 block discarded – undo
9 9
     $table_prefix= substr(md5(time()), rand(0, 27), rand(3, 5))."_";
10 10
 } else {
11 11
     $database_name = '';
12
-    if (!is_file($base_path.MGR_DIR.'/includes/config.inc.php')) $upgradeable = 0;
13
-    else {
12
+    if (!is_file($base_path.MGR_DIR.'/includes/config.inc.php')) {
13
+        $upgradeable = 0;
14
+    } else {
14 15
         // Include the file so we can test its validity
15 16
         include($base_path.MGR_DIR.'/includes/config.inc.php');
16 17
         // We need to have all connection settings - but prefix may be empty so we have to ignore it
17 18
         if ($dbase) {
18 19
             $database_name = trim($dbase, '`');
19
-            if (!$conn = mysqli_connect($database_server, $database_user, $database_password))
20
-                $upgradeable = (isset($_POST['installmode']) && $_POST['installmode']=='new') ? 0 : 2;
21
-            elseif (! mysqli_select_db($conn, trim($dbase, '`')))
22
-                $upgradeable = (isset($_POST['installmode']) && $_POST['installmode']=='new') ? 0 : 2;
23
-            else
24
-                $upgradeable = 1;
20
+            if (!$conn = mysqli_connect($database_server, $database_user, $database_password)) {
21
+                            $upgradeable = (isset($_POST['installmode']) && $_POST['installmode']=='new') ? 0 : 2;
22
+            } elseif (! mysqli_select_db($conn, trim($dbase, '`'))) {
23
+                            $upgradeable = (isset($_POST['installmode']) && $_POST['installmode']=='new') ? 0 : 2;
24
+            } else {
25
+                            $upgradeable = 1;
26
+            }
27
+        } else {
28
+            $upgradable= 2;
25 29
         }
26
-        else $upgradable= 2;
27 30
     }
28 31
 }
29 32
 
Please login to merge, or discard this patch.
install/sqlParser.class.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -4,141 +4,141 @@
 block discarded – undo
4 4
 // SNUFFKIN/ Alex 2004
5 5
 
6 6
 class SqlParser {
7
-	public $host;
8
-	public $dbname;
9
-	public $prefix;
10
-	public $user;
11
-	public $password;
12
-	public $mysqlErrors;
13
-	public $conn;
14
-	public $installFailed;
15
-	public $sitename;
16
-	public $adminname;
17
-	public $adminemail;
18
-	public $adminpass;
19
-	public $managerlanguage;
20
-	public $mode;
21
-	public $fileManagerPath;
22
-	public $imgPath;
23
-	public $imgUrl;
24
-	public $dbMODx;
25
-	public $dbVersion;
7
+    public $host;
8
+    public $dbname;
9
+    public $prefix;
10
+    public $user;
11
+    public $password;
12
+    public $mysqlErrors;
13
+    public $conn;
14
+    public $installFailed;
15
+    public $sitename;
16
+    public $adminname;
17
+    public $adminemail;
18
+    public $adminpass;
19
+    public $managerlanguage;
20
+    public $mode;
21
+    public $fileManagerPath;
22
+    public $imgPath;
23
+    public $imgUrl;
24
+    public $dbMODx;
25
+    public $dbVersion;
26 26
     public $connection_charset;
27 27
     public $connection_method;
28 28
     public $ignoreDuplicateErrors;
29 29
     public $autoTemplateLogic;
30 30
 
31
-	public function __construct($host, $user, $password, $db, $prefix='modx_', $adminname, $adminemail, $adminpass, $connection_charset= 'utf8', $managerlanguage='english', $connection_method = 'SET CHARACTER SET', $auto_template_logic = 'parent') {
32
-		$this->host = $host;
33
-		$this->dbname = $db;
34
-		$this->prefix = $prefix;
35
-		$this->user = $user;
36
-		$this->password = $password;
37
-		$this->adminpass = $adminpass;
38
-		$this->adminname = $adminname;
39
-		$this->adminemail = $adminemail;
40
-		$this->connection_charset = $connection_charset;
41
-		$this->connection_method = $connection_method;
42
-		$this->ignoreDuplicateErrors = false;
43
-		$this->managerlanguage = $managerlanguage;
31
+    public function __construct($host, $user, $password, $db, $prefix='modx_', $adminname, $adminemail, $adminpass, $connection_charset= 'utf8', $managerlanguage='english', $connection_method = 'SET CHARACTER SET', $auto_template_logic = 'parent') {
32
+        $this->host = $host;
33
+        $this->dbname = $db;
34
+        $this->prefix = $prefix;
35
+        $this->user = $user;
36
+        $this->password = $password;
37
+        $this->adminpass = $adminpass;
38
+        $this->adminname = $adminname;
39
+        $this->adminemail = $adminemail;
40
+        $this->connection_charset = $connection_charset;
41
+        $this->connection_method = $connection_method;
42
+        $this->ignoreDuplicateErrors = false;
43
+        $this->managerlanguage = $managerlanguage;
44 44
         $this->autoTemplateLogic = $auto_template_logic;
45
-	}
45
+    }
46 46
 
47
-	public function connect() {
48
-		$this->conn = mysqli_connect($this->host, $this->user, $this->password);
49
-		mysqli_select_db($this->conn, $this->dbname);
50
-		if (function_exists('mysqli_set_charset')) mysqli_set_charset($this->conn, $this->connection_charset);
47
+    public function connect() {
48
+        $this->conn = mysqli_connect($this->host, $this->user, $this->password);
49
+        mysqli_select_db($this->conn, $this->dbname);
50
+        if (function_exists('mysqli_set_charset')) mysqli_set_charset($this->conn, $this->connection_charset);
51 51
 
52
-		$this->dbVersion = 3.23; // assume version 3.23
53
-		if(function_exists("mysqli_get_server_info")) {
54
-			$ver = mysqli_get_server_info($this->conn);
55
-			$this->dbMODx 	 = version_compare($ver,"4.0.2");
56
-			$this->dbVersion = (float) $ver; // Typecasting (float) instead of floatval() [PHP < 4.2]
57
-		}
52
+        $this->dbVersion = 3.23; // assume version 3.23
53
+        if(function_exists("mysqli_get_server_info")) {
54
+            $ver = mysqli_get_server_info($this->conn);
55
+            $this->dbMODx 	 = version_compare($ver,"4.0.2");
56
+            $this->dbVersion = (float) $ver; // Typecasting (float) instead of floatval() [PHP < 4.2]
57
+        }
58 58
 
59 59
         mysqli_query($this->conn,"{$this->connection_method} {$this->connection_charset}");
60
-	}
60
+    }
61 61
 
62 62
     public function process($filename) {
63
-	    global $custom_placeholders;
64
-
65
-		// check to make sure file exists
66
-		if (!file_exists($filename)) {
67
-			$this->mysqlErrors[] = array("error" => "File '$filename' not found");
68
-			$this->installFailed = true ;
69
-			return false;
70
-		}
71
-
72
-		$fh = fopen($filename, 'r');
73
-		$idata = '';
74
-
75
-		while (!feof($fh)) {
76
-			$idata .= fread($fh, 1024);
77
-		}
78
-
79
-		fclose($fh);
80
-		$idata = str_replace("\r", '', $idata);
81
-
82
-		// check if in upgrade mode
83
-		if ($this->mode === 'upd') {
84
-			// remove non-upgradeable parts
85
-			$s = strpos($idata,'non-upgrade-able[[');
86
-			$e = strpos($idata,']]non-upgrade-able') + 17;
87
-			if($s && $e) {
88
-			    $idata = str_replace(substr($idata, $s,$e-$s),' Removed non upgradeable items', $idata);
63
+        global $custom_placeholders;
64
+
65
+        // check to make sure file exists
66
+        if (!file_exists($filename)) {
67
+            $this->mysqlErrors[] = array("error" => "File '$filename' not found");
68
+            $this->installFailed = true ;
69
+            return false;
70
+        }
71
+
72
+        $fh = fopen($filename, 'r');
73
+        $idata = '';
74
+
75
+        while (!feof($fh)) {
76
+            $idata .= fread($fh, 1024);
77
+        }
78
+
79
+        fclose($fh);
80
+        $idata = str_replace("\r", '', $idata);
81
+
82
+        // check if in upgrade mode
83
+        if ($this->mode === 'upd') {
84
+            // remove non-upgradeable parts
85
+            $s = strpos($idata,'non-upgrade-able[[');
86
+            $e = strpos($idata,']]non-upgrade-able') + 17;
87
+            if($s && $e) {
88
+                $idata = str_replace(substr($idata, $s,$e-$s),' Removed non upgradeable items', $idata);
89 89
             }
90
-		}
91
-
92
-		// replace {} tags
93
-		$idata = str_replace('{PREFIX}', $this->prefix, $idata);
94
-		$idata = str_replace('{ADMIN}', $this->adminname, $idata);
95
-		$idata = str_replace('{ADMINEMAIL}', $this->adminemail, $idata);
96
-		$idata = str_replace('{ADMINPASS}', $this->adminpass, $idata);
97
-		$idata = str_replace('{IMAGEPATH}', $this->imgPath, $idata);
98
-		$idata = str_replace('{IMAGEURL}', $this->imgUrl, $idata);
99
-		$idata = str_replace('{FILEMANAGERPATH}', $this->fileManagerPath, $idata);
100
-		$idata = str_replace('{MANAGERLANGUAGE}', $this->managerlanguage, $idata);
101
-		$idata = str_replace('{AUTOTEMPLATELOGIC}', $this->autoTemplateLogic, $idata);
102
-		/*$idata = str_replace('{VERSION}', $modx_version, $idata);*/
103
-
104
-		// Replace custom placeholders
105
-		foreach($custom_placeholders as $key=>$val) {
106
-			if (strpos($idata, '{'.$key.'}') !== false) {
107
-				$idata = str_replace('{'.$key.'}', $val, $idata);
108
-			}
109
-		}
110
-
111
-		$sql_array = explode("\n\n", $idata);
112
-
113
-		$num = 0;
114
-		foreach($sql_array as $sql_entry) {
115
-			$sql_do = trim($sql_entry, "\r\n; ");
116
-
117
-			if (preg_match('/^\#/', $sql_do)) continue;
118
-
119
-			// strip out comments and \n for mysql 3.x
120
-			if ($this->dbVersion <4.0) {
121
-				$sql_do = preg_replace("~COMMENT.*[^']?'.*[^']?'~","",$sql_do);
122
-				$sql_do = str_replace('\r', "", $sql_do);
123
-				$sql_do = str_replace('\n', "", $sql_do);
124
-			}
125
-
126
-
127
-			$num = $num + 1;
128
-			if ($sql_do) mysqli_query($this->conn, $sql_do);
129
-			if(mysqli_error($this->conn)) {
130
-				// Ignore duplicate and drop errors - Raymond
131
-				if ($this->ignoreDuplicateErrors){
132
-					if (mysqli_errno($this->conn) == 1060 || mysqli_errno($this->conn) == 1061 || mysqli_errno($this->conn) == 1062 ||mysqli_errno($this->conn) == 1091) continue;
133
-				}
134
-				// End Ignore duplicate
135
-				$this->mysqlErrors[] = array("error" => mysqli_error($this->conn), "sql" => $sql_do);
136
-				$this->installFailed = true;
137
-			}
138
-		}
139
-	}
90
+        }
91
+
92
+        // replace {} tags
93
+        $idata = str_replace('{PREFIX}', $this->prefix, $idata);
94
+        $idata = str_replace('{ADMIN}', $this->adminname, $idata);
95
+        $idata = str_replace('{ADMINEMAIL}', $this->adminemail, $idata);
96
+        $idata = str_replace('{ADMINPASS}', $this->adminpass, $idata);
97
+        $idata = str_replace('{IMAGEPATH}', $this->imgPath, $idata);
98
+        $idata = str_replace('{IMAGEURL}', $this->imgUrl, $idata);
99
+        $idata = str_replace('{FILEMANAGERPATH}', $this->fileManagerPath, $idata);
100
+        $idata = str_replace('{MANAGERLANGUAGE}', $this->managerlanguage, $idata);
101
+        $idata = str_replace('{AUTOTEMPLATELOGIC}', $this->autoTemplateLogic, $idata);
102
+        /*$idata = str_replace('{VERSION}', $modx_version, $idata);*/
103
+
104
+        // Replace custom placeholders
105
+        foreach($custom_placeholders as $key=>$val) {
106
+            if (strpos($idata, '{'.$key.'}') !== false) {
107
+                $idata = str_replace('{'.$key.'}', $val, $idata);
108
+            }
109
+        }
110
+
111
+        $sql_array = explode("\n\n", $idata);
112
+
113
+        $num = 0;
114
+        foreach($sql_array as $sql_entry) {
115
+            $sql_do = trim($sql_entry, "\r\n; ");
116
+
117
+            if (preg_match('/^\#/', $sql_do)) continue;
118
+
119
+            // strip out comments and \n for mysql 3.x
120
+            if ($this->dbVersion <4.0) {
121
+                $sql_do = preg_replace("~COMMENT.*[^']?'.*[^']?'~","",$sql_do);
122
+                $sql_do = str_replace('\r', "", $sql_do);
123
+                $sql_do = str_replace('\n', "", $sql_do);
124
+            }
125
+
126
+
127
+            $num = $num + 1;
128
+            if ($sql_do) mysqli_query($this->conn, $sql_do);
129
+            if(mysqli_error($this->conn)) {
130
+                // Ignore duplicate and drop errors - Raymond
131
+                if ($this->ignoreDuplicateErrors){
132
+                    if (mysqli_errno($this->conn) == 1060 || mysqli_errno($this->conn) == 1061 || mysqli_errno($this->conn) == 1062 ||mysqli_errno($this->conn) == 1091) continue;
133
+                }
134
+                // End Ignore duplicate
135
+                $this->mysqlErrors[] = array("error" => mysqli_error($this->conn), "sql" => $sql_do);
136
+                $this->installFailed = true;
137
+            }
138
+        }
139
+    }
140 140
 
141 141
     public function close() {
142
-		mysqli_close($this->conn);
143
-	}
142
+        mysqli_close($this->conn);
143
+    }
144 144
 }
Please login to merge, or discard this patch.
Braces   +23 added lines, -10 removed lines patch added patch discarded remove patch
@@ -3,7 +3,8 @@  discard block
 block discarded – undo
3 3
 // MySQL Dump Parser
4 4
 // SNUFFKIN/ Alex 2004
5 5
 
6
-class SqlParser {
6
+class SqlParser
7
+{
7 8
 	public $host;
8 9
 	public $dbname;
9 10
 	public $prefix;
@@ -28,7 +29,8 @@  discard block
 block discarded – undo
28 29
     public $ignoreDuplicateErrors;
29 30
     public $autoTemplateLogic;
30 31
 
31
-	public function __construct($host, $user, $password, $db, $prefix='modx_', $adminname, $adminemail, $adminpass, $connection_charset= 'utf8', $managerlanguage='english', $connection_method = 'SET CHARACTER SET', $auto_template_logic = 'parent') {
32
+	public function __construct($host, $user, $password, $db, $prefix='modx_', $adminname, $adminemail, $adminpass, $connection_charset= 'utf8', $managerlanguage='english', $connection_method = 'SET CHARACTER SET', $auto_template_logic = 'parent')
33
+	{
32 34
 		$this->host = $host;
33 35
 		$this->dbname = $db;
34 36
 		$this->prefix = $prefix;
@@ -44,10 +46,13 @@  discard block
 block discarded – undo
44 46
         $this->autoTemplateLogic = $auto_template_logic;
45 47
 	}
46 48
 
47
-	public function connect() {
49
+	public function connect()
50
+	{
48 51
 		$this->conn = mysqli_connect($this->host, $this->user, $this->password);
49 52
 		mysqli_select_db($this->conn, $this->dbname);
50
-		if (function_exists('mysqli_set_charset')) mysqli_set_charset($this->conn, $this->connection_charset);
53
+		if (function_exists('mysqli_set_charset')) {
54
+		    mysqli_set_charset($this->conn, $this->connection_charset);
55
+		}
51 56
 
52 57
 		$this->dbVersion = 3.23; // assume version 3.23
53 58
 		if(function_exists("mysqli_get_server_info")) {
@@ -59,7 +64,8 @@  discard block
 block discarded – undo
59 64
         mysqli_query($this->conn,"{$this->connection_method} {$this->connection_charset}");
60 65
 	}
61 66
 
62
-    public function process($filename) {
67
+    public function process($filename)
68
+    {
63 69
 	    global $custom_placeholders;
64 70
 
65 71
 		// check to make sure file exists
@@ -114,7 +120,9 @@  discard block
 block discarded – undo
114 120
 		foreach($sql_array as $sql_entry) {
115 121
 			$sql_do = trim($sql_entry, "\r\n; ");
116 122
 
117
-			if (preg_match('/^\#/', $sql_do)) continue;
123
+			if (preg_match('/^\#/', $sql_do)) {
124
+			    continue;
125
+			}
118 126
 
119 127
 			// strip out comments and \n for mysql 3.x
120 128
 			if ($this->dbVersion <4.0) {
@@ -125,11 +133,15 @@  discard block
 block discarded – undo
125 133
 
126 134
 
127 135
 			$num = $num + 1;
128
-			if ($sql_do) mysqli_query($this->conn, $sql_do);
136
+			if ($sql_do) {
137
+			    mysqli_query($this->conn, $sql_do);
138
+			}
129 139
 			if(mysqli_error($this->conn)) {
130 140
 				// Ignore duplicate and drop errors - Raymond
131
-				if ($this->ignoreDuplicateErrors){
132
-					if (mysqli_errno($this->conn) == 1060 || mysqli_errno($this->conn) == 1061 || mysqli_errno($this->conn) == 1062 ||mysqli_errno($this->conn) == 1091) continue;
141
+				if ($this->ignoreDuplicateErrors) {
142
+					if (mysqli_errno($this->conn) == 1060 || mysqli_errno($this->conn) == 1061 || mysqli_errno($this->conn) == 1062 ||mysqli_errno($this->conn) == 1091) {
143
+					    continue;
144
+					}
133 145
 				}
134 146
 				// End Ignore duplicate
135 147
 				$this->mysqlErrors[] = array("error" => mysqli_error($this->conn), "sql" => $sql_do);
@@ -138,7 +150,8 @@  discard block
 block discarded – undo
138 150
 		}
139 151
 	}
140 152
 
141
-    public function close() {
153
+    public function close()
154
+    {
142 155
 		mysqli_close($this->conn);
143 156
 	}
144 157
 }
Please login to merge, or discard this patch.
manager/actions/bkmanager.static.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -597,7 +597,9 @@
 block discarded – undo
597 597
                 $insertdump = $lf;
598 598
                 $insertdump .= "INSERT INTO `{$tblval}` VALUES (";
599 599
                 $arr = $this->object2Array($row);
600
-                if( ! is_array($arr)) $arr = array();
600
+                if( ! is_array($arr)) {
601
+                    $arr = array();
602
+                }
601 603
                 foreach ($arr as $key => $value) {
602 604
                     if (is_null($value)) {
603 605
                         $value = 'NULL';
Please login to merge, or discard this patch.
manager/actions/import_site.static.php 2 patches
Indentation   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3
-	die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
3
+    die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.");
4 4
 }
5 5
 if(!$modx->hasPermission('import_static')) {
6
-	$modx->webAlertAndQuit($_lang["error_no_privileges"]);
6
+    $modx->webAlertAndQuit($_lang["error_no_privileges"]);
7 7
 }
8 8
 
9 9
 // Files to upload
10 10
 $allowedfiles = array(
11
-	'html',
12
-	'htm',
13
-	'shtml',
14
-	'xml'
11
+    'html',
12
+    'htm',
13
+    'shtml',
14
+    'xml'
15 15
 );
16 16
 ?>
17 17
 	<script language="javascript">
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	<div class="tab-page">
44 44
 		<div class="container container-body">
45 45
 			<?php
46
-			if(!isset($_POST['import'])) {
47
-				echo "<div class=\"element-edit-message\">" . $_lang['import_site_message'] . "</div>";
48
-				?>
46
+            if(!isset($_POST['import'])) {
47
+                echo "<div class=\"element-edit-message\">" . $_lang['import_site_message'] . "</div>";
48
+                ?>
49 49
 				<form action="index.php" method="post" name="importFrm">
50 50
 					<input type="hidden" name="import" value="import" />
51 51
 					<input type="hidden" name="a" value="95" />
@@ -85,375 +85,375 @@  discard block
 block discarded – undo
85 85
 					<a href="javascript:;" class="btn btn-primary" onclick="window.importFrm.submit();"><i class="<?= $_style["actions_save"] ?>"></i> <?= $_lang["import_site_start"] ?></a>
86 86
 				</form>
87 87
 			<?php
88
-			} else {
89
-			run();
90
-			$modx->clearCache('full');
91
-			?>
88
+            } else {
89
+            run();
90
+            $modx->clearCache('full');
91
+            ?>
92 92
 				<a href="javascript:;" class="btn btn-primary" onclick="window.location.href='index.php?a=2';"><i class="<?= $_style["actions_close"] ?>"></i> <?= $_lang["close"] ?></a>
93 93
 				<script type="text/javascript">
94 94
 					top.mainMenu.reloadtree();
95 95
 					parent.tree.ca = 'open';
96 96
 				</script>
97 97
 				<?php
98
-			}
99
-			?>
98
+            }
99
+            ?>
100 100
 		</div>
101 101
 	</div>
102 102
 
103 103
 <?php
104 104
 function run() {
105
-	global $modx, $_lang;
105
+    global $modx, $_lang;
106 106
 
107
-	$tbl_site_content = $modx->getFullTableName('site_content');
108
-	$output = '';
109
-	$maxtime = $_POST['maxtime'];
107
+    $tbl_site_content = $modx->getFullTableName('site_content');
108
+    $output = '';
109
+    $maxtime = $_POST['maxtime'];
110 110
 
111
-	if(!is_numeric($maxtime)) {
112
-		$maxtime = 30;
113
-	}
111
+    if(!is_numeric($maxtime)) {
112
+        $maxtime = 30;
113
+    }
114 114
 
115
-	@set_time_limit($maxtime);
115
+    @set_time_limit($maxtime);
116 116
 
117
-	$mtime = microtime();
118
-	$mtime = explode(' ', $mtime);
119
-	$mtime = $mtime[1] + $mtime[0];
120
-	$importstart = $mtime;
117
+    $mtime = microtime();
118
+    $mtime = explode(' ', $mtime);
119
+    $mtime = $mtime[1] + $mtime[0];
120
+    $importstart = $mtime;
121 121
 
122
-	if($_POST['reset'] == 'on') {
123
-		$modx->db->truncate($tbl_site_content);
124
-		$modx->db->query("ALTER TABLE {$tbl_site_content} AUTO_INCREMENT = 1");
125
-	}
122
+    if($_POST['reset'] == 'on') {
123
+        $modx->db->truncate($tbl_site_content);
124
+        $modx->db->query("ALTER TABLE {$tbl_site_content} AUTO_INCREMENT = 1");
125
+    }
126 126
 
127
-	$parent = intval($_POST['parent']);
127
+    $parent = intval($_POST['parent']);
128 128
 
129
-	if(is_dir(MODX_BASE_PATH . 'temp/import')) {
130
-		$filedir = MODX_BASE_PATH . 'temp/import/';
131
-	} elseif(is_dir(MODX_BASE_PATH . 'assets/import')) {
132
-		$filedir = MODX_BASE_PATH . 'assets/import/';
133
-	} else {
129
+    if(is_dir(MODX_BASE_PATH . 'temp/import')) {
130
+        $filedir = MODX_BASE_PATH . 'temp/import/';
131
+    } elseif(is_dir(MODX_BASE_PATH . 'assets/import')) {
132
+        $filedir = MODX_BASE_PATH . 'assets/import/';
133
+    } else {
134 134
         $filedir = '';
135 135
     }
136 136
 
137
-	$filesfound = 0;
137
+    $filesfound = 0;
138 138
 
139
-	$files = getFiles($filedir);
140
-	$files = pop_index($files);
139
+    $files = getFiles($filedir);
140
+    $files = pop_index($files);
141 141
 
142
-	// no. of files to import
143
-	$output .= sprintf('<p>' . $_lang['import_files_found'] . '</p>', $filesfound);
142
+    // no. of files to import
143
+    $output .= sprintf('<p>' . $_lang['import_files_found'] . '</p>', $filesfound);
144 144
 
145
-	// import files
146
-	if(0 < count($files)) {
147
-		$modx->db->update(array('isfolder' => 1), $tbl_site_content, "id='{$parent}'");
148
-		importFiles($parent, $filedir, $files, 'root');
149
-	}
145
+    // import files
146
+    if(0 < count($files)) {
147
+        $modx->db->update(array('isfolder' => 1), $tbl_site_content, "id='{$parent}'");
148
+        importFiles($parent, $filedir, $files, 'root');
149
+    }
150 150
 
151
-	$mtime = microtime();
152
-	$mtime = explode(' ', $mtime);
153
-	$mtime = $mtime[1] + $mtime[0];
154
-	$importend = $mtime;
155
-	$totaltime = ($importend - $importstart);
156
-	$output .= sprintf('<p>' . $_lang['import_site_time'] . '</p>', round($totaltime, 3));
151
+    $mtime = microtime();
152
+    $mtime = explode(' ', $mtime);
153
+    $mtime = $mtime[1] + $mtime[0];
154
+    $importend = $mtime;
155
+    $totaltime = ($importend - $importstart);
156
+    $output .= sprintf('<p>' . $_lang['import_site_time'] . '</p>', round($totaltime, 3));
157 157
 
158
-	if($_POST['convert_link'] == 'on') {
159
-		convertLink();
160
-	}
158
+    if($_POST['convert_link'] == 'on') {
159
+        convertLink();
160
+    }
161 161
 
162
-	return $output;
162
+    return $output;
163 163
 }
164 164
 
165 165
 function importFiles($parent, $filedir, $files, $mode) {
166
-	global $modx;
167
-	global $_lang, $allowedfiles;
168
-	global $search_default, $cache_default, $publish_default;
169
-
170
-	$tbl_site_content = $modx->getFullTableName('site_content');
171
-	$tbl_system_settings = $modx->getFullTableName('system_settings');
172
-
173
-	$createdby = $modx->getLoginUserID();
174
-	if(!is_array($files)) {
175
-		return;
176
-	}
177
-	if($_POST['object'] == 'all') {
178
-		$modx->config['default_template'] = '0';
179
-		$richtext = '0';
180
-	} else {
181
-		$richtext = '1';
182
-	}
183
-
184
-	foreach($files as $id => $value) {
185
-		if(is_array($value)) {
186
-			// create folder
187
-			$alias = $id;
188
-			printf('<span>' . $_lang['import_site_importing_document'] . '</span>', $alias);
189
-			$field = array();
190
-			$field['type'] = 'document';
191
-			$field['contentType'] = 'text/html';
192
-			$field['published'] = $publish_default;
193
-			$field['parent'] = $parent;
194
-			$field['alias'] = $modx->stripAlias($alias);
195
-			$field['richtext'] = $richtext;
196
-			$field['template'] = $modx->config['default_template'];
197
-			$field['searchable'] = $search_default;
198
-			$field['cacheable'] = $cache_default;
199
-			$field['createdby'] = $createdby;
200
-			$field['isfolder'] = 1;
201
-			$field['menuindex'] = 1;
202
-			$find = false;
203
-			foreach(array(
204
-						'index.html',
205
-						'index.htm'
206
-					) as $filename) {
207
-				$filepath = $filedir . $alias . '/' . $filename;
208
-				if($find === false && file_exists($filepath)) {
209
-					$file = getFileContent($filepath);
210
-					list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
211
-
212
-					$date = filemtime($filepath);
213
-					$field['pagetitle'] = $pagetitle;
214
-					$field['longtitle'] = $pagetitle;
215
-					$field['description'] = $description;
216
-					$field['content'] = $modx->db->escape($content);
217
-					$field['createdon'] = $date;
218
-					$field['editedon'] = $date;
219
-					$newid = $modx->db->insert($field, $tbl_site_content);
220
-					if($newid) {
221
-						$find = true;
222
-						echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
223
-						importFiles($newid, $filedir . $alias . '/', $value, 'sub');
224
-					} else {
225
-						echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
226
-						exit;
227
-					}
228
-				}
229
-			}
230
-			if($find === false) {
231
-				$date = time();
232
-				$field['pagetitle'] = '---';
233
-				$field['content'] = '';
234
-				$field['createdon'] = $date;
235
-				$field['editedon'] = $date;
236
-				$field['hidemenu'] = '1';
237
-				$newid = $modx->db->insert($field, $tbl_site_content);
238
-				if($newid) {
239
-					$find = true;
240
-					echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
241
-					importFiles($newid, $filedir . $alias . '/', $value, 'sub');
242
-				} else {
243
-					echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
244
-					exit;
245
-				}
246
-			}
247
-		} else {
248
-			// create document
249
-			if($mode == 'sub' && $value == 'index.html') {
250
-				continue;
251
-			}
252
-			$filename = $value;
253
-			$fparts = explode('.', $value);
254
-			$alias = $fparts[0];
255
-			$ext = (count($fparts) > 1) ? $fparts[count($fparts) - 1] : "";
256
-			printf("<span>" . $_lang['import_site_importing_document'] . "</span>", $filename);
257
-
258
-			if(!in_array($ext, $allowedfiles)) {
259
-				echo ' - <span class="fail">' . $_lang["import_site_skip"] . '</span><br />' . "\n";
260
-			} else {
261
-				$filepath = $filedir . $filename;
262
-				$file = getFileContent($filepath);
263
-				list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
264
-
265
-				$date = filemtime($filepath);
266
-				$field = array();
267
-				$field['type'] = 'document';
268
-				$field['contentType'] = 'text/html';
269
-				$field['pagetitle'] = $pagetitle;
270
-				$field['longtitle'] = $pagetitle;
271
-				$field['description'] = $description;
272
-				$field['alias'] = $modx->stripAlias($alias);
273
-				$field['published'] = $publish_default;
274
-				$field['parent'] = $parent;
275
-				$field['content'] = $modx->db->escape($content);
276
-				$field['richtext'] = $richtext;
277
-				$field['template'] = $modx->config['default_template'];
278
-				$field['searchable'] = $search_default;
279
-				$field['cacheable'] = $cache_default;
280
-				$field['createdby'] = $createdby;
281
-				$field['createdon'] = $date;
282
-				$field['editedon'] = $date;
283
-				$field['isfolder'] = 0;
284
-				$field['menuindex'] = ($alias == 'index') ? 0 : 2;
285
-				$newid = $modx->db->insert($field, $tbl_site_content);
286
-				if($newid) {
287
-					echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
288
-				} else {
289
-					echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
290
-					exit;
291
-				}
292
-
293
-				$is_site_start = false;
294
-				if($filename == 'index.html') {
295
-					$is_site_start = true;
296
-				}
297
-				if($is_site_start == true && $_POST['reset'] == 'on') {
298
-					$modx->db->update(array('setting_value' => $newid), $tbl_system_settings, "setting_name='site_start'");
299
-					$modx->db->update(array('menuindex' => 0), $tbl_site_content, "id='{$newid}'");
300
-				}
301
-			}
302
-		}
303
-	}
166
+    global $modx;
167
+    global $_lang, $allowedfiles;
168
+    global $search_default, $cache_default, $publish_default;
169
+
170
+    $tbl_site_content = $modx->getFullTableName('site_content');
171
+    $tbl_system_settings = $modx->getFullTableName('system_settings');
172
+
173
+    $createdby = $modx->getLoginUserID();
174
+    if(!is_array($files)) {
175
+        return;
176
+    }
177
+    if($_POST['object'] == 'all') {
178
+        $modx->config['default_template'] = '0';
179
+        $richtext = '0';
180
+    } else {
181
+        $richtext = '1';
182
+    }
183
+
184
+    foreach($files as $id => $value) {
185
+        if(is_array($value)) {
186
+            // create folder
187
+            $alias = $id;
188
+            printf('<span>' . $_lang['import_site_importing_document'] . '</span>', $alias);
189
+            $field = array();
190
+            $field['type'] = 'document';
191
+            $field['contentType'] = 'text/html';
192
+            $field['published'] = $publish_default;
193
+            $field['parent'] = $parent;
194
+            $field['alias'] = $modx->stripAlias($alias);
195
+            $field['richtext'] = $richtext;
196
+            $field['template'] = $modx->config['default_template'];
197
+            $field['searchable'] = $search_default;
198
+            $field['cacheable'] = $cache_default;
199
+            $field['createdby'] = $createdby;
200
+            $field['isfolder'] = 1;
201
+            $field['menuindex'] = 1;
202
+            $find = false;
203
+            foreach(array(
204
+                        'index.html',
205
+                        'index.htm'
206
+                    ) as $filename) {
207
+                $filepath = $filedir . $alias . '/' . $filename;
208
+                if($find === false && file_exists($filepath)) {
209
+                    $file = getFileContent($filepath);
210
+                    list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
211
+
212
+                    $date = filemtime($filepath);
213
+                    $field['pagetitle'] = $pagetitle;
214
+                    $field['longtitle'] = $pagetitle;
215
+                    $field['description'] = $description;
216
+                    $field['content'] = $modx->db->escape($content);
217
+                    $field['createdon'] = $date;
218
+                    $field['editedon'] = $date;
219
+                    $newid = $modx->db->insert($field, $tbl_site_content);
220
+                    if($newid) {
221
+                        $find = true;
222
+                        echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
223
+                        importFiles($newid, $filedir . $alias . '/', $value, 'sub');
224
+                    } else {
225
+                        echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
226
+                        exit;
227
+                    }
228
+                }
229
+            }
230
+            if($find === false) {
231
+                $date = time();
232
+                $field['pagetitle'] = '---';
233
+                $field['content'] = '';
234
+                $field['createdon'] = $date;
235
+                $field['editedon'] = $date;
236
+                $field['hidemenu'] = '1';
237
+                $newid = $modx->db->insert($field, $tbl_site_content);
238
+                if($newid) {
239
+                    $find = true;
240
+                    echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
241
+                    importFiles($newid, $filedir . $alias . '/', $value, 'sub');
242
+                } else {
243
+                    echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
244
+                    exit;
245
+                }
246
+            }
247
+        } else {
248
+            // create document
249
+            if($mode == 'sub' && $value == 'index.html') {
250
+                continue;
251
+            }
252
+            $filename = $value;
253
+            $fparts = explode('.', $value);
254
+            $alias = $fparts[0];
255
+            $ext = (count($fparts) > 1) ? $fparts[count($fparts) - 1] : "";
256
+            printf("<span>" . $_lang['import_site_importing_document'] . "</span>", $filename);
257
+
258
+            if(!in_array($ext, $allowedfiles)) {
259
+                echo ' - <span class="fail">' . $_lang["import_site_skip"] . '</span><br />' . "\n";
260
+            } else {
261
+                $filepath = $filedir . $filename;
262
+                $file = getFileContent($filepath);
263
+                list($pagetitle, $content, $description) = treatContent($file, $filename, $alias);
264
+
265
+                $date = filemtime($filepath);
266
+                $field = array();
267
+                $field['type'] = 'document';
268
+                $field['contentType'] = 'text/html';
269
+                $field['pagetitle'] = $pagetitle;
270
+                $field['longtitle'] = $pagetitle;
271
+                $field['description'] = $description;
272
+                $field['alias'] = $modx->stripAlias($alias);
273
+                $field['published'] = $publish_default;
274
+                $field['parent'] = $parent;
275
+                $field['content'] = $modx->db->escape($content);
276
+                $field['richtext'] = $richtext;
277
+                $field['template'] = $modx->config['default_template'];
278
+                $field['searchable'] = $search_default;
279
+                $field['cacheable'] = $cache_default;
280
+                $field['createdby'] = $createdby;
281
+                $field['createdon'] = $date;
282
+                $field['editedon'] = $date;
283
+                $field['isfolder'] = 0;
284
+                $field['menuindex'] = ($alias == 'index') ? 0 : 2;
285
+                $newid = $modx->db->insert($field, $tbl_site_content);
286
+                if($newid) {
287
+                    echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n";
288
+                } else {
289
+                    echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError();
290
+                    exit;
291
+                }
292
+
293
+                $is_site_start = false;
294
+                if($filename == 'index.html') {
295
+                    $is_site_start = true;
296
+                }
297
+                if($is_site_start == true && $_POST['reset'] == 'on') {
298
+                    $modx->db->update(array('setting_value' => $newid), $tbl_system_settings, "setting_name='site_start'");
299
+                    $modx->db->update(array('menuindex' => 0), $tbl_site_content, "id='{$newid}'");
300
+                }
301
+            }
302
+        }
303
+    }
304 304
 }
305 305
 
306 306
 function getFiles($directory, $listing = array(), $count = 0) {
307
-	global $_lang;
308
-	global $filesfound;
309
-	$dummy = $count;
310
-	if( ! empty($directory) && $files = scandir($directory)) {
311
-		foreach($files as $file) {
312
-			if($file == '.' || $file == '..') {
313
-				continue;
314
-			} elseif($h = @opendir($directory . $file . "/")) {
315
-				closedir($h);
316
-				$count = -1;
317
-				$listing[$file] = getFiles($directory . $file . "/", array(), $count + 1);
318
-			} elseif(strpos($file, '.htm') !== false) {
319
-				$listing[$dummy] = $file;
320
-				$dummy = $dummy + 1;
321
-				$filesfound++;
322
-			}
323
-		}
324
-	} else {
325
-		echo '<p><span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_no_open_dir"] . $directory . ".</p>";
326
-	}
327
-	return ($listing);
307
+    global $_lang;
308
+    global $filesfound;
309
+    $dummy = $count;
310
+    if( ! empty($directory) && $files = scandir($directory)) {
311
+        foreach($files as $file) {
312
+            if($file == '.' || $file == '..') {
313
+                continue;
314
+            } elseif($h = @opendir($directory . $file . "/")) {
315
+                closedir($h);
316
+                $count = -1;
317
+                $listing[$file] = getFiles($directory . $file . "/", array(), $count + 1);
318
+            } elseif(strpos($file, '.htm') !== false) {
319
+                $listing[$dummy] = $file;
320
+                $dummy = $dummy + 1;
321
+                $filesfound++;
322
+            }
323
+        }
324
+    } else {
325
+        echo '<p><span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_no_open_dir"] . $directory . ".</p>";
326
+    }
327
+    return ($listing);
328 328
 }
329 329
 
330 330
 function getFileContent($filepath) {
331
-	global $_lang;
332
-	// get the file
333
-	if(!$buffer = file_get_contents($filepath)) {
334
-		echo '<p><span class="fail">' . $_lang['import_site_failed'] . "</span> " . $_lang["import_site_failed_no_retrieve_file"] . $filepath . ".</p>";
335
-	} else {
336
-		return $buffer;
337
-	}
331
+    global $_lang;
332
+    // get the file
333
+    if(!$buffer = file_get_contents($filepath)) {
334
+        echo '<p><span class="fail">' . $_lang['import_site_failed'] . "</span> " . $_lang["import_site_failed_no_retrieve_file"] . $filepath . ".</p>";
335
+    } else {
336
+        return $buffer;
337
+    }
338 338
 }
339 339
 
340 340
 function pop_index($array) {
341
-	$new_array = array();
342
-	foreach($array as $k => $v) {
343
-		if($v !== 'index.html' && $v !== 'index.htm') {
344
-			$new_array[$k] = $v;
345
-		} else {
346
-			array_unshift($new_array, $v);
347
-		}
348
-	}
349
-	foreach($array as $k => $v) {
350
-		if(is_array($v)) {
351
-			$new_array[$k] = $v;
352
-		}
353
-	}
354
-	return $new_array;
341
+    $new_array = array();
342
+    foreach($array as $k => $v) {
343
+        if($v !== 'index.html' && $v !== 'index.htm') {
344
+            $new_array[$k] = $v;
345
+        } else {
346
+            array_unshift($new_array, $v);
347
+        }
348
+    }
349
+    foreach($array as $k => $v) {
350
+        if(is_array($v)) {
351
+            $new_array[$k] = $v;
352
+        }
353
+    }
354
+    return $new_array;
355 355
 }
356 356
 
357 357
 function treatContent($src, $filename, $alias) {
358
-	global $modx;
359
-
360
-	$src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII');
361
-
362
-	if(preg_match("@<title>(.*)</title>@i", $src, $matches)) {
363
-		$pagetitle = ($matches[1] !== '') ? $matches[1] : $filename;
364
-		$pagetitle = str_replace('[*pagetitle*]', '', $pagetitle);
365
-	} else {
366
-		$pagetitle = $alias;
367
-	}
368
-	if(!$pagetitle) {
369
-		$pagetitle = $alias;
370
-	}
371
-
372
-	if(preg_match('@<meta[^>]+"description"[^>]+content=[\'"](.*)[\'"].+>@i', $src, $matches)) {
373
-		$description = ($matches[1] !== '') ? $matches[1] : $filename;
374
-		$description = str_replace('[*description*]', '', $description);
375
-	} else {
376
-		$description = '';
377
-	}
378
-
379
-	if((preg_match("@<body[^>]*>(.*)[^<]+</body>@is", $src, $matches)) && $_POST['object'] == 'body') {
380
-		$content = $matches[1];
381
-	} else {
382
-		$content = $src;
383
-		$s = '/(<meta[^>]+charset\s*=)[^>"\'=]+(.+>)/i';
384
-		$r = '$1' . $modx->config['modx_charset'] . '$2';
385
-		$content = preg_replace($s, $r, $content);
386
-		$content = preg_replace('@<title>.*</title>@i', "<title>[*pagetitle*]</title>", $content);
387
-	}
388
-	$content = str_replace('[*content*]', '[ *content* ]', $content);
389
-	$content = trim($content);
390
-	$pagetitle = $modx->db->escape($pagetitle);
391
-	return array(
392
-		$pagetitle,
393
-		$content,
394
-		$description
395
-	);
358
+    global $modx;
359
+
360
+    $src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII');
361
+
362
+    if(preg_match("@<title>(.*)</title>@i", $src, $matches)) {
363
+        $pagetitle = ($matches[1] !== '') ? $matches[1] : $filename;
364
+        $pagetitle = str_replace('[*pagetitle*]', '', $pagetitle);
365
+    } else {
366
+        $pagetitle = $alias;
367
+    }
368
+    if(!$pagetitle) {
369
+        $pagetitle = $alias;
370
+    }
371
+
372
+    if(preg_match('@<meta[^>]+"description"[^>]+content=[\'"](.*)[\'"].+>@i', $src, $matches)) {
373
+        $description = ($matches[1] !== '') ? $matches[1] : $filename;
374
+        $description = str_replace('[*description*]', '', $description);
375
+    } else {
376
+        $description = '';
377
+    }
378
+
379
+    if((preg_match("@<body[^>]*>(.*)[^<]+</body>@is", $src, $matches)) && $_POST['object'] == 'body') {
380
+        $content = $matches[1];
381
+    } else {
382
+        $content = $src;
383
+        $s = '/(<meta[^>]+charset\s*=)[^>"\'=]+(.+>)/i';
384
+        $r = '$1' . $modx->config['modx_charset'] . '$2';
385
+        $content = preg_replace($s, $r, $content);
386
+        $content = preg_replace('@<title>.*</title>@i', "<title>[*pagetitle*]</title>", $content);
387
+    }
388
+    $content = str_replace('[*content*]', '[ *content* ]', $content);
389
+    $content = trim($content);
390
+    $pagetitle = $modx->db->escape($pagetitle);
391
+    return array(
392
+        $pagetitle,
393
+        $content,
394
+        $description
395
+    );
396 396
 }
397 397
 
398 398
 function convertLink() {
399
-	global $modx;
400
-	$tbl_site_content = $modx->getFullTableName('site_content');
399
+    global $modx;
400
+    $tbl_site_content = $modx->getFullTableName('site_content');
401 401
 
402
-	$rs = $modx->db->select('id,content', $tbl_site_content);
403
-	$p = array();
402
+    $rs = $modx->db->select('id,content', $tbl_site_content);
403
+    $p = array();
404 404
     $target = array();
405
-	$dir = '';
406
-	while($row = $modx->db->getRow($rs)) {
407
-		$id = $row['id'];
408
-		$array = explode('<a href=', $row['content']);
409
-		$c = 0;
410
-		foreach($array as $v) {
411
-			if($v[0] === '"') {
412
-				$v = substr($v, 1);
413
-				list($href, $v) = explode('"', $v, 2);
414
-				$_ = $href;
415
-				if(strpos($_, $modx->config['site_url']) !== false) {
416
-					$_ = $modx->config['base_url'] . str_replace($modx->config['site_url'], '', $_);
417
-				}
418
-				if($_[0] === '/') {
419
-					$_ = substr($_, 1);
420
-				}
421
-				$_ = str_replace('/index.html', '.html', $_);
422
-				$level = substr_count($_, '../');
423
-				if(1 < $level) {
424
-					if(!isset($p[$id])) {
425
-						$p[$id] = $modx->getParentIds($id);
426
-					}
427
-					$k = array_keys($p[$id]);
428
-					while(0 < $level) {
429
-						$dir = array_shift($k);
430
-						$level--;
431
-					}
432
-					if($dir != '') {
433
-						$dir .= '/';
434
-					}
435
-				} else {
436
-					$dir = '';
437
-				}
438
-
439
-				$_ = trim($_, './');
440
-				if(strpos($_, '/') !== false) {
441
-					$_ = substr($_, strrpos($_, '/'));
442
-				}
443
-				$_ = $dir . str_replace('.html', '', $_);
444
-				if(!isset($target[$_])) {
445
-					$target[$_] = $modx->getIdFromAlias($_);
446
-				}
447
-				$target[$_] = trim($target[$_]);
448
-				if(!empty($target[$_])) {
449
-					$href = '[~' . $target[$_] . '~]';
450
-				}
451
-				$array[$c] = '<a href="' . $href . '"' . $v;
452
-			}
453
-			$c++;
454
-		}
455
-		$content = implode('', $array);
456
-		$f['content'] = $modx->db->escape($content);
457
-		$modx->db->update($f, $tbl_site_content, "id='{$id}'");
458
-	}
405
+    $dir = '';
406
+    while($row = $modx->db->getRow($rs)) {
407
+        $id = $row['id'];
408
+        $array = explode('<a href=', $row['content']);
409
+        $c = 0;
410
+        foreach($array as $v) {
411
+            if($v[0] === '"') {
412
+                $v = substr($v, 1);
413
+                list($href, $v) = explode('"', $v, 2);
414
+                $_ = $href;
415
+                if(strpos($_, $modx->config['site_url']) !== false) {
416
+                    $_ = $modx->config['base_url'] . str_replace($modx->config['site_url'], '', $_);
417
+                }
418
+                if($_[0] === '/') {
419
+                    $_ = substr($_, 1);
420
+                }
421
+                $_ = str_replace('/index.html', '.html', $_);
422
+                $level = substr_count($_, '../');
423
+                if(1 < $level) {
424
+                    if(!isset($p[$id])) {
425
+                        $p[$id] = $modx->getParentIds($id);
426
+                    }
427
+                    $k = array_keys($p[$id]);
428
+                    while(0 < $level) {
429
+                        $dir = array_shift($k);
430
+                        $level--;
431
+                    }
432
+                    if($dir != '') {
433
+                        $dir .= '/';
434
+                    }
435
+                } else {
436
+                    $dir = '';
437
+                }
438
+
439
+                $_ = trim($_, './');
440
+                if(strpos($_, '/') !== false) {
441
+                    $_ = substr($_, strrpos($_, '/'));
442
+                }
443
+                $_ = $dir . str_replace('.html', '', $_);
444
+                if(!isset($target[$_])) {
445
+                    $target[$_] = $modx->getIdFromAlias($_);
446
+                }
447
+                $target[$_] = trim($target[$_]);
448
+                if(!empty($target[$_])) {
449
+                    $href = '[~' . $target[$_] . '~]';
450
+                }
451
+                $array[$c] = '<a href="' . $href . '"' . $v;
452
+            }
453
+            $c++;
454
+        }
455
+        $content = implode('', $array);
456
+        $f['content'] = $modx->db->escape($content);
457
+        $modx->db->update($f, $tbl_site_content, "id='{$id}'");
458
+    }
459 459
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -101,7 +101,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
manager/actions/mutate_settings/functions.inc.php 1 patch
Braces   +34 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,12 +4,13 @@  discard block
 block discarded – undo
4 4
  *
5 5
  * @return array of keys from a language file
6 6
  */
7
-function get_lang_keys($filename) {
7
+function get_lang_keys($filename)
8
+{
8 9
     $file = MODX_MANAGER_PATH.'includes/lang' . DIRECTORY_SEPARATOR . $filename;
9
-    if(is_file($file) && is_readable($file)) {
10
+    if(is_file($file) && is_readable($file)) {
10 11
         include($file);
11 12
         $out = isset($_lang) ? array_keys($_lang) : array();
12
-    } else {
13
+    } else {
13 14
         $out = array();
14 15
     }
15 16
 
@@ -20,11 +21,12 @@  discard block
 block discarded – undo
20 21
  *
21 22
  * @return array of languages that define the key in their file
22 23
  */
23
-function get_langs_by_key($key) {
24
+function get_langs_by_key($key)
25
+{
24 26
     global $lang_keys;
25 27
     $lang_return = array();
26
-    foreach($lang_keys as $lang=>$keys) {
27
-        if(in_array($key, $keys)) {
28
+    foreach($lang_keys as $lang=>$keys) {
29
+        if(in_array($key, $keys)) {
28 30
             $lang_return[] = $lang;
29 31
         }
30 32
     }
@@ -40,23 +42,24 @@  discard block
 block discarded – undo
40 42
  * @param string $selected_lang specify language to select in option list, default none
41 43
  * @return string html option list
42 44
  */
43
-function get_lang_options($key = '', $selected_lang=null) {
45
+function get_lang_options($key = '', $selected_lang=null)
46
+{
44 47
     global $lang_keys, $_lang;
45 48
     $lang_options = '';
46
-    if( ! empty($key)) {
49
+    if( ! empty($key)) {
47 50
         $languages = get_langs_by_key($key);
48 51
         sort($languages);
49 52
         $lang_options .= '<option value="">'.$_lang['language_title'].'</option>';
50 53
 
51
-        foreach($languages as $language_name) {
54
+        foreach($languages as $language_name) {
52 55
             $uclanguage_name = ucwords(str_replace("_", " ", $language_name));
53 56
             $lang_options .= '<option value="'.$language_name.'">'.$uclanguage_name.'</option>';
54 57
         }
55 58
         return $lang_options;
56
-    } else {
59
+    } else {
57 60
         $languages = array_keys($lang_keys);
58 61
         sort($languages);
59
-        foreach($languages as $language_name) {
62
+        foreach($languages as $language_name) {
60 63
             $uclanguage_name = ucwords(str_replace("_", " ", $language_name));
61 64
             $sel = $language_name == $selected_lang ? ' selected="selected"' : '';
62 65
             $lang_options .= '<option value="'.$language_name.'" '.$sel.'>'.$uclanguage_name.'</option>';
@@ -65,31 +68,42 @@  discard block
 block discarded – undo
65 68
     }
66 69
 }
67 70
 
68
-function form_radio($name,$value,$add='',$disabled=false) {
71
+function form_radio($name,$value,$add='',$disabled=false)
72
+{
69 73
     global ${$name};
70 74
     $var = ${$name};
71 75
     $checked  = ($var==$value) ? ' checked="checked"' : '';
72
-    if($disabled) $disabled = ' disabled'; else $disabled = '';
73
-  if($add)     $add = ' ' . $add;
76
+    if($disabled) {
77
+        $disabled = ' disabled';
78
+    } else {
79
+        $disabled = '';
80
+    }
81
+  if($add) {
82
+      $add = ' ' . $add;
83
+  }
74 84
   return sprintf('<input onchange="documentDirty=true;" type="radio" name="%s" value="%s" %s %s %s />', $name, $value, $checked, $disabled, $add);
75 85
 }
76 86
 
77
-function wrap_label($str='',$object) {
87
+function wrap_label($str='',$object)
88
+{
78 89
   return "<label>{$object}\n{$str}</label>";
79 90
 }
80 91
 
81
-function parseText($tpl='', $ph=array()) {
82
-    if(empty($ph) || empty($tpl)) return $tpl;
92
+function parseText($tpl='', $ph=array())
93
+{
94
+    if(empty($ph) || empty($tpl)) {
95
+        return $tpl;
96
+    }
83 97
 
84
-    foreach($ph as $k=>$v)
85
-    {
98
+    foreach($ph as $k=>$v) {
86 99
         $k = "[+{$k}+]";
87 100
         $tpl = str_replace($k, $v, $tpl);
88 101
     }
89 102
     return $tpl;
90 103
 }
91 104
 
92
-function showHide($cond=true) {
105
+function showHide($cond=true)
106
+{
93 107
     global $displayStyle;
94 108
     $showHide = $cond ? $displayStyle : 'none';
95 109
     return sprintf('style="display:%s"', $showHide);
Please login to merge, or discard this patch.
manager/actions/files.dynamic.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -733,7 +733,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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];
Please login to merge, or discard this patch.
manager/includes/document.parser.class.inc.php 1 patch
Braces   +55 added lines, -26 removed lines patch added patch discarded remove patch
@@ -695,13 +695,15 @@  discard block
 block discarded – undo
695 695
             $this->virtualDir = '';
696 696
         }
697 697
 
698
-        if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) { /* we got an ID returned, check to make sure it's not an alias */
698
+        if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) {
699
+/* we got an ID returned, check to make sure it's not an alias */
699 700
             /* FS#476 and FS#308: check that id is valid in terms of virtualDir structure */
700 701
             if ($this->config['use_alias_path'] == 1) {
701 702
                 if (($this->virtualDir != '' && !isset($this->documentListing[$this->virtualDir . '/' . $q]) || ($this->virtualDir == '' && !isset($this->documentListing[$q]))) && (($this->virtualDir != '' && isset($this->documentListing[$this->virtualDir]) && in_array($q, $this->getChildIds($this->documentListing[$this->virtualDir], 1))) || ($this->virtualDir == '' && in_array($q, $this->getChildIds(0, 1))))) {
702 703
                     $this->documentMethod = 'id';
703 704
                     return $q;
704
-                } else { /* not a valid id in terms of virtualDir, treat as alias */
705
+                } else {
706
+/* not a valid id in terms of virtualDir, treat as alias */
705 707
                     $this->documentMethod = 'alias';
706 708
                     return $q;
707 709
                 }
@@ -709,7 +711,8 @@  discard block
 block discarded – undo
709 711
                 $this->documentMethod = 'id';
710 712
                 return $q;
711 713
             }
712
-        } else { /* we didn't get an ID back, so instead we assume it's an alias */
714
+        } else {
715
+/* we didn't get an ID back, so instead we assume it's an alias */
713 716
             if ($this->config['friendly_alias_urls'] != 1) {
714 717
                 $q = $qOrig;
715 718
             }
@@ -739,13 +742,14 @@  discard block
 block discarded – undo
739 742
      * @param $id
740 743
      * @return array|mixed|null|string
741 744
      */
742
-    public function makePageCacheKey($id){
745
+    public function makePageCacheKey($id)
746
+    {
743 747
         $hash = $id;
744 748
         $tmp = null;
745 749
         $params = array();
746
-        if(!empty($this->systemCacheKey)){
750
+        if(!empty($this->systemCacheKey)) {
747 751
             $hash = $this->systemCacheKey;
748
-        }else {
752
+        } else {
749 753
             if (!empty($_GET)) {
750 754
                 // Sort GET parameters so that the order of parameters on the HTTP request don't affect the generated cache ID.
751 755
                 $params = $_GET;
@@ -754,7 +758,7 @@  discard block
 block discarded – undo
754 758
             }
755 759
         }
756 760
         $evtOut = $this->invokeEvent("OnMakePageCacheKey", array ("hash" => $hash, "id" => $id, 'params' => $params));
757
-        if (is_array($evtOut) && count($evtOut) > 0){
761
+        if (is_array($evtOut) && count($evtOut) > 0) {
758 762
             $tmp = array_pop($evtOut);
759 763
         }
760 764
         return empty($tmp) ? $hash : $tmp;
@@ -1165,10 +1169,18 @@  discard block
 block discarded – undo
1165 1169
             return array();
1166 1170
         }
1167 1171
         $spacer = md5('<<<EVO>>>');
1168
-        if($left==='{{' && strpos($content,';}}')!==false)  $content = str_replace(';}}', sprintf(';}%s}',   $spacer),$content);
1169
-        if($left==='{{' && strpos($content,'{{}}')!==false) $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content);
1170
-        if($left==='[[' && strpos($content,']]]]')!==false) $content = str_replace(']]]]',sprintf(']]%s]]',  $spacer),$content);
1171
-        if($left==='[[' && strpos($content,']]]')!==false)  $content = str_replace(']]]', sprintf(']%s]]',   $spacer),$content);
1172
+        if($left==='{{' && strpos($content,';}}')!==false) {
1173
+            $content = str_replace(';}}', sprintf(';}%s}',   $spacer),$content);
1174
+        }
1175
+        if($left==='{{' && strpos($content,'{{}}')!==false) {
1176
+            $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content);
1177
+        }
1178
+        if($left==='[[' && strpos($content,']]]]')!==false) {
1179
+            $content = str_replace(']]]]',sprintf(']]%s]]',  $spacer),$content);
1180
+        }
1181
+        if($left==='[[' && strpos($content,']]]')!==false) {
1182
+            $content = str_replace(']]]', sprintf(']%s]]',   $spacer),$content);
1183
+        }
1172 1184
 
1173 1185
         $pos['<![CDATA['] = strpos($content, '<![CDATA[');
1174 1186
         $pos[']]>'] = strpos($content, ']]>');
@@ -1221,7 +1233,8 @@  discard block
 block discarded – undo
1221 1233
                         }
1222 1234
                     }
1223 1235
 
1224
-                    if (!in_array($fetch, $tags)) {  // Avoid double Matches
1236
+                    if (!in_array($fetch, $tags)) {
1237
+// Avoid double Matches
1225 1238
                         $tags[] = $fetch; // Fetch
1226 1239
                     };
1227 1240
                     $fetch = ''; // and reset
@@ -1239,7 +1252,9 @@  discard block
 block discarded – undo
1239 1252
             }
1240 1253
         }
1241 1254
         foreach($tags as $i=>$tag) {
1242
-            if(strpos($tag,$spacer)!==false) $tags[$i] = str_replace($spacer, '', $tag);
1255
+            if(strpos($tag,$spacer)!==false) {
1256
+                $tags[$i] = str_replace($spacer, '', $tag);
1257
+            }
1243 1258
         }
1244 1259
         return $tags;
1245 1260
     }
@@ -1279,7 +1294,10 @@  discard block
 block discarded – undo
1279 1294
         }
1280 1295
 
1281 1296
         foreach ($matches[1] as $i => $key) {
1282
-            if(strpos($key,'[+')!==false) continue; // Allow chunk {{chunk?&param=`xxx`}} with [*tv_name_[+param+]*] as content
1297
+            if(strpos($key,'[+')!==false) {
1298
+                continue;
1299
+            }
1300
+            // Allow chunk {{chunk?&param=`xxx`}} with [*tv_name_[+param+]*] as content
1283 1301
             if (substr($key, 0, 1) == '#') {
1284 1302
                 $key = substr($key, 1);
1285 1303
             } // remove # for QuickEdit format
@@ -2004,7 +2022,8 @@  discard block
 block discarded – undo
2004 2022
      * @return mixed|string
2005 2023
      */
2006 2024
     public function _getSGVar($value)
2007
-    { // Get super globals
2025
+    {
2026
+// Get super globals
2008 2027
         $key = $value;
2009 2028
         $_ = $this->config['enable_filter'];
2010 2029
         $this->config['enable_filter'] = 1;
@@ -2409,7 +2428,8 @@  discard block
 block discarded – undo
2409 2428
         if ($this->config['friendly_urls'] == 1) {
2410 2429
             $aliases = array();
2411 2430
             if (is_array($this->documentListing)) {
2412
-                foreach ($this->documentListing as $path => $docid) { // This is big Loop on large site!
2431
+                foreach ($this->documentListing as $path => $docid) {
2432
+// This is big Loop on large site!
2413 2433
                     $aliases[$docid] = $path;
2414 2434
                     $isfolder[$docid] = $this->aliasListing[$docid]['isfolder'];
2415 2435
                 }
@@ -2442,7 +2462,7 @@  discard block
 block discarded – undo
2442 2462
             $isfriendly = ($this->config['friendly_alias_urls'] == 1 ? 1 : 0);
2443 2463
             $pref = $this->config['friendly_url_prefix'];
2444 2464
             $suff = $this->config['friendly_url_suffix'];
2445
-            $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff) {
2465
+            $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff){
2446 2466
                 global $modx;
2447 2467
                 $thealias = $aliases[$m[1]];
2448 2468
                 $thefolder = $isfolder[$m[1]];
@@ -4214,7 +4234,8 @@  discard block
 block discarded – undo
4214 4234
         if (isset ($this->snippetCache[$snippetName])) {
4215 4235
             $snippet = $this->snippetCache[$snippetName];
4216 4236
             $properties = !empty($this->snippetCache[$snippetName . "Props"]) ? $this->snippetCache[$snippetName . "Props"] : '';
4217
-        } else { // not in cache so let's check the db
4237
+        } else {
4238
+// not in cache so let's check the db
4218 4239
             $sql = "SELECT ss.`name`, ss.`snippet`, ss.`properties`, sm.properties as `sharedproperties` FROM " . $this->getFullTableName("site_snippets") . " as ss LEFT JOIN " . $this->getFullTableName('site_modules') . " as sm on sm.guid=ss.moduleguid WHERE ss.`name`='" . $this->db->escape($snippetName) . "'  AND ss.disabled=0;";
4219 4240
             $result = $this->db->query($sql);
4220 4241
             if ($this->db->getRecordCount($result) == 1) {
@@ -4718,7 +4739,7 @@  discard block
 block discarded – undo
4718 4739
             $result = $this->db->makeArray($rs);
4719 4740
 
4720 4741
             // get default/built-in template variables
4721
-            if(is_array($docRow)){
4742
+            if(is_array($docRow)) {
4722 4743
                 ksort($docRow);
4723 4744
 
4724 4745
                 foreach ($docRow as $key => $value) {
@@ -5197,12 +5218,16 @@  discard block
 block discarded – undo
5197 5218
             return '';
5198 5219
         } // nothing to register
5199 5220
         if (!is_array($options)) {
5200
-            if (is_bool($options))  // backward compatibility with old plaintext parameter
5221
+            if (is_bool($options)) {
5222
+                // backward compatibility with old plaintext parameter
5201 5223
             {
5202 5224
                 $options = array('plaintext' => $options);
5203
-            } elseif (is_string($options)) // Also allow script name as 2nd param
5225
+            }
5226
+            } elseif (is_string($options)) {
5227
+                // Also allow script name as 2nd param
5204 5228
             {
5205 5229
                 $options = array('name' => $options);
5230
+            }
5206 5231
             } else {
5207 5232
                 $options = array();
5208 5233
             }
@@ -5214,7 +5239,8 @@  discard block
 block discarded – undo
5214 5239
         unset($overwritepos); // probably unnecessary--just making sure
5215 5240
 
5216 5241
         $useThisVer = true;
5217
-        if (isset($this->loadedjscripts[$key])) { // a matching script was found
5242
+        if (isset($this->loadedjscripts[$key])) {
5243
+// a matching script was found
5218 5244
             // if existing script is a startup script, make sure the candidate is also a startup script
5219 5245
             if ($this->loadedjscripts[$key]['startup']) {
5220 5246
                 $startup = true;
@@ -5234,7 +5260,8 @@  discard block
 block discarded – undo
5234 5260
                     // overwrite the old script (the position may be important for dependent scripts)
5235 5261
                     $overwritepos = $this->loadedjscripts[$key]['pos'];
5236 5262
                 }
5237
-            } else { // Use the original version
5263
+            } else {
5264
+// Use the original version
5238 5265
                 if ($startup == true && $this->loadedjscripts[$key]['startup'] == false) {
5239 5266
                     // need to move the exisiting script to the head
5240 5267
                     $version = $this->loadedjscripts[$key][$version];
@@ -5358,7 +5385,8 @@  discard block
 block discarded – undo
5358 5385
         }
5359 5386
 
5360 5387
         $results = null;
5361
-        foreach ($this->pluginEvent[$evtName] as $pluginName) { // start for loop
5388
+        foreach ($this->pluginEvent[$evtName] as $pluginName) {
5389
+// start for loop
5362 5390
             if ($this->dumpPlugins) {
5363 5391
                 $eventtime = $this->getMicroTime();
5364 5392
             }
@@ -5906,7 +5934,8 @@  discard block
 block discarded – undo
5906 5934
      * @return bool
5907 5935
      */
5908 5936
     public function isSafeCode($phpcode = '', $safe_functions = '')
5909
-    { // return true or false
5937
+    {
5938
+// return true or false
5910 5939
         if ($safe_functions == '') {
5911 5940
             return false;
5912 5941
         }
@@ -6322,7 +6351,7 @@  discard block
 block discarded – undo
6322 6351
             $args = array_pad(array(), $_, '$var');
6323 6352
             $args = implode(", ", $args);
6324 6353
             $modx = &$this;
6325
-            $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val) {
6354
+            $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val){
6326 6355
                 $arg = $val['args'][$tmp - 1];
6327 6356
                 switch (true) {
6328 6357
                     case is_null($arg): {
Please login to merge, or discard this patch.
manager/includes/extenders/ex_modifiers.inc.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,9 @@
 block discarded – undo
5 5
  * Time: 10:00
6 6
  */
7 7
 
8
-if (isset($this->filter) && is_object($this->filter)) return true;
8
+if (isset($this->filter) && is_object($this->filter)) {
9
+    return true;
10
+}
9 11
 
10 12
 include_once(MODX_MANAGER_PATH.'includes/extenders/modifiers.class.inc.php');
11 13
 $this->filter = new MODIFIERS;
Please login to merge, or discard this patch.