2022-12-05 21:39:13 +00:00
|
|
|
<?php
|
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;
|
|
|
|
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 = [
|
|
|
|
' — ' => 'empty',
|
|
|
|
'post.html' => 'post',
|
|
|
|
];
|
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 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 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(
|
|
|
|
rawurldecode($_POST['filename']) . '.html',
|
|
|
|
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 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(
|
|
|
|
'category-' . rawurldecode($_POST['filecat']) . '.html',
|
|
|
|
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 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 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([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('New template') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Duplicate dotclear template
|
|
|
|
*/
|
|
|
|
} elseif ('new' == $part) {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('New template') => '',
|
|
|
|
]) .
|
|
|
|
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) {
|
|
|
|
echo
|
|
|
|
'<p><label for="filecat" class="required"><abbr title="' . __('Required field') . '">*</abbr>' . __('Category:') .'</label> ' .
|
|
|
|
form::combo('filecat', $categories_combo, '') . '</p>' .
|
|
|
|
'<p class="form-note">' . __('Required only for category template.') . '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<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 00:07:56 +00:00
|
|
|
/**
|
|
|
|
* Copy templator template
|
|
|
|
*/
|
|
|
|
} 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([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('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 00:07:56 +00:00
|
|
|
/**
|
|
|
|
* Copy templator category template
|
|
|
|
*/
|
|
|
|
} elseif ('copycat' == $part && !empty($_REQUEST['file'])) {
|
|
|
|
$category_id = 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([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('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 00:07:56 +00:00
|
|
|
/**
|
|
|
|
* Delete templator template
|
|
|
|
*/
|
|
|
|
} elseif ('delete' == $part && !empty($_REQUEST['file'])) {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('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 00:07:56 +00:00
|
|
|
/**
|
|
|
|
* List templator templates
|
|
|
|
*/
|
|
|
|
} elseif ('files' == $part) {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('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());
|
|
|
|
|
|
|
|
$pager = new dcPager($filter->page, count($items), $filter->nb, 10);
|
2022-12-07 00:07:56 +00:00
|
|
|
$pager->html_prev = __('«prev.');
|
|
|
|
$pager->html_next = __('next»');
|
|
|
|
|
|
|
|
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 00:07:56 +00:00
|
|
|
/**
|
|
|
|
* List Used templator template
|
|
|
|
*/
|
|
|
|
} 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">' .
|
|
|
|
'<td class="maximal"><a href="' .
|
|
|
|
dcCore::app()->adminurl->get('admin.plugin.templator', [
|
|
|
|
'part' => 'posts',
|
|
|
|
'file' => $tags->meta_id,
|
|
|
|
'redir' => dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'used']),
|
|
|
|
]) .'">' . $tags->meta_id . '</a> ' . $img_status . '</td>' .
|
|
|
|
'<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([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('Used templates') => '',
|
|
|
|
]) .
|
|
|
|
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>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit emplator template
|
|
|
|
*/
|
|
|
|
} 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)) {
|
|
|
|
$category = dcCore::app()->blog->getCategory($cat_id[1]);
|
|
|
|
$full_name = '';
|
|
|
|
$cat_parents = dcCore::app()->blog->getCategoryParents($cat_id[1]);
|
|
|
|
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([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('Edit template') => '',
|
|
|
|
]) .
|
|
|
|
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 00:07:56 +00:00
|
|
|
/**
|
|
|
|
* Edit posts options linked to a template
|
|
|
|
*/
|
|
|
|
} elseif ('posts' == $part && (!empty($_REQUEST['file']) || $_REQUEST['file'] == '0')) {
|
|
|
|
$file = $_REQUEST['file'];
|
|
|
|
$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', '');
|
|
|
|
|
|
|
|
$params = $filter->params();
|
|
|
|
$params['no_content'] = true;
|
|
|
|
$params['meta_id'] = $file;
|
|
|
|
$params['meta_type'] = 'template';
|
|
|
|
|
|
|
|
# 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([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Templates engine') => dcCore::app()->adminurl->get('admin.plugin.templator'),
|
|
|
|
__('Unselect template') => '',
|
|
|
|
]) .
|
|
|
|
dcPage::notices() .
|
|
|
|
|
|
|
|
'<h3>' . __('Unselect template') . '</h3>' .
|
|
|
|
'<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>' .
|
|
|
|
|
|
|
|
'<p class="col right">' .
|
|
|
|
'<input type="submit" value="' . __('Unselect template for selcted entries') . '" /></p>' .
|
|
|
|
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())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default page
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
echo
|
|
|
|
'<html><head><title>' . __('Templator') . '</title>' .
|
|
|
|
'</head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('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');
|
|
|
|
|
|
|
|
echo '</body></html>';
|