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
|
|
|
|
*/
|
2022-12-05 21:42:34 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
dcPage::check(dcCore::app()->auth->makePermissions([
|
|
|
|
dcAuth::PERMISSION_CONTENT_ADMIN,
|
|
|
|
initTemplator::PERMISSION_TEMPLATOR,
|
|
|
|
]));
|
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
$part = $_REQUEST['part'] ?? '';
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
### grab info ###
|
2022-12-05 21:42:34 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
if (in_array($part, ['files', 'delete'])) {
|
2022-12-07 20:19:33 +00:00
|
|
|
//Extend dcMedia to change settings to allow .html vs media_exclusion
|
2022-12-07 00:07:56 +00:00
|
|
|
$media = new templatorMedia();
|
|
|
|
$media->chdir(dcCore::app()->templator->template_dir_name);
|
|
|
|
// For users with only templator permission, we use sudo.
|
|
|
|
dcCore::app()->auth->sudo([$media,'getDir']);
|
|
|
|
$dir = $media->dir;
|
|
|
|
$items = array_values($dir['files']);
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
2022-12-05 21:42:34 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
if (in_array($part, ['new', 'copycat'])) {
|
|
|
|
$has_categories = false;
|
2022-12-07 20:58:18 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
try {
|
|
|
|
$categories = dcCore::app()->blog->getCategories(['post_type' => 'post']);
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
$categories_combo = [];
|
|
|
|
$l = $categories->level;
|
|
|
|
$full_name = [$categories->cat_title];
|
2022-12-05 21:42:34 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
while ($categories->fetch()) {
|
|
|
|
if ($categories->level < $l) {
|
|
|
|
$full_name = [];
|
|
|
|
} elseif ($categories->level == $l) {
|
|
|
|
array_pop($full_name);
|
|
|
|
}
|
|
|
|
$full_name[] = html::escapeHTML($categories->cat_title);
|
2022-12-05 21:42:34 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
$categories_combo[implode(' › ', $full_name)] = $categories->cat_id;
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
$l = $categories->level;
|
|
|
|
}
|
|
|
|
$has_categories = !$categories->isEmpty();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
$combo_source = [
|
2022-12-10 00:08:47 +00:00
|
|
|
__('Empty template') => 'empty',
|
|
|
|
'post.html' => 'post',
|
2022-12-07 00:07:56 +00:00
|
|
|
];
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcPages::PERMISSION_PAGES]), dcCore::app()->blog->id) && dcCore::app()->plugins->moduleExists('pages')) {
|
|
|
|
$combo_source['page.html'] = 'page';
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
if ($has_categories) {
|
|
|
|
$combo_source['category.html'] = 'category';
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
### Action ###
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
2022-12-07 00:07:56 +00:00
|
|
|
* Duplicate dc template
|
|
|
|
*/
|
|
|
|
if ('new' == $part && !empty($_POST['filesource'])) {
|
2022-12-05 21:42:34 +00:00
|
|
|
try {
|
2022-12-07 00:07:56 +00:00
|
|
|
if ('category' == $_POST['filesource']) {
|
2022-12-05 21:42:34 +00:00
|
|
|
$name = 'category-' . $_POST['filecat'] . '.html';
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif (!empty($_POST['filename'])) {
|
|
|
|
$name = files::tidyFileName($_POST['filename']) . '.html';
|
|
|
|
} else {
|
|
|
|
throw new Exception(__('Filename is empty.'));
|
2022-12-05 21:42:34 +00:00
|
|
|
}
|
2022-12-07 00:07:56 +00:00
|
|
|
dcCore::app()->templator->initializeTpl($name, $_POST['filesource']);
|
2022-12-05 21:42:34 +00:00
|
|
|
|
|
|
|
if (!dcCore::app()->error->flag()) {
|
|
|
|
dcAdminNotices::addSuccessNotice(__('The new template has been successfully created.'));
|
|
|
|
dcCore::app()->adminurl->redirect('admin.plugin.templator');
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
2022-12-07 00:07:56 +00:00
|
|
|
* Copy tempaltor template
|
|
|
|
*/
|
|
|
|
if ('copy' == $part && !empty($_POST['filename'])) {
|
2022-12-05 21:42:34 +00:00
|
|
|
try {
|
2022-12-07 00:07:56 +00:00
|
|
|
dcCore::app()->templator->copypasteTpl(
|
2022-12-07 20:58:18 +00:00
|
|
|
rawurldecode($_POST['filename']) . '.html',
|
2022-12-07 00:07:56 +00:00
|
|
|
rawurldecode($_POST['file'])
|
|
|
|
);
|
2022-12-05 21:42:34 +00:00
|
|
|
|
|
|
|
if (!dcCore::app()->error->flag()) {
|
2022-12-07 00:07:56 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.'));
|
|
|
|
dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'files']);
|
2022-12-05 21:42:34 +00:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
2022-12-07 00:07:56 +00:00
|
|
|
* Copy templator category template
|
|
|
|
*/
|
|
|
|
if ('copycat' == $part && !empty($_POST['filecat'])) {
|
2022-12-05 21:42:34 +00:00
|
|
|
try {
|
2022-12-07 00:07:56 +00:00
|
|
|
dcCore::app()->templator->copypasteTpl(
|
2022-12-07 20:58:18 +00:00
|
|
|
'category-' . rawurldecode($_POST['filecat']) . '.html',
|
2022-12-07 00:07:56 +00:00
|
|
|
rawurldecode($_POST['file'])
|
|
|
|
);
|
2022-12-05 21:42:34 +00:00
|
|
|
|
|
|
|
if (!dcCore::app()->error->flag()) {
|
|
|
|
dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.'));
|
2022-12-07 00:07:56 +00:00
|
|
|
dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'files']);
|
2022-12-05 21:42:34 +00:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
2022-12-07 00:07:56 +00:00
|
|
|
* Delete tempaltor template
|
|
|
|
*/
|
|
|
|
if ('delete' == $part && !empty($_POST['file'])) {
|
2022-12-05 21:42:34 +00:00
|
|
|
try {
|
2022-12-07 00:07:56 +00:00
|
|
|
$file = rawurldecode($_POST['file']);
|
|
|
|
$media->removeItem($file);
|
|
|
|
dcCore::app()->meta->delMeta($file, 'template');
|
2022-12-05 21:42:34 +00:00
|
|
|
|
|
|
|
if (!dcCore::app()->error->flag()) {
|
2022-12-07 00:07:56 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(__('The template has been successfully removed.'));
|
|
|
|
dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'files']);
|
2022-12-05 21:42:34 +00:00
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
### Display ###
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
2022-12-07 00:07:56 +00:00
|
|
|
* Check
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!dcCore::app()->templator->canUseRessources(true)) {
|
|
|
|
dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
|
2022-12-05 21:42:34 +00:00
|
|
|
echo
|
2022-12-07 00:07:56 +00:00
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 20:58:18 +00:00
|
|
|
__('New template') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
]) .
|
|
|
|
dcPage::notices();
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Duplicate dotclear template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('new' == $part) {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 20:58:18 +00:00
|
|
|
__('New template') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
|
|
|
|
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'new']) . '" method="post" id="add-template">' .
|
|
|
|
'<h3>' . __('New template') . '</h3>' .
|
|
|
|
'<p><label for="filesource" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Template source:') . '</label> ' .
|
|
|
|
form::combo('filesource', $combo_source) . '</p>' .
|
|
|
|
'<p><label for="filename" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Filename:') . '</label> ' .
|
|
|
|
form::field('filename', 25, 255) . '</p>' .
|
|
|
|
'<p class="form-note">' . __('Extension .html is automatically added to filename.') . '</p>';
|
|
|
|
|
|
|
|
if ($has_categories) {
|
2022-12-07 20:58:18 +00:00
|
|
|
echo
|
|
|
|
'<p><label for="filecat" class="required"><abbr title="' . __('Required field') . '">*</abbr>' . __('Category:') . '</label> ' .
|
2022-12-07 00:07:56 +00:00
|
|
|
form::combo('filecat', $categories_combo, '') . '</p>' .
|
|
|
|
'<p class="form-note">' . __('Required only for category template.') . '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
2022-12-07 20:58:18 +00:00
|
|
|
'<p>' .
|
2022-12-05 21:42:34 +00:00
|
|
|
dcCore::app()->formNonce() .
|
2022-12-07 00:07:56 +00:00
|
|
|
'<input type="submit" value="' . __('Create') . '" /></p>' .
|
2022-12-05 21:42:34 +00:00
|
|
|
'</form>';
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Copy templator template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('copy' == $part && !empty($_REQUEST['file'])) {
|
2022-12-05 21:42:34 +00:00
|
|
|
echo
|
2022-12-07 00:07:56 +00:00
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Copy available template') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
|
|
|
|
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'copy']) . '" method="post">' .
|
|
|
|
'<h3>' . __('Copy available template') . '</h3>' .
|
|
|
|
'<p><label for="filename" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('New filename:') . '</label> ' .
|
|
|
|
form::field('filename', 25, 255) . '<code>' . html::escapeHTML('.html') . '</code></p> ' .
|
|
|
|
'<p class="form-note">' . sprintf(
|
2022-12-05 21:42:34 +00:00
|
|
|
__('To copy the template <strong>%s</strong>, you need to fill a new filename.'),
|
2022-12-07 00:07:56 +00:00
|
|
|
html::escapeHTML($_REQUEST['file'])
|
2022-12-05 21:42:34 +00:00
|
|
|
) . '</p>' .
|
2022-12-07 00:07:56 +00:00
|
|
|
'<p>' .
|
|
|
|
'<input type="submit" name="submit" value="' . __('Copy') . '" /> ' .
|
|
|
|
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
|
2022-12-05 21:42:34 +00:00
|
|
|
dcCore::app()->formNonce() .
|
2022-12-07 00:07:56 +00:00
|
|
|
form::hidden('file', html::escapeHTML($_REQUEST['file'])) . '</p>' .
|
2022-12-05 21:42:34 +00:00
|
|
|
'</form>';
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Copy templator category template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('copycat' == $part && !empty($_REQUEST['file'])) {
|
2022-12-07 20:58:18 +00:00
|
|
|
$category_id = (int) str_replace(['category-','.html'], '', $_REQUEST['file']);
|
2022-12-05 21:42:34 +00:00
|
|
|
$cat_parents = dcCore::app()->blog->getCategoryParents($category_id);
|
|
|
|
$full_name = '';
|
|
|
|
while ($cat_parents->fetch()) {
|
|
|
|
$full_name = $cat_parents->cat_title . ' › ';
|
|
|
|
};
|
|
|
|
$name = $full_name . dcCore::app()->blog->getCategory($category_id)->cat_title;
|
2022-12-07 00:07:56 +00:00
|
|
|
|
2022-12-05 21:42:34 +00:00
|
|
|
echo
|
2022-12-07 00:07:56 +00:00
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Copy available template') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
|
|
|
|
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'copycat']) . '" method="post">' .
|
|
|
|
'<h3>' . __('Copy available template') . '</h3>' .
|
|
|
|
'<p><label for="filecat" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Target category:') . '</label> ' .
|
|
|
|
form::combo('filecat', $categories_combo, '') . '</p>' .
|
|
|
|
'<p class="form-note">' . sprintf(
|
2022-12-05 21:42:34 +00:00
|
|
|
__('To copy the template <strong>%s</strong> (%s), you need to choose a category.'),
|
2022-12-07 00:07:56 +00:00
|
|
|
html::escapeHTML($_GET['file']),
|
2022-12-05 21:42:34 +00:00
|
|
|
$name
|
|
|
|
) . '</p>' .
|
2022-12-07 00:07:56 +00:00
|
|
|
'<input type="submit" name="submit" value="' . __('Copy') . '" /> ' .
|
|
|
|
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
|
|
|
|
dcCore::app()->formNonce() .
|
|
|
|
form::hidden('file', html::escapeHTML($_REQUEST['file'])) . '</p>' .
|
2022-12-05 21:42:34 +00:00
|
|
|
'</form>';
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Delete templator template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('delete' == $part && !empty($_REQUEST['file'])) {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Delete available template') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
|
|
|
|
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'delete']) . '" method="post">' .
|
|
|
|
'<h3>' . __('Delete available template') . '</h3>' .
|
|
|
|
'<p>' . sprintf(
|
|
|
|
__('Are you sure you want to remove the template "%s"?'),
|
|
|
|
html::escapeHTML($_GET['file'])
|
|
|
|
) . '</p>' .
|
|
|
|
'<p><input type="submit" class="delete" value="' . __('Delete') . '" /> ' .
|
|
|
|
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
|
|
|
|
dcCore::app()->formNonce() .
|
|
|
|
form::hidden('file', html::escapeHTML($_GET['file'])) . '</p>' .
|
|
|
|
'</form>';
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* List templator templates
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('files' == $part) {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Available templates') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
'<h3>' . __('Available templates') . '</h3>';
|
|
|
|
|
|
|
|
if (count($items) == 0) {
|
|
|
|
echo '<p><strong>' . __('No template.') . '</strong></p>';
|
|
|
|
} else {
|
2022-12-07 20:19:33 +00:00
|
|
|
// reuse "used templatro template" filter settings
|
|
|
|
$filter = new adminGenericFilterV2('templator');
|
|
|
|
$filter->add(dcAdminFilters::getPageFilter());
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
$pager = new dcPager($filter->page, count($items), $filter->nb, 10);
|
2022-12-07 00:07:56 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
'<div class="media-list">' .
|
2022-12-07 20:19:33 +00:00
|
|
|
$pager->getLinks();
|
2022-12-07 00:07:56 +00:00
|
|
|
|
|
|
|
for ($i = $pager->index_start, $j = 0; $i <= $pager->index_end; $i++, $j++) {
|
2022-12-07 20:19:33 +00:00
|
|
|
echo templatorPager::templatorItemLine($items[$i], $j);
|
2022-12-07 00:07:56 +00:00
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
echo
|
2022-12-07 20:19:33 +00:00
|
|
|
$pager->getLinks() .
|
2022-12-07 00:07:56 +00:00
|
|
|
'</div>';
|
|
|
|
}
|
2022-12-05 21:39:13 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* List Used templator template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('used' == $part) {
|
|
|
|
$tags = dcCore::app()->meta->getMetadata(['meta_type' => 'template']);
|
|
|
|
$tags = dcCore::app()->meta->computeMetaStats($tags);
|
|
|
|
$tags->sort('meta_id_lower', 'asc');
|
|
|
|
|
|
|
|
$last_letter = null;
|
|
|
|
$cols = ['',''];
|
|
|
|
$col = 0;
|
|
|
|
|
|
|
|
while ($tags->fetch()) {
|
|
|
|
$letter = mb_strtoupper(mb_substr($tags->meta_id, 0, 1));
|
|
|
|
|
|
|
|
if ($last_letter != $letter) {
|
|
|
|
if ($tags->index() >= round($tags->count() / 2)) {
|
|
|
|
$col = 1;
|
|
|
|
}
|
|
|
|
$cols[$col] .= '<tr class="tagLetter"><td colspan="2"><span>' . $letter . '</span></td></tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
|
|
|
|
if (array_key_exists($tags->meta_id, dcCore::app()->templator->tpl)) {
|
|
|
|
$img_status = sprintf($img, __('available template'), 'check-on.png');
|
|
|
|
} else {
|
|
|
|
$img_status = sprintf($img, __('missing template'), 'check-off.png');
|
|
|
|
}
|
|
|
|
|
|
|
|
$cols[$col] .= '<tr class="line">' .
|
2022-12-07 20:58:18 +00:00
|
|
|
'<td class="maximal"><a href="' .
|
2022-12-07 00:07:56 +00:00
|
|
|
dcCore::app()->adminurl->get('admin.plugin.templator', [
|
2022-12-07 20:58:18 +00:00
|
|
|
'part' => 'posts',
|
2022-12-07 00:07:56 +00:00
|
|
|
'file' => $tags->meta_id,
|
2022-12-07 20:58:18 +00:00
|
|
|
'redir' => dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'used']),
|
|
|
|
]) . '">' . $tags->meta_id . '</a> ' . $img_status . '</td>' .
|
2022-12-07 00:07:56 +00:00
|
|
|
'<td class="nowrap"><strong>' . $tags->count . '</strong> ' .
|
|
|
|
(($tags->count == 1) ? __('entry') : __('entries')) . '</td>' .
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
$last_letter = $letter;
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = '<div class="col"><table class="tags">%s</table></div>';
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
dcPage::cssLoad(dcPage::getPF('tags/style.css')) .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Used templates') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
'<h3>' . __('Used templates') . '</h3>';
|
|
|
|
|
|
|
|
if ($cols[0]) {
|
|
|
|
echo '<div class="two-cols">';
|
|
|
|
printf($table, $cols[0]);
|
|
|
|
if ($cols[1]) {
|
|
|
|
printf($table, $cols[1]);
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
} else {
|
|
|
|
echo '<p>' . __('No specific templates on this blog.') . '</p>';
|
|
|
|
}
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Edit emplator template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('edit' == $part && !empty($_REQUEST['file'])) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
$name = rawurldecode($_REQUEST['file']);
|
|
|
|
$file = dcCore::app()->templator->getSourceContent($name);
|
|
|
|
$name = $file['f'];
|
|
|
|
|
|
|
|
if (preg_match('/^category-(.+).html$/', $name, $cat_id)) {
|
2022-12-07 20:58:18 +00:00
|
|
|
$category = dcCore::app()->blog->getCategory((int) $cat_id[1]);
|
2022-12-07 00:07:56 +00:00
|
|
|
$full_name = '';
|
2022-12-07 20:58:18 +00:00
|
|
|
$cat_parents = dcCore::app()->blog->getCategoryParents((int) $cat_id[1]);
|
2022-12-07 00:07:56 +00:00
|
|
|
while ($cat_parents->fetch()) {
|
|
|
|
$full_name = $cat_parents->cat_title . ' › ';
|
|
|
|
};
|
|
|
|
$name .= '</strong> (' . $full_name . $category->cat_title . ')<strong>';
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
2022-12-07 20:19:33 +00:00
|
|
|
$file = '';
|
2022-12-07 00:07:56 +00:00
|
|
|
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
# Write file
|
|
|
|
if (!empty($_POST['write'])) {
|
|
|
|
$file['c'] = $_POST['file_content'];
|
|
|
|
dcCore::app()->templator->writeTpl($file['f'], $file['c']);
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
dcCore::app()->auth->user_prefs->addWorkspace('interface');
|
2022-12-05 21:42:34 +00:00
|
|
|
|
|
|
|
echo
|
2022-12-07 00:07:56 +00:00
|
|
|
'<html><head><title>' . __('Templator') . '</title>';
|
2022-12-05 21:42:34 +00:00
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) {
|
|
|
|
echo
|
|
|
|
dcPage::jsJson('dotclear_colorsyntax', ['colorsyntax' => dcCore::app()->auth->user_prefs->interface->colorsyntax]);
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
dcPage::jsJson('theme_editor_msg', [
|
|
|
|
'saving_document' => __('Saving document...'),
|
|
|
|
'document_saved' => __('Document saved'),
|
|
|
|
'error_occurred' => __('An error occurred:'),
|
|
|
|
'confirm_reset_file' => __('Are you sure you want to reset this file?'),
|
|
|
|
]) .
|
|
|
|
dcPage::jsModuleLoad('themeEditor/js/script.js') .
|
|
|
|
dcPage::jsConfirmClose('file-form');
|
|
|
|
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) {
|
|
|
|
echo
|
|
|
|
dcPage::jsLoadCodeMirror(dcCore::app()->auth->user_prefs->interface->colorsyntax_theme);
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
dcPage::cssModuleLoad('themeEditor/style.css') .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Edit template') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
]) .
|
|
|
|
dcPage::notices();
|
|
|
|
|
|
|
|
if (($file['c'] !== null)) {
|
|
|
|
echo
|
|
|
|
'<form id="file-form" action="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'edit', 'file' => $name]) . '" method="post">' .
|
|
|
|
'<div><h3><label for="file_content">' . sprintf(__('Editing file %s'), '<strong>' . $name) . '</strong></label></h3>' .
|
|
|
|
'<p>' . form::textarea('file_content', 72, 25, [
|
|
|
|
'default' => html::escapeHTML($file['c']),
|
|
|
|
'class' => 'maximal',
|
|
|
|
'disabled' => !$file['w'],
|
|
|
|
]) . '</p>';
|
|
|
|
|
|
|
|
if ($file['w']) {
|
|
|
|
echo
|
|
|
|
'<p><input type="submit" name="write" value="' . __('Save') . '" accesskey="s" /> ' .
|
|
|
|
'<a class="button" href="' . dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']) . '">' . __('Cancel') . '</a>' .
|
|
|
|
dcCore::app()->formNonce() .
|
|
|
|
form::hidden(['file_id'], html::escapeHTML($file['f'])) .
|
|
|
|
'</p>';
|
|
|
|
} else {
|
|
|
|
echo '<p>' . __('This file is not writable. Please check your files permissions.') . '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
|
|
|
'</div></form>';
|
|
|
|
if (dcCore::app()->auth->user_prefs->interface->colorsyntax) {
|
|
|
|
echo
|
|
|
|
dcPage::jsJson('theme_editor_mode', ['mode' => 'html']) .
|
|
|
|
dcPage::jsModuleLoad('themeEditor/js/mode.js') .
|
|
|
|
dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', dcCore::app()->auth->user_prefs->interface->colorsyntax_theme);
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 21:42:34 +00:00
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Edit posts options linked to a template
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} elseif ('posts' == $part && (!empty($_REQUEST['file']) || $_REQUEST['file'] == '0')) {
|
2022-12-07 20:58:18 +00:00
|
|
|
$file = $_REQUEST['file'];
|
2022-12-07 00:07:56 +00:00
|
|
|
$redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'used']);
|
|
|
|
|
|
|
|
# Unselect the template
|
|
|
|
if (!empty($_POST['action']) && 'unselecttpl' == $_POST['action'] && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
|
|
|
dcAuth::PERMISSION_PUBLISH,
|
|
|
|
dcAuth::PERMISSION_CONTENT_ADMIN,
|
|
|
|
]), dcCore::app()->blog->id)) {
|
|
|
|
try {
|
|
|
|
dcCore::app()->meta->delMeta($file, 'template');
|
|
|
|
dcCore::app()->adminurl->redirect('admin.plugin.templator', ['part' => 'posts', 'file' => $file]);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$filter = new adminGenericFilterV2('templator');
|
|
|
|
$filter->add(dcAdminFilters::getPageFilter());
|
|
|
|
$filter->add('part', 'posts');
|
|
|
|
$filter->add('file', $file);
|
|
|
|
$filter->add('post_type', '');
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
$params = $filter->params();
|
2022-12-07 00:07:56 +00:00
|
|
|
$params['no_content'] = true;
|
2022-12-07 20:58:18 +00:00
|
|
|
$params['meta_id'] = $file;
|
|
|
|
$params['meta_type'] = 'template';
|
2022-12-07 00:07:56 +00:00
|
|
|
|
|
|
|
# Get posts
|
|
|
|
try {
|
|
|
|
$posts = dcCore::app()->meta->getPostsByMeta($params);
|
|
|
|
$counter = dcCore::app()->meta->getPostsByMeta($params, true);
|
|
|
|
$post_list = new adminPostList($posts, $counter->f(0));
|
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
2022-12-05 21:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
2022-12-07 00:07:56 +00:00
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
dcPage::jsFilterControl($filter->show()) .
|
|
|
|
dcPage::jsLoad(dcPage::getPF('templator/js/posts.js')) .
|
|
|
|
$filter->js(dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'posts', 'file' => $file])) .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Unselect template') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
'<h3>' . sprintf(__('Unselect template "%s"'), '<strong>' . $file . '</strong>') . '</h3>' .
|
2022-12-07 00:07:56 +00:00
|
|
|
'<p><a class ="back" href="' . $redir . '">' . __('Back') . '</a></p>';
|
|
|
|
|
|
|
|
if (!dcCore::app()->error->flag()) {
|
|
|
|
if ($posts->isEmpty() && !$filter->show()) {
|
|
|
|
echo '<p>' . __('There is no entries') . '</p>';
|
|
|
|
} else {
|
|
|
|
$filter->display(
|
|
|
|
'admin.plugin.templator',
|
|
|
|
form::hidden('p', 'templator') . form::hidden('part', 'posts') . form::hidden('file', $file)
|
|
|
|
);
|
|
|
|
# Show posts
|
|
|
|
$post_list->display(
|
|
|
|
$filter->page,
|
|
|
|
$filter->nb,
|
|
|
|
'<form action="' . dcCore::app()->adminurl->get('admin.plugin.templator') . '" method="post" id="form-entries">' .
|
|
|
|
|
|
|
|
'%s' .
|
|
|
|
|
|
|
|
'<div class="two-cols">' .
|
|
|
|
'<p class="col checkboxes-helpers"></p>' .
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
'<p class="col right">' .
|
|
|
|
'<input type="submit" value="' . __('Unselect template for selected entries') . '" /></p>' .
|
2022-12-07 00:07:56 +00:00
|
|
|
form::hidden('action', 'unselecttpl') .
|
|
|
|
dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.templator', $filter->values()) .
|
|
|
|
form::hidden('redir', $redir) .
|
|
|
|
dcCore::app()->formNonce() .
|
|
|
|
'</div>' .
|
|
|
|
'</form>',
|
|
|
|
$filter->show(),
|
|
|
|
dcCore::app()->adminurl->get('admin.plugin.templator', $filter->values())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
/*
|
|
|
|
* Default page
|
|
|
|
*/
|
2022-12-07 00:07:56 +00:00
|
|
|
} else {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2022-12-07 20:58:18 +00:00
|
|
|
__('Plugins') => '',
|
2022-12-07 00:07:56 +00:00
|
|
|
__('Templates engine') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices();
|
|
|
|
|
|
|
|
$line = '<li><a href="%s">%s</a></li>';
|
|
|
|
echo '
|
|
|
|
<h4><i>' . __('Manage additional templates') . '</i></h4>' .
|
|
|
|
sprintf(
|
|
|
|
'<h3><ul class="nice">%s</ul></h3>',
|
|
|
|
sprintf(
|
|
|
|
$line,
|
|
|
|
dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']),
|
|
|
|
__('Available templates')
|
|
|
|
) .
|
|
|
|
sprintf(
|
|
|
|
$line,
|
|
|
|
dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'used']),
|
|
|
|
__('Used templates')
|
|
|
|
) .
|
|
|
|
sprintf(
|
|
|
|
$line,
|
|
|
|
dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'new']),
|
|
|
|
__('New template')
|
|
|
|
)
|
|
|
|
);
|
2022-12-05 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 00:07:56 +00:00
|
|
|
dcPage::helpBlock('templator');
|
|
|
|
|
2022-12-07 20:58:18 +00:00
|
|
|
echo '</body></html>';
|