update to dotclear 2.24, refresh admin (WIP)

This commit is contained in:
Jean-Christian Paul Denis 2022-12-05 22:42:34 +01:00
parent 61939f68e1
commit a051f78816
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
14 changed files with 1113 additions and 1180 deletions

View File

@ -1,152 +1,148 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$_menu['Plugins']->addItem(__('Templates'),
'plugin.php?p=templator','index.php?pf=templator/icon.png',
preg_match('/plugin.php\?p=templator(&.*)?$/',$_SERVER['REQUEST_URI']),
$core->auth->check('contentadmin,templator',$core->blog->id));
dcCore::app()->auth->setPermissionType(initTemplator::PERMISSION_TEMPLATOR, __('manage templates'));
$core->auth->setPermissionType('templator',__('manage templates'));
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Templates'),
dcCore::app()->adminurl->get('admin.plugin.templator'),
urldecode(dcPage::getPF('templator/icon.png')),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.templator')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]), dcCore::app()->blog->id)
);
if ($core->auth->check('templator,contentadmin',$core->blog->id)) {
$core->addBehavior('adminPostFormSidebar',array('templatorBehaviors','adminPostFormSidebar'));
$core->addBehavior('adminPageFormSidebar',array('templatorBehaviors','adminPostFormSidebar'));
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]), dcCore::app()->blog->id)) {
dcCore::app()->addBehavior('adminPostHeaders', ['templatorBehaviors','adminPostHeaders']);
dcCore::app()->addBehavior('adminPostFormItems', ['templatorBehaviors','adminPostFormItems']);
dcCore::app()->addBehavior('adminPageHeaders', ['templatorBehaviors','adminPostHeaders']);
dcCore::app()->addBehavior('adminPageFormItems', ['templatorBehaviors','adminPostFormItems']);
$core->addBehavior('adminAfterPostCreate',array('templatorBehaviors','adminBeforePostUpdate'));
$core->addBehavior('adminBeforePostUpdate',array('templatorBehaviors','adminBeforePostUpdate'));
$core->addBehavior('adminAfterPageCreate',array('templatorBehaviors','adminBeforePostUpdate'));
$core->addBehavior('adminBeforePageUpdate',array('templatorBehaviors','adminBeforePostUpdate'));
dcCore::app()->addBehavior('adminAfterPostCreate', ['templatorBehaviors','adminBeforePostUpdate']);
dcCore::app()->addBehavior('adminBeforePostUpdate', ['templatorBehaviors','adminBeforePostUpdate']);
dcCore::app()->addBehavior('adminAfterPageCreate', ['templatorBehaviors','adminBeforePostUpdate']);
dcCore::app()->addBehavior('adminBeforePageUpdate', ['templatorBehaviors','adminBeforePostUpdate']);
dcCore::app()->addBehavior('adminPostsActions', ['templatorBehaviors','adminPostsActions']);
dcCore::app()->addBehavior('adminPagesActions', ['templatorBehaviors','adminPostsActions']);
$core->addBehavior('adminPostsActionsCombo',array('templatorBehaviors','adminPostsActionsCombo'));
$core->addBehavior('adminPostsActions',array('templatorBehaviors','adminPostsActions'));
$core->addBehavior('adminPostsActionsContent',array('templatorBehaviors','adminPostsActionsContent'));
$core->addBehavior('adminPagesActionsCombo',array('templatorBehaviors','adminPostsActionsCombo'));
$core->addBehavior('adminPagesActions',array('templatorBehaviors','adminPostsActions'));
$core->addBehavior('adminPagesActionsContent',array('templatorBehaviors','adminPostsActionsContent'));
}
class templatorBehaviors
{
public static function adminPostFormSidebar($post)
{
global $core;
public static function adminPostHeaders()
{
return dcPage::jsLoad(dcPage::getPF('templator/js/admin.js'));
}
$tpl = array('&nbsp;' => '');
$tpl_post = array();
$selected = '';
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{
$selected = '';
foreach ($core->templator->tpl as $k => $v) {
if (!preg_match('/^category-(.+)$/',$k))
{
$tpl_post= array_merge($tpl_post, array($k => $k));
}
}
if ($post) {
$post_meta = dcCore::app()->meta->getMetadata(['meta_type' => 'template', 'post_id' => $post->post_id]);
$selected = $post_meta->isEmpty() ? '' : $post_meta->meta_id;
}
$tpl = array_merge($tpl,$tpl_post);
if ($post)
{
$params['meta_type'] = 'template';
$params['post_id'] = $post->post_id;
$post_meta = $core->meta->getMetadata($params);
$selected = $post_meta->isEmpty()? '' : $post_meta->meta_id ;
}
$sidebar_items['options-box']['items']['templator'] =
'<div id="templator">' .
'<h5>' . __('Template') . '</h5>' .
'<p><label for="post_tpl">' . __('Select template:') . '</label>' .
form::combo('post_tpl', self::getTemplateCombo(), $selected) . '</p>' .
'</div>';
}
echo
'<div class="p" id="meta-edit-tpl"><label for="post_tpl">
'.__('Entry template:').'</label>'.form::combo('post_tpl',$tpl,$selected).'</div>';
public static function adminBeforePostUpdate($cur, $post_id)
{
$post_id = (int) $post_id;
}
if (isset($_POST['post_tpl'])) {
dcCore::app()->meta->delPostMeta($post_id, 'template');
if (!empty($_POST['post_tpl'])) {
dcCore::app()->meta->setPostMeta($post_id, 'template', $_POST['post_tpl']);
}
}
}
public static function adminBeforePostUpdate($cur,$post_id)
{
global $core;
public static function adminPostsActions(dcPostsActions $pa)
{
$pa->addAction(
[
__('Appearance') => [
__('Select the template') => 'tpl',
],
],
['templatorBehaviors', 'adminPostsActionsCallback']
);
}
$post_id = (integer) $post_id;
public static function adminPostsActionsCallback(dcPostsActions $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
}
if (isset($_POST['post_tpl'])) {
$tpl = $_POST['post_tpl'];
if (isset($post['post_tpl'])) {
try {
foreach ($posts_ids as $post_id) {
dcCore::app()->meta->delPostMeta($post_id, 'template');
if (!empty($post['post_tpl'])) {
dcCore::app()->meta->setPostMeta($post_id, 'template', $post['post_tpl']);
}
}
$core->meta->delPostMeta($post_id,'template');
if (!empty($_POST['post_tpl']))
{
$core->meta->setPostMeta($post_id,'template',$tpl);
}
}
}
dcAdminNotices::addSuccessNotice(__('Entries template updated.'));
$pa->redirect(true);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
public static function adminPostsActionsCombo($args)
{
$args[0][__('Appearance')] = array(__('Select the template') => 'tpl');
}
$pa->beginPage(
dcPage::breadcrumb([
html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Entry template') => '',
])
);
public static function adminPostsActions($core,$posts,$action,$redir)
{
if ($action == 'tpl' && isset($_POST['post_tpl']))
{
try
{
$tpl = $_POST['post_tpl'];
echo
'<h2 class="page-title">' . __('Select template for the selection') . '</h2>' .
'<form action="' . $pa->getURI() . '" method="post">' .
$pa->getCheckboxes() .
'<p><label class="classic">' . __('Select template:') . '</label> ' .
form::combo('post_tpl', self::getTemplateCombo()) . '</p>' .
while ($posts->fetch())
{
$core->meta->delPostMeta($posts->post_id,'template');
if (!empty($_POST['post_tpl']))
{
$core->meta->setPostMeta($posts->post_id,'template',$tpl);
}
}
'<p>' .
$pa->getHiddenFields() .
dcCore::app()->formNonce() .
form::hidden(['action'], 'tpl') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';
http::redirect($redir);
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
}
}
$pa->endPage();
}
public static function adminPostsActionsContent($core,$action,$hidden_fields)
{
if ($action == 'tpl')
{
$tpl = array('&nbsp;' => '');
$tpl_post = array();
$selected = '';
private static function getTemplateCombo()
{
$tpl = [__('No specific template') => ''];
foreach ($core->templator->tpl as $k => $v) {
if (!preg_match('/^category-(.+)$/',$k) && !preg_match('/^list-(.+)$/',$k))
{
$tpl_post= array_merge($tpl_post, array($k => $k));
}
}
foreach (dcCore::app()->templator->tpl as $k => $v) {
if (!preg_match('/^category-(.+)$/', $k) && !preg_match('/^list-(.+)$/', $k)) {
$tpl[$k] = $k;
}
}
$tpl = array_merge($tpl,$tpl_post);
echo
'<h2 class="page-title">'.__('Select template for these entries').'</h2>'.
'<form action="posts_actions.php" method="post">'.
'<p><label class="classic">'.__('Choose template:').' '.
form::combo('post_tpl',$tpl).
'</label> '.
$hidden_fields.
$core->formNonce().
form::hidden(array('action'),'tpl').
'<input type="submit" value="'.__('Save').'" /></p>'.
'</form>';
}
}
return $tpl;
}
}
?>

View File

@ -1,22 +1,23 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule(
/* Name */ 'Templator',
/* Description*/ 'Create and select more templates for your posts',
/* Author */ 'Osku and contributors',
/* Version */ '1.3.3',
/* Permissions */ 'contentadmin,templator'
'Templator',
'Create and select more templates for your posts',
'Osku and contributors',
'1.4-dev',
[
'requires' => [['core', '2.24']],
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]),
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/templator',
'details' => 'https://plugins.dotaddict.org/dc2/details/templator',
'repository' => 'https://raw.githubusercontent.com/JcDenis/templator/master/dcstore.xml',
]
);
?>

10
_init.php Normal file
View File

@ -0,0 +1,10 @@
<?php
if (!defined('DC_RC_PATH')) {
return null;
}
class initTemplator
{
public const PERMISSION_TEMPLATOR = 'templator';
}

View File

@ -1,32 +1,35 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { exit; }
if (version_compare(DC_VERSION,'2.3.1','<'))
{
$core->error->add(__('Version 2.3.1 of Dotclear at least is required for this version of Templator.'));
$core->plugins->deactivateModule('templator');
return false;
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$new_version = $core->plugins->moduleInfo('templator','version');
try {
# Grab info
$mod_id = basename(__DIR__);
$dc_min = dcCore::app()->plugins->moduleInfo($mod_id, 'requires')[0][1];
$new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version');
$current_version = $core->getVersion('templator');
if (version_compare(dcCore::app()->getVersion($mod_id), $new_version, '>=')) {
return null;
}
if (version_compare($current_version,$new_version,'>=')) {
return;
# Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
throw new Exception(sprintf(
'%s requires Dotclear %s',
$mod_id,
$dc_min
));
}
# Set version
dcCore::app()->setVersion($mod_id, $new_version);
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
$core->setVersion('templator',$new_version);
return true;
?>
return false;

View File

@ -1,48 +1,38 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
//if (version_compare(DC_VERSION,'2.2-beta','<')) { return; }
$__autoload['dcTemplator'] = dirname(__FILE__).'/inc/class.templator.php';
$__autoload['pagerTemplator'] = dirname(__FILE__).'/inc/admin.pager.templator.php';
if (!defined('DC_RC_PATH')) {
return null;
}
Clearbricks::lib()->autoload([
'dcTemplator' => __DIR__ . '/inc/class.templator.php',
'pagerTemplator' => __DIR__ . '/inc/admin.pager.templator.php',
]);
$core->templator = new dcTemplator($core);
dcCore::app()->templator = new dcTemplator();
$core->addBehavior('initWidgets',array('templatorWidgets','initWidgets'));
dcCore::app()->addBehavior('initWidgets', ['templatorWidgets', 'initWidgets']);
class templatorWidgets
{
public static function initWidgets($w)
{
$w->create('templatorWidget',__('Templator Rendering'),array('widgetTemplator','getDataTpl'));
$tpl = array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.html' => '');
foreach ($GLOBALS['core']->templator->tpl as $k => $v) {
if (preg_match('/^widget-(.+)$/',$k))
{
$tpl = array_merge($tpl, array($k => $k));
}
}
$w->templatorWidget->setting('template',__('Template:'),'','combo',$tpl);
}
public static function initWidgets($w)
{
$w->create('templatorWidget', __('Templator Rendering'), ['widgetTemplator', 'getDataTpl']);
$tpl = ['&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.html' => ''];
foreach (dcCore::app()->templator->tpl as $k => $v) {
if (preg_match('/^widget-(.+)$/', $k)) {
$tpl = array_merge($tpl, [$k => $k]);
}
}
$w->templatorWidget->setting('template', __('Template:'), '', 'combo', $tpl);
}
}
class widgetTemplator
{
public static function getDataTpl($w)
{
if (($GLOBALS['core']->tpl->getFilePath($w->template)))
{
echo $GLOBALS['core']->tpl->getData($w->template);
}
}
public static function getDataTpl($w)
{
if (dcCore::app()->tpl->getFilePath($w->template)) {
echo dcCore::app()->tpl->getData($w->template);
}
}
}
?>

View File

@ -1,46 +1,32 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
$core->tpl->setPath($core->tpl->getPath(), $core->templator->path);
$core->addBehavior('urlHandlerBeforeGetData',array('publicTemplatorBehaviors','BeforeGetData'));
if (!defined('DC_RC_PATH')) {
return null;
}
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), dcCore::app()->templator->path);
dcCore::app()->addBehavior('urlHandlerBeforeGetData', ['publicTemplatorBehaviors','BeforeGetData']);
class publicTemplatorBehaviors
{
public static function BeforeGetData ($_ctx)
{
global $core;
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 (array_key_exists($core->url->type,$core->getPostTypes()) || ($core->url->type == 'pages'))
{
$params = array();
$params['meta_type'] = 'template';
$params['post_id'] = $_ctx->posts->post_id;
$post_meta = $core->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 (!$post_meta->isEmpty() && ($core->tpl->getFilePath($post_meta->meta_id)))
{
$_ctx->current_tpl = $post_meta->meta_id;
}
}
if (($_ctx->current_tpl == "category.html") && preg_match('/^[0-9]{1,}/',$_ctx->categories->cat_id,$cat_id))
{
$tpl = 'category-'.$cat_id[0].'.html';
if (($core->tpl->getFilePath($tpl))) {
$_ctx->current_tpl = $tpl;
}
}
}
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;
}
}
}
}
?>

View File

@ -1,79 +1,71 @@
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
?>
<html>
<head>
<title><?php echo __('Templator'); ?></title>
<link rel="stylesheet" type="text/css" href="index.php?pf=tags/style.css" />
</head>
<body>
<?php echo
'<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <a href="'.$p_url.'">'.__('Supplementary templates').'</a> &rsaquo; <span class="page-title">'.__('Database informations').'</span></h2>';
$tags = $core->meta->getMetadata(array('meta_type' => 'template'));
$tags = $core->meta->computeMetaStats($tags);
$tags->sort('meta_id_lower','asc');
$tags = dcCore::app()->meta->getMetadata(['meta_type' => 'template']);
$tags = dcCore::app()->meta->computeMetaStats($tags);
$tags->sort('meta_id_lower', 'asc');
$last_letter = null;
$cols = array('','');
$col = 0;
while ($tags->fetch())
{
$letter = mb_strtoupper(mb_substr($tags->meta_id,0,1));
$cols = ['',''];
$col = 0;
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>';
}
while ($tags->fetch()) {
$letter = mb_strtoupper(mb_substr($tags->meta_id, 0, 1));
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
if (array_key_exists($tags->meta_id,$core->templator->tpl)) {
$img_status = sprintf($img,__('available template'),'check-on.png');
} else {
$img_status = sprintf($img,__('missing template'),'check-off.png');
}
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>';
}
$cols[$col] .=
'<tr class="line">'.
'<td class="maximal"><a href="'.$p_url.
'&amp;m=template_posts&amp;template='.rawurlencode($tags->meta_id).'">'.$tags->meta_id.'</a> '.$img_status.'</td>'.
'<td class="nowrap"><strong>'.$tags->count.'</strong> '.
(($tags->count==1) ? __('entry') : __('entries')).'</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');
}
$last_letter = $letter;
$cols[$col] .= '<tr class="line">' .
'<td class="maximal"><a href="' . $p_url .
'&amp;m=template_posts&amp;template=' . rawurlencode($tags->meta_id) . '">' . $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>';
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>';
}
?>
echo
'<html><head><title>' . __('Templator') . '</title>' .
dcPage::cssLoad(dcPage::getPF('tags/style.css')) .
'</head><body>' .
dcPage::breadcrumb([
html::escapeHTML(dcCore::app()->blog->name) => '',
__('Additional templates') => '',
]) .
dcPage::notices() .
'<p class="top-add"><a class="button add" id="templator-control" href="' .
dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'new']) .
'">' . __('New template') . '</a></p>';
</body>
</html>
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>';
}
dcPage::helpBlock('templator');
echo '</body></html>';

