admintools.class.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <?php
  2. /**
  3. * The base class for AdminTools.
  4. */
  5. class AdminTools
  6. {
  7. /* @var modX $modx */
  8. public $modx;
  9. public $initialized = [];
  10. protected $config = [];
  11. /**
  12. * @param modX $modx
  13. * @param array $config
  14. */
  15. function __construct(modX &$modx, array $config = [])
  16. {
  17. $this->modx =& $modx;
  18. $corePath = $this->modx->getOption('admintools_core_path', $config, $this->modx->getOption('core_path') . 'components/admintools/');
  19. $assetsUrl = $this->modx->getOption('admintools_assets_url', $config, $this->modx->getOption('assets_url') . 'components/admintools/');
  20. $connectorUrl = $assetsUrl . 'connector.php';
  21. $this->config = array_merge([
  22. 'assetsUrl' => $assetsUrl,
  23. 'cssUrl' => $assetsUrl . 'css/',
  24. 'jsUrl' => $assetsUrl . 'js/',
  25. 'connectorUrl' => $connectorUrl,
  26. 'corePath' => $corePath,
  27. 'modelPath' => $corePath . 'model/',
  28. 'templatesPath' => $corePath . 'elements/templates/',
  29. 'processorsPath' => $corePath . 'processors/',
  30. 'unlockCode' => $this->modx->getOption('admintools_unlock_code', null, ''),
  31. 'lockTimeout' => $this->modx->getOption('admintools_lock_timeout', null, 0) * 60 * 1000,
  32. 'show_lockmenu' => $this->modx->getOption('admintools_show_lockmenu', null, true),
  33. ], $config);
  34. if (!$this->modx->addPackage('admintools', $this->config['modelPath'])) {
  35. $this->modx->log(modX::LOG_LEVEL_ERROR, '[adminTools] Can\'t load the package.');
  36. }
  37. $this->modx->lexicon->load('admintools:default');
  38. }
  39. public function initialize($ctx = 'mgr')
  40. {
  41. switch ($ctx) {
  42. case 'mgr':
  43. if (empty($this->initialized[$ctx])) {
  44. $this->modx->controller->addLexiconTopic('admintools:default');
  45. $this->modx->controller->addCss($this->config['cssUrl'] . 'mgr/main.css');
  46. $theme = $this->modx->getOption('admintools_theme', null, '');
  47. $theme = trim($theme) == 'default' ? '' : trim($theme);
  48. if (!empty($theme)) {
  49. $themeCssFile = 'mgr/themes/' . $theme . '.css';
  50. $this->modx->controller->addCss($this->config['cssUrl'] . $themeCssFile);
  51. $theme .= '-theme';
  52. }
  53. // Custom style files
  54. if ($customCSS = $this->modx->getOption('admintools_custom_css')) {
  55. $customCSS = explode(',', $customCSS);
  56. foreach ($customCSS as $cssFile) {
  57. $cssFile = str_replace('{adminToolsCss}', $this->config['cssUrl'] . 'mgr/', $cssFile);
  58. $this->modx->controller->addCss($cssFile);
  59. }
  60. }
  61. $this->modx->controller->addJavascript($this->config['jsUrl'] . 'mgr/admintools.js');
  62. /** @var bool $pElementTree Permission for the element tree */
  63. $pElementTree = $this->modx->hasPermission('element_tree');
  64. // favorite elements
  65. if ($pElementTree && $this->modx->getOption('admintools_enable_favorite_elements', null, true)) {
  66. $this->modx->controller->addLastJavascript($this->config['jsUrl'] . 'mgr/favorites.js');
  67. // View "All/Favorites"
  68. $states = $this->getFromProfile('adminToolsStates');
  69. if (empty($states)) {
  70. $_SESSION['admintools']['favoriteElements']['states'] = ['template' => false, 'chunk' => false, 'tv' => false, 'plugin' => false, 'snippet' => false];
  71. $this->saveToProfile($_SESSION['admintools']['favoriteElements']['states'], 'adminToolsStates');
  72. //$this->saveToCache($_SESSION['admintools']['favoriteElements']['states'], 'states', 'favorite_elements/' . $this->modx->user->id);
  73. } else {
  74. $_SESSION['admintools']['favoriteElements']['states'] = $states;
  75. }
  76. // Get favorites elements
  77. $elements = $this->getFromProfile('adminToolsElements');
  78. if (empty($elements)) {
  79. $_SESSION['admintools']['favoriteElements']['elements'] = [
  80. 'templates' => [],
  81. 'tvs' => [],
  82. 'chunks' => [],
  83. 'plugins' => [],
  84. 'snippets' => [],
  85. ];
  86. $this->saveToProfile($_SESSION['admintools']['favoriteElements']['elements'], 'adminToolsElements');
  87. } else {
  88. $_SESSION['admintools']['favoriteElements']['elements'] = $elements;
  89. }
  90. $_SESSION['admintools']['favoriteElements']['icon'] = $this->modx->getOption('admintools_favorites_icon') ? 'icon ' . $this->modx->getOption('admintools_favorites_icon') : '';
  91. }
  92. // system settings
  93. if ($this->modx->hasPermission('settings') && $this->modx->getOption('admintools_remember_system_settings', null, true)) {
  94. $this->modx->controller->addLastJavascript($this->config['jsUrl'] . 'mgr/systemsettings.js');
  95. $settings = $this->getFromProfile('systemSettings');
  96. if (empty($settings)) {
  97. $_SESSION['admintools']['systemSettings'] = ['namespace' => 'core', 'area' => ''];
  98. $this->saveToProfile($_SESSION['admintools']['systemSettings'], 'systemSettings');
  99. } else {
  100. $_SESSION['admintools']['systemSettings'] = $settings;
  101. }
  102. if (empty($_SESSION['admintools']['systemSettings']['namespace'])) {
  103. $_SESSION['admintools']['systemSettings']['namespace'] = 'core';
  104. }
  105. }
  106. // edited elements log
  107. if ($pElementTree && $this->modx->getOption('admintools_enable_elements_log', null, true)) {
  108. $this->modx->controller->addLastJavascript($this->config['jsUrl'] . 'mgr/elementlog.js');
  109. $this->modx->controller->addLexiconTopic('manager_log');
  110. }
  111. // admin notes
  112. if ($this->modx->getOption('admintools_enable_notes', null, true)) {
  113. $this->modx->controller->addLastJavascript($this->config['jsUrl'] . 'mgr/notes.js');
  114. }
  115. // Hide components description
  116. $_css = '';
  117. if ($this->modx->getOption('admintools_hide_component_description', null, true)) {
  118. $_css .= "\t#limenu-components ul.modx-subnav li a span.description {display: none;}\n";
  119. }
  120. // Animate the main menu
  121. if ($this->modx->getOption('admintools_animate_menu', null, true)) {
  122. $_css .= "\t#modx-navbar ul.modx-subnav, #modx-navbar ul.modx-subsubnav {transition: all .2s ease-in .2s;} \n";
  123. $_css .= "\t#modx-navbar ul.modx-subsubnav {display:block !important;opacity: 0; visibility: hidden;} \n";
  124. $_css .= "\t#modx-navbar ul.modx-subnav li:hover ul.modx-subsubnav {opacity: 1; visibility: visible;} \n";
  125. }
  126. if ($_css) {
  127. $this->modx->controller->addHtml("<style>\n" . $_css . "</style>");
  128. }
  129. // Plugins
  130. if ($pElementTree && $this->modx->getOption('admintools_plugins_events', null, true)) {
  131. $this->modx->controller->addLastJavascript($this->config['jsUrl'] . 'mgr/plugins.js');
  132. }
  133. // taskpanel
  134. /*
  135. if ($this->modx->getOption('admintools_enable_taskpanel',null,false)) {
  136. $this->modx->controller->addLastJavascript($this->config['jsUrl'] . 'mgr/taskpanel.js');
  137. }
  138. */
  139. // config
  140. $region = $this->modx->getOption('admintools_modx_tree_position', null, 'left', true) == 'right' ? 'east' : 'west';
  141. if ($region == 'east') {
  142. $scripts = "<script>let sideBarRegion = '{$region}'</script>\n";
  143. $scripts .= $this->modx->smarty->get_template_vars('maincssjs');
  144. $layout_src = $this->getOption('jsUrl') . 'mgr/core/modx.layout.js';
  145. $scripts .= "<script src=\"{$layout_src}\"></script>";
  146. $this->modx->smarty->assign('maincssjs', $scripts);
  147. }
  148. // Messages
  149. $messageNumber = $this->modx->getOption('admintools_messages', null, true)
  150. ? $this->modx->getCount('modUserMessage', ['recipient' => $this->modx->user->id, 'read' => 0])
  151. : -1;
  152. // Lock
  153. $_SESSION['admintools']['locked'] = isset($_SESSION['admintools']['locked']) ? $_SESSION['admintools']['locked'] : false;
  154. $_SESSION['admintools']['config'] = [
  155. 'connector_url' => $this->config['assetsUrl'] . 'connector.php',
  156. 'theme' => $theme,
  157. 'region' => $region,
  158. 'lock_timeout' => $this->config['lockTimeout'],
  159. 'show_lockmenu' => $this->config['show_lockmenu'],
  160. 'messages' => $messageNumber,
  161. ];
  162. $scripts = "<script>\n";
  163. $scripts .= "\tlet adminToolsSettings = " . $this->modx->toJSON(array_merge($_SESSION['admintools'], ['currentUser' => $this->modx->user->id])) . ";\n";
  164. // Package Denies
  165. $packageActions = $this->modx->getOption('admintools_package_actions', null, '{}', true);
  166. $scripts .= "\tlet adminToolsPackageActions = " . $packageActions . ";\n";
  167. $scripts .= "</script>";
  168. $this->modx->controller->addHtml($scripts);
  169. // Custom javascript files
  170. if ($customJS = $this->modx->getOption('admintools_custom_js')) {
  171. $customJS = explode(',', $customJS);
  172. foreach ($customJS as $jsFile) {
  173. $jsFile = str_replace('{adminToolsJs}', $this->config['jsUrl'] . 'mgr/', $jsFile);
  174. $this->modx->controller->addLastJavascript($jsFile);
  175. }
  176. }
  177. $this->initialized[$ctx] = true;
  178. }
  179. break;
  180. case 'web':
  181. break;
  182. }
  183. return true;
  184. }
  185. /**
  186. * @param $key
  187. * @param mixed $value
  188. * @internal param $property
  189. */
  190. public function setOption($key, $value)
  191. {
  192. if (!empty($key)) {
  193. $this->config[$key] = $value;
  194. }
  195. }
  196. /**
  197. * @param $property
  198. * @param string $default
  199. * @return mixed
  200. */
  201. public function getOption($property, $default = '')
  202. {
  203. return isset($this->config[$property]) ? $this->config[$property] : $default;
  204. }
  205. /**
  206. * @return array
  207. */
  208. public function getOptions()
  209. {
  210. return $this->config;
  211. }
  212. public function getFromProfile($key)
  213. {
  214. if ($this->modx->user->isAuthenticated('mgr')) {
  215. $profile = $this->modx->user->getOne('Profile');
  216. $fields = $profile->get('extended');
  217. if (isset($fields[$key])) {
  218. return $fields[$key];
  219. } else {
  220. return false;
  221. }
  222. } else {
  223. return false;
  224. }
  225. }
  226. /**
  227. * @param array $data
  228. * @param string $key
  229. */
  230. public function saveToProfile($data, $key)
  231. {
  232. if ($this->modx->user->isAuthenticated('mgr')) {
  233. $profile = $this->modx->user->getOne('Profile');
  234. $fields = $profile->get('extended');
  235. $fields[$key] = $data;
  236. $profile->set('extended', $fields);
  237. if (!$profile->save()) {
  238. $this->modx->log(modX::LOG_LEVEL_ERROR, '[' . __METHOD__ . '] Could not save extended fields = ' . print_r($fields, 1));
  239. }
  240. }
  241. }
  242. /**
  243. * @param array $object
  244. * @deprecated
  245. */
  246. public function updateElementLog(array $object)
  247. {
  248. $type = explode('/', $object['action']);
  249. $elementData = [
  250. 'type' => $type[1],
  251. 'eid' => $object['id'],
  252. 'name' => $type[1] == 'template' ? $object['templatename'] : $object['name'],
  253. 'editedon' => date('Y-m-d H:i:s'),
  254. 'user' => $this->modx->user->get('username'),
  255. ];
  256. $key = $elementData['type'] . '-' . $elementData['eid'];
  257. $data[$key] = $elementData;
  258. $elements = $this->getFromCache('element_log', 'elementlog/');
  259. if (is_array($elements)) {
  260. if (isset($elements[$key])) {
  261. unset($elements[$key]);
  262. }
  263. $elements = array_merge($data, $elements);
  264. } else {
  265. $elements = $data;
  266. }
  267. $this->saveToCache($elements, 'element_log', 'elementlog/');
  268. }
  269. /**
  270. * @deprecated
  271. * @return mixed
  272. */
  273. public function getElementLog()
  274. {
  275. return $this->getFromCache('element_log', 'elementlog/');
  276. }
  277. /**
  278. * @param modResource $resource
  279. */
  280. public function clearResourceCache(&$resource)
  281. {
  282. // $resource->clearCache();
  283. $resource->_contextKey = $resource->context_key;
  284. /** @var modCacheManager $cache */
  285. $cache = $this->modx->cacheManager->getCacheProvider($this->modx->getOption('cache_resource_key', null, 'resource'));
  286. $key = $resource->getCacheKey();
  287. $cache->delete($key, ['deleteTop' => true]);
  288. $cache->delete($key);
  289. $this->modx->_clearResourceCache = true;
  290. $this->modx->cacheManager = new atCacheManager($this->modx);
  291. }
  292. public function sendLoginLink($data)
  293. {
  294. $c = $this->modx->newQuery('modUser');
  295. $c->select(['modUser.*', 'Profile.email', 'Profile.fullname']);
  296. $c->innerJoin('modUserProfile', 'Profile');
  297. $c->where([
  298. 'modUser.username' => $data['userdata'],
  299. 'OR:Profile.email:=' => $data['userdata'],
  300. ]);
  301. $c->where([
  302. 'modUser.active' => 1,
  303. 'Profile.blocked' => 0,
  304. ]);
  305. $message = '';
  306. /** @var modUser $user */
  307. $user = $this->modx->getObject('modUser', $c);
  308. if ($user) {
  309. $this->modx->user = $user;
  310. if (!$this->modx->hasPermission('frames')) {
  311. $message = $this->modx->lexicon('admintools_user_not_found');
  312. $this->modx->user = null;
  313. $this->modx->user = $this->modx->getUser();
  314. return $message;
  315. }
  316. $hash = $this->addLoginState($user);
  317. if (!empty($hash)) {
  318. $key = md5($_SERVER['REMOTE_ADDR'] . '/' . $_SERVER['HTTP_USER_AGENT'] . $user->id);
  319. $args = ['a' => 'login', 'id' => $key, 'hash' => $hash];
  320. $url = $this->modx->makeUrl($this->modx->resource->id, '', $args, 'full');
  321. $options['email_body'] = $this->modx->lexicon('admintools_authorization_email_body', ['url' => $url]);
  322. $this->sendEmail($user->get('email'), $options);
  323. } else {
  324. $message = $this->modx->lexicon('admintools_link_already_sent');
  325. }
  326. } else {
  327. $message = $this->modx->lexicon('admintools_user_not_found');
  328. }
  329. return $message;
  330. }
  331. /**
  332. * @param modUser $user
  333. * @return bool
  334. */
  335. public function addLoginState($user)
  336. {
  337. $hash = '';
  338. $key = md5($_SERVER['REMOTE_ADDR'] . '/' . $_SERVER['HTTP_USER_AGENT'] . $user->id);
  339. $state = $this->getLoginState($key);
  340. if (empty($state)) {
  341. $ttl = $this->modx->getOption('admintools_authorization_ttl', null, 200);
  342. $hash = md5(uniqid(md5($user->get('email') . '/' . $key), true));
  343. $this->modx->registry->user->subscribe('/admintools/login/');
  344. $this->modx->registry->user->send('/admintools/login/', [
  345. $key => [
  346. 'hash' => $hash,
  347. 'uid' => $user->get('id'),
  348. ],
  349. ], ['ttl' => $ttl]);
  350. }
  351. return $hash;
  352. }
  353. public function getLoginState($key)
  354. {
  355. $data = '';
  356. if ($this->modx->getService('registry', 'registry.modRegistry')) {
  357. $this->modx->registry->addRegister('user', 'registry.modDbRegister');
  358. $this->modx->registry->user->connect();
  359. $this->modx->registry->user->subscribe('/admintools/login/' . $key);
  360. if ($msgs = $this->modx->registry->user->read(['remove_read' => false, 'poll_limit' => 1])) {
  361. $data = reset($msgs);
  362. }
  363. }
  364. return $data;
  365. }
  366. public function deleteLoginState($key)
  367. {
  368. $deleted = false;
  369. if ($this->modx->getService('registry', 'registry.modRegistry')) {
  370. $this->modx->registry->addRegister('user', 'registry.modDbRegister');
  371. $this->modx->registry->user->connect();
  372. $this->modx->registry->user->subscribe('/admintools/login/' . $key);
  373. $this->modx->registry->user->read(['remove_read' => true, 'poll_limit' => 1]);
  374. $deleted = true;
  375. }
  376. return $deleted;
  377. }
  378. /**
  379. * Sends email with authorization link
  380. *
  381. * @param $email
  382. * @param array $options
  383. *
  384. * @return string|bool
  385. */
  386. public function sendEmail($email, array $options = [])
  387. {
  388. /** @var modPHPMailer $mail */
  389. $mail = $this->modx->getService('mail', 'mail.modPHPMailer');
  390. $mail->set(modMail::MAIL_SUBJECT, $this->modx->getOption('email_subject', $options, $this->modx->lexicon('admintools_authorization_email_subject')));
  391. $mail->set(modMail::MAIL_BODY, $this->modx->getOption('email_body', $options, ''));
  392. $mail->set(modMail::MAIL_SENDER, $this->modx->getOption('email_from', $options, $this->modx->getOption('emailsender'), true));
  393. $mail->set(modMail::MAIL_FROM, $this->modx->getOption('email_from', $options, $this->modx->getOption('emailsender'), true));
  394. $mail->set(modMail::MAIL_FROM_NAME, $this->modx->getOption('email_from_name', $options, $this->modx->getOption('site_name'), true));
  395. $mail->address('to', $email);
  396. $mail->address('reply-to', $this->modx->getOption('email_from', $options, $this->modx->getOption('emailsender'), true));
  397. $mail->setHTML(true);
  398. $response = !$mail->send()
  399. ? $mail->mailer->errorInfo
  400. : true;
  401. $mail->reset();
  402. return $response;
  403. }
  404. public function loginUser($userId)
  405. {
  406. $error_message = '';
  407. /** @var modUser $user */
  408. if ($user = $this->modx->getObject('modUser', $userId)) {
  409. $data['username'] = $user->get('username');
  410. $data['password'] = 'password';
  411. $data['login_context'] = 'mgr';
  412. $data['addContexts'] = [];
  413. $data['rememberme'] = (int)$this->modx->getOption('admintools_rememberme', null, 0);
  414. } else {
  415. return 'Error when try to login.';
  416. }
  417. $query = $this->modx->newQuery('modPlugin', [
  418. 'name' => 'AdminTools',
  419. ]);
  420. $query->select('id');
  421. $id = $this->modx->getValue($query->prepare());
  422. if (!empty($id)) {
  423. // $this->modx->addEventListener('OnManagerPageBeforeRender', $id);
  424. // $this->modx->addEventListener('OnManagerAuthentication', $id);
  425. $this->modx->eventMap['OnManagerPageBeforeRender'][$id] = $id;
  426. $this->modx->eventMap['OnManagerAuthentication'][$id] = $id;
  427. } else {
  428. $error_message = $this->modx->lexicon('admintools_plugin_not_found');
  429. return $error_message;
  430. }
  431. $this->modx->setOption('admintools_user_can_login', true);
  432. /** @var modProcessorResponse $response */
  433. $response = $this->modx->runProcessor('security/login', $data);
  434. if (($response instanceof modProcessorResponse) && !$response->isError()) {
  435. $key = md5($_SERVER['REMOTE_ADDR'] . '/' . $_SERVER['HTTP_USER_AGENT'] . $userId);
  436. $this->deleteLoginState($key);
  437. $url = $this->modx->getOption('manager_url', null, MODX_MANAGER_URL);
  438. $url = $this->modx->getOption('url_scheme', null, MODX_URL_SCHEME) . $this->modx->getOption('http_host', null, MODX_HTTP_HOST) . rtrim($url, '/');
  439. $this->modx->sendRedirect($url);
  440. } else {
  441. $errors = $response->getAllErrors();
  442. $error_message = implode("\n", $errors);
  443. }
  444. return $error_message;
  445. }
  446. /**
  447. * @param int $rid Resource id
  448. * @return bool
  449. */
  450. public function hasPermissions($rid = 0)
  451. {
  452. //TODO-sergant Сделать map файл.
  453. if ($rid == 0) {
  454. $rid = $this->modx->resource->get('id');
  455. }
  456. $user = $this->modx->user;
  457. $userId = $this->modx->user->get('id');
  458. $q = $this->modx->newQuery('adminToolsPermissions');
  459. $q->setClassAlias('Permissions');
  460. // $q->leftJoin('modUserProfile','User', 'Permissions.principal = User.internalKey AND Permissions.principal_type = "usr"');
  461. $q->leftJoin('modUserGroup', 'Group', 'Permissions.principal = Group.id AND Permissions.principal_type = "grp"');
  462. $q->select('Permissions.*, Group.name as groupname');
  463. $q->where([
  464. 'Permissions.rid' => $rid,
  465. ]);
  466. $q->sortby('Permissions.weight', 'ASC');
  467. $q->sortby('Permissions.priority', 'ASC');
  468. $tstart = microtime(true);
  469. if ($q->prepare() && $q->stmt->execute()) {
  470. $this->modx->queryTime += microtime(true) - $tstart;
  471. $this->modx->executedQueries++;
  472. $permissions = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
  473. }
  474. $allow = true;
  475. if (!empty($permissions)) {
  476. foreach ($permissions as $permission) {
  477. switch ($permission['principal_type']) {
  478. case 'all':
  479. $allow = (bool)$permission['status'];
  480. break;
  481. case 'gst':
  482. if ($userId == 0) {
  483. $allow = (bool)$permission['status'];
  484. }
  485. break;
  486. case 'grp':
  487. if ($userId && $user->isMember($permission['groupname'])) {
  488. $allow = (bool)$permission['status'];
  489. }
  490. break;
  491. case 'usr':
  492. if ($userId == $permission['principal']) {
  493. $allow = (bool)$permission['status'];
  494. }
  495. break;
  496. }
  497. }
  498. }
  499. return $allow;
  500. }
  501. public function createResourceCache($uri = '/')
  502. {
  503. $siteUrl = $this->modx->getOption('site_url');
  504. /** @var modRestCurlClient $client */
  505. $client = $this->modx->getService('rest.modRestCurlClient');
  506. $result = $client->request($siteUrl, $uri, 'POST');
  507. }
  508. public function isLocked()
  509. {
  510. return !empty($_SESSION['admintools']['locked']);
  511. }
  512. public function unlock($unlockCode)
  513. {
  514. if (!empty($unlockCode)) {
  515. $_SESSION['admintools']['locked'] = empty($this->config['unlockCode'])
  516. ? !$this->modx->user->passwordMatches($unlockCode)
  517. : $this->config['unlockCode'] !== $unlockCode;
  518. }
  519. return !$_SESSION['admintools']['locked'];
  520. }
  521. public function getInputPlaceholder()
  522. {
  523. return empty($this->config['unlockCode']) ? $this->modx->lexicon('admintools_enter_password') : $this->modx->lexicon('admintools_enter_unlockcode');
  524. }
  525. }
  526. /**
  527. * Cache manager class for adminTools.
  528. */
  529. require_once MODX_CORE_PATH . 'model/modx/modcachemanager.class.php';
  530. class atCacheManager extends modCacheManager
  531. {
  532. public function refresh(array $providers = [], array &$results = [])
  533. {
  534. if ($this->modx->getOption('admintools_clear_only_resource_cache', null, false) && !empty($this->modx->_clearResourceCache)) {
  535. $this->modx->_clearResourceCache = false;
  536. unset($providers['resource']);
  537. $this->modx->cacheManager = null;
  538. $this->modx->getCacheManager();
  539. }
  540. return parent::refresh($providers, $results);
  541. }
  542. }