Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 77 additions & 13 deletions core/components/modxsmarty/elements/plugins/modxsmarty.plugin.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

// Инициализируем Смарти

$core_path = $modx->getOption('modxSmarty.core_path', $scriptProperties, $modx->getOption('core_path', null).'components/modxsmarty/');
$template_dir = $modx->getOption('modxSmarty.template_dir', $scriptProperties, $core_path.'templates/');
$template = $modx->getOption('modxSmarty.template', $scriptProperties, 'default');
$cache_dir = $modx->getOption('modxSmarty.cache_dir', $scriptProperties, $modx->getOption('core_path', null).'cache/modxsmarty/');

if(!$compile_dir = $modx->getOption('modxSmarty.compile_dir', $scriptProperties, null)){
$compile_dir = "{$core_path}compiled/";
}
// папка для скомпилированных шаблонов
$compile_dir = $modx->getOption('modxSmarty.compile_dir', $scriptProperties, "{$core_path}compiled/");

$config = array(
'template_dir' => $template_dir."{$template}/",
Expand All @@ -29,23 +28,88 @@
}

$smarty = $modx->getService('smarty', 'modxSmarty', MODX_CORE_PATH . 'components/modxsmarty/model/modxSmarty/', $config);

$templates = array();

// переберем настройки из неймспейса modxsmarty
// и найдем там настройки с шаблонами
// modxSmarty.{ключ_шаблона}_{индекс_приоритета}_template
// напр.: modxSmarty.shop_1_template
// шаблоны main и pre будут всегда иметь низший приоритет
$ar_tmp = array();
foreach ($modx->getIterator('modSystemSetting', array(
'namespace' => 'modxsmarty'
)) as $i => $st) {
if (preg_match('/^modxSmarty\.(.+?)?_?(\d+?)?_?template$/', $st->key, $matches) && !empty($st->value)) {
$key = $matches[1];
$index = !empty($matches[2]) ? $matches[2] : $i;

if (empty($key)) {
$key = 'main';
$index = -2;
}
if ($key == 'pre') {
$key = 'prepend';
$index = -1;
}

$ar_tmp[$index] = array(
'st_key' => $st->key,
'key' => $key,
'value' => $st->value,
);
}
}

$_compile_dir = "{$template}/";

if($pre_template = $modx->getOption('modxSmarty.pre_template', null, false)){
$templates['prepend'] = $template_dir."{$pre_template}/";
$modx->smarty->assign('pre_template', $pre_template);
$modx->smarty->assign('pre_template_url', $modx->getOption('modxSite.template_url'). $pre_template .'/');
$_compile_dir .= "{$pre_template}/";
}
if (!empty($ar_tmp)) {
krsort($ar_tmp);

foreach ($ar_tmp as $ar_tmp_item) {
$key = $ar_tmp_item['key'];
$value = $ar_tmp_item['value'];

switch ($key) {
case 'main':
$templateKey = "template";
$templateUrlKey = "template_url";
break;

case 'prepend':
$templateKey = "pre_template";
$templateUrlKey = "pre_template_url";
break;

default:
$templateKey = "{$key}_template";
$templateUrlKey = "{$key}_template_url";
}

$templates[$key] = $template_dir . $value . "/";

$modx->smarty->assign($templateKey, $value);
$modx->smarty->assign(
$templateUrlKey
,$modx->getOption('modxSite.template_url') . $value . "/"
);

// $_compile_dir .= "{$value}/";
}
}

// if($pre_template = $modx->getOption('modxSmarty.pre_template', null, false)){
// $templates['prepend'] = $template_dir."{$pre_template}/";
// $modx->smarty->assign('pre_template', $pre_template);
// $modx->smarty->assign('pre_template_url', $modx->getOption('modxSite.template_url'). $pre_template .'/');
// $_compile_dir .= "{$pre_template}/";
// }
// $templates['main'] = $template_dir."{$template}/";

$_compile_dir .= $modx->context->key. "/";

$templates['main'] = $template_dir."{$template}/";
$smarty->setTemplateDir($templates);
$smarty->setCompileDir($config['compile_dir']. $_compile_dir);
$smarty->setCompileDir($config['compile_dir'] . $_compile_dir);

/*
http://www.smarty.net/forums/viewtopic.php?p=87138&sid=03237308442c46664f9a5a80353eb277#87138
Expand Down