132
edit.php
View File

@ -1,97 +1,79 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
try
{
try
{
if (!empty($_GET['edit'])) {
$name = rawurldecode($_GET['edit']);
$file = $core->templator->getSourceContent($name);
$name = $file['f'];
}
if (preg_match('/^category-(.+).html$/',$name,$cat_id)) {
$category = $core->blog->getCategory($cat_id[1]);
$full_name = '';
$cat_parents = $core->blog->getCategoryParents($cat_id[1]);
while ($cat_parents->fetch()) {$full_name = $cat_parents->cat_title.' &rsaquo; ';};
$full_name = $full_name.$core->blog->getCategory($cat_id)->cat_title;
$name .= '</strong> ('.$full_name.$category->cat_title.')<strong>';
}
}
catch (Exception $e)
{
$file = $file_default;
throw $e;
}
# Write file
if (!empty($_POST['write']))
{
$file['c'] = $_POST['file_content'];
$core->templator->writeTpl($file['f'],$file['c']);
}
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
try {
try {
if (!empty($_GET['edit'])) {
$name = rawurldecode($_GET['edit']);
$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 . ' &rsaquo; ';
};
$full_name = $full_name . dcCore::app()->blog->getCategory($cat_id)->cat_title;
$name .= '</strong> (' . $full_name . $category->cat_title . ')<strong>';
}
} catch (Exception $e) {
$file = $file_default;
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());
}
?>
<html>
<head>
<title><?php echo __('Templator'); ?></title>
<link rel="stylesheet" type="text/css" href="index.php?pf=templator/style/style.css" />
<link rel="stylesheet" type="text/css" href="<?php dcPage::getPF('templator/style/style.css'); ?>" />
<script type="text/javascript">
//<![CDATA[
<?php echo dcPage::jsVar('dotclear.msg.saving_document',__("Saving document...")); ?>
<?php echo dcPage::jsVar('dotclear.msg.document_saved',__("Document saved")); ?>
<?php echo dcPage::jsVar('dotclear.msg.error_occurred',__("An error occurred:")); ?>
<?php echo dcPage::jsVar('dotclear.msg.saving_document', __('Saving document...')); ?>
<?php echo dcPage::jsVar('dotclear.msg.document_saved', __('Document saved')); ?>
<?php echo dcPage::jsVar('dotclear.msg.error_occurred', __('An error occurred:')); ?>
//]]>
</script>
<?php echo dcPage::jsLoad('index.php?pf=templator/js/script.js');?>
<?php echo dcPage::jsLoad(dcPage::getPF('templator/js/script.js'));?>
</head>
<body>
<?php
echo
'<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <a href="'.$p_url.'">'.__('Supplementary templates').'</a> &rsaquo; <span class="page-title">'.__('Edit the template').'</span></h2>';
'<h2>' . html::escapeHTML(dcCore::app()->blog->name) . ' &rsaquo; <a href="' . $p_url . '">' . __('Supplementary templates') . '</a> &rsaquo; <span class="page-title">' . __('Edit the template') . '</span></h2>';
if (($file['c'] !== null))
{
echo
'<div id="file-templator">'.
'<form id="file-form" action="'.$p_url.'&amp;edit='.$name.'" method="post">'.
'<fieldset><legend>'.__('File editor').'</legend>'.
'<p>'.sprintf(__('Editing file %s'),'<strong>'.$name).'</strong></p>'.
'<p>'.form::textarea('file_content',72,30,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>';
if (($file['c'] !== null)) {
echo
'<div id="file-templator">' .
'<form id="file-form" action="' . $p_url . '&amp;edit=' . $name . '" method="post">' .
'<fieldset><legend>' . __('File editor') . '</legend>' .
'<p>' . sprintf(__('Editing file %s'), '<strong>' . $name) . '</strong></p>' .
'<p>' . form::textarea('file_content', 72, 30, html::escapeHTML($file['c']), 'maximal', '', !$file['w']) . '</p>';
if ($file['w'])
{
echo
'<p><input type="submit" name="write" value="'.__('Save').'" accesskey="s" /> '.
$core->formNonce().
form::hidden(array('file_id'),html::escapeHTML($file['f'])).
'</p>';
if ($file['w']) {
echo
'<p><input type="submit" name="write" value="' . __('Save') . '" accesskey="s" /> ' .
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>';
}
}
else
{
echo '<p>'.__('This file is not writable. Please check your files permissions.').'</p>';
}
echo
'</fieldset></form></div>';
echo
'</fieldset></form></div>';
}
?>

View File

@ -1,4 +1,5 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
@ -9,112 +10,114 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
if (!defined('DC_RC_PATH')) {
return;
}
class pagerTemplator
{
public static function templatorItemLine($f,$i)
{
global $core, $p_url;
public static function templatorItemLine($f, $i)
{
$p_url = dcCore::app()->admin->getPageURL();
$fname = $f->basename;
$count = '';
$params = [];
$link = 'media_item.php?id=' . $f->media_id;
$link_edit = $p_url . '&amp;edit=' . $fname;
$icon = dcPage::getPF('templator/img/template.png');
$class = 'media-item media-col-' . ($i % 2);
$details = $special = '';
$widget_icon = '<span class="widget" title="' . __('Template widget') . '">&diams;</span>';
$copy_url = '&amp;copy=';
$fname = $f->basename;
$count = '';
$params = array();
$link = 'media_item.php?id='.$f->media_id;
$link_edit = $p_url.'&amp;edit='.$fname;
$icon = 'index.php?pf=templator/img/template.png';
$class = 'media-item media-col-'.($i%2);
$details = $special = '';
$widget_icon = '<span class="widget" title="'.__('Template widget').'">&diams;</span>';
$copy_url = '&amp;copy=';
if (preg_match('/^category-(.+)$/', $f->basename)) {
// That is ugly.
$cat_id = str_replace('category-', '', $f->basename);
$cat_id = str_replace('.html', '', $cat_id);
$cat_parents = dcCore::app()->blog->getCategoryParents($cat_id);
$full_name = '';
while ($cat_parents->fetch()) {
$full_name = $cat_parents->cat_title . ' &rsaquo; ';
};
$fname = '<strong>' . __('Category') . '</strong> :&nbsp;' . $full_name . dcCore::app()->blog->getCategory($cat_id)->cat_title;
$params['cat_id'] = $cat_id;
$params['post_type'] = '';
$icon = dcPage::getPF('templator/img/template-alt.png');
$copy_url = '&amp;copycat=';
if (preg_match('/^category-(.+)$/',$f->basename)) {
// That is ugly.
$cat_id = str_replace('category-', '', $f->basename);
$cat_id = str_replace('.html', '', $cat_id);
$cat_parents = $core->blog->getCategoryParents($cat_id);
$full_name = '';
while ($cat_parents->fetch()) {$full_name = $cat_parents->cat_title.' &rsaquo; ';};
$fname = '<strong>'.__('Category').'</strong> :&nbsp;'.$full_name.$core->blog->getCategory($cat_id)->cat_title;
$params['cat_id'] = $cat_id;
$params['post_type'] = '';
$icon = 'index.php?pf=templator/img/template-alt.png';
$copy_url = '&amp;copycat=';
try {
$counter = $core->blog->getPosts($params,true);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
try {
$counter = dcCore::app()->blog->getPosts($params, true);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
if ($counter->f(0) == 0) {
$count = __('No entry');
} elseif ($counter->f(0) == 1) {
$count = '<strong>'.$counter->f(0).'</strong> <a href="posts.php?cat_id='.$cat_id.'">'.__('entry').'</a>';
} else {
$count = '<strong>'.$counter->f(0).'</strong> <a href="posts.php?cat_id='.$cat_id.'">'.__('entries').'</a>';
}
}
elseif (preg_match('/^widget-(.+)$/',$f->basename)) {
$count = '&nbsp;';
$icon = 'index.php?pf=templator/img/template-widget.png';
$special = $widget_icon;
}
else {
$params['meta_id'] = $f->basename;
$params['meta_type'] = 'template';
$params['post_type'] = '';
try {
$counter = $core->meta->getPostsByMeta($params,true);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
if ($counter->f(0) == 0) {
$count = '&nbsp;';
} elseif ($counter->f(0) == 1) {
$count = '<strong>'.$counter->f(0).'</strong> <a href="'.$p_url.'&amp;m=template_posts&amp;template='.$fname.'">'.__('entry').'</a>';
} else {
$count = '<strong>'.$counter->f(0).'</strong> <a href="'.$p_url.'&amp;m=template_posts&amp;template='.$fname.'">'.__('entries').'</a>';
}
}
if ($counter->f(0) == 0) {
$count = __('No entry');
} elseif ($counter->f(0) == 1) {
$count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entry') . '</a>';
} else {
$count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entries') . '</a>';
}
} elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
$count = '&nbsp;';
$icon = dcPage::getPF('templator/img/template-widget.png');
$special = $widget_icon;
} else {
$params['meta_id'] = $f->basename;
$params['meta_type'] = 'template';
$params['post_type'] = '';
$res =
'<div class="'.$class.'"><a class="media-icon media-link" href="'.$link_edit.'">'.
'<img src="'.$icon.'" alt="" /></a>'.
'<ul>'.
'<li><a class="media-link" href="'.$link_edit.'">'.$fname.'</a> '.$special.'</li>';
try {
$counter = dcCore::app()->meta->getPostsByMeta($params, true);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
if ($counter->f(0) == 0) {
$count = '&nbsp;';
} elseif ($counter->f(0) == 1) {
$count = '<strong>' . $counter->f(0) . '</strong> <a href="' . $p_url . '&amp;m=template_posts&amp;template=' . $fname . '">' . __('entry') . '</a>';
} else {
$count = '<strong>' . $counter->f(0) . '</strong> <a href="' . $p_url . '&amp;m=template_posts&amp;template=' . $fname . '">' . __('entries') . '</a>';
}
}
if($core->auth->check('contentadmin,media',$core->blog->id)) {
$details = ' - <a href="'.$link.'">'.__('details').'</a>';
}
$res = '<div class="' . $class . '"><a class="media-icon media-link" href="' . $link_edit . '">' .
'<img src="' . $icon . '" alt="" /></a>' .
'<ul>' .
'<li><a class="media-link" href="' . $link_edit . '">' . $fname . '</a> ' . $special . '</li>';
if (!$f->d) {
$res .=
'<li>'.$count.'</li>'.
'<li>'.
$f->media_dtstr.' - '.
files::size($f->size).
$details.
'</li>';
}
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]), dcCore::app()->blog->id)) {
$details = ' - <a href="' . $link . '">' . __('details') . '</a>';
}
$res .= '<li class="media-action">&nbsp;';
if (!$f->d) {
$res .= '<li>' . $count . '</li>' .
'<li>' .
$f->media_dtstr . ' - ' .
files::size($f->size) .
$details .
'</li>';
}
$res .= '<a class="media-remove" '.
'href="'.$p_url.$copy_url.rawurlencode($f->basename).'">'.
'<img src="index.php?pf=templator/img/copy.png" alt="'.__('copy').'" title="'.__('copy the template').'" /></a>&nbsp;';
$res .= '<li class="media-action">&nbsp;';
$res .= '<a class="media-remove" ' .
'href="' . $p_url . $copy_url . rawurlencode($f->basename) . '">' .
'<img src="' . dcPage::getPF('templator/img/copy.png') . '" alt="' . __('copy') . '" title="' . __('copy the template') . '" /></a>&nbsp;';
if ($f->del) {
$res .= '<a class="media-remove" '.
'href="'.$p_url.'&amp;remove='.rawurlencode($f->basename).'">'.
'<img src="index.php?pf=templator/img/delete.png" alt="'.__('delete').'" title="'.__('delete the template').'" /></a>';
}
if ($f->del) {
$res .= '<a class="media-remove" ' .
'href="' . $p_url . '&amp;remove=' . rawurlencode($f->basename) . '">' .
'<img src="' . dcPage::getPF('templator/img/delete.png') . '" alt="' . __('delete') . '" title="' . __('delete the template') . '" /></a>';
}
$res .= '</li>';
$res .= '</li>';
$res .= '</ul></div>';
$res .= '</ul></div>';
return $res;
}
return $res;
}
}
?>

View File

@ -1,380 +1,353 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
if (!defined('DC_RC_PATH')) {
return null;
}
class dcTemplator
{
protected $post_default_name = 'post.html';
protected $page_default_name = 'page.html';
protected $category_default_name = 'category.html';
public $template_dir_name = 'other-templates';
public $path;
public $tpl = array();
public $theme_tpl = array();
/**
*
*/
public function __construct($core)
{
$this->core =& $core;
$this->path = $this->core->blog->public_path.'/'.$this->template_dir_name;
// Initial templates
$this->post_tpl = DC_ROOT.'/inc/public/default-templates/'.$this->post_default_name;
$this->category_tpl = DC_ROOT.'/inc/public/default-templates/'.$this->category_default_name;
if ($this->core->plugins->moduleExists('pages')) {
$plugin_page = $this->core->plugins->getModules('pages');
$this->page_tpl = path::real($plugin_page['root'].'/default-templates/'.$this->page_default_name);
}
$this->user_theme = $this->core->blog->themes_path.'/'.$this->core->blog->settings->system->theme;
$this->user_post_tpl = path::real($this->user_theme.'/tpl/'.$this->post_default_name);
$this->user_category_tpl = path::real($this->user_theme.'/tpl/'.$this->category_default_name);
$this->user_page_tpl = path::real($this->user_theme.'/tpl/'.$this->page_default_name);
$this->findTemplates();
}
/**
*
*/
public function canUseRessources($create=false)
{
if (!is_dir($this->path)) {
if ($create) {
files::makeDir($this->path);
}
return true;
}
if (!is_writable($this->path)) {
return false;
}
if (!is_file($this->path.'/.htaccess')) {
try {
file_put_contents($this->path.'/.htaccess',"Deny from all\n");
}
catch (Exception $e) {return false;}
}
return true;
}
/**
*
*/
public function getSourceContent($f)
{
$source = $this->tpl;
if (!isset($source[$f])) {
throw new Exception(__('File does not exist.'));
}
$F = $source[$f];
if (!is_readable($F)) {
throw new Exception(sprintf(__('File %s is not readable'),$f));
}
return array(
'c' => file_get_contents($source[$f]),
'w' => $this->getDestinationFile($f) !== false,
'f' => $f
);
}
/**
*
*/
public function filesList($item='%1$s')
{
$files = $this->tpl;
if (empty($files)) {
return '<p>'.__('No file').'</p>';
}
$list = '';
foreach ($files as $k => $v)
{
$li = sprintf('<li>%s</li>',$item);
$list .= sprintf($li,$k,html::escapeHTML($k));
}
return sprintf('<ul>%s</ul>',$list);
}
/**
*
*/
public function initializeTpl($name,$type)
{
if ($type == 'category')
{
if ($this->user_category_tpl) {
$base = $this->user_category_tpl;
} else {
$base = $this->category_tpl;
}
}
elseif ($type == 'page')
{
if ($this->user_page_tpl) {
$base = $this->user_page_tpl;
} else {
$base = $this->page_tpl;
}
}
else {
if ($this->user_post_tpl) {
$base = $this->user_post_tpl;
} else {
$base = $this->post_tpl;
}
}
$source = array(
'c' => file_get_contents($base),
'w' => $this->getDestinationFile($name) !== false,
'f' => $f);
if (!$source['w'])
{
throw new Exception(sprintf(__('File %s is not readable'),$source));
}
if ($type == 'empty')
{
$source['c'] = '';
}
try
{
$dest = $this->getDestinationFile($name);
if ($dest == false) {
throw new Exception();
}
$content = $source['c'];
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest,'wb');
if (!$fp) {
throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m',"\n",$content);
$content = preg_replace('/\r/m',"\n",$content);
fwrite($fp,$content);
fclose($fp);
}
catch (Exception $e)
{
throw $e;
}
}
/**
*
*/
public function copypasteTpl($name,$source)
{
if ($name == $source) {throw new Exception(__('Why copy file content in the same file?'));}
$file = $this->getSourceContent($source);
$source = array(
'c' => $file['c'],
'w' => $this->getDestinationFile($name) !== false,
'f' => $f);
if (!$source['w'])
{
throw new Exception(sprintf(__('File %s is not readable'),$source));
}
if ($type == 'empty')
{
$source['c'] = '';
}
try
{
$dest = $this->getDestinationFile($name);
if ($dest == false) {
throw new Exception();
}
$content = $source['c'];
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest,'wb');
if (!$fp) {
throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m',"\n",$content);
$content = preg_replace('/\r/m',"\n",$content);
fwrite($fp,$content);
fclose($fp);
}
catch (Exception $e)
{
throw $e;
}
}
/**
*
*/
public function writeTpl($name,$content)
{
try
{
$dest = $this->getDestinationFile($name);
if ($dest == false) {
throw new Exception();
}
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest,'wb');
if (!$fp) {
//throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m',"\n",$content);
$content = preg_replace('/\r/m',"\n",$content);
fwrite($fp,$content);
fclose($fp);
}
catch (Exception $e)
{
throw $e;
}
}
/**
*
*/
public function copyTpl($name)
{
try
{
$file = $this->getSourceContent($name);
$dest = $this->getDestinationFile($name,true);
if ($dest == false) {
throw new Exception();
}
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest,'wb');
if (!$fp) {
throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m',"\n",$file['c']);
$content = preg_replace('/\r/m',"\n",$file['c']);
fwrite($fp,$file['c']);
fclose($fp);
}
catch (Exception $e)
{
throw $e;
}
}
protected function getDestinationFile($f,$totheme=false)
{
$dest = $this->path.'/'.$f;
if ($totheme) {
$dest = $this->user_theme.'/tpl/'.$f;
}
if (file_exists($dest) && is_writable($dest)) {
return $dest;
}
if (is_writable(dirname($dest))) {
return $dest;
}
return false;
}
protected function findTemplates()
{
$this->tpl = $this->getFilesInDir($this->path);
//$this->theme_tpl = $this->getFilesInDir(path::real($this->user_theme).'/tpl');
uksort($this->tpl,array($this,'sortFilesHelper'));
//uksort($this->theme_tpl,array($this,'sortFilesHelper'));
}
protected function getFilesInDir($dir)
{
$dir = path::real($dir);
if (!$dir || !is_dir($dir) || !is_readable($dir)) {
return array();
}
$d = dir($dir);
$res = array();
while (($f = $d->read()) !== false)
{
if (is_file($dir.'/'.$f) && !preg_match('/^\./',$f)) {
$res[$f] = $dir.'/'.$f;
}
}
return $res;
}
protected function sortFilesHelper($a,$b)
{
if ($a == $b) {
return 0;
}
$ext_a = files::getExtension($a);
$ext_b = files::getExtension($b);
return strcmp($ext_a.'.'.$a,$ext_b.'.'.$b);
}
protected $tpls_default_name = 'dotty';
protected $post_default_name = 'post.html';
protected $page_default_name = 'page.html';
protected $category_default_name = 'category.html';
public $template_dir_name = 'other-templates';
public $path;
public $tpl = [];
public $theme_tpl = [];
/**
*
*/
public function __construct()
{
$this->path = dcCore::app()->blog->public_path . '/' . $this->template_dir_name;
// Initial templates
$this->post_tpl = DC_ROOT . '/inc/public/default-templates/' . $this->tpls_default_name . '/' . $this->post_default_name;
$this->category_tpl = DC_ROOT . '/inc/public/default-templates/' . $this->tpls_default_name . '/' . $this->category_default_name;
if (dcCore::app()->plugins->moduleExists('pages')) {
$plugin_page = dcCore::app()->plugins->getModules('pages');
$this->page_tpl = path::real($plugin_page['root'] . '/default-templates/' . $this->tpls_default_name . '/' . $this->page_default_name);
}
$this->user_theme = dcCore::app()->blog->themes_path . '/' . dcCore::app()->blog->settings->system->theme;
$this->user_post_tpl = path::real($this->user_theme . '/tpl/' . $this->post_default_name);
$this->user_category_tpl = path::real($this->user_theme . '/tpl/' . $this->category_default_name);
$this->user_page_tpl = path::real($this->user_theme . '/tpl/' . $this->page_default_name);
$this->findTemplates();
}
/**
*
*/
public function canUseRessources($create = false)
{
if (!is_dir($this->path)) {
if ($create) {
files::makeDir($this->path);
}
return true;
}
if (!is_writable($this->path)) {
return false;
}
if (!is_file($this->path . '/.htaccess')) {
try {
file_put_contents($this->path . '/.htaccess', "Deny from all\n");
} catch (Exception $e) {
return false;
}
}
return true;
}
/**
*
*/
public function getSourceContent($f)
{
$source = $this->tpl;
if (!isset($source[$f])) {
throw new Exception(__('File does not exist.'));
}
$F = $source[$f];
if (!is_readable($F)) {
throw new Exception(sprintf(__('File %s is not readable'), $f));
}
return [
'c' => file_get_contents($source[$f]),
'w' => $this->getDestinationFile($f) !== false,
'f' => $f,
];
}
/**
*
*/
public function filesList($item = '%1$s')
{
$files = $this->tpl;
if (empty($files)) {
return '<p>' . __('No file') . '</p>';
}
$list = '';
foreach ($files as $k => $v) {
$li = sprintf('<li>%s</li>', $item);
$list .= sprintf($li, $k, html::escapeHTML($k));
}
return sprintf('<ul>%s</ul>', $list);
}
/**
*
*/
public function initializeTpl($name, $type)
{
if ($type == 'category') {
if ($this->user_category_tpl) {
$base = $this->user_category_tpl;
} else {
$base = $this->category_tpl;
}
} elseif ($type == 'page') {
if ($this->user_page_tpl) {
$base = $this->user_page_tpl;
} else {
$base = $this->page_tpl;
}
} else {
if ($this->user_post_tpl) {
$base = $this->user_post_tpl;
} else {
$base = $this->post_tpl;
}
}
$source = [
'c' => file_get_contents($base),
'w' => $this->getDestinationFile($name) !== false,
'f' => $f, ];
if (!$source['w']) {
throw new Exception(sprintf(__('File %s is not readable'), $source));
}
if ($type == 'empty') {
$source['c'] = '';
}
try {
$dest = $this->getDestinationFile($name);
if ($dest == false) {
throw new Exception();
}
$content = $source['c'];
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest, 'wb');
if (!$fp) {
throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m', "\n", $content);
$content = preg_replace('/\r/m', "\n", $content);
fwrite($fp, $content);
fclose($fp);
} catch (Exception $e) {
throw $e;
}
}
/**
*
*/
public function copypasteTpl($name, $source)
{
if ($name == $source) {
throw new Exception(__('Why copy file content in the same file?'));
}
$file = $this->getSourceContent($source);
$source = [
'c' => $file['c'],
'w' => $this->getDestinationFile($name) !== false,
'f' => $f, ];
if (!$source['w']) {
throw new Exception(sprintf(__('File %s is not readable'), $source));
}
if ($type == 'empty') {
$source['c'] = '';
}
try {
$dest = $this->getDestinationFile($name);
if ($dest == false) {
throw new Exception();
}
$content = $source['c'];
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest, 'wb');
if (!$fp) {
throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m', "\n", $content);
$content = preg_replace('/\r/m', "\n", $content);
fwrite($fp, $content);
fclose($fp);
} catch (Exception $e) {
throw $e;
}
}
/**
*
*/
public function writeTpl($name, $content)
{
try {
$dest = $this->getDestinationFile($name);
if ($dest == false) {
throw new Exception();
}
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest, 'wb');
if (!$fp) {
//throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m', "\n", $content);
$content = preg_replace('/\r/m', "\n", $content);
fwrite($fp, $content);
fclose($fp);
} catch (Exception $e) {
throw $e;
}
}
/**
*
*/
public function copyTpl($name)
{
try {
$file = $this->getSourceContent($name);
$dest = $this->getDestinationFile($name, true);
if ($dest == false) {
throw new Exception();
}
if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
}
$fp = @fopen($dest, 'wb');
if (!$fp) {
throw new Exception('tocatch');
}
$content = preg_replace('/(\r?\n)/m', "\n", $file['c']);
$content = preg_replace('/\r/m', "\n", $file['c']);
fwrite($fp, $file['c']);
fclose($fp);
} catch (Exception $e) {
throw $e;
}
}
protected function getDestinationFile($f, $totheme = false)
{
$dest = $this->path . '/' . $f;
if ($totheme) {
$dest = $this->user_theme . '/tpl/' . $f;
}
if (file_exists($dest) && is_writable($dest)) {
return $dest;
}
if (is_writable(dirname($dest))) {
return $dest;
}
return false;
}
protected function findTemplates()
{
$this->tpl = $this->getFilesInDir($this->path);
//$this->theme_tpl = $this->getFilesInDir(path::real($this->user_theme).'/tpl');
uksort($this->tpl, [$this,'sortFilesHelper']);
//uksort($this->theme_tpl,array($this,'sortFilesHelper'));
}
protected function getFilesInDir($dir)
{
$dir = path::real($dir);
if (!$dir || !is_dir($dir) || !is_readable($dir)) {
return [];
}
$d = dir($dir);
$res = [];
while (($f = $d->read()) !== false) {
if (is_file($dir . '/' . $f) && !preg_match('/^\./', $f)) {
$res[$f] = $dir . '/' . $f;
}
}
return $res;
}
protected function sortFilesHelper($a, $b)
{
if ($a == $b) {
return 0;
}
$ext_a = files::getExtension($a);
$ext_b = files::getExtension($b);
return strcmp($ext_a . '.' . $a, $ext_b . '.' . $b);
}
}
?>

