update to dotclear 2.24, refresh admin (WIP)
This commit is contained in:
parent
61939f68e1
commit
a051f78816
272
_admin.php
272
_admin.php
@ -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(' ' => '');
|
|
||||||
$tpl_post = array();
|
|
||||||
$selected = '';
|
|
||||||
|
|
||||||
foreach ($core->templator->tpl as $k => $v) {
|
|
||||||
if (!preg_match('/^category-(.+)$/',$k))
|
|
||||||
{
|
|
||||||
$tpl_post= array_merge($tpl_post, array($k => $k));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$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 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
|
||||||
{
|
{
|
||||||
global $core;
|
$selected = '';
|
||||||
|
|
||||||
$post_id = (integer) $post_id;
|
|
||||||
|
|
||||||
if (isset($_POST['post_tpl'])) {
|
|
||||||
$tpl = $_POST['post_tpl'];
|
|
||||||
|
|
||||||
$core->meta->delPostMeta($post_id,'template');
|
|
||||||
if (!empty($_POST['post_tpl']))
|
|
||||||
{
|
|
||||||
$core->meta->setPostMeta($post_id,'template',$tpl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function adminPostsActionsCombo($args)
|
if ($post) {
|
||||||
{
|
$post_meta = dcCore::app()->meta->getMetadata(['meta_type' => 'template', 'post_id' => $post->post_id]);
|
||||||
$args[0][__('Appearance')] = array(__('Select the template') => 'tpl');
|
$selected = $post_meta->isEmpty() ? '' : $post_meta->meta_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function adminPostsActions($core,$posts,$action,$redir)
|
$sidebar_items['options-box']['items']['templator'] =
|
||||||
{
|
'<div id="templator">' .
|
||||||
if ($action == 'tpl' && isset($_POST['post_tpl']))
|
'<h5>' . __('Template') . '</h5>' .
|
||||||
{
|
'<p><label for="post_tpl">' . __('Select template:') . '</label>' .
|
||||||
try
|
form::combo('post_tpl', self::getTemplateCombo(), $selected) . '</p>' .
|
||||||
{
|
'</div>';
|
||||||
$tpl = $_POST['post_tpl'];
|
}
|
||||||
|
|
||||||
while ($posts->fetch())
|
public static function adminBeforePostUpdate($cur, $post_id)
|
||||||
{
|
{
|
||||||
$core->meta->delPostMeta($posts->post_id,'template');
|
$post_id = (int) $post_id;
|
||||||
if (!empty($_POST['post_tpl']))
|
|
||||||
{
|
if (isset($_POST['post_tpl'])) {
|
||||||
$core->meta->setPostMeta($posts->post_id,'template',$tpl);
|
dcCore::app()->meta->delPostMeta($post_id, 'template');
|
||||||
}
|
if (!empty($_POST['post_tpl'])) {
|
||||||
}
|
dcCore::app()->meta->setPostMeta($post_id, 'template', $_POST['post_tpl']);
|
||||||
|
}
|
||||||
http::redirect($redir);
|
}
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
|
||||||
{
|
public static function adminPostsActions(dcPostsActions $pa)
|
||||||
$core->error->add($e->getMessage());
|
{
|
||||||
}
|
$pa->addAction(
|
||||||
}
|
[
|
||||||
}
|
__('Appearance') => [
|
||||||
|
__('Select the template') => 'tpl',
|
||||||
public static function adminPostsActionsContent($core,$action,$hidden_fields)
|
],
|
||||||
{
|
],
|
||||||
if ($action == 'tpl')
|
['templatorBehaviors', 'adminPostsActionsCallback']
|
||||||
{
|
);
|
||||||
$tpl = array(' ' => '');
|
}
|
||||||
$tpl_post = array();
|
|
||||||
$selected = '';
|
public static function adminPostsActionsCallback(dcPostsActions $pa, ArrayObject $post)
|
||||||
|
{
|
||||||
foreach ($core->templator->tpl as $k => $v) {
|
# No entry
|
||||||
if (!preg_match('/^category-(.+)$/',$k) && !preg_match('/^list-(.+)$/',$k))
|
$posts_ids = $pa->getIDs();
|
||||||
{
|
if (empty($posts_ids)) {
|
||||||
$tpl_post= array_merge($tpl_post, array($k => $k));
|
throw new Exception(__('No entry selected'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (isset($post['post_tpl'])) {
|
||||||
$tpl = array_merge($tpl,$tpl_post);
|
try {
|
||||||
|
foreach ($posts_ids as $post_id) {
|
||||||
echo
|
dcCore::app()->meta->delPostMeta($post_id, 'template');
|
||||||
'<h2 class="page-title">'.__('Select template for these entries').'</h2>'.
|
if (!empty($post['post_tpl'])) {
|
||||||
'<form action="posts_actions.php" method="post">'.
|
dcCore::app()->meta->setPostMeta($post_id, 'template', $post['post_tpl']);
|
||||||
'<p><label class="classic">'.__('Choose template:').' '.
|
}
|
||||||
form::combo('post_tpl',$tpl).
|
}
|
||||||
'</label> '.
|
|
||||||
|
dcAdminNotices::addSuccessNotice(__('Entries template updated.'));
|
||||||
$hidden_fields.
|
$pa->redirect(true);
|
||||||
$core->formNonce().
|
} catch (Exception $e) {
|
||||||
form::hidden(array('action'),'tpl').
|
dcCore::app()->error->add($e->getMessage());
|
||||||
'<input type="submit" value="'.__('Save').'" /></p>'.
|
}
|
||||||
'</form>';
|
}
|
||||||
|
|
||||||
}
|
$pa->beginPage(
|
||||||
}
|
dcPage::breadcrumb([
|
||||||
|
html::escapeHTML(dcCore::app()->blog->name) => '',
|
||||||
|
$pa->getCallerTitle() => $pa->getRedirection(true),
|
||||||
|
__('Entry template') => '',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
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>' .
|
||||||
|
|
||||||
|
'<p>' .
|
||||||
|
$pa->getHiddenFields() .
|
||||||
|
dcCore::app()->formNonce() .
|
||||||
|
form::hidden(['action'], 'tpl') .
|
||||||
|
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
||||||
|
'</form>';
|
||||||
|
|
||||||
|
$pa->endPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getTemplateCombo()
|
||||||
|
{
|
||||||
|
$tpl = [__('No specific template') => ''];
|
||||||
|
|
||||||
|
foreach (dcCore::app()->templator->tpl as $k => $v) {
|
||||||
|
if (!preg_match('/^category-(.+)$/', $k) && !preg_match('/^list-(.+)$/', $k)) {
|
||||||
|
$tpl[$k] = $k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tpl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
37
_define.php
37
_define.php
@ -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
10
_init.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
class initTemplator
|
||||||
|
{
|
||||||
|
public const PERMISSION_TEMPLATOR = 'templator';
|
||||||
|
}
|
55
_install.php
55
_install.php
@ -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
|
||||||
$current_version = $core->getVersion('templator');
|
$mod_id = basename(__DIR__);
|
||||||
|
$dc_min = dcCore::app()->plugins->moduleInfo($mod_id, 'requires')[0][1];
|
||||||
if (version_compare($current_version,$new_version,'>=')) {
|
$new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version');
|
||||||
return;
|
|
||||||
|
if (version_compare(dcCore::app()->getVersion($mod_id), $new_version, '>=')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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 false;
|
||||||
return true;
|
|
||||||
?>
|
|
||||||
|
62
_prepend.php
62
_prepend.php
@ -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(' .html' => '');
|
$tpl = [' .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);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
64
_public.php
64
_public.php
@ -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 = [];
|
||||||
if (array_key_exists($core->url->type,$core->getPostTypes()) || ($core->url->type == 'pages'))
|
$params['meta_type'] = 'template';
|
||||||
{
|
$params['post_id'] = dcCore::app()->ctx->posts->post_id;
|
||||||
$params = array();
|
$post_meta = dcCore::app()->meta->getMetadata($params);
|
||||||
$params['meta_type'] = 'template';
|
|
||||||
$params['post_id'] = $_ctx->posts->post_id;
|
if (!$post_meta->isEmpty() && dcCore::app()->tpl->getFilePath($post_meta->meta_id)) {
|
||||||
$post_meta = $core->meta->getMetadata($params);
|
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 (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;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
126
advanced.php
126
advanced.php
@ -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).' › <a href="'.$p_url.'">'.__('Supplementary templates').'</a> › <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) {
|
|
||||||
if ($tags->index() >= round($tags->count()/2)) {
|
|
||||||
$col = 1;
|
|
||||||
}
|
|
||||||
$cols[$col] .= '<tr class="tagLetter"><td colspan="2"><span>'.$letter.'</span></td></tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
|
while ($tags->fetch()) {
|
||||||
if (array_key_exists($tags->meta_id,$core->templator->tpl)) {
|
$letter = mb_strtoupper(mb_substr($tags->meta_id, 0, 1));
|
||||||
$img_status = sprintf($img,__('available template'),'check-on.png');
|
|
||||||
} else {
|
if ($last_letter != $letter) {
|
||||||
$img_status = sprintf($img,__('missing template'),'check-off.png');
|
if ($tags->index() >= round($tags->count() / 2)) {
|
||||||
}
|
$col = 1;
|
||||||
|
}
|
||||||
$cols[$col] .=
|
$cols[$col] .= '<tr class="tagLetter"><td colspan="2"><span>' . $letter . '</span></td></tr>';
|
||||||
'<tr class="line">'.
|
}
|
||||||
'<td class="maximal"><a href="'.$p_url.
|
|
||||||
'&m=template_posts&template='.rawurlencode($tags->meta_id).'">'.$tags->meta_id.'</a> '.$img_status.'</td>'.
|
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
|
||||||
'<td class="nowrap"><strong>'.$tags->count.'</strong> '.
|
if (array_key_exists($tags->meta_id, dcCore::app()->templator->tpl)) {
|
||||||
(($tags->count==1) ? __('entry') : __('entries')).'</td>'.
|
$img_status = sprintf($img, __('available template'), 'check-on.png');
|
||||||
'</tr>';
|
} 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 .
|
||||||
|
'&m=template_posts&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
132
edit.php
@ -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.' › ';};
|
|
||||||
$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 . ' › ';
|
||||||
|
};
|
||||||
|
$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).' › <a href="'.$p_url.'">'.__('Supplementary templates').'</a> › <span class="page-title">'.__('Edit the template').'</span></h2>';
|
'<h2>' . html::escapeHTML(dcCore::app()->blog->name) . ' › <a href="' . $p_url . '">' . __('Supplementary templates') . '</a> › <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 . '&edit=' . $name . '" method="post">' .
|
||||||
'<form id="file-form" action="'.$p_url.'&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
|
||||||
else
|
'</fieldset></form></div>';
|
||||||
{
|
|
||||||
echo '<p>'.__('This file is not writable. Please check your files permissions.').'</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
'</fieldset></form></div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,120 +1,123 @@
|
|||||||
<?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.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2010 Osku and contributors
|
# Copyright (c) 2010 Osku and contributors
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
# 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;
|
||||||
$fname = $f->basename;
|
$count = '';
|
||||||
$count = '';
|
$params = [];
|
||||||
$params = array();
|
$link = 'media_item.php?id=' . $f->media_id;
|
||||||
$link = 'media_item.php?id='.$f->media_id;
|
$link_edit = $p_url . '&edit=' . $fname;
|
||||||
$link_edit = $p_url.'&edit='.$fname;
|
$icon = dcPage::getPF('templator/img/template.png');
|
||||||
$icon = 'index.php?pf=templator/img/template.png';
|
$class = 'media-item media-col-' . ($i % 2);
|
||||||
$class = 'media-item media-col-'.($i%2);
|
$details = $special = '';
|
||||||
$details = $special = '';
|
$widget_icon = '<span class="widget" title="' . __('Template widget') . '">♦</span>';
|
||||||
$widget_icon = '<span class="widget" title="'.__('Template widget').'">♦</span>';
|
$copy_url = '&copy=';
|
||||||
$copy_url = '&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 = $core->blog->getCategoryParents($cat_id);
|
|
||||||
$full_name = '';
|
|
||||||
while ($cat_parents->fetch()) {$full_name = $cat_parents->cat_title.' › ';};
|
|
||||||
$fname = '<strong>'.__('Category').'</strong> : '.$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 = '&copycat=';
|
|
||||||
try {
|
|
||||||
$counter = $core->blog->getPosts($params,true);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$core->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 = ' ';
|
|
||||||
$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 = ' ';
|
|
||||||
} elseif ($counter->f(0) == 1) {
|
|
||||||
$count = '<strong>'.$counter->f(0).'</strong> <a href="'.$p_url.'&m=template_posts&template='.$fname.'">'.__('entry').'</a>';
|
|
||||||
} else {
|
|
||||||
$count = '<strong>'.$counter->f(0).'</strong> <a href="'.$p_url.'&m=template_posts&template='.$fname.'">'.__('entries').'</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($core->auth->check('contentadmin,media',$core->blog->id)) {
|
|
||||||
$details = ' - <a href="'.$link.'">'.__('details').'</a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$f->d) {
|
|
||||||
$res .=
|
|
||||||
'<li>'.$count.'</li>'.
|
|
||||||
'<li>'.
|
|
||||||
$f->media_dtstr.' - '.
|
|
||||||
files::size($f->size).
|
|
||||||
$details.
|
|
||||||
'</li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$res .= '<li class="media-action"> ';
|
|
||||||
|
|
||||||
$res .= '<a class="media-remove" '.
|
if (preg_match('/^category-(.+)$/', $f->basename)) {
|
||||||
'href="'.$p_url.$copy_url.rawurlencode($f->basename).'">'.
|
// That is ugly.
|
||||||
'<img src="index.php?pf=templator/img/copy.png" alt="'.__('copy').'" title="'.__('copy the template').'" /></a> ';
|
$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 . ' › ';
|
||||||
|
};
|
||||||
|
$fname = '<strong>' . __('Category') . '</strong> : ' . $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 = '&copycat=';
|
||||||
|
|
||||||
|
try {
|
||||||
if ($f->del) {
|
$counter = dcCore::app()->blog->getPosts($params, true);
|
||||||
$res .= '<a class="media-remove" '.
|
} catch (Exception $e) {
|
||||||
'href="'.$p_url.'&remove='.rawurlencode($f->basename).'">'.
|
dcCore::app()->error->add($e->getMessage());
|
||||||
'<img src="index.php?pf=templator/img/delete.png" alt="'.__('delete').'" title="'.__('delete the template').'" /></a>';
|
}
|
||||||
}
|
|
||||||
|
if ($counter->f(0) == 0) {
|
||||||
$res .= '</li>';
|
$count = __('No entry');
|
||||||
|
} elseif ($counter->f(0) == 1) {
|
||||||
$res .= '</ul></div>';
|
$count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entry') . '</a>';
|
||||||
|
} else {
|
||||||
return $res;
|
$count = '<strong>' . $counter->f(0) . '</strong> <a href="posts.php?cat_id=' . $cat_id . '">' . __('entries') . '</a>';
|
||||||
}
|
}
|
||||||
|
} elseif (preg_match('/^widget-(.+)$/', $f->basename)) {
|
||||||
|
$count = ' ';
|
||||||
|
$icon = dcPage::getPF('templator/img/template-widget.png');
|
||||||
|
$special = $widget_icon;
|
||||||
|
} else {
|
||||||
|
$params['meta_id'] = $f->basename;
|
||||||
|
$params['meta_type'] = 'template';
|
||||||
|
$params['post_type'] = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$counter = dcCore::app()->meta->getPostsByMeta($params, true);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($counter->f(0) == 0) {
|
||||||
|
$count = ' ';
|
||||||
|
} elseif ($counter->f(0) == 1) {
|
||||||
|
$count = '<strong>' . $counter->f(0) . '</strong> <a href="' . $p_url . '&m=template_posts&template=' . $fname . '">' . __('entry') . '</a>';
|
||||||
|
} else {
|
||||||
|
$count = '<strong>' . $counter->f(0) . '</strong> <a href="' . $p_url . '&m=template_posts&template=' . $fname . '">' . __('entries') . '</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 (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>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$f->d) {
|
||||||
|
$res .= '<li>' . $count . '</li>' .
|
||||||
|
'<li>' .
|
||||||
|
$f->media_dtstr . ' - ' .
|
||||||
|
files::size($f->size) .
|
||||||
|
$details .
|
||||||
|
'</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$res .= '<li class="media-action"> ';
|
||||||
|
|
||||||
|
$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> ';
|
||||||
|
|
||||||
|
if ($f->del) {
|
||||||
|
$res .= '<a class="media-remove" ' .
|
||||||
|
'href="' . $p_url . '&remove=' . rawurlencode($f->basename) . '">' .
|
||||||
|
'<img src="' . dcPage::getPF('templator/img/delete.png') . '" alt="' . __('delete') . '" title="' . __('delete the template') . '" /></a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$res .= '</li>';
|
||||||
|
|
||||||
|
$res .= '</ul></div>';
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
@ -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 $tpl = array();
|
|
||||||
public $theme_tpl = array();
|
|
||||||
|
|
||||||
/**
|
public $template_dir_name = 'other-templates';
|
||||||
*
|
public $path;
|
||||||
*/
|
|
||||||
public function __construct($core)
|
|
||||||
{
|
|
||||||
$this->core =& $core;
|
|
||||||
|
|
||||||
$this->path = $this->core->blog->public_path.'/'.$this->template_dir_name;
|
public $tpl = [];
|
||||||
|
public $theme_tpl = [];
|
||||||
// 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);
|
*/
|
||||||
}
|
public function __construct()
|
||||||
|
{
|
||||||
$this->user_theme = $this->core->blog->themes_path.'/'.$this->core->blog->settings->system->theme;
|
$this->path = dcCore::app()->blog->public_path . '/' . $this->template_dir_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_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));
|
// 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;
|
||||||
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')
|
if (dcCore::app()->plugins->moduleExists('pages')) {
|
||||||
{
|
$plugin_page = dcCore::app()->plugins->getModules('pages');
|
||||||
$source['c'] = '';
|
$this->page_tpl = path::real($plugin_page['root'] . '/default-templates/' . $this->tpls_default_name . '/' . $this->page_default_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
$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);
|
||||||
$dest = $this->getDestinationFile($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);
|
||||||
|
|
||||||
if ($dest == false) {
|
$this->findTemplates();
|
||||||
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'] = '';
|
*/
|
||||||
}
|
public function canUseRessources($create = false)
|
||||||
|
{
|
||||||
|
if (!is_dir($this->path)) {
|
||||||
|
if ($create) {
|
||||||
|
files::makeDir($this->path);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
return true;
|
||||||
{
|
}
|
||||||
$dest = $this->getDestinationFile($name);
|
|
||||||
|
|
||||||
if ($dest == false) {
|
if (!is_writable($this->path)) {
|
||||||
throw new Exception();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $source['c'];
|
if (!is_file($this->path . '/.htaccess')) {
|
||||||
|
try {
|
||||||
if (!is_dir(dirname($dest))) {
|
file_put_contents($this->path . '/.htaccess', "Deny from all\n");
|
||||||
files::makeDir(dirname($dest));
|
} catch (Exception $e) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
$fp = @fopen($dest,'wb');
|
}
|
||||||
if (!$fp) {
|
|
||||||
throw new Exception('tocatch');
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = preg_replace('/(\r?\n)/m',"\n",$content);
|
/**
|
||||||
$content = preg_replace('/\r/m',"\n",$content);
|
*
|
||||||
|
*/
|
||||||
fwrite($fp,$content);
|
public function getSourceContent($f)
|
||||||
fclose($fp);
|
{
|
||||||
}
|
$source = $this->tpl;
|
||||||
catch (Exception $e)
|
|
||||||
{
|
if (!isset($source[$f])) {
|
||||||
throw $e;
|
throw new Exception(__('File does not exist.'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
$F = $source[$f];
|
||||||
/**
|
if (!is_readable($F)) {
|
||||||
*
|
throw new Exception(sprintf(__('File %s is not readable'), $f));
|
||||||
*/
|
}
|
||||||
public function writeTpl($name,$content)
|
|
||||||
{
|
return [
|
||||||
try
|
'c' => file_get_contents($source[$f]),
|
||||||
{
|
'w' => $this->getDestinationFile($f) !== false,
|
||||||
$dest = $this->getDestinationFile($name);
|
'f' => $f,
|
||||||
|
];
|
||||||
if ($dest == false) {
|
}
|
||||||
throw new Exception();
|
|
||||||
}
|
/**
|
||||||
|
*
|
||||||
if (!is_dir(dirname($dest))) {
|
*/
|
||||||
files::makeDir(dirname($dest));
|
public function filesList($item = '%1$s')
|
||||||
}
|
{
|
||||||
|
$files = $this->tpl;
|
||||||
$fp = @fopen($dest,'wb');
|
|
||||||
if (!$fp) {
|
if (empty($files)) {
|
||||||
//throw new Exception('tocatch');
|
return '<p>' . __('No file') . '</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = preg_replace('/(\r?\n)/m',"\n",$content);
|
$list = '';
|
||||||
$content = preg_replace('/\r/m',"\n",$content);
|
foreach ($files as $k => $v) {
|
||||||
|
$li = sprintf('<li>%s</li>', $item);
|
||||||
fwrite($fp,$content);
|
|
||||||
fclose($fp);
|
$list .= sprintf($li, $k, html::escapeHTML($k));
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
|
||||||
{
|
return sprintf('<ul>%s</ul>', $list);
|
||||||
throw $e;
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
*
|
||||||
/**
|
*/
|
||||||
*
|
public function initializeTpl($name, $type)
|
||||||
*/
|
{
|
||||||
public function copyTpl($name)
|
if ($type == 'category') {
|
||||||
{
|
if ($this->user_category_tpl) {
|
||||||
try
|
$base = $this->user_category_tpl;
|
||||||
{
|
} else {
|
||||||
$file = $this->getSourceContent($name);
|
$base = $this->category_tpl;
|
||||||
$dest = $this->getDestinationFile($name,true);
|
}
|
||||||
|
} elseif ($type == 'page') {
|
||||||
if ($dest == false) {
|
if ($this->user_page_tpl) {
|
||||||
throw new Exception();
|
$base = $this->user_page_tpl;
|
||||||
}
|
} else {
|
||||||
|
$base = $this->page_tpl;
|
||||||
if (!is_dir(dirname($dest))) {
|
}
|
||||||
files::makeDir(dirname($dest));
|
} else {
|
||||||
}
|
if ($this->user_post_tpl) {
|
||||||
|
$base = $this->user_post_tpl;
|
||||||
$fp = @fopen($dest,'wb');
|
} else {
|
||||||
if (!$fp) {
|
$base = $this->post_tpl;
|
||||||
throw new Exception('tocatch');
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = preg_replace('/(\r?\n)/m',"\n",$file['c']);
|
$source = [
|
||||||
$content = preg_replace('/\r/m',"\n",$file['c']);
|
'c' => file_get_contents($base),
|
||||||
|
'w' => $this->getDestinationFile($name) !== false,
|
||||||
fwrite($fp,$file['c']);
|
'f' => $f, ];
|
||||||
fclose($fp);
|
|
||||||
}
|
if (!$source['w']) {
|
||||||
catch (Exception $e)
|
throw new Exception(sprintf(__('File %s is not readable'), $source));
|
||||||
{
|
}
|
||||||
throw $e;
|
|
||||||
}
|
if ($type == 'empty') {
|
||||||
}
|
$source['c'] = '';
|
||||||
|
}
|
||||||
protected function getDestinationFile($f,$totheme=false)
|
|
||||||
{
|
try {
|
||||||
$dest = $this->path.'/'.$f;
|
$dest = $this->getDestinationFile($name);
|
||||||
if ($totheme) {
|
|
||||||
$dest = $this->user_theme.'/tpl/'.$f;
|
if ($dest == false) {
|
||||||
}
|
throw new Exception();
|
||||||
|
}
|
||||||
if (file_exists($dest) && is_writable($dest)) {
|
|
||||||
return $dest;
|
$content = $source['c'];
|
||||||
}
|
|
||||||
|
if (!is_dir(dirname($dest))) {
|
||||||
if (is_writable(dirname($dest))) {
|
files::makeDir(dirname($dest));
|
||||||
return $dest;
|
}
|
||||||
}
|
|
||||||
|
$fp = @fopen($dest, 'wb');
|
||||||
return false;
|
if (!$fp) {
|
||||||
}
|
throw new Exception('tocatch');
|
||||||
|
}
|
||||||
protected function findTemplates()
|
|
||||||
{
|
$content = preg_replace('/(\r?\n)/m', "\n", $content);
|
||||||
$this->tpl = $this->getFilesInDir($this->path);
|
$content = preg_replace('/\r/m', "\n", $content);
|
||||||
//$this->theme_tpl = $this->getFilesInDir(path::real($this->user_theme).'/tpl');
|
|
||||||
|
fwrite($fp, $content);
|
||||||
uksort($this->tpl,array($this,'sortFilesHelper'));
|
fclose($fp);
|
||||||
//uksort($this->theme_tpl,array($this,'sortFilesHelper'));
|
} catch (Exception $e) {
|
||||||
}
|
throw $e;
|
||||||
|
}
|
||||||
protected function getFilesInDir($dir)
|
}
|
||||||
{
|
|
||||||
$dir = path::real($dir);
|
/**
|
||||||
if (!$dir || !is_dir($dir) || !is_readable($dir)) {
|
*
|
||||||
return array();
|
*/
|
||||||
}
|
public function copypasteTpl($name, $source)
|
||||||
|
{
|
||||||
$d = dir($dir);
|
if ($name == $source) {
|
||||||
$res = array();
|
throw new Exception(__('Why copy file content in the same file?'));
|
||||||
while (($f = $d->read()) !== false)
|
}
|
||||||
{
|
|
||||||
if (is_file($dir.'/'.$f) && !preg_match('/^\./',$f)) {
|
$file = $this->getSourceContent($source);
|
||||||
$res[$f] = $dir.'/'.$f;
|
|
||||||
}
|
$source = [
|
||||||
}
|
'c' => $file['c'],
|
||||||
|
'w' => $this->getDestinationFile($name) !== false,
|
||||||
return $res;
|
'f' => $f, ];
|
||||||
}
|
|
||||||
|
if (!$source['w']) {
|
||||||
protected function sortFilesHelper($a,$b)
|
throw new Exception(sprintf(__('File %s is not readable'), $source));
|
||||||
{
|
}
|
||||||
if ($a == $b) {
|
|
||||||
return 0;
|
if ($type == 'empty') {
|
||||||
}
|
$source['c'] = '';
|
||||||
|
}
|
||||||
$ext_a = files::getExtension($a);
|
|
||||||
$ext_b = files::getExtension($b);
|
try {
|
||||||
|
$dest = $this->getDestinationFile($name);
|
||||||
return strcmp($ext_a.'.'.$a,$ext_b.'.'.$b);
|
|
||||||
}
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
447
index.php
447
index.php
@ -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();
|
|
||||||
$l = $categories->level;
|
|
||||||
$full_name = array($categories->cat_title);
|
|
||||||
|
|
||||||
while ($categories->fetch()) {
|
|
||||||
|
|
||||||
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(' › ',$full_name)] = $categories->cat_id;
|
|
||||||
|
|
||||||
$l = $categories->level;
|
|
||||||
|
|
||||||
}
|
$categories_combo = [];
|
||||||
} catch (Exception $e) { }
|
$l = $categories->level;
|
||||||
|
$full_name = [$categories->cat_title];
|
||||||
|
|
||||||
|
while ($categories->fetch()) {
|
||||||
|
if ($categories->level < $l) {
|
||||||
|
$full_name = [];
|
||||||
|
} elseif ($categories->level == $l) {
|
||||||
|
array_pop($full_name);
|
||||||
|
}
|
||||||
|
$full_name[] = html::escapeHTML($categories->cat_title);
|
||||||
|
|
||||||
|
$categories_combo[implode(' › ', $full_name)] = $categories->cat_id;
|
||||||
|
|
||||||
|
$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[' — '] = 'empty';
|
$combo_source[' — '] = '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).' › <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'])
|
||||||
' <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>'.
|
' <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> '.
|
) . '</p>' .
|
||||||
'<input type="submit" name="cpyes" value="'.__('Copy').'" /> <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> ' .
|
||||||
form::hidden('copy',html::escapeHTML($_GET['copy'])).'</p>'.
|
'<input type="submit" name="cpyes" value="' . __('Copy') . '" /> <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.' › ';};
|
while ($cat_parents->fetch()) {
|
||||||
$name = $full_name.$core->blog->getCategory($category_id)->cat_title;
|
$full_name = $cat_parents->cat_title . ' › ';
|
||||||
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').'" /> <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') . '" /> <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 = __('«prev.');
|
||||||
{
|
$pager->html_next = __('next»');
|
||||||
$pager = new pager($page,count($items),$nb_per_page,10);
|
|
||||||
$pager->html_prev = __('«prev.');
|
echo
|
||||||
$pager->html_next = __('next»');
|
'<form action="media.php" method="get">' .
|
||||||
|
'</form>' .
|
||||||
echo
|
|
||||||
'<form action="media.php" method="get">'.
|
'<div class="media-list">' .
|
||||||
'</form>'.
|
'<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
|
||||||
|
|
||||||
'<div class="media-list">'.
|
for ($i = $pager->index_start, $j = 0; $i <= $pager->index_end; $i++, $j++) {
|
||||||
'<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
|
echo pagerTemplator::templatorItemLine($items[$i], $j);
|
||||||
|
}
|
||||||
for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++, $j++)
|
|
||||||
{
|
echo
|
||||||
echo pagerTemplator::templatorItemLine($items[$i],$j);
|
'<p class="clear">' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>' .
|
||||||
}
|
'</div>';
|
||||||
|
|
||||||
echo
|
|
||||||
'<p class="clear">'.__('Page(s)').' : '.$pager->getLinks().'</p>'.
|
|
||||||
'</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
'<p class="clear">
|
'<p class="clear">
|
||||||
<a class="button"
|
<a class="button"
|
||||||
href="'.$p_url.'&database=on"
|
href="' . $p_url . '&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
7
js/admin.js
Normal 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}
|
||||||
|
);
|
||||||
|
});
|
@ -1,8 +1,9 @@
|
|||||||
<?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
|
||||||
// Translated with dcTranslater - 1.5
|
// Translated with dcTranslater - 1.5
|
||||||
|
|
||||||
#_admin.php:15
|
#_admin.php:15
|
||||||
$GLOBALS['__l10n']['Templates'] = 'Templates';
|
$GLOBALS['__l10n']['Templates'] = 'Templates';
|
||||||
@ -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';
|
||||||
|
|
||||||
?>
|
|
@ -2,78 +2,86 @@
|
|||||||
# -- 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.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2010 Osku and contributors
|
# Copyright (c) 2010 Osku and contributors
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
# 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.'&m=template_posts&template='.rawurlencode($template);
|
$this_url = $p_url . '&m=template_posts&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); ?> ›
|
<h2><?php echo html::escapeHTML(dcCore::app()->blog->name); ?> ›
|
||||||
<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">'.
|
|
||||||
'<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).
|
'<p class="col right">' . __('Selected entries action:') . ' ' .
|
||||||
'<input type="submit" value="'.__('ok').'" /></p>'.
|
form::combo('action', $combo_action) .
|
||||||
form::hidden('post_type','').
|
'<input type="submit" value="' . __('ok') . '" /></p>' .
|
||||||
form::hidden('redir',$p_url.'&m=template_posts&tag='.
|
form::hidden('post_type', '') .
|
||||||
str_replace('%','%%',rawurlencode($template)).'&page='.$page).
|
form::hidden('redir', $p_url . '&m=template_posts&tag=' .
|
||||||
$core->formNonce().
|
str_replace('%', '%%', rawurlencode($template)) . '&page=' . $page) .
|
||||||
'</div>'.
|
dcCore::app()->formNonce() .
|
||||||
'</form>');
|
'</div>' .
|
||||||
|
'</form>'
|
||||||
# Remove tag
|
);
|
||||||
if (!$posts->isEmpty() && $core->auth->check('contentadmin',$core->blog->id)) {
|
|
||||||
echo
|
# Remove tag
|
||||||
'<form id="template_change" action="'.$this_url.'" method="post">'.
|
if (!$posts->isEmpty() && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||||
'<p><input type="submit" name="initialise" value="'.__('Unselect the template').'" />'.
|
dcAuth::PERMISSION_CONTENT_ADMIN,
|
||||||
$core->formNonce().'</p>'.
|
]), dcCore::app()->blog->id)) {
|
||||||
'</form>';
|
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>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user