diff --git a/README.md b/README.md index 1f06112f34..85bb568ec9 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ Previous Releases: https://modx.com/download/evolution/previous-releases.html Extras: -https://extras.evolution-cms.com +https://extras.evo.im Documentation: +http://docs.evo.im https://evolution-docs.com diff --git a/assets/docs/changelog.txt b/assets/docs/changelog.txt index be3e4b2c10..b421d79090 100755 --- a/assets/docs/changelog.txt +++ b/assets/docs/changelog.txt @@ -1,6 +1,212 @@ This file shows the changes in recent releases of Evolution CMS. The most current release is usually the development release, and is only shown to give an idea of what's currently in the pipeline. + +Evolution CMS 1.4.7 (Dec 10, 2018) +* [GitHub:#92a15c0b6] - [fix] for php7: ddmultiplefields.php http://modx.im/blog/addons/4265.html#comment44232 (Dmi3yy) +* [GitHub:#fa8ba4219] - [fix] typo for 7.3 (Dmi3yy) +* [GitHub:#e132703e4] - [fix] phpthumb to 1.3.3 (Agel_Nash) +* [GitHub:#116f383be] - [fix] Php Thumb image cache path #896 (Nicola) +* [GitHub:#e4ef60a24] - [fix] Undefined index (Agel_Nash) +* [GitHub:#24bd8dd49] - [fix] Save module name and code, if module exist (issue #892) (Serg) +* [GitHub:#4afe71703] - [fix] Form attribute "action" fixes (issue #892) (Serg) +* [GitHub:#e88614d3c] - [fix] #892 duplicated element name issue (Serg) +* [GitHub:#e194b6b59] - [fix] sort modules by name (#887) (Nicola) +* [GitHub:#288a6f96b] - [fix] sort elements by name (#887) (Nicola) +* [GitHub:#e353554f3] - [fix] #888 The FileSource 0.1 is dependent on the mootools (Serg) +* [GitHub:#c5b019ca9] - [fix] #874 Remove fullstop at end of new password displayed on screen(Serg) +* [GitHub:#24eaa5a3d] - [Fix] #882 broken extras module link in RSS check (Nicola) +* [GitHub:#f644a6b1e] - [fix] #869 (missing 1 lexicon) (Agel_Nash) +* [GitHub:#30f27489c] - [fix] update ElementsInTree 1.5.10 (Agel_Nash) +* [GitHub:#403e590d1] - [fix] Update DocInfo and DocLister (Agel_Nash) +* [GitHub:#aa5086c01] - [improvement]colorpicker added (mnoskov) +* [GitHub:#eb2e24936] - [improvement] Enable Mootools Setting Option (Nicola) +* [GitHub:#d4200c3f2] - [improvement] rename extras.evolution-cms.com to extras.evo.im (Dmi3yy) +* [GitHub:#cadb97e2a] - [typo] format code save_user_processor (Serg) +* [GitHub:#d9b8e3c84] - [typo] fix typo in color mode name (Nicola) +* [GitHub:#8130c764c] - [typo] code tag for singleton example (Nicola) +* [GitHub:#91e36991d] - [delete] deprecated snippet DLBuildMenu (Pathologic) +* [GitHub:#a97b1b5f7] - [info] Update 1.4.7 Version Noticies (help) (Nicola) +* [GitHub:#9a174d0b2] - [info] 1.4.6 Version Noticies (help) (Nicola) +* [GitHub:#9e209b4ef] - [info] 1.4.5 Version Noticies (help) (Nicola) +* [GitHub:#bdce11559] - [info] 1.4.4 Version Noticies (help) (Nicola) +* [GitHub:#fd5dfab2c] - [info] 1.4.3 Version Noticies (help) (Nicola) +* [GitHub:#918a14bab] - [info] 1.4.2 Version Noticies (help) (Nicola) +* [GitHub:#a9830af28] - [lang] Polish translation (#891) (Piotr Matysiak) +* [GitHub:#640eea798] - [lang] Updated Italian Language (#861) (Nicola) +* [GitHub:#c28388868] - [lang] Resolve #869 (Agel_Nash) +* [GitHub:#c443927e4] - [lang] #859 (missing 6 manager, 2 installer) https://github.com/evolution-cms/evolution/issues/853#issuecomment-435479192 (Agel_Nash) + + +Evolution CMS 1.4.6 (Nov 02, 2018) +* [GitHub:#3d445623f] - OutdatedExtrasCheck add url for check Outdated (Dmi3yy) +* [GitHub:#4265bc48e] - Исправлена бага. Если создать ресурс через modResource и получить для него урл и Использовать AliasListing только для Папок [(aliaslistingfolder)] стояло Да то получал /{doc_id}.html вместо нормального урла (dzhuryn) +* [GitHub:#bad13152e] - Исправлена бага. Если создать ресурс через modResource и получить для него урл то в место /proizvoditeli/proizvoditel_1541140716/kolekciya_1541140716/tovar_1541140716.html получал /tovar_1541140716.html из за отсутствия alias_visible (dzhuryn) +* [GitHub:#9aa1c9369] - Remove debug (Agel_Nash) +* [GitHub:#c7cd2ccce] - Update OutdatedExtrasCheck (Agel_Nash) +* [GitHub:#d232ae622] - fix existes GET[q] (Serg) +* [GitHub:#d5827b63c] - moved menu item version in config menu (Serg) +* [GitHub:#cfbe776cd] - Code refactoring the OutdatedExtrasCheck plugin (Agel_Nash) +* [GitHub:#c0a82df48] - Update the OutdatedExtrasCheck lexicon (Agel_Nash) +* [GitHub:#e3d08940d] - Reformat source code the OutdatedExtrasCheck plugin (Agel_Nash) +* [GitHub:#5b837b592] - Up version OutdatedExtrasCheck (Agel_Nash) +* [GitHub:#31e1e651c] - Move source code the OutdatedExtrasCheck plugin into file (Agel_Nash) +* [GitHub:#907a44ea2] - Resolve #845 (Agel_Nash) +* [GitHub:#0a902dab3] - remove redundant property (Pathologic) +* [GitHub:#a23c162bc] - DocLister 2.4.0 (Agel_Nash) +* [GitHub:#ad905490f] - update Filters.php (Pathologic) +* [GitHub:#e5da5675c] - change PHP version in lexicons (Pathologic) +* [GitHub:#a315fe63f] - remove dot from password output (Pathologic) +* [GitHub:#faba1ef7a] - update FormLister to 1.8.0 (Pathologic) +* [GitHub:#917cdb6f9] - Relation to #876 (Agel_Nash) +* [GitHub:#57682bc13] - Refactor the send_errormail cell (Agel_Nash) +* [GitHub:#811f5903b] - #868 (Installer + Update date) (Agel_Nash) +* [GitHub:#11aad77cb] - Polish translations (Manager) (Piotr Matysiak) +* [GitHub:#39654dc2a] - Polish translations (Installer) (Piotr Matysiak) +* [GitHub:#49343d989] - Rename "Создать PHP-файл" to "Создать файл" (#872) (Ser1ous) +* [GitHub:#31ace520a] - Resolve #868 (Agel_Nash) +* [GitHub:#c3ddd2228] - Remove duplicate lexicon (Agel_Nash) +* [GitHub:#c907375de] - Replacing div to pre at the messageQuit method (Agel_Nash) +* [GitHub:#0442323ea] - Fix #825 (Agel_Nash) +* [GitHub:#2e247bfd9] - errorHandlers (Agel_Nash) +* [GitHub:#4d5566bb1] - Resolve #792 (Agel_Nash) +* [GitHub:#343ff4070] - Update phpthumb snippet (Agel_Nash) +* [GitHub:#6aea8b048] - phpthumb 1.7.15 (Agel_Nash) +* [GitHub:#a233a3ff6] - Update DL for compability https://github.com/evolution-cms/evolution/commit/49fab5242971a42eb225c3186238d5649f2e328e (Agel_Nash) +* [GitHub:#f1b0d559b] - fix JS event for radio[chunk_processor] (Serg) +* [GitHub:#de24eaa3f] - add JS event for radio[chunk_processor] (Serg) +* [GitHub:#dc02ce968] - MM removed unused script Tips (Serg) +* [GitHub:#64fccfefa] - fix #818 (Serg) +* [GitHub:#b59bc534d] - fix ip lenght for work with ipw6 #849 (#850) (Ser1ous) +* [GitHub:#49fab5242] - Fix #848 (Agel_Nash) +* [GitHub:#81e10ea54] - Fix #280 (Agel_Nash) +* [GitHub:#2ffdb4e68] - #834 (Agel_Nash) +* [GitHub:#ca4cb5498] - Fix #834 (Agel_Nash) +* [GitHub:#fcc2024e4] - addOutput method (Agel_Nash) +* [GitHub:#c57a5d844] - FIX Lighness Navbar Logo (#827) (Nicola) +* [GitHub:#ada15c795] - event reference fix (#844) (mnoskov) +* [GitHub:#99ba335ac] - fix style loginform in dark mode (Serg) +* [GitHub:#07ca6dea6] - remove mootools.js (Serg) +* [GitHub:#7043a5321] - fix sysalert.display.inc.php (Serg) +* [GitHub:#c2b01a5a6] - fix popup.wrap (Serg) +* [GitHub:#3f846155d] - phpMailer update to 6.0.5 (Dmi3yy) +* [GitHub:#47011d823] - up ajaxSearch version to 1.12.0 in OutdatedExtrasCheck (Dmi3yy) +* [GitHub:#402a5e99d] - Fix #806 (Agel_Nash) +* [GitHub:#3261911f4] - Update snippet.docinfo.php (#806) (Anton Kanopkin) +* [GitHub:#ab1c9ec5a] - events stack (mnoskov) +* [GitHub:#1e59390d4] - events stack (mnoskov) +* [GitHub:#3d15cb1c7] - removing debug statement (Agel_Nash) +* [GitHub:#05a80d9f8] - Fix JS error – typo (esszett) +* [GitHub:#e8025d501] - Fix #26 (Agel_Nash) +* [GitHub:#be22213f0] - Change checking of manager mode / Part 2 (Agel_Nash) +* [GitHub:#46eaa39e6] - Resolve review in PR #779 (Agel_Nash) +* [GitHub:#e4231e872] - Fix #793 (Agel_Nash) +* [GitHub:#3c5aa9b8a] - Fix #828 (Agel_Nash) +* [GitHub:#270ae36c5] - Fix mysql 8.0 bug with copy tv #809 (Ser1ous) +* [GitHub:#615841010] - Refactoring DocumentParser::getHiddenIdFromAlias() (Agel_Nash) +* [GitHub:#6fa6950f0] - Fix #790 (Agel_Nash) +* [GitHub:#1684460b4] - Fix #784 (Agel_Nash) +* [GitHub:#af38bca42] - Fix #797 (Agel_Nash) +* [GitHub:#288068bb1] - Fix #535 (Agel_Nash) +* [GitHub:#27dce74cc] - resolve #819 (Agel_Nash) +* [GitHub:#0ca34ccf0] - improved loginbox styles (Nicola) +* [GitHub:#082db9992] - Update tree.php (Mr B) +* [GitHub:#9a956458d] - [I] Add title for theme mode icon (Mr B) +* [GitHub:#5abf6da33] - fix style on login light (Nicola) +* [GitHub:#4e9a12007] - wrong position (Nicola) +* [GitHub:#c824e55f1] - manager_theme_mode_message #818 (Nicola) +* [GitHub:#cc47a7c1c] - fix light login styles (Nicola) +* [GitHub:#128e35b88] - fix light login fields (Nicola) +* [GitHub:#9d2a81ada] - Updated extrascheck plugin v1.4.5 (Nicola) +* [GitHub:#f4e8d1b76] - Login form style Settings #800 (Nicola) +* [GitHub:#f786a4180] - [F] Fix unable to uncheck permissions (Mr B) +* [GitHub:#9799c7e13] - fix browser resize issues of kcfinder (Pathologic) +* [GitHub:#5471839a9] - fix escape name components (Serg) +* [GitHub:#f4632e571] - fix escape for widget docs (Serg) +* [GitHub:#f6d50671e] - fix escape search result (Serg) +* [GitHub:#9201cd8ea] - fix view svg (Serg) +* [GitHub:#f99b291dd] - Update search.static.php (luigif) +* [GitHub:#373c31cfe] - Update search.static.php (luigif) +* [GitHub:#bc457c79a] - Rename 01About_EVO.php to 01About_Title.php (luigif) +* [GitHub:#6385ac4ba] - Update mutate_categories.dynamic.php (luigif) +* [GitHub:#841ac1ff9] - fix not working clientResize option (Pathologic) +* [GitHub:#473725d08] - fixed #794 (Serg) +* [GitHub:#dc005e5cd] - fix #794 (Serg) +* [GitHub:#85094c9e5] - fix #780 (Serg) +* [GitHub:#149fdb0a2] - Revert "fix #792" (Serg) +* [GitHub:#86eebdd5c] - fix #792 (Serg) +* [GitHub:#a176c043e] - fix notice php7 (Serg) +* [GitHub:#8e30682a4] - Fix some XSS (Agel_Nash) +* [GitHub:#a7fe1cfbc] - Security Fix (Agel_Nash) +* [GitHub:#b59d1f57b] - Fix #789 (Agel_Nash) +* [GitHub:#2b8aaa622] - Fix #788 (Agel_Nash) +* [GitHub:#1845b64b2] - html_escape function (Agel_Nash) +* [GitHub:#79edb9ef5] - Change checking of manager mode (thalegion) + + +Evolution CMS 1.4.5 (Aug 07, 2018) +* [GitHub:#18627a876] - [F] fix #693 Drag/drop sortable lists (Serg) +* [GitHub:#9cdf9e173] - [F] fix #770 Restyle manager lockout page (Serg) +* [GitHub:#c4a06df62] - [F] fix tree update "Save and Quit" (Serg) +* [GitHub:#f11a627fb] - [I] add file browser events (Pathologic) +* [GitHub:#6ef91bc82] - [I] add more events (Pathologic) +* [GitHub:#618f4313f] - [F] fix #692 Manager left menu charset issue (dmi3yy) +* [GitHub:#a6fc60de7] - [F] fix #755 cookie context and lifetime (dmi3yy) +* [GitHub:#08aad4482] - [F] fix doclister (Pathologic) +* [GitHub:#b219ec85e] - [I] add support mysql 8.0 (Ser1ous) +* [GitHub:#6198dc5ac] - [F] fix #624 Issues for manager with no 'Interface Access' setting (Pathologic) +* [GitHub:#a1c3d37ab] - [F] fix #769 plugin settings get lost while upgrading to newer version (Pathologic) +* [GitHub:#26a430eb6] - [F] fix #730 Retain Plugin Event Execution Order When Upgrading (Pathologic) +* [GitHub:#c8080596b] - [F] update FormLister to 1.7.21 (Pathologic) +* [GitHub:#db41ba731] - [F] fix #767 Web Users not showing in Online Users (Pathologic) +* [GitHub:#747985a47] - [F] fix #368 problem with dublicete snippet (Pathologic) +* [GitHub:#a0c7f264c] - [F] fix for work with mysql 8.0 (Ser1ous) +* [GitHub:#04863cd88] - [I] Update mutate_user.dynamic.php (Mr B) +* [GitHub:#83550c437] - [I] Add username label (Mr B) +* [GitHub:#3130df11c] - [F] fix memory leak (Pathologic) +* [GitHub:#61cd0c0eb] - [F] fix #763 Evolution 1.4.5RC2 Does not work logo replacement(Serg) +* [GitHub:#3bed43eb9] - [F] fix text color in darkness mode (Serg) +* [GitHub:#196e815be] - [F] Fix saving web users (Mr B) +* [GitHub:#841db700d] - [F] fix #552 Weird Chunk Rendering When minifyphp_incache is enabled (Pathologic) +* [GitHub:#ce83e5411] - [F] fix checkVersion (Pathologic) +* [GitHub:#7626ccfbd] - [I] update FormLister (Pathologic) +* [GitHub:#553ff5332] - [F] fix #519 2 functions parseProperties (Pathologic) +* [GitHub:#b637d20ce] - [F] fix #556 Cli mode (Pathologic) +* [GitHub:#86ecaec70] - [F] fix #300 OnDocPublished add automatic start (Pathologic) +* [GitHub:#ac3033f12] - [F] fix #233 Disabling function touch generates error "Cannot access or create thumbnails folder." in media manager (Pathologic) +* [GitHub:#5223b3ab4] - [I] alter recent info table (Mr B) +* [GitHub:#d753660e0] - [I] add OnFileBrowserInit event (Pathologic) +* [GitHub:#5e0a3510f] - [F] fix #749 not bloced user (Serg) +* [GitHub:#5af0c3c4f] - [I] cancel close tabs for components (Serg) +* [GitHub:#b8a27cad0] - [F] fix #758 modxlink plugin (Pathologic) +* [GitHub:#3db936dab] - [I] events of directory delete (Pathologic) +* [GitHub:#57da95fee] - [F] fix #736 backup button back into the dashboard (dmi3yy) +* [GitHub:#63b229bf3] - [F] fix #750 tinymce 4 - link to images folder, not only to files (Pathologic) +* [GitHub:#3032cd717] - [I] stop username wrap if has spaces (Mr B) +* [GitHub:#f3639c642] - [F] Fix saving web user permissions (Mr B) +* [GitHub:#8e083becb] - [I] add File Browser events, skip thumbnails creation (Pathologic) +* [GitHub:#471b9e41a] - [I] add more File Browser events (Pathologic) +* [GitHub:#8ad6402a6] - [F] Fix #737 (Serg) +* [GitHub:#4a1f6972d] - [I] Update mainmenu.css (Mr B) +* [GitHub:#bc539c054] - [I] Update style.php (Mr B) +* [GitHub:#7132beb6b] - [I] Add time to dashboard resource edit dates (Mr B) +* [GitHub:#118f69e47] - [R] russian-UTF8.inc.php #728 (Agel_Nash) +* [GitHub:#62285b7b4] - [R] Update english.inc.php (Mr B) +* [GitHub:#d5d170404] - [I] Add confirmation for purge plugins (Mr B) +* [GitHub:#4143fea6b] - [F] remove docs from core FormLister #366 (dmi3yy) +* [GitHub:#3d178f654] - [F] fix #727 Ampersand (&) in Site Name escaped infinitely (Serg) +* [GitHub:#b5b88d912] - [F] Save and close global tabs (Serg) +* [GitHub:#239fda8a2] - [F] Fix html (Serg) +* [GitHub:#4d909750f] - [F] fix validator in FormLister (dmi3yy) +* [GitHub:#44ff0ff10] - [F] Fix #722 Issues with managing users (Serg) +* [GitHub:#9a64f25aa] - [F] Fix style left-menu position (Serg) +* [GitHub:#51f9102e0] - [F] Fix theme ajax.php (Serg) +* [GitHub:#3eda7b7d6] - [F] Fix add images in settings (Serg) +* [GitHub:#005993658] - [F] Fix notice variables (Serg) +* [GitHub:#952c85d0a] - [I] Action name for dashboard (Mr B) +* [GitHub:#25140784a] - [I] Add date to active users hit time (Mr B) + + Evolution CMS 1.4.4 (Jun 08, 2018) * [GitHub:#5d177a4ea] - [I] Auto set Sender (Евгений Борисов) * [GitHub:#f13d19d60] - [I] Move color switcher icon (Mr B) diff --git a/assets/lib/APIHelpers.class.php b/assets/lib/APIHelpers.class.php index f03d058373..c387279bc8 100644 --- a/assets/lib/APIHelpers.class.php +++ b/assets/lib/APIHelpers.class.php @@ -80,7 +80,7 @@ public static function getkey($data, $key, $default = null, $validate = null) if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) { $out = $data[$key]; } - if (!empty($validate) && is_callable($validate)) { + if (! empty($validate) && is_callable($validate)) { $out = (($validate($out) === true) ? $out : $default); } return $out; @@ -94,14 +94,14 @@ public static function getkey($data, $key, $default = null, $validate = null) * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html * @param string $email проверяемый email * @param boolean $dns проверять ли DNS записи - * @return boolean Результат проверки почтового ящика + * @return boolean|string Результат проверки почтового ящика * @author Anton Shevchuk */ public static function emailValidate($email, $dns = true) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { list(, $domain) = explode("@", $email, 2); - if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) { + if (! $dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) { $error = false; } else { $error = 'dns'; @@ -232,7 +232,7 @@ public static function getUserIP($default = '127.0.0.1') case ($tmp = self::getEnv('HTTP_X_FORWARDED_FOR')): $out = $tmp; break; - case (!empty($_SERVER['REMOTE_ADDR'])): + case (! empty($_SERVER['REMOTE_ADDR'])): $out = $_SERVER['REMOTE_ADDR']; break; default: @@ -270,13 +270,14 @@ public static function sanitarTag( $out = str_replace( array_keys($chars), array_values($chars), - is_null($charset) ? $data : self::e($data, $charset) + $charset === null ? $data : self::e($data, $charset) ); break; case is_array($data): - $out = $data; - foreach ($out as $key => &$val) { - $val = self::sanitarTag($val, $charset, $chars); + $out = array(); + foreach ($data as $key => $val) { + $key = self::sanitarTag($key, $charset, $chars); + $out[$key] = self::sanitarTag($val, $charset, $chars); } break; default: @@ -402,9 +403,7 @@ public static function cleanIDs($IDs, $sep = ',', $ignore = array()) foreach ($IDs as $item) { $item = trim($item); if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff - if (!empty($ignore) && in_array((int)$item, $ignore, true)) { - $this->log[] = 'Ignore id ' . (int)$item; - } else { + if (empty($ignore) || !\in_array((int)$item, $ignore, true)) { $out[] = (int)$item; } } diff --git a/assets/lib/Formatter/CSSMinify.php b/assets/lib/Formatter/CSSMinify.php old mode 100755 new mode 100644 index 821aa813d6..1f72c60fd5 --- a/assets/lib/Formatter/CSSMinify.php +++ b/assets/lib/Formatter/CSSMinify.php @@ -6,7 +6,7 @@ class CSSMinify public function __construct($cssFilesPath = array()) { - if (is_array($cssFilesPath) && !empty($cssFilesPath)) { + if (is_array($cssFilesPath) && ! empty($cssFilesPath)) { $this->cssPath = $cssFilesPath; } } diff --git a/assets/lib/Formatter/SqlFormatter.php b/assets/lib/Formatter/SqlFormatter.php index ccc0a96365..50f795cbf2 100644 --- a/assets/lib/Formatter/SqlFormatter.php +++ b/assets/lib/Formatter/SqlFormatter.php @@ -834,7 +834,7 @@ protected static function getNextToken($string, $previous = null) } // Non-quoted variable name else { preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches); - if (!empty($matches)) { + if (! empty($matches)) { $ret[self::TOKEN_VALUE] = $matches[1]; } } @@ -863,7 +863,7 @@ protected static function getNextToken($string, $previous = null) // A reserved word cannot be preceded by a '.' // this makes it so in "mytable.from", "from" is not considered a reserved word - if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { + if (! $previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') { $upper = strtoupper($string); // Top Level Reserved Word if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper, @@ -1158,7 +1158,7 @@ public static function format($string, $highlight = true) $return = rtrim($return, ' '); } - if (!$inline_parentheses) { + if (! $inline_parentheses) { $increase_block_indent = true; // Add a newline after the parentheses $newline = true; @@ -1191,7 +1191,7 @@ public static function format($string, $highlight = true) } // Add a newline before the closing parentheses (if not already added) - if (!$added_newline) { + if (! $added_newline) { $return .= "\n" . str_repeat($tab, $indent_level); } } // Top level reserved words start a new line and increase the special indent level @@ -1208,7 +1208,7 @@ public static function format($string, $highlight = true) // Add a newline after the top level reserved word $newline = true; // Add a newline before the top level reserved word (if not already added) - if (!$added_newline) { + if (! $added_newline) { $return .= "\n" . str_repeat($tab, $indent_level); } // If we already added a newline, redo the indentation since it may be different now else { @@ -1222,14 +1222,14 @@ public static function format($string, $highlight = true) $highlighted = preg_replace('/\s+/', ' ', $highlighted); } //if SQL 'LIMIT' clause, start variable to reset newline - if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) { + if ($token[self::TOKEN_VALUE] === 'LIMIT' && ! $inline_parentheses) { $clause_limit = true; } } // Checks if we are out of the limit clause elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) { $clause_limit = false; } // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause) - elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) { + elseif ($token[self::TOKEN_VALUE] === ',' && ! $inline_parentheses) { //If the previous TOKEN_VALUE is 'LIMIT', resets new line if ($clause_limit === true) { $newline = false; @@ -1241,7 +1241,7 @@ public static function format($string, $highlight = true) } // Newline reserved words start a new line elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) { // Add a newline before the reserved word (if not already added) - if (!$added_newline) { + if (! $added_newline) { $return .= "\n" . str_repeat($tab, $indent_level); } @@ -1335,7 +1335,7 @@ public static function splitQuery($string) foreach ($tokens as $token) { // If this is a query separator if ($token[self::TOKEN_VALUE] === ';') { - if (!$empty) { + if (! $empty) { $queries[] = $current_query . ';'; } $current_query = ''; @@ -1351,7 +1351,7 @@ public static function splitQuery($string) $current_query .= $token[self::TOKEN_VALUE]; } - if (!$empty) { + if (! $empty) { $queries[] = trim($current_query); } diff --git a/assets/lib/Helpers/Assets.php b/assets/lib/Helpers/Assets.php old mode 100755 new mode 100644 index 73829d61f8..3e4f5efd83 --- a/assets/lib/Helpers/Assets.php +++ b/assets/lib/Helpers/Assets.php @@ -12,8 +12,10 @@ class AssetsHelper * @var \DocumentParser * @access protected */ - protected $modx = null; - protected $fs = null; + protected $modx; + + /** @var \Helpers\FS */ + protected $fs; /** * @var AssetsHelper cached reference to singleton instance @@ -52,7 +54,6 @@ private function __construct(DocumentParser $modx) */ private function __clone() { - } /** @@ -62,7 +63,6 @@ private function __clone() */ private function __wakeup() { - } /** @@ -94,12 +94,12 @@ public function registerJQuery() public function registerScript($name, $params) { $out = ''; - if (!isset($this->modx->loadedjscripts[$name])) { + if (! isset($this->modx->loadedjscripts[$name])) { $src = $params['src']; - $remote = strpos($src, "http") !== false; - if (!$remote) { + $remote = strpos($src, 'http') === 0 || strpos($src, '//') === 0; + if (! $remote) { $src = $this->modx->config['site_url'] . $src; - if (!$this->fs->checkFile($params['src'])) { + if (! $this->fs->checkFile($params['src'])) { $this->modx->logEvent(0, 3, 'Cannot load ' . $src, 'Assets helper'); return $out; @@ -116,7 +116,6 @@ public function registerScript($name, $params) } $this->modx->loadedjscripts[$name] = $params; - } return $out; @@ -129,7 +128,9 @@ public function registerScript($name, $params) public function registerScriptsList($list = array()) { $out = ''; - if (!is_array($list)) return $out; + if (! \is_array($list)) { + return $out; + } foreach ($list as $script => $params) { $out .= $this->registerScript($script, $params); diff --git a/assets/lib/Helpers/Collection.php b/assets/lib/Helpers/Collection.php index a68ddc370f..fbae59571c 100644 --- a/assets/lib/Helpers/Collection.php +++ b/assets/lib/Helpers/Collection.php @@ -93,7 +93,7 @@ public function partition(Closure $p) /** * @param $offset - * @param null $length + * @param null|int $length * @return array */ public function slice($offset, $length = null) @@ -132,7 +132,7 @@ public function append($value) /** * @param $data - * @param null $id + * @param null|int|string $id * @return $this */ public function add($data, $id = null) @@ -280,10 +280,13 @@ public function offsetGet($offset) */ public function offsetSet($offset, $value) { - if (! isset($offset)) { - return $this->add($value); + if ($offset !== null) { + $this->set($offset, $value); + } else { + $this->add($value); } - $this->set($offset, $value); + + return $this; } /** diff --git a/assets/lib/Helpers/Config.php b/assets/lib/Helpers/Config.php index e8166c2187..f82b5367ec 100644 --- a/assets/lib/Helpers/Config.php +++ b/assets/lib/Helpers/Config.php @@ -10,7 +10,8 @@ class Config { private $_cfg = array(); - protected $fs = null; + /** @var FS */ + protected $fs; protected $path = ''; /** @@ -20,7 +21,7 @@ class Config */ public function __construct($cfg = array()) { - if (!empty($cfg)) { + if (! empty($cfg)) { $this->setConfig($cfg); } $this->fs = FS::getInstance(); @@ -69,7 +70,9 @@ public function loadConfig($name) if ($this->fs->checkFile($configFile)) { $json = file_get_contents(MODX_BASE_PATH . $configFile); - $config = array_merge($config, jsonHelper::jsonDecode($json, array('assoc' => true), true)); + /** @var array $json */ + $json = jsonHelper::jsonDecode($json, array('assoc' => true), true); + $config = array_merge($config, $json); } } @@ -90,7 +93,7 @@ public function getConfig() /** * Сохранение массива настроек * @param array $cfg массив настроек - * @return int результат сохранения настроек + * @return int|bool результат сохранения настроек */ public function setConfig($cfg, $overwrite = false) { @@ -106,7 +109,7 @@ public function setConfig($cfg, $overwrite = false) /** * @param $name - * @param null $def + * @param mixed $def * @return mixed */ public function getCFGDef($name, $def = null) diff --git a/assets/lib/Helpers/FS.php b/assets/lib/Helpers/FS.php old mode 100755 new mode 100644 index 67310ae852..3c8db115db --- a/assets/lib/Helpers/FS.php +++ b/assets/lib/Helpers/FS.php @@ -107,7 +107,7 @@ public function takeFileName($file) /** * @param $file - * @param bool $lower + * @param bool $lower * @return string */ public function takeFileExt($file, $lower = true) @@ -127,7 +127,7 @@ public function checkFile($file) { $f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : ''; - return (!empty($f) && is_file($f) && is_readable($f)); + return (! empty($f) && is_file($f) && is_readable($f)); } /** @@ -138,7 +138,7 @@ public function checkDir($path) { $f = is_scalar($path) ? $this->relativePath($path) : ''; - return (!empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)); + return (! empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)); } /** @@ -152,14 +152,14 @@ public function fileSize($file, $format = false) if ($this->checkFile($file)) { $out = filesize(MODX_BASE_PATH . $this->relativePath($file)); } - + if($format === true) $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); if (is_array($format)) { $size = $out > 0 ? floor(log($out, 1024)) : 0; $type = isset($format[$size]) ? ' '.$format[$size] : ''; $out = number_format($out / pow(1024, $size), 2, '.', ',') . $type; } - + return $out; } @@ -228,7 +228,7 @@ public function takeFileMIME($file) */ public function makeDir($path, $perm = 0755) { - if (!$this->checkDir($path)) { + if (! $this->checkDir($path)) { $path = MODX_BASE_PATH . $this->relativePath($path); $flag = mkdir($path, $this->toOct($perm), true); } else { diff --git a/assets/lib/Helpers/Mailer.php b/assets/lib/Helpers/Mailer.php index 397fa01b4f..c4ab8c7630 100644 --- a/assets/lib/Helpers/Mailer.php +++ b/assets/lib/Helpers/Mailer.php @@ -17,8 +17,8 @@ class Mailer /** * @var MODxMailer $mail */ - protected $mail = null; - protected $modx = null; + protected $mail; + protected $modx; public $config = array(); protected $debug = false; protected $queuePath = 'assets/cache/mail/'; @@ -43,7 +43,7 @@ public function __construct(DocumentParser $modx, $cfg, $debug = false) { $this->modx = $modx; $this->noemail = (bool)(isset($cfg['noemail']) ? $cfg['noemail'] : 0); - if (!$this->noemail) { + if (! $this->noemail) { $this->mail = new MODxMailer(); if (method_exists('MODxMailer', 'init')) { $this->mail->init($modx); @@ -61,7 +61,7 @@ public function __construct(DocumentParser $modx, $cfg, $debug = false) */ public function addAddressToMailer($type, $addr) { - if (!$this->noemail && !empty($addr)) { + if (! $this->noemail && ! empty($addr)) { $a = array_filter(array_map('trim', explode(',', $addr))); foreach ($a as $address) { switch ($type) { @@ -89,7 +89,7 @@ public function addAddressToMailer($type, $addr) */ public function attachFiles($filelist = array()) { - if (!$this->noemail) { + if (! $this->noemail) { $contentType = "application/octetstream"; foreach ($filelist as $file) { if (is_file($file['filepath']) && is_readable($file['filepath'])) { @@ -108,7 +108,7 @@ public function attachFiles($filelist = array()) public function send($report) { //если отправлять некуда или незачем, то делаем вид, что отправили - if (!$this->getCFGDef('to') || $this->noemail) { + if (! $this->getCFGDef('to') || $this->noemail) { return true; } elseif (empty($report)) { return false; @@ -127,12 +127,12 @@ public function send($report) /** * @param $report - * @return bool + * @return bool|string */ public function toQueue($report) { //если отправлять некуда или незачем, то делаем вид, что отправили - if (!$this->getCFGDef('to') || $this->noemail) { + if (! $this->getCFGDef('to') || $this->noemail) { return true; } elseif (empty($report)) { return false; @@ -165,7 +165,7 @@ public function toQueue($report) */ public function setQueuePath($path = '') { - if (!empty($path)) { + if (! empty($path)) { $this->queuePath = $path; return true; } else { diff --git a/assets/lib/Helpers/PHPThumb.php b/assets/lib/Helpers/PHPThumb.php index 508c892406..98fc1b482f 100644 --- a/assets/lib/Helpers/PHPThumb.php +++ b/assets/lib/Helpers/PHPThumb.php @@ -10,8 +10,10 @@ class PHPThumb { - private $thumb = null; - protected $fs = null; + /** @var \phpthumb */ + private $thumb; + /** @var FS */ + protected $fs; public $debugMessages = ''; /** diff --git a/assets/lib/Helpers/Video.php b/assets/lib/Helpers/Video.php index 315826d144..842c920b36 100644 --- a/assets/lib/Helpers/Video.php +++ b/assets/lib/Helpers/Video.php @@ -90,7 +90,7 @@ class Video */ public function __construct($link = null, $autostart = true, $info = false) { - if (!empty($link)) { + if (! empty($link)) { $this->setLink($link); $this->setInfo($info); if ($autostart) { @@ -181,10 +181,10 @@ public function setLink($link) /** Обработка ссылки. Возвращает идентификатор видеохостинга или false */ public function process($link = null, $info = null) { - if (!empty($link)) { + if (! empty($link)) { $this->setLink($link); } - if (!empty($info)) { + if (! empty($info)) { $this->setInfo($info); } @@ -208,11 +208,11 @@ public function process($link = null, $info = null) /** Скачать превью. Если не указать имя файла для записи - функция вернет содержимое файла */ public function fetchImage($filename = null) { - if (!$url = $this->getImage()) { + if (! $url = $this->getImage()) { return false; } - if (!$res = $this->fetchPage($url)) { + if (! $res = $this->fetchPage($url)) { return false; } @@ -228,7 +228,7 @@ protected function cleanLink() $this->link = 'http://' . $this->link; } - if (!$this->link_parts = parse_url($this->link)) { + if (! $this->link_parts = parse_url($this->link)) { return false; } @@ -244,7 +244,7 @@ protected function maybeYoutube() if ('youtube.com' == $h) { parse_str($this->link_parts['query'], $q); - if ('/watch' == $p && !empty($q['v'])) { + if ('/watch' == $p && ! empty($q['v'])) { return $this->foundYoutube($q['v']); } if (0 === strpos($p, '/embed/')) { @@ -396,7 +396,7 @@ public function getEmbed($options) $class = isset($options['class']) ? $options['class'] : ''; $url = $this->getVideo($autoplay); - if (!empty($class)) { + if (! empty($class)) { $class = ' class="' . $class . '"'; } diff --git a/assets/lib/MODxAPI/MODx.php b/assets/lib/MODxAPI/MODx.php index 3d5bf6a436..67eae07d2e 100644 --- a/assets/lib/MODxAPI/MODx.php +++ b/assets/lib/MODxAPI/MODx.php @@ -90,9 +90,9 @@ abstract class MODxAPI extends MODxAPIhelpers protected $default_field = array(); /** - * @var null|integer|string + * @var mixed */ - protected $id = null; + protected $id; /** * @var array @@ -198,11 +198,11 @@ public function getDefaultFields() protected function getTime($value) { $value = trim($value); - if (!empty($value)) { - if (!is_numeric($value)) { + if (! empty($value)) { + if (! is_numeric($value)) { $value = (int)strtotime($value); } - if (!empty($value)) { + if (! empty($value)) { $value += $this->modxConfig('server_offset_time'); } } @@ -226,7 +226,7 @@ final public function modxConfig($name, $default = null) */ public function addQuery($q) { - if (is_scalar($q) && !empty($q)) { + if (is_scalar($q) && ! empty($q)) { $this->_query[] = $q; } @@ -260,7 +260,7 @@ final public function query($SQL) */ final public function escape($value) { - if (!is_scalar($value)) { + if (! is_scalar($value)) { $value = ''; } else { $value = $this->modx->db->escape($value); @@ -292,7 +292,7 @@ final public function invokeEvent($name, $data = array(), $flag = false) */ final public function getInvokeEventResult($name, $data = array(), $flag = null) { - $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; + $flag = (isset($flag) && $flag !== '') ? (bool)$flag : false; return $flag ? $this->modx->invokeEvent($name, $data) : false; } @@ -400,7 +400,7 @@ public function switchObject($id) //Если уже загружен объект, с которым мы хотим временно поработать case ($this->getID() == $id && $id): //Если $id не указан, но уже загружен какой-то объект - case (!$id && null !== $this->getID()): + case (! $id && null !== $this->getID()): default: $obj = $this; break; @@ -435,7 +435,7 @@ public function hasIgnore() */ public function set($key, $value) { - if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { + if ((is_scalar($value) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) { $this->field[$key] = $value; } @@ -484,7 +484,7 @@ public function fromArray($data) */ final protected function Uset($key, $id = '') { - if (!isset($this->field[$key])) { + if (! isset($this->field[$key])) { $tmp = "`{$key}`=''"; $this->log[] = "{$key} is empty"; } else { @@ -494,7 +494,7 @@ final protected function Uset($key, $id = '') throw new Exception("{$key} is invalid
" . print_r($this->field[$key], true) . ""); } } - if (!empty($tmp) && $this->isChanged($key)) { + if (! empty($tmp) && $this->isChanged($key)) { if ($id == '') { $this->set[] = $tmp; } else { @@ -528,7 +528,7 @@ public function store($data = array()) */ public function rollback($key = '') { - if (!empty($key) && isset($this->store[$key])) { + if (! empty($key) && isset($this->store[$key])) { $this->set($key, $this->store[$key]); } else { $this->fromArray($this->store); @@ -545,7 +545,7 @@ public function rollback($key = '') */ public function isChanged($key) { - $flag = !isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); + $flag = ! isset($this->store[$key]) || (isset($this->store[$key]) && $this->store[$key] != $this->field[$key]); return $flag; } @@ -572,7 +572,7 @@ final public function cleanIDs($IDs, $sep = ',', $ignore = array()) */ final public function fromJson($data, $callback = null) { - if (is_scalar($data) && !empty($data)) { + if (is_scalar($data) && ! empty($data)) { $json = json_decode($data); } else { throw new Exception("json is not string with json data"); @@ -654,7 +654,7 @@ public function toArray($prefix = '', $suffix = '', $sep = '_') $out = array(); $fields = $this->field; $fields[$this->fieldPKName()] = $this->getID(); - if ($tpl != $plh) { + if ($tpl !== $plh) { foreach ($fields as $key => $value) { $out[str_replace($plh, $key, $tpl)] = $value; } @@ -690,7 +690,7 @@ final public function makeTable($table) */ final public function sanitarIn($data, $sep = ',') { - if (!is_array($data)) { + if (! is_array($data)) { $data = explode($sep, $data); } $out = array(); @@ -732,11 +732,7 @@ public function checkUnique($table, $field, $PK = 'id') if ($where != '') { $sql = $this->query("SELECT `" . $this->escape($PK) . "` FROM " . $this->makeTable($table) . " WHERE " . $where); $id = $this->modx->db->getValue($sql); - if (!$id || (!$this->newDoc && $id == $this->getID())) { - $flag = true; - } else { - $flag = false; - } + $flag = (! $id || (! $this->newDoc && $id == $this->getID())); } else { $flag = false; } @@ -836,7 +832,7 @@ final protected function checkVersion($version, $dmi3yy = true) if (version_compare($tmp, $version, '>=')) { $flag = true; if ($dmi3yy) { - $flag = (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer); + $flag = $flag || (boolean)preg_match('/^' . $tmp . '(.*)\-d/', $currentVer); } } @@ -845,7 +841,7 @@ final protected function checkVersion($version, $dmi3yy = true) /** * @param string $name - * @return bool|mixed + * @return bool|string|int */ protected function eraseField($name) { diff --git a/assets/lib/MODxAPI/autoTable.abstract.php b/assets/lib/MODxAPI/autoTable.abstract.php index 3ea788bf82..4c1c53adda 100644 --- a/assets/lib/MODxAPI/autoTable.abstract.php +++ b/assets/lib/MODxAPI/autoTable.abstract.php @@ -90,12 +90,12 @@ public function save($fire_events = false, $clearCache = false) if ($this->newDoc && $this->get($key) === null && $this->get($key) !== $value) { $this->set($key, $value); } - if ((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null) { + if ((! $this->generateField || isset($fld[$key])) && $this->get($key) !== null) { $this->Uset($key); } unset($fld[$key]); } - if (!empty($this->set)) { + if (! empty($this->set)) { if ($this->newDoc) { $SQL = "INSERT {$this->ignoreError} INTO {$this->makeTable($this->table)} SET " . implode(', ', $this->set); @@ -125,9 +125,9 @@ public function save($fire_events = false, $clearCache = false) public function delete($ids, $fire_events = false) { $_ids = $this->cleanIDs($ids, ','); - if (is_array($_ids) && $_ids != array()) { + if (is_array($_ids) && $_ids !== array()) { $id = $this->sanitarIn($_ids); - if (!empty($id)) { + if (! empty($id)) { $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})"); } $this->clearCache($fire_events); diff --git a/assets/lib/MODxAPI/modManagers.php b/assets/lib/MODxAPI/modManagers.php index dedef4be23..9472b489f2 100644 --- a/assets/lib/MODxAPI/modManagers.php +++ b/assets/lib/MODxAPI/modManagers.php @@ -143,7 +143,7 @@ public function edit($id) $this->close(); $this->newDoc = false; - if (!$find = $this->findUser($id)) { + if (! $find = $this->findUser($id)) { $this->id = null; } else { $this->set('editedon', time()); @@ -175,7 +175,7 @@ public function edit($id) */ public function set($key, $value) { - if (is_scalar($value) && is_scalar($key) && !empty($key)) { + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { switch ($key) { case 'password': $this->givenPassword = $value; @@ -233,20 +233,20 @@ public function save($fire_events = false, $clearCache = false) return false; } - if (!$this->checkUnique('manager_users', 'username')) { + if (! $this->checkUnique('manager_users', 'username')) { $this->log['UniqueUsername'] = 'username not unique
' . print_r($this->get('username'), true) . ''; return false; } - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { + if (! $this->checkUnique('user_attributes', 'email', 'internalKey')) { $this->log['UniqueEmail'] = 'Email not unique
' . print_r($this->get('email'), true) . ''; return false; } - if(!$this->get('role')) { + if(! $this->get('role')) { $this->log['UniqueEmail'] = 'Wrong manager role
' . print_r($this->get('role'), true) . ''; } @@ -260,7 +260,7 @@ public function save($fire_events = false, $clearCache = false) $this->Uset($key, 'user'); unset($fld[$key]); } - if (!empty($this->set['user'])) { + if (! empty($this->set['user'])) { if ($this->newDoc) { $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); } else { @@ -282,7 +282,7 @@ public function save($fire_events = false, $clearCache = false) $this->Uset($key, 'attribute'); unset($fld[$key]); } - if (!empty($this->set['attribute'])) { + if (! empty($this->set['attribute'])) { if ($this->newDoc) { $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', @@ -295,7 +295,7 @@ public function save($fire_events = false, $clearCache = false) } unset($fld['id']); foreach ($fld as $key => $value) { - if ($value == '' || !$this->isChanged($key)) { + if ($value == '' || ! $this->isChanged($key)) { continue; } $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); @@ -306,7 +306,7 @@ public function save($fire_events = false, $clearCache = false) } } // TODO - if (!$this->newDoc && $this->givenPassword) { + if (! $this->newDoc && $this->givenPassword) { $this->invokeEvent('OnManagerChangePassword', array( 'userObj' => $this, 'userid' => $this->id, @@ -316,7 +316,7 @@ public function save($fire_events = false, $clearCache = false) ), $fire_events); } - if (!empty($this->groupIds)) { + if (! empty($this->groupIds)) { $this->setUserGroups($this->id, $this->groupIds); } // TODO @@ -412,7 +412,7 @@ public function checkBlock($id = 0) $b = $tmp->get('blocked'); $bu = $tmp->get('blockeduntil'); $ba = $tmp->get('blockedafter'); - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); unset($tmp); return $flag; @@ -434,7 +434,7 @@ public function testAuth($id, $password, $blocker, $fire_events = false) $flag = $pluginFlag = false; if ( - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) + (null !== $tmp->getID()) && (! $blocker || ($blocker && ! $tmp->checkBlock($id))) ) { $_password = $tmp->get('password'); $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( @@ -451,7 +451,7 @@ public function testAuth($id, $password, $blocker, $fire_events = false) } else { $pluginFlag = (bool)$eventResult; } - if (!$pluginFlag) { + if (! $pluginFlag) { $hashType = $this->getPasswordHashType($_password); switch ($hashType) { case 'phpass': @@ -488,7 +488,7 @@ public function testAuth($id, $password, $blocker, $fire_events = false) */ public function logOut($cookieName = 'modx_remember_manager', $fire_events = false) { - if (!$uid = $this->modx->getLoginUserID('mgr')) { + if (! $uid = $this->modx->getLoginUserID('mgr')) { return; } $params = array( @@ -534,7 +534,7 @@ protected function SessionHandler($directive, $cookieName, $remember = true) $_SESSION['mgrPermissions'] = $this->mgrPermissions; $_SESSION['mgrDocgroups'] = $this->getDocumentGroups(); $_SESSION['mgrToken'] = md5($this->get('sessionid')); - if (!empty($remember)) { + if (! empty($remember)) { $this->setAutoLoginCookie($cookieName, $remember); } } @@ -584,7 +584,7 @@ public function isSecure() */ public function setAutoLoginCookie($cookieName, $remember = true) { - if (!empty($cookieName) && $this->getID() !== null) { + if (! empty($cookieName) && $this->getID() !== null) { $secure = $this->isSecure(); $remember = is_bool($remember) ? $this->getRememberTime() : (int)$remember; $cookieValue = $this->get('username'); @@ -659,7 +659,7 @@ public function setUserGroups($userID = 0, $groupIds = array()) foreach ($groupIds as $gid) { $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); } - if (!$this->newDoc) { + if (! $this->newDoc) { $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); } diff --git a/assets/lib/MODxAPI/modResource.php b/assets/lib/MODxAPI/modResource.php index d671a87d50..ec9c9180cd 100644 --- a/assets/lib/MODxAPI/modResource.php +++ b/assets/lib/MODxAPI/modResource.php @@ -1,1126 +1,1132 @@ - 'document', - 'contentType' => 'text/html', - 'pagetitle' => 'New document', - 'longtitle' => '', - 'description' => '', - 'alias' => '', - 'link_attributes' => '', - 'published' => 1, - 'pub_date' => 0, - 'unpub_date' => 0, - 'parent' => 0, - 'isfolder' => 0, - 'introtext' => '', - 'content' => '', - 'richtext' => 1, - 'template' => 0, - 'menuindex' => 0, - 'searchable' => 1, - 'cacheable' => 1, - 'createdon' => 0, - 'createdby' => 0, - 'editedon' => 0, - 'editedby' => 0, - 'deleted' => 0, - 'deletedon' => 0, - 'deletedby' => 0, - 'publishedon' => 0, - 'publishedby' => 0, - 'menutitle' => '', - 'donthit' => 0, - 'privateweb' => 0, - 'privatemgr' => 0, - 'content_dispo' => 0, - 'hidemenu' => 0, - 'alias_visible' => 1 - ); - /** - * @var array - */ - private $table = array( - '"' => '_', - "'" => '_', - ' ' => '_', - '.' => '_', - ',' => '_', - 'а' => 'a', - 'б' => 'b', - 'в' => 'v', - 'г' => 'g', - 'д' => 'd', - 'е' => 'e', - 'ё' => 'e', - 'ж' => 'zh', - 'з' => 'z', - 'и' => 'i', - 'й' => 'y', - 'к' => 'k', - 'л' => 'l', - 'м' => 'm', - 'н' => 'n', - 'о' => 'o', - 'п' => 'p', - 'р' => 'r', - 'с' => 's', - 'т' => 't', - 'у' => 'u', - 'ф' => 'f', - 'х' => 'h', - 'ц' => 'c', - 'ч' => 'ch', - 'ш' => 'sh', - 'щ' => 'sch', - 'ь' => '', - 'ы' => 'y', - 'ъ' => '', - 'э' => 'e', - 'ю' => 'yu', - 'я' => 'ya', - 'А' => 'A', - 'Б' => 'B', - 'В' => 'V', - 'Г' => 'G', - 'Д' => 'D', - 'Е' => 'E', - 'Ё' => 'E', - 'Ж' => 'Zh', - 'З' => 'Z', - 'И' => 'I', - 'Й' => 'Y', - 'К' => 'K', - 'Л' => 'L', - 'М' => 'M', - 'Н' => 'N', - 'О' => 'O', - 'П' => 'P', - 'Р' => 'R', - 'С' => 'S', - 'Т' => 'T', - 'У' => 'U', - 'Ф' => 'F', - 'Х' => 'H', - 'Ц' => 'C', - 'Ч' => 'Ch', - 'Ш' => 'Sh', - 'Щ' => 'Sch', - 'Ь' => '', - 'Ы' => 'Y', - 'Ъ' => '', - 'Э' => 'E', - 'Ю' => 'Yu', - 'Я' => 'Ya', - ); - /** - * @var array массив ТВшек где name это ключ массива, а ID это значение - */ - private $tv = array(); - /** - * @var array массив ТВшек где ID это ключ массива, а name это значение - */ - private $tvid = array(); - /** - * @var array значения по умолчанию для ТВ параметров - */ - private $tvd = array(); - - /** @var array связи ТВ и шаблонов */ - private $tvTpl = array(); - - /** @var array параметры ТВ с массивами */ - protected $tvaFields = array(); - - /** - * Массив администраторов - * @var DLCollection - */ - private $managerUsers = null; - /** @var array группы документов */ - protected $groupIds = array(); - - /** - * modResource constructor. - * @param DocumentParser $modx - * @param bool $debug - */ - public function __construct($modx, $debug = false) - { - parent::__construct($modx, $debug); - $this->get_TV(); - $uTable = $this->makeTable("manager_users"); - $aTable = $this->makeTable("user_attributes"); - $query = "SELECT `u`.`id`, `a`.`email`, `u`.`username` FROM " . $aTable . " as `a` LEFT JOIN " . $uTable . " as `u` ON `u`.`id`=`a`.`internalKey`"; - $query = $this->query($query); - $this->managerUsers = new DLCollection($modx, empty($query) ? array() : $query); - } - - /** - * @return array - */ - public function toArrayMain() - { - $out = array_intersect_key(parent::toArray(), $this->default_field); - - return $out; - } - - /** - * @param bool $render - * @return array - */ - public function toArrayTV($render = false) - { - $out = array_diff_key(parent::toArray(), $this->default_field); - $tpl = $this->get('template'); - $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); - foreach ($tvTPL as $item) { - if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { - $value = $this->get($this->tvid[$item]); - $out[$this->tvid[$item]] = empty($value) ? $this->tvd[$this->tvid[$item]] : $value; - } - - } - if ($render) { - foreach ($out as $key => $val) { - $out[$key] = $this->renderTV($key); - } - } - - return $out; - } - - /** - * @param string $prefix - * @param string $suffix - * @param string $sep - * @param bool $render - * @return array - */ - public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) - { - $out = array_merge( - $this->toArrayMain(), - $this->toArrayTV($render), - array($this->fieldPKName() => $this->getID()) - ); - - return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); - } - - /** - * @return null|string - */ - public function getUrl() - { - $out = null; - $id = (int)$this->getID(); - if (!empty($id)) { - $out = $this->modx->makeUrl($id); - } - - return $out; - } - - /** - * @param string $main - * @param string $second - * @return mixed - */ - public function getTitle($main = 'menutitle', $second = 'pagetitle') - { - $title = $this->get($main); - if (empty($title) && $title !== '0') { - $title = $this->get($second); - } - - return $title; - } - - /** - * @return bool - */ - public function isWebShow() - { - $pub = ($this->get('publishedon') < time() && $this->get('published')); - $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time()); - $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); - - return ($pub && $unpub && $del); - } - - /** - * @return $this - */ - public function touch() - { - $this->set('editedon', time()); - - return $this; - } - - /** - * @param $tvname - * @return null|string - */ - public function renderTV($tvname) - { - $out = null; - if ($this->getID() > 0) { - include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; - include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; - $tvval = $this->get($tvname); - if ($this->isTVarrayField($tvname) && is_array($tvval)) { - $tvval = implode('||', $tvval); - } - $param = APIHelpers::getkey($this->tvd, $tvname, array()); - $display = APIHelpers::getkey($param, 'display', ''); - $display_params = APIHelpers::getkey($param, 'display_params', ''); - $type = APIHelpers::getkey($param, 'type', ''); - $out = getTVDisplayFormat($tvname, $tvval, $display, $display_params, $type, $this->getID(), ''); - } - - return $out; - } - - /** - * @param $key - * @return mixed - */ - public function get($key) - { - $out = parent::get($key); - if (isset($this->tv[$key])) { - $tpl = $this->get('template'); - $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); - $tvID = APIHelpers::getkey($this->tv, $key, 0); - if (in_array($tvID, $tvTPL) && is_null($out)) { - $out = APIHelpers::getkey($this->tvd, $key, null); - $out = $out['default']; - } - } - - return $out; - } - - /** - * @param $key - * @param $value - * @return $this - */ - public function set($key, $value) - { - if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && !empty($key)) { - switch ($key) { - case 'parent': - $value = (int)$value; - break; - case 'template': - $value = trim($value); - $value = $this->setTemplate($value); - break; - case 'published': - $value = (int)((bool)$value); - if ($value) { - $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); - } - break; - case 'pub_date': - $value = $this->getTime($value); - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { - $this->field['published'] = 1; - $this->field['publishedon'] = $value; - } - break; - case 'unpub_date': - $value = $this->getTime($value); - if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { - $this->field['published'] = 0; - $this->field['publishedon'] = 0; - } - break; - case 'deleted': - $value = (int)((bool)$value); - if ($value) { - $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); - } else { - $this->field['deletedon'] = 0; - } - break; - case 'deletedon': - $value = $this->getTime($value); - if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { - $value = 0; - } - if ($value) { - $this->field['deleted'] = 1; - } - break; - case 'editedon': - case 'createdon': - case 'publishedon': - $value = $this->getTime($value); - break; - case 'publishedby': - case 'editedby': - case 'createdby': - case 'deletedby': - $value = $this->getUser($value, $this->default_field[$key]); - break; - } - $this->field[$key] = $value; - } - - return $this; - } - - /** - * @param $value - * @param int $default - * @return int|mixed - */ - protected function getUser($value, $default = 0) - { - $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); - $value = (int)$value; - if (!empty($value)) { - $by = $this->findUserBy($value); - $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { - return ($val->containsKey($by) && $val->get($by) === (string)$value); - }); - if (!$exists) { - $value = 0; - } - } - if (empty($value)) { - $value = empty($currentAdmin) ? $default : $currentAdmin; - } - - return $value; - } - - /** - * @param $data - * @return bool|string - */ - protected function findUserBy($data) - { - switch (true) { - case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): - $find = 'id'; - break; - case filter_var($data, FILTER_VALIDATE_EMAIL): - $find = 'email'; - break; - case is_scalar($data): - $find = 'username'; - break; - default: - $find = false; - } - - return $find; - } - - /** - * @param array $data - * @return $this - */ - public function create($data = array()) - { - $this->close(); - $fld = array(); - foreach ($this->tvd as $name => $tv) { - $fld[$name] = $tv['default']; - }; - $this->store($fld); - - $this->fromArray(array_merge($fld, $data)); - $this->set('createdby', null) - ->set('editedby', null) - ->set('createdon', time()) - ->touch(); - - return $this; - } - - /** - * @param $id - * @return $this - */ - public function edit($id) - { - $id = is_scalar($id) ? trim($id) : ''; - if ($this->getID() != $id) { - $this->close(); - $this->markAllEncode(); - $this->newDoc = false; - $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); - $this->fromArray($this->modx->db->getRow($result)); - $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); - while ($row = $this->modx->db->getRow($result)) { - $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; - } - $fld = array(); - foreach ($this->tvd as $name => $tv) { - if ($this->belongsToTemplate($this->tv[$name])) { - $fld[$name] = $tv['default']; - } - }; - $this->store(array_merge($fld, $this->field)); - if (empty($this->field['id'])) { - $this->id = null; - } else { - $this->id = $this->field['id']; - $this->set('editedby', null)->touch(); - $this->decodeFields(); - } - unset($this->field['id']); - } - - return $this; - } - - /** - * @param bool $fire_events - * @param bool $clearCache - * @return bool|null - */ - public function save($fire_events = false, $clearCache = false) - { - $parent = null; - if ($this->field['pagetitle'] == '') { - $this->log['emptyPagetitle'] = 'Pagetitle is empty in
' . print_r($this->field, true) . ''; - - return false; - } - - $uid = $this->modx->getLoginUserID('mgr'); - - if ( - $this->field['parent'] == 0 && - !$this->modxConfig('udperms_allowroot') && - !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) - ) { - $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; - - return false; - } - - $this->set('alias', $this->getAlias()); - - $this->invokeEvent('OnBeforeDocFormSave', array( - 'mode' => $this->newDoc ? "new" : "upd", - 'id' => isset($this->id) ? $this->id : '', - 'doc' => $this->toArray(), - 'docObj' => $this - ), $fire_events); - - $fld = $this->encodeFields()->toArray(null, null, null, false); - foreach ($this->default_field as $key => $value) { - $tmp = $this->get($key); - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { - if ($tmp == $value) { - switch ($key) { - case 'cacheable': - $value = $this->modxConfig('cache_default'); - break; - case 'template': - $value = $value = $this->modxConfig('default_template'); - break; - case 'published': - $value = $this->modxConfig('publish_default'); - break; - case 'searchable': - $value = $this->modxConfig('search_default'); - break; - case 'donthit': - $value = $this->modxConfig('track_visitors'); - break; - } - } - $this->field[$key] = $value; - } - switch (true) { - case $key == 'parent': - $parent = (int)$this->get($key); - $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); - if ($this->modx->db->getValue($q) != 1) { - $parent = 0; - } - $this->field[$key] = $parent; - $this->Uset($key); - break; - case ($key == 'alias_visible' && !$this->checkVersion('1.0.10', true)): - $this->eraseField('alias_visible'); - break; - default: - $this->Uset($key); - } - unset($fld[$key]); - } - - if (!empty($this->set)) { - if ($this->newDoc) { - $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); - } else { - $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', - $this->set) . " WHERE `id` = " . $this->id; - } - $this->query($SQL); - - if ($this->newDoc) { - $this->id = $this->modx->db->getInsertId(); - } - - if ($parent > 0) { - $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'"); - } - } - - $_deleteTVs = $_insertTVs = array(); - foreach ($fld as $key => $value) { - if (empty($this->tv[$key]) || !$this->isChanged($key) || !$this->belongsToTemplate($this->tv[$key])) { - continue; - } elseif ($value === '' || is_null($value) || (isset($this->tvd[$key]) && $value == $this->tvd[$key]['default'])) { - $_deleteTVs[] = $this->tv[$key]; - } else { - $_insertTVs[$this->tv[$key]] = $this->escape($value); - } - } - - if (!empty($_insertTVs)) { - $values = array(); - foreach ($_insertTVs as $id => $value) { - $values[] = "({$this->id}, {$id}, '{$value}')"; - } - $values = implode(',', $values); - $this->query("INSERT INTO {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values} ON DUPLICATE KEY UPDATE - `value` = VALUES(`value`)"); - } - - if (!empty($_deleteTVs)) { - $ids = implode(',', $_deleteTVs); - $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); - } - - if (!isset($this->mode)) { - $this->mode = $this->newDoc ? "new" : "upd"; - $this->newDoc = false; - } - - if (!empty($this->groupIds)) { - $this->setDocumentGroups($this->id, $this->groupIds); - } - $this->invokeEvent('OnDocFormSave', array( - 'mode' => $this->mode, - 'id' => isset($this->id) ? $this->id : '', - 'doc' => $this->toArray(), - 'docObj' => $this - ), $fire_events); - - if ($clearCache) { - $this->clearCache($fire_events); - } - $this->decodeFields(); - - return $this->id; - } - - /** - * @param $tvId - * @return bool - */ - protected function belongsToTemplate($tvId) - { - $template = $this->get('template'); - - return isset($this->tvTpl[$template]) && in_array($tvId, $this->tvTpl[$template]); - } - - /** - * @param $ids - * @return $this - * @throws Exception - */ - public function toTrash($ids) - { - $ignore = $this->systemID(); - $_ids = $this->cleanIDs($ids, ',', $ignore); - if (is_array($_ids) && $_ids != array()) { - $id = $this->sanitarIn($_ids); - $uid = (int)$this->modx->getLoginUserId(); - $deletedon = time() + $this->modxConfig('server_offset_time'); - $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})"); - } else { - throw new Exception('Invalid IDs list for mark trash:
' . print_r($ids, - 1) . 'please, check ignore list:
' . print_r($ignore, 1) . ''); - } - - return $this; - } - - /** - * @param bool $fire_events - * @return $this - */ - public function clearTrash($fire_events = false) - { - $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); - $_ids = $this->modx->db->getColumn('id', $q); - if (is_array($_ids) && $_ids != array()) { - $this->invokeEvent('OnBeforeEmptyTrash', array( - "ids" => $_ids - ), $fire_events); - - $id = $this->sanitarIn($_ids); - $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); - $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); - - $this->invokeEvent('OnEmptyTrash', array( - "ids" => $_ids - ), $fire_events); - } - - return $this; - } - - /** - * @param $ids - * @param int|bool $depth - * @return array - */ - public function children($ids, $depth) - { - $_ids = $this->cleanIDs($ids, ','); - if (is_array($_ids) && $_ids != array()) { - $id = $this->sanitarIn($_ids); - if (!empty($id)) { - $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); - $id = $this->modx->db->getColumn('id', $q); - if ($depth > 0 || $depth === true) { - $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1)); - } - $_ids = array_merge($_ids, $id); - } - } - - return $_ids; - } - - /** - * @param string|array $ids - * @param bool $fire_events - * @return $this - * @throws Exception - */ - public function delete($ids, $fire_events = false) - { - $ids = $this->children($ids, true); - $_ids = $this->cleanIDs($ids, ',', $this->systemID()); - $this->invokeEvent('OnBeforeDocFormDelete', array( - 'ids' => $_ids - ), $fire_events); - $this->toTrash($_ids); - $this->invokeEvent('OnDocFormDelete', array( - 'ids' => $_ids - ), $fire_events); - - return $this; - } - - /** - * @return array - */ - private function systemID() - { - $ignore = array( - 0, //empty document - (int)$this->modxConfig('site_start'), - (int)$this->modxConfig('error_page'), - (int)$this->modxConfig('unauthorized_page'), - (int)$this->modxConfig('site_unavailable_page') - ); - $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''"); - $data = $this->modx->db->makeArray($data); - foreach ($data as $item) { - $ignore[] = (int)$item['setting_value']; - } - - return array_unique($ignore); - - } - - /** - * @param $alias - * @return string - */ - protected function checkAlias($alias) - { - $alias = strtolower($alias); - if ($this->modxConfig('friendly_urls')) { - $_alias = $this->escape($alias); - if ((!$this->modxConfig('allow_duplicate_alias') && !$this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { - $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); - } else { - $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); - } - if (($flag && $this->newDoc) || (!$this->newDoc && $flag && $this->id != $flag)) { - $suffix = substr($alias, -2); - if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { - $suffix = (int)$tmp[1] + 1; - $alias = substr($alias, 0, -2) . '-' . $suffix; - } else { - $alias .= '-2'; - } - $alias = $this->checkAlias($alias); - } - } - - return $alias; - } - - /** - * @param $key - * @return bool - */ - public function issetField($key) - { - return (array_key_exists($key, $this->default_field) || (array_key_exists($key, $this->tv) && $this->belongsToTemplate($this->tv[$key]))); - } - - /** - * @param bool $reload - * @return $this - */ - protected function get_TV($reload = false) - { - $this->modx->_TVnames = $this->loadFromCache('_TVnames'); - if ($this->modx->_TVnames === false || empty($this->modx->_TVnames) || $reload) { - $this->modx->_TVnames = array(); - $result = $this->query('SELECT `id`,`name`,`default_text`,`type`,`display`,`display_params` FROM ' . $this->makeTable('site_tmplvars')); - while ($row = $this->modx->db->GetRow($result)) { - $this->modx->_TVnames[$row['name']] = array( - 'id' => $row['id'], - 'type' => $row['type'], - 'default' => $row['default_text'], - 'display' => $row['display'], - 'display_params' => $row['display_params'] - ); - } - $this->saveToCache($this->modx->_TVnames, '_TVnames'); - } - $arrayTypes = array('checkbox', 'listbox-multiple'); - $arrayTVs = array(); - foreach ($this->modx->_TVnames as $name => $data) { - $this->tvid[$data['id']] = $name; - $this->tv[$name] = $data['id']; - if (in_array($data['type'], $arrayTypes)) { - $arrayTVs[] = $name; - } - } - if (empty($this->tvaFields)) { - $this->tvaFields = $arrayTVs; - } - $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); - - return $this; - } - - /** - * @return $this - */ - protected function loadTVTemplate() - { - $this->tvTpl = $this->loadFromCache('_tvTpl'); - if ($this->tvTpl === false) { - $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); - $this->tvTpl = array(); - while ($item = $this->modx->db->getRow($q)) { - $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; - } - $this->saveToCache($this->tvTpl, '_tvTpl'); - } - - return $this; - } - - /** - * @param array $tvId - * @return $this - */ - protected function loadTVDefault(array $tvId = array()) - { - if (is_array($tvId) && !empty($tvId)) { - $this->tvd = array(); - foreach ($tvId as $id) { - $name = $this->tvid[$id]; - $this->tvd[$name] = $this->modx->_TVnames[$name]; - } - } - - return $this; - } - - /** - * @param $tpl - * @return int - * @throws Exception - */ - public function setTemplate($tpl) - { - if (!is_numeric($tpl) || $tpl != (int)$tpl) { - if (is_scalar($tpl)) { - $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; - $rs = $this->query($sql); - if (!$rs || $this->modx->db->getRecordCount($rs) <= 0) { - throw new Exception("Template {$tpl} is not exists"); - } - $tpl = $this->modx->db->getValue($rs); - } else { - throw new Exception("Invalid template name: " . print_r($tpl, 1)); - } - } - - return (int)$tpl; - } - - /** - * @return string - */ - protected function getAlias() - { - if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { - $alias = strtr($this->get('pagetitle'), $this->table); - } else { - if ($this->get('alias') != '') { - $alias = $this->get('alias'); - } else { - $alias = ''; - } - } - $alias = $this->modx->stripAlias($alias); - - return $this->checkAlias($alias); - } - - /** - * @param int $parent - * @param string $criteria - * @param string $dir - * @return $this - * - * Пересчет menuindex по полю таблицы site_content - */ - public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') - { - $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; - if (is_integer($parent) && $criteria !== '') { - $this->query("SET @index := 0"); - $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}"); - } - - return $this; - } - - /** - * Устанавливает значение шаблона согласно системной настройке - * - * @return $this - */ - public function setDefaultTemplate() - { - $parent = $this->get('parent'); - $template = $this->modxConfig('default_template'); - switch ($this->modxConfig('auto_template_logic')) { - case 'sibling': - if (!$parent) { - $site_start = $this->modxConfig('site_start'); - $where = "sc.isfolder=0 AND sc.id!={$site_start}"; - $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { - $template = $sibl[0]['template']; - } - } else { - $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex', - 'ASC', 1); - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { - $template = $sibl[0]['template']; - } else { - $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex', - 'ASC', 1); - if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { - $template = $sibl[0]['template']; - } - } - } - break; - case 'parent': - if ($parent) { - $_parent = $this->modx->getPageInfo($parent, 0, 'template'); - if (isset($_parent['template'])) { - $template = $_parent['template']; - } - } - break; - } - $this->set('template', $template); - - return $this; - } - - /** - * Декодирует конкретное поле - * @param string $field Имя поля - * @param bool $store обновить распакованное поле - * @return array ассоциативный массив с данными из json строки - */ - public function decodeField($field, $store = false) - { - $out = array(); - if ($this->isDecodableField($field)) { - $data = $this->get($field); - if ($this->isTVarrayField($field)) { - $out = explode('||', $data); - } else { - $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); - } - } - if ($store) { - $this->field[$field] = $out; - $this->markAsDecode($field); - } - - return $out; - } - - /** - * Запаковывает конкретное поле в JSON - * @param string $field Имя поля - * @param bool $store обновить запакованное поле - * @return string|null json строка - */ - public function encodeField($field, $store = false) - { - $out = null; - if ($this->isEncodableField($field)) { - $data = $this->get($field); - if ($this->isTVarrayField($field)) { - $out = is_array($data) ? implode('||', $data) : (string)$data; - } else { - $out = json_encode($data); - } - } - if ($store) { - $this->field[$field] = $out; - $this->markAsEncode($field); - } - - return $out; - } - - /** - * Может ли содержать данное поле json массив - * @param string $field имя поля - * @return boolean - */ - public function isTVarrayField($field) - { - return (is_scalar($field) && in_array($field, $this->tvaFields)); - } - - /** - * Пометить все поля как запакованные - * @return $this - */ - public function markAllEncode() - { - parent::markAllEncode(); - foreach ($this->tvaFields as $field) { - $this->markAsEncode($field); - } - - return $this; - } - - /** - * Пометить все поля как распакованные - * @return $this - */ - public function markAllDecode() - { - parent::markAllDecode(); - foreach ($this->tvaFields as $field) { - $this->markAsDecode($field); - } - - return $this; - } - - /** - * @param int $docId - */ - public function getDocumentGroups($docId = 0) - { - $out = array(); - $doc = $this->switchObject($docId); - if (null !== $doc->getID()) { - $doc_groups = $this->makeTable('document_groups'); - $docgroup_names = $this->makeTable('documentgroup_names'); - - $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` - WHERE `dg`.`document` = " . $doc->getID()); - while ($row = $this->modx->db->getRow($rs)) { - $out[$row['document_group']] = $row['name']; - } - - } - unset($doc); - - return $out; - } - - /** - * @param int $docId - * @param array $groupIds - * @return $this - */ - public function setDocumentGroups($docId = 0, $groupIds = array()) - { - if (!is_array($groupIds)) { - return $this; - } - if ($this->newDoc && $docId == 0) { - $this->groupIds = $groupIds; - } else { - $doc = $this->switchObject($docId); - if ($id = $doc->getID()) { - foreach ($groupIds as $gid) { - $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); - } - if (!$this->newDoc) { - $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); - $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); - } - } - unset($doc); - $this->groupIds = array(); - } - - return $this; - } -} + 'document', + 'contentType' => 'text/html', + 'pagetitle' => 'New document', + 'longtitle' => '', + 'description' => '', + 'alias' => '', + 'link_attributes' => '', + 'published' => 1, + 'pub_date' => 0, + 'unpub_date' => 0, + 'parent' => 0, + 'isfolder' => 0, + 'introtext' => '', + 'content' => '', + 'richtext' => 1, + 'template' => 0, + 'menuindex' => 0, + 'searchable' => 1, + 'cacheable' => 1, + 'createdon' => 0, + 'createdby' => 0, + 'editedon' => 0, + 'editedby' => 0, + 'deleted' => 0, + 'deletedon' => 0, + 'deletedby' => 0, + 'publishedon' => 0, + 'publishedby' => 0, + 'menutitle' => '', + 'donthit' => 0, + 'privateweb' => 0, + 'privatemgr' => 0, + 'content_dispo' => 0, + 'hidemenu' => 0, + 'alias_visible' => 1 + ); + /** + * @var array + */ + private $table = array( + '"' => '_', + "'" => '_', + ' ' => '_', + '.' => '_', + ',' => '_', + 'а' => 'a', + 'б' => 'b', + 'в' => 'v', + 'г' => 'g', + 'д' => 'd', + 'е' => 'e', + 'ё' => 'e', + 'ж' => 'zh', + 'з' => 'z', + 'и' => 'i', + 'й' => 'y', + 'к' => 'k', + 'л' => 'l', + 'м' => 'm', + 'н' => 'n', + 'о' => 'o', + 'п' => 'p', + 'р' => 'r', + 'с' => 's', + 'т' => 't', + 'у' => 'u', + 'ф' => 'f', + 'х' => 'h', + 'ц' => 'c', + 'ч' => 'ch', + 'ш' => 'sh', + 'щ' => 'sch', + 'ь' => '', + 'ы' => 'y', + 'ъ' => '', + 'э' => 'e', + 'ю' => 'yu', + 'я' => 'ya', + 'А' => 'A', + 'Б' => 'B', + 'В' => 'V', + 'Г' => 'G', + 'Д' => 'D', + 'Е' => 'E', + 'Ё' => 'E', + 'Ж' => 'Zh', + 'З' => 'Z', + 'И' => 'I', + 'Й' => 'Y', + 'К' => 'K', + 'Л' => 'L', + 'М' => 'M', + 'Н' => 'N', + 'О' => 'O', + 'П' => 'P', + 'Р' => 'R', + 'С' => 'S', + 'Т' => 'T', + 'У' => 'U', + 'Ф' => 'F', + 'Х' => 'H', + 'Ц' => 'C', + 'Ч' => 'Ch', + 'Ш' => 'Sh', + 'Щ' => 'Sch', + 'Ь' => '', + 'Ы' => 'Y', + 'Ъ' => '', + 'Э' => 'E', + 'Ю' => 'Yu', + 'Я' => 'Ya', + ); + /** + * @var array массив ТВшек где name это ключ массива, а ID это значение + */ + private $tv = array(); + /** + * @var array массив ТВшек где ID это ключ массива, а name это значение + */ + private $tvid = array(); + /** + * @var array значения по умолчанию для ТВ параметров + */ + private $tvd = array(); + + /** @var array связи ТВ и шаблонов */ + private $tvTpl = array(); + + /** @var array параметры ТВ с массивами */ + protected $tvaFields = array(); + + /** + * Массив администраторов + * @var DLCollection + */ + private $managerUsers = null; + /** @var array группы документов */ + protected $groupIds = array(); + + /** + * modResource constructor. + * @param DocumentParser $modx + * @param bool $debug + */ + public function __construct($modx, $debug = false) + { + parent::__construct($modx, $debug); + $this->get_TV(); + $uTable = $this->makeTable("manager_users"); + $aTable = $this->makeTable("user_attributes"); + $query = "SELECT `u`.`id`, `a`.`email`, `u`.`username` FROM " . $aTable . " as `a` LEFT JOIN " . $uTable . " as `u` ON `u`.`id`=`a`.`internalKey`"; + $query = $this->query($query); + $this->managerUsers = new DLCollection($modx, empty($query) ? array() : $query); + } + + /** + * @return array + */ + public function toArrayMain() + { + $out = array_intersect_key(parent::toArray(), $this->default_field); + + return $out; + } + + /** + * @param bool $render + * @return array + */ + public function toArrayTV($render = false) + { + $out = array_diff_key(parent::toArray(), $this->default_field); + $tpl = $this->get('template'); + $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); + foreach ($tvTPL as $item) { + if (isset($this->tvid[$item]) && !array_key_exists($this->tvid[$item], $out)) { + $value = $this->get($this->tvid[$item]); + $out[$this->tvid[$item]] = empty($value) ? $this->tvd[$this->tvid[$item]] : $value; + } + + } + if ($render) { + foreach ($out as $key => $val) { + $out[$key] = $this->renderTV($key); + } + } + + return $out; + } + + /** + * @param string $prefix + * @param string $suffix + * @param string $sep + * @param bool $render + * @return array + */ + public function toArray($prefix = '', $suffix = '', $sep = '_', $render = true) + { + $out = array_merge( + $this->toArrayMain(), + $this->toArrayTV($render), + array($this->fieldPKName() => $this->getID()) + ); + + return \APIhelpers::renameKeyArr($out, $prefix, $suffix, $sep); + } + + /** + * @return null|string + */ + public function getUrl() + { + $out = null; + $id = (int)$this->getID(); + if (! empty($id)) { + $out = $this->modx->makeUrl($id); + } + + return $out; + } + + /** + * @param string $main + * @param string $second + * @return mixed + */ + public function getTitle($main = 'menutitle', $second = 'pagetitle') + { + $title = $this->get($main); + if (empty($title) && $title !== '0') { + $title = $this->get($second); + } + + return $title; + } + + /** + * @return bool + */ + public function isWebShow() + { + $pub = ($this->get('publishedon') < time() && $this->get('published')); + $unpub = ($this->get('unpub_date') == 0 || $this->get('unpub_date') > time()); + $del = ($this->get('deleted') == 0 && ($this->get('deletedon') == 0 || $this->get('deletedon') > time())); + + return ($pub && $unpub && $del); + } + + /** + * @return $this + */ + public function touch() + { + $this->set('editedon', time()); + + return $this; + } + + /** + * @param $tvname + * @return null|string + */ + public function renderTV($tvname) + { + $out = null; + if ($this->getID() > 0) { + include_once MODX_MANAGER_PATH . "includes/tmplvars.format.inc.php"; + include_once MODX_MANAGER_PATH . "includes/tmplvars.commands.inc.php"; + $tvval = $this->get($tvname); + if ($this->isTVarrayField($tvname) && is_array($tvval)) { + $tvval = implode('||', $tvval); + } + $param = APIHelpers::getkey($this->tvd, $tvname, array()); + $display = APIHelpers::getkey($param, 'display', ''); + $display_params = APIHelpers::getkey($param, 'display_params', ''); + $type = APIHelpers::getkey($param, 'type', ''); + $out = getTVDisplayFormat($tvname, $tvval, $display, $display_params, $type, $this->getID(), ''); + } + + return $out; + } + + /** + * @param $key + * @return mixed + */ + public function get($key) + { + $out = parent::get($key); + if (isset($this->tv[$key])) { + $tpl = $this->get('template'); + $tvTPL = APIHelpers::getkey($this->tvTpl, $tpl, array()); + $tvID = APIHelpers::getkey($this->tv, $key, 0); + if (in_array($tvID, $tvTPL) && is_null($out)) { + $out = APIHelpers::getkey($this->tvd, $key, null); + $out = $out['default']; + } + } + + return $out; + } + + /** + * @param $key + * @param $value + * @return $this + */ + public function set($key, $value) + { + if ((is_scalar($value) || $this->isTVarrayField($key) || $this->isJsonField($key)) && is_scalar($key) && ! empty($key)) { + switch ($key) { + case 'donthit': + $value = (int)((bool)$value); + break; + case 'parent': + $value = (int)$value; + break; + case 'template': + $value = trim($value); + $value = $this->setTemplate($value); + break; + case 'published': + $value = (int)((bool)$value); + if ($value) { + $this->field['publishedon'] = time() + $this->modxConfig('server_offset_time'); + } + break; + case 'pub_date': + $value = $this->getTime($value); + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { + $this->field['published'] = 1; + $this->field['publishedon'] = $value; + } + break; + case 'unpub_date': + $value = $this->getTime($value); + if ($value > 0 && time() + $this->modxConfig('server_offset_time') > $value) { + $this->field['published'] = 0; + $this->field['publishedon'] = 0; + } + break; + case 'deleted': + $value = (int)((bool)$value); + if ($value) { + $this->field['deletedon'] = time() + $this->modxConfig('server_offset_time'); + } else { + $this->field['deletedon'] = 0; + } + break; + case 'deletedon': + $value = $this->getTime($value); + if ($value > 0 && time() + $this->modxConfig('server_offset_time') < $value) { + $value = 0; + } + if ($value) { + $this->field['deleted'] = 1; + } + break; + case 'editedon': + case 'createdon': + case 'publishedon': + $value = $this->getTime($value); + break; + case 'publishedby': + case 'editedby': + case 'createdby': + case 'deletedby': + $value = $this->getUser($value, $this->default_field[$key]); + break; + } + $this->field[$key] = $value; + } + + return $this; + } + + /** + * @param $value + * @param int $default + * @return int|mixed + */ + protected function getUser($value, $default = 0) + { + $currentAdmin = APIHelpers::getkey($_SESSION, 'mgrInternalKey', 0); + $value = (int)$value; + if (! empty($value)) { + $by = $this->findUserBy($value); + $exists = $this->managerUsers->exists(function ($key, Helpers\Collection $val) use ($by, $value) { + return ($val->containsKey($by) && $val->get($by) === (string)$value); + }); + if (! $exists) { + $value = 0; + } + } + if (empty($value)) { + $value = empty($currentAdmin) ? $default : $currentAdmin; + } + + return $value; + } + + /** + * @param $data + * @return bool|string + */ + protected function findUserBy($data) + { + switch (true) { + case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): + $find = 'id'; + break; + case filter_var($data, FILTER_VALIDATE_EMAIL): + $find = 'email'; + break; + case is_scalar($data): + $find = 'username'; + break; + default: + $find = false; + } + + return $find; + } + + /** + * @param array $data + * @return $this + */ + public function create($data = array()) + { + $this->close(); + $fld = array(); + foreach ($this->tvd as $name => $tv) { + $fld[$name] = $tv['default']; + }; + $this->store($fld); + + $this->fromArray(array_merge($fld, $data)); + $this->set('createdby', null) + ->set('editedby', null) + ->set('createdon', time()) + ->touch(); + + return $this; + } + + /** + * @param $id + * @return $this + */ + public function edit($id) + { + $id = is_scalar($id) ? trim($id) : ''; + if ($this->getID() != $id) { + $this->close(); + $this->markAllEncode(); + $this->newDoc = false; + $result = $this->query("SELECT * from {$this->makeTable('site_content')} where `id`=" . (int)$id); + $this->fromArray($this->modx->db->getRow($result)); + $result = $this->query("SELECT * from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid`=" . (int)$id); + while ($row = $this->modx->db->getRow($result)) { + $this->field[$this->tvid[$row['tmplvarid']]] = $row['value']; + } + $fld = array(); + foreach ($this->tvd as $name => $tv) { + if ($this->belongsToTemplate($this->tv[$name])) { + $fld[$name] = $tv['default']; + } + }; + $this->store(array_merge($fld, $this->field)); + if (empty($this->field['id'])) { + $this->id = null; + } else { + $this->id = $this->field['id']; + $this->set('editedby', null)->touch(); + $this->decodeFields(); + } + unset($this->field['id']); + } + + return $this; + } + + /** + * @param bool $fire_events + * @param bool $clearCache + * @return mixed + */ + public function save($fire_events = false, $clearCache = false) + { + $parent = null; + if ($this->field['pagetitle'] == '') { + $this->log['emptyPagetitle'] = 'Pagetitle is empty in
' . print_r($this->field, true) . ''; + + return false; + } + + $uid = $this->modx->getLoginUserID('mgr'); + + if ( + empty($this->field['parent']) && + ! $this->modxConfig('udperms_allowroot') && + !($uid && isset($_SESSION['mgrRole']) && $_SESSION['mgrRole'] == 1) + ) { + $this->log['rootForbidden'] = 'Only Administrators can create documents in the root folder because udperms_allowroot setting is off'; + + return false; + } + + $this->set('alias', $this->getAlias()); + + $this->invokeEvent('OnBeforeDocFormSave', array( + 'mode' => $this->newDoc ? "new" : "upd", + 'id' => isset($this->id) ? $this->id : '', + 'doc' => $this->toArray(), + 'docObj' => $this + ), $fire_events); + + $fld = $this->encodeFields()->toArray(null, null, null, false); + foreach ($this->default_field as $key => $value) { + $tmp = $this->get($key); + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { + if ($tmp == $value) { + switch ($key) { + case 'cacheable': + $value = (int)$this->modxConfig('cache_default'); + break; + case 'template': + $value = (int)$this->modxConfig('default_template'); + break; + case 'published': + $value = (int)$this->modxConfig('publish_default'); + break; + case 'searchable': + $value = (int)$this->modxConfig('search_default'); + break; + case 'donthit': + $value = (int)$this->modxConfig('track_visitors'); + break; + } + } + $this->field[$key] = $value; + } + switch (true) { + case $key == 'parent': + $parent = (int)$this->get($key); + $q = $this->query("SELECT count(`id`) FROM {$this->makeTable('site_content')} WHERE `id`='{$parent}'"); + if ($this->modx->db->getValue($q) != 1) { + $parent = 0; + } + $this->field[$key] = $parent; + $this->Uset($key); + break; + case ($key == 'alias_visible' && ! $this->checkVersion('1.0.10', true)): + $this->eraseField('alias_visible'); + break; + default: + $this->Uset($key); + } + unset($fld[$key]); + } + + if (! empty($this->set)) { + if ($this->newDoc) { + $SQL = "INSERT into {$this->makeTable('site_content')} SET " . implode(', ', $this->set); + } else { + $SQL = "UPDATE {$this->makeTable('site_content')} SET " . implode(', ', + $this->set) . " WHERE `id` = " . $this->id; + } + $this->query($SQL); + + if ($this->newDoc) { + $this->id = $this->modx->db->getInsertId(); + } + + if ($parent > 0) { + $this->query("UPDATE {$this->makeTable('site_content')} SET `isfolder`='1' WHERE `id`='{$parent}'"); + } + } + + $_deleteTVs = $_insertTVs = array(); + foreach ($fld as $key => $value) { + if (empty($this->tv[$key]) || ! $this->isChanged($key) || ! $this->belongsToTemplate($this->tv[$key])) { + continue; + } elseif ($value === '' || is_null($value) || (isset($this->tvd[$key]) && $value == $this->tvd[$key]['default'])) { + $_deleteTVs[] = $this->tv[$key]; + } else { + $_insertTVs[$this->tv[$key]] = $this->escape($value); + } + } + + if (! empty($_insertTVs)) { + $values = array(); + foreach ($_insertTVs as $id => $value) { + $values[] = "({$this->id}, {$id}, '{$value}')"; + } + $values = implode(',', $values); + $this->query("INSERT INTO {$this->makeTable('site_tmplvar_contentvalues')} (`contentid`,`tmplvarid`,`value`) VALUES {$values} ON DUPLICATE KEY UPDATE + `value` = VALUES(`value`)"); + } + + if (! empty($_deleteTVs)) { + $ids = implode(',', $_deleteTVs); + $this->query("DELETE FROM {$this->makeTable('site_tmplvar_contentvalues')} WHERE `contentid` = '{$this->id}' AND `tmplvarid` IN ({$ids})"); + } + + if (!isset($this->mode)) { + $this->mode = $this->newDoc ? "new" : "upd"; + $this->newDoc = false; + } + + if (! empty($this->groupIds)) { + $this->setDocumentGroups($this->id, $this->groupIds); + } + $this->invokeEvent('OnDocFormSave', array( + 'mode' => $this->mode, + 'id' => isset($this->id) ? $this->id : '', + 'doc' => $this->toArray(), + 'docObj' => $this + ), $fire_events); + + + $this->modx->getAliasListing($this->id); + + if ($clearCache) { + $this->clearCache($fire_events); + } + $this->decodeFields(); + + return $this->id; + } + + /** + * @param $tvId + * @return bool + */ + protected function belongsToTemplate($tvId) + { + $template = $this->get('template'); + + return isset($this->tvTpl[$template]) && in_array($tvId, $this->tvTpl[$template]); + } + + /** + * @param $ids + * @return $this + * @throws Exception + */ + public function toTrash($ids) + { + $ignore = $this->systemID(); + $_ids = $this->cleanIDs($ids, ',', $ignore); + if (is_array($_ids) && $_ids != array()) { + $id = $this->sanitarIn($_ids); + $uid = (int)$this->modx->getLoginUserId(); + $deletedon = time() + $this->modxConfig('server_offset_time'); + $this->query("UPDATE {$this->makeTable('site_content')} SET `deleted`=1, `deletedby`={$uid}, `deletedon`={$deletedon} WHERE `id` IN ({$id})"); + } else { + throw new Exception('Invalid IDs list for mark trash:
' . print_r($ids, + 1) . 'please, check ignore list:
' . print_r($ignore, 1) . ''); + } + + return $this; + } + + /** + * @param bool $fire_events + * @return $this + */ + public function clearTrash($fire_events = false) + { + $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `deleted`='1'"); + $_ids = $this->modx->db->getColumn('id', $q); + if (is_array($_ids) && $_ids != array()) { + $this->invokeEvent('OnBeforeEmptyTrash', array( + "ids" => $_ids + ), $fire_events); + + $id = $this->sanitarIn($_ids); + $this->query("DELETE from {$this->makeTable('site_content')} where `id` IN ({$id})"); + $this->query("DELETE from {$this->makeTable('site_tmplvar_contentvalues')} where `contentid` IN ({$id})"); + + $this->invokeEvent('OnEmptyTrash', array( + "ids" => $_ids + ), $fire_events); + } + + return $this; + } + + /** + * @param $ids + * @param int|bool $depth + * @return array + */ + public function children($ids, $depth) + { + $_ids = $this->cleanIDs($ids, ','); + if (is_array($_ids) && $_ids != array()) { + $id = $this->sanitarIn($_ids); + if (! empty($id)) { + $q = $this->query("SELECT `id` FROM {$this->makeTable('site_content')} where `parent` IN ({$id})"); + $id = $this->modx->db->getColumn('id', $q); + if ($depth > 0 || $depth === true) { + $id = $this->children($id, is_bool($depth) ? $depth : ($depth - 1)); + } + $_ids = array_merge($_ids, $id); + } + } + + return $_ids; + } + + /** + * @param string|array $ids + * @param bool $fire_events + * @return $this + * @throws Exception + */ + public function delete($ids, $fire_events = false) + { + $ids = $this->children($ids, true); + $_ids = $this->cleanIDs($ids, ',', $this->systemID()); + $this->invokeEvent('OnBeforeDocFormDelete', array( + 'ids' => $_ids + ), $fire_events); + $this->toTrash($_ids); + $this->invokeEvent('OnDocFormDelete', array( + 'ids' => $_ids + ), $fire_events); + + return $this; + } + + /** + * @return array + */ + private function systemID() + { + $ignore = array( + 0, //empty document + (int)$this->modxConfig('site_start'), + (int)$this->modxConfig('error_page'), + (int)$this->modxConfig('unauthorized_page'), + (int)$this->modxConfig('site_unavailable_page') + ); + $data = $this->query("SELECT DISTINCT setting_value FROM {$this->makeTable('web_user_settings')} WHERE `setting_name`='login_home' AND `setting_value`!=''"); + $data = $this->modx->db->makeArray($data); + foreach ($data as $item) { + $ignore[] = (int)$item['setting_value']; + } + + return array_unique($ignore); + + } + + /** + * @param $alias + * @return string + */ + protected function checkAlias($alias) + { + $alias = strtolower($alias); + if ($this->modxConfig('friendly_urls')) { + $_alias = $this->escape($alias); + if ((! $this->modxConfig('allow_duplicate_alias') && ! $this->modxConfig('use_alias_path')) || ($this->modxConfig('allow_duplicate_alias') && $this->modxConfig('use_alias_path'))) { + $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' AND `parent`={$this->get('parent')} LIMIT 1")); + } else { + $flag = $this->modx->db->getValue($this->query("SELECT `id` FROM {$this->makeTable('site_content')} WHERE `alias`='{$_alias}' LIMIT 1")); + } + if (($flag && $this->newDoc) || (! $this->newDoc && $flag && $this->id != $flag)) { + $suffix = substr($alias, -2); + if (preg_match('/-(\d+)/', $suffix, $tmp) && isset($tmp[1]) && (int)$tmp[1] > 1) { + $suffix = (int)$tmp[1] + 1; + $alias = substr($alias, 0, -2) . '-' . $suffix; + } else { + $alias .= '-2'; + } + $alias = $this->checkAlias($alias); + } + } + + return $alias; + } + + /** + * @param $key + * @return bool + */ + public function issetField($key) + { + return (array_key_exists($key, $this->default_field) || (array_key_exists($key, $this->tv) && $this->belongsToTemplate($this->tv[$key]))); + } + + /** + * @param bool $reload + * @return $this + */ + protected function get_TV($reload = false) + { + $this->modx->_TVnames = $this->loadFromCache('_TVnames'); + if ($this->modx->_TVnames === false || empty($this->modx->_TVnames) || $reload) { + $this->modx->_TVnames = array(); + $result = $this->query('SELECT `id`,`name`,`default_text`,`type`,`display`,`display_params` FROM ' . $this->makeTable('site_tmplvars')); + while ($row = $this->modx->db->GetRow($result)) { + $this->modx->_TVnames[$row['name']] = array( + 'id' => $row['id'], + 'type' => $row['type'], + 'default' => $row['default_text'], + 'display' => $row['display'], + 'display_params' => $row['display_params'] + ); + } + $this->saveToCache($this->modx->_TVnames, '_TVnames'); + } + $arrayTypes = array('checkbox', 'listbox-multiple'); + $arrayTVs = array(); + foreach ($this->modx->_TVnames as $name => $data) { + $this->tvid[$data['id']] = $name; + $this->tv[$name] = $data['id']; + if (in_array($data['type'], $arrayTypes)) { + $arrayTVs[] = $name; + } + } + if (empty($this->tvaFields)) { + $this->tvaFields = $arrayTVs; + } + $this->loadTVTemplate()->loadTVDefault(array_values($this->tv)); + + return $this; + } + + /** + * @return $this + */ + protected function loadTVTemplate() + { + $this->tvTpl = $this->loadFromCache('_tvTpl'); + if ($this->tvTpl === false) { + $q = $this->query("SELECT `tmplvarid`, `templateid` FROM " . $this->makeTable('site_tmplvar_templates')); + $this->tvTpl = array(); + while ($item = $this->modx->db->getRow($q)) { + $this->tvTpl[$item['templateid']][] = $item['tmplvarid']; + } + $this->saveToCache($this->tvTpl, '_tvTpl'); + } + + return $this; + } + + /** + * @param array $tvId + * @return $this + */ + protected function loadTVDefault(array $tvId = array()) + { + if (is_array($tvId) && ! empty($tvId)) { + $this->tvd = array(); + foreach ($tvId as $id) { + $name = $this->tvid[$id]; + $this->tvd[$name] = $this->modx->_TVnames[$name]; + } + } + + return $this; + } + + /** + * @param $tpl + * @return int + * @throws Exception + */ + public function setTemplate($tpl) + { + if (!is_numeric($tpl) || $tpl != (int)$tpl) { + if (is_scalar($tpl)) { + $sql = "SELECT `id` FROM {$this->makeTable('site_templates')} WHERE `templatename` = '" . $this->escape($tpl) . "'"; + $rs = $this->query($sql); + if (! $rs || $this->modx->db->getRecordCount($rs) <= 0) { + throw new Exception("Template {$tpl} is not exists"); + } + $tpl = $this->modx->db->getValue($rs); + } else { + throw new Exception("Invalid template name: " . print_r($tpl, 1)); + } + } + + return (int)$tpl; + } + + /** + * @return string + */ + protected function getAlias() + { + if ($this->modxConfig('friendly_urls') && $this->modxConfig('automatic_alias') && $this->get('alias') == '') { + $alias = strtr($this->get('pagetitle'), $this->table); + } else { + if ($this->get('alias') != '') { + $alias = $this->get('alias'); + } else { + $alias = ''; + } + } + $alias = $this->modx->stripAlias($alias); + + return $this->checkAlias($alias); + } + + /** + * @param int $parent + * @param string $criteria + * @param string $dir + * @return $this + * + * Пересчет menuindex по полю таблицы site_content + */ + public function updateMenuindex($parent, $criteria = 'id', $dir = 'asc') + { + $dir = strtolower($dir) == 'desc' ? 'desc' : 'asc'; + if (is_integer($parent) && $criteria !== '') { + $this->query("SET @index := 0"); + $this->query("UPDATE {$this->makeTable('site_content')} SET `menuindex` = (@index := @index + 1) WHERE `parent`={$parent} ORDER BY {$criteria} {$dir}"); + } + + return $this; + } + + /** + * Устанавливает значение шаблона согласно системной настройке + * + * @return $this + */ + public function setDefaultTemplate() + { + $parent = $this->get('parent'); + $template = $this->modxConfig('default_template'); + switch ($this->modxConfig('auto_template_logic')) { + case 'sibling': + if (! $parent) { + $site_start = $this->modxConfig('site_start'); + $where = "sc.isfolder=0 AND sc.id!={$site_start}"; + $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', $where, 'menuindex', 'ASC', 1); + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { + $template = $sibl[0]['template']; + } + } else { + $sibl = $this->modx->getDocumentChildren($parent, 1, 0, 'template', 'isfolder=0', 'menuindex', + 'ASC', 1); + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { + $template = $sibl[0]['template']; + } else { + $sibl = $this->modx->getDocumentChildren($parent, 0, 0, 'template', 'isfolder=0', 'menuindex', + 'ASC', 1); + if (isset($sibl[0]['template']) && $sibl[0]['template'] !== '') { + $template = $sibl[0]['template']; + } + } + } + break; + case 'parent': + if ($parent) { + $_parent = $this->modx->getPageInfo($parent, 0, 'template'); + if (isset($_parent['template'])) { + $template = $_parent['template']; + } + } + break; + } + $this->set('template', $template); + + return $this; + } + + /** + * Декодирует конкретное поле + * @param string $field Имя поля + * @param bool $store обновить распакованное поле + * @return array ассоциативный массив с данными из json строки + */ + public function decodeField($field, $store = false) + { + $out = array(); + if ($this->isDecodableField($field)) { + $data = $this->get($field); + if ($this->isTVarrayField($field)) { + $out = explode('||', $data); + } else { + $out = jsonHelper::jsonDecode($data, array('assoc' => true), true); + } + } + if ($store) { + $this->field[$field] = $out; + $this->markAsDecode($field); + } + + return $out; + } + + /** + * Запаковывает конкретное поле в JSON + * @param string $field Имя поля + * @param bool $store обновить запакованное поле + * @return string|null json строка + */ + public function encodeField($field, $store = false) + { + $out = null; + if ($this->isEncodableField($field)) { + $data = $this->get($field); + if ($this->isTVarrayField($field)) { + $out = is_array($data) ? implode('||', $data) : (string)$data; + } else { + $out = json_encode($data); + } + } + if ($store) { + $this->field[$field] = $out; + $this->markAsEncode($field); + } + + return $out; + } + + /** + * Может ли содержать данное поле json массив + * @param string $field имя поля + * @return boolean + */ + public function isTVarrayField($field) + { + return (is_scalar($field) && in_array($field, $this->tvaFields)); + } + + /** + * Пометить все поля как запакованные + * @return $this + */ + public function markAllEncode() + { + parent::markAllEncode(); + foreach ($this->tvaFields as $field) { + $this->markAsEncode($field); + } + + return $this; + } + + /** + * Пометить все поля как распакованные + * @return $this + */ + public function markAllDecode() + { + parent::markAllDecode(); + foreach ($this->tvaFields as $field) { + $this->markAsDecode($field); + } + + return $this; + } + + /** + * @param int $docId + */ + public function getDocumentGroups($docId = 0) + { + $out = array(); + $doc = $this->switchObject($docId); + if (null !== $doc->getID()) { + $doc_groups = $this->makeTable('document_groups'); + $docgroup_names = $this->makeTable('documentgroup_names'); + + $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` + WHERE `dg`.`document` = " . $doc->getID()); + while ($row = $this->modx->db->getRow($rs)) { + $out[$row['document_group']] = $row['name']; + } + + } + unset($doc); + + return $out; + } + + /** + * @param int $docId + * @param array $groupIds + * @return $this + */ + public function setDocumentGroups($docId = 0, $groupIds = array()) + { + if (!is_array($groupIds)) { + return $this; + } + if ($this->newDoc && $docId == 0) { + $this->groupIds = $groupIds; + } else { + $doc = $this->switchObject($docId); + if ($id = $doc->getID()) { + foreach ($groupIds as $gid) { + $this->query("REPLACE INTO {$this->makeTable('document_groups')} (`document_group`, `document`) VALUES ('{$gid}', '{$id}')"); + } + if (! $this->newDoc) { + $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); + $this->query("DELETE FROM {$this->makeTable('document_groups')} WHERE `document`={$id} AND `document_group` NOT IN ({$groupIds})"); + } + } + unset($doc); + $this->groupIds = array(); + } + + return $this; + } +} diff --git a/assets/lib/MODxAPI/modUsers.php b/assets/lib/MODxAPI/modUsers.php index 0f22907dd5..64af4797dd 100644 --- a/assets/lib/MODxAPI/modUsers.php +++ b/assets/lib/MODxAPI/modUsers.php @@ -159,7 +159,7 @@ public function close() */ protected function getUserId($id) { $find = $this->findUser($id); - if ($find && !empty($this->userIdCache[$find])) { + if ($find && ! empty($this->userIdCache[$find])) { $id = $this->userIdCache[$find]; } else { $id = null; @@ -179,7 +179,7 @@ public function edit($id) $this->close(); $this->newDoc = false; - if (!$find = $this->findUser($id)) { + if (! $find = $this->findUser($id)) { $this->id = null; } else { $this->set('editedon', time()); @@ -218,7 +218,7 @@ protected function editQuery($find, $id) */ public function set($key, $value) { - if (is_scalar($value) && is_scalar($key) && !empty($key)) { + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { switch ($key) { case 'password': $this->givenPassword = $value; @@ -269,7 +269,7 @@ public function save($fire_events = false, $clearCache = false) return false; } - if ($this->isChanged('username') && !$this->checkUnique('web_users', 'username')) { + if ($this->isChanged('username') && ! $this->checkUnique('web_users', 'username')) { $this->log['UniqueUsername'] = 'username not unique
' . print_r( $this->get('username'), true @@ -278,7 +278,7 @@ public function save($fire_events = false, $clearCache = false) return false; } - if ($this->isChanged('username') && !$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { + if ($this->isChanged('username') && ! $this->checkUnique('web_user_attributes', 'email', 'internalKey')) { $this->log['UniqueEmail'] = 'Email not unique' . print_r($this->get('email'), true) . ''; return false; @@ -293,7 +293,7 @@ public function save($fire_events = false, $clearCache = false) $this->Uset($key, 'user'); unset($fld[$key]); } - if (!empty($this->set['user'])) { + if (! empty($this->set['user'])) { if ($this->newDoc) { $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); } else { @@ -313,7 +313,7 @@ public function save($fire_events = false, $clearCache = false) unset($fld['id']); foreach ($fld as $key => $value) { - if ($value == '' || !$this->isChanged($key)) { + if ($value == '' || ! $this->isChanged($key)) { continue; } $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); @@ -323,7 +323,7 @@ public function save($fire_events = false, $clearCache = false) $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); } } - if (!$this->newDoc && $this->givenPassword) { + if (! $this->newDoc && $this->givenPassword) { $this->invokeEvent('OnWebChangePassword', array( 'userObj' => $this, 'userid' => $this->id, @@ -334,7 +334,7 @@ public function save($fire_events = false, $clearCache = false) ), $fire_events); } - if (!empty($this->groupIds)) { + if (! empty($this->groupIds)) { $this->setUserGroups($this->id, $this->groupIds); } @@ -365,7 +365,7 @@ protected function saveQuery(array &$fld) $this->Uset($key, 'attribute'); unset($fld[$key]); } - if (!empty($this->set['attribute'])) { + if (! empty($this->set['attribute'])) { if ($this->newDoc) { $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode( @@ -467,7 +467,7 @@ public function checkBlock($id = 0) $b = $tmp->get('blocked'); $bu = $tmp->get('blockeduntil'); $ba = $tmp->get('blockedafter'); - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); unset($tmp); return $flag; @@ -492,7 +492,7 @@ public function testAuth($id, $password, $blocker, $fire_events = false) } $flag = $pluginFlag = false; - if ((null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) + if ((null !== $tmp->getID()) && (! $blocker || ($blocker && ! $tmp->checkBlock($id))) ) { $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( 'userObj' => $this, @@ -508,7 +508,7 @@ public function testAuth($id, $password, $blocker, $fire_events = false) } else { $pluginFlag = (bool)$eventResult; } - if (!$pluginFlag) { + if (! $pluginFlag) { $flag = ($tmp->get('password') == $tmp->getPassword($password)); } } @@ -528,7 +528,7 @@ public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_ev if (isset($_COOKIE[$cookieName])) { $cookie = explode('|', $_COOKIE[$cookieName], 4); if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { - if (!$fulltime && isset($cookie[4])) { + if (! $fulltime && isset($cookie[4])) { $fulltime = (int)$cookie[4]; } $this->close(); @@ -538,7 +538,7 @@ public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_ev && null !== $this->getID() && $this->get('password') == $cookie[1] && $this->get('sessionid') == $cookie[2] - && !$this->checkBlock($this->getID()) + && ! $this->checkBlock($this->getID()) ) { $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); } @@ -554,7 +554,7 @@ public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_ev */ public function logOut($cookieName = 'WebLoginPE', $fire_events = false) { - if (!$uid = $this->modx->getLoginUserID('web')) { + if (! $uid = $this->modx->getLoginUserID('web')) { return; } $params = array( @@ -598,7 +598,7 @@ protected function SessionHandler($directive, $cookieName, $remember = true) $_SESSION['webUsrConfigSet'] = array(); $_SESSION['webUserGroupNames'] = $this->getUserGroups(); $_SESSION['webDocgroups'] = $this->getDocumentGroups(); - if (!empty($remember)) { + if (! empty($remember)) { $this->setAutoLoginCookie($cookieName, $remember); } } @@ -650,7 +650,7 @@ public function isSecure() */ public function setAutoLoginCookie($cookieName, $remember = true) { - if (!empty($cookieName) && $this->getID() !== null) { + if (! empty($cookieName) && $this->getID() !== null) { $secure = $this->isSecure(); $remember = is_bool($remember) ? $this->getRememberTime() : (int)$remember; $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); @@ -726,7 +726,7 @@ public function setUserGroups($userID = 0, $groupIds = array()) foreach ($groupIds as $gid) { $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); } - if (!$this->newDoc) { + if (! $this->newDoc) { $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); } diff --git a/assets/lib/Module/Action.php b/assets/lib/Module/Action.php index f06b6189f9..4a953439cb 100644 --- a/assets/lib/Module/Action.php +++ b/assets/lib/Module/Action.php @@ -95,7 +95,7 @@ protected static function _workValue($callback) self::$TPL = 'ajax/getValue'; $data = Helper::jeditable('data'); $out = array(); - if (!empty($data)) { + if (! empty($data)) { $modObj = self::$classTable; $modObj->edit($data['id']); if ($modObj->getID() !== null && ((is_object($callback) && ($callback instanceof \Closure)) || is_callable($callback))) { diff --git a/assets/lib/Module/Helper.php b/assets/lib/Module/Helper.php index 14d23f85f1..449ab3ffcd 100644 --- a/assets/lib/Module/Helper.php +++ b/assets/lib/Module/Helper.php @@ -70,7 +70,7 @@ public static function jeditable($key = 'id', $post = true) isset($request[$key]) && is_scalar($request[$key]) && preg_match("/^(.*)_(\d+)$/i", $request[$key], $match) ) ? $match : array(); - if (!empty($match)) { + if (! empty($match)) { $data = array( 'key' => $match[1], 'id' => $match[2] @@ -96,7 +96,7 @@ public static function curl($url, $data = '', $post = false, array $header = arr if ($post) { curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } - if (!empty($header)) { + if (! empty($header)) { curl_setopt($ch, CURLOPT_HTTPHEADER, $header); } curl_setopt($ch, CURLOPT_TIMEOUT, 10); diff --git a/assets/lib/Module/Template.php b/assets/lib/Module/Template.php old mode 100755 new mode 100644 index 08ddcd1309..794d19484b --- a/assets/lib/Module/Template.php +++ b/assets/lib/Module/Template.php @@ -7,13 +7,13 @@ abstract class Template { /** - * @var \DocumentParser|null + * @var \DocumentParser */ - protected $_modx = null; + protected $_modx; /** - * @var null|string + * @var string */ - protected $_tplFolder = null; + protected $_tplFolder; /** * @var string */ @@ -47,7 +47,7 @@ abstract class Template * Template constructor. * @param \DocumentParser $modx * @param bool $ajax - * @param null $tplFolder + * @param null|string $tplFolder */ public function __construct(\DocumentParser $modx, $ajax = false, $tplFolder = null) { @@ -166,7 +166,7 @@ public function showBody($TplName, array $tplParams = array()) /** * @param $key * @param array $param - * @param null $default + * @param mixed $default * @return mixed|null */ public static function getParam($key, array $param = array(), $default = null) @@ -177,7 +177,7 @@ public static function getParam($key, array $param = array(), $default = null) /** * @param $action * @param array $data - * @param null $module + * @param null|int|string $module * @param bool $full * @return string */ diff --git a/assets/lib/SimpleTab/controller.abstract.php b/assets/lib/SimpleTab/controller.abstract.php index 544b36a986..691ff37147 100644 --- a/assets/lib/SimpleTab/controller.abstract.php +++ b/assets/lib/SimpleTab/controller.abstract.php @@ -72,7 +72,7 @@ public function remove() $ids = isset($_POST['ids']) ? (string)$_POST['ids'] : ''; $ids = isset($_POST['id']) ? (string)$_POST['id'] : $ids; $out['success'] = false; - if (!empty($ids)) { + if (! empty($ids)) { if ($this->data->deleteAll($ids, $this->rid)) { $out['success'] = true; } @@ -90,7 +90,7 @@ public function place() $ids = isset($_POST['ids']) ? (string)$_POST['ids'] : ''; $dir = isset($_POST['dir']) ? $_POST['dir'] : 'top'; $out['success'] = false; - if (!empty($ids)) { + if (! empty($ids)) { if ($this->data->place($ids, $dir, $this->rid)) { $out['success'] = true; } @@ -125,7 +125,7 @@ public function reorder() */ public function listing() { - if (!$this->rid) { + if (! $this->rid) { $this->isExit = true; return; diff --git a/assets/lib/SimpleTab/plugin.class.php b/assets/lib/SimpleTab/plugin.class.php index 0b9b663881..2379ba7183 100644 --- a/assets/lib/SimpleTab/plugin.class.php +++ b/assets/lib/SimpleTab/plugin.class.php @@ -102,10 +102,9 @@ public function checkPermissions() $templates = isset($this->params['templates']) ? explode(',', $this->params['templates']) : false; $roles = isset($this->params['roles']) ? explode(',', $this->params['roles']) : false; - $tplFlag = ($this->checkTemplate && !$templates || ($templates && !in_array( - $this->params['template'], - $templates - ))); + $tplFlag = ($this->checkTemplate && ( + ! $templates || ($templates && !in_array($this->params['template'],$templates)) + )); $documents = isset($this->params['documents']) ? explode(',', $this->params['documents']) : false; $docFlag = ($this->checkId && $tplFlag) ? !($documents && in_array($this->params['id'], $documents)) : $tplFlag; @@ -121,9 +120,9 @@ public function checkPermissions() */ public function prerender() { - if (!$this->checkTable()) { + if (! $this->checkTable()) { $result = $this->createTable(); - if (!$result) { + if (! $result) { $this->modx->logEvent(0, 3, "Cannot create {$this->table} table.", $this->pluginName); return; @@ -184,7 +183,7 @@ public function getTplPlaceholders() */ public function render() { - if (!$this->checkPermissions()) { + if (! $this->checkPermissions()) { $output = $this->prerender(); if ($output !== false) { $ph = $this->getTplPlaceholders(); @@ -205,7 +204,7 @@ public function render() */ public function renderEmpty() { - if (!$this->checkPermissions()) { + if (! $this->checkPermissions()) { $tpl = MODX_BASE_PATH . $this->emptyTpl; if ($this->fs->checkFile($tpl)) { $output = '[+js+]' . file_get_contents($tpl); @@ -249,9 +248,9 @@ public function registerEvents($events = array(), $eventsType = '6') $eventsTable = $this->modx->getFullTableName('system_eventnames'); foreach ($events as $event) { $result = $this->modx->db->select('`id`', $eventsTable, "`name` = '{$event}'"); - if (!$this->modx->db->getRecordCount($result)) { + if (! $this->modx->db->getRecordCount($result)) { $sql = "INSERT INTO {$eventsTable} VALUES (NULL, '{$event}', '{$eventsType}', '{$this->pluginName} Events')"; - if (!$this->modx->db->query($sql)) { + if (! $this->modx->db->query($sql)) { $this->modx->logEvent(0, 3, "Cannot register {$event} event.", $this->pluginName); } } diff --git a/assets/lib/SimpleTab/table.abstract.php b/assets/lib/SimpleTab/table.abstract.php index dd2d57f45c..7dfe634bf3 100644 --- a/assets/lib/SimpleTab/table.abstract.php +++ b/assets/lib/SimpleTab/table.abstract.php @@ -123,7 +123,7 @@ public function deleteThumb($url, $cache = false) } $dir = $this->fs->takeFileDir($url); $iterator = new \FilesystemIterator($dir); - if (!$iterator->valid()) { + if (! $iterator->valid()) { rmdir($dir); } if ($cache) { diff --git a/assets/lib/class.modxRTEbridge.php b/assets/lib/class.modxRTEbridge.php index 448c5fa28b..5279133f8b 100755 --- a/assets/lib/class.modxRTEbridge.php +++ b/assets/lib/class.modxRTEbridge.php @@ -452,11 +452,11 @@ public function renderConfigRawString() // Get final value of editor-config public function determineValue($key, $conf=NULL) { - if($conf == NULL) { $conf = $this->themeConfig[$key]; }; + if($conf == NULL && isset($this->themeConfig[$key])) { $conf = $this->themeConfig[$key]; }; $value = isset($this->themeConfig[$key]['bridged']) ? $this->themeConfig[$key]['bridged'] : NULL; $value = $value === NULL && isset($this->themeConfig[$key]['force']) ? $this->themeConfig[$key]['force'] : $value; - $value = $value === NULL ? $this->themeConfig[$key]['value'] : $value; + $value = $value === NULL && isset($this->themeConfig[$key]['value']) ? $this->themeConfig[$key]['value'] : $value; if(!in_array($conf['type'], array('boolean','bool'))) { if ($value === '' && $conf['empty'] === false) { // Empty values not allowed @@ -966,7 +966,7 @@ public function getTemplateChunkList() $templatesArr = array(); - if ($modx->getLoginUserType() === 'manager') { + if ($modx->getLoginUserType() === 'manager' || IN_MANAGER_MODE) { $modx->getSettings(); $ids = $modx->config[$this->editorKey.'_template_docs']; @@ -1017,7 +1017,7 @@ public function saveContentProcessor($rid, $ppPluginName, $ppEditableIds='editab { global $modx; - if ($rid > 0 && $modx->getLoginUserType() === 'manager') + if ($rid > 0 && ($modx->getLoginUserType() === 'manager' || IN_MANAGER_MODE)) { if(!isset($_POST['secHash']) || !isset($_SESSION['modxRTEbridge']['secHash'][$rid]) || diff --git a/assets/lib/class.summary.php b/assets/lib/class.summary.php index 9ec665d7bb..0e325690bd 100644 --- a/assets/lib/class.summary.php +++ b/assets/lib/class.summary.php @@ -41,9 +41,9 @@ class SummaryText /** * SummaryText constructor. - * @param $text - * @param $action - * @param null $break + * @param string $text + * @param string $action + * @param null|string $break */ public function __construct($text, $action, $break = null) { @@ -214,7 +214,7 @@ protected function html_substr($posttext, $minimum_length = 200, $length_offset } else { $next_char = ""; } - if (!$quotes_on) { + if (! $quotes_on) { // Check if it's a tag // On a "<" add 3 if it's an opening tag (like ) @@ -354,7 +354,7 @@ private function closeTags($text) if (mb_strstr($tag, ' ', 'UTF-8')) { $tag = mb_substr($tag, 0, strpos($tag, ' '), 'UTF-8'); } - if (!mb_stristr($tag, 'br', 'UTF-8') && !mb_stristr($tag, 'img', 'UTF-8') && !empty($tag)) { + if (! mb_stristr($tag, 'br', 'UTF-8') && ! mb_stristr($tag, 'img', 'UTF-8') && ! empty($tag)) { $endTags .= '' . $tag . '>'; } } diff --git a/assets/modules/docmanager/tv.ajax.php b/assets/modules/docmanager/tv.ajax.php index b51ce802df..bf3d2f7dbd 100755 --- a/assets/modules/docmanager/tv.ajax.php +++ b/assets/modules/docmanager/tv.ajax.php @@ -93,7 +93,7 @@ function renderFormElement($field_type, $field_id, $default_text, $field_element case "dropdown": // handler for select boxes $field_html .= '