Last active
February 8, 2022 03:39
-
-
Save AgelxNash/9239062 to your computer and use it in GitHub Desktop.
[MODX Evolution] Плагин загрузки элементов (чанков и сниппетов) из файлов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* LoadElement | |
* | |
* Загрузка элементов из файлов | |
* | |
* @version 2.0.0 | |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License (GPL) | |
* @category plugin | |
* @author Agel Nash <modx@agel-nash.ru> | |
* @internal @legacy_names LoadElement | |
* @internal @properties &extChunk=Расширения чанков (<i>через запятую</i>);input;txt,html &extSnippet=Расширения сниппетов (<i>через запятую</i>);input;php &pathElement=Папка с элементами (<i>относительно корня сайта</i>);input;assets/element/ &namespace=В какой Namespace загружать элеменыт;input;custom | |
* @internal @modx_category API | |
* @internal @events OnWebPageInit,OnManagerPageInit,OnPageNotFound | |
*/ | |
if (!defined('MODX_BASE_PATH')) { die('HACK???'); } | |
if(!isset($namespace)) { | |
$namespace = 'custom'; | |
} | |
$extChunk = (!empty($extChunk) && is_scalar($extChunk)) ? $extChunk : 'txt,html'; | |
$extChunk = array_map('trim', explode(",", $extChunk)); | |
$found = $modx->findElements('chunk', MODX_BASE_PATH . $pathElement . '/chunk/', $extChunk); | |
foreach ($found as $name => $code) { | |
$modx->addChunk($name, $code, $namespace . '#'); | |
} | |
$extSnippet = (!empty($extSnippet) && is_scalar($extSnippet)) ? $extSnippet : 'txt,html'; | |
$extSnippet = array_map('trim', explode(",", $extSnippet)); | |
$found = $modx->findElements('snippet', MODX_BASE_PATH . $pathElement . '/snippet/', $extSnippet); | |
foreach ($found as $name => $code) { | |
$modx->addSnippet($name, $code, $namespace . '#'); | |
} |
@AgelxNash
L62
$modx->snippetCache[$snippetName . "Props"] = array();
В новых реализациях modx, snippet properties, только как строка и больше не проверяется на пустоту.
modxcms/evolution@e0ffb3e#commitcomment-17488835
I had to replace all '/'
by DIRECTORY_SEPARATOR
for windows-compatibilty.
Евгений, скажи, в начале каждого сниппета нужно указывать:
if ( !defined('MODX_BASE_PATH') ) die('HACK???');
я правильно понимаю? На сколько было бы критично пренебречь этим правилом?
Это еще работает?
@AntonFix Да, работает. Обновил код который работает еще и с версии 1.4.4
@atomoc Есть ситуации, когда можно принебречь. Но если не в даваться в подробности, то лучше не стоит.
@Deesen See the new version
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Не знаю зачем плагину событие
OnPageNotFound
, но убрав его всё становится как надо, правда лишь в версии 0.2.