Изменение заголовка ресурса в админке на лету (OnDocFormRender)
03 июня 2020, 17:20
switch ($modx->event->name) { case 'OnDocFormRender': if ($mode != 'upd') return; if ($event = $modx->getObject('Event', ['resource_id' => $resource->id])) { $modx->controller->addHtml('<script>Ext.onReady(function(){ setTimeout(function(){ Ext.getCmp("modx-resource-pagetitle").setValue("' . addslashes($event->title) . '"); Ext.getCmp("modx-resource-description").setValue("' . addslashes(strip_tags($event->description)) . '"); }, 300); });</script>'); } break; }
Читать дальше
Зависимые комбобоксы в форме ExtJS
01 июня 2020, 11:24
Чтобы обновить список внутри одного комбобокса, нужно добавить listener в другой комбобокс:
Читать дальше
listeners : { 'select' : { fn : function(tf, nv, ov) { Ext.getCmp('mycomponent-panel-object-model_id').reset(); Ext.getCmp('mycomponent-panel-object-model_id').baseParams.brand_id = tf.getValue(); Ext.getCmp('mycomponent-panel-object-model_id').getStore().load(); }, scope : this } }
Читать дальше
Combobox в виде динамических чекбоксов
01 июня 2020, 11:19
Поля в форме:
Читать дальше
{ /* При изменении значения этого комбобокса будут перестраиваться чекбоксы */ xtype : 'mycomponent-combo-select', fieldLabel : _('mycomponent.select'), name : 'select_id', anchor : '99%', allowBlank : false, listeners : { 'select' : { fn : function(tf, nv, ov) { if (Ext.get('mycomponent-checkbox-dynamic')) { Ext.get('mycomponent-checkbox-dynamic').parent().parent().remove(); } Ext.getCmp('mycomponent-panel-checkboxes-panel').add({ xtype : 'mycomponent-checkbox-dynamic', fieldLabel : _('mycomponent.checkboxes'), id : 'mycomponent-panel-checkbox-dynamic', anchor : '99%', select_id : tf.value }); Ext.getCmp('mycomponent-panel-checkboxes-panel').doLayout(); }, scope : this },
Читать дальше
Костыль для кеширования mFilter
13 декабря 2019, 09:08
Вызов mFilter2 только если кеша нет:
Читать дальше
{var $get = ($.get | toJSON) | md5} {* Проверяем, есть ли фильтр уже в кеше *} {if !$filter = $_modx->cacheManager->get('filters/' ~ $_modx->resource.id ~ '/' ~ $get ~ '/filters')} {set $filter = $_modx->runSnippet('!mFilter2_cache_config', [ 'class' => 'msProduct', 'parents' => $_modx->resource.id, 'element' => 'msProducts', ])} {* Нужно закешировать ещё и config, помимо самого фильтра *} {set $need_cache = true} {set $null = $_modx->cacheManager->set('filters/' ~ $_modx->resource.id ~ '/' ~ $get ~ '/need_cache', $need_cache)} {* Сохраняем фильтр в кеш *} {set $null = $_modx->cacheManager->set('filters/' ~ $_modx->resource.id ~ '/' ~ $get ~ '/filters', $filter)} {/if} {* Подключаем JS-скрипты и прописываем config на странице *} {'!cache_mFilter' | snippet} {* Показываем фильтр из кеша *} {$filter}
Читать дальше
Парсинг новостей с картинками для сайта
17 июня 2019, 16:07
<?php $url = 'https://site.ru/type/news'; require_once(MODX_CORE_PATH . 'components/simplehtmldom/simple-html-dom.php'); $html = file_get_html($url); $teasers = $html->find('.teaser'); $news = []; foreach ($teasers as $teaser) { $link = $teaser->find('a', 0); $date = $teaser->find('.date', 0); $parser = date_create_from_format('d.m.y', trim($date->plaintext)); $publishedon = date_format($parser, 'Y-m-d'); $news[] = ['link' => 'https://site.ru' . $link->href, 'publishedon' => $publishedon, 'pagetitle' => $link->plaintext]; } foreach ($news as $page) { $page['parent'] = 15; $html = file_get_html($page['link']); $content = $html->find('.body', 0); $imgs = $content->find('img'); foreach ($imgs as $img) { if (strpos($img->src, 'http') !== false) { $url = $img->src; } else { $url = 'https://site.ru' . $img->src; } $name = md5(uniqid()) . '.' . pathinfo($url, PATHINFO_EXTENSION); $path = MODX_BASE_PATH . 'assets/images/archive/' . $name; file_put_contents($path, file_get_contents($url)); $img->src = '/assets/images/archive/' . $name; if (!isset($page['img']) || !$page['img']) { $page['tv1'] = $img->src; } } if ($olds = $content->find('.field-field-old-filename',0)) { $olds->outertext = ''; } $page['content'] = $content->innertext; if (!$res = $modx->getObject('modResource', ['parent' => $page['parent'], 'pagetitle' => $page['pagetitle'], 'publishedon' => strtotime($page['publishedon'])])) { if ($count = $modx->getCount('modResource', ['parent' => $page['parent'], 'pagetitle' => $page['pagetitle']])) { $page['alias'] = $page['pagetitle'] . '-' . $count; print $page['alias'] . ' - '; } $response = $modx->runProcessor('resource/create', $page); if ($response->isError()) { echo '<p>' . $page['pagetitle'] . '</p>'; return $modx->error->failure($response->getMessage()); } else { echo '<p>Resource created</p>'; } } else { echo '<p>Resource found</p>'; } }
Читать дальше
Правила сервера для MODX Cloud
23 мая 2019, 16:34
location ~* \.(?:ico|css|js|jpe?g|png|gif|svg|pdf|mov|mp4|mp3|woff)$ { try_files $uri $uri/ @modx-rewrite; expires 7d; add_header Pragma public; add_header Cache-Control "public"; gzip_vary on; } if ($scheme != "https") { return 301 https://www.webslite.com$request_uri; } if ($host != "www.groepenkastmontagenoord.nl") { rewrite ^ https://www.webslite.com$request_uri permanent; } location / { try_files $uri $uri/ @modx-rewrite; } location = /robots.txt { try_files $uri $uri/ @modx-rewrite; }
Читать дальше
Удалить все вирусы, найденные ai-bolit'ом
25 апреля 2019, 20:09
<?php @ini_set('display_errors', 1); echo 'Start' . PHP_EOL; $report_file = __DIR__ . '/report.json'; if (!file_exists($report_file)) { echo 'Report not found' . PHP_EOL; return; } $report_json = file_get_contents($report_file); if (!$report = json_decode($report_json, true)) { echo 'Can not decode JSON' . PHP_EOL; return; } if (isset($report['php_malware'])) { foreach ($report['php_malware'] as $php_malware) { echo $php_malware['fn'] . PHP_EOL; //unlink($php_malware['fn']); } } else { echo 'Php Malware not found' . PHP_EOL; } if (isset($report['js_malware'])) { foreach ($report['js_malware'] as $js_malware) { echo $js_malware['fn'] . PHP_EOL; //unlink($js_malware['fn']); } } else { echo 'JS Malware not found' . PHP_EOL; }
Читать дальше
Добавление вкладки на страницу редактирования ресурса
18 апреля 2019, 09:06
Плагин
Читать дальше
<?php switch ($modx->event->name) { case 'OnDocFormRender': if ($mode == modSystemEvent::MODE_UPD) { $modx->controller->addLexiconTopic('core:user'); $modx->controller->addLastJavascript($modx->getOption('assets_url') . 'components/resourceextender/mgr/resource/tab.js?v=1.0.0'); } break; }
Читать дальше
Добавляем запись лексикона для строки KB
10 апреля 2019, 10:36
<?php $path = MODX_CORE_PATH . 'lexicon/'; $dirs = scandir($path); unset($dirs[0]); unset($dirs[1]); foreach ($dirs as $dir) { $file = $path . $dir . '/file.inc.php'; if (is_dir($path . $dir) && file_exists($file)) { $content = file_get_contents($file); if (strpos($content, 'file_size_bytes') === false && strpos($content, 'file_size_kilobytes') === false) { $content = str_replace( '$_lang[\'image_size\']', '$_lang[\'file_size_bytes\'] = \'bytes\';' . PHP_EOL . '$_lang[\'file_size_kilobytes\'] = \'KB\';' . PHP_EOL . '$_lang[\'image_size\']', $content); file_put_contents($file, $content); } } }
Читать дальше
Поместить превью и keywords для SeoPRO перед контентом
10 апреля 2019, 10:16
Файл
Меняем:
Читать дальше
assets/components/seopro/js/mgr/seopro.js
Меняем:
// ... var fieldDesc = new Ext.form.Label({ forId: 'pagetitle', text: _('seopro.focuskeywords_desc'), cls: 'desc-under' }); fp.insert(3,fieldDesc); /* было fp.add(field); */ fp.insert(3,field); /* было fp.add(fieldDesc); */ fp.doLayout(); }, addPanel: function() { var fp = Ext.getCmp('modx-resource-main-left'); fp.insert(3, { /* было fp.add({ */ xtype: 'panel', // ...
Читать дальше