@@ -33,6 +33,10 @@ |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | if( ! function_exists('parse')) { |
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param string $src |
|
| 39 | + */ |
|
| 36 | 40 | function parse($src, $ph, $left = '[+', $right = '+]') |
| 37 | 41 | { |
| 38 | 42 | foreach ($ph as $k => $v) { |
@@ -18,6 +18,7 @@ |
||
| 18 | 18 | /** |
| 19 | 19 | * get_langs_by_key |
| 20 | 20 | * |
| 21 | + * @param string $key |
|
| 21 | 22 | * @return array of languages that define the key in their file |
| 22 | 23 | */ |
| 23 | 24 | function get_langs_by_key($key) {
|
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * MODX_MANAGER_PATH."includes/extenders/ex_{$extname}.inc.php" |
| 253 | 253 | * $extname - extension name in lowercase |
| 254 | 254 | * |
| 255 | - * @param $extname |
|
| 255 | + * @param string $extname |
|
| 256 | 256 | * @param bool $reload |
| 257 | 257 | * @return bool |
| 258 | 258 | */ |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param int $count_attempts |
| 296 | 296 | * @param string $type $type |
| 297 | 297 | * @param string $responseCode |
| 298 | - * @return bool |
|
| 298 | + * @return false|null |
|
| 299 | 299 | * @global string $base_url |
| 300 | 300 | * @global string $site_url |
| 301 | 301 | */ |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | /** |
| 998 | - * @param $contents |
|
| 998 | + * @param string $contents |
|
| 999 | 999 | * @return mixed |
| 1000 | 1000 | */ |
| 1001 | 1001 | public function RecoveryEscapedTags($contents) |
@@ -1019,7 +1019,7 @@ discard block |
||
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
| 1022 | - * @param $tstart |
|
| 1022 | + * @param double $tstart |
|
| 1023 | 1023 | * @return array |
| 1024 | 1024 | */ |
| 1025 | 1025 | public function getTimerStats($tstart) |
@@ -1771,7 +1771,7 @@ discard block |
||
| 1771 | 1771 | |
| 1772 | 1772 | /** |
| 1773 | 1773 | * Remove Comment-Tags from output like <!--@- Comment -@--> |
| 1774 | - * @param $content |
|
| 1774 | + * @param string $content |
|
| 1775 | 1775 | * @param string $left |
| 1776 | 1776 | * @param string $right |
| 1777 | 1777 | * @return mixed |
@@ -1944,7 +1944,7 @@ discard block |
||
| 1944 | 1944 | /** |
| 1945 | 1945 | * Run snippets as per the tags in $documentSource and replace the tags with the returned values. |
| 1946 | 1946 | * |
| 1947 | - * @param $content |
|
| 1947 | + * @param string $content |
|
| 1948 | 1948 | * @return string |
| 1949 | 1949 | * @internal param string $documentSource |
| 1950 | 1950 | */ |
@@ -2977,7 +2977,7 @@ discard block |
||
| 2977 | 2977 | |
| 2978 | 2978 | /** |
| 2979 | 2979 | * @param $templateID |
| 2980 | - * @return mixed |
|
| 2980 | + * @return string |
|
| 2981 | 2981 | */ |
| 2982 | 2982 | public function _getTemplateCodeFromDB($templateID) |
| 2983 | 2983 | { |
@@ -3018,9 +3018,9 @@ discard block |
||
| 3018 | 3018 | } |
| 3019 | 3019 | |
| 3020 | 3020 | /** |
| 3021 | - * @param $id |
|
| 3021 | + * @param integer $id |
|
| 3022 | 3022 | * @param int $top |
| 3023 | - * @return mixed |
|
| 3023 | + * @return string |
|
| 3024 | 3024 | */ |
| 3025 | 3025 | public function getUltimateParentId($id, $top = 0) |
| 3026 | 3026 | { |
@@ -3351,7 +3351,7 @@ discard block |
||
| 3351 | 3351 | * |
| 3352 | 3352 | * @param int $type Types: 1=template, 2=tv, 3=chunk, 4=snippet, 5=plugin, 6=module, 7=resource, 8=role |
| 3353 | 3353 | * @param int $id Element- / Resource-id |
| 3354 | - * @return bool |
|
| 3354 | + * @return false|null |
|
| 3355 | 3355 | */ |
| 3356 | 3356 | public function lockElement($type, $id) |
| 3357 | 3357 | { |
@@ -3373,7 +3373,7 @@ discard block |
||
| 3373 | 3373 | * @param int $type Types: 1=template, 2=tv, 3=chunk, 4=snippet, 5=plugin, 6=module, 7=resource, 8=role |
| 3374 | 3374 | * @param int $id Element- / Resource-id |
| 3375 | 3375 | * @param bool $includeAllUsers true = Deletes not only own user-locks |
| 3376 | - * @return bool |
|
| 3376 | + * @return false|null |
|
| 3377 | 3377 | */ |
| 3378 | 3378 | public function unlockElement($type, $id, $includeAllUsers = false) |
| 3379 | 3379 | { |
@@ -3481,7 +3481,7 @@ discard block |
||
| 3481 | 3481 | * @param array $params |
| 3482 | 3482 | * @param string $msg |
| 3483 | 3483 | * @param array $files |
| 3484 | - * @return mixed |
|
| 3484 | + * @return boolean |
|
| 3485 | 3485 | */ |
| 3486 | 3486 | public function sendmail($params = array(), $msg = '', $files = array()) |
| 3487 | 3487 | { |
@@ -3977,7 +3977,7 @@ discard block |
||
| 3977 | 3977 | * |
| 3978 | 3978 | * @param string $type |
| 3979 | 3979 | * @param bool $report |
| 3980 | - * @return bool |
|
| 3980 | + * @return boolean|null |
|
| 3981 | 3981 | */ |
| 3982 | 3982 | public function clearCache($type = '', $report = false) |
| 3983 | 3983 | { |
@@ -5322,7 +5322,7 @@ discard block |
||
| 5322 | 5322 | * Remove event listener - only for use within the current execution cycle |
| 5323 | 5323 | * |
| 5324 | 5324 | * @param string $evtName |
| 5325 | - * @return boolean |
|
| 5325 | + * @return false|null |
|
| 5326 | 5326 | */ |
| 5327 | 5327 | public function removeEventListener($evtName) |
| 5328 | 5328 | { |
@@ -5346,7 +5346,7 @@ discard block |
||
| 5346 | 5346 | * |
| 5347 | 5347 | * @param string $evtName |
| 5348 | 5348 | * @param array $extParams Parameters available to plugins. Each array key will be the PHP variable name, and the array value will be the variable value. |
| 5349 | - * @return boolean|array |
|
| 5349 | + * @return false|null |
|
| 5350 | 5350 | */ |
| 5351 | 5351 | public function invokeEvent($evtName, $extParams = array()) |
| 5352 | 5352 | { |
@@ -5767,7 +5767,7 @@ discard block |
||
| 5767 | 5767 | |
| 5768 | 5768 | /** |
| 5769 | 5769 | * @param string $string |
| 5770 | - * @return mixed|string |
|
| 5770 | + * @return string |
|
| 5771 | 5771 | */ |
| 5772 | 5772 | public function removeSanitizeSeed($string = '') |
| 5773 | 5773 | { |
@@ -5782,7 +5782,7 @@ discard block |
||
| 5782 | 5782 | |
| 5783 | 5783 | /** |
| 5784 | 5784 | * @param string $content |
| 5785 | - * @return mixed|string |
|
| 5785 | + * @return string |
|
| 5786 | 5786 | */ |
| 5787 | 5787 | public function cleanUpMODXTags($content = '') |
| 5788 | 5788 | { |
@@ -5945,7 +5945,7 @@ discard block |
||
| 5945 | 5945 | |
| 5946 | 5946 | /** |
| 5947 | 5947 | * @param string $str |
| 5948 | - * @return bool|mixed|string |
|
| 5948 | + * @return string |
|
| 5949 | 5949 | */ |
| 5950 | 5950 | public function atBindFileContent($str = '') |
| 5951 | 5951 | { |
@@ -5996,8 +5996,8 @@ discard block |
||
| 5996 | 5996 | } |
| 5997 | 5997 | |
| 5998 | 5998 | /** |
| 5999 | - * @param $str |
|
| 6000 | - * @return bool|string |
|
| 5999 | + * @param string $str |
|
| 6000 | + * @return false|string |
|
| 6001 | 6001 | */ |
| 6002 | 6002 | public function getExtFromFilename($str) |
| 6003 | 6003 | { |
@@ -6025,7 +6025,7 @@ discard block |
||
| 6025 | 6025 | * @param string $text Error message |
| 6026 | 6026 | * @param string $file File where the error was detected |
| 6027 | 6027 | * @param string $line Line number within $file |
| 6028 | - * @return boolean |
|
| 6028 | + * @return boolean|null |
|
| 6029 | 6029 | */ |
| 6030 | 6030 | public function phpError($nr, $text, $file, $line) |
| 6031 | 6031 | { |
@@ -6077,7 +6077,7 @@ discard block |
||
| 6077 | 6077 | * @param string $text |
| 6078 | 6078 | * @param string $line |
| 6079 | 6079 | * @param string $output |
| 6080 | - * @return bool |
|
| 6080 | + * @return null|boolean |
|
| 6081 | 6081 | */ |
| 6082 | 6082 | public function messageQuit($msg = 'unspecified error', $query = '', $is_error = true, $nr = '', $file = '', $source = '', $text = '', $line = '', $output = '') |
| 6083 | 6083 | { |
@@ -6499,7 +6499,7 @@ discard block |
||
| 6499 | 6499 | |
| 6500 | 6500 | /** |
| 6501 | 6501 | * @param string $str |
| 6502 | - * @return bool|mixed|string |
|
| 6502 | + * @return string |
|
| 6503 | 6503 | */ |
| 6504 | 6504 | public function atBindInclude($str = '') |
| 6505 | 6505 | { |
@@ -6550,7 +6550,7 @@ discard block |
||
| 6550 | 6550 | * @param $str |
| 6551 | 6551 | * @param int $flags |
| 6552 | 6552 | * @param string $encode |
| 6553 | - * @return mixed |
|
| 6553 | + * @return string |
|
| 6554 | 6554 | */ |
| 6555 | 6555 | public function htmlspecialchars($str, $flags = ENT_COMPAT, $encode = '') |
| 6556 | 6556 | { |
@@ -6559,7 +6559,7 @@ discard block |
||
| 6559 | 6559 | } |
| 6560 | 6560 | |
| 6561 | 6561 | /** |
| 6562 | - * @param $string |
|
| 6562 | + * @param string $string |
|
| 6563 | 6563 | * @param bool $returnData |
| 6564 | 6564 | * @return bool|mixed |
| 6565 | 6565 | */ |
@@ -4,141 +4,141 @@ |
||
| 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 | } |
@@ -1,17 +1,17 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |