@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
| 81 | 81 | * @param string $email проверяемый email |
| 82 | 82 | * @param boolean $dns проверять ли DNS записи |
| 83 | - * @return boolean Результат проверки почтового ящика |
|
| 83 | + * @return false|string Результат проверки почтового ящика |
|
| 84 | 84 | * @author Anton Shevchuk |
| 85 | 85 | */ |
| 86 | 86 | public static function emailValidate($email, $dns = true) |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * @param $data |
|
| 158 | + * @param string $data |
|
| 159 | 159 | * @return bool|false|string |
| 160 | 160 | */ |
| 161 | 161 | public static function getEnv($data) |
@@ -3,16 +3,16 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Class APIhelpers |
| 5 | 5 | */ |
| 6 | -class APIhelpers |
|
| 7 | -{ |
|
| 6 | +class APIhelpers |
|
| 7 | +{
|
|
| 8 | 8 | /** |
| 9 | 9 | * Преобразует первый символ в нижний регистр |
| 10 | 10 | * @param $str |
| 11 | 11 | * @param string $encoding - кодировка, по-умолчанию UTF-8 |
| 12 | 12 | * @return string |
| 13 | 13 | */ |
| 14 | - public static function mb_lcfirst($str, $encoding = 'UTF-8') |
|
| 15 | - { |
|
| 14 | + public static function mb_lcfirst($str, $encoding = 'UTF-8') |
|
| 15 | + {
|
|
| 16 | 16 | return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str), |
| 17 | 17 | $encoding); |
| 18 | 18 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | * @param string $encoding - кодировка, по-умолчанию UTF-8 |
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | - public static function mb_ucfirst($str, $encoding = 'UTF-8') |
|
| 27 | - { |
|
| 26 | + public static function mb_ucfirst($str, $encoding = 'UTF-8') |
|
| 27 | + {
|
|
| 28 | 28 | $str = mb_ereg_replace('^[\ ]+', '', $str); |
| 29 | 29 | $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str), |
| 30 | 30 | $encoding); |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | * @param string $encoding кодировка |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public static function mb_trim_word($html, $len, $encoding = 'UTF-8') |
|
| 47 | - { |
|
| 46 | + public static function mb_trim_word($html, $len, $encoding = 'UTF-8') |
|
| 47 | + {
|
|
| 48 | 48 | $text = trim(preg_replace('|\s+|', ' ', strip_tags($html))); |
| 49 | 49 | $text = mb_substr($text, 0, $len + 1, $encoding); |
| 50 | - if (mb_substr($text, -1, null, $encoding) == ' ') { |
|
| 50 | + if (mb_substr($text, -1, null, $encoding) == ' ') {
|
|
| 51 | 51 | $out = trim($text); |
| 52 | - } else { |
|
| 52 | + } else {
|
|
| 53 | 53 | $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * @param Closure $validate null функция дополнительной валидации значения (должна возвращать true или false) |
| 66 | 66 | * @return mixed |
| 67 | 67 | */ |
| 68 | - public static function getkey($data, $key, $default = null, $validate = null) |
|
| 69 | - { |
|
| 68 | + public static function getkey($data, $key, $default = null, $validate = null) |
|
| 69 | + {
|
|
| 70 | 70 | $out = $default; |
| 71 | - if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) { |
|
| 71 | + if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
|
|
| 72 | 72 | $out = $data[$key]; |
| 73 | 73 | } |
| 74 | - if (!empty($validate) && is_callable($validate)) { |
|
| 74 | + if (!empty($validate) && is_callable($validate)) {
|
|
| 75 | 75 | $out = (($validate($out) === true) ? $out : $default); |
| 76 | 76 | } |
| 77 | 77 | return $out; |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | * @return boolean Результат проверки почтового ящика |
| 89 | 89 | * @author Anton Shevchuk |
| 90 | 90 | */ |
| 91 | - public static function emailValidate($email, $dns = true) |
|
| 92 | - { |
|
| 93 | - if (filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 91 | + public static function emailValidate($email, $dns = true) |
|
| 92 | + {
|
|
| 93 | + if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
| 94 | 94 | list(, $domain) = explode("@", $email, 2); |
| 95 | - if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) { |
|
| 95 | + if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
|
|
| 96 | 96 | $error = false; |
| 97 | - } else { |
|
| 97 | + } else {
|
|
| 98 | 98 | $error = 'dns'; |
| 99 | 99 | } |
| 100 | - } else { |
|
| 100 | + } else {
|
|
| 101 | 101 | $error = 'format'; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | * $this->genPass(20,"."); //AMV,>&?J)v55,(^g}Z06 |
| 131 | 131 | * $this->genPass(20,"aaa0aaa.A"); //rtvKja5xb0\KpdiRR1if |
| 132 | 132 | */ |
| 133 | - public static function genPass($len, $data = '') |
|
| 134 | - { |
|
| 135 | - if ($data == '') { |
|
| 133 | + public static function genPass($len, $data = '') |
|
| 134 | + {
|
|
| 135 | + if ($data == '') {
|
|
| 136 | 136 | $data = 'Aa0.'; |
| 137 | 137 | } |
| 138 | 138 | $opt = strlen($data); |
| 139 | 139 | $pass = array(); |
| 140 | 140 | |
| 141 | - for ($i = $len; $i > 0; $i--) { |
|
| 142 | - switch ($data[rand(0, ($opt - 1))]) { |
|
| 141 | + for ($i = $len; $i > 0; $i--) {
|
|
| 142 | + switch ($data[rand(0, ($opt - 1))]) {
|
|
| 143 | 143 | case 'A': |
| 144 | 144 | $tmp = rand(65, 90); |
| 145 | 145 | break; |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * @param $data |
| 164 | 164 | * @return bool|false|string |
| 165 | 165 | */ |
| 166 | - public static function getEnv($data) |
|
| 167 | - { |
|
| 168 | - switch (true) { |
|
| 166 | + public static function getEnv($data) |
|
| 167 | + {
|
|
| 168 | + switch (true) {
|
|
| 169 | 169 | case (isset($_SERVER[$data])): |
| 170 | 170 | $out = $_SERVER[$data]; |
| 171 | 171 | break; |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @see http://stackoverflow.com/questions/5036443/php-how-to-block-proxies-from-my-site |
| 200 | 200 | */ |
| 201 | - public static function getUserIP($default = '127.0.0.1') |
|
| 202 | - { |
|
| 201 | + public static function getUserIP($default = '127.0.0.1') |
|
| 202 | + {
|
|
| 203 | 203 | //Порядок условий зависит от приоритетов |
| 204 | - switch (true) { |
|
| 204 | + switch (true) {
|
|
| 205 | 205 | case ($tmp = self::getEnv('HTTP_COMING_FROM')): |
| 206 | 206 | $out = $tmp; |
| 207 | 207 | break; |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | '`' => '`', |
| 256 | 256 | '%60' => '`' |
| 257 | 257 | ) |
| 258 | - ) { |
|
| 259 | - switch (true) { |
|
| 258 | + ) {
|
|
| 259 | + switch (true) {
|
|
| 260 | 260 | case is_scalar($data): |
| 261 | 261 | $out = str_replace( |
| 262 | 262 | array_keys($chars), |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | break; |
| 267 | 267 | case is_array($data): |
| 268 | 268 | $out = $data; |
| 269 | - foreach ($out as $key => &$val) { |
|
| 269 | + foreach ($out as $key => &$val) {
|
|
| 270 | 270 | $val = self::sanitarTag($val, $charset, $chars); |
| 271 | 271 | } |
| 272 | 272 | break; |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | * @param string $charset |
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | - public static function e($text, $charset = 'UTF-8') |
|
| 286 | - { |
|
| 285 | + public static function e($text, $charset = 'UTF-8') |
|
| 286 | + {
|
|
| 287 | 287 | return is_scalar($text) ? htmlspecialchars($text, ENT_QUOTES, $charset, false) : ''; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -298,17 +298,17 @@ discard block |
||
| 298 | 298 | * @param array $mixArray Примесь символов, которые так же могут использоваться в строке |
| 299 | 299 | * @return bool |
| 300 | 300 | */ |
| 301 | - public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
| 302 | - { |
|
| 301 | + public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
| 302 | + {
|
|
| 303 | 303 | $flag = true; |
| 304 | 304 | $len = mb_strlen($value, 'UTF-8'); |
| 305 | 305 | $value = trim($value); |
| 306 | - if (mb_strlen($value, 'UTF-8') == $len) { |
|
| 306 | + if (mb_strlen($value, 'UTF-8') == $len) {
|
|
| 307 | 307 | $data = is_array($mixArray) ? $mixArray : array(); |
| 308 | 308 | $alph = is_array($alph) ? array_unique($alph) : array(); |
| 309 | - foreach ($alph as $item) { |
|
| 309 | + foreach ($alph as $item) {
|
|
| 310 | 310 | $item = strtolower($item); |
| 311 | - switch ($item) { |
|
| 311 | + switch ($item) {
|
|
| 312 | 312 | case 'rus': |
| 313 | 313 | $data = array_merge($data, array( |
| 314 | 314 | 'А', |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | break; |
| 349 | 349 | case 'num': |
| 350 | 350 | $tmp = range('0', '9'); |
| 351 | - foreach ($tmp as $t) { |
|
| 351 | + foreach ($tmp as $t) {
|
|
| 352 | 352 | $data[] = (string)$t; |
| 353 | 353 | } |
| 354 | 354 | break; |
@@ -357,15 +357,15 @@ discard block |
||
| 357 | 357 | break; |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | - for ($i = 0; $i < $len; $i++) { |
|
| 360 | + for ($i = 0; $i < $len; $i++) {
|
|
| 361 | 361 | $chr = mb_strtoupper(mb_substr($value, $i, 1, 'UTF-8'), 'UTF-8'); |
| 362 | - if (!in_array($chr, $data, true)) { |
|
| 362 | + if (!in_array($chr, $data, true)) {
|
|
| 363 | 363 | $flag = false; |
| 364 | 364 | break; |
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | $flag = ($flag && $len >= $minLen); |
| 368 | - } else { |
|
| 368 | + } else {
|
|
| 369 | 369 | $flag = false; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -382,18 +382,18 @@ discard block |
||
| 382 | 382 | * @param string $sep разделитель ключей при склейке многомерных массивов |
| 383 | 383 | * @return array массив с переименованными ключами |
| 384 | 384 | */ |
| 385 | - public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.') |
|
| 386 | - { |
|
| 385 | + public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.') |
|
| 386 | + {
|
|
| 387 | 387 | $out = array(); |
| 388 | - if ($prefix == '' && $suffix == '') { |
|
| 388 | + if ($prefix == '' && $suffix == '') {
|
|
| 389 | 389 | $out = $data; |
| 390 | - } else { |
|
| 390 | + } else {
|
|
| 391 | 391 | $InsertPrefix = ($prefix != '') ? ($prefix . $addPS) : ''; |
| 392 | 392 | $InsertSuffix = ($suffix != '') ? ($addPS . $suffix) : ''; |
| 393 | - foreach ($data as $key => $item) { |
|
| 393 | + foreach ($data as $key => $item) {
|
|
| 394 | 394 | $key = $InsertPrefix . $key; |
| 395 | 395 | $val = null; |
| 396 | - switch (true) { |
|
| 396 | + switch (true) {
|
|
| 397 | 397 | case is_scalar($item): |
| 398 | 398 | $val = $item; |
| 399 | 399 | break; |
@@ -152,7 +152,7 @@ |
||
| 152 | 152 | /** |
| 153 | 153 | * @param $ids |
| 154 | 154 | * @param $rid |
| 155 | - * @param null $fire_events |
|
| 155 | + * @param false|null $fire_events |
|
| 156 | 156 | * @return $this |
| 157 | 157 | */ |
| 158 | 158 | public function deleteAll($ids, $rid, $fire_events = false) |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | * Class dataTable |
| 9 | 9 | * @package SimpleTab |
| 10 | 10 | */ |
| 11 | -class dataTable extends \autoTable |
|
| 12 | -{ |
|
| 11 | +class dataTable extends \autoTable |
|
| 12 | +{
|
|
| 13 | 13 | /** |
| 14 | 14 | * @var array |
| 15 | 15 | */ |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | * @param \DocumentParser $modx |
| 41 | 41 | * @param bool $debug |
| 42 | 42 | */ |
| 43 | - public function __construct($modx, $debug = false) |
|
| 44 | - { |
|
| 43 | + public function __construct($modx, $debug = false) |
|
| 44 | + {
|
|
| 45 | 45 | parent::__construct($modx, $debug); |
| 46 | 46 | $this->modx = $modx; |
| 47 | 47 | $this->fs = \Helpers\FS::getInstance(); |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * @param $ids |
| 52 | 52 | * @param $rid |
| 53 | 53 | */ |
| 54 | - protected function clearIndexes($ids, $rid) |
|
| 55 | - { |
|
| 54 | + protected function clearIndexes($ids, $rid) |
|
| 55 | + {
|
|
| 56 | 56 | $ids = $this->cleanIDs($ids, ',', array(0)); |
| 57 | 57 | $ids = $this->sanitarIn($ids); |
| 58 | 58 | $table = $this->makeTable($this->table); |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | * @param $field |
| 71 | 71 | * @return $this |
| 72 | 72 | */ |
| 73 | - public function touch($field) |
|
| 74 | - { |
|
| 73 | + public function touch($field) |
|
| 74 | + {
|
|
| 75 | 75 | $this->set($field, date('Y-m-d H:i:s', time() + $this->modx->config['server_offset_time'])); |
| 76 | 76 | |
| 77 | 77 | return $this; |
@@ -82,22 +82,22 @@ discard block |
||
| 82 | 82 | * @param $dir |
| 83 | 83 | * @param $rid |
| 84 | 84 | */ |
| 85 | - public function place($ids, $dir, $rid) |
|
| 86 | - { |
|
| 85 | + public function place($ids, $dir, $rid) |
|
| 86 | + {
|
|
| 87 | 87 | $table = $this->makeTable($this->table); |
| 88 | 88 | $ids = $this->cleanIDs($ids, ',', array(0)); |
| 89 | - if (empty($ids) || is_scalar($ids)) { |
|
| 89 | + if (empty($ids) || is_scalar($ids)) {
|
|
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | $rows = $this->query("SELECT count(`{$this->pkName}`) FROM {$table} WHERE `{$this->rfName}`={$rid}"); |
| 93 | 93 | $index = $this->modx->db->getValue($rows); |
| 94 | 94 | $cnt = count($ids); |
| 95 | 95 | $ids = implode(',', $ids); |
| 96 | - if ($dir == 'top') { |
|
| 96 | + if ($dir == 'top') {
|
|
| 97 | 97 | $this->query("SET @index := " . ($index - $cnt - 1)); |
| 98 | 98 | $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC"); |
| 99 | 99 | $this->query("SET @index := -1"); |
| 100 | - } else { |
|
| 100 | + } else {
|
|
| 101 | 101 | $this->query("SET @index := -1"); |
| 102 | 102 | $this->query("UPDATE {$table} SET `{$this->indexName}` = (@index := @index + 1) WHERE (`{$this->pkName}` IN ({$ids})) ORDER BY `{$this->indexName}` ASC"); |
| 103 | 103 | $this->query("SET @index := " . ($cnt - 1)); |
@@ -112,26 +112,26 @@ discard block |
||
| 112 | 112 | * @param $url |
| 113 | 113 | * @param bool $cache |
| 114 | 114 | */ |
| 115 | - public function deleteThumb($url, $cache = false) |
|
| 116 | - { |
|
| 115 | + public function deleteThumb($url, $cache = false) |
|
| 116 | + {
|
|
| 117 | 117 | $url = $this->fs->relativePath($url); |
| 118 | - if (empty($url)) { |
|
| 118 | + if (empty($url)) {
|
|
| 119 | 119 | return; |
| 120 | 120 | } |
| 121 | - if ($this->fs->checkFile($url)) { |
|
| 121 | + if ($this->fs->checkFile($url)) {
|
|
| 122 | 122 | unlink(MODX_BASE_PATH . $url); |
| 123 | 123 | } |
| 124 | 124 | $dir = $this->fs->takeFileDir($url); |
| 125 | 125 | $iterator = new \FilesystemIterator($dir); |
| 126 | - if (!$iterator->valid()) { |
|
| 126 | + if (!$iterator->valid()) {
|
|
| 127 | 127 | rmdir($dir); |
| 128 | 128 | } |
| 129 | - if ($cache) { |
|
| 129 | + if ($cache) {
|
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | $thumbsCache = \APIhelpers::getkey($this->params,'thumbsCache',$this->thumbsCache); |
| 133 | 133 | $thumb = $thumbsCache . $url; |
| 134 | - if ($this->fs->checkFile($thumb)) { |
|
| 134 | + if ($this->fs->checkFile($thumb)) {
|
|
| 135 | 135 | $this->deleteThumb($thumb, true); |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | * @param bool $fire_events |
| 142 | 142 | * @return $this |
| 143 | 143 | */ |
| 144 | - public function delete($ids, $fire_events = false) |
|
| 145 | - { |
|
| 144 | + public function delete($ids, $fire_events = false) |
|
| 145 | + {
|
|
| 146 | 146 | $out = parent::delete($ids, $fire_events); |
| 147 | 147 | $this->query("ALTER TABLE {$this->makeTable($this->table)} AUTO_INCREMENT = 1"); |
| 148 | 148 | |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | * @param null $fire_events |
| 156 | 156 | * @return $this |
| 157 | 157 | */ |
| 158 | - public function deleteAll($ids, $rid, $fire_events = false) |
|
| 159 | - { |
|
| 158 | + public function deleteAll($ids, $rid, $fire_events = false) |
|
| 159 | + {
|
|
| 160 | 160 | $this->clearIndexes($ids, $rid); |
| 161 | 161 | |
| 162 | 162 | return $this->delete($ids, $fire_events); |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | /** |
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | - public function fieldNames() |
|
| 169 | - { |
|
| 168 | + public function fieldNames() |
|
| 169 | + {
|
|
| 170 | 170 | $fields = array_keys($this->getDefaultFields()); |
| 171 | 171 | $fields[] = $this->fieldPKName(); |
| 172 | 172 | |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | * @param string $name |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public function stripName($name) |
|
| 181 | - { |
|
| 180 | + public function stripName($name) |
|
| 181 | + {
|
|
| 182 | 182 | |
| 183 | 183 | $filename = $this->fs->takeFileName($name); |
| 184 | 184 | $ext = $this->fs->takeFileExt($name); |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | * @param $orderDir |
| 195 | 195 | * @return int|void |
| 196 | 196 | */ |
| 197 | - public function reorder($source, $target, $point, $rid, $orderDir) |
|
| 198 | - { |
|
| 197 | + public function reorder($source, $target, $point, $rid, $orderDir) |
|
| 198 | + {
|
|
| 199 | 199 | $rid = (int)$rid; |
| 200 | 200 | $point = strtolower($point); |
| 201 | 201 | $orderDir = strtolower($orderDir); |
@@ -205,25 +205,25 @@ discard block |
||
| 205 | 205 | $table = $this->makeTable($this->table); |
| 206 | 206 | $rows = 0; |
| 207 | 207 | /* more refactoring needed */ |
| 208 | - if ($targetIndex < $sourceIndex) { |
|
| 209 | - if (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) { |
|
| 208 | + if ($targetIndex < $sourceIndex) {
|
|
| 209 | + if (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) {
|
|
| 210 | 210 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`+1", $table, |
| 211 | 211 | "`{$this->indexName}`>={$targetIndex} AND `{$this->indexName}`<{$sourceIndex} AND `{$this->rfName}`={$rid}"); |
| 212 | 212 | $rows = $this->modx->db->update("`{$this->indexName}`={$targetIndex}", $table, |
| 213 | 213 | "`{$this->pkName}`={$sourceId}"); |
| 214 | - } elseif (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) { |
|
| 214 | + } elseif (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) {
|
|
| 215 | 215 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`+1", $table, |
| 216 | 216 | "`{$this->indexName}`>{$targetIndex} AND `{$this->indexName}`<{$sourceIndex} AND `{$this->rfName}`={$rid}"); |
| 217 | 217 | $rows = $this->modx->db->update("`{$this->indexName}`=1+{$targetIndex}", $table, |
| 218 | 218 | "`{$this->pkName}`={$sourceId}"); |
| 219 | 219 | } |
| 220 | - } else { |
|
| 221 | - if (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) { |
|
| 220 | + } else {
|
|
| 221 | + if (($point == 'bottom' && $orderDir == 'asc') || ($point == 'top' && $orderDir == 'desc')) {
|
|
| 222 | 222 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`-1", $table, |
| 223 | 223 | "`{$this->indexName}`<={$targetIndex} AND `{$this->indexName}`>={$sourceIndex} AND `{$this->rfName}`={$rid}"); |
| 224 | 224 | $rows = $this->modx->db->update("`{$this->indexName}`={$targetIndex}", $table, |
| 225 | 225 | "`{$this->pkName}`={$sourceId}"); |
| 226 | - } elseif (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) { |
|
| 226 | + } elseif (($point == 'top' && $orderDir == 'asc') || ($point == 'bottom' && $orderDir == 'desc')) {
|
|
| 227 | 227 | $this->modx->db->update("`{$this->indexName}`=`{$this->indexName}`-1", $table, |
| 228 | 228 | "`{$this->indexName}`<{$targetIndex} AND `{$this->indexName}`>={$sourceIndex} AND `{$this->rfName}`={$rid}"); |
| 229 | 229 | $rows = $this->modx->db->update("`{$this->indexName}`=-1+{$targetIndex}", $table, |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @param $options |
| 241 | 241 | * @return bool |
| 242 | 242 | */ |
| 243 | - public function makeThumb($folder, $url, $options) |
|
| 244 | - { |
|
| 245 | - if (empty($url)) { |
|
| 243 | + public function makeThumb($folder, $url, $options) |
|
| 244 | + {
|
|
| 245 | + if (empty($url)) {
|
|
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | $thumb = new \Helpers\PHPThumb(); |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | $outputFile = MODX_BASE_PATH . $this->fs->relativePath($folder) . '/' . $this->fs->relativePath($url); |
| 251 | 251 | $dir = $this->fs->takeFileDir($outputFile); |
| 252 | 252 | $this->fs->makeDir($dir, $this->modx->config['new_folder_permissions']); |
| 253 | - if ($thumb->create($inputFile, $outputFile, $options)) { |
|
| 253 | + if ($thumb->create($inputFile, $outputFile, $options)) {
|
|
| 254 | 254 | return true; |
| 255 | - } else { |
|
| 255 | + } else {
|
|
| 256 | 256 | $this->modx->logEvent(0, 3, $thumb->debugMessages, __NAMESPACE__); |
| 257 | 257 | |
| 258 | 258 | return false; |
@@ -262,16 +262,18 @@ discard block |
||
| 262 | 262 | /** |
| 263 | 263 | * @return array |
| 264 | 264 | */ |
| 265 | - public function getParams() |
|
| 266 | - { |
|
| 265 | + public function getParams() |
|
| 266 | + {
|
|
| 267 | 267 | return $this->params; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
| 271 | 271 | * @param array $params |
| 272 | 272 | */ |
| 273 | - public function setParams($params = array()) |
|
| 274 | - { |
|
| 275 | - if (is_array($params)) $this->params = $params; |
|
| 273 | + public function setParams($params = array()) |
|
| 274 | + {
|
|
| 275 | + if (is_array($params)) {
|
|
| 276 | + $this->params = $params; |
|
| 277 | + } |
|
| 276 | 278 | } |
| 277 | 279 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * DLphx constructor. |
| 43 | - * @param int|bool|string $debug |
|
| 43 | + * @param integer $debug |
|
| 44 | 44 | * @param int $maxpass |
| 45 | 45 | */ |
| 46 | 46 | public function __construct($debug = false, $maxpass = 50) |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // Parser: Preparation, cleaning and checkup |
| 77 | 77 | /** |
| 78 | 78 | * @param string $template |
| 79 | - * @return mixed|string |
|
| 79 | + * @return string |
|
| 80 | 80 | */ |
| 81 | 81 | public function Parse($template = '') |
| 82 | 82 | { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // Parser: modifier detection and eXtended processing if needed |
| 235 | 235 | /** |
| 236 | 236 | * @param $input |
| 237 | - * @param $modifiers |
|
| 237 | + * @param string $modifiers |
|
| 238 | 238 | * @return mixed|null|string |
| 239 | 239 | */ |
| 240 | 240 | public function Filter($input, $modifiers) |
@@ -589,8 +589,8 @@ discard block |
||
| 589 | 589 | // positive userid = manager, negative integer = webuser |
| 590 | 590 | /** |
| 591 | 591 | * @param $userid |
| 592 | - * @param $field |
|
| 593 | - * @return mixed |
|
| 592 | + * @param string $field |
|
| 593 | + * @return string |
|
| 594 | 594 | */ |
| 595 | 595 | public function ModUser($userid, $field) |
| 596 | 596 | { |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | |
| 652 | 652 | // Returns the value of a PHx/MODx placeholder. |
| 653 | 653 | /** |
| 654 | - * @param $name |
|
| 654 | + * @param string $name |
|
| 655 | 655 | * @return mixed|string |
| 656 | 656 | */ |
| 657 | 657 | public function getPHxVariable($name) |
@@ -669,8 +669,8 @@ discard block |
||
| 669 | 669 | |
| 670 | 670 | // Sets a placeholder variable which can only be access by PHx |
| 671 | 671 | /** |
| 672 | - * @param $name |
|
| 673 | - * @param $value |
|
| 672 | + * @param string $name |
|
| 673 | + * @param string $value |
|
| 674 | 674 | */ |
| 675 | 675 | public function setPHxVariable($name, $value) |
| 676 | 676 | { |
@@ -681,9 +681,9 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | //mbstring |
| 683 | 683 | /** |
| 684 | - * @param $str |
|
| 685 | - * @param $s |
|
| 686 | - * @param null $l |
|
| 684 | + * @param string $str |
|
| 685 | + * @param integer $s |
|
| 686 | + * @param integer $l |
|
| 687 | 687 | * @return string |
| 688 | 688 | */ |
| 689 | 689 | public function substr($str, $s, $l = null) |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
| 699 | - * @param $str |
|
| 699 | + * @param string $str |
|
| 700 | 700 | * @return int |
| 701 | 701 | */ |
| 702 | 702 | public function strlen($str) |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
| 712 | - * @param $str |
|
| 712 | + * @param string $str |
|
| 713 | 713 | * @return string |
| 714 | 714 | */ |
| 715 | 715 | public function strtolower($str) |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
| 725 | - * @param $str |
|
| 725 | + * @param string $str |
|
| 726 | 726 | * @return string |
| 727 | 727 | */ |
| 728 | 728 | public function strtoupper($str) |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
| 738 | - * @param $str |
|
| 738 | + * @param string $str |
|
| 739 | 739 | * @return string |
| 740 | 740 | */ |
| 741 | 741 | public function ucfirst($str) |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | /** |
| 751 | - * @param $str |
|
| 751 | + * @param string $str |
|
| 752 | 752 | * @return string |
| 753 | 753 | */ |
| 754 | 754 | public function lcfirst($str) |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
| 764 | - * @param $str |
|
| 764 | + * @param string $str |
|
| 765 | 765 | * @return string |
| 766 | 766 | */ |
| 767 | 767 | public function ucwords($str) |
@@ -774,7 +774,7 @@ discard block |
||
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /** |
| 777 | - * @param $str |
|
| 777 | + * @param string $str |
|
| 778 | 778 | * @return string |
| 779 | 779 | */ |
| 780 | 780 | public function strrev($str) |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /** |
| 788 | - * @param $str |
|
| 788 | + * @param string $str |
|
| 789 | 789 | * @return string |
| 790 | 790 | */ |
| 791 | 791 | public function str_shuffle($str) |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | /** |
| 800 | - * @param $str |
|
| 800 | + * @param string $str |
|
| 801 | 801 | * @return int |
| 802 | 802 | */ |
| 803 | 803 | public function str_word_count($str) |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * Class DLphx |
| 17 | 17 | */ |
| 18 | -class DLphx |
|
| 19 | -{ |
|
| 18 | +class DLphx |
|
| 19 | +{
|
|
| 20 | 20 | public $placeholders = array(); |
| 21 | 21 | public $name = 'PHx'; |
| 22 | 22 | public $version = '2.2.0'; |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @param int|bool|string $debug |
| 44 | 44 | * @param int $maxpass |
| 45 | 45 | */ |
| 46 | - public function __construct($debug = false, $maxpass = 50) |
|
| 47 | - { |
|
| 46 | + public function __construct($debug = false, $maxpass = 50) |
|
| 47 | + {
|
|
| 48 | 48 | global $modx; |
| 49 | 49 | |
| 50 | 50 | $this->user["mgrid"] = isset($_SESSION['mgrInternalKey']) ? intval($_SESSION['mgrInternalKey']) : 0; |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | $this->maxPasses = ($maxpass != '') ? $maxpass : 50; |
| 57 | 57 | |
| 58 | 58 | $modx->setPlaceholder("phx", "&_PHX_INTERNAL_&"); |
| 59 | - if (function_exists('mb_internal_encoding')) { |
|
| 59 | + if (function_exists('mb_internal_encoding')) {
|
|
| 60 | 60 | mb_internal_encoding($modx->config['modx_charset']); |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // Plugin event hook for MODx |
| 65 | - public function OnParseDocument() |
|
| 66 | - { |
|
| 65 | + public function OnParseDocument() |
|
| 66 | + {
|
|
| 67 | 67 | global $modx; |
| 68 | 68 | // Get document output from MODx |
| 69 | 69 | $template = $modx->documentOutput; |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | * @param string $template |
| 79 | 79 | * @return mixed|string |
| 80 | 80 | */ |
| 81 | - public function Parse($template = '') |
|
| 82 | - { |
|
| 81 | + public function Parse($template = '') |
|
| 82 | + {
|
|
| 83 | 83 | global $modx; |
| 84 | 84 | // If we already reached max passes don't get at it again. |
| 85 | - if ($this->curPass == $this->maxPasses) { |
|
| 85 | + if ($this->curPass == $this->maxPasses) {
|
|
| 86 | 86 | return $template; |
| 87 | 87 | } |
| 88 | 88 | // Set template pre-process hash |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $template = $this->ParseValues($template); |
| 94 | 94 | // clean up unused placeholders that have modifiers attached (MODx can't clean them) |
| 95 | 95 | preg_match_all('~(?:=`[^`@]*?)(\[\+([^:\+\[\]]+)([^\[\]]*?)\+\])~s', $template, $matches); |
| 96 | - if ($matches[0]) { |
|
| 96 | + if ($matches[0]) {
|
|
| 97 | 97 | $template = str_replace($matches[1], '', $template); |
| 98 | 98 | $this->Log("Cleaning unsolved tags: \n" . implode("\n", $matches[2])); |
| 99 | 99 | } |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | // Set template post-process hash |
| 103 | 103 | $et = md5($template); |
| 104 | 104 | // If template has changed, parse it once more... |
| 105 | - if ($st != $et) { |
|
| 105 | + if ($st != $et) {
|
|
| 106 | 106 | $template = $this->Parse($template); |
| 107 | 107 | } |
| 108 | 108 | // Write an event log if debugging is enabled and there is something to log |
| 109 | - if ($this->debug && $this->debugLog) { |
|
| 109 | + if ($this->debug && $this->debugLog) {
|
|
| 110 | 110 | $modx->logEvent($this->curPass, 1, $this->createEventLog(), $this->name . ' ' . $this->version); |
| 111 | 111 | $this->debugLog = false; |
| 112 | 112 | } |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | * @param string $template |
| 121 | 121 | * @return mixed|string |
| 122 | 122 | */ |
| 123 | - public function ParseValues($template = '') |
|
| 124 | - { |
|
| 123 | + public function ParseValues($template = '') |
|
| 124 | + {
|
|
| 125 | 125 | global $modx; |
| 126 | 126 | |
| 127 | 127 | $this->curPass = $this->curPass + 1; |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | $this->LogPass(); |
| 131 | 131 | |
| 132 | 132 | // MODX Chunks |
| 133 | - if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) { |
|
| 133 | + if (preg_match_all('~(?<!(?:then|else)=`){{([^:\+{}]+)([^{}]*?)}}~s', $template, $matches)) {
|
|
| 134 | 134 | $this->Log('MODX Chunks -> Merging all chunk tags'); |
| 135 | 135 | $count = count($matches[0]); |
| 136 | 136 | $var_search = array(); |
| 137 | 137 | $var_replace = array(); |
| 138 | - for ($i = 0; $i < $count; $i++) { |
|
| 138 | + for ($i = 0; $i < $count; $i++) {
|
|
| 139 | 139 | $var_search[] = $matches[0][$i]; |
| 140 | 140 | $input = $matches[1][$i]; |
| 141 | 141 | $this->Log('MODX Chunk: ' . $input); |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | // MODx Snippets |
| 149 | 149 | //if ( preg_match_all('~\[(\[|!)([^\[]*?)(!|\])\]~s',$template, $matches)) { |
| 150 | - if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) { |
|
| 150 | + if (preg_match_all('~(?<!(?:then|else)=`)\[(\[)([^\[]*?)(\])\]~s', $template, $matches)) {
|
|
| 151 | 151 | $count = count($matches[0]); |
| 152 | 152 | $var_search = array(); |
| 153 | 153 | $var_replace = array(); |
| 154 | 154 | |
| 155 | 155 | // for each detected snippet |
| 156 | - for ($i = 0; $i < $count; $i++) { |
|
| 156 | + for ($i = 0; $i < $count; $i++) {
|
|
| 157 | 157 | $snippet = $matches[2][$i]; // snippet call |
| 158 | 158 | $this->Log("MODx Snippet -> " . $snippet); |
| 159 | 159 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // PHx / MODx Tags |
| 172 | - if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) { |
|
| 172 | + if (preg_match_all('~\[(\+|\*|\()([^:\+\[\]]+)([^\[\]]*?)(\1|\))\]~s', $template, $matches)) {
|
|
| 173 | 173 | |
| 174 | 174 | //$matches[0] // Complete string that's need to be replaced |
| 175 | 175 | //$matches[1] // Type |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | $count = count($matches[0]); |
| 181 | 181 | $var_search = array(); |
| 182 | 182 | $var_replace = array(); |
| 183 | - for ($i = 0; $i < $count; $i++) { |
|
| 183 | + for ($i = 0; $i < $count; $i++) {
|
|
| 184 | 184 | $input = $matches[2][$i]; |
| 185 | 185 | $modifiers = $matches[3][$i]; |
| 186 | 186 | $var_search[] = $matches[0][$i]; |
| 187 | - switch ($matches[1][$i]) { |
|
| 187 | + switch ($matches[1][$i]) {
|
|
| 188 | 188 | // Document / Template Variable eXtended |
| 189 | 189 | case "*": |
| 190 | 190 | $this->Log("MODx TV/DV: " . $input); |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | // Check if placeholder is set |
| 204 | 204 | if (!array_key_exists($input, $this->placeholders) && !array_key_exists($input, |
| 205 | 205 | $modx->placeholders) |
| 206 | - ) { |
|
| 206 | + ) {
|
|
| 207 | 207 | // not set so try again later. |
| 208 | 208 | $input = ''; |
| 209 | - } else { |
|
| 209 | + } else {
|
|
| 210 | 210 | // is set, get value and run filter |
| 211 | 211 | $input = $this->getPHxVariable($input); |
| 212 | 212 | } |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | $et = md5($template); // Post-process template hash |
| 221 | 221 | |
| 222 | 222 | // Log an event if this was the maximum pass |
| 223 | - if ($this->curPass == $this->maxPasses) { |
|
| 223 | + if ($this->curPass == $this->maxPasses) {
|
|
| 224 | 224 | $this->Log("Max passes reached. infinite loop protection so exiting.\n If you need the extra passes set the max passes to the highest count of nested tags in your template."); |
| 225 | 225 | } |
| 226 | 226 | // If this pass is not at maximum passes and the template hash is not the same, get at it again. |
| 227 | - if (($this->curPass < $this->maxPasses) && ($st != $et)) { |
|
| 227 | + if (($this->curPass < $this->maxPasses) && ($st != $et)) {
|
|
| 228 | 228 | $template = $this->ParseValues($template); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -237,23 +237,23 @@ discard block |
||
| 237 | 237 | * @param $modifiers |
| 238 | 238 | * @return mixed|null|string |
| 239 | 239 | */ |
| 240 | - public function Filter($input, $modifiers) |
|
| 241 | - { |
|
| 240 | + public function Filter($input, $modifiers) |
|
| 241 | + {
|
|
| 242 | 242 | global $modx; |
| 243 | 243 | $output = $input; |
| 244 | 244 | $this->Log(" |--- Input = '" . $output . "'"); |
| 245 | - if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) { |
|
| 245 | + if (preg_match_all('~:([^:=]+)(?:=`(.*?)`(?=:[^:=]+|$))?~s', $modifiers, $matches)) {
|
|
| 246 | 246 | $modifier_cmd = $matches[1]; // modifier command |
| 247 | 247 | $modifier_value = $matches[2]; // modifier value |
| 248 | 248 | $count = count($modifier_cmd); |
| 249 | 249 | $condition = array(); |
| 250 | - for ($i = 0; $i < $count; $i++) { |
|
| 250 | + for ($i = 0; $i < $count; $i++) {
|
|
| 251 | 251 | $output = trim($output); |
| 252 | 252 | $this->Log(" |--- Modifier = '" . $modifier_cmd[$i] . "'"); |
| 253 | - if ($modifier_value[$i] != '') { |
|
| 253 | + if ($modifier_value[$i] != '') {
|
|
| 254 | 254 | $this->Log(" |--- Options = '" . $modifier_value[$i] . "'"); |
| 255 | 255 | } |
| 256 | - switch ($modifier_cmd[$i]) { |
|
| 256 | + switch ($modifier_cmd[$i]) {
|
|
| 257 | 257 | ##### Conditional Modifiers |
| 258 | 258 | case "input": |
| 259 | 259 | case "if": |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | case "ir": |
| 296 | 296 | case "memberof": |
| 297 | 297 | case "mo": // Is Member Of (same as inrole but this one can be stringed as a conditional) |
| 298 | - if ($output == "&_PHX_INTERNAL_&") { |
|
| 298 | + if ($output == "&_PHX_INTERNAL_&") {
|
|
| 299 | 299 | $output = $this->user["id"]; |
| 300 | 300 | } |
| 301 | 301 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -310,23 +310,23 @@ discard block |
||
| 310 | 310 | case "show": |
| 311 | 311 | $conditional = implode(' ', $condition); |
| 312 | 312 | $isvalid = intval(eval("return (" . $conditional . ");")); |
| 313 | - if (!$isvalid) { |
|
| 313 | + if (!$isvalid) {
|
|
| 314 | 314 | $output = null; |
| 315 | 315 | } |
| 316 | 316 | break; |
| 317 | 317 | case "then": |
| 318 | 318 | $conditional = implode(' ', $condition); |
| 319 | 319 | $isvalid = intval(eval("return (" . $conditional . ");")); |
| 320 | - if ($isvalid) { |
|
| 320 | + if ($isvalid) {
|
|
| 321 | 321 | $output = $modifier_value[$i]; |
| 322 | - } else { |
|
| 322 | + } else {
|
|
| 323 | 323 | $output = null; |
| 324 | 324 | } |
| 325 | 325 | break; |
| 326 | 326 | case "else": |
| 327 | 327 | $conditional = implode(' ', $condition); |
| 328 | 328 | $isvalid = intval(eval("return (" . $conditional . ");")); |
| 329 | - if (!$isvalid) { |
|
| 329 | + if (!$isvalid) {
|
|
| 330 | 330 | $output = $modifier_value[$i]; |
| 331 | 331 | } |
| 332 | 332 | break; |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | $raw = explode("&", $modifier_value[$i]); |
| 335 | 335 | $map = array(); |
| 336 | 336 | $count = count($raw); |
| 337 | - for ($m = 0; $m < $count; $m++) { |
|
| 337 | + for ($m = 0; $m < $count; $m++) {
|
|
| 338 | 338 | $mi = explode("=", $raw[$m]); |
| 339 | 339 | $map[$mi[0]] = $mi[1]; |
| 340 | 340 | } |
@@ -415,13 +415,13 @@ discard block |
||
| 415 | 415 | $output = eval("return " . $filter . ";"); |
| 416 | 416 | break; |
| 417 | 417 | case "isnotempty": |
| 418 | - if (!empty($output)) { |
|
| 418 | + if (!empty($output)) {
|
|
| 419 | 419 | $output = $modifier_value[$i]; |
| 420 | 420 | } |
| 421 | 421 | break; |
| 422 | 422 | case "isempty": |
| 423 | 423 | case "ifempty": |
| 424 | - if (empty($output)) { |
|
| 424 | + if (empty($output)) {
|
|
| 425 | 425 | $output = $modifier_value[$i]; |
| 426 | 426 | } |
| 427 | 427 | break; |
@@ -433,12 +433,12 @@ discard block |
||
| 433 | 433 | break; |
| 434 | 434 | case "set": |
| 435 | 435 | $c = $i + 1; |
| 436 | - if ($count > $c && $modifier_cmd[$c] == "value") { |
|
| 436 | + if ($count > $c && $modifier_cmd[$c] == "value") {
|
|
| 437 | 437 | $output = preg_replace("~([^a-zA-Z0-9])~", "", $modifier_value[$i]); |
| 438 | 438 | } |
| 439 | 439 | break; |
| 440 | 440 | case "value": |
| 441 | - if ($i > 0 && $modifier_cmd[$i - 1] == "set") { |
|
| 441 | + if ($i > 0 && $modifier_cmd[$i - 1] == "set") {
|
|
| 442 | 442 | $modx->SetPlaceholder("phx." . $output, $modifier_value[$i]); |
| 443 | 443 | } |
| 444 | 444 | $output = null; |
@@ -447,13 +447,13 @@ discard block |
||
| 447 | 447 | $output = md5($output); |
| 448 | 448 | break; |
| 449 | 449 | case "userinfo": |
| 450 | - if ($output == "&_PHX_INTERNAL_&") { |
|
| 450 | + if ($output == "&_PHX_INTERNAL_&") {
|
|
| 451 | 451 | $output = $this->user["id"]; |
| 452 | 452 | } |
| 453 | 453 | $output = $this->ModUser($output, $modifier_value[$i]); |
| 454 | 454 | break; |
| 455 | 455 | case "inrole": // deprecated |
| 456 | - if ($output == "&_PHX_INTERNAL_&") { |
|
| 456 | + if ($output == "&_PHX_INTERNAL_&") {
|
|
| 457 | 457 | $output = $this->user["id"]; |
| 458 | 458 | } |
| 459 | 459 | $grps = ($this->strlen($modifier_value[$i]) > 0) ? explode(",", $modifier_value[$i]) : array(); |
@@ -465,19 +465,21 @@ discard block |
||
| 465 | 465 | $snippet = ''; |
| 466 | 466 | // modified by Anton Kuzmin (23.06.2010) // |
| 467 | 467 | $snippetName = 'phx:' . $modifier_cmd[$i]; |
| 468 | - if (isset($modx->snippetCache[$snippetName])) { |
|
| 468 | + if (isset($modx->snippetCache[$snippetName])) {
|
|
| 469 | 469 | $snippet = $modx->snippetCache[$snippetName]; |
| 470 | - } else { // not in cache so let's check the db |
|
| 470 | + } else {
|
|
| 471 | +// not in cache so let's check the db |
|
| 471 | 472 | $sql = "SELECT snippet FROM " . $modx->getFullTableName("site_snippets") . " WHERE " . $modx->getFullTableName("site_snippets") . ".name='" . $modx->db->escape($snippetName) . "';"; |
| 472 | 473 | $result = $modx->dbQuery($sql); |
| 473 | - if ($modx->recordCount($result) == 1) { |
|
| 474 | + if ($modx->recordCount($result) == 1) {
|
|
| 474 | 475 | $row = $modx->fetchRow($result); |
| 475 | 476 | $snippet = $modx->snippetCache[$row['name']] = $row['snippet']; |
| 476 | 477 | $this->Log(" |--- DB -> Custom Modifier"); |
| 477 | - } else { |
|
| 478 | - if ($modx->recordCount($result) == 0) { // If snippet not found, look in the modifiers folder |
|
| 478 | + } else {
|
|
| 479 | + if ($modx->recordCount($result) == 0) {
|
|
| 480 | +// If snippet not found, look in the modifiers folder |
|
| 479 | 481 | $filename = $modx->config['rb_base_dir'] . 'plugins/phx/modifiers/' . $modifier_cmd[$i] . '.phx.php'; |
| 480 | - if (@file_exists($filename)) { |
|
| 482 | + if (@file_exists($filename)) {
|
|
| 481 | 483 | $file_contents = @file_get_contents($filename); |
| 482 | 484 | $file_contents = str_replace('<' . '?php', '', $file_contents); |
| 483 | 485 | $file_contents = str_replace('?' . '>', '', $file_contents); |
@@ -485,7 +487,7 @@ discard block |
||
| 485 | 487 | $snippet = $modx->snippetCache[$snippetName] = $file_contents; |
| 486 | 488 | $modx->snippetCache[$snippetName . 'Props'] = ''; |
| 487 | 489 | $this->Log(" |--- File ($filename) -> Custom Modifier"); |
| 488 | - } else { |
|
| 490 | + } else {
|
|
| 489 | 491 | $this->Log(" |--- PHX Error: {$modifier_cmd[$i]} could not be found"); |
| 490 | 492 | } |
| 491 | 493 | } |
@@ -494,19 +496,19 @@ discard block |
||
| 494 | 496 | $cm = $snippet; |
| 495 | 497 | // end // |
| 496 | 498 | |
| 497 | - if (!empty($cm)) { |
|
| 499 | + if (!empty($cm)) {
|
|
| 498 | 500 | ob_start(); |
| 499 | 501 | $options = $modifier_value[$i]; |
| 500 | 502 | $custom = eval($cm); |
| 501 | 503 | $msg = ob_get_contents(); |
| 502 | 504 | $output = $msg . $custom; |
| 503 | 505 | ob_end_clean(); |
| 504 | - } else { |
|
| 506 | + } else {
|
|
| 505 | 507 | $output = ''; |
| 506 | 508 | } |
| 507 | 509 | break; |
| 508 | 510 | } |
| 509 | - if (count($condition)) { |
|
| 511 | + if (count($condition)) {
|
|
| 510 | 512 | $this->Log(" |--- Condition = '" . $condition[count($condition) - 1] . "'"); |
| 511 | 513 | } |
| 512 | 514 | $this->Log(" |--- Output = '" . $output . "'"); |
@@ -520,9 +522,9 @@ discard block |
||
| 520 | 522 | /** |
| 521 | 523 | * @return string |
| 522 | 524 | */ |
| 523 | - public function createEventLog() |
|
| 524 | - { |
|
| 525 | - if (!empty($this->console)) { |
|
| 525 | + public function createEventLog() |
|
| 526 | + {
|
|
| 527 | + if (!empty($this->console)) {
|
|
| 526 | 528 | $console = implode("\n", $this->console); |
| 527 | 529 | $this->console = array(); |
| 528 | 530 | |
@@ -535,8 +537,8 @@ discard block |
||
| 535 | 537 | * @param $string |
| 536 | 538 | * @return array|mixed|string |
| 537 | 539 | */ |
| 538 | - public function LogClean($string) |
|
| 539 | - { |
|
| 540 | + public function LogClean($string) |
|
| 541 | + {
|
|
| 540 | 542 | $string = preg_replace("/&(#[0-9]+|[a-z]+);/i", "&$1;", $string); |
| 541 | 543 | $string = APIHelpers::sanitarTag($string); |
| 542 | 544 | |
@@ -547,9 +549,9 @@ discard block |
||
| 547 | 549 | /** |
| 548 | 550 | * @param $string |
| 549 | 551 | */ |
| 550 | - public function Log($string) |
|
| 551 | - { |
|
| 552 | - if ($this->debug) { |
|
| 552 | + public function Log($string) |
|
| 553 | + {
|
|
| 554 | + if ($this->debug) {
|
|
| 553 | 555 | $this->debugLog = true; |
| 554 | 556 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
| 555 | 557 | time()) . "] " . $this->LogClean($string); |
@@ -560,9 +562,9 @@ discard block |
||
| 560 | 562 | /** |
| 561 | 563 | * @param $string |
| 562 | 564 | */ |
| 563 | - public function LogSnippet($string) |
|
| 564 | - { |
|
| 565 | - if ($this->debug) { |
|
| 565 | + public function LogSnippet($string) |
|
| 566 | + {
|
|
| 567 | + if ($this->debug) {
|
|
| 566 | 568 | $this->debugLog = true; |
| 567 | 569 | $this->console[] = (count($this->console) + 1 - $this->curPass) . " [" . strftime("%H:%M:%S", |
| 568 | 570 | time()) . "] " . " |--- Returns: <div style='margin: 10px;'>" . $this->LogClean($string) . "</div>"; |
@@ -570,8 +572,8 @@ discard block |
||
| 570 | 572 | } |
| 571 | 573 | |
| 572 | 574 | // Log pass |
| 573 | - public function LogPass() |
|
| 574 | - { |
|
| 575 | + public function LogPass() |
|
| 576 | + {
|
|
| 575 | 577 | $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>"; |
| 576 | 578 | } |
| 577 | 579 | |
@@ -579,8 +581,8 @@ discard block |
||
| 579 | 581 | /** |
| 580 | 582 | * @param $string |
| 581 | 583 | */ |
| 582 | - public function LogSource($string) |
|
| 583 | - { |
|
| 584 | + public function LogSource($string) |
|
| 585 | + {
|
|
| 584 | 586 | $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string); |
| 585 | 587 | } |
| 586 | 588 | |
@@ -592,17 +594,17 @@ discard block |
||
| 592 | 594 | * @param $field |
| 593 | 595 | * @return mixed |
| 594 | 596 | */ |
| 595 | - public function ModUser($userid, $field) |
|
| 596 | - { |
|
| 597 | + public function ModUser($userid, $field) |
|
| 598 | + {
|
|
| 597 | 599 | global $modx; |
| 598 | - if (!array_key_exists($userid, $this->cache["ui"])) { |
|
| 599 | - if (intval($userid) < 0) { |
|
| 600 | + if (!array_key_exists($userid, $this->cache["ui"])) {
|
|
| 601 | + if (intval($userid) < 0) {
|
|
| 600 | 602 | $user = $modx->getWebUserInfo(-($userid)); |
| 601 | - } else { |
|
| 603 | + } else {
|
|
| 602 | 604 | $user = $modx->getUserInfo($userid); |
| 603 | 605 | } |
| 604 | 606 | $this->cache["ui"][$userid] = $user; |
| 605 | - } else { |
|
| 607 | + } else {
|
|
| 606 | 608 | $user = $this->cache["ui"][$userid]; |
| 607 | 609 | } |
| 608 | 610 | |
@@ -615,32 +617,32 @@ discard block |
||
| 615 | 617 | * @param array $groupNames |
| 616 | 618 | * @return bool |
| 617 | 619 | */ |
| 618 | - public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
| 619 | - { |
|
| 620 | + public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array()) |
|
| 621 | + {
|
|
| 620 | 622 | global $modx; |
| 621 | 623 | |
| 622 | 624 | // if $groupNames is not an array return false |
| 623 | - if (!is_array($groupNames)) { |
|
| 625 | + if (!is_array($groupNames)) {
|
|
| 624 | 626 | return false; |
| 625 | 627 | } |
| 626 | 628 | |
| 627 | 629 | // if the user id is a negative number make it positive |
| 628 | - if (intval($userid) < 0) { |
|
| 630 | + if (intval($userid) < 0) {
|
|
| 629 | 631 | $userid = -($userid); |
| 630 | 632 | } |
| 631 | 633 | |
| 632 | 634 | // Creates an array with all webgroups the user id is in |
| 633 | - if (!array_key_exists($userid, $this->cache["mo"])) { |
|
| 635 | + if (!array_key_exists($userid, $this->cache["mo"])) {
|
|
| 634 | 636 | $tbl = $modx->getFullTableName("webgroup_names"); |
| 635 | 637 | $tbl2 = $modx->getFullTableName("web_groups"); |
| 636 | 638 | $sql = "SELECT wgn.name FROM $tbl wgn INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wg.webuser='" . $userid . "'"; |
| 637 | 639 | $this->cache["mo"][$userid] = $grpNames = $modx->db->getColumn("name", $sql); |
| 638 | - } else { |
|
| 640 | + } else {
|
|
| 639 | 641 | $grpNames = $this->cache["mo"][$userid]; |
| 640 | 642 | } |
| 641 | 643 | // Check if a supplied group matches a webgroup from the array we just created |
| 642 | - foreach ($groupNames as $k => $v) { |
|
| 643 | - if (in_array(trim($v), $grpNames)) { |
|
| 644 | + foreach ($groupNames as $k => $v) {
|
|
| 645 | + if (in_array(trim($v), $grpNames)) {
|
|
| 644 | 646 | return true; |
| 645 | 647 | } |
| 646 | 648 | } |
@@ -654,14 +656,14 @@ discard block |
||
| 654 | 656 | * @param $name |
| 655 | 657 | * @return mixed|string |
| 656 | 658 | */ |
| 657 | - public function getPHxVariable($name) |
|
| 658 | - { |
|
| 659 | + public function getPHxVariable($name) |
|
| 660 | + {
|
|
| 659 | 661 | global $modx; |
| 660 | 662 | // Check if this variable is created by PHx |
| 661 | - if (array_key_exists($name, $this->placeholders)) { |
|
| 663 | + if (array_key_exists($name, $this->placeholders)) {
|
|
| 662 | 664 | // Return the value from PHx |
| 663 | 665 | return $this->placeholders[$name]; |
| 664 | - } else { |
|
| 666 | + } else {
|
|
| 665 | 667 | // Return the value from MODx |
| 666 | 668 | return $modx->getPlaceholder($name); |
| 667 | 669 | } |
@@ -672,9 +674,9 @@ discard block |
||
| 672 | 674 | * @param $name |
| 673 | 675 | * @param $value |
| 674 | 676 | */ |
| 675 | - public function setPHxVariable($name, $value) |
|
| 676 | - { |
|
| 677 | - if ($name != "phx") { |
|
| 677 | + public function setPHxVariable($name, $value) |
|
| 678 | + {
|
|
| 679 | + if ($name != "phx") {
|
|
| 678 | 680 | $this->placeholders[$name] = $value; |
| 679 | 681 | } |
| 680 | 682 | } |
@@ -686,9 +688,9 @@ discard block |
||
| 686 | 688 | * @param null $l |
| 687 | 689 | * @return string |
| 688 | 690 | */ |
| 689 | - public function substr($str, $s, $l = null) |
|
| 690 | - { |
|
| 691 | - if (function_exists('mb_substr')) { |
|
| 691 | + public function substr($str, $s, $l = null) |
|
| 692 | + {
|
|
| 693 | + if (function_exists('mb_substr')) {
|
|
| 692 | 694 | return mb_substr($str, $s, $l); |
| 693 | 695 | } |
| 694 | 696 | |
@@ -699,9 +701,9 @@ discard block |
||
| 699 | 701 | * @param $str |
| 700 | 702 | * @return int |
| 701 | 703 | */ |
| 702 | - public function strlen($str) |
|
| 703 | - { |
|
| 704 | - if (function_exists('mb_strlen')) { |
|
| 704 | + public function strlen($str) |
|
| 705 | + {
|
|
| 706 | + if (function_exists('mb_strlen')) {
|
|
| 705 | 707 | return mb_strlen($str); |
| 706 | 708 | } |
| 707 | 709 | |
@@ -712,9 +714,9 @@ discard block |
||
| 712 | 714 | * @param $str |
| 713 | 715 | * @return string |
| 714 | 716 | */ |
| 715 | - public function strtolower($str) |
|
| 716 | - { |
|
| 717 | - if (function_exists('mb_strtolower')) { |
|
| 717 | + public function strtolower($str) |
|
| 718 | + {
|
|
| 719 | + if (function_exists('mb_strtolower')) {
|
|
| 718 | 720 | return mb_strtolower($str); |
| 719 | 721 | } |
| 720 | 722 | |
@@ -725,9 +727,9 @@ discard block |
||
| 725 | 727 | * @param $str |
| 726 | 728 | * @return string |
| 727 | 729 | */ |
| 728 | - public function strtoupper($str) |
|
| 729 | - { |
|
| 730 | - if (function_exists('mb_strtoupper')) { |
|
| 730 | + public function strtoupper($str) |
|
| 731 | + {
|
|
| 732 | + if (function_exists('mb_strtoupper')) {
|
|
| 731 | 733 | return mb_strtoupper($str); |
| 732 | 734 | } |
| 733 | 735 | |
@@ -738,9 +740,9 @@ discard block |
||
| 738 | 740 | * @param $str |
| 739 | 741 | * @return string |
| 740 | 742 | */ |
| 741 | - public function ucfirst($str) |
|
| 742 | - { |
|
| 743 | - if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
| 743 | + public function ucfirst($str) |
|
| 744 | + {
|
|
| 745 | + if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
|
| 744 | 746 | return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
| 745 | 747 | } |
| 746 | 748 | |
@@ -751,9 +753,9 @@ discard block |
||
| 751 | 753 | * @param $str |
| 752 | 754 | * @return string |
| 753 | 755 | */ |
| 754 | - public function lcfirst($str) |
|
| 755 | - { |
|
| 756 | - if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) { |
|
| 756 | + public function lcfirst($str) |
|
| 757 | + {
|
|
| 758 | + if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen')) {
|
|
| 757 | 759 | return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str)); |
| 758 | 760 | } |
| 759 | 761 | |
@@ -764,9 +766,9 @@ discard block |
||
| 764 | 766 | * @param $str |
| 765 | 767 | * @return string |
| 766 | 768 | */ |
| 767 | - public function ucwords($str) |
|
| 768 | - { |
|
| 769 | - if (function_exists('mb_convert_case')) { |
|
| 769 | + public function ucwords($str) |
|
| 770 | + {
|
|
| 771 | + if (function_exists('mb_convert_case')) {
|
|
| 770 | 772 | return mb_convert_case($str, MB_CASE_TITLE); |
| 771 | 773 | } |
| 772 | 774 | |
@@ -777,8 +779,8 @@ discard block |
||
| 777 | 779 | * @param $str |
| 778 | 780 | * @return string |
| 779 | 781 | */ |
| 780 | - public function strrev($str) |
|
| 781 | - { |
|
| 782 | + public function strrev($str) |
|
| 783 | + {
|
|
| 782 | 784 | preg_match_all('/./us', $str, $ar); |
| 783 | 785 | |
| 784 | 786 | return implode(array_reverse($ar[0])); |
@@ -788,8 +790,8 @@ discard block |
||
| 788 | 790 | * @param $str |
| 789 | 791 | * @return string |
| 790 | 792 | */ |
| 791 | - public function str_shuffle($str) |
|
| 792 | - { |
|
| 793 | + public function str_shuffle($str) |
|
| 794 | + {
|
|
| 793 | 795 | preg_match_all('/./us', $str, $ar); |
| 794 | 796 | shuffle($ar[0]); |
| 795 | 797 | |
@@ -800,8 +802,8 @@ discard block |
||
| 800 | 802 | * @param $str |
| 801 | 803 | * @return int |
| 802 | 804 | */ |
| 803 | - public function str_word_count($str) |
|
| 804 | - { |
|
| 805 | + public function str_word_count($str) |
|
| 806 | + {
|
|
| 805 | 807 | return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
| 806 | 808 | } |
| 807 | 809 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | if (($scheme == 1 && ($this->_useCut === true || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && $this->_useCut !== true)) { |
| 87 | 87 | $this->_cfg['content'] .= '…'; //... |
| 88 | 88 | } else { |
| 89 | - if ($scheme && ($this->_useCut !== true|| $scheme != 2)) { |
|
| 89 | + if ($scheme && ($this->_useCut !== true || $scheme != 2)) { |
|
| 90 | 90 | $this->_cfg['content'] .= '.'; |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | $this->_cfg['content'] = APIhelpers::sanitarTag($this->_cfg['content']); |
| 116 | 116 | break; |
| 117 | 117 | case 'chars': |
| 118 | - if (!(isset($process[1]) && $process[1] > 0)) { |
|
| 118 | + if ( ! (isset($process[1]) && $process[1] > 0)) { |
|
| 119 | 119 | $process[1] = 200; |
| 120 | 120 | } |
| 121 | 121 | $this->_cfg['content'] = APIhelpers::mb_trim_word($this->_cfg['content'], $process[1]); |
| 122 | 122 | break; |
| 123 | 123 | case 'len': |
| 124 | - if (!(isset($process[1]) && $process[1] > 0)) { |
|
| 124 | + if ( ! (isset($process[1]) && $process[1] > 0)) { |
|
| 125 | 125 | $process[1] = 200; |
| 126 | 126 | } |
| 127 | 127 | $this->_cfg['content'] = $this->summary($this->_cfg['content'], $process[1], 50, true, |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | } else { |
| 209 | 209 | $next_char = ""; |
| 210 | 210 | } |
| 211 | - if (!$quotes_on) { |
|
| 211 | + if ( ! $quotes_on) { |
|
| 212 | 212 | // Check if it's a tag |
| 213 | 213 | // On a "<" add 3 if it's an opening tag (like <a href...) |
| 214 | 214 | // or add only 1 if it's an ending tag (like </a>) |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | if (mb_strstr($tag, ' ', 'UTF-8')) { |
| 349 | 349 | $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8'); |
| 350 | 350 | } |
| 351 | - if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) { |
|
| 351 | + if ( ! mb_stristr($tag, 'br', 'UTF-8') && ! mb_stristr($tag, 'img', 'UTF-8') && ! empty ($tag)) { |
|
| 352 | 352 | $endTags .= '</' . $tag . '>'; |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Class SummaryText |
| 19 | 19 | */ |
| 20 | -class SummaryText |
|
| 21 | -{ |
|
| 20 | +class SummaryText |
|
| 21 | +{
|
|
| 22 | 22 | /** |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * @param $action |
| 46 | 46 | * @param null $break |
| 47 | 47 | */ |
| 48 | - public function __construct($text, $action, $break = null) |
|
| 49 | - { |
|
| 48 | + public function __construct($text, $action, $break = null) |
|
| 49 | + {
|
|
| 50 | 50 | $this->_cfg['content'] = is_scalar($text) ? $text : ''; |
| 51 | 51 | $this->_cfg['original'] = $this->_cfg['content']; |
| 52 | 52 | $this->_cfg['summary'] = is_scalar($action) ? $action : ''; |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * @param $cut |
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | - public function setCut($cut) |
|
| 61 | - { |
|
| 62 | - if (is_scalar($cut) && $cut != '') { |
|
| 60 | + public function setCut($cut) |
|
| 61 | + {
|
|
| 62 | + if (is_scalar($cut) && $cut != '') {
|
|
| 63 | 63 | $this->_cfg['cut'] = $cut; |
| 64 | 64 | $flag = true; |
| 65 | - } else { |
|
| 65 | + } else {
|
|
| 66 | 66 | $flag = false; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | /** |
| 73 | 73 | * @return mixed |
| 74 | 74 | */ |
| 75 | - public function getCut() |
|
| 76 | - { |
|
| 75 | + public function getCut() |
|
| 76 | + {
|
|
| 77 | 77 | return \APIHelpers::getkey($this->_cfg, 'cut', '<cut/>'); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | * @param int $scheme |
| 82 | 82 | * @return mixed |
| 83 | 83 | */ |
| 84 | - protected function dotted($scheme = 0) |
|
| 85 | - { |
|
| 86 | - if (($scheme == 1 && ($this->_useCut === true || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && $this->_useCut !== true)) { |
|
| 84 | + protected function dotted($scheme = 0) |
|
| 85 | + {
|
|
| 86 | + if (($scheme == 1 && ($this->_useCut === true || $this->_useSubstr)) || ($scheme == 2 && $this->_useSubstr && $this->_useCut !== true)) {
|
|
| 87 | 87 | $this->_cfg['content'] .= '…'; //... |
| 88 | - } else { |
|
| 89 | - if ($scheme && ($this->_useCut !== true|| $scheme != 2)) { |
|
| 88 | + } else {
|
|
| 89 | + if ($scheme && ($this->_useCut !== true|| $scheme != 2)) {
|
|
| 90 | 90 | $this->_cfg['content'] .= '.'; |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -98,16 +98,16 @@ discard block |
||
| 98 | 98 | * @param int $dotted |
| 99 | 99 | * @return mixed |
| 100 | 100 | */ |
| 101 | - public function run($dotted = 0) |
|
| 102 | - { |
|
| 101 | + public function run($dotted = 0) |
|
| 102 | + {
|
|
| 103 | 103 | $this->_dotted = $dotted; |
| 104 | - if (isset($this->_cfg['content'], $this->_cfg['summary']) && $this->_cfg['summary'] != '' && $this->_cfg['content'] != '') { |
|
| 104 | + if (isset($this->_cfg['content'], $this->_cfg['summary']) && $this->_cfg['summary'] != '' && $this->_cfg['content'] != '') {
|
|
| 105 | 105 | $param = explode(",", $this->_cfg['summary']); |
| 106 | 106 | $this->_cfg['content'] = $this->beforeCut($this->_cfg['content'], $this->getCut()); |
| 107 | - foreach ($param as $doing) { |
|
| 107 | + foreach ($param as $doing) {
|
|
| 108 | 108 | |
| 109 | 109 | $process = explode(":", $doing); |
| 110 | - switch ($process[0]) { |
|
| 110 | + switch ($process[0]) {
|
|
| 111 | 111 | case 'notags': |
| 112 | 112 | $this->_cfg['content'] = strip_tags($this->_cfg['content']); |
| 113 | 113 | break; |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | $this->_cfg['content'] = APIhelpers::sanitarTag($this->_cfg['content']); |
| 116 | 116 | break; |
| 117 | 117 | case 'chars': |
| 118 | - if (!(isset($process[1]) && $process[1] > 0)) { |
|
| 118 | + if (!(isset($process[1]) && $process[1] > 0)) {
|
|
| 119 | 119 | $process[1] = 200; |
| 120 | 120 | } |
| 121 | 121 | $this->_cfg['content'] = APIhelpers::mb_trim_word($this->_cfg['content'], $process[1]); |
| 122 | 122 | break; |
| 123 | 123 | case 'len': |
| 124 | - if (!(isset($process[1]) && $process[1] > 0)) { |
|
| 124 | + if (!(isset($process[1]) && $process[1] > 0)) {
|
|
| 125 | 125 | $process[1] = 200; |
| 126 | 126 | } |
| 127 | 127 | $this->_cfg['content'] = $this->summary($this->_cfg['content'], $process[1], 50, true, |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | * @param string $splitter |
| 140 | 140 | * @return array|mixed |
| 141 | 141 | */ |
| 142 | - protected function beforeCut($resource, $splitter = '') |
|
| 143 | - { |
|
| 144 | - if ($splitter !== '') { |
|
| 142 | + protected function beforeCut($resource, $splitter = '') |
|
| 143 | + {
|
|
| 144 | + if ($splitter !== '') {
|
|
| 145 | 145 | $summary = str_replace('<p>' . $splitter . '</p>', $splitter, |
| 146 | 146 | $resource); // For TinyMCE or if it isn't wrapped inside paragraph tags |
| 147 | 147 | $summary = explode($splitter, $summary, 2); |
| 148 | 148 | $this->_useCut = isset($summary[1]); |
| 149 | 149 | $summary = $summary['0']; |
| 150 | - } else { |
|
| 150 | + } else {
|
|
| 151 | 151 | $summary = $resource; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -162,18 +162,18 @@ discard block |
||
| 162 | 162 | * @param string $splitter |
| 163 | 163 | * @return array|mixed|string |
| 164 | 164 | */ |
| 165 | - protected function summary($resource, $truncLen, $truncOffset, $truncChars, $splitter = '') |
|
| 166 | - { |
|
| 167 | - if (isset($this->_useCut) && $splitter != '' && mb_strstr($resource, $splitter, 'UTF-8')) { |
|
| 165 | + protected function summary($resource, $truncLen, $truncOffset, $truncChars, $splitter = '') |
|
| 166 | + {
|
|
| 167 | + if (isset($this->_useCut) && $splitter != '' && mb_strstr($resource, $splitter, 'UTF-8')) {
|
|
| 168 | 168 | $summary = $this->beforeCut($resource, $splitter); |
| 169 | - } else { |
|
| 170 | - if ($this->_useCut !== true && (mb_strlen($resource, 'UTF-8') > $truncLen)) { |
|
| 169 | + } else {
|
|
| 170 | + if ($this->_useCut !== true && (mb_strlen($resource, 'UTF-8') > $truncLen)) {
|
|
| 171 | 171 | |
| 172 | 172 | $summary = $this->html_substr($resource, $truncLen, $truncOffset, $truncChars); |
| 173 | - if ($resource != $summary) { |
|
| 173 | + if ($resource != $summary) {
|
|
| 174 | 174 | $this->_useSubstr = true; |
| 175 | 175 | } |
| 176 | - } else { |
|
| 176 | + } else {
|
|
| 177 | 177 | $summary = $resource; |
| 178 | 178 | } |
| 179 | 179 | } |
@@ -194,60 +194,60 @@ discard block |
||
| 194 | 194 | * @param bool $truncChars |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - protected function html_substr($posttext, $minimum_length = 200, $length_offset = 100, $truncChars = false) |
|
| 198 | - { |
|
| 197 | + protected function html_substr($posttext, $minimum_length = 200, $length_offset = 100, $truncChars = false) |
|
| 198 | + {
|
|
| 199 | 199 | $tag_counter = 0; |
| 200 | 200 | $quotes_on = false; |
| 201 | - if (mb_strlen($posttext) > $minimum_length && $truncChars !== true) { |
|
| 201 | + if (mb_strlen($posttext) > $minimum_length && $truncChars !== true) {
|
|
| 202 | 202 | $c = 0; |
| 203 | 203 | $len = mb_strlen($posttext, 'UTF-8'); |
| 204 | - for ($i = 0; $i < $len; $i++) { |
|
| 204 | + for ($i = 0; $i < $len; $i++) {
|
|
| 205 | 205 | $current_char = mb_substr($posttext, $i, 1, 'UTF-8'); |
| 206 | - if ($i < mb_strlen($posttext, 'UTF-8') - 1) { |
|
| 206 | + if ($i < mb_strlen($posttext, 'UTF-8') - 1) {
|
|
| 207 | 207 | $next_char = mb_substr($posttext, $i + 1, 1, 'UTF-8'); |
| 208 | - } else { |
|
| 208 | + } else {
|
|
| 209 | 209 | $next_char = ""; |
| 210 | 210 | } |
| 211 | - if (!$quotes_on) { |
|
| 211 | + if (!$quotes_on) {
|
|
| 212 | 212 | // Check if it's a tag |
| 213 | 213 | // On a "<" add 3 if it's an opening tag (like <a href...) |
| 214 | 214 | // or add only 1 if it's an ending tag (like </a>) |
| 215 | - if ($current_char == '<') { |
|
| 216 | - if ($next_char == '/') { |
|
| 215 | + if ($current_char == '<') {
|
|
| 216 | + if ($next_char == '/') {
|
|
| 217 | 217 | $tag_counter += 1; |
| 218 | - } else { |
|
| 218 | + } else {
|
|
| 219 | 219 | $tag_counter += 3; |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | // Slash signifies an ending (like </a> or ... />) |
| 223 | 223 | // substract 2 |
| 224 | - if ($current_char == '/' && $tag_counter <> 0) { |
|
| 224 | + if ($current_char == '/' && $tag_counter <> 0) {
|
|
| 225 | 225 | $tag_counter -= 2; |
| 226 | 226 | } |
| 227 | 227 | // On a ">" substract 1 |
| 228 | - if ($current_char == '>') { |
|
| 228 | + if ($current_char == '>') {
|
|
| 229 | 229 | $tag_counter -= 1; |
| 230 | 230 | } |
| 231 | 231 | // If quotes are encountered, start ignoring the tags |
| 232 | 232 | // (for directory slashes) |
| 233 | - if ($current_char == '"') { |
|
| 233 | + if ($current_char == '"') {
|
|
| 234 | 234 | $quotes_on = true; |
| 235 | 235 | } |
| 236 | - } else { |
|
| 236 | + } else {
|
|
| 237 | 237 | // IF quotes are encountered again, turn it back off |
| 238 | - if ($current_char == '"') { |
|
| 238 | + if ($current_char == '"') {
|
|
| 239 | 239 | $quotes_on = false; |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Count only the chars outside html tags |
| 244 | - if ($tag_counter == 2 || $tag_counter == 0) { |
|
| 244 | + if ($tag_counter == 2 || $tag_counter == 0) {
|
|
| 245 | 245 | $c++; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Check if the counter has reached the minimum length yet, |
| 249 | 249 | // then wait for the tag_counter to become 0, and chop the string there |
| 250 | - if ($c > $minimum_length - $length_offset && $tag_counter == 0) { |
|
| 250 | + if ($c > $minimum_length - $length_offset && $tag_counter == 0) {
|
|
| 251 | 251 | $posttext = mb_substr($posttext, 0, $i + 1, 'UTF-8'); |
| 252 | 252 | |
| 253 | 253 | return $posttext; |
@@ -267,20 +267,20 @@ discard block |
||
| 267 | 267 | * @param string $break |
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | - protected function textTrunc($string, $limit, $break = ". ") |
|
| 271 | - { |
|
| 270 | + protected function textTrunc($string, $limit, $break = ". ") |
|
| 271 | + {
|
|
| 272 | 272 | // Original PHP code from The Art of Web: www.the-art-of-web.com |
| 273 | 273 | |
| 274 | 274 | // return with no change if string is shorter than $limit |
| 275 | - if (mb_strlen($string, 'UTF-8') < $limit) { |
|
| 275 | + if (mb_strlen($string, 'UTF-8') < $limit) {
|
|
| 276 | 276 | return $string; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $string = mb_substr($string, 0, $limit, 'UTF-8'); |
| 280 | - if (false !== ($breakpoint = mb_strrpos($string, $break, 'UTF-8'))) { |
|
| 280 | + if (false !== ($breakpoint = mb_strrpos($string, $break, 'UTF-8'))) {
|
|
| 281 | 281 | $string = mb_substr($string, 0, $breakpoint + 1, 'UTF-8'); |
| 282 | - } else { |
|
| 283 | - if ($break != ' ') { |
|
| 282 | + } else {
|
|
| 283 | + if ($break != ' ') {
|
|
| 284 | 284 | $string = $this->textTrunc($string, $limit, " "); |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | * @param $str |
| 293 | 293 | * @return mixed |
| 294 | 294 | */ |
| 295 | - protected function rTriming($str) |
|
| 296 | - { |
|
| 295 | + protected function rTriming($str) |
|
| 296 | + {
|
|
| 297 | 297 | $str = preg_replace('/[\r\n]++/', ' ', $str); |
| 298 | - if ($this->_useCut !== true || $this->_dotted != 2) { |
|
| 298 | + if ($this->_useCut !== true || $this->_dotted != 2) {
|
|
| 299 | 299 | $str = preg_replace("/(([\.,\-:!?;\s])|(&\w+;))+$/ui", "", $str); |
| 300 | 300 | } |
| 301 | 301 | |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | * @param $text |
| 309 | 309 | * @return string |
| 310 | 310 | */ |
| 311 | - private function closeTags($text) |
|
| 312 | - { |
|
| 311 | + private function closeTags($text) |
|
| 312 | + {
|
|
| 313 | 313 | $openPattern = "/<([^\/].*?)>/"; |
| 314 | 314 | $closePattern = "/<\/(.*?)>/"; |
| 315 | 315 | $endTags = ''; |
@@ -319,15 +319,15 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | $c = 0; |
| 321 | 321 | $loopCounter = count($closeTags[1]); //used to prevent an infinite loop if the html is malformed |
| 322 | - while ($c < count($closeTags[1]) && $loopCounter) { |
|
| 322 | + while ($c < count($closeTags[1]) && $loopCounter) {
|
|
| 323 | 323 | $i = 0; |
| 324 | - while ($i < count($openTags[1])) { |
|
| 324 | + while ($i < count($openTags[1])) {
|
|
| 325 | 325 | $tag = trim($openTags[1][$i]); |
| 326 | 326 | |
| 327 | - if (mb_strstr($tag, ' ', 'UTF-8')) { |
|
| 327 | + if (mb_strstr($tag, ' ', 'UTF-8')) {
|
|
| 328 | 328 | $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8'); |
| 329 | 329 | } |
| 330 | - if ($tag == $closeTags[1][$c]) { |
|
| 330 | + if ($tag == $closeTags[1][$c]) {
|
|
| 331 | 331 | $openTags[1][$i] = ''; |
| 332 | 332 | $c++; |
| 333 | 333 | break; |
@@ -339,16 +339,16 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | $results = $openTags[1]; |
| 341 | 341 | |
| 342 | - if (is_array($results)) { |
|
| 342 | + if (is_array($results)) {
|
|
| 343 | 343 | $results = array_reverse($results); |
| 344 | 344 | |
| 345 | - foreach ($results as $tag) { |
|
| 345 | + foreach ($results as $tag) {
|
|
| 346 | 346 | $tag = trim($tag); |
| 347 | 347 | |
| 348 | - if (mb_strstr($tag, ' ', 'UTF-8')) { |
|
| 348 | + if (mb_strstr($tag, ' ', 'UTF-8')) {
|
|
| 349 | 349 | $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8'); |
| 350 | 350 | } |
| 351 | - if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) { |
|
| 351 | + if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty ($tag)) {
|
|
| 352 | 352 | $endTags .= '</' . $tag . '>'; |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | /** |
| 8 | 8 | * Class MODxAPIhelpers |
| 9 | 9 | */ |
| 10 | -class MODxAPIhelpers |
|
| 11 | -{ |
|
| 10 | +class MODxAPIhelpers |
|
| 11 | +{
|
|
| 12 | 12 | /** |
| 13 | 13 | * @param $email |
| 14 | 14 | * @param bool $dns |
| 15 | 15 | * @return false|string |
| 16 | 16 | */ |
| 17 | - public function emailValidate($email, $dns = true) |
|
| 18 | - { |
|
| 17 | + public function emailValidate($email, $dns = true) |
|
| 18 | + {
|
|
| 19 | 19 | return \APIhelpers::emailValidate($email, $dns); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * @param string $data |
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | - public function genPass($len, $data = '') |
|
| 28 | - { |
|
| 27 | + public function genPass($len, $data = '') |
|
| 28 | + {
|
|
| 29 | 29 | return \APIhelpers::genPass($len, $data); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | * @param string $out |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - public function getUserIP($out = '127.0.0.1') |
|
| 37 | - { |
|
| 36 | + public function getUserIP($out = '127.0.0.1') |
|
| 37 | + {
|
|
| 38 | 38 | return \APIhelpers::getUserIP($out); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @param $data |
| 43 | 43 | * @return array|mixed|string |
| 44 | 44 | */ |
| 45 | - public function sanitarTag($data) |
|
| 46 | - { |
|
| 45 | + public function sanitarTag($data) |
|
| 46 | + {
|
|
| 47 | 47 | return \APIhelpers::sanitarTag($data); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | * @param array $mixArray |
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | - public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
| 58 | - { |
|
| 57 | + public function checkString($value, $minLen = 1, $alph = array(), $mixArray = array()) |
|
| 58 | + {
|
|
| 59 | 59 | return \APIhelpers::checkString($value, $minLen, $alph, $mixArray); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * Class MODxAPI |
| 65 | 65 | */ |
| 66 | -abstract class MODxAPI extends MODxAPIhelpers |
|
| 67 | -{ |
|
| 66 | +abstract class MODxAPI extends MODxAPIhelpers |
|
| 67 | +{
|
|
| 68 | 68 | /** |
| 69 | 69 | * Объект DocumentParser - основной класс MODX |
| 70 | 70 | * @var \DocumentParser |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | * @param bool $debug |
| 149 | 149 | * @throws Exception |
| 150 | 150 | */ |
| 151 | - public function __construct(DocumentParser $modx, $debug = false) |
|
| 152 | - { |
|
| 151 | + public function __construct(DocumentParser $modx, $debug = false) |
|
| 152 | + {
|
|
| 153 | 153 | $this->modx = $modx; |
| 154 | - if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) { |
|
| 154 | + if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()) {
|
|
| 155 | 155 | throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.'); |
| 156 | 156 | } |
| 157 | 157 | |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | * @param boolean $flag |
| 164 | 164 | * @return $this |
| 165 | 165 | */ |
| 166 | - public function setDebug($flag) |
|
| 167 | - { |
|
| 166 | + public function setDebug($flag) |
|
| 167 | + {
|
|
| 168 | 168 | $this->_debug = (bool)$flag; |
| 169 | 169 | |
| 170 | 170 | return $this; |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * @return bool |
| 175 | 175 | */ |
| 176 | - public function getDebug() |
|
| 177 | - { |
|
| 176 | + public function getDebug() |
|
| 177 | + {
|
|
| 178 | 178 | return $this->_debug; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | - public function getDefaultFields() |
|
| 185 | - { |
|
| 184 | + public function getDefaultFields() |
|
| 185 | + {
|
|
| 186 | 186 | return $this->default_field; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | * @param $value |
| 191 | 191 | * @return int|mixed|string |
| 192 | 192 | */ |
| 193 | - protected function getTime($value) |
|
| 194 | - { |
|
| 193 | + protected function getTime($value) |
|
| 194 | + {
|
|
| 195 | 195 | $value = trim($value); |
| 196 | - if (!empty($value)) { |
|
| 197 | - if (!is_numeric($value)) { |
|
| 196 | + if (!empty($value)) {
|
|
| 197 | + if (!is_numeric($value)) {
|
|
| 198 | 198 | $value = (int)strtotime($value); |
| 199 | 199 | } |
| 200 | - if (!empty($value)) { |
|
| 200 | + if (!empty($value)) {
|
|
| 201 | 201 | $value += $this->modxConfig('server_offset_time'); |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | * @param null $default |
| 211 | 211 | * @return mixed |
| 212 | 212 | */ |
| 213 | - final public function modxConfig($name, $default = null) |
|
| 214 | - { |
|
| 213 | + final public function modxConfig($name, $default = null) |
|
| 214 | + {
|
|
| 215 | 215 | return APIHelpers::getkey($this->modx->config, $name, $default); |
| 216 | 216 | } |
| 217 | 217 | |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | * @param $q |
| 220 | 220 | * @return $this |
| 221 | 221 | */ |
| 222 | - public function addQuery($q) |
|
| 223 | - { |
|
| 224 | - if (is_scalar($q) && !empty($q)) { |
|
| 222 | + public function addQuery($q) |
|
| 223 | + {
|
|
| 224 | + if (is_scalar($q) && !empty($q)) {
|
|
| 225 | 225 | $this->_query[] = $q; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * @return array |
| 233 | 233 | */ |
| 234 | - public function getQueryList() |
|
| 235 | - { |
|
| 234 | + public function getQueryList() |
|
| 235 | + {
|
|
| 236 | 236 | return $this->_query; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @param $SQL |
| 241 | 241 | * @return mixed |
| 242 | 242 | */ |
| 243 | - final public function query($SQL) |
|
| 244 | - { |
|
| 245 | - if ($this->getDebug()) { |
|
| 243 | + final public function query($SQL) |
|
| 244 | + {
|
|
| 245 | + if ($this->getDebug()) {
|
|
| 246 | 246 | $this->addQuery($SQL); |
| 247 | 247 | } |
| 248 | 248 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @param $value |
| 254 | 254 | * @return string|void |
| 255 | 255 | */ |
| 256 | - final public function escape($value) |
|
| 257 | - { |
|
| 258 | - if (!is_scalar($value)) { |
|
| 256 | + final public function escape($value) |
|
| 257 | + {
|
|
| 258 | + if (!is_scalar($value)) {
|
|
| 259 | 259 | $value = ''; |
| 260 | - } else { |
|
| 260 | + } else {
|
|
| 261 | 261 | $value = $this->modx->db->escape($value); |
| 262 | 262 | } |
| 263 | 263 | |
@@ -270,9 +270,9 @@ discard block |
||
| 270 | 270 | * @param bool $flag |
| 271 | 271 | * @return $this |
| 272 | 272 | */ |
| 273 | - final public function invokeEvent($name, $data = array(), $flag = false) |
|
| 274 | - { |
|
| 275 | - if ((bool)$flag === true) { |
|
| 273 | + final public function invokeEvent($name, $data = array(), $flag = false) |
|
| 274 | + {
|
|
| 275 | + if ((bool)$flag === true) {
|
|
| 276 | 276 | $this->modx->invokeEvent($name, $data); |
| 277 | 277 | } |
| 278 | 278 | |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | * @param boolean $flag |
| 286 | 286 | * @return array|bool |
| 287 | 287 | */ |
| 288 | - final public function getInvokeEventResult($name, $data = array(), $flag = null) |
|
| 289 | - { |
|
| 288 | + final public function getInvokeEventResult($name, $data = array(), $flag = null) |
|
| 289 | + {
|
|
| 290 | 290 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
| 291 | 291 | |
| 292 | 292 | return $flag ? $this->modx->invokeEvent($name, $data) : false; |
@@ -295,8 +295,8 @@ discard block |
||
| 295 | 295 | /** |
| 296 | 296 | * @return $this |
| 297 | 297 | */ |
| 298 | - final public function clearLog() |
|
| 299 | - { |
|
| 298 | + final public function clearLog() |
|
| 299 | + {
|
|
| 300 | 300 | $this->log = array(); |
| 301 | 301 | |
| 302 | 302 | return $this; |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | /** |
| 306 | 306 | * @return array |
| 307 | 307 | */ |
| 308 | - final public function getLog() |
|
| 309 | - { |
|
| 308 | + final public function getLog() |
|
| 309 | + {
|
|
| 310 | 310 | return $this->log; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -314,10 +314,10 @@ discard block |
||
| 314 | 314 | * @param bool $flush |
| 315 | 315 | * @return $this |
| 316 | 316 | */ |
| 317 | - final public function list_log($flush = false) |
|
| 318 | - { |
|
| 317 | + final public function list_log($flush = false) |
|
| 318 | + {
|
|
| 319 | 319 | echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>'; |
| 320 | - if ($flush) { |
|
| 320 | + if ($flush) {
|
|
| 321 | 321 | $this->clearLog(); |
| 322 | 322 | } |
| 323 | 323 | |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | * @param bool $full |
| 329 | 329 | * @return string |
| 330 | 330 | */ |
| 331 | - final public function getCachePath($full = true) |
|
| 332 | - { |
|
| 331 | + final public function getCachePath($full = true) |
|
| 332 | + {
|
|
| 333 | 333 | $path = $this->modx->getCachePath(); |
| 334 | - if ($full) { |
|
| 334 | + if ($full) {
|
|
| 335 | 335 | $path = MODX_BASE_PATH . substr($path, strlen(MODX_BASE_URL)); |
| 336 | 336 | } |
| 337 | 337 | |
@@ -342,10 +342,10 @@ discard block |
||
| 342 | 342 | * @param boolean $fire_events |
| 343 | 343 | * @param bool $custom |
| 344 | 344 | */ |
| 345 | - final public function clearCache($fire_events = false, $custom = false) |
|
| 346 | - { |
|
| 345 | + final public function clearCache($fire_events = false, $custom = false) |
|
| 346 | + {
|
|
| 347 | 347 | $IDs = array(); |
| 348 | - if ($custom === false) { |
|
| 348 | + if ($custom === false) {
|
|
| 349 | 349 | $this->modx->clearCache(); |
| 350 | 350 | include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
| 351 | 351 | $sync = new synccache(); |
@@ -353,22 +353,22 @@ discard block |
||
| 353 | 353 | $sync->setCachepath($path); |
| 354 | 354 | $sync->setReport(false); |
| 355 | 355 | $sync->emptyCache(); |
| 356 | - } else { |
|
| 357 | - if (is_scalar($custom)) { |
|
| 356 | + } else {
|
|
| 357 | + if (is_scalar($custom)) {
|
|
| 358 | 358 | $custom = array($custom); |
| 359 | 359 | } |
| 360 | - switch ($this->modx->config['cache_type']) { |
|
| 360 | + switch ($this->modx->config['cache_type']) {
|
|
| 361 | 361 | case 2: |
| 362 | 362 | $cacheFile = "_*.pageCache.php"; |
| 363 | 363 | break; |
| 364 | 364 | default: |
| 365 | 365 | $cacheFile = ".pageCache.php"; |
| 366 | 366 | } |
| 367 | - if (is_array($custom)) { |
|
| 368 | - foreach ($custom as $id) { |
|
| 367 | + if (is_array($custom)) {
|
|
| 368 | + foreach ($custom as $id) {
|
|
| 369 | 369 | $tmp = glob(MODX_BASE_PATH . "assets/cache/docid_" . $id . $cacheFile); |
| 370 | - foreach ($tmp as $file) { |
|
| 371 | - if (is_readable($file)) { |
|
| 370 | + foreach ($tmp as $file) {
|
|
| 371 | + if (is_readable($file)) {
|
|
| 372 | 372 | unlink($file); |
| 373 | 373 | } |
| 374 | 374 | $IDs[] = $id; |
@@ -384,9 +384,9 @@ discard block |
||
| 384 | 384 | * @param integer $id |
| 385 | 385 | * @return MODxAPI |
| 386 | 386 | */ |
| 387 | - public function switchObject($id) |
|
| 388 | - { |
|
| 389 | - switch (true) { |
|
| 387 | + public function switchObject($id) |
|
| 388 | + {
|
|
| 389 | + switch (true) {
|
|
| 390 | 390 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
| 391 | 391 | case ($this->getID() != $id && $id): |
| 392 | 392 | $obj = clone $this; |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @param bool $flag |
| 409 | 409 | * @return $this |
| 410 | 410 | */ |
| 411 | - public function useIgnore($flag = true) |
|
| 412 | - { |
|
| 411 | + public function useIgnore($flag = true) |
|
| 412 | + {
|
|
| 413 | 413 | $this->ignoreError = $flag ? 'IGNORE' : ''; |
| 414 | 414 | |
| 415 | 415 | return $this; |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | /** |
| 419 | 419 | * @return bool |
| 420 | 420 | */ |
| 421 | - public function hasIgnore() |
|
| 422 | - { |
|
| 421 | + public function hasIgnore() |
|
| 422 | + {
|
|
| 423 | 423 | return (bool)$this->ignoreError; |
| 424 | 424 | } |
| 425 | 425 | |
@@ -428,9 +428,9 @@ discard block |
||
| 428 | 428 | * @param $value |
| 429 | 429 | * @return $this |
| 430 | 430 | */ |
| 431 | - public function set($key, $value) |
|
| 432 | - { |
|
| 433 | - if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 431 | + public function set($key, $value) |
|
| 432 | + {
|
|
| 433 | + if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
|
|
| 434 | 434 | $this->field[$key] = $value; |
| 435 | 435 | } |
| 436 | 436 | |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | /** |
| 441 | 441 | * @return null|int |
| 442 | 442 | */ |
| 443 | - final public function getID() |
|
| 444 | - { |
|
| 443 | + final public function getID() |
|
| 444 | + {
|
|
| 445 | 445 | return $this->id; |
| 446 | 446 | } |
| 447 | 447 | |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * @param $key |
| 450 | 450 | * @return mixed |
| 451 | 451 | */ |
| 452 | - public function get($key) |
|
| 453 | - { |
|
| 452 | + public function get($key) |
|
| 453 | + {
|
|
| 454 | 454 | return APIHelpers::getkey($this->field, $key, null); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -458,10 +458,10 @@ discard block |
||
| 458 | 458 | * @param $data |
| 459 | 459 | * @return $this |
| 460 | 460 | */ |
| 461 | - public function fromArray($data) |
|
| 462 | - { |
|
| 463 | - if (is_array($data)) { |
|
| 464 | - foreach ($data as $key => $value) { |
|
| 461 | + public function fromArray($data) |
|
| 462 | + {
|
|
| 463 | + if (is_array($data)) {
|
|
| 464 | + foreach ($data as $key => $value) {
|
|
| 465 | 465 | $this->set($key, $value); |
| 466 | 466 | } |
| 467 | 467 | } |
@@ -477,22 +477,22 @@ discard block |
||
| 477 | 477 | * @return $this |
| 478 | 478 | * @throws Exception |
| 479 | 479 | */ |
| 480 | - final protected function Uset($key, $id = '') |
|
| 481 | - { |
|
| 482 | - if (!isset($this->field[$key])) { |
|
| 480 | + final protected function Uset($key, $id = '') |
|
| 481 | + {
|
|
| 482 | + if (!isset($this->field[$key])) {
|
|
| 483 | 483 | $tmp = "`{$key}`=''"; |
| 484 | 484 | $this->log[] = "{$key} is empty"; |
| 485 | - } else { |
|
| 486 | - if ($this->issetField($key) && is_scalar($this->field[$key])) { |
|
| 485 | + } else {
|
|
| 486 | + if ($this->issetField($key) && is_scalar($this->field[$key])) {
|
|
| 487 | 487 | $tmp = "`{$key}`='{$this->escape($this->field[$key])}'"; |
| 488 | - } else { |
|
| 488 | + } else {
|
|
| 489 | 489 | throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>"); |
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | - if (!empty($tmp) && $this->isChanged($key)) { |
|
| 493 | - if ($id == '') { |
|
| 492 | + if (!empty($tmp) && $this->isChanged($key)) {
|
|
| 493 | + if ($id == '') {
|
|
| 494 | 494 | $this->set[] = $tmp; |
| 495 | - } else { |
|
| 495 | + } else {
|
|
| 496 | 496 | $this->set[$id][] = $tmp; |
| 497 | 497 | } |
| 498 | 498 | } |
@@ -506,8 +506,11 @@ discard block |
||
| 506 | 506 | * @param array $data |
| 507 | 507 | * @return $this |
| 508 | 508 | */ |
| 509 | - public function store($data = array()) { |
|
| 510 | - if (is_array($data)) $this->store = $data; |
|
| 509 | + public function store($data = array()) |
|
| 510 | + {
|
|
| 511 | + if (is_array($data)) {
|
|
| 512 | + $this->store = $data; |
|
| 513 | + } |
|
| 511 | 514 | |
| 512 | 515 | return $this; |
| 513 | 516 | } |
@@ -518,10 +521,11 @@ discard block |
||
| 518 | 521 | * @param string $key |
| 519 | 522 | * @return MODxAPI |
| 520 | 523 | */ |
| 521 | - public function rollback($key = '') { |
|
| 522 | - if (!empty($key) && isset($this->store[$key])) { |
|
| 524 | + public function rollback($key = '') |
|
| 525 | + {
|
|
| 526 | + if (!empty($key) && isset($this->store[$key])) {
|
|
| 523 | 527 | $this->set($key,$this->store[$key]); |
| 524 | - } else { |
|
| 528 | + } else {
|
|
| 525 | 529 | $this->fromArray($this->store); |
| 526 | 530 | } |
| 527 | 531 | |
@@ -534,7 +538,8 @@ discard block |
||
| 534 | 538 | * @param $key |
| 535 | 539 | * @return bool |
| 536 | 540 | */ |
| 537 | - public function isChanged($key) { |
|
| 541 | + public function isChanged($key) |
|
| 542 | + {
|
|
| 538 | 543 | $flag = !isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); |
| 539 | 544 | |
| 540 | 545 | return $flag; |
@@ -547,23 +552,24 @@ discard block |
||
| 547 | 552 | * @return array |
| 548 | 553 | * @throws Exception |
| 549 | 554 | */ |
| 550 | - final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
|
| 551 | - { |
|
| 555 | + final public function cleanIDs($IDs, $sep = ',', $ignore = array()) |
|
| 556 | + {
|
|
| 552 | 557 | $out = array(); |
| 553 | - if (!is_array($IDs)) { |
|
| 554 | - if (is_scalar($IDs)) { |
|
| 558 | + if (!is_array($IDs)) {
|
|
| 559 | + if (is_scalar($IDs)) {
|
|
| 555 | 560 | $IDs = explode($sep, $IDs); |
| 556 | - } else { |
|
| 561 | + } else {
|
|
| 557 | 562 | $IDs = array(); |
| 558 | 563 | throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>'); |
| 559 | 564 | } |
| 560 | 565 | } |
| 561 | - foreach ($IDs as $item) { |
|
| 566 | + foreach ($IDs as $item) {
|
|
| 562 | 567 | $item = trim($item); |
| 563 | - if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff |
|
| 564 | - if (!empty($ignore) && in_array((int)$item, $ignore, true)) { |
|
| 568 | + if (is_scalar($item) && (int)$item >= 0) {
|
|
| 569 | +//Fix 0xfffffffff |
|
| 570 | + if (!empty($ignore) && in_array((int)$item, $ignore, true)) {
|
|
| 565 | 571 | $this->log[] = 'Ignore id ' . (int)$item; |
| 566 | - } else { |
|
| 572 | + } else {
|
|
| 567 | 573 | $out[] = (int)$item; |
| 568 | 574 | } |
| 569 | 575 | } |
@@ -579,26 +585,26 @@ discard block |
||
| 579 | 585 | * @return $this |
| 580 | 586 | * @throws Exception |
| 581 | 587 | */ |
| 582 | - final public function fromJson($data, $callback = null) |
|
| 583 | - { |
|
| 584 | - if (is_scalar($data) && !empty($data)) { |
|
| 588 | + final public function fromJson($data, $callback = null) |
|
| 589 | + {
|
|
| 590 | + if (is_scalar($data) && !empty($data)) {
|
|
| 585 | 591 | $json = json_decode($data); |
| 586 | - } else { |
|
| 592 | + } else {
|
|
| 587 | 593 | throw new Exception("json is not string with json data"); |
| 588 | 594 | } |
| 589 | 595 | |
| 590 | - if ($this->jsonError($json)) { |
|
| 591 | - if (isset($callback) && is_callable($callback)) { |
|
| 596 | + if ($this->jsonError($json)) {
|
|
| 597 | + if (isset($callback) && is_callable($callback)) {
|
|
| 592 | 598 | call_user_func_array($callback, array($json)); |
| 593 | - } else { |
|
| 594 | - if (isset($callback)) { |
|
| 599 | + } else {
|
|
| 600 | + if (isset($callback)) {
|
|
| 595 | 601 | throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>"); |
| 596 | 602 | } |
| 597 | - foreach ($json as $key => $val) { |
|
| 603 | + foreach ($json as $key => $val) {
|
|
| 598 | 604 | $this->set($key, $val); |
| 599 | 605 | } |
| 600 | 606 | } |
| 601 | - } else { |
|
| 607 | + } else {
|
|
| 602 | 608 | throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>'); |
| 603 | 609 | } |
| 604 | 610 | |
@@ -610,19 +616,19 @@ discard block |
||
| 610 | 616 | * @return string |
| 611 | 617 | * @throws Exception |
| 612 | 618 | */ |
| 613 | - final public function toJson($callback = null) |
|
| 614 | - { |
|
| 619 | + final public function toJson($callback = null) |
|
| 620 | + {
|
|
| 615 | 621 | $data = $this->toArray(); |
| 616 | - if (isset($callback) && is_callable($callback)) { |
|
| 622 | + if (isset($callback) && is_callable($callback)) {
|
|
| 617 | 623 | $data = call_user_func_array($callback, array($data)); |
| 618 | - } else { |
|
| 619 | - if (isset($callback)) { |
|
| 624 | + } else {
|
|
| 625 | + if (isset($callback)) {
|
|
| 620 | 626 | throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>"); |
| 621 | 627 | } |
| 622 | 628 | } |
| 623 | 629 | $json = json_encode($data); |
| 624 | 630 | |
| 625 | - if ($this->jsonError($data)) { |
|
| 631 | + if ($this->jsonError($data)) {
|
|
| 626 | 632 | throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>'); |
| 627 | 633 | } |
| 628 | 634 | |
@@ -633,10 +639,10 @@ discard block |
||
| 633 | 639 | * @param $data |
| 634 | 640 | * @return bool |
| 635 | 641 | */ |
| 636 | - final protected function jsonError($data) |
|
| 637 | - { |
|
| 642 | + final protected function jsonError($data) |
|
| 643 | + {
|
|
| 638 | 644 | $flag = false; |
| 639 | - if (json_last_error() === JSON_ERROR_NONE && is_object($data) && $data instanceof stdClass) { |
|
| 645 | + if (json_last_error() === JSON_ERROR_NONE && is_object($data) && $data instanceof stdClass) {
|
|
| 640 | 646 | $flag = true; |
| 641 | 647 | } |
| 642 | 648 | |
@@ -649,25 +655,25 @@ discard block |
||
| 649 | 655 | * @param string $sep |
| 650 | 656 | * @return array |
| 651 | 657 | */ |
| 652 | - public function toArray($prefix = '', $suffix = '', $sep = '_') |
|
| 653 | - { |
|
| 658 | + public function toArray($prefix = '', $suffix = '', $sep = '_') |
|
| 659 | + {
|
|
| 654 | 660 | $tpl = ''; |
| 655 | 661 | $plh = '[+key+]'; |
| 656 | - if ($prefix !== '') { |
|
| 662 | + if ($prefix !== '') {
|
|
| 657 | 663 | $tpl = $prefix . $sep; |
| 658 | 664 | } |
| 659 | 665 | $tpl .= $plh; |
| 660 | - if ($suffix !== '') { |
|
| 666 | + if ($suffix !== '') {
|
|
| 661 | 667 | $tpl .= $sep . $suffix; |
| 662 | 668 | } |
| 663 | 669 | $out = array(); |
| 664 | 670 | $fields = $this->field; |
| 665 | 671 | $fields[$this->fieldPKName()] = $this->getID(); |
| 666 | - if ($tpl != $plh) { |
|
| 667 | - foreach ($fields as $key => $value) { |
|
| 672 | + if ($tpl != $plh) {
|
|
| 673 | + foreach ($fields as $key => $value) {
|
|
| 668 | 674 | $out[str_replace($plh, $key, $tpl)] = $value; |
| 669 | 675 | } |
| 670 | - } else { |
|
| 676 | + } else {
|
|
| 671 | 677 | $out = $fields; |
| 672 | 678 | } |
| 673 | 679 | |
@@ -677,8 +683,8 @@ discard block |
||
| 677 | 683 | /** |
| 678 | 684 | * @return string |
| 679 | 685 | */ |
| 680 | - final public function fieldPKName() |
|
| 681 | - { |
|
| 686 | + final public function fieldPKName() |
|
| 687 | + {
|
|
| 682 | 688 | return $this->pkName; |
| 683 | 689 | } |
| 684 | 690 | |
@@ -686,8 +692,8 @@ discard block |
||
| 686 | 692 | * @param $table |
| 687 | 693 | * @return mixed|string |
| 688 | 694 | */ |
| 689 | - final public function makeTable($table) |
|
| 690 | - { |
|
| 695 | + final public function makeTable($table) |
|
| 696 | + {
|
|
| 691 | 697 | //Без использования APIHelpers::getkey(). Иначе getFullTableName будет всегда выполняться |
| 692 | 698 | return (isset($this->_table[$table])) ? $this->_table[$table] : $this->modx->getFullTableName($table); |
| 693 | 699 | } |
@@ -697,14 +703,14 @@ discard block |
||
| 697 | 703 | * @param string $sep |
| 698 | 704 | * @return array|string |
| 699 | 705 | */ |
| 700 | - final public function sanitarIn($data, $sep = ',') |
|
| 701 | - { |
|
| 702 | - if (!is_array($data)) { |
|
| 706 | + final public function sanitarIn($data, $sep = ',') |
|
| 707 | + {
|
|
| 708 | + if (!is_array($data)) {
|
|
| 703 | 709 | $data = explode($sep, $data); |
| 704 | 710 | } |
| 705 | 711 | $out = array(); |
| 706 | - foreach ($data as $item) { |
|
| 707 | - if ($item !== '') { |
|
| 712 | + foreach ($data as $item) {
|
|
| 713 | + if ($item !== '') {
|
|
| 708 | 714 | $out[] = $this->escape($item); |
| 709 | 715 | } |
| 710 | 716 | } |
@@ -719,34 +725,34 @@ discard block |
||
| 719 | 725 | * @param string $PK |
| 720 | 726 | * @return bool |
| 721 | 727 | */ |
| 722 | - public function checkUnique($table, $field, $PK = 'id') |
|
| 723 | - { |
|
| 724 | - if (is_array($field)) { |
|
| 728 | + public function checkUnique($table, $field, $PK = 'id') |
|
| 729 | + {
|
|
| 730 | + if (is_array($field)) {
|
|
| 725 | 731 | $where = array(); |
| 726 | - foreach ($field as $_field) { |
|
| 732 | + foreach ($field as $_field) {
|
|
| 727 | 733 | $val = $this->get($_field); |
| 728 | - if ($val != '') { |
|
| 734 | + if ($val != '') {
|
|
| 729 | 735 | $where[] = "`" . $this->escape($_field) . "` = '" . $this->escape($val) . "'"; |
| 730 | 736 | } |
| 731 | 737 | } |
| 732 | 738 | $where = implode(' AND ', $where); |
| 733 | - } else { |
|
| 739 | + } else {
|
|
| 734 | 740 | $where = ''; |
| 735 | 741 | $val = $this->get($field); |
| 736 | - if ($val != '') { |
|
| 742 | + if ($val != '') {
|
|
| 737 | 743 | $where = "`" . $this->escape($field) . "` = '" . $this->escape($val) . "'"; |
| 738 | 744 | } |
| 739 | 745 | } |
| 740 | 746 | |
| 741 | - if ($where != '') { |
|
| 747 | + if ($where != '') {
|
|
| 742 | 748 | $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE " . $where); |
| 743 | 749 | $id = $this->modx->db->getValue($sql); |
| 744 | - if (is_null($id) || (!$this->newDoc && $id == $this->getID())) { |
|
| 750 | + if (is_null($id) || (!$this->newDoc && $id == $this->getID())) {
|
|
| 745 | 751 | $flag = true; |
| 746 | - } else { |
|
| 752 | + } else {
|
|
| 747 | 753 | $flag = false; |
| 748 | 754 | } |
| 749 | - } else { |
|
| 755 | + } else {
|
|
| 750 | 756 | $flag = false; |
| 751 | 757 | } |
| 752 | 758 | |
@@ -757,8 +763,8 @@ discard block |
||
| 757 | 763 | * @param array $data |
| 758 | 764 | * @return $this |
| 759 | 765 | */ |
| 760 | - public function create($data = array()) |
|
| 761 | - { |
|
| 766 | + public function create($data = array()) |
|
| 767 | + {
|
|
| 762 | 768 | $this->close(); |
| 763 | 769 | $this->fromArray($data); |
| 764 | 770 | |
@@ -769,8 +775,8 @@ discard block |
||
| 769 | 775 | * @param $id |
| 770 | 776 | * @return $this |
| 771 | 777 | */ |
| 772 | - public function copy($id) |
|
| 773 | - { |
|
| 778 | + public function copy($id) |
|
| 779 | + {
|
|
| 774 | 780 | $this->edit($id)->id = 0; |
| 775 | 781 | $this->newDoc = true; |
| 776 | 782 | $this->store = array(); |
@@ -781,8 +787,8 @@ discard block |
||
| 781 | 787 | /** |
| 782 | 788 | * |
| 783 | 789 | */ |
| 784 | - public function close() |
|
| 785 | - { |
|
| 790 | + public function close() |
|
| 791 | + {
|
|
| 786 | 792 | $this->newDoc = true; |
| 787 | 793 | $this->id = null; |
| 788 | 794 | $this->field = array(); |
@@ -795,8 +801,8 @@ discard block |
||
| 795 | 801 | * @param $key |
| 796 | 802 | * @return bool |
| 797 | 803 | */ |
| 798 | - public function issetField($key) |
|
| 799 | - { |
|
| 804 | + public function issetField($key) |
|
| 805 | + {
|
|
| 800 | 806 | return (is_scalar($key) && array_key_exists($key, $this->default_field)); |
| 801 | 807 | } |
| 802 | 808 | |
@@ -824,8 +830,8 @@ discard block |
||
| 824 | 830 | * @param $data |
| 825 | 831 | * @return array|mixed|string |
| 826 | 832 | */ |
| 827 | - final public function sanitarTag($data) |
|
| 828 | - { |
|
| 833 | + final public function sanitarTag($data) |
|
| 834 | + {
|
|
| 829 | 835 | return parent::sanitarTag($this->modx->stripTags($data)); |
| 830 | 836 | } |
| 831 | 837 | |
@@ -834,17 +840,17 @@ discard block |
||
| 834 | 840 | * @param bool $dmi3yy |
| 835 | 841 | * @return bool |
| 836 | 842 | */ |
| 837 | - final protected function checkVersion($version, $dmi3yy = true) |
|
| 838 | - { |
|
| 843 | + final protected function checkVersion($version, $dmi3yy = true) |
|
| 844 | + {
|
|
| 839 | 845 | $flag = false; |
| 840 | 846 | $currentVer = $this->modx->getVersionData('version'); |
| 841 | - if (is_array($currentVer)) { |
|
| 847 | + if (is_array($currentVer)) {
|
|
| 842 | 848 | $currentVer = APIHelpers::getkey($currentVer, 'version', ''); |
| 843 | 849 | } |
| 844 | 850 | $tmp = substr($currentVer, 0, strlen($version)); |
| 845 | - if (version_compare($tmp, $version, '>=')) { |
|
| 851 | + if (version_compare($tmp, $version, '>=')) {
|
|
| 846 | 852 | $flag = true; |
| 847 | - if ($dmi3yy) { |
|
| 853 | + if ($dmi3yy) {
|
|
| 848 | 854 | $flag = (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer); |
| 849 | 855 | } |
| 850 | 856 | } |
@@ -856,10 +862,10 @@ discard block |
||
| 856 | 862 | * @param string $name |
| 857 | 863 | * @return bool|mixed |
| 858 | 864 | */ |
| 859 | - protected function eraseField($name) |
|
| 860 | - { |
|
| 865 | + protected function eraseField($name) |
|
| 866 | + {
|
|
| 861 | 867 | $flag = false; |
| 862 | - if (array_key_exists($name, $this->field)) { |
|
| 868 | + if (array_key_exists($name, $this->field)) {
|
|
| 863 | 869 | $flag = $this->field[$name]; |
| 864 | 870 | unset($this->field[$name]); |
| 865 | 871 | } |
@@ -872,8 +878,8 @@ discard block |
||
| 872 | 878 | * @param string $field имя поля |
| 873 | 879 | * @return boolean |
| 874 | 880 | */ |
| 875 | - public function isJsonField($field) |
|
| 876 | - { |
|
| 881 | + public function isJsonField($field) |
|
| 882 | + {
|
|
| 877 | 883 | return (is_scalar($field) && in_array($field, $this->jsonFields)); |
| 878 | 884 | } |
| 879 | 885 | |
@@ -882,9 +888,9 @@ discard block |
||
| 882 | 888 | * @param string $field имя поля |
| 883 | 889 | * @return $this |
| 884 | 890 | */ |
| 885 | - public function markAsDecode($field) |
|
| 886 | - { |
|
| 887 | - if (is_scalar($field)) { |
|
| 891 | + public function markAsDecode($field) |
|
| 892 | + {
|
|
| 893 | + if (is_scalar($field)) {
|
|
| 888 | 894 | $this->_decodedFields->set($field, false); |
| 889 | 895 | } |
| 890 | 896 | |
@@ -896,9 +902,9 @@ discard block |
||
| 896 | 902 | * @param string $field имя поля |
| 897 | 903 | * @return $this |
| 898 | 904 | */ |
| 899 | - public function markAsEncode($field) |
|
| 900 | - { |
|
| 901 | - if (is_scalar($field)) { |
|
| 905 | + public function markAsEncode($field) |
|
| 906 | + {
|
|
| 907 | + if (is_scalar($field)) {
|
|
| 902 | 908 | $this->_decodedFields->set($field, true); |
| 903 | 909 | } |
| 904 | 910 | |
@@ -909,10 +915,10 @@ discard block |
||
| 909 | 915 | * Пометить все поля как запакованные |
| 910 | 916 | * @return $this |
| 911 | 917 | */ |
| 912 | - public function markAllEncode() |
|
| 913 | - { |
|
| 918 | + public function markAllEncode() |
|
| 919 | + {
|
|
| 914 | 920 | $this->_decodedFields->clear(); |
| 915 | - foreach ($this->jsonFields as $field) { |
|
| 921 | + foreach ($this->jsonFields as $field) {
|
|
| 916 | 922 | $this->markAsEncode($field); |
| 917 | 923 | } |
| 918 | 924 | |
@@ -923,10 +929,10 @@ discard block |
||
| 923 | 929 | * Пометить все поля как распакованные |
| 924 | 930 | * @return $this |
| 925 | 931 | */ |
| 926 | - public function markAllDecode() |
|
| 927 | - { |
|
| 932 | + public function markAllDecode() |
|
| 933 | + {
|
|
| 928 | 934 | $this->_decodedFields->clear(); |
| 929 | - foreach ($this->jsonFields as $field) { |
|
| 935 | + foreach ($this->jsonFields as $field) {
|
|
| 930 | 936 | $this->markAsDecode($field); |
| 931 | 937 | } |
| 932 | 938 | |
@@ -937,9 +943,9 @@ discard block |
||
| 937 | 943 | * Получить список не запакованных полей |
| 938 | 944 | * @return DLCollection |
| 939 | 945 | */ |
| 940 | - public function getNoEncodeFields() |
|
| 941 | - { |
|
| 942 | - return $this->_decodedFields->filter(function ($value) { |
|
| 946 | + public function getNoEncodeFields() |
|
| 947 | + {
|
|
| 948 | + return $this->_decodedFields->filter(function ($value) {
|
|
| 943 | 949 | return ($value === false); |
| 944 | 950 | }); |
| 945 | 951 | } |
@@ -948,9 +954,9 @@ discard block |
||
| 948 | 954 | * Получить список не распакованных полей |
| 949 | 955 | * @return DLCollection |
| 950 | 956 | */ |
| 951 | - public function getNoDecodeFields() |
|
| 952 | - { |
|
| 953 | - return $this->_decodedFields->filter(function ($value) { |
|
| 957 | + public function getNoDecodeFields() |
|
| 958 | + {
|
|
| 959 | + return $this->_decodedFields->filter(function ($value) {
|
|
| 954 | 960 | return ($value === true); |
| 955 | 961 | }); |
| 956 | 962 | } |
@@ -960,8 +966,8 @@ discard block |
||
| 960 | 966 | * @param string $field имя поля |
| 961 | 967 | * @return boolean |
| 962 | 968 | */ |
| 963 | - public function isDecodableField($field) |
|
| 964 | - { |
|
| 969 | + public function isDecodableField($field) |
|
| 970 | + {
|
|
| 965 | 971 | $data = $this->get($field); |
| 966 | 972 | |
| 967 | 973 | /** |
@@ -976,8 +982,8 @@ discard block |
||
| 976 | 982 | * @param string $field имя поля |
| 977 | 983 | * @return boolean |
| 978 | 984 | */ |
| 979 | - public function isEncodableField($field) |
|
| 980 | - { |
|
| 985 | + public function isEncodableField($field) |
|
| 986 | + {
|
|
| 981 | 987 | /** |
| 982 | 988 | * Если поле было распаковано ранее и еще не упаковано |
| 983 | 989 | */ |
@@ -990,14 +996,14 @@ discard block |
||
| 990 | 996 | * @param bool $store обновить распакованное поле |
| 991 | 997 | * @return array ассоциативный массив с данными из json строки |
| 992 | 998 | */ |
| 993 | - public function decodeField($field, $store = false) |
|
| 994 | - { |
|
| 999 | + public function decodeField($field, $store = false) |
|
| 1000 | + {
|
|
| 995 | 1001 | $out = array(); |
| 996 | - if ($this->isDecodableField($field)) { |
|
| 1002 | + if ($this->isDecodableField($field)) {
|
|
| 997 | 1003 | $data = $this->get($field); |
| 998 | 1004 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
| 999 | 1005 | } |
| 1000 | - if ($store) { |
|
| 1006 | + if ($store) {
|
|
| 1001 | 1007 | $this->field[$field] = $out; |
| 1002 | 1008 | $this->markAsDecode($field); |
| 1003 | 1009 | } |
@@ -1009,9 +1015,9 @@ discard block |
||
| 1009 | 1015 | * Декодирование всех json полей |
| 1010 | 1016 | * @return $this |
| 1011 | 1017 | */ |
| 1012 | - protected function decodeFields() |
|
| 1013 | - { |
|
| 1014 | - foreach ($this->getNoDecodeFields() as $field => $flag) { |
|
| 1018 | + protected function decodeFields() |
|
| 1019 | + {
|
|
| 1020 | + foreach ($this->getNoDecodeFields() as $field => $flag) {
|
|
| 1015 | 1021 | $this->decodeField($field, true); |
| 1016 | 1022 | } |
| 1017 | 1023 | |
@@ -1024,14 +1030,14 @@ discard block |
||
| 1024 | 1030 | * @param bool $store обновить запакованное поле |
| 1025 | 1031 | * @return string|null json строка |
| 1026 | 1032 | */ |
| 1027 | - public function encodeField($field, $store = false) |
|
| 1028 | - { |
|
| 1033 | + public function encodeField($field, $store = false) |
|
| 1034 | + {
|
|
| 1029 | 1035 | $out = null; |
| 1030 | - if ($this->isEncodableField($field)) { |
|
| 1036 | + if ($this->isEncodableField($field)) {
|
|
| 1031 | 1037 | $data = $this->get($field); |
| 1032 | 1038 | $out = json_encode($data); |
| 1033 | 1039 | } |
| 1034 | - if ($store) { |
|
| 1040 | + if ($store) {
|
|
| 1035 | 1041 | $this->field[$field] = $out; |
| 1036 | 1042 | $this->markAsEncode($field); |
| 1037 | 1043 | } |
@@ -1043,9 +1049,9 @@ discard block |
||
| 1043 | 1049 | * Запаковка всех json полей |
| 1044 | 1050 | * @return $this |
| 1045 | 1051 | */ |
| 1046 | - protected function encodeFields() |
|
| 1047 | - { |
|
| 1048 | - foreach ($this->getNoEncodeFields() as $field => $flag) { |
|
| 1052 | + protected function encodeFields() |
|
| 1053 | + {
|
|
| 1054 | + foreach ($this->getNoEncodeFields() as $field => $flag) {
|
|
| 1049 | 1055 | $this->encodeField($field, true); |
| 1050 | 1056 | } |
| 1051 | 1057 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $tpl = $this->get('template'); |
| 189 | 189 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 190 | 190 | foreach ($tvTPL as $item) { |
| 191 | - if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
| 191 | + if (isset($this->tvid[$item]) && ! array_key_exists($this->tvid[$item], $out)) { |
|
| 192 | 192 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $out = null; |
| 228 | 228 | $id = (int)$this->getID(); |
| 229 | - if (!empty($id)) { |
|
| 229 | + if ( ! empty($id)) { |
|
| 230 | 230 | $out = $this->modx->makeUrl($id); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | */ |
| 321 | 321 | public function set($key, $value) |
| 322 | 322 | { |
| 323 | - if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 323 | + if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) { |
|
| 324 | 324 | switch ($key) { |
| 325 | 325 | case 'parent': |
| 326 | 326 | $value = (int)$value; |
@@ -393,12 +393,12 @@ discard block |
||
| 393 | 393 | { |
| 394 | 394 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
| 395 | 395 | $value = (int)$value; |
| 396 | - if (!empty($value)) { |
|
| 396 | + if ( ! empty($value)) { |
|
| 397 | 397 | $by = $this->findUserBy($value); |
| 398 | - $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { |
|
| 398 | + $exists = $this->managerUsers->exists(function($key, Helpers\Collection $val) use ($by, $value) { |
|
| 399 | 399 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
| 400 | 400 | }); |
| 401 | - if (!$exists) { |
|
| 401 | + if ( ! $exists) { |
|
| 402 | 402 | $value = 0; |
| 403 | 403 | } |
| 404 | 404 | } |
@@ -504,8 +504,8 @@ discard block |
||
| 504 | 504 | |
| 505 | 505 | if ( |
| 506 | 506 | $this->field['parent'] == 0 && |
| 507 | - !$this->modxConfig('udperms_allowroot') && |
|
| 508 | - !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
|
| 507 | + ! $this->modxConfig('udperms_allowroot') && |
|
| 508 | + ! ($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
|
| 509 | 509 | ) { |
| 510 | 510 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
| 511 | 511 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
| 525 | 525 | foreach ($this->default_field as $key => $value) { |
| 526 | 526 | $tmp = $this->get($key); |
| 527 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 527 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 528 | 528 | if ($tmp == $value) { |
| 529 | 529 | switch ($key) { |
| 530 | 530 | case 'cacheable': |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | $this->field[$key] = $parent; |
| 557 | 557 | $this->Uset($key); |
| 558 | 558 | break; |
| 559 | - case ($key == 'alias_visible' && !$this->checkVersion('1.0.10', true)): |
|
| 559 | + case ($key == 'alias_visible' && ! $this->checkVersion('1.0.10', true)): |
|
| 560 | 560 | $this->eraseField('alias_visible'); |
| 561 | 561 | break; |
| 562 | 562 | default: |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | unset($fld[$key]); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - if (!empty($this->set)) { |
|
| 568 | + if ( ! empty($this->set)) { |
|
| 569 | 569 | if ($this->newDoc) { |
| 570 | 570 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
| 571 | 571 | } else { |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | |
| 586 | 586 | $_deleteTVs = $_insertTVs = array(); |
| 587 | 587 | foreach ($fld as $key => $value) { |
| 588 | - if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { |
|
| 588 | + if (empty($this->tv[$key]) || ! $this->isChanged($key) || ! $this->belongsToTemplate($this->tv[$key])) { |
|
| 589 | 589 | continue; |
| 590 | 590 | } elseif ($value === '') { |
| 591 | 591 | $_deleteTVs[] = $this->tv[$key]; |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - if (!empty($_insertTVs)) { |
|
| 597 | + if ( ! empty($_insertTVs)) { |
|
| 598 | 598 | $values = array(); |
| 599 | 599 | foreach ($_insertTVs as $id => $value) { |
| 600 | 600 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
@@ -604,17 +604,17 @@ discard block |
||
| 604 | 604 | `value` = VALUES(`value`)"); |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - if (!empty($_deleteTVs)) { |
|
| 607 | + if ( ! empty($_deleteTVs)) { |
|
| 608 | 608 | $ids = implode(',', $_deleteTVs); |
| 609 | 609 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - if (!isset($this->mode)) { |
|
| 612 | + if ( ! isset($this->mode)) { |
|
| 613 | 613 | $this->mode = $this->newDoc ? "new" : "upd"; |
| 614 | 614 | $this->newDoc = false; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if (!empty($this->groupIds)) $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 617 | + if ( ! empty($this->groupIds)) $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 618 | 618 | $this->invokeEvent('OnDocFormSave', array( |
| 619 | 619 | 'mode' => $this->mode, |
| 620 | 620 | 'id' => isset($this->id) ? $this->id : '', |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | $_ids = $this->cleanIDs($ids, ','); |
| 698 | 698 | if (is_array($_ids) && $_ids != array()) { |
| 699 | 699 | $id = $this->sanitarIn($_ids); |
| 700 | - if (!empty($id)) { |
|
| 700 | + if ( ! empty($id)) { |
|
| 701 | 701 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
| 702 | 702 | $id = $this->modx->db->getColumn('id', $q); |
| 703 | 703 | if ($depth > 0 || $depth === true) { |
@@ -762,12 +762,12 @@ discard block |
||
| 762 | 762 | $alias = strtolower($alias); |
| 763 | 763 | if ($this->modxConfig('friendly_urls')) { |
| 764 | 764 | $_alias = $this->escape($alias); |
| 765 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 765 | + if (( ! $this->modxConfig('allow_duplicate_alias') && ! $this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 766 | 766 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
| 767 | 767 | } else { |
| 768 | 768 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
| 769 | 769 | } |
| 770 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
| 770 | + if (($flag && $this->newDoc) || ( ! $this->newDoc && $flag && $this->id != $flag)) { |
|
| 771 | 771 | $suffix = substr($alias, -2); |
| 772 | 772 | if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
| 773 | 773 | $suffix = (int)$tmp[1] + 1; |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | */ |
| 844 | 844 | protected function loadTVDefault(array $tvId = array()) |
| 845 | 845 | { |
| 846 | - if (is_array($tvId) && !empty($tvId)) { |
|
| 846 | + if (is_array($tvId) && ! empty($tvId)) { |
|
| 847 | 847 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 848 | 848 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 849 | 849 | $implodeTvId = implode(',', $tvId); |
@@ -865,11 +865,11 @@ discard block |
||
| 865 | 865 | */ |
| 866 | 866 | public function setTemplate($tpl) |
| 867 | 867 | { |
| 868 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 868 | + if ( ! is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 869 | 869 | if (is_scalar($tpl)) { |
| 870 | 870 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
| 871 | 871 | $rs = $this->query($sql); |
| 872 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 872 | + if ( ! $rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 873 | 873 | throw new Exception("Template {$tpl} is not exists"); |
| 874 | 874 | } |
| 875 | 875 | $tpl = $this->modx->db->getValue($rs); |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | $template = $this->modxConfig('default_template'); |
| 931 | 931 | switch ($this->modxConfig('auto_template_logic')) { |
| 932 | 932 | case 'sibling': |
| 933 | - if (!$parent) { |
|
| 933 | + if ( ! $parent) { |
|
| 934 | 934 | $site_start = $this->modxConfig('site_start'); |
| 935 | 935 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
| 936 | 936 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
@@ -1082,7 +1082,7 @@ discard block |
||
| 1082 | 1082 | */ |
| 1083 | 1083 | public function setDocumentGroups($docId = 0, $groupIds = array()) |
| 1084 | 1084 | { |
| 1085 | - if (!is_array($groupIds)) return $this; |
|
| 1085 | + if ( ! is_array($groupIds)) return $this; |
|
| 1086 | 1086 | if ($this->newDoc && $docId == 0) { |
| 1087 | 1087 | $this->groupIds = $groupIds; |
| 1088 | 1088 | } else { |
@@ -1091,7 +1091,7 @@ discard block |
||
| 1091 | 1091 | foreach ($groupIds as $gid) { |
| 1092 | 1092 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
| 1093 | 1093 | } |
| 1094 | - if (!$this->newDoc) { |
|
| 1094 | + if ( ! $this->newDoc) { |
|
| 1095 | 1095 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 1096 | 1096 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
| 1097 | 1097 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Class modResource |
| 6 | 6 | */ |
| 7 | -class modResource extends MODxAPI |
|
| 8 | -{ |
|
| 7 | +class modResource extends MODxAPI |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var string |
| 11 | 11 | */ |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * @param DocumentParser $modx |
| 158 | 158 | * @param bool $debug |
| 159 | 159 | */ |
| 160 | - public function __construct($modx, $debug = false) |
|
| 161 | - { |
|
| 160 | + public function __construct($modx, $debug = false) |
|
| 161 | + {
|
|
| 162 | 162 | parent::__construct($modx, $debug); |
| 163 | 163 | $this->get_TV(); |
| 164 | 164 | $uTable = $this->makeTable("manager_users"); |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | /** |
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | - public function toArrayMain() |
|
| 175 | - { |
|
| 174 | + public function toArrayMain() |
|
| 175 | + {
|
|
| 176 | 176 | $out = array_intersect_key(parent::toArray(), $this->default_field); |
| 177 | 177 | |
| 178 | 178 | return $out; |
@@ -182,18 +182,18 @@ discard block |
||
| 182 | 182 | * @param bool $render |
| 183 | 183 | * @return array |
| 184 | 184 | */ |
| 185 | - public function toArrayTV($render = false) |
|
| 186 | - { |
|
| 185 | + public function toArrayTV($render = false) |
|
| 186 | + {
|
|
| 187 | 187 | $out = array_diff_key(parent::toArray(), $this->default_field); |
| 188 | 188 | $tpl = $this->get('template'); |
| 189 | 189 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 190 | - foreach ($tvTPL as $item) { |
|
| 191 | - if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { |
|
| 190 | + foreach ($tvTPL as $item) {
|
|
| 191 | + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) {
|
|
| 192 | 192 | $out[$this->tvid[$item]] = $this->get($this->tvid[$item]); |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | - if ($render) { |
|
| 196 | - foreach ($out as $key => $val) { |
|
| 195 | + if ($render) {
|
|
| 196 | + foreach ($out as $key => $val) {
|
|
| 197 | 197 | $out[$key] = $this->renderTV($key); |
| 198 | 198 | } |
| 199 | 199 | } |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | * @param bool $render |
| 209 | 209 | * @return array |
| 210 | 210 | */ |
| 211 | - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) |
|
| 212 | - { |
|
| 211 | + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) |
|
| 212 | + {
|
|
| 213 | 213 | $out = array_merge( |
| 214 | 214 | $this->toArrayMain(), |
| 215 | 215 | $this->toArrayTV($render), |
@@ -222,11 +222,11 @@ discard block |
||
| 222 | 222 | /** |
| 223 | 223 | * @return null|string |
| 224 | 224 | */ |
| 225 | - public function getUrl() |
|
| 226 | - { |
|
| 225 | + public function getUrl() |
|
| 226 | + {
|
|
| 227 | 227 | $out = null; |
| 228 | 228 | $id = (int)$this->getID(); |
| 229 | - if (!empty($id)) { |
|
| 229 | + if (!empty($id)) {
|
|
| 230 | 230 | $out = $this->modx->makeUrl($id); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -238,10 +238,10 @@ discard block |
||
| 238 | 238 | * @param string $second |
| 239 | 239 | * @return mixed |
| 240 | 240 | */ |
| 241 | - public function getTitle($main = 'menutitle', $second = 'pagetitle') |
|
| 242 | - { |
|
| 241 | + public function getTitle($main = 'menutitle', $second = 'pagetitle') |
|
| 242 | + {
|
|
| 243 | 243 | $title = $this->get($main); |
| 244 | - if (empty($title) && $title !== '0') { |
|
| 244 | + if (empty($title) && $title !== '0') {
|
|
| 245 | 245 | $title = $this->get($second); |
| 246 | 246 | } |
| 247 | 247 | |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | /** |
| 252 | 252 | * @return bool |
| 253 | 253 | */ |
| 254 | - public function isWebShow() |
|
| 255 | - { |
|
| 254 | + public function isWebShow() |
|
| 255 | + {
|
|
| 256 | 256 | $pub = ($this->get('publishedon') < time() && $this->get('published')); |
| 257 | 257 | $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time()); |
| 258 | 258 | $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | /** |
| 264 | 264 | * @return $this |
| 265 | 265 | */ |
| 266 | - public function touch() |
|
| 267 | - { |
|
| 266 | + public function touch() |
|
| 267 | + {
|
|
| 268 | 268 | $this->set('editedon', time()); |
| 269 | 269 | |
| 270 | 270 | return $this; |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | * @param $tvname |
| 275 | 275 | * @return null|string |
| 276 | 276 | */ |
| 277 | - public function renderTV($tvname) |
|
| 278 | - { |
|
| 277 | + public function renderTV($tvname) |
|
| 278 | + {
|
|
| 279 | 279 | $out = null; |
| 280 | - if ($this->getID() > 0) { |
|
| 280 | + if ($this->getID() > 0) {
|
|
| 281 | 281 | include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; |
| 282 | 282 | include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; |
| 283 | 283 | $tvval = $this->get($tvname); |
| 284 | - if ($this->isTVarrayField($tvname) && is_array($tvval)) { |
|
| 284 | + if ($this->isTVarrayField($tvname) && is_array($tvval)) {
|
|
| 285 | 285 | $tvval = implode('||', $tvval); |
| 286 | 286 | } |
| 287 | 287 | $param = APIHelpers::getkey($this->tvd, $tvname, array()); |
@@ -298,14 +298,14 @@ discard block |
||
| 298 | 298 | * @param $key |
| 299 | 299 | * @return mixed |
| 300 | 300 | */ |
| 301 | - public function get($key) |
|
| 302 | - { |
|
| 301 | + public function get($key) |
|
| 302 | + {
|
|
| 303 | 303 | $out = parent::get($key); |
| 304 | - if (isset($this->tv[$key])) { |
|
| 304 | + if (isset($this->tv[$key])) {
|
|
| 305 | 305 | $tpl = $this->get('template'); |
| 306 | 306 | $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); |
| 307 | 307 | $tvID = APIHelpers::getkey($this->tv, $key, 0); |
| 308 | - if (in_array($tvID, $tvTPL) && is_null($out)) { |
|
| 308 | + if (in_array($tvID, $tvTPL) && is_null($out)) {
|
|
| 309 | 309 | $out = APIHelpers::getkey($this->tvd[$key], 'value', null); |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -318,10 +318,10 @@ discard block |
||
| 318 | 318 | * @param $value |
| 319 | 319 | * @return $this |
| 320 | 320 | */ |
| 321 | - public function set($key, $value) |
|
| 322 | - { |
|
| 323 | - if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { |
|
| 324 | - switch ($key) { |
|
| 321 | + public function set($key, $value) |
|
| 322 | + {
|
|
| 323 | + if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) {
|
|
| 324 | + switch ($key) {
|
|
| 325 | 325 | case 'parent': |
| 326 | 326 | $value = (int)$value; |
| 327 | 327 | break; |
@@ -331,38 +331,38 @@ discard block |
||
| 331 | 331 | break; |
| 332 | 332 | case 'published': |
| 333 | 333 | $value = (int)((bool)$value); |
| 334 | - if ($value) { |
|
| 334 | + if ($value) {
|
|
| 335 | 335 | $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); |
| 336 | 336 | } |
| 337 | 337 | break; |
| 338 | 338 | case 'pub_date': |
| 339 | 339 | $value = $this->getTime($value); |
| 340 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
| 340 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
|
|
| 341 | 341 | $this->field['published'] = 1; |
| 342 | 342 | $this->field['publishedon'] = $value; |
| 343 | 343 | } |
| 344 | 344 | break; |
| 345 | 345 | case 'unpub_date': |
| 346 | 346 | $value = $this->getTime($value); |
| 347 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { |
|
| 347 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) {
|
|
| 348 | 348 | $this->field['published'] = 0; |
| 349 | 349 | $this->field['publishedon'] = 0; |
| 350 | 350 | } |
| 351 | 351 | break; |
| 352 | 352 | case 'deleted': |
| 353 | 353 | $value = (int)((bool)$value); |
| 354 | - if ($value) { |
|
| 354 | + if ($value) {
|
|
| 355 | 355 | $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); |
| 356 | - } else { |
|
| 356 | + } else {
|
|
| 357 | 357 | $this->field['deletedon'] = 0; |
| 358 | 358 | } |
| 359 | 359 | break; |
| 360 | 360 | case 'deletedon': |
| 361 | 361 | $value = $this->getTime($value); |
| 362 | - if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { |
|
| 362 | + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) {
|
|
| 363 | 363 | $value = 0; |
| 364 | 364 | } |
| 365 | - if ($value) { |
|
| 365 | + if ($value) {
|
|
| 366 | 366 | $this->field['deleted'] = 1; |
| 367 | 367 | } |
| 368 | 368 | break; |
@@ -389,20 +389,20 @@ discard block |
||
| 389 | 389 | * @param int $default |
| 390 | 390 | * @return int|mixed |
| 391 | 391 | */ |
| 392 | - protected function getUser($value, $default = 0) |
|
| 393 | - { |
|
| 392 | + protected function getUser($value, $default = 0) |
|
| 393 | + {
|
|
| 394 | 394 | $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); |
| 395 | 395 | $value = (int)$value; |
| 396 | - if (!empty($value)) { |
|
| 396 | + if (!empty($value)) {
|
|
| 397 | 397 | $by = $this->findUserBy($value); |
| 398 | - $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { |
|
| 398 | + $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) {
|
|
| 399 | 399 | return ($val->containsKey($by) && $val->get($by) === (string)$value); |
| 400 | 400 | }); |
| 401 | - if (!$exists) { |
|
| 401 | + if (!$exists) {
|
|
| 402 | 402 | $value = 0; |
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | - if (empty($value)) { |
|
| 405 | + if (empty($value)) {
|
|
| 406 | 406 | $value = empty($currentAdmin) ? $default : $currentAdmin; |
| 407 | 407 | } |
| 408 | 408 | |
@@ -413,9 +413,9 @@ discard block |
||
| 413 | 413 | * @param $data |
| 414 | 414 | * @return bool|string |
| 415 | 415 | */ |
| 416 | - protected function findUserBy($data) |
|
| 417 | - { |
|
| 418 | - switch (true) { |
|
| 416 | + protected function findUserBy($data) |
|
| 417 | + {
|
|
| 418 | + switch (true) {
|
|
| 419 | 419 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
| 420 | 420 | $find = 'id'; |
| 421 | 421 | break; |
@@ -436,11 +436,11 @@ discard block |
||
| 436 | 436 | * @param array $data |
| 437 | 437 | * @return $this |
| 438 | 438 | */ |
| 439 | - public function create($data = array()) |
|
| 440 | - { |
|
| 439 | + public function create($data = array()) |
|
| 440 | + {
|
|
| 441 | 441 | $this->close(); |
| 442 | 442 | $fld = array(); |
| 443 | - foreach ($this->tvd as $name => $tv) { |
|
| 443 | + foreach ($this->tvd as $name => $tv) {
|
|
| 444 | 444 | $fld[$name] = $tv['value']; |
| 445 | 445 | }; |
| 446 | 446 | $this->store($fld); |
@@ -458,10 +458,10 @@ discard block |
||
| 458 | 458 | * @param $id |
| 459 | 459 | * @return $this |
| 460 | 460 | */ |
| 461 | - public function edit($id) |
|
| 462 | - { |
|
| 461 | + public function edit($id) |
|
| 462 | + {
|
|
| 463 | 463 | $id = is_scalar($id) ? trim($id) : ''; |
| 464 | - if ($this->getID() != $id) { |
|
| 464 | + if ($this->getID() != $id) {
|
|
| 465 | 465 | $this->close(); |
| 466 | 466 | $this->markAllEncode(); |
| 467 | 467 | $this->newDoc = false; |
@@ -469,12 +469,12 @@ discard block |
||
| 469 | 469 | $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); |
| 470 | 470 | $this->fromArray($this->modx->db->getRow($result)); |
| 471 | 471 | $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); |
| 472 | - while ($row = $this->modx->db->getRow($result)) { |
|
| 472 | + while ($row = $this->modx->db->getRow($result)) {
|
|
| 473 | 473 | $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; |
| 474 | 474 | } |
| 475 | - if (empty($this->field['id'])) { |
|
| 475 | + if (empty($this->field['id'])) {
|
|
| 476 | 476 | $this->id = null; |
| 477 | - } else { |
|
| 477 | + } else {
|
|
| 478 | 478 | $this->id = $this->field['id']; |
| 479 | 479 | $this->set('editedby', null)->touch(); |
| 480 | 480 | $this->decodeFields(); |
@@ -491,10 +491,10 @@ discard block |
||
| 491 | 491 | * @param bool $clearCache |
| 492 | 492 | * @return bool|null |
| 493 | 493 | */ |
| 494 | - public function save($fire_events = false, $clearCache = false) |
|
| 495 | - { |
|
| 494 | + public function save($fire_events = false, $clearCache = false) |
|
| 495 | + {
|
|
| 496 | 496 | $parent = null; |
| 497 | - if ($this->field['pagetitle'] == '') { |
|
| 497 | + if ($this->field['pagetitle'] == '') {
|
|
| 498 | 498 | $this->log['emptyPagetitle'] = 'Pagetitle is empty in <pre>' . print_r($this->field, true) . '</pre>'; |
| 499 | 499 | |
| 500 | 500 | return false; |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | $this->field['parent'] == 0 && |
| 507 | 507 | !$this->modxConfig('udperms_allowroot') && |
| 508 | 508 | !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) |
| 509 | - ) { |
|
| 509 | + ) {
|
|
| 510 | 510 | $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; |
| 511 | 511 | |
| 512 | 512 | return false; |
@@ -522,11 +522,11 @@ discard block |
||
| 522 | 522 | ), $fire_events); |
| 523 | 523 | |
| 524 | 524 | $fld = $this->encodeFields()->toArray(null, null, null, false); |
| 525 | - foreach ($this->default_field as $key => $value) { |
|
| 525 | + foreach ($this->default_field as $key => $value) {
|
|
| 526 | 526 | $tmp = $this->get($key); |
| 527 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 528 | - if ($tmp == $value) { |
|
| 529 | - switch ($key) { |
|
| 527 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 528 | + if ($tmp == $value) {
|
|
| 529 | + switch ($key) {
|
|
| 530 | 530 | case 'cacheable': |
| 531 | 531 | $value = $this->modxConfig('cache_default'); |
| 532 | 532 | break; |
@@ -546,11 +546,11 @@ discard block |
||
| 546 | 546 | } |
| 547 | 547 | $this->field[$key] = $value; |
| 548 | 548 | } |
| 549 | - switch (true) { |
|
| 549 | + switch (true) {
|
|
| 550 | 550 | case $key == 'parent': |
| 551 | 551 | $parent = (int)$this->get($key); |
| 552 | 552 | $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); |
| 553 | - if ($this->modx->db->getValue($q) != 1) { |
|
| 553 | + if ($this->modx->db->getValue($q) != 1) {
|
|
| 554 | 554 | $parent = 0; |
| 555 | 555 | } |
| 556 | 556 | $this->field[$key] = $parent; |
@@ -565,38 +565,38 @@ discard block |
||
| 565 | 565 | unset($fld[$key]); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - if (!empty($this->set)) { |
|
| 569 | - if ($this->newDoc) { |
|
| 568 | + if (!empty($this->set)) {
|
|
| 569 | + if ($this->newDoc) {
|
|
| 570 | 570 | $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); |
| 571 | - } else { |
|
| 571 | + } else {
|
|
| 572 | 572 | $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', |
| 573 | 573 | $this->set) . " WHERE `id` = " . $this->id; |
| 574 | 574 | } |
| 575 | 575 | $this->query($SQL); |
| 576 | 576 | |
| 577 | - if ($this->newDoc) { |
|
| 577 | + if ($this->newDoc) {
|
|
| 578 | 578 | $this->id = $this->modx->db->getInsertId(); |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - if ($parent > 0) { |
|
| 581 | + if ($parent > 0) {
|
|
| 582 | 582 | $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'"); |
| 583 | 583 | } |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | $_deleteTVs = $_insertTVs = array(); |
| 587 | - foreach ($fld as $key => $value) { |
|
| 588 | - if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { |
|
| 587 | + foreach ($fld as $key => $value) {
|
|
| 588 | + if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) {
|
|
| 589 | 589 | continue; |
| 590 | - } elseif ($value === '') { |
|
| 590 | + } elseif ($value === '') {
|
|
| 591 | 591 | $_deleteTVs[] = $this->tv[$key]; |
| 592 | - } else { |
|
| 592 | + } else {
|
|
| 593 | 593 | $_insertTVs[$this->tv[$key]] = $this->escape($value); |
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - if (!empty($_insertTVs)) { |
|
| 597 | + if (!empty($_insertTVs)) {
|
|
| 598 | 598 | $values = array(); |
| 599 | - foreach ($_insertTVs as $id => $value) { |
|
| 599 | + foreach ($_insertTVs as $id => $value) {
|
|
| 600 | 600 | $values[] = "({$this->id}, {$id}, '{$value}')"; |
| 601 | 601 | } |
| 602 | 602 | $values = implode(',', $values); |
@@ -604,17 +604,19 @@ discard block |
||
| 604 | 604 | `value` = VALUES(`value`)"); |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - if (!empty($_deleteTVs)) { |
|
| 607 | + if (!empty($_deleteTVs)) {
|
|
| 608 | 608 | $ids = implode(',', $_deleteTVs); |
| 609 | 609 | $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - if (!isset($this->mode)) { |
|
| 612 | + if (!isset($this->mode)) {
|
|
| 613 | 613 | $this->mode = $this->newDoc ? "new" : "upd"; |
| 614 | 614 | $this->newDoc = false; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if (!empty($this->groupIds)) $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 617 | + if (!empty($this->groupIds)) {
|
|
| 618 | + $this->setDocumentGroups($this->id, $this->groupIds); |
|
| 619 | + } |
|
| 618 | 620 | $this->invokeEvent('OnDocFormSave', array( |
| 619 | 621 | 'mode' => $this->mode, |
| 620 | 622 | 'id' => isset($this->id) ? $this->id : '', |
@@ -622,7 +624,7 @@ discard block |
||
| 622 | 624 | 'docObj' => $this |
| 623 | 625 | ), $fire_events); |
| 624 | 626 | |
| 625 | - if ($clearCache) { |
|
| 627 | + if ($clearCache) {
|
|
| 626 | 628 | $this->clearCache($fire_events); |
| 627 | 629 | } |
| 628 | 630 | $this->decodeFields(); |
@@ -634,7 +636,8 @@ discard block |
||
| 634 | 636 | * @param $tvId |
| 635 | 637 | * @return bool |
| 636 | 638 | */ |
| 637 | - protected function belongsToTemplate($tvId) { |
|
| 639 | + protected function belongsToTemplate($tvId) |
|
| 640 | + {
|
|
| 638 | 641 | $template = $this->get('template'); |
| 639 | 642 | |
| 640 | 643 | return isset($this->tvTpl[$template]) && in_array($tvId, $this->tvTpl[$template]); |
@@ -645,16 +648,16 @@ discard block |
||
| 645 | 648 | * @return $this |
| 646 | 649 | * @throws Exception |
| 647 | 650 | */ |
| 648 | - public function toTrash($ids) |
|
| 649 | - { |
|
| 651 | + public function toTrash($ids) |
|
| 652 | + {
|
|
| 650 | 653 | $ignore = $this->systemID(); |
| 651 | 654 | $_ids = $this->cleanIDs($ids, ',', $ignore); |
| 652 | - if (is_array($_ids) && $_ids != array()) { |
|
| 655 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 653 | 656 | $id = $this->sanitarIn($_ids); |
| 654 | 657 | $uid = (int)$this->modx->getLoginUserId(); |
| 655 | 658 | $deletedon = time() + $this->modxConfig('server_offset_time'); |
| 656 | 659 | $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})"); |
| 657 | - } else { |
|
| 660 | + } else {
|
|
| 658 | 661 | throw new Exception('Invalid IDs list for mark trash: <pre>' . print_r($ids, |
| 659 | 662 | 1) . '</pre> please, check ignore list: <pre>' . print_r($ignore, 1) . '</pre>'); |
| 660 | 663 | } |
@@ -666,11 +669,11 @@ discard block |
||
| 666 | 669 | * @param bool $fire_events |
| 667 | 670 | * @return $this |
| 668 | 671 | */ |
| 669 | - public function clearTrash($fire_events = false) |
|
| 670 | - { |
|
| 672 | + public function clearTrash($fire_events = false) |
|
| 673 | + {
|
|
| 671 | 674 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); |
| 672 | 675 | $_ids = $this->modx->db->getColumn('id', $q); |
| 673 | - if (is_array($_ids) && $_ids != array()) { |
|
| 676 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 674 | 677 | $this->invokeEvent('OnBeforeEmptyTrash', array( |
| 675 | 678 | "ids" => $_ids |
| 676 | 679 | ), $fire_events); |
@@ -692,15 +695,15 @@ discard block |
||
| 692 | 695 | * @param int|bool $depth |
| 693 | 696 | * @return array |
| 694 | 697 | */ |
| 695 | - public function children($ids, $depth) |
|
| 696 | - { |
|
| 698 | + public function children($ids, $depth) |
|
| 699 | + {
|
|
| 697 | 700 | $_ids = $this->cleanIDs($ids, ','); |
| 698 | - if (is_array($_ids) && $_ids != array()) { |
|
| 701 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 699 | 702 | $id = $this->sanitarIn($_ids); |
| 700 | - if (!empty($id)) { |
|
| 703 | + if (!empty($id)) {
|
|
| 701 | 704 | $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); |
| 702 | 705 | $id = $this->modx->db->getColumn('id', $q); |
| 703 | - if ($depth > 0 || $depth === true) { |
|
| 706 | + if ($depth > 0 || $depth === true) {
|
|
| 704 | 707 | $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1)); |
| 705 | 708 | } |
| 706 | 709 | $_ids = array_merge($_ids, $id); |
@@ -716,8 +719,8 @@ discard block |
||
| 716 | 719 | * @return $this |
| 717 | 720 | * @throws Exception |
| 718 | 721 | */ |
| 719 | - public function delete($ids, $fire_events = false) |
|
| 720 | - { |
|
| 722 | + public function delete($ids, $fire_events = false) |
|
| 723 | + {
|
|
| 721 | 724 | $ids = $this->children($ids, true); |
| 722 | 725 | $_ids = $this->cleanIDs($ids, ',', $this->systemID()); |
| 723 | 726 | $this->invokeEvent('OnBeforeDocFormDelete', array( |
@@ -734,8 +737,8 @@ discard block |
||
| 734 | 737 | /** |
| 735 | 738 | * @return array |
| 736 | 739 | */ |
| 737 | - private function systemID() |
|
| 738 | - { |
|
| 740 | + private function systemID() |
|
| 741 | + {
|
|
| 739 | 742 | $ignore = array( |
| 740 | 743 | 0, //empty document |
| 741 | 744 | (int)$this->modxConfig('site_start'), |
@@ -745,7 +748,7 @@ discard block |
||
| 745 | 748 | ); |
| 746 | 749 | $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''"); |
| 747 | 750 | $data = $this->modx->db->makeArray($data); |
| 748 | - foreach ($data as $item) { |
|
| 751 | + foreach ($data as $item) {
|
|
| 749 | 752 | $ignore[] = (int)$item['setting_value']; |
| 750 | 753 | } |
| 751 | 754 | |
@@ -757,22 +760,22 @@ discard block |
||
| 757 | 760 | * @param $alias |
| 758 | 761 | * @return string |
| 759 | 762 | */ |
| 760 | - protected function checkAlias($alias) |
|
| 761 | - { |
|
| 763 | + protected function checkAlias($alias) |
|
| 764 | + {
|
|
| 762 | 765 | $alias = strtolower($alias); |
| 763 | - if ($this->modxConfig('friendly_urls')) { |
|
| 766 | + if ($this->modxConfig('friendly_urls')) {
|
|
| 764 | 767 | $_alias = $this->escape($alias); |
| 765 | - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { |
|
| 768 | + if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) {
|
|
| 766 | 769 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); |
| 767 | - } else { |
|
| 770 | + } else {
|
|
| 768 | 771 | $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); |
| 769 | 772 | } |
| 770 | - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { |
|
| 773 | + if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) {
|
|
| 771 | 774 | $suffix = substr($alias, -2); |
| 772 | - if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { |
|
| 775 | + if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) {
|
|
| 773 | 776 | $suffix = (int)$tmp[1] + 1; |
| 774 | 777 | $alias = substr($alias, 0, -2) . '-' . $suffix; |
| 775 | - } else { |
|
| 778 | + } else {
|
|
| 776 | 779 | $alias .= '-2'; |
| 777 | 780 | } |
| 778 | 781 | $alias = $this->checkAlias($alias); |
@@ -786,8 +789,8 @@ discard block |
||
| 786 | 789 | * @param $key |
| 787 | 790 | * @return bool |
| 788 | 791 | */ |
| 789 | - public function issetField($key) |
|
| 790 | - { |
|
| 792 | + public function issetField($key) |
|
| 793 | + {
|
|
| 791 | 794 | return (array_key_exists($key, $this->default_field) || array_key_exists($key, $this->tv)); |
| 792 | 795 | } |
| 793 | 796 | |
@@ -795,12 +798,12 @@ discard block |
||
| 795 | 798 | * @param bool $reload |
| 796 | 799 | * @return $this |
| 797 | 800 | */ |
| 798 | - protected function get_TV($reload = false) |
|
| 799 | - { |
|
| 801 | + protected function get_TV($reload = false) |
|
| 802 | + {
|
|
| 800 | 803 | $this->modx->_TVnames = array(); |
| 801 | - if (empty($this->modx->_TVnames) || $reload) { |
|
| 804 | + if (empty($this->modx->_TVnames) || $reload) {
|
|
| 802 | 805 | $result = $this->query('SELECT `id`,`name`,`type` FROM ' . $this->makeTable('site_tmplvars')); |
| 803 | - while ($row = $this->modx->db->GetRow($result)) { |
|
| 806 | + while ($row = $this->modx->db->GetRow($result)) {
|
|
| 804 | 807 | $this->modx->_TVnames[$row['name']] = array( |
| 805 | 808 | "id" => $row['id'], |
| 806 | 809 | "type" => $row['type'] |
@@ -809,14 +812,16 @@ discard block |
||
| 809 | 812 | } |
| 810 | 813 | $arrayTypes = array('checkbox', 'listbox-multiple'); |
| 811 | 814 | $arrayTVs = array(); |
| 812 | - foreach ($this->modx->_TVnames as $name => $data) { |
|
| 815 | + foreach ($this->modx->_TVnames as $name => $data) {
|
|
| 813 | 816 | $this->tvid[$data['id']] = $name; |
| 814 | 817 | $this->tv[$name] = $data['id']; |
| 815 | - if (in_array($data['type'], $arrayTypes)) { |
|
| 818 | + if (in_array($data['type'], $arrayTypes)) {
|
|
| 816 | 819 | $arrayTVs[] = $name; |
| 817 | 820 | } |
| 818 | 821 | } |
| 819 | - if (empty($this->tvaFields)) $this->tvaFields = $arrayTVs; |
|
| 822 | + if (empty($this->tvaFields)) {
|
|
| 823 | + $this->tvaFields = $arrayTVs; |
|
| 824 | + } |
|
| 820 | 825 | $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); |
| 821 | 826 | |
| 822 | 827 | return $this; |
@@ -825,12 +830,12 @@ discard block |
||
| 825 | 830 | /** |
| 826 | 831 | * @return $this |
| 827 | 832 | */ |
| 828 | - protected function loadTVTemplate() |
|
| 829 | - { |
|
| 833 | + protected function loadTVTemplate() |
|
| 834 | + {
|
|
| 830 | 835 | $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); |
| 831 | 836 | $q = $this->modx->db->makeArray($q); |
| 832 | 837 | $this->tvTpl = array(); |
| 833 | - foreach ($q as $item) { |
|
| 838 | + foreach ($q as $item) {
|
|
| 834 | 839 | $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; |
| 835 | 840 | } |
| 836 | 841 | |
@@ -841,16 +846,16 @@ discard block |
||
| 841 | 846 | * @param array $tvId |
| 842 | 847 | * @return $this |
| 843 | 848 | */ |
| 844 | - protected function loadTVDefault(array $tvId = array()) |
|
| 845 | - { |
|
| 846 | - if (is_array($tvId) && !empty($tvId)) { |
|
| 849 | + protected function loadTVDefault(array $tvId = array()) |
|
| 850 | + {
|
|
| 851 | + if (is_array($tvId) && !empty($tvId)) {
|
|
| 847 | 852 | $tbl_site_tmplvars = $this->makeTable('site_tmplvars'); |
| 848 | 853 | $fields = 'id,name,default_text as value,display,display_params,type'; |
| 849 | 854 | $implodeTvId = implode(',', $tvId); |
| 850 | 855 | $rs = $this->query("SELECT {$fields} FROM {$tbl_site_tmplvars} WHERE id IN({$implodeTvId})"); |
| 851 | 856 | $rows = $this->modx->db->makeArray($rs); |
| 852 | 857 | $this->tvd = array(); |
| 853 | - foreach ($rows as $item) { |
|
| 858 | + foreach ($rows as $item) {
|
|
| 854 | 859 | $this->tvd[$item['name']] = $item; |
| 855 | 860 | } |
| 856 | 861 | } |
@@ -863,17 +868,17 @@ discard block |
||
| 863 | 868 | * @return int |
| 864 | 869 | * @throws Exception |
| 865 | 870 | */ |
| 866 | - public function setTemplate($tpl) |
|
| 867 | - { |
|
| 868 | - if (!is_numeric($tpl) || $tpl != (int)$tpl) { |
|
| 869 | - if (is_scalar($tpl)) { |
|
| 871 | + public function setTemplate($tpl) |
|
| 872 | + {
|
|
| 873 | + if (!is_numeric($tpl) || $tpl != (int)$tpl) {
|
|
| 874 | + if (is_scalar($tpl)) {
|
|
| 870 | 875 | $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; |
| 871 | 876 | $rs = $this->query($sql); |
| 872 | - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { |
|
| 877 | + if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) {
|
|
| 873 | 878 | throw new Exception("Template {$tpl} is not exists"); |
| 874 | 879 | } |
| 875 | 880 | $tpl = $this->modx->db->getValue($rs); |
| 876 | - } else { |
|
| 881 | + } else {
|
|
| 877 | 882 | throw new Exception("Invalid template name: " . print_r($tpl, 1)); |
| 878 | 883 | } |
| 879 | 884 | } |
@@ -884,14 +889,14 @@ discard block |
||
| 884 | 889 | /** |
| 885 | 890 | * @return string |
| 886 | 891 | */ |
| 887 | - protected function getAlias() |
|
| 888 | - { |
|
| 889 | - if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { |
|
| 892 | + protected function getAlias() |
|
| 893 | + {
|
|
| 894 | + if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') {
|
|
| 890 | 895 | $alias = strtr($this->get('pagetitle'), $this->table); |
| 891 | - } else { |
|
| 892 | - if ($this->get('alias') != '') { |
|
| 896 | + } else {
|
|
| 897 | + if ($this->get('alias') != '') {
|
|
| 893 | 898 | $alias = $this->get('alias'); |
| 894 | - } else { |
|
| 899 | + } else {
|
|
| 895 | 900 | $alias = ''; |
| 896 | 901 | } |
| 897 | 902 | } |
@@ -908,10 +913,10 @@ discard block |
||
| 908 | 913 | * |
| 909 | 914 | * Пересчет menuindex по полю таблицы site_content |
| 910 | 915 | */ |
| 911 | - public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
| 912 | - { |
|
| 916 | + public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') |
|
| 917 | + {
|
|
| 913 | 918 | $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; |
| 914 | - if (is_integer($parent) && $criteria !== '') { |
|
| 919 | + if (is_integer($parent) && $criteria !== '') {
|
|
| 915 | 920 | $this->query("SET @index := 0"); |
| 916 | 921 | $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}"); |
| 917 | 922 | } |
@@ -924,37 +929,37 @@ discard block |
||
| 924 | 929 | * |
| 925 | 930 | * @return $this |
| 926 | 931 | */ |
| 927 | - public function setDefaultTemplate() |
|
| 928 | - { |
|
| 932 | + public function setDefaultTemplate() |
|
| 933 | + {
|
|
| 929 | 934 | $parent = $this->get('parent'); |
| 930 | 935 | $template = $this->modxConfig('default_template'); |
| 931 | - switch ($this->modxConfig('auto_template_logic')) { |
|
| 936 | + switch ($this->modxConfig('auto_template_logic')) {
|
|
| 932 | 937 | case 'sibling': |
| 933 | - if (!$parent) { |
|
| 938 | + if (!$parent) {
|
|
| 934 | 939 | $site_start = $this->modxConfig('site_start'); |
| 935 | 940 | $where = "sc.isfolder=0 AND sc.id!={$site_start}"; |
| 936 | 941 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); |
| 937 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 942 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 938 | 943 | $template = $sibl[0]['template']; |
| 939 | 944 | } |
| 940 | - } else { |
|
| 945 | + } else {
|
|
| 941 | 946 | $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex', |
| 942 | 947 | 'ASC', 1); |
| 943 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 948 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 944 | 949 | $template = $sibl[0]['template']; |
| 945 | - } else { |
|
| 950 | + } else {
|
|
| 946 | 951 | $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex', |
| 947 | 952 | 'ASC', 1); |
| 948 | - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { |
|
| 953 | + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') {
|
|
| 949 | 954 | $template = $sibl[0]['template']; |
| 950 | 955 | } |
| 951 | 956 | } |
| 952 | 957 | } |
| 953 | 958 | break; |
| 954 | 959 | case 'parent': |
| 955 | - if ($parent) { |
|
| 960 | + if ($parent) {
|
|
| 956 | 961 | $_parent = $this->modx->getPageInfo($parent, 0, 'template'); |
| 957 | - if (isset($_parent['template'])) { |
|
| 962 | + if (isset($_parent['template'])) {
|
|
| 958 | 963 | $template = $_parent['template']; |
| 959 | 964 | } |
| 960 | 965 | } |
@@ -971,18 +976,18 @@ discard block |
||
| 971 | 976 | * @param bool $store обновить распакованное поле |
| 972 | 977 | * @return array ассоциативный массив с данными из json строки |
| 973 | 978 | */ |
| 974 | - public function decodeField($field, $store = false) |
|
| 975 | - { |
|
| 979 | + public function decodeField($field, $store = false) |
|
| 980 | + {
|
|
| 976 | 981 | $out = array(); |
| 977 | - if ($this->isDecodableField($field)) { |
|
| 982 | + if ($this->isDecodableField($field)) {
|
|
| 978 | 983 | $data = $this->get($field); |
| 979 | - if ($this->isTVarrayField($field)) { |
|
| 984 | + if ($this->isTVarrayField($field)) {
|
|
| 980 | 985 | $out = explode('||', $data); |
| 981 | - } else { |
|
| 986 | + } else {
|
|
| 982 | 987 | $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); |
| 983 | 988 | } |
| 984 | 989 | } |
| 985 | - if ($store) { |
|
| 990 | + if ($store) {
|
|
| 986 | 991 | $this->field[$field] = $out; |
| 987 | 992 | $this->markAsDecode($field); |
| 988 | 993 | } |
@@ -996,18 +1001,18 @@ discard block |
||
| 996 | 1001 | * @param bool $store обновить запакованное поле |
| 997 | 1002 | * @return string|null json строка |
| 998 | 1003 | */ |
| 999 | - public function encodeField($field, $store = false) |
|
| 1000 | - { |
|
| 1004 | + public function encodeField($field, $store = false) |
|
| 1005 | + {
|
|
| 1001 | 1006 | $out = null; |
| 1002 | - if ($this->isEncodableField($field)) { |
|
| 1007 | + if ($this->isEncodableField($field)) {
|
|
| 1003 | 1008 | $data = $this->get($field); |
| 1004 | - if ($this->isTVarrayField($field)) { |
|
| 1009 | + if ($this->isTVarrayField($field)) {
|
|
| 1005 | 1010 | $out = is_array($data) ? implode('||', $data) : $data; |
| 1006 | - } else { |
|
| 1011 | + } else {
|
|
| 1007 | 1012 | $out = json_encode($data); |
| 1008 | 1013 | } |
| 1009 | 1014 | } |
| 1010 | - if ($store) { |
|
| 1015 | + if ($store) {
|
|
| 1011 | 1016 | $this->field[$field] = $out; |
| 1012 | 1017 | $this->markAsEncode($field); |
| 1013 | 1018 | } |
@@ -1020,8 +1025,8 @@ discard block |
||
| 1020 | 1025 | * @param string $field имя поля |
| 1021 | 1026 | * @return boolean |
| 1022 | 1027 | */ |
| 1023 | - public function isTVarrayField($field) |
|
| 1024 | - { |
|
| 1028 | + public function isTVarrayField($field) |
|
| 1029 | + {
|
|
| 1025 | 1030 | return (is_scalar($field) && in_array($field, $this->tvaFields)); |
| 1026 | 1031 | } |
| 1027 | 1032 | |
@@ -1029,10 +1034,10 @@ discard block |
||
| 1029 | 1034 | * Пометить все поля как запакованные |
| 1030 | 1035 | * @return $this |
| 1031 | 1036 | */ |
| 1032 | - public function markAllEncode() |
|
| 1033 | - { |
|
| 1037 | + public function markAllEncode() |
|
| 1038 | + {
|
|
| 1034 | 1039 | parent::markAllEncode(); |
| 1035 | - foreach ($this->tvaFields as $field) { |
|
| 1040 | + foreach ($this->tvaFields as $field) {
|
|
| 1036 | 1041 | $this->markAsEncode($field); |
| 1037 | 1042 | } |
| 1038 | 1043 | |
@@ -1043,10 +1048,10 @@ discard block |
||
| 1043 | 1048 | * Пометить все поля как распакованные |
| 1044 | 1049 | * @return $this |
| 1045 | 1050 | */ |
| 1046 | - public function markAllDecode() |
|
| 1047 | - { |
|
| 1051 | + public function markAllDecode() |
|
| 1052 | + {
|
|
| 1048 | 1053 | parent::markAllDecode(); |
| 1049 | - foreach ($this->tvaFields as $field) { |
|
| 1054 | + foreach ($this->tvaFields as $field) {
|
|
| 1050 | 1055 | $this->markAsDecode($field); |
| 1051 | 1056 | } |
| 1052 | 1057 | |
@@ -1056,16 +1061,17 @@ discard block |
||
| 1056 | 1061 | /** |
| 1057 | 1062 | * @param int $docId |
| 1058 | 1063 | */ |
| 1059 | - public function getDocumentGroups($docId = 0) { |
|
| 1064 | + public function getDocumentGroups($docId = 0) |
|
| 1065 | + {
|
|
| 1060 | 1066 | $out = array(); |
| 1061 | 1067 | $doc = $this->switchObject($docId); |
| 1062 | - if (null !== $doc->getID()) { |
|
| 1068 | + if (null !== $doc->getID()) {
|
|
| 1063 | 1069 | $doc_groups = $this->makeTable('document_groups'); |
| 1064 | 1070 | $docgroup_names = $this->makeTable('documentgroup_names'); |
| 1065 | 1071 | |
| 1066 | 1072 | $rs = $this->query("SELECT `dg`.`document_group`, `dgn`.`name` FROM {$doc_groups} as `dg` INNER JOIN {$docgroup_names} as `dgn` ON `dgn`.`id`=`dg`.`document_group` |
| 1067 | 1073 | WHERE `dg`.`document` = " . $doc->getID()); |
| 1068 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 1074 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 1069 | 1075 | $out[$row['document_group']] = $row['name']; |
| 1070 | 1076 | } |
| 1071 | 1077 | |
@@ -1080,18 +1086,20 @@ discard block |
||
| 1080 | 1086 | * @param array $groupIds |
| 1081 | 1087 | * @return $this |
| 1082 | 1088 | */ |
| 1083 | - public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
| 1084 | - { |
|
| 1085 | - if (!is_array($groupIds)) return $this; |
|
| 1086 | - if ($this->newDoc && $docId == 0) { |
|
| 1089 | + public function setDocumentGroups($docId = 0, $groupIds = array()) |
|
| 1090 | + {
|
|
| 1091 | + if (!is_array($groupIds)) {
|
|
| 1092 | + return $this; |
|
| 1093 | + } |
|
| 1094 | + if ($this->newDoc && $docId == 0) {
|
|
| 1087 | 1095 | $this->groupIds = $groupIds; |
| 1088 | - } else { |
|
| 1096 | + } else {
|
|
| 1089 | 1097 | $doc = $this->switchObject($docId); |
| 1090 | - if ($id = $doc->getID()) { |
|
| 1091 | - foreach ($groupIds as $gid) { |
|
| 1098 | + if ($id = $doc->getID()) {
|
|
| 1099 | + foreach ($groupIds as $gid) {
|
|
| 1092 | 1100 | $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); |
| 1093 | 1101 | } |
| 1094 | - if (!$this->newDoc) { |
|
| 1102 | + if (!$this->newDoc) {
|
|
| 1095 | 1103 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 1096 | 1104 | $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); |
| 1097 | 1105 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param $val |
| 76 | 76 | * @return $this |
| 77 | 77 | */ |
| 78 | - protected function setRememberTime($val){ |
|
| 78 | + protected function setRememberTime($val) { |
|
| 79 | 79 | $this->rememberTime = (int)$val; |
| 80 | 80 | return $this; |
| 81 | 81 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | /** |
| 84 | 84 | * @return integer |
| 85 | 85 | */ |
| 86 | - public function getRememberTime(){ |
|
| 86 | + public function getRememberTime() { |
|
| 87 | 87 | return $this->rememberTime; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $this->close(); |
| 144 | 144 | $this->newDoc = false; |
| 145 | 145 | |
| 146 | - if (!$find = $this->findUser($id)) { |
|
| 146 | + if ( ! $find = $this->findUser($id)) { |
|
| 147 | 147 | $this->id = null; |
| 148 | 148 | } else { |
| 149 | 149 | $this->set('editedon', time()); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function set($key, $value) |
| 177 | 177 | { |
| 178 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 178 | + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { |
|
| 179 | 179 | switch ($key) { |
| 180 | 180 | case 'password': |
| 181 | 181 | $this->givenPassword = $value; |
@@ -233,20 +233,20 @@ discard block |
||
| 233 | 233 | return false; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
| 236 | + if ( ! $this->checkUnique('manager_users', 'username')) { |
|
| 237 | 237 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 238 | 238 | true) . '</pre>'; |
| 239 | 239 | |
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
| 243 | + if ( ! $this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
| 244 | 244 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 245 | 245 | |
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if(!$this->get('role')) { |
|
| 249 | + if ( ! $this->get('role')) { |
|
| 250 | 250 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
| 251 | 251 | } |
| 252 | 252 | |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | $fld = $this->toArray(); |
| 255 | 255 | foreach ($this->default_field['user'] as $key => $value) { |
| 256 | 256 | $tmp = $this->get($key); |
| 257 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 257 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 258 | 258 | $this->field[$key] = $value; |
| 259 | 259 | } |
| 260 | 260 | $this->Uset($key, 'user'); |
| 261 | 261 | unset($fld[$key]); |
| 262 | 262 | } |
| 263 | - if (!empty($this->set['user'])) { |
|
| 263 | + if ( ! empty($this->set['user'])) { |
|
| 264 | 264 | if ($this->newDoc) { |
| 265 | 265 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
| 266 | 266 | } else { |
@@ -276,13 +276,13 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | foreach ($this->default_field['attribute'] as $key => $value) { |
| 278 | 278 | $tmp = $this->get($key); |
| 279 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 279 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 280 | 280 | $this->field[$key] = $value; |
| 281 | 281 | } |
| 282 | 282 | $this->Uset($key, 'attribute'); |
| 283 | 283 | unset($fld[$key]); |
| 284 | 284 | } |
| 285 | - if (!empty($this->set['attribute'])) { |
|
| 285 | + if ( ! empty($this->set['attribute'])) { |
|
| 286 | 286 | if ($this->newDoc) { |
| 287 | 287 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 288 | 288 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | unset($fld['id']); |
| 297 | 297 | foreach ($fld as $key => $value) { |
| 298 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 298 | + if ($value == '' || ! $this->isChanged($key)) { |
|
| 299 | 299 | continue; |
| 300 | 300 | } |
| 301 | 301 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | // TODO |
| 309 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 309 | + if ( ! $this->newDoc && $this->givenPassword) { |
|
| 310 | 310 | $this->invokeEvent('OnManagerChangePassword', array( |
| 311 | 311 | 'userObj' => $this, |
| 312 | 312 | 'userid' => $this->id, |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | ), $fire_events); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - if (!empty($this->groupIds)) { |
|
| 319 | + if ( ! empty($this->groupIds)) { |
|
| 320 | 320 | $this->setUserGroups($this->id, $this->groupIds); |
| 321 | 321 | } |
| 322 | 322 | // TODO |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | $b = $tmp->get('blocked'); |
| 413 | 413 | $bu = $tmp->get('blockeduntil'); |
| 414 | 414 | $ba = $tmp->get('blockedafter'); |
| 415 | - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 415 | + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 416 | 416 | unset($tmp); |
| 417 | 417 | |
| 418 | 418 | return $flag; |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | $flag = $pluginFlag = false; |
| 436 | 436 | if ( |
| 437 | - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
|
| 437 | + (null !== $tmp->getID()) && ( ! $blocker || ($blocker && ! $tmp->checkBlock($id))) |
|
| 438 | 438 | ) { |
| 439 | 439 | $_password = $tmp->get('password'); |
| 440 | 440 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | } else { |
| 452 | 452 | $pluginFlag = (bool)$eventResult; |
| 453 | 453 | } |
| 454 | - if (!$pluginFlag) { |
|
| 454 | + if ( ! $pluginFlag) { |
|
| 455 | 455 | $hashType = $this->getPasswordHashType($_password); |
| 456 | 456 | switch ($hashType) { |
| 457 | 457 | case 'phpass': |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | */ |
| 489 | 489 | public function logOut($cookieName = 'modx_remember_manager', $fire_events = false) |
| 490 | 490 | { |
| 491 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
| 491 | + if ( ! $uid = $this->modx->getLoginUserID('mgr')) { |
|
| 492 | 492 | return; |
| 493 | 493 | } |
| 494 | 494 | $params = array( |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | $_SESSION['mgrPermissions'] = $this->mgrPermissions; |
| 535 | 535 | $_SESSION['mgrDocgroups'] = $this->getDocumentGroups(); |
| 536 | 536 | $_SESSION['mgrToken'] = md5($this->get('sessionid')); |
| 537 | - if (!empty($remember)) { |
|
| 537 | + if ( ! empty($remember)) { |
|
| 538 | 538 | $this->setAutoLoginCookie($cookieName, $remember); |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | */ |
| 585 | 585 | public function setAutoLoginCookie($cookieName, $remember = true) |
| 586 | 586 | { |
| 587 | - if (!empty($cookieName) && $this->getID() !== null) { |
|
| 587 | + if ( ! empty($cookieName) && $this->getID() !== null) { |
|
| 588 | 588 | $secure = $this->isSecure(); |
| 589 | 589 | $remember = is_bool($remember) ? $this->getRememberTime() : (int)$remember; |
| 590 | 590 | $cookieValue = $this->get('username'); |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | */ |
| 649 | 649 | public function setUserGroups($userID = 0, $groupIds = array()) |
| 650 | 650 | { |
| 651 | - if (!is_array($groupIds)) { |
|
| 651 | + if ( ! is_array($groupIds)) { |
|
| 652 | 652 | return $this; |
| 653 | 653 | } |
| 654 | 654 | if ($this->newDoc && $userID == 0) { |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | foreach ($groupIds as $gid) { |
| 660 | 660 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
| 661 | 661 | } |
| 662 | - if (!$this->newDoc) { |
|
| 662 | + if ( ! $this->newDoc) { |
|
| 663 | 663 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 664 | 664 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
| 665 | 665 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Class modUsers |
| 6 | 6 | */ |
| 7 | -class modManagers extends MODxAPI |
|
| 8 | -{ |
|
| 7 | +class modManagers extends MODxAPI |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | * @param bool $debug |
| 65 | 65 | * @throws Exception |
| 66 | 66 | */ |
| 67 | - public function __construct(DocumentParser $modx, $debug = false) |
|
| 68 | - { |
|
| 67 | + public function __construct(DocumentParser $modx, $debug = false) |
|
| 68 | + {
|
|
| 69 | 69 | $this->setRememberTime(60 * 60 * 24 * 365 * 5); |
| 70 | 70 | parent::__construct($modx, $debug); |
| 71 | 71 | $this->modx->loadExtension('phpass'); |
@@ -75,7 +75,8 @@ discard block |
||
| 75 | 75 | * @param $val |
| 76 | 76 | * @return $this |
| 77 | 77 | */ |
| 78 | - protected function setRememberTime($val){ |
|
| 78 | + protected function setRememberTime($val) |
|
| 79 | + {
|
|
| 79 | 80 | $this->rememberTime = (int)$val; |
| 80 | 81 | return $this; |
| 81 | 82 | } |
@@ -83,7 +84,8 @@ discard block |
||
| 83 | 84 | /** |
| 84 | 85 | * @return integer |
| 85 | 86 | */ |
| 86 | - public function getRememberTime(){ |
|
| 87 | + public function getRememberTime() |
|
| 88 | + {
|
|
| 87 | 89 | return $this->rememberTime; |
| 88 | 90 | } |
| 89 | 91 | |
@@ -91,8 +93,8 @@ discard block |
||
| 91 | 93 | * @param $key |
| 92 | 94 | * @return bool |
| 93 | 95 | */ |
| 94 | - public function issetField($key) |
|
| 95 | - { |
|
| 96 | + public function issetField($key) |
|
| 97 | + {
|
|
| 96 | 98 | return (array_key_exists($key, $this->default_field['user']) || array_key_exists($key, |
| 97 | 99 | $this->default_field['attribute']) || in_array($key, $this->default_field['hidden'])); |
| 98 | 100 | } |
@@ -101,9 +103,9 @@ discard block |
||
| 101 | 103 | * @param string $data |
| 102 | 104 | * @return string|false |
| 103 | 105 | */ |
| 104 | - protected function findUser($data) |
|
| 105 | - { |
|
| 106 | - switch (true) { |
|
| 106 | + protected function findUser($data) |
|
| 107 | + {
|
|
| 108 | + switch (true) {
|
|
| 107 | 109 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
| 108 | 110 | $find = 'attribute.internalKey'; |
| 109 | 111 | break; |
@@ -124,8 +126,8 @@ discard block |
||
| 124 | 126 | * @param array $data |
| 125 | 127 | * @return $this |
| 126 | 128 | */ |
| 127 | - public function create($data = array()) |
|
| 128 | - { |
|
| 129 | + public function create($data = array()) |
|
| 130 | + {
|
|
| 129 | 131 | parent::create($data); |
| 130 | 132 | $this->set('createdon', time()); |
| 131 | 133 | |
@@ -136,16 +138,16 @@ discard block |
||
| 136 | 138 | * @param $id |
| 137 | 139 | * @return $this |
| 138 | 140 | */ |
| 139 | - public function edit($id) |
|
| 140 | - { |
|
| 141 | + public function edit($id) |
|
| 142 | + {
|
|
| 141 | 143 | $id = is_scalar($id) ? trim($id) : ''; |
| 142 | - if ($this->getID() != $id) { |
|
| 144 | + if ($this->getID() != $id) {
|
|
| 143 | 145 | $this->close(); |
| 144 | 146 | $this->newDoc = false; |
| 145 | 147 | |
| 146 | - if (!$find = $this->findUser($id)) { |
|
| 148 | + if (!$find = $this->findUser($id)) {
|
|
| 147 | 149 | $this->id = null; |
| 148 | - } else { |
|
| 150 | + } else {
|
|
| 149 | 151 | $this->set('editedon', time()); |
| 150 | 152 | $result = $this->query(" |
| 151 | 153 | SELECT * from {$this->makeTable('user_attributes')} as attribute |
@@ -173,10 +175,10 @@ discard block |
||
| 173 | 175 | * @param $value |
| 174 | 176 | * @return $this |
| 175 | 177 | */ |
| 176 | - public function set($key, $value) |
|
| 177 | - { |
|
| 178 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 179 | - switch ($key) { |
|
| 178 | + public function set($key, $value) |
|
| 179 | + {
|
|
| 180 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) {
|
|
| 181 | + switch ($key) {
|
|
| 180 | 182 | case 'password': |
| 181 | 183 | $this->givenPassword = $value; |
| 182 | 184 | $value = $this->getPassword($value); |
@@ -184,7 +186,7 @@ discard block |
||
| 184 | 186 | case 'sessionid': |
| 185 | 187 | session_regenerate_id(false); |
| 186 | 188 | $value = session_id(); |
| 187 | - if ($mid = $this->modx->getLoginUserID('mgr')) { |
|
| 189 | + if ($mid = $this->modx->getLoginUserID('mgr')) {
|
|
| 188 | 190 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
| 189 | 191 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
| 190 | 192 | $this->modx->db->query("UPDATE {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
@@ -205,8 +207,8 @@ discard block |
||
| 205 | 207 | * @param $pass |
| 206 | 208 | * @return string |
| 207 | 209 | */ |
| 208 | - public function getPassword($pass) |
|
| 209 | - { |
|
| 210 | + public function getPassword($pass) |
|
| 211 | + {
|
|
| 210 | 212 | return $this->modx->phpass->HashPassword($pass); |
| 211 | 213 | } |
| 212 | 214 | |
@@ -214,8 +216,8 @@ discard block |
||
| 214 | 216 | * @param string $name |
| 215 | 217 | * @return bool |
| 216 | 218 | */ |
| 217 | - public function hasPermission($name) |
|
| 218 | - { |
|
| 219 | + public function hasPermission($name) |
|
| 220 | + {
|
|
| 219 | 221 | return (is_string($name) && $name && isset($this->mgrPermissions[$name])); |
| 220 | 222 | } |
| 221 | 223 | |
@@ -224,89 +226,89 @@ discard block |
||
| 224 | 226 | * @param bool $clearCache |
| 225 | 227 | * @return bool|int|null|void |
| 226 | 228 | */ |
| 227 | - public function save($fire_events = false, $clearCache = false) |
|
| 228 | - { |
|
| 229 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
| 229 | + public function save($fire_events = false, $clearCache = false) |
|
| 230 | + {
|
|
| 231 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') {
|
|
| 230 | 232 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
| 231 | 233 | true) . '</pre>'; |
| 232 | 234 | |
| 233 | 235 | return false; |
| 234 | 236 | } |
| 235 | 237 | |
| 236 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
| 238 | + if (!$this->checkUnique('manager_users', 'username')) {
|
|
| 237 | 239 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 238 | 240 | true) . '</pre>'; |
| 239 | 241 | |
| 240 | 242 | return false; |
| 241 | 243 | } |
| 242 | 244 | |
| 243 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
| 245 | + if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) {
|
|
| 244 | 246 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 245 | 247 | |
| 246 | 248 | return false; |
| 247 | 249 | } |
| 248 | 250 | |
| 249 | - if(!$this->get('role')) { |
|
| 251 | + if(!$this->get('role')) {
|
|
| 250 | 252 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
| 251 | 253 | } |
| 252 | 254 | |
| 253 | 255 | $this->set('sessionid', ''); |
| 254 | 256 | $fld = $this->toArray(); |
| 255 | - foreach ($this->default_field['user'] as $key => $value) { |
|
| 257 | + foreach ($this->default_field['user'] as $key => $value) {
|
|
| 256 | 258 | $tmp = $this->get($key); |
| 257 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 259 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 258 | 260 | $this->field[$key] = $value; |
| 259 | 261 | } |
| 260 | 262 | $this->Uset($key, 'user'); |
| 261 | 263 | unset($fld[$key]); |
| 262 | 264 | } |
| 263 | - if (!empty($this->set['user'])) { |
|
| 264 | - if ($this->newDoc) { |
|
| 265 | + if (!empty($this->set['user'])) {
|
|
| 266 | + if ($this->newDoc) {
|
|
| 265 | 267 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
| 266 | - } else { |
|
| 268 | + } else {
|
|
| 267 | 269 | $SQL = "UPDATE {$this->makeTable('manager_users')} SET " . implode(', ', |
| 268 | 270 | $this->set['user']) . " WHERE id = " . $this->id; |
| 269 | 271 | } |
| 270 | 272 | $this->query($SQL); |
| 271 | 273 | } |
| 272 | 274 | |
| 273 | - if ($this->newDoc) { |
|
| 275 | + if ($this->newDoc) {
|
|
| 274 | 276 | $this->id = $this->modx->db->getInsertId(); |
| 275 | 277 | } |
| 276 | 278 | |
| 277 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
| 279 | + foreach ($this->default_field['attribute'] as $key => $value) {
|
|
| 278 | 280 | $tmp = $this->get($key); |
| 279 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 281 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 280 | 282 | $this->field[$key] = $value; |
| 281 | 283 | } |
| 282 | 284 | $this->Uset($key, 'attribute'); |
| 283 | 285 | unset($fld[$key]); |
| 284 | 286 | } |
| 285 | - if (!empty($this->set['attribute'])) { |
|
| 286 | - if ($this->newDoc) { |
|
| 287 | + if (!empty($this->set['attribute'])) {
|
|
| 288 | + if ($this->newDoc) {
|
|
| 287 | 289 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 288 | 290 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
| 289 | 291 | $this->set['attribute']); |
| 290 | - } else { |
|
| 292 | + } else {
|
|
| 291 | 293 | $SQL = "UPDATE {$this->makeTable('user_attributes')} SET " . implode(', ', |
| 292 | 294 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
| 293 | 295 | } |
| 294 | 296 | $this->query($SQL); |
| 295 | 297 | } |
| 296 | 298 | unset($fld['id']); |
| 297 | - foreach ($fld as $key => $value) { |
|
| 298 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 299 | + foreach ($fld as $key => $value) {
|
|
| 300 | + if ($value == '' || !$this->isChanged($key)) {
|
|
| 299 | 301 | continue; |
| 300 | 302 | } |
| 301 | 303 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
| 302 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
| 304 | + if ($this->modx->db->getRecordCount($result) > 0) {
|
|
| 303 | 305 | $this->query("UPDATE {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
| 304 | - } else { |
|
| 306 | + } else {
|
|
| 305 | 307 | $this->query("INSERT into {$this->makeTable('user_settings')} SET `user` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 306 | 308 | } |
| 307 | 309 | } |
| 308 | 310 | // TODO |
| 309 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 311 | + if (!$this->newDoc && $this->givenPassword) {
|
|
| 310 | 312 | $this->invokeEvent('OnManagerChangePassword', array( |
| 311 | 313 | 'userObj' => $this, |
| 312 | 314 | 'userid' => $this->id, |
@@ -316,7 +318,7 @@ discard block |
||
| 316 | 318 | ), $fire_events); |
| 317 | 319 | } |
| 318 | 320 | |
| 319 | - if (!empty($this->groupIds)) { |
|
| 321 | + if (!empty($this->groupIds)) {
|
|
| 320 | 322 | $this->setUserGroups($this->id, $this->groupIds); |
| 321 | 323 | } |
| 322 | 324 | // TODO |
@@ -332,7 +334,7 @@ discard block |
||
| 332 | 334 | "userroleid" => $this->get('role') |
| 333 | 335 | ), $fire_events); |
| 334 | 336 | |
| 335 | - if ($clearCache) { |
|
| 337 | + if ($clearCache) {
|
|
| 336 | 338 | $this->clearCache($fire_events); |
| 337 | 339 | } |
| 338 | 340 | |
@@ -344,9 +346,9 @@ discard block |
||
| 344 | 346 | * @param bool $fire_events |
| 345 | 347 | * @return bool|null|void |
| 346 | 348 | */ |
| 347 | - public function delete($ids, $fire_events = false) |
|
| 348 | - { |
|
| 349 | - if ($this->edit($ids)) { |
|
| 349 | + public function delete($ids, $fire_events = false) |
|
| 350 | + {
|
|
| 351 | + if ($this->edit($ids)) {
|
|
| 350 | 352 | $flag = $this->query(" |
| 351 | 353 | DELETE user,attribute FROM {$this->makeTable('user_attributes')} as attribute |
| 352 | 354 | LEFT JOIN {$this->makeTable('manager_users')} as user ON user.id=attribute.internalKey |
@@ -360,7 +362,7 @@ discard block |
||
| 360 | 362 | 'username' => $this->get('username'), |
| 361 | 363 | 'timestamp' => time() |
| 362 | 364 | ), $fire_events); |
| 363 | - } else { |
|
| 365 | + } else {
|
|
| 364 | 366 | $flag = false; |
| 365 | 367 | } |
| 366 | 368 | $this->close(); |
@@ -375,13 +377,13 @@ discard block |
||
| 375 | 377 | * @param bool $fire_events |
| 376 | 378 | * @return bool |
| 377 | 379 | */ |
| 378 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
| 379 | - { |
|
| 380 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
| 381 | + {
|
|
| 380 | 382 | $flag = false; |
| 381 | - if (null === $this->getID() && $id) { |
|
| 383 | + if (null === $this->getID() && $id) {
|
|
| 382 | 384 | $this->edit($id); |
| 383 | 385 | } |
| 384 | - if (null !== $this->getID()) { |
|
| 386 | + if (null !== $this->getID()) {
|
|
| 385 | 387 | $flag = true; |
| 386 | 388 | $this->save(false); |
| 387 | 389 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -401,10 +403,10 @@ discard block |
||
| 401 | 403 | * @param int $id |
| 402 | 404 | * @return bool |
| 403 | 405 | */ |
| 404 | - public function checkBlock($id = 0) |
|
| 405 | - { |
|
| 406 | + public function checkBlock($id = 0) |
|
| 407 | + {
|
|
| 406 | 408 | $tmp = clone $this; |
| 407 | - if ($id && $tmp->getID() != $id) { |
|
| 409 | + if ($id && $tmp->getID() != $id) {
|
|
| 408 | 410 | $tmp->edit($id); |
| 409 | 411 | } |
| 410 | 412 | $now = time(); |
@@ -425,17 +427,17 @@ discard block |
||
| 425 | 427 | * @param bool $fire_events |
| 426 | 428 | * @return bool |
| 427 | 429 | */ |
| 428 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 429 | - { |
|
| 430 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 431 | + {
|
|
| 430 | 432 | $tmp = clone $this; |
| 431 | - if ($id && $tmp->getID() != $id) { |
|
| 433 | + if ($id && $tmp->getID() != $id) {
|
|
| 432 | 434 | $tmp->edit($id); |
| 433 | 435 | } |
| 434 | 436 | |
| 435 | 437 | $flag = $pluginFlag = false; |
| 436 | 438 | if ( |
| 437 | 439 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
| 438 | - ) { |
|
| 440 | + ) {
|
|
| 439 | 441 | $_password = $tmp->get('password'); |
| 440 | 442 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
| 441 | 443 | 'userObj' => $this, |
@@ -444,16 +446,16 @@ discard block |
||
| 444 | 446 | 'userpassword' => $password, |
| 445 | 447 | 'savedpassword' => $_password |
| 446 | 448 | ), $fire_events); |
| 447 | - if (is_array($eventResult)) { |
|
| 448 | - foreach ($eventResult as $result) { |
|
| 449 | + if (is_array($eventResult)) {
|
|
| 450 | + foreach ($eventResult as $result) {
|
|
| 449 | 451 | $pluginFlag = (bool)$result; |
| 450 | 452 | } |
| 451 | - } else { |
|
| 453 | + } else {
|
|
| 452 | 454 | $pluginFlag = (bool)$eventResult; |
| 453 | 455 | } |
| 454 | - if (!$pluginFlag) { |
|
| 456 | + if (!$pluginFlag) {
|
|
| 455 | 457 | $hashType = $this->getPasswordHashType($_password); |
| 456 | - switch ($hashType) { |
|
| 458 | + switch ($hashType) {
|
|
| 457 | 459 | case 'phpass': |
| 458 | 460 | $flag = $this->modx->phpass->CheckPassword($password, $_password); |
| 459 | 461 | break; |
@@ -463,15 +465,15 @@ discard block |
||
| 463 | 465 | case 'v1': |
| 464 | 466 | $algorithm = \APIhelpers::getkey($this->modx->config, 'pwd_hash_algo', 'UNCRYPT'); |
| 465 | 467 | $userAlgorithm = $this->getPasswordHashAlgorithm($_password); |
| 466 | - if ($algorithm !== $userAlgorithm) { |
|
| 468 | + if ($algorithm !== $userAlgorithm) {
|
|
| 467 | 469 | $algorithm = $userAlgorithm; |
| 468 | 470 | } |
| 469 | 471 | $flag = $_password == $this->makeHash($password, $tmp->getID(), $algorithm); |
| 470 | 472 | break; |
| 471 | 473 | } |
| 472 | - if ($flag && $hashType == 'md5' || $hashType == 'v1') { |
|
| 474 | + if ($flag && $hashType == 'md5' || $hashType == 'v1') {
|
|
| 473 | 475 | $tmp->set('password', $password)->save(); |
| 474 | - if ($id == $this->getID()) { |
|
| 476 | + if ($id == $this->getID()) {
|
|
| 475 | 477 | $this->field['password'] = $tmp->get('password'); |
| 476 | 478 | } |
| 477 | 479 | } |
@@ -486,9 +488,9 @@ discard block |
||
| 486 | 488 | * @param string $cookieName |
| 487 | 489 | * @param bool $fire_events |
| 488 | 490 | */ |
| 489 | - public function logOut($cookieName = 'modx_remember_manager', $fire_events = false) |
|
| 490 | - { |
|
| 491 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
| 491 | + public function logOut($cookieName = 'modx_remember_manager', $fire_events = false) |
|
| 492 | + {
|
|
| 493 | + if (!$uid = $this->modx->getLoginUserID('mgr')) {
|
|
| 492 | 494 | return; |
| 493 | 495 | } |
| 494 | 496 | $params = array( |
@@ -516,11 +518,11 @@ discard block |
||
| 516 | 518 | * |
| 517 | 519 | * remeber может быть числом в секундах |
| 518 | 520 | */ |
| 519 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 520 | - { |
|
| 521 | - switch ($directive) { |
|
| 521 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 522 | + {
|
|
| 523 | + switch ($directive) {
|
|
| 522 | 524 | case 'start': |
| 523 | - if ($this->getID() !== null) { |
|
| 525 | + if ($this->getID() !== null) {
|
|
| 524 | 526 | $_SESSION['usertype'] = 'manager'; |
| 525 | 527 | $_SESSION['mgrShortname'] = $this->get('username'); |
| 526 | 528 | $_SESSION['mgrFullname'] = $this->get('fullname'); |
@@ -534,13 +536,13 @@ discard block |
||
| 534 | 536 | $_SESSION['mgrPermissions'] = $this->mgrPermissions; |
| 535 | 537 | $_SESSION['mgrDocgroups'] = $this->getDocumentGroups(); |
| 536 | 538 | $_SESSION['mgrToken'] = md5($this->get('sessionid')); |
| 537 | - if (!empty($remember)) { |
|
| 539 | + if (!empty($remember)) {
|
|
| 538 | 540 | $this->setAutoLoginCookie($cookieName, $remember); |
| 539 | 541 | } |
| 540 | 542 | } |
| 541 | 543 | break; |
| 542 | 544 | case 'destroy': |
| 543 | - if (isset($_SESSION['mgrValidated'])) { |
|
| 545 | + if (isset($_SESSION['mgrValidated'])) {
|
|
| 544 | 546 | unset($_SESSION['usertype']); |
| 545 | 547 | unset($_SESSION['mgrShortname']); |
| 546 | 548 | unset($_SESSION['mgrFullname']); |
@@ -554,8 +556,8 @@ discard block |
||
| 554 | 556 | unset($_SESSION['mgrPermissions']); |
| 555 | 557 | unset($_SESSION['mgrToken']); |
| 556 | 558 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
| 557 | - } else { |
|
| 558 | - if (isset($_COOKIE[session_name()])) { |
|
| 559 | + } else {
|
|
| 560 | + if (isset($_COOKIE[session_name()])) {
|
|
| 559 | 561 | setcookie(session_name(), '', time() - 60, MODX_BASE_URL); |
| 560 | 562 | } |
| 561 | 563 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
@@ -570,8 +572,8 @@ discard block |
||
| 570 | 572 | /** |
| 571 | 573 | * @return bool |
| 572 | 574 | */ |
| 573 | - public function isSecure() |
|
| 574 | - { |
|
| 575 | + public function isSecure() |
|
| 576 | + {
|
|
| 575 | 577 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
| 576 | 578 | |
| 577 | 579 | return $out; |
@@ -582,9 +584,9 @@ discard block |
||
| 582 | 584 | * @param bool|integer $remember |
| 583 | 585 | * @return $this |
| 584 | 586 | */ |
| 585 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 586 | - { |
|
| 587 | - if (!empty($cookieName) && $this->getID() !== null) { |
|
| 587 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 588 | + {
|
|
| 589 | + if (!empty($cookieName) && $this->getID() !== null) {
|
|
| 588 | 590 | $secure = $this->isSecure(); |
| 589 | 591 | $remember = is_bool($remember) ? $this->getRememberTime() : (int)$remember; |
| 590 | 592 | $cookieValue = $this->get('username'); |
@@ -599,11 +601,11 @@ discard block |
||
| 599 | 601 | * @param int $userID |
| 600 | 602 | * @return array |
| 601 | 603 | */ |
| 602 | - public function getDocumentGroups($userID = 0) |
|
| 603 | - { |
|
| 604 | + public function getDocumentGroups($userID = 0) |
|
| 605 | + {
|
|
| 604 | 606 | $out = array(); |
| 605 | 607 | $user = $this->switchObject($userID); |
| 606 | - if (null !== $user->getID()) { |
|
| 608 | + if (null !== $user->getID()) {
|
|
| 607 | 609 | $member_groups = $this->modx->getFullTableName('member_groups'); |
| 608 | 610 | $membergroup_access = $this->modx->getFullTableName('membergroup_access'); |
| 609 | 611 | |
@@ -621,18 +623,18 @@ discard block |
||
| 621 | 623 | * @param int $userID |
| 622 | 624 | * @return array |
| 623 | 625 | */ |
| 624 | - public function getUserGroups($userID = 0) |
|
| 625 | - { |
|
| 626 | + public function getUserGroups($userID = 0) |
|
| 627 | + {
|
|
| 626 | 628 | $out = array(); |
| 627 | 629 | $user = $this->switchObject($userID); |
| 628 | - if (null !== $user->getID()) { |
|
| 630 | + if (null !== $user->getID()) {
|
|
| 629 | 631 | $member_groups = $this->makeTable('member_groups'); |
| 630 | 632 | $membergroup_names = $this->makeTable('membergroup_names'); |
| 631 | 633 | |
| 632 | 634 | $rs = $this->query("SELECT `ug`.`user_group`, `ugn`.`name` FROM {$member_groups} as `ug` |
| 633 | 635 | INNER JOIN {$membergroup_names} as `ugn` ON `ugn`.`id`=`ug`.`user_group` |
| 634 | 636 | WHERE `ug`.`member` = " . $user->getID()); |
| 635 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 637 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 636 | 638 | $out[$row['user_group']] = $row['name']; |
| 637 | 639 | } |
| 638 | 640 | } |
@@ -646,20 +648,20 @@ discard block |
||
| 646 | 648 | * @param array $groupIds |
| 647 | 649 | * @return $this |
| 648 | 650 | */ |
| 649 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 650 | - { |
|
| 651 | - if (!is_array($groupIds)) { |
|
| 651 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 652 | + {
|
|
| 653 | + if (!is_array($groupIds)) {
|
|
| 652 | 654 | return $this; |
| 653 | 655 | } |
| 654 | - if ($this->newDoc && $userID == 0) { |
|
| 656 | + if ($this->newDoc && $userID == 0) {
|
|
| 655 | 657 | $this->groupIds = $groupIds; |
| 656 | - } else { |
|
| 658 | + } else {
|
|
| 657 | 659 | $user = $this->switchObject($userID); |
| 658 | - if ($uid = $user->getID()) { |
|
| 659 | - foreach ($groupIds as $gid) { |
|
| 660 | + if ($uid = $user->getID()) {
|
|
| 661 | + foreach ($groupIds as $gid) {
|
|
| 660 | 662 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
| 661 | 663 | } |
| 662 | - if (!$this->newDoc) { |
|
| 664 | + if (!$this->newDoc) {
|
|
| 663 | 665 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 664 | 666 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
| 665 | 667 | } |
@@ -675,14 +677,14 @@ discard block |
||
| 675 | 677 | * @param string $pass |
| 676 | 678 | * @return string |
| 677 | 679 | */ |
| 678 | - public function getPasswordHashType($pass) |
|
| 679 | - { |
|
| 680 | + public function getPasswordHashType($pass) |
|
| 681 | + {
|
|
| 680 | 682 | $out = 'unknown'; |
| 681 | - if (substr($pass, 0, 1) === '$') { |
|
| 683 | + if (substr($pass, 0, 1) === '$') {
|
|
| 682 | 684 | $out = 'phpass'; |
| 683 | - } elseif (strpos($pass, '>') !== false) { |
|
| 685 | + } elseif (strpos($pass, '>') !== false) {
|
|
| 684 | 686 | $out = 'v1'; |
| 685 | - } elseif (strlen($pass) === 32) { |
|
| 687 | + } elseif (strlen($pass) === 32) {
|
|
| 686 | 688 | $out = 'md5'; |
| 687 | 689 | } |
| 688 | 690 | |
@@ -693,8 +695,8 @@ discard block |
||
| 693 | 695 | * @param string $pass |
| 694 | 696 | * @return string |
| 695 | 697 | */ |
| 696 | - public function getPasswordHashAlgorithm($pass) |
|
| 697 | - { |
|
| 698 | + public function getPasswordHashAlgorithm($pass) |
|
| 699 | + {
|
|
| 698 | 700 | $pointer = strpos($pass, '>'); |
| 699 | 701 | $out = $pointer === false ? 'NOSALT' : substr($pass, 0, $pointer); |
| 700 | 702 | |
@@ -707,11 +709,11 @@ discard block |
||
| 707 | 709 | * @param string $algorithm |
| 708 | 710 | * @return string |
| 709 | 711 | */ |
| 710 | - public function makeHash($pass, $seed, $algorithm) |
|
| 711 | - { |
|
| 712 | + public function makeHash($pass, $seed, $algorithm) |
|
| 713 | + {
|
|
| 712 | 714 | $salt = md5($pass . $seed); |
| 713 | 715 | |
| 714 | - switch ($algorithm) { |
|
| 716 | + switch ($algorithm) {
|
|
| 715 | 717 | case 'BLOWFISH_Y': |
| 716 | 718 | $salt = '$2y$07$' . substr($salt, 0, 22); |
| 717 | 719 | break; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param $val |
| 75 | 75 | * @return $this |
| 76 | 76 | */ |
| 77 | - protected function setRememberTime($val){ |
|
| 77 | + protected function setRememberTime($val) { |
|
| 78 | 78 | $this->rememberTime = (int)$val; |
| 79 | 79 | return $this; |
| 80 | 80 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | /** |
| 83 | 83 | * @return integer |
| 84 | 84 | */ |
| 85 | - public function getRememberTime(){ |
|
| 85 | + public function getRememberTime() { |
|
| 86 | 86 | return $this->rememberTime; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | $this->close(); |
| 143 | 143 | $this->newDoc = false; |
| 144 | 144 | |
| 145 | - if (!$find = $this->findUser($id)) { |
|
| 145 | + if ( ! $find = $this->findUser($id)) { |
|
| 146 | 146 | $this->id = null; |
| 147 | 147 | } else { |
| 148 | 148 | $this->set('editedon', time()); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | public function set($key, $value) |
| 179 | 179 | { |
| 180 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 180 | + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { |
|
| 181 | 181 | switch ($key) { |
| 182 | 182 | case 'password': |
| 183 | 183 | $this->givenPassword = $value; |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | return false; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if (!$this->checkUnique('web_users', 'username')) { |
|
| 229 | + if ( ! $this->checkUnique('web_users', 'username')) { |
|
| 230 | 230 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 231 | 231 | true) . '</pre>'; |
| 232 | 232 | |
| 233 | 233 | return false; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 236 | + if ( ! $this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 237 | 237 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 238 | 238 | |
| 239 | 239 | return false; |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | $fld = $this->toArray(); |
| 243 | 243 | foreach ($this->default_field['user'] as $key => $value) { |
| 244 | 244 | $tmp = $this->get($key); |
| 245 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 245 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 246 | 246 | $this->field[$key] = $value; |
| 247 | 247 | } |
| 248 | 248 | $this->Uset($key, 'user'); |
| 249 | 249 | unset($fld[$key]); |
| 250 | 250 | } |
| 251 | - if (!empty($this->set['user'])) { |
|
| 251 | + if ( ! empty($this->set['user'])) { |
|
| 252 | 252 | if ($this->newDoc) { |
| 253 | 253 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 254 | 254 | } else { |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | unset($fld['id']); |
| 267 | 267 | |
| 268 | 268 | foreach ($fld as $key => $value) { |
| 269 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 269 | + if ($value == '' || ! $this->isChanged($key)) { |
|
| 270 | 270 | continue; |
| 271 | 271 | } |
| 272 | 272 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 279 | + if ( ! $this->newDoc && $this->givenPassword) { |
|
| 280 | 280 | $this->invokeEvent('OnWebChangePassword', array( |
| 281 | 281 | 'userObj' => $this, |
| 282 | 282 | 'userid' => $this->id, |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | ), $fire_events); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - if (!empty($this->groupIds)) $this->setUserGroups($this->id, $this->groupIds); |
|
| 290 | + if ( ! empty($this->groupIds)) $this->setUserGroups($this->id, $this->groupIds); |
|
| 291 | 291 | |
| 292 | 292 | $this->invokeEvent('OnWebSaveUser', array( |
| 293 | 293 | 'userObj' => $this, |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | protected function saveQuery(array &$fld) { |
| 310 | 310 | foreach ($this->default_field['attribute'] as $key => $value) { |
| 311 | 311 | $tmp = $this->get($key); |
| 312 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 312 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 313 | 313 | $this->field[$key] = $value; |
| 314 | 314 | } |
| 315 | 315 | $this->Uset($key, 'attribute'); |
| 316 | 316 | unset($fld[$key]); |
| 317 | 317 | } |
| 318 | - if (!empty($this->set['attribute'])) { |
|
| 318 | + if ( ! empty($this->set['attribute'])) { |
|
| 319 | 319 | if ($this->newDoc) { |
| 320 | 320 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 321 | 321 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | $b = $tmp->get('blocked'); |
| 406 | 406 | $bu = $tmp->get('blockeduntil'); |
| 407 | 407 | $ba = $tmp->get('blockedafter'); |
| 408 | - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 408 | + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 409 | 409 | unset($tmp); |
| 410 | 410 | |
| 411 | 411 | return $flag; |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | |
| 428 | 428 | $flag = $pluginFlag = false; |
| 429 | 429 | if ( |
| 430 | - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
|
| 430 | + (null !== $tmp->getID()) && ( ! $blocker || ($blocker && ! $tmp->checkBlock($id))) |
|
| 431 | 431 | ) { |
| 432 | 432 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
| 433 | 433 | 'userObj' => $this, |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | } else { |
| 444 | 444 | $pluginFlag = (bool)$eventResult; |
| 445 | 445 | } |
| 446 | - if (!$pluginFlag) { |
|
| 446 | + if ( ! $pluginFlag) { |
|
| 447 | 447 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
| 448 | 448 | } |
| 449 | 449 | } |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | if (isset($_COOKIE[$cookieName])) { |
| 464 | 464 | $cookie = explode('|', $_COOKIE[$cookieName], 4); |
| 465 | 465 | if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
| 466 | - if (!$fulltime && isset($cookie[4])) { |
|
| 466 | + if ( ! $fulltime && isset($cookie[4])) { |
|
| 467 | 467 | $fulltime = (int)$cookie[4]; |
| 468 | 468 | } |
| 469 | 469 | $this->close(); |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | && null !== $this->getID() |
| 475 | 475 | && $this->get('password') == $cookie[1] |
| 476 | 476 | && $this->get('sessionid') == $cookie[2] |
| 477 | - && !$this->checkBlock($this->getID()) |
|
| 477 | + && ! $this->checkBlock($this->getID()) |
|
| 478 | 478 | ) { |
| 479 | 479 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
| 480 | 480 | |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | public function logOut($cookieName = 'WebLoginPE', $fire_events = false) |
| 493 | 493 | { |
| 494 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
| 494 | + if ( ! $uid = $this->modx->getLoginUserID('web')) { |
|
| 495 | 495 | return; |
| 496 | 496 | } |
| 497 | 497 | $params = array( |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | $_SESSION['webUsrConfigSet'] = array(); |
| 536 | 536 | $_SESSION['webUserGroupNames'] = $this->getUserGroups(); |
| 537 | 537 | $_SESSION['webDocgroups'] = $this->getDocumentGroups(); |
| 538 | - if (!empty($remember)) { |
|
| 538 | + if ( ! empty($remember)) { |
|
| 539 | 539 | $this->setAutoLoginCookie($cookieName, $remember); |
| 540 | 540 | } |
| 541 | 541 | } |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | */ |
| 588 | 588 | public function setAutoLoginCookie($cookieName, $remember = true) |
| 589 | 589 | { |
| 590 | - if (!empty($cookieName) && $this->getID() !== null) { |
|
| 590 | + if ( ! empty($cookieName) && $this->getID() !== null) { |
|
| 591 | 591 | $secure = $this->isSecure(); |
| 592 | 592 | $remember = is_bool($remember) ? $this->getRememberTime() : (int)$remember; |
| 593 | 593 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | */ |
| 654 | 654 | public function setUserGroups($userID = 0, $groupIds = array()) |
| 655 | 655 | { |
| 656 | - if (!is_array($groupIds)) return $this; |
|
| 656 | + if ( ! is_array($groupIds)) return $this; |
|
| 657 | 657 | if ($this->newDoc && $userID == 0) { |
| 658 | 658 | $this->groupIds = $groupIds; |
| 659 | 659 | } else { |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | foreach ($groupIds as $gid) { |
| 663 | 663 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
| 664 | 664 | } |
| 665 | - if (!$this->newDoc) { |
|
| 665 | + if ( ! $this->newDoc) { |
|
| 666 | 666 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 667 | 667 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
| 668 | 668 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Class modUsers |
| 6 | 6 | */ |
| 7 | -class modUsers extends MODxAPI |
|
| 8 | -{ |
|
| 7 | +class modUsers extends MODxAPI |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | * @param bool $debug |
| 65 | 65 | * @throws Exception |
| 66 | 66 | */ |
| 67 | - public function __construct(DocumentParser $modx, $debug = false) |
|
| 68 | - { |
|
| 67 | + public function __construct(DocumentParser $modx, $debug = false) |
|
| 68 | + {
|
|
| 69 | 69 | $this->setRememberTime(60 * 60 * 24 * 365 * 5); |
| 70 | 70 | parent::__construct($modx, $debug); |
| 71 | 71 | } |
@@ -74,7 +74,8 @@ discard block |
||
| 74 | 74 | * @param $val |
| 75 | 75 | * @return $this |
| 76 | 76 | */ |
| 77 | - protected function setRememberTime($val){ |
|
| 77 | + protected function setRememberTime($val) |
|
| 78 | + {
|
|
| 78 | 79 | $this->rememberTime = (int)$val; |
| 79 | 80 | return $this; |
| 80 | 81 | } |
@@ -82,7 +83,8 @@ discard block |
||
| 82 | 83 | /** |
| 83 | 84 | * @return integer |
| 84 | 85 | */ |
| 85 | - public function getRememberTime(){ |
|
| 86 | + public function getRememberTime() |
|
| 87 | + {
|
|
| 86 | 88 | return $this->rememberTime; |
| 87 | 89 | } |
| 88 | 90 | |
@@ -90,8 +92,8 @@ discard block |
||
| 90 | 92 | * @param $key |
| 91 | 93 | * @return bool |
| 92 | 94 | */ |
| 93 | - public function issetField($key) |
|
| 94 | - { |
|
| 95 | + public function issetField($key) |
|
| 96 | + {
|
|
| 95 | 97 | return (array_key_exists($key, $this->default_field['user']) || array_key_exists($key, |
| 96 | 98 | $this->default_field['attribute']) || in_array($key, $this->default_field['hidden'])); |
| 97 | 99 | } |
@@ -100,9 +102,9 @@ discard block |
||
| 100 | 102 | * @param string $data |
| 101 | 103 | * @return string|false |
| 102 | 104 | */ |
| 103 | - protected function findUser($data) |
|
| 104 | - { |
|
| 105 | - switch (true) { |
|
| 105 | + protected function findUser($data) |
|
| 106 | + {
|
|
| 107 | + switch (true) {
|
|
| 106 | 108 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
| 107 | 109 | $find = 'attribute.internalKey'; |
| 108 | 110 | break; |
@@ -123,8 +125,8 @@ discard block |
||
| 123 | 125 | * @param array $data |
| 124 | 126 | * @return $this |
| 125 | 127 | */ |
| 126 | - public function create($data = array()) |
|
| 127 | - { |
|
| 128 | + public function create($data = array()) |
|
| 129 | + {
|
|
| 128 | 130 | parent::create($data); |
| 129 | 131 | $this->set('createdon', time()); |
| 130 | 132 | |
@@ -135,16 +137,16 @@ discard block |
||
| 135 | 137 | * @param $id |
| 136 | 138 | * @return $this |
| 137 | 139 | */ |
| 138 | - public function edit($id) |
|
| 139 | - { |
|
| 140 | + public function edit($id) |
|
| 141 | + {
|
|
| 140 | 142 | $id = is_scalar($id) ? trim($id) : ''; |
| 141 | - if ($this->getID() != $id) { |
|
| 143 | + if ($this->getID() != $id) {
|
|
| 142 | 144 | $this->close(); |
| 143 | 145 | $this->newDoc = false; |
| 144 | 146 | |
| 145 | - if (!$find = $this->findUser($id)) { |
|
| 147 | + if (!$find = $this->findUser($id)) {
|
|
| 146 | 148 | $this->id = null; |
| 147 | - } else { |
|
| 149 | + } else {
|
|
| 148 | 150 | $this->set('editedon', time()); |
| 149 | 151 | $this->editQuery($find, $id); |
| 150 | 152 | $this->id = empty($this->field['internalKey']) ? null : $this->get('internalKey'); |
@@ -161,7 +163,8 @@ discard block |
||
| 161 | 163 | * @param string $find |
| 162 | 164 | * @param string $id |
| 163 | 165 | */ |
| 164 | - protected function editQuery($find, $id) { |
|
| 166 | + protected function editQuery($find, $id) |
|
| 167 | + {
|
|
| 165 | 168 | $result = $this->query(" |
| 166 | 169 | SELECT * from {$this->makeTable('web_user_attributes')} as attribute |
| 167 | 170 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -175,10 +178,10 @@ discard block |
||
| 175 | 178 | * @param $value |
| 176 | 179 | * @return $this |
| 177 | 180 | */ |
| 178 | - public function set($key, $value) |
|
| 179 | - { |
|
| 180 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 181 | - switch ($key) { |
|
| 181 | + public function set($key, $value) |
|
| 182 | + {
|
|
| 183 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) {
|
|
| 184 | + switch ($key) {
|
|
| 182 | 185 | case 'password': |
| 183 | 186 | $this->givenPassword = $value; |
| 184 | 187 | $value = $this->getPassword($value); |
@@ -186,7 +189,7 @@ discard block |
||
| 186 | 189 | case 'sessionid': |
| 187 | 190 | session_regenerate_id(false); |
| 188 | 191 | $value = session_id(); |
| 189 | - if ($mid = $this->modx->getLoginUserID('mgr')) { |
|
| 192 | + if ($mid = $this->modx->getLoginUserID('mgr')) {
|
|
| 190 | 193 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
| 191 | 194 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
| 192 | 195 | $this->modx->db->query("UPDATE {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
@@ -207,8 +210,8 @@ discard block |
||
| 207 | 210 | * @param $pass |
| 208 | 211 | * @return string |
| 209 | 212 | */ |
| 210 | - public function getPassword($pass) |
|
| 211 | - { |
|
| 213 | + public function getPassword($pass) |
|
| 214 | + {
|
|
| 212 | 215 | return md5($pass); |
| 213 | 216 | } |
| 214 | 217 | |
@@ -217,66 +220,66 @@ discard block |
||
| 217 | 220 | * @param bool $clearCache |
| 218 | 221 | * @return bool|int|null|void |
| 219 | 222 | */ |
| 220 | - public function save($fire_events = false, $clearCache = false) |
|
| 221 | - { |
|
| 222 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
| 223 | + public function save($fire_events = false, $clearCache = false) |
|
| 224 | + {
|
|
| 225 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') {
|
|
| 223 | 226 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
| 224 | 227 | true) . '</pre>'; |
| 225 | 228 | |
| 226 | 229 | return false; |
| 227 | 230 | } |
| 228 | 231 | |
| 229 | - if (!$this->checkUnique('web_users', 'username')) { |
|
| 232 | + if (!$this->checkUnique('web_users', 'username')) {
|
|
| 230 | 233 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 231 | 234 | true) . '</pre>'; |
| 232 | 235 | |
| 233 | 236 | return false; |
| 234 | 237 | } |
| 235 | 238 | |
| 236 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 239 | + if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) {
|
|
| 237 | 240 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 238 | 241 | |
| 239 | 242 | return false; |
| 240 | 243 | } |
| 241 | 244 | $this->set('sessionid', ''); |
| 242 | 245 | $fld = $this->toArray(); |
| 243 | - foreach ($this->default_field['user'] as $key => $value) { |
|
| 246 | + foreach ($this->default_field['user'] as $key => $value) {
|
|
| 244 | 247 | $tmp = $this->get($key); |
| 245 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 248 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 246 | 249 | $this->field[$key] = $value; |
| 247 | 250 | } |
| 248 | 251 | $this->Uset($key, 'user'); |
| 249 | 252 | unset($fld[$key]); |
| 250 | 253 | } |
| 251 | - if (!empty($this->set['user'])) { |
|
| 252 | - if ($this->newDoc) { |
|
| 254 | + if (!empty($this->set['user'])) {
|
|
| 255 | + if ($this->newDoc) {
|
|
| 253 | 256 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 254 | - } else { |
|
| 257 | + } else {
|
|
| 255 | 258 | $SQL = "UPDATE {$this->makeTable('web_users')} SET " . implode(', ', |
| 256 | 259 | $this->set['user']) . " WHERE id = " . $this->id; |
| 257 | 260 | } |
| 258 | 261 | $this->query($SQL); |
| 259 | 262 | } |
| 260 | 263 | |
| 261 | - if ($this->newDoc) { |
|
| 264 | + if ($this->newDoc) {
|
|
| 262 | 265 | $this->id = $this->modx->db->getInsertId(); |
| 263 | 266 | } |
| 264 | 267 | |
| 265 | 268 | $this->saveQuery($fld); |
| 266 | 269 | unset($fld['id']); |
| 267 | 270 | |
| 268 | - foreach ($fld as $key => $value) { |
|
| 269 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 271 | + foreach ($fld as $key => $value) {
|
|
| 272 | + if ($value == '' || !$this->isChanged($key)) {
|
|
| 270 | 273 | continue; |
| 271 | 274 | } |
| 272 | 275 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
| 273 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
| 276 | + if ($this->modx->db->getRecordCount($result) > 0) {
|
|
| 274 | 277 | $this->query("UPDATE {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
| 275 | - } else { |
|
| 278 | + } else {
|
|
| 276 | 279 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 277 | 280 | } |
| 278 | 281 | } |
| 279 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 282 | + if (!$this->newDoc && $this->givenPassword) {
|
|
| 280 | 283 | $this->invokeEvent('OnWebChangePassword', array( |
| 281 | 284 | 'userObj' => $this, |
| 282 | 285 | 'userid' => $this->id, |
@@ -287,7 +290,9 @@ discard block |
||
| 287 | 290 | ), $fire_events); |
| 288 | 291 | } |
| 289 | 292 | |
| 290 | - if (!empty($this->groupIds)) $this->setUserGroups($this->id, $this->groupIds); |
|
| 293 | + if (!empty($this->groupIds)) {
|
|
| 294 | + $this->setUserGroups($this->id, $this->groupIds); |
|
| 295 | + } |
|
| 291 | 296 | |
| 292 | 297 | $this->invokeEvent('OnWebSaveUser', array( |
| 293 | 298 | 'userObj' => $this, |
@@ -296,7 +301,7 @@ discard block |
||
| 296 | 301 | 'user' => $this->toArray() |
| 297 | 302 | ), $fire_events); |
| 298 | 303 | |
| 299 | - if ($clearCache) { |
|
| 304 | + if ($clearCache) {
|
|
| 300 | 305 | $this->clearCache($fire_events); |
| 301 | 306 | } |
| 302 | 307 | |
@@ -306,21 +311,22 @@ discard block |
||
| 306 | 311 | /** |
| 307 | 312 | * @param array $fld |
| 308 | 313 | */ |
| 309 | - protected function saveQuery(array &$fld) { |
|
| 310 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
| 314 | + protected function saveQuery(array &$fld) |
|
| 315 | + {
|
|
| 316 | + foreach ($this->default_field['attribute'] as $key => $value) {
|
|
| 311 | 317 | $tmp = $this->get($key); |
| 312 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 318 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 313 | 319 | $this->field[$key] = $value; |
| 314 | 320 | } |
| 315 | 321 | $this->Uset($key, 'attribute'); |
| 316 | 322 | unset($fld[$key]); |
| 317 | 323 | } |
| 318 | - if (!empty($this->set['attribute'])) { |
|
| 319 | - if ($this->newDoc) { |
|
| 324 | + if (!empty($this->set['attribute'])) {
|
|
| 325 | + if ($this->newDoc) {
|
|
| 320 | 326 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 321 | 327 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 322 | 328 | $this->set['attribute']); |
| 323 | - } else { |
|
| 329 | + } else {
|
|
| 324 | 330 | $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 325 | 331 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
| 326 | 332 | } |
@@ -333,9 +339,9 @@ discard block |
||
| 333 | 339 | * @param bool $fire_events |
| 334 | 340 | * @return bool|null|void |
| 335 | 341 | */ |
| 336 | - public function delete($ids, $fire_events = false) |
|
| 337 | - { |
|
| 338 | - if ($this->edit($ids)) { |
|
| 342 | + public function delete($ids, $fire_events = false) |
|
| 343 | + {
|
|
| 344 | + if ($this->edit($ids)) {
|
|
| 339 | 345 | $flag = $this->deleteQuery(); |
| 340 | 346 | $this->query("DELETE FROM {$this->makeTable('web_user_settings')} WHERE webuser='{$this->getID()}'"); |
| 341 | 347 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE webuser='{$this->getID()}'"); |
@@ -346,7 +352,7 @@ discard block |
||
| 346 | 352 | 'username' => $this->get('username'), |
| 347 | 353 | 'timestamp' => time() |
| 348 | 354 | ), $fire_events); |
| 349 | - } else { |
|
| 355 | + } else {
|
|
| 350 | 356 | $flag = false; |
| 351 | 357 | } |
| 352 | 358 | $this->close(); |
@@ -354,7 +360,8 @@ discard block |
||
| 354 | 360 | return $flag; |
| 355 | 361 | } |
| 356 | 362 | |
| 357 | - protected function deleteQuery() { |
|
| 363 | + protected function deleteQuery() |
|
| 364 | + {
|
|
| 358 | 365 | return $this->query(" |
| 359 | 366 | DELETE user,attribute FROM {$this->makeTable('web_user_attributes')} as attribute |
| 360 | 367 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -368,13 +375,13 @@ discard block |
||
| 368 | 375 | * @param bool $fire_events |
| 369 | 376 | * @return bool |
| 370 | 377 | */ |
| 371 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
| 372 | - { |
|
| 378 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
| 379 | + {
|
|
| 373 | 380 | $flag = false; |
| 374 | - if (null === $this->getID() && $id) { |
|
| 381 | + if (null === $this->getID() && $id) {
|
|
| 375 | 382 | $this->edit($id); |
| 376 | 383 | } |
| 377 | - if (null !== $this->getID()) { |
|
| 384 | + if (null !== $this->getID()) {
|
|
| 378 | 385 | $flag = true; |
| 379 | 386 | $this->save(false); |
| 380 | 387 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -394,10 +401,10 @@ discard block |
||
| 394 | 401 | * @param int $id |
| 395 | 402 | * @return bool |
| 396 | 403 | */ |
| 397 | - public function checkBlock($id = 0) |
|
| 398 | - { |
|
| 404 | + public function checkBlock($id = 0) |
|
| 405 | + {
|
|
| 399 | 406 | $tmp = clone $this; |
| 400 | - if ($id && $tmp->getID() != $id) { |
|
| 407 | + if ($id && $tmp->getID() != $id) {
|
|
| 401 | 408 | $tmp->edit($id); |
| 402 | 409 | } |
| 403 | 410 | $now = time(); |
@@ -418,17 +425,17 @@ discard block |
||
| 418 | 425 | * @param bool $fire_events |
| 419 | 426 | * @return bool |
| 420 | 427 | */ |
| 421 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 422 | - { |
|
| 428 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 429 | + {
|
|
| 423 | 430 | $tmp = clone $this; |
| 424 | - if ($id && $tmp->getID() != $id) { |
|
| 431 | + if ($id && $tmp->getID() != $id) {
|
|
| 425 | 432 | $tmp->edit($id); |
| 426 | 433 | } |
| 427 | 434 | |
| 428 | 435 | $flag = $pluginFlag = false; |
| 429 | 436 | if ( |
| 430 | 437 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
| 431 | - ) { |
|
| 438 | + ) {
|
|
| 432 | 439 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
| 433 | 440 | 'userObj' => $this, |
| 434 | 441 | 'userid' => $tmp->getID(), |
@@ -436,14 +443,14 @@ discard block |
||
| 436 | 443 | 'userpassword' => $password, |
| 437 | 444 | 'savedpassword' => $tmp->get('password') |
| 438 | 445 | ), $fire_events); |
| 439 | - if (is_array($eventResult)) { |
|
| 440 | - foreach ($eventResult as $result) { |
|
| 446 | + if (is_array($eventResult)) {
|
|
| 447 | + foreach ($eventResult as $result) {
|
|
| 441 | 448 | $pluginFlag = (bool)$result; |
| 442 | 449 | } |
| 443 | - } else { |
|
| 450 | + } else {
|
|
| 444 | 451 | $pluginFlag = (bool)$eventResult; |
| 445 | 452 | } |
| 446 | - if (!$pluginFlag) { |
|
| 453 | + if (!$pluginFlag) {
|
|
| 447 | 454 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
| 448 | 455 | } |
| 449 | 456 | } |
@@ -457,13 +464,13 @@ discard block |
||
| 457 | 464 | * @param string $cookieName |
| 458 | 465 | * @return bool |
| 459 | 466 | */ |
| 460 | - public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
| 461 | - { |
|
| 467 | + public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
| 468 | + {
|
|
| 462 | 469 | $flag = false; |
| 463 | - if (isset($_COOKIE[$cookieName])) { |
|
| 470 | + if (isset($_COOKIE[$cookieName])) {
|
|
| 464 | 471 | $cookie = explode('|', $_COOKIE[$cookieName], 4); |
| 465 | - if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
|
| 466 | - if (!$fulltime && isset($cookie[4])) { |
|
| 472 | + if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) {
|
|
| 473 | + if (!$fulltime && isset($cookie[4])) {
|
|
| 467 | 474 | $fulltime = (int)$cookie[4]; |
| 468 | 475 | } |
| 469 | 476 | $this->close(); |
@@ -475,7 +482,7 @@ discard block |
||
| 475 | 482 | && $this->get('password') == $cookie[1] |
| 476 | 483 | && $this->get('sessionid') == $cookie[2] |
| 477 | 484 | && !$this->checkBlock($this->getID()) |
| 478 | - ) { |
|
| 485 | + ) {
|
|
| 479 | 486 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
| 480 | 487 | |
| 481 | 488 | } |
@@ -489,9 +496,9 @@ discard block |
||
| 489 | 496 | * @param string $cookieName |
| 490 | 497 | * @param bool $fire_events |
| 491 | 498 | */ |
| 492 | - public function logOut($cookieName = 'WebLoginPE', $fire_events = false) |
|
| 493 | - { |
|
| 494 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
| 499 | + public function logOut($cookieName = 'WebLoginPE', $fire_events = false) |
|
| 500 | + {
|
|
| 501 | + if (!$uid = $this->modx->getLoginUserID('web')) {
|
|
| 495 | 502 | return; |
| 496 | 503 | } |
| 497 | 504 | $params = array( |
@@ -517,11 +524,11 @@ discard block |
||
| 517 | 524 | * |
| 518 | 525 | * remeber может быть числом в секундах |
| 519 | 526 | */ |
| 520 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 521 | - { |
|
| 522 | - switch ($directive) { |
|
| 527 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 528 | + {
|
|
| 529 | + switch ($directive) {
|
|
| 523 | 530 | case 'start': |
| 524 | - if ($this->getID() !== null) { |
|
| 531 | + if ($this->getID() !== null) {
|
|
| 525 | 532 | $_SESSION['webShortname'] = $this->get('username'); |
| 526 | 533 | $_SESSION['webFullname'] = $this->get('fullname'); |
| 527 | 534 | $_SESSION['webEmail'] = $this->get('email'); |
@@ -535,13 +542,13 @@ discard block |
||
| 535 | 542 | $_SESSION['webUsrConfigSet'] = array(); |
| 536 | 543 | $_SESSION['webUserGroupNames'] = $this->getUserGroups(); |
| 537 | 544 | $_SESSION['webDocgroups'] = $this->getDocumentGroups(); |
| 538 | - if (!empty($remember)) { |
|
| 545 | + if (!empty($remember)) {
|
|
| 539 | 546 | $this->setAutoLoginCookie($cookieName, $remember); |
| 540 | 547 | } |
| 541 | 548 | } |
| 542 | 549 | break; |
| 543 | 550 | case 'destroy': |
| 544 | - if (isset($_SESSION['mgrValidated'])) { |
|
| 551 | + if (isset($_SESSION['mgrValidated'])) {
|
|
| 545 | 552 | unset($_SESSION['webShortname']); |
| 546 | 553 | unset($_SESSION['webFullname']); |
| 547 | 554 | unset($_SESSION['webEmail']); |
@@ -557,8 +564,8 @@ discard block |
||
| 557 | 564 | unset($_SESSION['webDocgroups']); |
| 558 | 565 | |
| 559 | 566 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
| 560 | - } else { |
|
| 561 | - if (isset($_COOKIE[session_name()])) { |
|
| 567 | + } else {
|
|
| 568 | + if (isset($_COOKIE[session_name()])) {
|
|
| 562 | 569 | setcookie(session_name(), '', time() - 60, MODX_BASE_URL); |
| 563 | 570 | } |
| 564 | 571 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
@@ -573,8 +580,8 @@ discard block |
||
| 573 | 580 | /** |
| 574 | 581 | * @return bool |
| 575 | 582 | */ |
| 576 | - public function isSecure() |
|
| 577 | - { |
|
| 583 | + public function isSecure() |
|
| 584 | + {
|
|
| 578 | 585 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
| 579 | 586 | |
| 580 | 587 | return $out; |
@@ -585,9 +592,9 @@ discard block |
||
| 585 | 592 | * @param bool|integer $remember |
| 586 | 593 | * @return $this |
| 587 | 594 | */ |
| 588 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 589 | - { |
|
| 590 | - if (!empty($cookieName) && $this->getID() !== null) { |
|
| 595 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 596 | + {
|
|
| 597 | + if (!empty($cookieName) && $this->getID() !== null) {
|
|
| 591 | 598 | $secure = $this->isSecure(); |
| 592 | 599 | $remember = is_bool($remember) ? $this->getRememberTime() : (int)$remember; |
| 593 | 600 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -603,11 +610,11 @@ discard block |
||
| 603 | 610 | * @param int $userID |
| 604 | 611 | * @return array |
| 605 | 612 | */ |
| 606 | - public function getDocumentGroups($userID = 0) |
|
| 607 | - { |
|
| 613 | + public function getDocumentGroups($userID = 0) |
|
| 614 | + {
|
|
| 608 | 615 | $out = array(); |
| 609 | 616 | $user = $this->switchObject($userID); |
| 610 | - if (null !== $user->getID()) { |
|
| 617 | + if (null !== $user->getID()) {
|
|
| 611 | 618 | $web_groups = $this->modx->getFullTableName('web_groups'); |
| 612 | 619 | $webgroup_access = $this->modx->getFullTableName('webgroup_access'); |
| 613 | 620 | |
@@ -626,18 +633,18 @@ discard block |
||
| 626 | 633 | * @param int $userID |
| 627 | 634 | * @return array |
| 628 | 635 | */ |
| 629 | - public function getUserGroups($userID = 0) |
|
| 630 | - { |
|
| 636 | + public function getUserGroups($userID = 0) |
|
| 637 | + {
|
|
| 631 | 638 | $out = array(); |
| 632 | 639 | $user = $this->switchObject($userID); |
| 633 | - if (null !== $user->getID()) { |
|
| 640 | + if (null !== $user->getID()) {
|
|
| 634 | 641 | $web_groups = $this->makeTable('web_groups'); |
| 635 | 642 | $webgroup_names = $this->makeTable('webgroup_names'); |
| 636 | 643 | |
| 637 | 644 | $rs = $this->query("SELECT `ug`.`webgroup`, `ugn`.`name` FROM {$web_groups} as `ug` |
| 638 | 645 | INNER JOIN {$webgroup_names} as `ugn` ON `ugn`.`id`=`ug`.`webgroup` |
| 639 | 646 | WHERE `ug`.`webuser` = " . $user->getID()); |
| 640 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 647 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 641 | 648 | $out[$row['webgroup']] = $row['name']; |
| 642 | 649 | } |
| 643 | 650 | } |
@@ -651,18 +658,20 @@ discard block |
||
| 651 | 658 | * @param array $groupIds |
| 652 | 659 | * @return $this |
| 653 | 660 | */ |
| 654 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 655 | - { |
|
| 656 | - if (!is_array($groupIds)) return $this; |
|
| 657 | - if ($this->newDoc && $userID == 0) { |
|
| 661 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 662 | + {
|
|
| 663 | + if (!is_array($groupIds)) {
|
|
| 664 | + return $this; |
|
| 665 | + } |
|
| 666 | + if ($this->newDoc && $userID == 0) {
|
|
| 658 | 667 | $this->groupIds = $groupIds; |
| 659 | - } else { |
|
| 668 | + } else {
|
|
| 660 | 669 | $user = $this->switchObject($userID); |
| 661 | - if ($uid = $user->getID()) { |
|
| 662 | - foreach ($groupIds as $gid) { |
|
| 670 | + if ($uid = $user->getID()) {
|
|
| 671 | + foreach ($groupIds as $gid) {
|
|
| 663 | 672 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
| 664 | 673 | } |
| 665 | - if (!$this->newDoc) { |
|
| 674 | + if (!$this->newDoc) {
|
|
| 666 | 675 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 667 | 676 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
| 668 | 677 | } |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Class autoTable |
| 6 | 6 | */ |
| 7 | -abstract class autoTable extends MODxAPI |
|
| 8 | -{ |
|
| 7 | +abstract class autoTable extends MODxAPI |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var null |
| 11 | 11 | */ |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @return null |
| 20 | 20 | */ |
| 21 | - public function tableName() |
|
| 22 | - { |
|
| 21 | + public function tableName() |
|
| 22 | + {
|
|
| 23 | 23 | return $this->table; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -28,16 +28,16 @@ discard block |
||
| 28 | 28 | * @param DocumentParser $modx |
| 29 | 29 | * @param bool $debug |
| 30 | 30 | */ |
| 31 | - public function __construct($modx, $debug = false) |
|
| 32 | - { |
|
| 31 | + public function __construct($modx, $debug = false) |
|
| 32 | + {
|
|
| 33 | 33 | parent::__construct($modx, $debug); |
| 34 | - if (empty($this->default_field)) { |
|
| 34 | + if (empty($this->default_field)) {
|
|
| 35 | 35 | $data = $this->modx->db->getTableMetaData($this->makeTable($this->table)); |
| 36 | - foreach ($data as $item) { |
|
| 37 | - if (empty($this->pkName) && $item['Key'] == 'PRI') { |
|
| 36 | + foreach ($data as $item) {
|
|
| 37 | + if (empty($this->pkName) && $item['Key'] == 'PRI') {
|
|
| 38 | 38 | $this->pkName = $item['Field']; |
| 39 | 39 | } |
| 40 | - if ($this->pkName != $item['Field']) { |
|
| 40 | + if ($this->pkName != $item['Field']) {
|
|
| 41 | 41 | $this->default_field[$item['Field']] = $item['Default']; |
| 42 | 42 | } |
| 43 | 43 | } |
@@ -49,10 +49,10 @@ discard block |
||
| 49 | 49 | * @param $id |
| 50 | 50 | * @return $this |
| 51 | 51 | */ |
| 52 | - public function edit($id) |
|
| 53 | - { |
|
| 52 | + public function edit($id) |
|
| 53 | + {
|
|
| 54 | 54 | $id = is_scalar($id) ? trim($id) : ''; |
| 55 | - if ($this->getID() != $id) { |
|
| 55 | + if ($this->getID() != $id) {
|
|
| 56 | 56 | $this->close(); |
| 57 | 57 | $this->markAllEncode(); |
| 58 | 58 | $this->newDoc = false; |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | $this->fromArray($this->modx->db->getRow($result)); |
| 61 | 61 | $this->store($this->toArray()); |
| 62 | 62 | $this->id = $this->eraseField($this->pkName); |
| 63 | - if (is_bool($this->id) && $this->id === false) { |
|
| 63 | + if (is_bool($this->id) && $this->id === false) {
|
|
| 64 | 64 | $this->id = null; |
| 65 | - } else { |
|
| 65 | + } else {
|
|
| 66 | 66 | $this->decodeFields(); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -75,40 +75,39 @@ discard block |
||
| 75 | 75 | * @param bool $clearCache |
| 76 | 76 | * @return bool|null|void |
| 77 | 77 | */ |
| 78 | - public function save($fire_events = false, $clearCache = false) |
|
| 79 | - { |
|
| 80 | - foreach ($this->jsonFields as $field) { |
|
| 78 | + public function save($fire_events = false, $clearCache = false) |
|
| 79 | + {
|
|
| 80 | + foreach ($this->jsonFields as $field) {
|
|
| 81 | 81 | if ($this->get($field) === null |
| 82 | 82 | && isset($this->default_field[$field]) |
| 83 | - && is_array($this->default_field[$field])) |
|
| 84 | - { |
|
| 83 | + && is_array($this->default_field[$field])) {
|
|
| 85 | 84 | $this->set($field, $this->default_field[$field]); |
| 86 | 85 | } |
| 87 | 86 | } |
| 88 | 87 | $fld = $this->encodeFields()->toArray(); |
| 89 | - foreach ($this->default_field as $key => $value) { |
|
| 90 | - if ($this->newDoc && $this->get($key) === null && $this->get($key) !== $value) { |
|
| 88 | + foreach ($this->default_field as $key => $value) {
|
|
| 89 | + if ($this->newDoc && $this->get($key) === null && $this->get($key) !== $value) {
|
|
| 91 | 90 | $this->set($key, $value); |
| 92 | 91 | } |
| 93 | - if ((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null) { |
|
| 92 | + if ((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null) {
|
|
| 94 | 93 | $this->Uset($key); |
| 95 | 94 | } |
| 96 | 95 | unset($fld[$key]); |
| 97 | 96 | } |
| 98 | - if (!empty($this->set)) { |
|
| 99 | - if ($this->newDoc) { |
|
| 97 | + if (!empty($this->set)) {
|
|
| 98 | + if ($this->newDoc) {
|
|
| 100 | 99 | $SQL = "INSERT {$this->ignoreError} INTO {$this->makeTable($this->table)} SET " . implode(', ', |
| 101 | 100 | $this->set); |
| 102 | - } else { |
|
| 101 | + } else {
|
|
| 103 | 102 | $SQL = ($this->getID() === null) ? null : "UPDATE {$this->ignoreError} {$this->makeTable($this->table)} SET " . implode(', ', |
| 104 | 103 | $this->set) . " WHERE `" . $this->pkName . "` = " . $this->getID(); |
| 105 | 104 | } |
| 106 | 105 | $this->query($SQL); |
| 107 | - if ($this->newDoc) { |
|
| 106 | + if ($this->newDoc) {
|
|
| 108 | 107 | $this->id = $this->modx->db->getInsertId(); |
| 109 | 108 | } |
| 110 | 109 | } |
| 111 | - if ($clearCache) { |
|
| 110 | + if ($clearCache) {
|
|
| 112 | 111 | $this->clearCache($fire_events); |
| 113 | 112 | } |
| 114 | 113 | $this->decodeFields(); |
@@ -122,16 +121,16 @@ discard block |
||
| 122 | 121 | * @return $this |
| 123 | 122 | * @throws Exception |
| 124 | 123 | */ |
| 125 | - public function delete($ids, $fire_events = false) |
|
| 126 | - { |
|
| 124 | + public function delete($ids, $fire_events = false) |
|
| 125 | + {
|
|
| 127 | 126 | $_ids = $this->cleanIDs($ids, ','); |
| 128 | - if (is_array($_ids) && $_ids != array()) { |
|
| 127 | + if (is_array($_ids) && $_ids != array()) {
|
|
| 129 | 128 | $id = $this->sanitarIn($_ids); |
| 130 | - if (!empty($id)) { |
|
| 129 | + if (!empty($id)) {
|
|
| 131 | 130 | $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})"); |
| 132 | 131 | } |
| 133 | 132 | $this->clearCache($fire_events); |
| 134 | - } else { |
|
| 133 | + } else {
|
|
| 135 | 134 | throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre>'); |
| 136 | 135 | } |
| 137 | 136 | |