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 <?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'), dcCore::app()->auth->setPermissionType(initTemplator::PERMISSION_TEMPLATOR, __('manage 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));
$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)) { if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
$core->addBehavior('adminPostFormSidebar',array('templatorBehaviors','adminPostFormSidebar')); dcAuth::PERMISSION_CONTENT_ADMIN,
$core->addBehavior('adminPageFormSidebar',array('templatorBehaviors','adminPostFormSidebar')); 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')); dcCore::app()->addBehavior('adminAfterPostCreate', ['templatorBehaviors','adminBeforePostUpdate']);
$core->addBehavior('adminBeforePostUpdate',array('templatorBehaviors','adminBeforePostUpdate')); dcCore::app()->addBehavior('adminBeforePostUpdate', ['templatorBehaviors','adminBeforePostUpdate']);
$core->addBehavior('adminAfterPageCreate',array('templatorBehaviors','adminBeforePostUpdate')); dcCore::app()->addBehavior('adminAfterPageCreate', ['templatorBehaviors','adminBeforePostUpdate']);
$core->addBehavior('adminBeforePageUpdate',array('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 class templatorBehaviors
{ {
public static function adminPostFormSidebar($post) public static function adminPostHeaders()
{ {
global $core; return dcPage::jsLoad(dcPage::getPF('templator/js/admin.js'));
}
$tpl = array('&nbsp;' => ''); public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
$tpl_post = array(); {
$selected = ''; $selected = '';
foreach ($core->templator->tpl as $k => $v) { if ($post) {
if (!preg_match('/^category-(.+)$/',$k)) $post_meta = dcCore::app()->meta->getMetadata(['meta_type' => 'template', 'post_id' => $post->post_id]);
{ $selected = $post_meta->isEmpty() ? '' : $post_meta->meta_id;
$tpl_post= array_merge($tpl_post, array($k => $k)); }
}
}
$tpl = array_merge($tpl,$tpl_post); $sidebar_items['options-box']['items']['templator'] =
if ($post) '<div id="templator">' .
{ '<h5>' . __('Template') . '</h5>' .
$params['meta_type'] = 'template'; '<p><label for="post_tpl">' . __('Select template:') . '</label>' .
$params['post_id'] = $post->post_id; form::combo('post_tpl', self::getTemplateCombo(), $selected) . '</p>' .
$post_meta = $core->meta->getMetadata($params); '</div>';
$selected = $post_meta->isEmpty()? '' : $post_meta->meta_id ; }
}
echo public static function adminBeforePostUpdate($cur, $post_id)
'<div class="p" id="meta-edit-tpl"><label for="post_tpl"> {
'.__('Entry template:').'</label>'.form::combo('post_tpl',$tpl,$selected).'</div>'; $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) public static function adminPostsActions(dcPostsActions $pa)
{ {
global $core; $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'])) { if (isset($post['post_tpl'])) {
$tpl = $_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'); dcAdminNotices::addSuccessNotice(__('Entries template updated.'));
if (!empty($_POST['post_tpl'])) $pa->redirect(true);
{ } catch (Exception $e) {
$core->meta->setPostMeta($post_id,'template',$tpl); dcCore::app()->error->add($e->getMessage());
} }
} }
}
public static function adminPostsActionsCombo($args) $pa->beginPage(
{ dcPage::breadcrumb([
$args[0][__('Appearance')] = array(__('Select the template') => 'tpl'); html::escapeHTML(dcCore::app()->blog->name) => '',
} $pa->getCallerTitle() => $pa->getRedirection(true),
__('Entry template') => '',
])
);
public static function adminPostsActions($core,$posts,$action,$redir) echo
{ '<h2 class="page-title">' . __('Select template for the selection') . '</h2>' .
if ($action == 'tpl' && isset($_POST['post_tpl'])) '<form action="' . $pa->getURI() . '" method="post">' .
{ $pa->getCheckboxes() .
try '<p><label class="classic">' . __('Select template:') . '</label> ' .
{ form::combo('post_tpl', self::getTemplateCombo()) . '</p>' .
$tpl = $_POST['post_tpl'];
while ($posts->fetch()) '<p>' .
{ $pa->getHiddenFields() .
$core->meta->delPostMeta($posts->post_id,'template'); dcCore::app()->formNonce() .
if (!empty($_POST['post_tpl'])) form::hidden(['action'], 'tpl') .
{ '<input type="submit" value="' . __('Save') . '" /></p>' .
$core->meta->setPostMeta($posts->post_id,'template',$tpl); '</form>';
}
}
http::redirect($redir); $pa->endPage();
} }
catch (Exception $e)
{
$core->error->add($e->getMessage());
}
}
}
public static function adminPostsActionsContent($core,$action,$hidden_fields) private static function getTemplateCombo()
{ {
if ($action == 'tpl') $tpl = [__('No specific template') => ''];
{
$tpl = array('&nbsp;' => '');
$tpl_post = array();
$selected = '';
foreach ($core->templator->tpl as $k => $v) { foreach (dcCore::app()->templator->tpl as $k => $v) {
if (!preg_match('/^category-(.+)$/',$k) && !preg_match('/^list-(.+)$/',$k)) if (!preg_match('/^category-(.+)$/', $k) && !preg_match('/^list-(.+)$/', $k)) {
{ $tpl[$k] = $k;
$tpl_post= array_merge($tpl_post, array($k => $k)); }
} }
}
$tpl = array_merge($tpl,$tpl_post); return $tpl;
}
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>';
}
}
} }
?>

View File

@ -1,22 +1,23 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# if (!defined('DC_RC_PATH')) {
# This file is part of templator a plugin for Dotclear 2. return null;
# }
# 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; }
$this->registerModule( $this->registerModule(
/* Name */ 'Templator', 'Templator',
/* Description*/ 'Create and select more templates for your posts', 'Create and select more templates for your posts',
/* Author */ 'Osku and contributors', 'Osku and contributors',
/* Version */ '1.3.3', '1.4-dev',
/* Permissions */ 'contentadmin,templator' [
'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 <?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 (!defined('DC_CONTEXT_ADMIN')) {
return null;
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;
} }
$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,'>=')) { # Check Dotclear version
return; 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 false;
return true;
?>

View File

@ -1,48 +1,38 @@
<?php <?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; } if (!defined('DC_RC_PATH')) {
$__autoload['dcTemplator'] = dirname(__FILE__).'/inc/class.templator.php'; return null;
$__autoload['pagerTemplator'] = dirname(__FILE__).'/inc/admin.pager.templator.php'; }
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 class templatorWidgets
{ {
public static function initWidgets($w) public static function initWidgets($w)
{ {
$w->create('templatorWidget',__('Templator Rendering'),array('widgetTemplator','getDataTpl')); $w->create('templatorWidget', __('Templator Rendering'), ['widgetTemplator', 'getDataTpl']);
$tpl = array('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.html' => ''); $tpl = ['&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.html' => ''];
foreach ($GLOBALS['core']->templator->tpl as $k => $v) { foreach (dcCore::app()->templator->tpl as $k => $v) {
if (preg_match('/^widget-(.+)$/',$k)) if (preg_match('/^widget-(.+)$/', $k)) {
{ $tpl = array_merge($tpl, [$k => $k]);
$tpl = array_merge($tpl, array($k => $k)); }
} }
} $w->templatorWidget->setting('template', __('Template:'), '', 'combo', $tpl);
$w->templatorWidget->setting('template',__('Template:'),'','combo',$tpl); }
}
} }
class widgetTemplator class widgetTemplator
{ {
public static function getDataTpl($w) public static function getDataTpl($w)
{ {
if (($GLOBALS['core']->tpl->getFilePath($w->template))) if (dcCore::app()->tpl->getFilePath($w->template)) {
{ echo dcCore::app()->tpl->getData($w->template);
echo $GLOBALS['core']->tpl->getData($w->template); }
} }
}
} }
?>

