templator/_public.php

43 lines
1.4 KiB
PHP
Raw Normal View History

2022-12-05 21:39:13 +00:00
<?php
2022-12-07 20:58:18 +00:00
/**
* @brief templator, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Osku and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
2022-12-05 21:39:13 +00:00
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), dcCore::app()->templator->path);
dcCore::app()->addBehavior('urlHandlerBeforeGetData', ['publicTemplatorBehaviors','BeforeGetData']);
2022-12-05 21:39:13 +00:00
class publicTemplatorBehaviors
{
public static function BeforeGetData($_)
{
if (array_key_exists(dcCore::app()->url->type, dcCore::app()->getPostTypes()) || dcCore::app()->url->type == 'pages') {
$params = [];
$params['meta_type'] = 'template';
$params['post_id'] = dcCore::app()->ctx->posts->post_id;
$post_meta = dcCore::app()->meta->getMetadata($params);
if (!$post_meta->isEmpty() && dcCore::app()->tpl->getFilePath($post_meta->meta_id)) {
dcCore::app()->ctx->current_tpl = $post_meta->meta_id;
}
}
if (dcCore::app()->ctx->current_tpl == 'category.html' && preg_match('/^[0-9]{1,}/', dcCore::app()->ctx->categories->cat_id, $cat_id)) {
$tpl = 'category-' . $cat_id[0] . '.html';
if (dcCore::app()->tpl->getFilePath($tpl)) {
dcCore::app()->ctx->current_tpl = $tpl;
}
}
}
2022-12-05 21:39:13 +00:00
}