433
index.php
View File

@ -1,313 +1,292 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of templator a plugin for Dotclear 2.
#
# Copyright (c) 2010 Osku and contributors
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
dcPage::check('templator,contentadmin');
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
dcPage::check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
initTemplator::PERMISSION_TEMPLATOR,
]));
$p_url = dcCore::app()->admin->getPageURL();
if ((!empty($_REQUEST['m'])) && ($_REQUEST['m'] = 'template_posts')) {
require dirname(__FILE__).'/'.$_REQUEST['m'].'.php';
return;
require dirname(__FILE__) . '/' . $_REQUEST['m'] . '.php';
return;
}
if (!empty($_REQUEST['edit'])) {
require dirname(__FILE__).'/edit.php';
return;
require dirname(__FILE__) . '/edit.php';
return;
}
if (!empty($_REQUEST['database']) && $_REQUEST['database'] = 'on') {
require dirname(__FILE__).'/advanced.php';
return;
require dirname(__FILE__) . '/advanced.php';
return;
}
$file_default = $file = array('c'=>null, 'w'=>false, 'type'=>null, 'f'=>null, 'default_file'=>false);
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
$nb_per_page = 20;
$msg = '';
$file_default = $file = ['c' => null, 'w' => false, 'type' => null, 'f' => null, 'default_file' => false];
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
$nb_per_page = 20;
$msg = '';
$remove_confirm = false;
// Load infos.
$ressources = $core->templator->canUseRessources(true);
$files= $core->templator->tpl;
$ressources = dcCore::app()->templator->canUseRessources(true);
$files = dcCore::app()->templator->tpl;
// Media
$media = new dcMedia($core);
$media->chdir($core->templator->template_dir_name);
$media = new dcMedia();
$media->chdir(dcCore::app()->templator->template_dir_name);
// For users with only templator permission, we use sudo.
$core->auth->sudo(array($media,'getDir'));
$dir =& $media->dir;
dcCore::app()->auth->sudo([$media,'getDir']);
$dir = & $media->dir;
//if files did not appear in this list, check blog->settings->media_exclusion
$items = array_values($dir['files']);
// Categories
try {
$categories = $core->blog->getCategories(array('post_type'=>'post'));
$categories = dcCore::app()->blog->getCategories(['post_type' => 'post']);
$categories_combo = array();
$l = $categories->level;
$full_name = array($categories->cat_title);
$categories_combo = [];
$l = $categories->level;
$full_name = [$categories->cat_title];
while ($categories->fetch()) {
while ($categories->fetch()) {
if ($categories->level < $l) {
$full_name = [];
} elseif ($categories->level == $l) {
array_pop($full_name);
}
$full_name[] = html::escapeHTML($categories->cat_title);
if ($categories->level < $l) {
$full_name = array();
} elseif ($categories->level == $l) {
array_pop($full_name);
}
$full_name[] = html::escapeHTML($categories->cat_title);
$categories_combo[implode(' &rsaquo; ',$full_name)] = $categories->cat_id;
$l = $categories->level;
}
} catch (Exception $e) { }
$categories_combo[implode(' &rsaquo; ', $full_name)] = $categories->cat_id;
$l = $categories->level;
}
} catch (Exception $e) {
}
$hasCategories = ($categories->isEmpty()) ? false : true;
$combo_source = array(
'post.html' => 'post'
);
$combo_source = [
'post.html' => 'post',
];
if ($core->auth->check('pages',$core->blog->id) && $core->plugins->moduleExists('pages')) {
$combo_source['page.html'] = 'page';
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';
}
if (!$categories->isEmpty()) {
$combo_source['category.html'] = 'category';
$combo_source['category.html'] = 'category';
}
$combo_source[' &mdash; '] = 'empty';
$add_template = $copy_confirm = $copycat_confirm = false;
if (!$ressources)
{
$core->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
if (!$ressources) {
dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
}
if (!empty($_POST['filesource']))
{
try
{
$source = $_POST['filesource'];
if (empty($_POST['filename']) && $source != 'category') {
throw new Exception(__('Filename is empty.'));
}
$name = files::tidyFileName($_POST['filename']).'.html';
if ($source == 'category')
{
$name = 'category-'.$_POST['filecat'].'.html';
}
$core->templator->initializeTpl($name,$source);
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
if (!$core->error->flag()) {
http::redirect($p_url.'&msg=new');
}
if (!empty($_POST['filesource'])) {
try {
$source = $_POST['filesource'];
if (empty($_POST['filename']) && $source != 'category') {
throw new Exception(__('Filename is empty.'));
}
$name = files::tidyFileName($_POST['filename']) . '.html';
if ($source == 'category') {
$name = 'category-' . $_POST['filecat'] . '.html';
}
dcCore::app()->templator->initializeTpl($name, $source);
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());
}
}
if (!empty($_POST['rmyes']) && !empty($_POST['remove']) ) {
try
{
$file = rawurldecode($_POST['remove']);
$media->removeItem($file);
$core->meta->delMeta($file,'template');
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
if (!$core->error->flag()) {
http::redirect($p_url.'&msg=del');
}
if (!empty($_POST['rmyes']) && !empty($_POST['remove'])) {
try {
$file = rawurldecode($_POST['remove']);
$media->removeItem($file);
dcCore::app()->meta->delMeta($file, 'template');
if (!dcCore::app()->error->flag()) {
dcAdminNotices::addSuccessNotice(__('The template has been successfully removed.'));
dcCore::app()->adminurl->redirect('admin.plugin.templator');
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
if (!empty($_POST['cpyes']) && !empty($_POST['copy']) && !empty($_POST['newfile'])) {
try
{
$file = rawurldecode($_POST['copy']);
$newfile = rawurldecode($_POST['newfile']).'.html';
$core->templator->copypasteTpl($newfile,$file);
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
if (!$core->error->flag()) {
http::redirect($p_url.'&msg=cpy');
}
try {
$file = rawurldecode($_POST['copy']);
$newfile = rawurldecode($_POST['newfile']) . '.html';
dcCore::app()->templator->copypasteTpl($newfile, $file);
if (!dcCore::app()->error->flag()) {
dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.'));
dcCore::app()->adminurl->redirect('admin.plugin.templator');
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
if (!empty($_POST['cpyes']) && !empty($_POST['copycat']) && !empty($_POST['copcat'])) {
try
{
$file = rawurldecode($_POST['copycat']);
$newfile = 'category-'.rawurldecode($_POST['copcat']).'.html';
$core->templator->copypasteTpl($newfile,$file);
}
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
if (!$core->error->flag()) {
http::redirect($p_url.'&msg=cpy');
}
try {
$file = rawurldecode($_POST['copycat']);
$newfile = 'category-' . rawurldecode($_POST['copcat']) . '.html';
dcCore::app()->templator->copypasteTpl($newfile, $file);
if (!dcCore::app()->error->flag()) {
dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.'));
dcCore::app()->adminurl->redirect('admin.plugin.templator');
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
if (!empty($_GET['remove']))
{
$remove_confirm = true;
if (!empty($_GET['remove'])) {
$remove_confirm = true;
}
if (!empty($_GET['copy']))
{
$copy_confirm = true;
if (!empty($_GET['copy'])) {
$copy_confirm = true;
}
if (!empty($_GET['copycat']))
{
$copycat_confirm = true;
if (!empty($_GET['copycat'])) {
$copycat_confirm = true;
}
$msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : '';
$msg_list = array(
'new' => __('The new template has been successfully created.'),
'del' => __('The template has been successfully removed.'),
'cpy' => __('The template has been successfully copied.')
);
if (isset($msg_list[$msg])) {
$msg = sprintf('<p class="message">%s</p>',$msg_list[$msg]);
}
?>
<html>
<head>
<title><?php echo __('Templator'); ?></title>
<link rel="stylesheet" type="text/css" href="index.php?pf=templator/style/style.css" />
<?php if (!$add_template) {
echo dcPage::jsLoad('index.php?pf=templator/js/form.js');
}?>
<?php echo dcPage::jsLoad('index.php?pf=templator/js/script.js');?>
</head>
<body>
<?php
echo $msg;
echo
'<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <span class="page-title">'.__('Supplementary templates').'</span></h2>';
'<html><head><title>' . __('Templator') . '</title>' .
dcPage::cssLoad(dcPage::getPF('templator/style/style.css')) .
(!$add_template ? dcPage::jsLoad(dcPage::getPF('templator/js/form.js')) : '') .
dcPage::jsLoad(dcPage::getPF('templator/js/script.js')) .
'</head><body>' .
dcPage::breadcrumb([
html::escapeHTML(dcCore::app()->blog->name) => '',
__('Additional templates') => '',
]) .
dcPage::notices();
if ($remove_confirm) {
echo
'<form action="'.$p_url.'" method="post">'.
'<p>'.sprintf(__('Are you sure you want to remove the template "%s"?'),
html::escapeHTML($_GET['remove'])).'</p>'.
'<p><input type="submit" class="delete" value="'.__('Cancel').'" /> '.
' &nbsp; <input type="submit" name="rmyes" value="'.__('Yes').'" />'.
$core->formNonce().
form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'.
'</form>';
echo
'<form action="' . $p_url . '" method="post">' .
'<p>' . sprintf(
__('Are you sure you want to remove the template "%s"?'),
html::escapeHTML($_GET['remove'])
) . '</p>' .
'<p><input type="submit" class="delete" value="' . __('Cancel') . '" /> ' .
' &nbsp; <input type="submit" name="rmyes" value="' . __('Yes') . '" />' .
dcCore::app()->formNonce() .
form::hidden('remove', html::escapeHTML($_GET['remove'])) . '</p>' .
'</form>';
}
if ($copy_confirm) {
echo
'<form action="'.$p_url.'" method="post">'.
'<p>'.sprintf(__('To copy the template <strong>%s</strong>, you need to fill a new filename.'),
html::escapeHTML($_GET['copy'])).'</p>'.
'<p><label for="filename" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('New filename:').' '.
form::field('newfile',25,255).'</label><code>'.html::escapeHTML('.html').'</code>&nbsp; '.
'<input type="submit" name="cpyes" value="'.__('Copy').'" /> &nbsp;<input class="delete" type="submit" value="'.__('Cancel').'" />'.
$core->formNonce().
form::hidden('copy',html::escapeHTML($_GET['copy'])).'</p>'.
'</form>';
echo
'<form action="' . $p_url . '" method="post">' .
'<p>' . sprintf(
__('To copy the template <strong>%s</strong>, you need to fill a new filename.'),
html::escapeHTML($_GET['copy'])
) . '</p>' .
'<p><label for="filename" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('New filename:') . ' ' .
form::field('newfile', 25, 255) . '</label><code>' . html::escapeHTML('.html') . '</code>&nbsp; ' .
'<input type="submit" name="cpyes" value="' . __('Copy') . '" /> &nbsp;<input class="delete" type="submit" value="' . __('Cancel') . '" />' .
dcCore::app()->formNonce() .
form::hidden('copy', html::escapeHTML($_GET['copy'])) . '</p>' .
'</form>';
}
if ($copycat_confirm) {
$category_id = str_replace('category-', '', $_GET['copycat']);
$category_id = str_replace('.html', '', $category_id);
$cat_parents = $core->blog->getCategoryParents($category_id);
$full_name = '';
while ($cat_parents->fetch()) {$full_name = $cat_parents->cat_title.' &rsaquo; ';};
$name = $full_name.$core->blog->getCategory($category_id)->cat_title;
echo
'<form action="'.$p_url.'" method="post">'.
'<p>'.sprintf(__('To copy the template <strong>%s</strong> (%s), you need to choose a category.'),
html::escapeHTML($_GET['copycat']),$name).'</p>'.
'<p class="field"><label for="copcat" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Target category:').
form::combo('copcat',$categories_combo,'').'</label></p>'.
'<input type="submit" name="cpyes" value="'.__('Copy').'" /> &nbsp;<input class="delete" type="submit" value="'.__('Cancel').'" />'.
$core->formNonce().
form::hidden('copycat',html::escapeHTML($_GET['copycat'])).
'</form>';
$category_id = str_replace('category-', '', $_GET['copycat']);
$category_id = str_replace('.html', '', $category_id);
$cat_parents = dcCore::app()->blog->getCategoryParents($category_id);
$full_name = '';
while ($cat_parents->fetch()) {
$full_name = $cat_parents->cat_title . ' &rsaquo; ';
};
$name = $full_name . dcCore::app()->blog->getCategory($category_id)->cat_title;
echo
'<form action="' . $p_url . '" method="post">' .
'<p>' . sprintf(
__('To copy the template <strong>%s</strong> (%s), you need to choose a category.'),
html::escapeHTML($_GET['copycat']),
$name
) . '</p>' .
'<p class="field"><label for="copcat" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Target category:') .
form::combo('copcat', $categories_combo, '') . '</label></p>' .
'<input type="submit" name="cpyes" value="' . __('Copy') . '" /> &nbsp;<input class="delete" type="submit" value="' . __('Cancel') . '" />' .
$dcCore::app()->formNonce() .
form::hidden('copycat', html::escapeHTML($_GET['copycat'])) .
'</form>';
}
if (!$add_template) {
echo '<p class="top-add"><a class="button add" id="templator-control" href="#">'.
__('New template').'</a></p>';
echo '<p class="top-add"><a class="button add" id="templator-control" href="#">' .
__('New template') . '</a></p>';
}
echo
'<form action="'.$p_url.'" method="post" id="add-template">'.
'<h3>'.__('New template').'</h3>'.
'<p class="field"><label for="filesource" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Template source:').' '.
form::combo('filesource',$combo_source).'</label></p>'.
'<p class="field two-cols"><label for="filename" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Filename:').' '.
form::field('filename',25,255).'</label></p></br />
<p class="form-note warn">'.__('Extension <strong><code>.html</code></strong> is automatically added to filename').'</p>
'<form action="' . $p_url . '" method="post" id="add-template">' .
'<h3>' . __('New template') . '</h3>' .
'<p class="field"><label for="filesource" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Template source:') . ' ' .
form::combo('filesource', $combo_source) . '</label></p>' .
'<p class="field two-cols"><label for="filename" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Filename:') . ' ' .
form::field('filename', 25, 255) . '</label></p></br />
<p class="form-note warn">' . __('Extension <strong><code>.html</code></strong> is automatically added to filename') . '</p>
';
if ($hasCategories) {
echo '<p class="field"><label for="filecat" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Category:').
form::combo('filecat',$categories_combo,'').'</label></p>';
echo '<p class="field"><label for="filecat" class="required"><abbr title="' . __('Required field') . '">*</abbr>' . __('Category:') .
form::combo('filecat', $categories_combo, '') . '</label></p>';
}
echo
'<p>'.form::hidden(array('p'),'templator').
$core->formNonce().
'<input type="submit" name="add_message" value="'.__('Create').'" /></p>'.
'<p>' . form::hidden(['p'], 'templator') .
dcCore::app()->formNonce() .
'<input type="submit" name="add_message" value="' . __('Create') . '" /></p>' .
'</form>';
if (count($items) == 0)
{
echo '<p><strong>'.__('No template.').'</strong></p>';
}
else
{
$pager = new pager($page,count($items),$nb_per_page,10);
$pager->html_prev = __('&#171;prev.');
$pager->html_next = __('next&#187;');
if (count($items) == 0) {
echo '<p><strong>' . __('No template.') . '</strong></p>';
} else {
$pager = new pager($page, count($items), $nb_per_page, 10);
$pager->html_prev = __('&#171;prev.');
$pager->html_next = __('next&#187;');
echo
'<form action="media.php" method="get">'.
'</form>'.
echo
'<form action="media.php" method="get">' .
'</form>' .
'<div class="media-list">'.
'<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
'<div class="media-list">' .
'<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++, $j++)
{
echo pagerTemplator::templatorItemLine($items[$i],$j);
}
for ($i = $pager->index_start, $j = 0; $i <= $pager->index_end; $i++, $j++) {
echo pagerTemplator::templatorItemLine($items[$i], $j);
}
echo
'<p class="clear">'.__('Page(s)').' : '.$pager->getLinks().'</p>'.
'</div>';
echo
'<p class="clear">' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>' .
'</div>';
}
echo
'<p class="clear">
'<p class="clear">
<a class="button"
href="'.$p_url.'&amp;database=on"
title="'.__('Display templates used for entries in base').'"
>'.
__('Display templates used for entries in base').'
href="' . $p_url . '&amp;database=on"
title="' . __('Display templates used for entries in base') . '"
>' .
__('Display templates used for entries in base') . '
</a>
</p>';
?>

7
js/admin.js Normal file
View File

@ -0,0 +1,7 @@
$(function(){
/* toogle admin form sidebar */
$('#templator h5').toggleWithLegend(
$('#templator').children().not('h5'),
{cookie:'dcx_templator_admin_form_sidebar',legend_click:true}
);
});

View File

@ -1,4 +1,5 @@
<?php
// Language: Français
// Module: templator - 1.3.3
// Date: 2012-10-02 12:59:08
@ -146,5 +147,3 @@ $GLOBALS['__l10n']['Back to templates list'] = 'Retour à la liste des templates
#template_posts.php:128
$GLOBALS['__l10n']['Unselect the template'] = 'Désélectionner le template';
?>

View File

@ -9,71 +9,79 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
$template = (!empty($_REQUEST['template']) || $_REQUEST['template'] == '0') ? $_REQUEST['template'] : '';
$this_url = $p_url.'&amp;m=template_posts&amp;template='.rawurlencode($template);
$this_url = $p_url . '&amp;m=template_posts&amp;template=' . rawurlencode($template);
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
$nb_per_page = 30;
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
$nb_per_page = 30;
# Unselect the template
if (!empty($_POST['initialise']) && $core->auth->check('publish,contentadmin',$core->blog->id))
{
try {
$core->meta->delMeta($template,'template');
http::redirect($p_url.'&del='.$template);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
if (!empty($_POST['initialise']) && dcCore::app()->auth->check('publish,contentadmin', dcCore::app()->blog->id)) {
try {
dcCore::app()->meta->delMeta($template, 'template');
http::redirect($p_url . '&del=' . $template);
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
}
$params = array();
$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
$params = [];
$params['limit'] = [(($page - 1) * $nb_per_page),$nb_per_page];
$params['no_content'] = true;
$params['meta_id'] = $template;
$params['meta_id'] = $template;
$params['meta_type'] = 'template';
$params['post_type'] = '';
# Get posts
try {
$posts = $core->meta->getPostsByMeta($params);
$counter = $core->meta->getPostsByMeta($params,true);
$post_list = new adminPostList($core,$posts,$counter->f(0));
$posts = dcCore::app()->meta->getPostsByMeta($params);
$counter = dcCore::app()->meta->getPostsByMeta($params, true);
$post_list = new adminPostList($posts, $counter->f(0));
} catch (Exception $e) {
$core->error->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
}
# Actions combo box
$combo_action = array();
if ($core->auth->check('publish,contentadmin',$core->blog->id))
{
$combo_action[__('Status')] = array(
__('Publish') => 'publish',
__('Unpublish') => 'unpublish',
__('Schedule') => 'schedule',
__('Mark as pending') => 'pending'
);
$combo_action = [];
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_PUBLISH,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
$combo_action[__('Status')] = [
__('Publish') => 'publish',
__('Unpublish') => 'unpublish',
__('Schedule') => 'schedule',
__('Mark as pending') => 'pending',
];
}
$combo_action[__('Mark')] = array(
__('Mark as selected') => 'selected',
__('Mark as unselected') => 'unselected'
);
$combo_action[__('Change')] = array(__('Change category') => 'category');
if ($core->auth->check('admin',$core->blog->id))
{
$combo_action[__('Change')] = array_merge($combo_action[__('Change')],
array(__('Change author') => 'author'));
$combo_action[__('Mark')] = [
__('Mark as selected') => 'selected',
__('Mark as unselected') => 'unselected',
];
$combo_action[__('Change')] = [__('Change category') => 'category'];
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_ADMIN,
]), dcCore::app()->blog->id)) {
$combo_action[__('Change')] = array_merge(
$combo_action[__('Change')],
[__('Change author') => 'author']
);
}
if ($core->auth->check('delete,contentadmin',$core->blog->id))
{
$combo_action[__('Delete')] = array(__('Delete') => 'delete');
if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_DELETE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
$combo_action[__('Delete')] = [__('Delete') => 'delete'];
}
# --BEHAVIOR-- adminPostsActionsCombo
$core->callBehavior('adminPostsActionsCombo',array(&$combo_action));
dcCore::app()->callBehavior('adminPostsActionsCombo', [&$combo_action]);
?>
<html>
@ -93,42 +101,46 @@ $core->callBehavior('adminPostsActionsCombo',array(&$combo_action));
</head>
<body>
<h2><?php echo html::escapeHTML($core->blog->name); ?> &rsaquo;
<h2><?php echo html::escapeHTML(dcCore::app()->blog->name); ?> &rsaquo;
<span class="page-title"><?php echo __('Unselect specific template'); ?></span></h2>
<?php
echo '<p><a href="'.$p_url.'">'.__('Back to templates list').'</a></p>';
echo '<p><a href="' . $p_url . '">' . __('Back to templates list') . '</a></p>';
if (!$core->error->flag())
{
# Show posts
$post_list->display($page,$nb_per_page,
'<form action="posts_actions.php" method="post" id="form-entries">'.
if (!dcCore::app()->error->flag()) {
# Show posts
$post_list->display(
$page,
$nb_per_page,
'<form action="posts_actions.php" method="post" id="form-entries">' .
'%s'.
'%s' .
'<div class="two-cols">'.
'<p class="col checkboxes-helpers"></p>'.
'<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>' .
'<p class="col right">'.__('Selected entries action:').' '.
form::combo('action',$combo_action).
'<input type="submit" value="'.__('ok').'" /></p>'.
form::hidden('post_type','').
form::hidden('redir',$p_url.'&amp;m=template_posts&amp;tag='.
str_replace('%','%%',rawurlencode($template)).'&amp;page='.$page).
$core->formNonce().
'</div>'.
'</form>');
'<p class="col right">' . __('Selected entries action:') . ' ' .
form::combo('action', $combo_action) .
'<input type="submit" value="' . __('ok') . '" /></p>' .
form::hidden('post_type', '') .
form::hidden('redir', $p_url . '&amp;m=template_posts&amp;tag=' .
str_replace('%', '%%', rawurlencode($template)) . '&amp;page=' . $page) .
dcCore::app()->formNonce() .
'</div>' .
'</form>'
);
# Remove tag
if (!$posts->isEmpty() && $core->auth->check('contentadmin',$core->blog->id)) {
echo
'<form id="template_change" action="'.$this_url.'" method="post">'.
'<p><input type="submit" name="initialise" value="'.__('Unselect the template').'" />'.
$core->formNonce().'</p>'.
'</form>';
}
# Remove tag
if (!$posts->isEmpty() && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
echo
'<form id="template_change" action="' . $this_url . '" method="post">' .
'<p><input type="submit" name="initialise" value="' . __('Unselect the template') . '" />' .
dcCore::app()->formNonce() . '</p>' .
'</form>';
}
}
?>
</body>