View File

@ -1,46 +1,32 @@
<?php <?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); if (!defined('DC_RC_PATH')) {
$core->addBehavior('urlHandlerBeforeGetData',array('publicTemplatorBehaviors','BeforeGetData')); return null;
}
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), dcCore::app()->templator->path);
dcCore::app()->addBehavior('urlHandlerBeforeGetData', ['publicTemplatorBehaviors','BeforeGetData']);
class publicTemplatorBehaviors class publicTemplatorBehaviors
{ {
public static function BeforeGetData ($_ctx) public static function BeforeGetData($_)
{ {
global $core; 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')) if (!$post_meta->isEmpty() && dcCore::app()->tpl->getFilePath($post_meta->meta_id)) {
{ dcCore::app()->ctx->current_tpl = $post_meta->meta_id;
$params = array(); }
$params['meta_type'] = 'template'; }
$params['post_id'] = $_ctx->posts->post_id;
$post_meta = $core->meta->getMetadata($params);
if (!$post_meta->isEmpty() && ($core->tpl->getFilePath($post_meta->meta_id))) if (dcCore::app()->ctx->current_tpl == 'category.html' && preg_match('/^[0-9]{1,}/', dcCore::app()->ctx->categories->cat_id, $cat_id)) {
{ $tpl = 'category-' . $cat_id[0] . '.html';
$_ctx->current_tpl = $post_meta->meta_id; if (dcCore::app()->tpl->getFilePath($tpl)) {
} dcCore::app()->ctx->current_tpl = $tpl;
} }
}
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;
}
}
}
} }
?>

View File

@ -1,79 +1,71 @@
<?php <?php
# -- BEGIN LICENSE BLOCK --------------------------------------- if (!defined('DC_CONTEXT_ADMIN')) {
# return null;
# 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; }
?>
<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 = dcCore::app()->meta->getMetadata(['meta_type' => 'template']);
$tags = $core->meta->computeMetaStats($tags); $tags = dcCore::app()->meta->computeMetaStats($tags);
$tags->sort('meta_id_lower','asc'); $tags->sort('meta_id_lower', 'asc');
$last_letter = null; $last_letter = null;
$cols = array('',''); $cols = ['',''];
$col = 0; $col = 0;
while ($tags->fetch())
{
$letter = mb_strtoupper(mb_substr($tags->meta_id,0,1));
if ($last_letter != $letter) { while ($tags->fetch()) {
if ($tags->index() >= round($tags->count()/2)) { $letter = mb_strtoupper(mb_substr($tags->meta_id, 0, 1));
$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 ($last_letter != $letter) {
if (array_key_exists($tags->meta_id,$core->templator->tpl)) { if ($tags->index() >= round($tags->count() / 2)) {
$img_status = sprintf($img,__('available template'),'check-on.png'); $col = 1;
} else { }
$img_status = sprintf($img,__('missing template'),'check-off.png'); $cols[$col] .= '<tr class="tagLetter"><td colspan="2"><span>' . $letter . '</span></td></tr>';
} }
$cols[$col] .= $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
'<tr class="line">'. if (array_key_exists($tags->meta_id, dcCore::app()->templator->tpl)) {
'<td class="maximal"><a href="'.$p_url. $img_status = sprintf($img, __('available template'), 'check-on.png');
'&amp;m=template_posts&amp;template='.rawurlencode($tags->meta_id).'">'.$tags->meta_id.'</a> '.$img_status.'</td>'. } else {
'<td class="nowrap"><strong>'.$tags->count.'</strong> '. $img_status = sprintf($img, __('missing template'), 'check-off.png');
(($tags->count==1) ? __('entry') : __('entries')).'</td>'. }
'</tr>';
$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>'; $table = '<div class="col"><table class="tags">%s</table></div>';
if ($cols[0]) echo
{ '<html><head><title>' . __('Templator') . '</title>' .
echo '<div class="two-cols">'; dcPage::cssLoad(dcPage::getPF('tags/style.css')) .
printf($table,$cols[0]); '</head><body>' .
if ($cols[1]) { dcPage::breadcrumb([
printf($table,$cols[1]); html::escapeHTML(dcCore::app()->blog->name) => '',
} __('Additional templates') => '',
echo '</div>'; ]) .
} dcPage::notices() .
else '<p class="top-add"><a class="button add" id="templator-control" href="' .
{ dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'new']) .
echo '<p>'.__('No specific templates on this blog.').'</p>'; '">' . __('New template') . '</a></p>';
}
?>
</body> if ($cols[0]) {
</html> 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 <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- if (!defined('DC_CONTEXT_ADMIN')) {
# return null;
# 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']);
}
} }
catch (Exception $e)
{ try {
$core->error->add($e->getMessage()); 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> <html>
<head> <head>
<title><?php echo __('Templator'); ?></title> <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"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
<?php echo dcPage::jsVar('dotclear.msg.saving_document',__("Saving document...")); ?> <?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.document_saved', __('Document saved')); ?>
<?php echo dcPage::jsVar('dotclear.msg.error_occurred',__("An error occurred:")); ?> <?php echo dcPage::jsVar('dotclear.msg.error_occurred', __('An error occurred:')); ?>
//]]> //]]>
</script> </script>
<?php echo dcPage::jsLoad('index.php?pf=templator/js/script.js');?> <?php echo dcPage::jsLoad(dcPage::getPF('templator/js/script.js'));?>
</head> </head>
<body> <body>
<?php <?php
echo 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)) if (($file['c'] !== null)) {
{ echo
echo '<div id="file-templator">' .
'<div id="file-templator">'. '<form id="file-form" action="' . $p_url . '&amp;edit=' . $name . '" method="post">' .
'<form id="file-form" action="'.$p_url.'&amp;edit='.$name.'" method="post">'. '<fieldset><legend>' . __('File editor') . '</legend>' .
'<fieldset><legend>'.__('File editor').'</legend>'. '<p>' . sprintf(__('Editing file %s'), '<strong>' . $name) . '</strong></p>' .
'<p>'.sprintf(__('Editing file %s'),'<strong>'.$name).'</strong></p>'. '<p>' . form::textarea('file_content', 72, 30, html::escapeHTML($file['c']), 'maximal', '', !$file['w']) . '</p>';
'<p>'.form::textarea('file_content',72,30,html::escapeHTML($file['c']),'maximal','',!$file['w']).'</p>';
if ($file['w']) if ($file['w']) {
{ echo
echo '<p><input type="submit" name="write" value="' . __('Save') . '" accesskey="s" /> ' .
'<p><input type="submit" name="write" value="'.__('Save').'" accesskey="s" /> '. dcCore::app()->formNonce() .
$core->formNonce(). form::hidden(['file_id'], html::escapeHTML($file['f'])) .
form::hidden(array('file_id'),html::escapeHTML($file['f'])). '</p>';
'</p>'; } else {
echo '<p>' . __('This file is not writable. Please check your files permissions.') . '</p>';
}
echo
} '</fieldset></form></div>';
else
{
echo '<p>'.__('This file is not writable. Please check your files permissions.').'</p>';
}
echo
'</fieldset></form></div>';
} }
?> ?>

View File

@ -1,4 +1,5 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- # -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of templator a plugin for Dotclear 2. # 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 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; } if (!defined('DC_RC_PATH')) {
return;
}
class pagerTemplator class pagerTemplator
{ {
public static function templatorItemLine($f,$i) public static function templatorItemLine($f, $i)
{ {
global $core, $p_url; $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; if (preg_match('/^category-(.+)$/', $f->basename)) {
$count = ''; // That is ugly.
$params = array(); $cat_id = str_replace('category-', '', $f->basename);
$link = 'media_item.php?id='.$f->media_id; $cat_id = str_replace('.html', '', $cat_id);
$link_edit = $p_url.'&amp;edit='.$fname; $cat_parents = dcCore::app()->blog->getCategoryParents($cat_id);
$icon = 'index.php?pf=templator/img/template.png'; $full_name = '';
$class = 'media-item media-col-'.($i%2); while ($cat_parents->fetch()) {
$details = $special = ''; $full_name = $cat_parents->cat_title . ' &rsaquo; ';
$widget_icon = '<span class="widget" title="'.__('Template widget').'">&diams;</span>'; };
$copy_url = '&amp;copy='; $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)) { try {
// That is ugly. $counter = dcCore::app()->blog->getPosts($params, true);
$cat_id = str_replace('category-', '', $f->basename); } catch (Exception $e) {
$cat_id = str_replace('.html', '', $cat_id); dcCore::app()->error->add($e->getMessage());
$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());
}
if ($counter->f(0) == 0) { if ($counter->f(0) == 0) {
$count = __('No entry'); $count = __('No entry');
} elseif ($counter->f(0) == 1) { } elseif ($counter->f(0) == 1) {
$count = '<strong>'.$counter->f(0).'</strong> <a href="posts.php?cat_id='.$cat_id.'">'.__('entry').'</a>'; $count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entry') . '</a>';
} else { } else {
$count = '<strong>'.$counter->f(0).'</strong> <a href="posts.php?cat_id='.$cat_id.'">'.__('entries').'</a>'; $count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entries') . '</a>';
} }
} } elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
elseif (preg_match('/^widget-(.+)$/',$f->basename)) { $count = '&nbsp;';
$count = '&nbsp;'; $icon = dcPage::getPF('templator/img/template-widget.png');
$icon = 'index.php?pf=templator/img/template-widget.png'; $special = $widget_icon;
$special = $widget_icon; } else {
} $params['meta_id'] = $f->basename;
else { $params['meta_type'] = 'template';
$params['meta_id'] = $f->basename; $params['post_type'] = '';
$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>';
}
}
$res = try {
'<div class="'.$class.'"><a class="media-icon media-link" href="'.$link_edit.'">'. $counter = dcCore::app()->meta->getPostsByMeta($params, true);
'<img src="'.$icon.'" alt="" /></a>'. } catch (Exception $e) {
'<ul>'. dcCore::app()->error->add($e->getMessage());
'<li><a class="media-link" href="'.$link_edit.'">'.$fname.'</a> '.$special.'</li>'; }
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)) { $res = '<div class="' . $class . '"><a class="media-icon media-link" href="' . $link_edit . '">' .
$details = ' - <a href="'.$link.'">'.__('details').'</a>'; '<img src="' . $icon . '" alt="" /></a>' .
} '<ul>' .
'<li><a class="media-link" href="' . $link_edit . '">' . $fname . '</a> ' . $special . '</li>';
if (!$f->d) { if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
$res .= dcAuth::PERMISSION_CONTENT_ADMIN,
'<li>'.$count.'</li>'. initTemplator::PERMISSION_TEMPLATOR,
'<li>'. ]), dcCore::app()->blog->id)) {
$f->media_dtstr.' - '. $details = ' - <a href="' . $link . '">' . __('details') . '</a>';
files::size($f->size). }
$details.
'</li>';
}
$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" '. $res .= '<li class="media-action">&nbsp;';
'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 .= '<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) { if ($f->del) {
$res .= '<a class="media-remove" '. $res .= '<a class="media-remove" ' .
'href="'.$p_url.'&amp;remove='.rawurlencode($f->basename).'">'. 'href="' . $p_url . '&amp;remove=' . rawurlencode($f->basename) . '">' .
'<img src="index.php?pf=templator/img/delete.png" alt="'.__('delete').'" title="'.__('delete the template').'" /></a>'; '<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 <?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# if (!defined('DC_RC_PATH')) {
# This file is part of templator a plugin for Dotclear 2. return null;
# }
# 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; }
class dcTemplator class dcTemplator
{ {
protected $post_default_name = 'post.html'; protected $tpls_default_name = 'dotty';
protected $page_default_name = 'page.html'; protected $post_default_name = 'post.html';
protected $category_default_name = 'category.html'; protected $page_default_name = 'page.html';
protected $category_default_name = 'category.html';
public $template_dir_name = 'other-templates';
public $path; public $template_dir_name = 'other-templates';
public $path;
public $tpl = array();
public $theme_tpl = array(); public $tpl = [];
public $theme_tpl = [];
/**
* /**
*/ *
public function __construct($core) */
{ public function __construct()
$this->core =& $core; {
$this->path = dcCore::app()->blog->public_path . '/' . $this->template_dir_name;
$this->path = $this->core->blog->public_path.'/'.$this->template_dir_name;
// Initial templates
// Initial templates $this->post_tpl = DC_ROOT . '/inc/public/default-templates/' . $this->tpls_default_name . '/' . $this->post_default_name;
$this->post_tpl = DC_ROOT.'/inc/public/default-templates/'.$this->post_default_name; $this->category_tpl = DC_ROOT . '/inc/public/default-templates/' . $this->tpls_default_name . '/' . $this->category_default_name;
$this->category_tpl = DC_ROOT.'/inc/public/default-templates/'.$this->category_default_name;
if (dcCore::app()->plugins->moduleExists('pages')) {
if ($this->core->plugins->moduleExists('pages')) { $plugin_page = dcCore::app()->plugins->getModules('pages');
$plugin_page = $this->core->plugins->getModules('pages'); $this->page_tpl = path::real($plugin_page['root'] . '/default-templates/' . $this->tpls_default_name . '/' . $this->page_default_name);
$this->page_tpl = path::real($plugin_page['root'].'/default-templates/'.$this->page_default_name); }
}
$this->user_theme = dcCore::app()->blog->themes_path . '/' . dcCore::app()->blog->settings->system->theme;
$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_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_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->user_page_tpl = path::real($this->user_theme.'/tpl/'.$this->page_default_name);
$this->findTemplates();
$this->findTemplates(); }
}
/**
/** *
* */
*/ public function canUseRessources($create = false)
public function canUseRessources($create=false) {
{ if (!is_dir($this->path)) {
if (!is_dir($this->path)) { if ($create) {
if ($create) { files::makeDir($this->path);
files::makeDir($this->path); }
}
return true; return true;
} }
if (!is_writable($this->path)) { if (!is_writable($this->path)) {
return false; return false;
} }
if (!is_file($this->path.'/.htaccess')) { if (!is_file($this->path . '/.htaccess')) {
try { try {
file_put_contents($this->path.'/.htaccess',"Deny from all\n"); file_put_contents($this->path . '/.htaccess', "Deny from all\n");
} } catch (Exception $e) {
catch (Exception $e) {return false;} return false;
} }
return true; }
}
return true;
/** }
*
*/ /**
public function getSourceContent($f) *
{ */
$source = $this->tpl; public function getSourceContent($f)
{
if (!isset($source[$f])) { $source = $this->tpl;
throw new Exception(__('File does not exist.'));
} 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)); $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, return [
'f' => $f 'c' => file_get_contents($source[$f]),
); 'w' => $this->getDestinationFile($f) !== false,
} 'f' => $f,
];
/** }
*
*/ /**
public function filesList($item='%1$s') *
{ */
$files = $this->tpl; public function filesList($item = '%1$s')
{
if (empty($files)) { $files = $this->tpl;
return '<p>'.__('No file').'</p>';
} if (empty($files)) {
return '<p>' . __('No file') . '</p>';
$list = ''; }
foreach ($files as $k => $v)
{ $list = '';
$li = sprintf('<li>%s</li>',$item); foreach ($files as $k => $v) {
$li = sprintf('<li>%s</li>', $item);
$list .= sprintf($li,$k,html::escapeHTML($k));
} $list .= sprintf($li, $k, html::escapeHTML($k));
}
return sprintf('<ul>%s</ul>',$list);
} return sprintf('<ul>%s</ul>', $list);
}
/**
* /**
*/ *
public function initializeTpl($name,$type) */
{ public function initializeTpl($name, $type)
if ($type == 'category') {
{ if ($type == 'category') {
if ($this->user_category_tpl) { if ($this->user_category_tpl) {
$base = $this->user_category_tpl; $base = $this->user_category_tpl;
} else { } else {
$base = $this->category_tpl; $base = $this->category_tpl;
} }
} } elseif ($type == 'page') {
elseif ($type == 'page') if ($this->user_page_tpl) {
{ $base = $this->user_page_tpl;
if ($this->user_page_tpl) { } else {
$base = $this->user_page_tpl; $base = $this->page_tpl;
} else { }
$base = $this->page_tpl; } else {
} if ($this->user_post_tpl) {
} $base = $this->user_post_tpl;
else { } else {
if ($this->user_post_tpl) { $base = $this->post_tpl;
$base = $this->user_post_tpl; }
} else { }
$base = $this->post_tpl;
} $source = [
} 'c' => file_get_contents($base),
'w' => $this->getDestinationFile($name) !== false,
$source = array( 'f' => $f, ];
'c' => file_get_contents($base),
'w' => $this->getDestinationFile($name) !== false, if (!$source['w']) {
'f' => $f); throw new Exception(sprintf(__('File %s is not readable'), $source));
}
if (!$source['w'])
{ if ($type == 'empty') {
throw new Exception(sprintf(__('File %s is not readable'),$source)); $source['c'] = '';
} }
if ($type == 'empty') try {
{ $dest = $this->getDestinationFile($name);
$source['c'] = '';
} if ($dest == false) {
throw new Exception();
try }
{
$dest = $this->getDestinationFile($name); $content = $source['c'];
if ($dest == false) { if (!is_dir(dirname($dest))) {
throw new Exception(); files::makeDir(dirname($dest));
} }
$content = $source['c']; $fp = @fopen($dest, 'wb');
if (!$fp) {
if (!is_dir(dirname($dest))) { throw new Exception('tocatch');
files::makeDir(dirname($dest)); }
}
$content = preg_replace('/(\r?\n)/m', "\n", $content);
$fp = @fopen($dest,'wb'); $content = preg_replace('/\r/m', "\n", $content);
if (!$fp) {
throw new Exception('tocatch'); fwrite($fp, $content);
} fclose($fp);
} catch (Exception $e) {
$content = preg_replace('/(\r?\n)/m',"\n",$content); throw $e;
$content = preg_replace('/\r/m',"\n",$content); }
}
fwrite($fp,$content);
fclose($fp); /**
} *
catch (Exception $e) */
{ public function copypasteTpl($name, $source)
throw $e; {
} if ($name == $source) {
throw new Exception(__('Why copy file content in the same file?'));
} }
/** $file = $this->getSourceContent($source);
*
*/ $source = [
public function copypasteTpl($name,$source) 'c' => $file['c'],
{ 'w' => $this->getDestinationFile($name) !== false,
if ($name == $source) {throw new Exception(__('Why copy file content in the same file?'));} 'f' => $f, ];
$file = $this->getSourceContent($source); if (!$source['w']) {
throw new Exception(sprintf(__('File %s is not readable'), $source));
$source = array( }
'c' => $file['c'],
'w' => $this->getDestinationFile($name) !== false, if ($type == 'empty') {
'f' => $f); $source['c'] = '';
}
if (!$source['w'])
{ try {
throw new Exception(sprintf(__('File %s is not readable'),$source)); $dest = $this->getDestinationFile($name);
}
if ($dest == false) {
if ($type == 'empty') throw new Exception();
{ }
$source['c'] = '';
} $content = $source['c'];
try if (!is_dir(dirname($dest))) {
{ files::makeDir(dirname($dest));
$dest = $this->getDestinationFile($name); }
if ($dest == false) { $fp = @fopen($dest, 'wb');
throw new Exception(); if (!$fp) {
} throw new Exception('tocatch');
}
$content = $source['c'];
$content = preg_replace('/(\r?\n)/m', "\n", $content);
if (!is_dir(dirname($dest))) { $content = preg_replace('/\r/m', "\n", $content);
files::makeDir(dirname($dest));
} fwrite($fp, $content);
fclose($fp);
$fp = @fopen($dest,'wb'); } catch (Exception $e) {
if (!$fp) { throw $e;
throw new Exception('tocatch'); }
} }
$content = preg_replace('/(\r?\n)/m',"\n",$content); /**
$content = preg_replace('/\r/m',"\n",$content); *
*/
fwrite($fp,$content); public function writeTpl($name, $content)
fclose($fp); {
} try {
catch (Exception $e) $dest = $this->getDestinationFile($name);
{
throw $e; if ($dest == false) {
} throw new Exception();
} }
/** if (!is_dir(dirname($dest))) {
* files::makeDir(dirname($dest));
*/ }
public function writeTpl($name,$content)
{ $fp = @fopen($dest, 'wb');
try if (!$fp) {
{ //throw new Exception('tocatch');
$dest = $this->getDestinationFile($name); }
if ($dest == false) { $content = preg_replace('/(\r?\n)/m', "\n", $content);
throw new Exception(); $content = preg_replace('/\r/m', "\n", $content);
}
fwrite($fp, $content);
if (!is_dir(dirname($dest))) { fclose($fp);
files::makeDir(dirname($dest)); } catch (Exception $e) {
} throw $e;
}
$fp = @fopen($dest,'wb'); }
if (!$fp) {
//throw new Exception('tocatch'); /**
} *
*/
$content = preg_replace('/(\r?\n)/m',"\n",$content); public function copyTpl($name)
$content = preg_replace('/\r/m',"\n",$content); {
try {
fwrite($fp,$content); $file = $this->getSourceContent($name);
fclose($fp); $dest = $this->getDestinationFile($name, true);
}
catch (Exception $e) if ($dest == false) {
{ throw new Exception();
throw $e; }
}
} if (!is_dir(dirname($dest))) {
files::makeDir(dirname($dest));
/** }
*
*/ $fp = @fopen($dest, 'wb');
public function copyTpl($name) if (!$fp) {
{ throw new Exception('tocatch');
try }
{
$file = $this->getSourceContent($name); $content = preg_replace('/(\r?\n)/m', "\n", $file['c']);
$dest = $this->getDestinationFile($name,true); $content = preg_replace('/\r/m', "\n", $file['c']);
if ($dest == false) { fwrite($fp, $file['c']);
throw new Exception(); fclose($fp);
} } catch (Exception $e) {
throw $e;
if (!is_dir(dirname($dest))) { }
files::makeDir(dirname($dest)); }
}
protected function getDestinationFile($f, $totheme = false)
$fp = @fopen($dest,'wb'); {
if (!$fp) { $dest = $this->path . '/' . $f;
throw new Exception('tocatch'); if ($totheme) {
} $dest = $this->user_theme . '/tpl/' . $f;
}
$content = preg_replace('/(\r?\n)/m',"\n",$file['c']);
$content = preg_replace('/\r/m',"\n",$file['c']); if (file_exists($dest) && is_writable($dest)) {
return $dest;
fwrite($fp,$file['c']); }
fclose($fp);
} if (is_writable(dirname($dest))) {
catch (Exception $e) return $dest;
{ }
throw $e;
} return false;
} }
protected function getDestinationFile($f,$totheme=false) protected function findTemplates()
{ {
$dest = $this->path.'/'.$f; $this->tpl = $this->getFilesInDir($this->path);
if ($totheme) { //$this->theme_tpl = $this->getFilesInDir(path::real($this->user_theme).'/tpl');
$dest = $this->user_theme.'/tpl/'.$f;
} uksort($this->tpl, [$this,'sortFilesHelper']);
//uksort($this->theme_tpl,array($this,'sortFilesHelper'));
if (file_exists($dest) && is_writable($dest)) { }
return $dest;
} protected function getFilesInDir($dir)
{
if (is_writable(dirname($dest))) { $dir = path::real($dir);
return $dest; if (!$dir || !is_dir($dir) || !is_readable($dir)) {
} return [];
}
return false;
} $d = dir($dir);
$res = [];
protected function findTemplates() while (($f = $d->read()) !== false) {
{ if (is_file($dir . '/' . $f) && !preg_match('/^\./', $f)) {
$this->tpl = $this->getFilesInDir($this->path); $res[$f] = $dir . '/' . $f;
//$this->theme_tpl = $this->getFilesInDir(path::real($this->user_theme).'/tpl'); }
}
uksort($this->tpl,array($this,'sortFilesHelper'));
//uksort($this->theme_tpl,array($this,'sortFilesHelper')); return $res;
} }
protected function getFilesInDir($dir) protected function sortFilesHelper($a, $b)
{ {
$dir = path::real($dir); if ($a == $b) {
if (!$dir || !is_dir($dir) || !is_readable($dir)) { return 0;
return array(); }
}
$ext_a = files::getExtension($a);
$d = dir($dir); $ext_b = files::getExtension($b);
$res = array();
while (($f = $d->read()) !== false) return strcmp($ext_a . '.' . $a, $ext_b . '.' . $b);
{ }
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 <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- if (!defined('DC_CONTEXT_ADMIN')) {
# return null;
# This file is part of templator a plugin for Dotclear 2. }
#
# Copyright (c) 2010 Osku and contributors dcPage::check(dcCore::app()->auth->makePermissions([
# Licensed under the GPL version 2.0 license. dcAuth::PERMISSION_CONTENT_ADMIN,
# A copy of this license is available in LICENSE file or at initTemplator::PERMISSION_TEMPLATOR,
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html ]));
#
# -- END LICENSE BLOCK ------------------------------------ $p_url = dcCore::app()->admin->getPageURL();
if (!defined('DC_CONTEXT_ADMIN')) { return; }
dcPage::check('templator,contentadmin');
if ((!empty($_REQUEST['m'])) && ($_REQUEST['m'] = 'template_posts')) { if ((!empty($_REQUEST['m'])) && ($_REQUEST['m'] = 'template_posts')) {
require dirname(__FILE__).'/'.$_REQUEST['m'].'.php'; require dirname(__FILE__) . '/' . $_REQUEST['m'] . '.php';
return;
return;
} }
if (!empty($_REQUEST['edit'])) { if (!empty($_REQUEST['edit'])) {
require dirname(__FILE__).'/edit.php'; require dirname(__FILE__) . '/edit.php';
return;
return;
} }
if (!empty($_REQUEST['database']) && $_REQUEST['database'] = 'on') { if (!empty($_REQUEST['database']) && $_REQUEST['database'] = 'on') {
require dirname(__FILE__).'/advanced.php'; require dirname(__FILE__) . '/advanced.php';
return;
return;
} }
$file_default = $file = array('c'=>null, 'w'=>false, 'type'=>null, 'f'=>null, 'default_file'=>false); $file_default = $file = ['c' => null, 'w' => false, 'type' => null, 'f' => null, 'default_file' => false];
$page = !empty($_GET['page']) ? $_GET['page'] : 1; $page = !empty($_GET['page']) ? $_GET['page'] : 1;
$nb_per_page = 20; $nb_per_page = 20;
$msg = ''; $msg = '';
$remove_confirm = false; $remove_confirm = false;
// Load infos. // Load infos.
$ressources = $core->templator->canUseRessources(true); $ressources = dcCore::app()->templator->canUseRessources(true);
$files= $core->templator->tpl; $files = dcCore::app()->templator->tpl;
// Media // Media
$media = new dcMedia($core); $media = new dcMedia();
$media->chdir($core->templator->template_dir_name); $media->chdir(dcCore::app()->templator->template_dir_name);
// For users with only templator permission, we use sudo. // For users with only templator permission, we use sudo.
$core->auth->sudo(array($media,'getDir')); dcCore::app()->auth->sudo([$media,'getDir']);
$dir =& $media->dir; $dir = & $media->dir;
//if files did not appear in this list, check blog->settings->media_exclusion
$items = array_values($dir['files']); $items = array_values($dir['files']);
// Categories // Categories
try { try {
$categories = $core->blog->getCategories(array('post_type'=>'post')); $categories = dcCore::app()->blog->getCategories(['post_type' => 'post']);
$categories_combo = array(); $categories_combo = [];
$l = $categories->level; $l = $categories->level;
$full_name = array($categories->cat_title); $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) { $categories_combo[implode(' &rsaquo; ', $full_name)] = $categories->cat_id;
$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) { }
$l = $categories->level;
}
} catch (Exception $e) {
}
$hasCategories = ($categories->isEmpty()) ? false : true; $hasCategories = ($categories->isEmpty()) ? false : true;
$combo_source = array( $combo_source = [
'post.html' => 'post' 'post.html' => 'post',
); ];
if ($core->auth->check('pages',$core->blog->id) && $core->plugins->moduleExists('pages')) { 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'; $combo_source['page.html'] = 'page';
} }
if (!$categories->isEmpty()) { if (!$categories->isEmpty()) {
$combo_source['category.html'] = 'category'; $combo_source['category.html'] = 'category';
} }
$combo_source[' &mdash; '] = 'empty'; $combo_source[' &mdash; '] = 'empty';
$add_template = $copy_confirm = $copycat_confirm = false; $add_template = $copy_confirm = $copycat_confirm = false;
if (!$ressources) if (!$ressources) {
{ dcCore::app()->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
$core->error->add(__('The plugin is unusable with your configuration. You have to change file permissions.'));
} }
if (!empty($_POST['filesource'])) if (!empty($_POST['filesource'])) {
{ try {
try $source = $_POST['filesource'];
{ if (empty($_POST['filename']) && $source != 'category') {
$source = $_POST['filesource']; throw new Exception(__('Filename is empty.'));
if (empty($_POST['filename']) && $source != 'category') { }
throw new Exception(__('Filename is empty.')); $name = files::tidyFileName($_POST['filename']) . '.html';
} if ($source == 'category') {
$name = files::tidyFileName($_POST['filename']).'.html'; $name = 'category-' . $_POST['filecat'] . '.html';
if ($source == 'category') }
{ dcCore::app()->templator->initializeTpl($name, $source);
$name = 'category-'.$_POST['filecat'].'.html';
} if (!dcCore::app()->error->flag()) {
$core->templator->initializeTpl($name,$source); dcAdminNotices::addSuccessNotice(__('The new template has been successfully created.'));
} dcCore::app()->adminurl->redirect('admin.plugin.templator');
catch (Exception $e) }
{ } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
if (!$core->error->flag()) {
http::redirect($p_url.'&msg=new');
}
} }
if (!empty($_POST['rmyes']) && !empty($_POST['remove']) ) { if (!empty($_POST['rmyes']) && !empty($_POST['remove'])) {
try try {
{ $file = rawurldecode($_POST['remove']);
$file = rawurldecode($_POST['remove']); $media->removeItem($file);
$media->removeItem($file); dcCore::app()->meta->delMeta($file, 'template');
$core->meta->delMeta($file,'template');
} if (!dcCore::app()->error->flag()) {
catch (Exception $e) dcAdminNotices::addSuccessNotice(__('The template has been successfully removed.'));
{ dcCore::app()->adminurl->redirect('admin.plugin.templator');
$core->error->add($e->getMessage()); }
} } catch (Exception $e) {
if (!$core->error->flag()) { dcCore::app()->error->add($e->getMessage());
http::redirect($p_url.'&msg=del'); }
}
} }
if (!empty($_POST['cpyes']) && !empty($_POST['copy']) && !empty($_POST['newfile'])) { if (!empty($_POST['cpyes']) && !empty($_POST['copy']) && !empty($_POST['newfile'])) {
try try {
{ $file = rawurldecode($_POST['copy']);
$file = rawurldecode($_POST['copy']); $newfile = rawurldecode($_POST['newfile']) . '.html';
$newfile = rawurldecode($_POST['newfile']).'.html'; dcCore::app()->templator->copypasteTpl($newfile, $file);
$core->templator->copypasteTpl($newfile,$file);
} if (!dcCore::app()->error->flag()) {
catch (Exception $e) dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.'));
{ dcCore::app()->adminurl->redirect('admin.plugin.templator');
$core->error->add($e->getMessage()); }
} } catch (Exception $e) {
if (!$core->error->flag()) { dcCore::app()->error->add($e->getMessage());
http::redirect($p_url.'&msg=cpy'); }
}
} }
if (!empty($_POST['cpyes']) && !empty($_POST['copycat']) && !empty($_POST['copcat'])) { if (!empty($_POST['cpyes']) && !empty($_POST['copycat']) && !empty($_POST['copcat'])) {
try try {
{ $file = rawurldecode($_POST['copycat']);
$file = rawurldecode($_POST['copycat']); $newfile = 'category-' . rawurldecode($_POST['copcat']) . '.html';
$newfile = 'category-'.rawurldecode($_POST['copcat']).'.html'; dcCore::app()->templator->copypasteTpl($newfile, $file);
$core->templator->copypasteTpl($newfile,$file);
} if (!dcCore::app()->error->flag()) {
catch (Exception $e) dcAdminNotices::addSuccessNotice(__('The template has been successfully copied.'));
{ dcCore::app()->adminurl->redirect('admin.plugin.templator');
$core->error->add($e->getMessage()); }
} } catch (Exception $e) {
if (!$core->error->flag()) { dcCore::app()->error->add($e->getMessage());
http::redirect($p_url.'&msg=cpy'); }
}
} }
if (!empty($_GET['remove'])) if (!empty($_GET['remove'])) {
{ $remove_confirm = true;
$remove_confirm = true;
} }
if (!empty($_GET['copy'])) if (!empty($_GET['copy'])) {
{ $copy_confirm = true;
$copy_confirm = true;
} }
if (!empty($_GET['copycat'])) if (!empty($_GET['copycat'])) {
{ $copycat_confirm = true;
$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 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) { if ($remove_confirm) {
echo echo
'<form action="'.$p_url.'" method="post">'. '<form action="' . $p_url . '" method="post">' .
'<p>'.sprintf(__('Are you sure you want to remove the template "%s"?'), '<p>' . sprintf(
html::escapeHTML($_GET['remove'])).'</p>'. __('Are you sure you want to remove the template "%s"?'),
'<p><input type="submit" class="delete" value="'.__('Cancel').'" /> '. html::escapeHTML($_GET['remove'])
' &nbsp; <input type="submit" name="rmyes" value="'.__('Yes').'" />'. ) . '</p>' .
$core->formNonce(). '<p><input type="submit" class="delete" value="' . __('Cancel') . '" /> ' .
form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'. ' &nbsp; <input type="submit" name="rmyes" value="' . __('Yes') . '" />' .
'</form>'; dcCore::app()->formNonce() .
form::hidden('remove', html::escapeHTML($_GET['remove'])) . '</p>' .
'</form>';
} }
if ($copy_confirm) { if ($copy_confirm) {
echo echo
'<form action="'.$p_url.'" method="post">'. '<form action="' . $p_url . '" method="post">' .
'<p>'.sprintf(__('To copy the template <strong>%s</strong>, you need to fill a new filename.'), '<p>' . sprintf(
html::escapeHTML($_GET['copy'])).'</p>'. __('To copy the template <strong>%s</strong>, you need to fill a new filename.'),
'<p><label for="filename" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('New filename:').' '. html::escapeHTML($_GET['copy'])
form::field('newfile',25,255).'</label><code>'.html::escapeHTML('.html').'</code>&nbsp; '. ) . '</p>' .
'<input type="submit" name="cpyes" value="'.__('Copy').'" /> &nbsp;<input class="delete" type="submit" value="'.__('Cancel').'" />'. '<p><label for="filename" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('New filename:') . ' ' .
$core->formNonce(). form::field('newfile', 25, 255) . '</label><code>' . html::escapeHTML('.html') . '</code>&nbsp; ' .
form::hidden('copy',html::escapeHTML($_GET['copy'])).'</p>'. '<input type="submit" name="cpyes" value="' . __('Copy') . '" /> &nbsp;<input class="delete" type="submit" value="' . __('Cancel') . '" />' .
'</form>'; dcCore::app()->formNonce() .
form::hidden('copy', html::escapeHTML($_GET['copy'])) . '</p>' .
'</form>';
} }
if ($copycat_confirm) { if ($copycat_confirm) {
$category_id = str_replace('category-', '', $_GET['copycat']); $category_id = str_replace('category-', '', $_GET['copycat']);
$category_id = str_replace('.html', '', $category_id); $category_id = str_replace('.html', '', $category_id);
$cat_parents = $core->blog->getCategoryParents($category_id); $cat_parents = dcCore::app()->blog->getCategoryParents($category_id);
$full_name = ''; $full_name = '';
while ($cat_parents->fetch()) {$full_name = $cat_parents->cat_title.' &rsaquo; ';}; while ($cat_parents->fetch()) {
$name = $full_name.$core->blog->getCategory($category_id)->cat_title; $full_name = $cat_parents->cat_title . ' &rsaquo; ';
echo };
'<form action="'.$p_url.'" method="post">'. $name = $full_name . dcCore::app()->blog->getCategory($category_id)->cat_title;
'<p>'.sprintf(__('To copy the template <strong>%s</strong> (%s), you need to choose a category.'), echo
html::escapeHTML($_GET['copycat']),$name).'</p>'. '<form action="' . $p_url . '" method="post">' .
'<p class="field"><label for="copcat" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Target category:'). '<p>' . sprintf(
form::combo('copcat',$categories_combo,'').'</label></p>'. __('To copy the template <strong>%s</strong> (%s), you need to choose a category.'),
'<input type="submit" name="cpyes" value="'.__('Copy').'" /> &nbsp;<input class="delete" type="submit" value="'.__('Cancel').'" />'. html::escapeHTML($_GET['copycat']),
$core->formNonce(). $name
form::hidden('copycat',html::escapeHTML($_GET['copycat'])). ) . '</p>' .
'</form>'; '<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) { if (!$add_template) {
echo '<p class="top-add"><a class="button add" id="templator-control" href="#">'. echo '<p class="top-add"><a class="button add" id="templator-control" href="#">' .
__('New template').'</a></p>'; __('New template') . '</a></p>';
} }
echo echo
'<form action="'.$p_url.'" method="post" id="add-template">'. '<form action="' . $p_url . '" method="post" id="add-template">' .
'<h3>'.__('New template').'</h3>'. '<h3>' . __('New template') . '</h3>' .
'<p class="field"><label for="filesource" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Template source:').' '. '<p class="field"><label for="filesource" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Template source:') . ' ' .
form::combo('filesource',$combo_source).'</label></p>'. form::combo('filesource', $combo_source) . '</label></p>' .
'<p class="field two-cols"><label for="filename" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Filename:').' '. '<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 /> 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> <p class="form-note warn">' . __('Extension <strong><code>.html</code></strong> is automatically added to filename') . '</p>
'; ';
if ($hasCategories) { if ($hasCategories) {
echo '<p class="field"><label for="filecat" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Category:'). echo '<p class="field"><label for="filecat" class="required"><abbr title="' . __('Required field') . '">*</abbr>' . __('Category:') .
form::combo('filecat',$categories_combo,'').'</label></p>'; form::combo('filecat', $categories_combo, '') . '</label></p>';
} }
echo echo
'<p>'.form::hidden(array('p'),'templator'). '<p>' . form::hidden(['p'], 'templator') .
$core->formNonce(). dcCore::app()->formNonce() .
'<input type="submit" name="add_message" value="'.__('Create').'" /></p>'. '<input type="submit" name="add_message" value="' . __('Create') . '" /></p>' .
'</form>'; '</form>';
if (count($items) == 0) if (count($items) == 0) {
{ echo '<p><strong>' . __('No template.') . '</strong></p>';
echo '<p><strong>'.__('No template.').'</strong></p>'; } else {
} $pager = new pager($page, count($items), $nb_per_page, 10);
else $pager->html_prev = __('&#171;prev.');
{ $pager->html_next = __('next&#187;');
$pager = new pager($page,count($items),$nb_per_page,10);
$pager->html_prev = __('&#171;prev.');
$pager->html_next = __('next&#187;');
echo echo
'<form action="media.php" method="get">'. '<form action="media.php" method="get">' .
'</form>'. '</form>' .
'<div class="media-list">'. '<div class="media-list">' .
'<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++, $j++) for ($i = $pager->index_start, $j = 0; $i <= $pager->index_end; $i++, $j++) {
{ echo pagerTemplator::templatorItemLine($items[$i], $j);
echo pagerTemplator::templatorItemLine($items[$i],$j); }
}
echo echo
'<p class="clear">'.__('Page(s)').' : '.$pager->getLinks().'</p>'. '<p class="clear">' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>' .
'</div>'; '</div>';
} }
echo echo
'<p class="clear"> '<p class="clear">
<a class="button" <a class="button"
href="'.$p_url.'&amp;database=on" href="' . $p_url . '&amp;database=on"
title="'.__('Display templates used for entries in base').'" title="' . __('Display templates used for entries in base') . '"
>'. >' .
__('Display templates used for entries in base').' __('Display templates used for entries in base') . '
</a> </a>
</p>'; </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 <?php
// Language: Français // Language: Français
// Module: templator - 1.3.3 // Module: templator - 1.3.3
// Date: 2012-10-02 12:59:08 // 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 #template_posts.php:128
$GLOBALS['__l10n']['Unselect the template'] = 'Désélectionner le template'; $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 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; } if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
$template = (!empty($_REQUEST['template']) || $_REQUEST['template'] == '0') ? $_REQUEST['template'] : ''; $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; $page = !empty($_GET['page']) ? $_GET['page'] : 1;
$nb_per_page = 30; $nb_per_page = 30;
# Unselect the template # Unselect the template
if (!empty($_POST['initialise']) && $core->auth->check('publish,contentadmin',$core->blog->id)) if (!empty($_POST['initialise']) && dcCore::app()->auth->check('publish,contentadmin', dcCore::app()->blog->id)) {
{ try {
try { dcCore::app()->meta->delMeta($template, 'template');
$core->meta->delMeta($template,'template'); http::redirect($p_url . '&del=' . $template);
http::redirect($p_url.'&del='.$template); } catch (Exception $e) {
} catch (Exception $e) { dcCore::app()->error->add($e->getMessage());
$core->error->add($e->getMessage()); }
}
} }
$params = array(); $params = [];
$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); $params['limit'] = [(($page - 1) * $nb_per_page),$nb_per_page];
$params['no_content'] = true; $params['no_content'] = true;
$params['meta_id'] = $template; $params['meta_id'] = $template;
$params['meta_type'] = 'template'; $params['meta_type'] = 'template';
$params['post_type'] = ''; $params['post_type'] = '';
# Get posts # Get posts
try { try {
$posts = $core->meta->getPostsByMeta($params); $posts = dcCore::app()->meta->getPostsByMeta($params);
$counter = $core->meta->getPostsByMeta($params,true); $counter = dcCore::app()->meta->getPostsByMeta($params, true);
$post_list = new adminPostList($core,$posts,$counter->f(0)); $post_list = new adminPostList($posts, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
# Actions combo box # Actions combo box
$combo_action = array(); $combo_action = [];
if ($core->auth->check('publish,contentadmin',$core->blog->id)) if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
{ dcAuth::PERMISSION_PUBLISH,
$combo_action[__('Status')] = array( dcAuth::PERMISSION_CONTENT_ADMIN,
__('Publish') => 'publish', ]), dcCore::app()->blog->id)) {
__('Unpublish') => 'unpublish', $combo_action[__('Status')] = [
__('Schedule') => 'schedule', __('Publish') => 'publish',
__('Mark as pending') => 'pending' __('Unpublish') => 'unpublish',
); __('Schedule') => 'schedule',
__('Mark as pending') => 'pending',
];
} }
$combo_action[__('Mark')] = array( $combo_action[__('Mark')] = [
__('Mark as selected') => 'selected', __('Mark as selected') => 'selected',
__('Mark as unselected') => 'unselected' __('Mark as unselected') => 'unselected',
); ];
$combo_action[__('Change')] = array(__('Change category') => 'category'); $combo_action[__('Change')] = [__('Change category') => 'category'];
if ($core->auth->check('admin',$core->blog->id)) if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
{ dcAuth::PERMISSION_ADMIN,
$combo_action[__('Change')] = array_merge($combo_action[__('Change')], ]), dcCore::app()->blog->id)) {
array(__('Change author') => 'author')); $combo_action[__('Change')] = array_merge(
$combo_action[__('Change')],
[__('Change author') => 'author']
);
} }
if ($core->auth->check('delete,contentadmin',$core->blog->id)) if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
{ dcAuth::PERMISSION_DELETE,
$combo_action[__('Delete')] = array(__('Delete') => 'delete'); dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
$combo_action[__('Delete')] = [__('Delete') => 'delete'];
} }
# --BEHAVIOR-- adminPostsActionsCombo # --BEHAVIOR-- adminPostsActionsCombo
$core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); dcCore::app()->callBehavior('adminPostsActionsCombo', [&$combo_action]);
?> ?>
<html> <html>
@ -93,42 +101,46 @@ $core->callBehavior('adminPostsActionsCombo',array(&$combo_action));
</head> </head>
<body> <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> <span class="page-title"><?php echo __('Unselect specific template'); ?></span></h2>
<?php <?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()) if (!dcCore::app()->error->flag()) {
{ # Show posts
# Show posts $post_list->display(
$post_list->display($page,$nb_per_page, $page,
'<form action="posts_actions.php" method="post" id="form-entries">'. $nb_per_page,
'<form action="posts_actions.php" method="post" id="form-entries">' .
'%s'. '%s' .
'<div class="two-cols">'. '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>'. '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">'.__('Selected entries action:').' '. '<p class="col right">' . __('Selected entries action:') . ' ' .
form::combo('action',$combo_action). form::combo('action', $combo_action) .
'<input type="submit" value="'.__('ok').'" /></p>'. '<input type="submit" value="' . __('ok') . '" /></p>' .
form::hidden('post_type',''). form::hidden('post_type', '') .
form::hidden('redir',$p_url.'&amp;m=template_posts&amp;tag='. form::hidden('redir', $p_url . '&amp;m=template_posts&amp;tag=' .
str_replace('%','%%',rawurlencode($template)).'&amp;page='.$page). str_replace('%', '%%', rawurlencode($template)) . '&amp;page=' . $page) .
$core->formNonce(). dcCore::app()->formNonce() .
'</div>'. '</div>' .
'</form>'); '</form>'
);
# Remove tag # Remove tag
if (!$posts->isEmpty() && $core->auth->check('contentadmin',$core->blog->id)) { if (!$posts->isEmpty() && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
echo dcAuth::PERMISSION_CONTENT_ADMIN,
'<form id="template_change" action="'.$this_url.'" method="post">'. ]), dcCore::app()->blog->id)) {
'<p><input type="submit" name="initialise" value="'.__('Unselect the template').'" />'. echo
$core->formNonce().'</p>'. '<form id="template_change" action="' . $this_url . '" method="post">' .
'</form>'; '<p><input type="submit" name="initialise" value="' . __('Unselect the template') . '" />' .
} dcCore::app()->formNonce() . '</p>' .
'</form>';
}
} }
?> ?>
</body> </body>