clean up code, first pass

master
Jean-Christian Paul Denis 2021-09-10 21:18:51 +02:00
parent 7ed1ad5b03
commit c9e185a68c
16 changed files with 1014 additions and 692 deletions

View File

@ -1,95 +1,94 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
require dirname(__FILE__).'/_widgets.php'; require dirname(__FILE__).'/_widgets.php';
# Admin menu # Admin menu
if ($core->blog->settings->postwidgettext->postwidgettext_active) { if ($core->blog->settings->postwidgettext->postwidgettext_active) {
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('Post widget text'), __('Post widget text'),
'plugin.php?p=postWidgetText', 'plugin.php?p=postWidgetText',
'index.php?pf=postWidgetText/icon.png', 'index.php?pf=postWidgetText/icon.png',
preg_match( preg_match(
'/plugin.php\?p=postWidgetText(&.*)?$/', '/plugin.php\?p=postWidgetText(&.*)?$/',
$_SERVER['REQUEST_URI']), $_SERVER['REQUEST_URI']),
$core->auth->check('contentadmin', $core->blog->id) $core->auth->check('contentadmin', $core->blog->id)
); );
$core->addBehavior( $core->addBehavior(
'adminDashboardFavorites', 'adminDashboardFavorites',
array('postWidgetTextDashboard', 'favorites') array('postWidgetTextDashboard', 'favorites')
); );
} }
# Post # Post
$core->addBehavior( $core->addBehavior(
'adminPostHeaders', 'adminPostHeaders',
array('postWidgetTextAdmin', 'headers')); array('postWidgetTextAdmin', 'headers'));
$core->addBehavior( $core->addBehavior(
'adminPostFormItems', 'adminPostFormItems',
array('postWidgetTextAdmin', 'form')); array('postWidgetTextAdmin', 'form'));
$core->addBehavior( $core->addBehavior(
'adminAfterPostUpdate', 'adminAfterPostUpdate',
array('postWidgetTextAdmin', 'save')); array('postWidgetTextAdmin', 'save'));
$core->addBehavior( $core->addBehavior(
'adminAfterPostCreate', 'adminAfterPostCreate',
array('postWidgetTextAdmin', 'save')); array('postWidgetTextAdmin', 'save'));
$core->addBehavior( $core->addBehavior(
'adminBeforePostDelete', 'adminBeforePostDelete',
array('postWidgetTextAdmin', 'delete')); array('postWidgetTextAdmin', 'delete'));
# Plugin "pages" # Plugin "pages"
$core->addBehavior( $core->addBehavior(
'adminPageHeaders', 'adminPageHeaders',
array('postWidgetTextAdmin', 'headers')); array('postWidgetTextAdmin', 'headers'));
$core->addBehavior( $core->addBehavior(
'adminPageFormItems', 'adminPageFormItems',
array('postWidgetTextAdmin', 'form')); array('postWidgetTextAdmin', 'form'));
$core->addBehavior( $core->addBehavior(
'adminAfterPageUpdate', 'adminAfterPageUpdate',
array('postWidgetTextAdmin', 'save')); array('postWidgetTextAdmin', 'save'));
$core->addBehavior( $core->addBehavior(
'adminAfterPageCreate', 'adminAfterPageCreate',
array('postWidgetTextAdmin', 'save')); array('postWidgetTextAdmin', 'save'));
$core->addBehavior( $core->addBehavior(
'adminBeforePageDelete', 'adminBeforePageDelete',
array('postWidgetTextAdmin', 'delete')); array('postWidgetTextAdmin', 'delete'));
# Plugin "importExport" # Plugin "importExport"
if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) { if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) {
$core->addBehavior( $core->addBehavior(
'exportFull', 'exportFull',
array('postWidgetTextBackup', 'exportFull') array('postWidgetTextBackup', 'exportFull')
); );
$core->addBehavior( $core->addBehavior(
'exportSingle', 'exportSingle',
array('postWidgetTextBackup', 'exportSingle') array('postWidgetTextBackup', 'exportSingle')
); );
$core->addBehavior( $core->addBehavior(
'importInit', 'importInit',
array('postWidgetTextBackup', 'importInit') array('postWidgetTextBackup', 'importInit')
); );
$core->addBehavior( $core->addBehavior(
'importSingle', 'importSingle',
array('postWidgetTextBackup', 'importSingle') array('postWidgetTextBackup', 'importSingle')
); );
$core->addBehavior( $core->addBehavior(
'importFull', 'importFull',
array('postWidgetTextBackup', 'importFull') array('postWidgetTextBackup', 'importFull')
); );
} }

View File

@ -1,24 +1,23 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_MODULE')) { if (!defined('DC_CONTEXT_MODULE')) {
return null; return null;
} }
$redir = empty($_REQUEST['redir']) ? $redir = empty($_REQUEST['redir']) ?
$list->getURL().'#plugins' : $_REQUEST['redir']; $list->getURL().'#plugins' : $_REQUEST['redir'];
# -- Get settings -- # -- Get settings --
$core->blog->settings->addNamespace('postwidgettext'); $core->blog->settings->addNamespace('postwidgettext');
@ -30,26 +29,26 @@ $importexport_active = (boolean) $s->postwidgettext_importexport_active;
# -- Set settings -- # -- Set settings --
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
$active = !empty($_POST['active']); $active = !empty($_POST['active']);
$importexport_active = !empty($_POST['importexport_active']); $importexport_active = !empty($_POST['importexport_active']);
$s->put('postwidgettext_active', $active); $s->put('postwidgettext_active', $active);
$s->put('postwidgettext_importexport_active', $importexport_active); $s->put('postwidgettext_importexport_active', $importexport_active);
$core->blog->triggerBlog(); $core->blog->triggerBlog();
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Configuration has been successfully updated.') __('Configuration has been successfully updated.')
); );
http::redirect( http::redirect(
$list->getURL('module=postWidgetText&conf=1&redir='. $list->getURL('module=postWidgetText&conf=1&redir='.
$list->getRedir()) $list->getRedir())
); );
} }
catch (Exception $e) { catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
# -- Display form -- # -- Display form --

View File

@ -1,17 +1,15 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;

View File

@ -1,87 +1,86 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
try { try {
# Check module version # Check module version
if (version_compare( if (version_compare(
$core->getVersion('postWidgetText'), $core->getVersion('postWidgetText'),
$core->plugins->moduleInfo('postWidgetText', 'version'), $core->plugins->moduleInfo('postWidgetText', 'version'),
'>=' '>='
)) { )) {
return null; return null;
} }
# Check Dotclear version # Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare') if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, '2.6', '<', false)) { || dcUtils::versionsCompare(DC_VERSION, '2.6', '<', false)) {
throw new Exception(sprintf( throw new Exception(sprintf(
'%s requires Dotclear %s', 'postWidgetText', '2.6' '%s requires Dotclear %s', 'postWidgetText', '2.6'
)); ));
} }
# Table is the same for plugins # Table is the same for plugins
# pollsFactory, postTask, postWidgetText # pollsFactory, postTask, postWidgetText
$s = new dbStruct($core->con,$core->prefix); $s = new dbStruct($core->con,$core->prefix);
$s->post_option $s->post_option
->option_id ('bigint',0,false) ->option_id ('bigint',0,false)
->post_id ('bigint',0,false) ->post_id ('bigint',0,false)
->option_creadt ('timestamp',0,false,'now()') ->option_creadt ('timestamp',0,false,'now()')
->option_upddt ('timestamp',0,false,'now()') ->option_upddt ('timestamp',0,false,'now()')
->option_type ('varchar',32,false,"''") ->option_type ('varchar',32,false,"''")
->option_format ('varchar',32,false,"'xhtml'") ->option_format ('varchar',32,false,"'xhtml'")
->option_lang ('varchar',5,true,null) ->option_lang ('varchar',5,true,null)
->option_title ('varchar',255,true,null) ->option_title ('varchar',255,true,null)
->option_content ('text',0,true,null) ->option_content ('text',0,true,null)
->option_content_xhtml ('text',0,false) ->option_content_xhtml ('text',0,false)
->index('idx_post_option_option','btree','option_id') ->index('idx_post_option_option','btree','option_id')
->index('idx_post_option_post','btree','post_id') ->index('idx_post_option_post','btree','post_id')
->index('idx_post_option_type','btree','option_type'); ->index('idx_post_option_type','btree','option_type');
$si = new dbStruct($core->con,$core->prefix); $si = new dbStruct($core->con,$core->prefix);
$changes = $si->synchronize($s); $changes = $si->synchronize($s);
# Settings # Settings
$core->blog->settings->addNamespace('postwidgettext'); $core->blog->settings->addNamespace('postwidgettext');
$core->blog->settings->postwidgettext->put('postwidgettext_active', $core->blog->settings->postwidgettext->put('postwidgettext_active',
true,'boolean','post widget text plugin enabled',false,true); true,'boolean','post widget text plugin enabled',false,true);
$core->blog->settings->postwidgettext->put('postwidgettext_importexport_active', $core->blog->settings->postwidgettext->put('postwidgettext_importexport_active',
true,'boolean','activate import/export behaviors',false,true); true,'boolean','activate import/export behaviors',false,true);
# Transfert records from old table to the new one # Transfert records from old table to the new one
if ($core->getVersion('postWidgetText') !== null if ($core->getVersion('postWidgetText') !== null
&& version_compare($core->getVersion('postWidgetText'), '0.5', '<') && version_compare($core->getVersion('postWidgetText'), '0.5', '<')
) { ) {
require_once dirname(__FILE__).'/inc/patch.0.5.php'; require_once dirname(__FILE__).'/inc/patch.0.5.php';
} }
# Set module version # Set module version
$core->setVersion( $core->setVersion(
'postWidgetText', 'postWidgetText',
$core->plugins->moduleInfo('postWidgetText', 'version') $core->plugins->moduleInfo('postWidgetText', 'version')
); );
return true; return true;
} }
catch (Exception $e) { catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
return false; return false;
} }

View File

@ -1,29 +1,28 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__autoload['postWidgetText'] = $__autoload['postWidgetText'] =
dirname(__FILE__).'/inc/class.postwidgettext.php'; dirname(__FILE__).'/inc/class.postwidgettext.php';
$__autoload['postWidgetTextDashboard'] = $__autoload['postWidgetTextDashboard'] =
dirname(__FILE__).'/inc/lib.pwt.dashboard.php'; dirname(__FILE__).'/inc/lib.pwt.dashboard.php';
$__autoload['postWidgetTextAdmin'] = $__autoload['postWidgetTextAdmin'] =
dirname(__FILE__).'/inc/lib.pwt.admin.php'; dirname(__FILE__).'/inc/lib.pwt.admin.php';
$__autoload['postWidgetTextBackup'] = $__autoload['postWidgetTextBackup'] =
dirname(__FILE__).'/inc/lib.pwt.backup.php'; dirname(__FILE__).'/inc/lib.pwt.backup.php';
$__autoload['postWidgetTextList'] = $__autoload['postWidgetTextList'] =
dirname(__FILE__).'/inc/lib.pwt.list.php'; dirname(__FILE__).'/inc/lib.pwt.list.php';

View File

@ -1,15 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
if (!defined('DC_RC_PATH')) { return null; } require dirname(__FILE__).'/_widgets.php';
return null;
}
require dirname(__FILE__).'/_widgets.php';

View File

@ -1,15 +1,111 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
if (!defined('DC_RC_PATH')) { return null; } $core->blog->settings->addNamespace('postwidgettext'); $core->addBehavior( 'initWidgets', array('postWidgetTextWidget', 'init') ); /** * @ingroup DC_PLUGIN_POSTWIDGETTEXT * @brief postWidgetText - admin and public widget methods. * @since 2.6 */ class postWidgetTextWidget { public static function init($w) { global $core; $w->create( 'postwidgettext', __('Post widget text'), array('postWidgetTextWidget', 'display'), null, __('Add a widget with a text related to an entry') ); $w->postwidgettext->setting( 'title', __('Title:'), __('More about this entry'), 'text' ); $w->postwidgettext->setting( 'excerpt', __('Use excerpt if no content'), 0, 'check' ); $w->postwidgettext->setting( 'show', __('Show widget even if empty'), 0, 'check' ); $w->postwidgettext->setting( 'content_only', __('Content only'), 0, 'check' ); $w->postwidgettext->setting( 'class', __('CSS class:'), '' ); } public static function display($w) { global $core, $_ctx; if (!$core->blog->settings->postwidgettext->postwidgettext_active || !$_ctx->exists('posts') || !$_ctx->posts->post_id ) { return null; } $title = (strlen($w->title) > 0) ? '<h2>'.html::escapeHTML($w->title).'</h2>' : null; $content = ''; $pwt = new postWidgetText($core); $rs = $pwt->getWidgets(array('post_id'=>$_ctx->posts->post_id)); if ('' != $rs->option_title) { $title = '<h2>'.$rs->option_title.'</h2>'; } if ('' != $rs->option_content_xhtml) { $content = $rs->option_content_xhtml; } if ('' == $content && $w->excerpt) { $content = $_ctx->posts->post_excerpt_xhtml; } return '' == $content && !$w->show ? null : ($w->content_only ? '' : '<div class="postwidgettext'. ($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). $title. $content. ($w->content_only ? '' : '</div>'); } }
return null;
}
$core->blog->settings->addNamespace('postwidgettext');
$core->addBehavior(
'initWidgets',
array('postWidgetTextWidget', 'init')
);
/**
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
* @brief postWidgetText - admin and public widget methods.
* @since 2.6
*/
class postWidgetTextWidget
{
public static function init($w)
{
global $core;
$w->create(
'postwidgettext',
__('Post widget text'),
array('postWidgetTextWidget', 'display'),
null,
__('Add a widget with a text related to an entry')
);
$w->postwidgettext->setting(
'title',
__('Title:'),
__('More about this entry'),
'text'
);
$w->postwidgettext->setting(
'excerpt',
__('Use excerpt if no content'),
0,
'check'
);
$w->postwidgettext->setting(
'show',
__('Show widget even if empty'),
0,
'check'
);
$w->postwidgettext->setting(
'content_only',
__('Content only'),
0,
'check'
);
$w->postwidgettext->setting(
'class',
__('CSS class:'),
''
);
}
public static function display($w)
{
global $core, $_ctx;
if (!$core->blog->settings->postwidgettext->postwidgettext_active
|| !$_ctx->exists('posts')
|| !$_ctx->posts->post_id
) {
return null;
}
$title = (strlen($w->title) > 0) ?
'<h2>'.html::escapeHTML($w->title).'</h2>' : null;
$content = '';
$pwt = new postWidgetText($core);
$rs = $pwt->getWidgets(array('post_id'=>$_ctx->posts->post_id));
if ('' != $rs->option_title) {
$title = '<h2>'.$rs->option_title.'</h2>';
}
if ('' != $rs->option_content_xhtml) {
$content = $rs->option_content_xhtml;
}
if ('' == $content && $w->excerpt) {
$content = $_ctx->posts->post_excerpt_xhtml;
}
return '' == $content && !$w->show ?
null :
($w->content_only ? '' : '<div class="postwidgettext'.
($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
$title.
$content.
($w->content_only ? '' : '</div>');
}
}

12
dcstore.xml 100644
View File

@ -0,0 +1,12 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="postWidgetText">
<name>Widget texte de billet</name>
<version>2021.00.00.1</version>
<author>Jean-Christian Denis and Contributors</author>
<desc>Add a widget with a text related to an entry</desc>
<file>https://github.com/JcDenis/postWidgetText/releases/download/v2021.00.00.1/plugin-postWidgetText.zip</file>
<da:dcmin>2.19</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/postWidgetText</da:details>
<da:support>https://github.com/JcDenis/postWidgetText</da:support>
</module>
</modules>

File diff suppressed because one or more lines are too long

View File

@ -1,20 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
/** /**
@ -24,103 +23,103 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class postWidgetTextAdmin class postWidgetTextAdmin
{ {
public static function headers() public static function headers()
{ {
return dcPage::jsLoad('index.php?pf=postWidgetText/js/post.js'); return dcPage::jsLoad('index.php?pf=postWidgetText/js/post.js');
} }
public static function form($main, $sidebar, $post) public static function form($main, $sidebar, $post)
{ {
# _POST fields # _POST fields
$title = empty($_POST['post_wtitle']) ? '' : $_POST['post_wtitle']; $title = empty($_POST['post_wtitle']) ? '' : $_POST['post_wtitle'];
$content = empty($_POST['post_wtext']) ? '' : $_POST['post_wtext']; $content = empty($_POST['post_wtext']) ? '' : $_POST['post_wtext'];
# Existing post # Existing post
if ($post) { if ($post) {
$post_id = (integer) $post->post_id; $post_id = (integer) $post->post_id;
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
$w = $pwt->getWidgets(array('post_id' => $post_id)); $w = $pwt->getWidgets(array('post_id' => $post_id));
# Existing widget # Existing widget
if (!$w->isEmpty()) { if (!$w->isEmpty()) {
$title = $w->option_title; $title = $w->option_title;
$content = $w->option_content; $content = $w->option_content;
} }
} }
$main['post_widget'] = $main['post_widget'] =
'<div id="post-wtext-form">'. '<div id="post-wtext-form">'.
'<h4>'.__('Additional widget').'</h4>'. '<h4>'.__('Additional widget').'</h4>'.
'<p class="col">'. '<p class="col">'.
'<label class="bold" for="post_wtitle">'.__('Widget title:').'</label>'. '<label class="bold" for="post_wtitle">'.__('Widget title:').'</label>'.
form::field('post_wtitle',20,255,html::escapeHTML($title),'maximal'). form::field('post_wtitle',20,255,html::escapeHTML($title),'maximal').
'</p>'. '</p>'.
'<p class="area" id="post-wtext">'. '<p class="area" id="post-wtext">'.
'<label class="bold" for="post_wtext">'.__('Wigdet text:').'</label>'. '<label class="bold" for="post_wtext">'.__('Wigdet text:').'</label>'.
form::textarea('post_wtext',50,5,html::escapeHTML($content)). form::textarea('post_wtext',50,5,html::escapeHTML($content)).
'</p>'. '</p>'.
'</div>'; '</div>';
} }
public static function save($cur, $post_id) public static function save($cur, $post_id)
{ {
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
# _POST fields # _POST fields
$title = isset($_POST['post_wtitle']) && !empty($_POST['post_wtitle']) ? $title = isset($_POST['post_wtitle']) && !empty($_POST['post_wtitle']) ?
$_POST['post_wtitle'] : ''; $_POST['post_wtitle'] : '';
$content = isset($_POST['post_wtext']) && !empty($_POST['post_wtext']) ? $content = isset($_POST['post_wtext']) && !empty($_POST['post_wtext']) ?
$_POST['post_wtext'] : ''; $_POST['post_wtext'] : '';
# Object # Object
$pwt = new postWidgetText($GLOBALS['core']); $pwt = new postWidgetText($GLOBALS['core']);
# Get existing widget # Get existing widget
$w = $pwt->getWidgets(array('post_id'=>$post_id)); $w = $pwt->getWidgets(array('post_id'=>$post_id));
# If new content is empty, delete old existing widget # If new content is empty, delete old existing widget
if (empty($title) && empty($content) && !$w->isEmpty()) { if (empty($title) && empty($content) && !$w->isEmpty()) {
$pwt->delWidget($w->option_id); $pwt->delWidget($w->option_id);
} }
# If new content is not empty # If new content is not empty
if (!empty($title) || !empty($content)) { if (!empty($title) || !empty($content)) {
$wcur = $pwt->openCursor(); $wcur = $pwt->openCursor();
$wcur->post_id = $post_id; $wcur->post_id = $post_id;
$wcur->option_type = 'postwidgettext'; $wcur->option_type = 'postwidgettext';
$wcur->option_lang = $cur->post_lang; $wcur->option_lang = $cur->post_lang;
$wcur->option_format = $cur->post_format; $wcur->option_format = $cur->post_format;
$wcur->option_title = $title; $wcur->option_title = $title;
$wcur->option_content = $content; $wcur->option_content = $content;
# Create widget # Create widget
if ($w->isEmpty()) { if ($w->isEmpty()) {
$id = $pwt->addWidget($wcur); $id = $pwt->addWidget($wcur);
} }
# Upddate widget # Upddate widget
else { else {
$pwt->updWidget($w->option_id,$wcur); $pwt->updWidget($w->option_id,$wcur);
} }
} }
} }
public static function delete($post_id)
{
$post_id = (integer) $post_id;
# Object public static function delete($post_id)
$pwt = new postWidgetText($GLOBALS['core']); {
$post_id = (integer) $post_id;
# Get existing widget # Object
$w = $pwt->getWidgets(array('post_id'=>$post_id)); $pwt = new postWidgetText($GLOBALS['core']);
# If new content is empty, delete old existing widget # Get existing widget
if (!$w->isEmpty()) { $w = $pwt->getWidgets(array('post_id'=>$post_id));
$pwt->delWidget($w->option_id);
} # If new content is empty, delete old existing widget
} if (!$w->isEmpty()) {
} $pwt->delWidget($w->option_id);
}
}
}

View File

@ -1,20 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
/** /**
@ -24,100 +23,100 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class postWidgetTextBackup class postWidgetTextBackup
{ {
public static function exportSingle(dcCore $core, $exp, $blog_id) public static function exportSingle(dcCore $core, $exp, $blog_id)
{ {
$exp->export('postwidgettext', $exp->export('postwidgettext',
'SELECT option_type, option_content, '. 'SELECT option_type, option_content, '.
'option_content_xhtml, W.post_id '. 'option_content_xhtml, W.post_id '.
'FROM '.$core->prefix.'post_option W '. 'FROM '.$core->prefix.'post_option W '.
'LEFT JOIN '.$core->prefix.'post P '. 'LEFT JOIN '.$core->prefix.'post P '.
'ON P.post_id = W.post_id '. 'ON P.post_id = W.post_id '.
"WHERE P.blog_id = '".$blog_id."' ". "WHERE P.blog_id = '".$blog_id."' ".
"AND W.option_type = 'postwidgettext' " "AND W.option_type = 'postwidgettext' "
); );
} }
public static function exportFull(dcCore $core, $exp) public static function exportFull(dcCore $core, $exp)
{ {
$exp->export('postwidgettext', $exp->export('postwidgettext',
'SELECT option_type, option_content, '. 'SELECT option_type, option_content, '.
'option_content_xhtml, W.post_id '. 'option_content_xhtml, W.post_id '.
'FROM '.$core->prefix.'post_option W '. 'FROM '.$core->prefix.'post_option W '.
'LEFT JOIN '.$core->prefix.'post P '. 'LEFT JOIN '.$core->prefix.'post P '.
'ON P.post_id = W.post_id '. 'ON P.post_id = W.post_id '.
"WHERE W.option_type = 'postwidgettext' " "WHERE W.option_type = 'postwidgettext' "
); );
} }
public static function importInit($bk, dcCore $core) public static function importInit($bk, dcCore $core)
{ {
$bk->cur_postwidgettext = $core->con->openCursor( $bk->cur_postwidgettext = $core->con->openCursor(
$core->prefix.'post_option' $core->prefix.'post_option'
); );
$bk->postwidgettext = new postWidgetText($core); $bk->postwidgettext = new postWidgetText($core);
} }
public static function importSingle($line, $bk, dcCore $core) public static function importSingle($line, $bk, dcCore $core)
{ {
if ($line->__name == 'postwidgettext' if ($line->__name == 'postwidgettext'
&& isset($bk->old_ids['post'][(integer) $line->post_id]) && isset($bk->old_ids['post'][(integer) $line->post_id])
) { ) {
$line->post_id = $bk->old_ids['post'][(integer) $line->post_id]; $line->post_id = $bk->old_ids['post'][(integer) $line->post_id];
$exists = $bk->postwidgettext->getWidgets(array(
'post_id' => $line->post_id)
);
if ($exists->isEmpty()) { $exists = $bk->postwidgettext->getWidgets(array(
$bk->cur_postwidgettext->clean(); 'post_id' => $line->post_id)
);
$bk->cur_postwidgettext->post_id = if ($exists->isEmpty()) {
(integer) $line->post_id; $bk->cur_postwidgettext->clean();
$bk->cur_postwidgettext->option_type =
(string) $line->option_type;
$bk->cur_postwidgettext->option_lang =
(string) $line->option_lang;
$bk->cur_postwidgettext->option_format =
(string) $line->option_format;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content_xhtml =
(string) $line->option_content_xhtml;
$bk->postwidgettext->addWidget( $bk->cur_postwidgettext->post_id =
$bk->cur_postwidgettext (integer) $line->post_id;
); $bk->cur_postwidgettext->option_type =
} (string) $line->option_type;
} $bk->cur_postwidgettext->option_lang =
} (string) $line->option_lang;
$bk->cur_postwidgettext->option_format =
(string) $line->option_format;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content_xhtml =
(string) $line->option_content_xhtml;
public static function importFull($line ,$bk, dcCore $core) $bk->postwidgettext->addWidget(
{ $bk->cur_postwidgettext
if ($line->__name == 'postwidgettext') { );
$exists = $bk->postwidgettext->getWidgets(array( }
'post_id' => $line->post_id) }
); }
if ($exists->isEmpty()) { public static function importFull($line ,$bk, dcCore $core)
$bk->cur_postwidgettext->clean(); {
if ($line->__name == 'postwidgettext') {
$exists = $bk->postwidgettext->getWidgets(array(
'post_id' => $line->post_id)
);
$bk->cur_postwidgettext->post_id = if ($exists->isEmpty()) {
(integer) $line->post_id; $bk->cur_postwidgettext->clean();
$bk->cur_postwidgettext->option_type =
(string) $line->option_type;
$bk->cur_postwidgettext->option_format =
(string) $line->option_format;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content_xhtml =
(string) $line->option_content_xhtml;
$bk->postwidgettext->addWidget( $bk->cur_postwidgettext->post_id =
$bk->cur_postwidgettext (integer) $line->post_id;
); $bk->cur_postwidgettext->option_type =
} (string) $line->option_type;
} $bk->cur_postwidgettext->option_format =
} (string) $line->option_format;
} $bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content =
(string) $line->option_content;
$bk->cur_postwidgettext->option_content_xhtml =
(string) $line->option_content_xhtml;
$bk->postwidgettext->addWidget(
$bk->cur_postwidgettext
);
}
}
}
}

View File

@ -1,20 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
/** /**
@ -24,40 +23,40 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class postWidgetTextDashboard class postWidgetTextDashboard
{ {
/** /**
* Favorites. * Favorites.
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @param arrayObject $favs Array of favorites * @param arrayObject $favs Array of favorites
*/ */
public static function favorites(dcCore $core, $favs) public static function favorites(dcCore $core, $favs)
{ {
$favs->register('postWidgetText', array( $favs->register('postWidgetText', array(
'title' => __('Post widget text'), 'title' => __('Post widget text'),
'url' => 'plugin.php?p=postWidgetText', 'url' => 'plugin.php?p=postWidgetText',
'small-icon' => 'index.php?pf=postWidgetText/icon.png', 'small-icon' => 'index.php?pf=postWidgetText/icon.png',
'large-icon' => 'index.php?pf=postWidgetText/icon-big.png', 'large-icon' => 'index.php?pf=postWidgetText/icon-big.png',
'permissions' => $core->auth->check( 'permissions' => $core->auth->check(
'usage,contentadmin', 'usage,contentadmin',
$core->blog->id $core->blog->id
), ),
'active_cb' => array( 'active_cb' => array(
'postWidgetTextDashboard', 'postWidgetTextDashboard',
'active' 'active'
) )
)); ));
} }
/** /**
* Favorites selection. * Favorites selection.
* *
* @param string $request Requested page * @param string $request Requested page
* @param array $params Requested parameters * @param array $params Requested parameters
*/ */
public static function active($request, $params) public static function active($request, $params)
{ {
return $request == 'plugin.php' return $request == 'plugin.php'
&& isset($params['p']) && isset($params['p'])
&& $params['p'] == 'postWidgetText'; && $params['p'] == 'postWidgetText';
} }
} }

View File

@ -1,20 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
/** /**
@ -24,78 +23,78 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class postWidgetTextList extends adminGenericList class postWidgetTextList extends adminGenericList
{ {
public function display($page, $nb_per_page, $enclose='') public function display($page, $nb_per_page, $enclose='')
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
return '<p><strong>'.__('No widget').'</strong></p>'; return '<p><strong>'.__('No widget').'</strong></p>';
} }
$pager = new dcPager($page, $this->rs_count, $nb_per_page,10); $pager = new dcPager($page, $this->rs_count, $nb_per_page,10);
$pager->html_prev = $this->html_prev; $pager->html_prev = $this->html_prev;
$pager->html_next = $this->html_next; $pager->html_next = $this->html_next;
$pager->var_page = 'page'; $pager->var_page = 'page';
$content = $content =
'<div class="table-outer">'. '<div class="table-outer">'.
'<table class="clear">'. '<table class="clear">'.
'<thead>'. '<thead>'.
'<tr>'. '<tr>'.
'<th colspan="2" class="nowrap">'.__('Post title').'</th>'. '<th colspan="2" class="nowrap">'.__('Post title').'</th>'.
'<th class="nowrap">'.__('Post date').'</th>'. '<th class="nowrap">'.__('Post date').'</th>'.
'<th class="nowrap">'.__('Widget title').'</th>'. '<th class="nowrap">'.__('Widget title').'</th>'.
'<th class="nowrap">'.__('Widget date').'</th>'. '<th class="nowrap">'.__('Widget date').'</th>'.
'<th class="nowrap">'.__('Author').'</th>'. '<th class="nowrap">'.__('Author').'</th>'.
'<th class="nowrap">'.__('Type').'</th>'. '<th class="nowrap">'.__('Type').'</th>'.
'</tr></thead><tbody>'; '</tr></thead><tbody>';
while ($this->rs->fetch()) {
$w_title = html::escapeHTML($this->rs->option_title); while ($this->rs->fetch()) {
if ($w_title == '') {
$w_title = '<em>'.context::global_filter(
$this->rs->option_content, 1, 1, 80, 0, 0
).'</em>';
}
$content .= $w_title = html::escapeHTML($this->rs->option_title);
'<tr class="line'.($this->rs->post_status != 1 ? if ($w_title == '') {
' offline' : '' $w_title = '<em>'.context::global_filter(
).'" id="p'.$this->rs->post_id.'">'. $this->rs->option_content, 1, 1, 80, 0, 0
'<td class="nowrap">'. ).'</em>';
form::checkbox( }
array('widgets[]'),
$this->rs->option_id,
'', '', '',
!$this->rs->isEditable()
).'</td>'.
'<td class="maximal"><a href="'.
$this->core->getPostAdminURL(
$this->rs->post_type,
$this->rs->post_id
).'#post-wtext-form">'.
html::escapeHTML($this->rs->post_title).
'</a></td>'.
'<td class="nowrap">'.dt::dt2str(
__('%Y-%m-%d %H:%M'),
$this->rs->post_dt
).'</td>'.
'<td class="nowrap">'.$w_title.'</td>'.
'<td class="nowrap">'.dt::dt2str(
__('%Y-%m-%d %H:%M'),
$this->rs->option_upddt
).'</td>'.
'<td class="nowrap">'.$this->rs->user_id.'</td>'.
'<td class="nowrap">'.$this->rs->post_type.'</td>'.
'</tr>';
}
$content .=
'</tbody></table></div>';
return $content .=
$pager->getLinks(). '<tr class="line'.($this->rs->post_status != 1 ?
sprintf($enclose, $content). ' offline' : ''
$pager->getLinks(); ).'" id="p'.$this->rs->post_id.'">'.
} '<td class="nowrap">'.
} form::checkbox(
array('widgets[]'),
$this->rs->option_id,
'', '', '',
!$this->rs->isEditable()
).'</td>'.
'<td class="maximal"><a href="'.
$this->core->getPostAdminURL(
$this->rs->post_type,
$this->rs->post_id
).'#post-wtext-form">'.
html::escapeHTML($this->rs->post_title).
'</a></td>'.
'<td class="nowrap">'.dt::dt2str(
__('%Y-%m-%d %H:%M'),
$this->rs->post_dt
).'</td>'.
'<td class="nowrap">'.$w_title.'</td>'.
'<td class="nowrap">'.dt::dt2str(
__('%Y-%m-%d %H:%M'),
$this->rs->option_upddt
).'</td>'.
'<td class="nowrap">'.$this->rs->user_id.'</td>'.
'<td class="nowrap">'.$this->rs->post_type.'</td>'.
'</tr>';
}
$content .=
'</tbody></table></div>';
return
$pager->getLinks().
sprintf($enclose, $content).
$pager->getLinks();
}
}

View File

@ -1,54 +1,52 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
$records = $core->con->select( $records = $core->con->select(
'SELECT W.*, P.post_lang, P.post_format FROM '.$core->prefix.'post_wtext W '. 'SELECT W.*, P.post_lang, P.post_format FROM '.$core->prefix.'post_wtext W '.
'LEFT JOIN '.$core->prefix.'post P ON P.post_id=W.post_id ' 'LEFT JOIN '.$core->prefix.'post P ON P.post_id=W.post_id '
); );
if (!$records->isEmpty()) if (!$records->isEmpty())
{ {
$cur = $core->con->openCursor($core->prefix.'post_option'); $cur = $core->con->openCursor($core->prefix.'post_option');
while ($records->fetch()) while ($records->fetch())
{ {
$core->con->writeLock($core->prefix.'post_option'); $core->con->writeLock($core->prefix.'post_option');
try { try {
$id = $core->con->select( $id = $core->con->select(
'SELECT MAX(option_id) FROM '.$core->prefix.'post_option' 'SELECT MAX(option_id) FROM '.$core->prefix.'post_option'
)->f(0) + 1; )->f(0) + 1;
$cur->clean(); $cur->clean();
$cur->option_creadt = date('Y-m-d H:i:s'); $cur->option_creadt = date('Y-m-d H:i:s');
$cur->option_upddt = date('Y-m-d H:i:s'); $cur->option_upddt = date('Y-m-d H:i:s');
$cur->option_id = $id; $cur->option_id = $id;
$cur->post_id = $records->post_id; $cur->post_id = $records->post_id;
$cur->option_type = $records->wtext_type; $cur->option_type = $records->wtext_type;
$cur->option_lang = $records->post_lang; $cur->option_lang = $records->post_lang;
$cur->option_format = $records->post_format; $cur->option_format = $records->post_format;
$cur->option_title = $records->wtext_title; $cur->option_title = $records->wtext_title;
$cur->option_content = $records->wtext_content; $cur->option_content = $records->wtext_content;
$cur->option_content_xhtml = $records->wtext_content_xhtml; $cur->option_content_xhtml = $records->wtext_content_xhtml;
$cur->insert(); $cur->insert();
$core->con->unlock(); $core->con->unlock();
} }
catch (Exception $e) catch (Exception $e)
{ {
$core->con->unlock(); $core->con->unlock();
throw $e; throw $e;
} }
} }
} }
?>

155
index.php
View File

@ -1,20 +1,19 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /**
# * @brief postWidgetText, a plugin for Dotclear 2
# This file is part of postWidgetText, a plugin for Dotclear 2. *
# * @package Dotclear
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors * @subpackage Plugin
# contact@jcdenis.fr http://jcd.lv *
# * @author Jean-Christian Denis and Contributors
# Licensed under the GPL version 2.0 license. *
# A copy of this license is available in LICENSE file or at * @copyright Jean-Christian Denis
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
# */
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
dcPage::check('usage,contentadmin'); dcPage::check('usage,contentadmin');
@ -23,35 +22,35 @@ $pwt = new postWidgetText($core);
# Delete widgets # Delete widgets
if (!empty($_POST['save']) && !empty($_POST['widgets'])) { if (!empty($_POST['save']) && !empty($_POST['widgets'])) {
try { try {
foreach($_POST['widgets'] as $k => $id) { foreach($_POST['widgets'] as $k => $id) {
$id = (integer) $id; $id = (integer) $id;
$pwt->delWidget($id); $pwt->delWidget($id);
} }
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Posts widgets successfully delete.') __('Posts widgets successfully delete.')
); );
http::redirect( http::redirect(
$p_url $p_url
); );
} }
catch (Exception $e) { catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
# Combos # Combos
$sortby_combo = array( $sortby_combo = array(
__('Post title') => 'post_title', __('Post title') => 'post_title',
__('Post date') => 'post_dt', __('Post date') => 'post_dt',
__('Widget title') => 'option_title', __('Widget title') => 'option_title',
__('Widget date') => 'option_upddt', __('Widget date') => 'option_upddt',
); );
$order_combo = array( $order_combo = array(
__('Descending') => 'desc', __('Descending') => 'desc',
__('Ascending') => 'asc' __('Ascending') => 'asc'
); );
# Filters # Filters
@ -63,55 +62,55 @@ $order = !empty($_GET['order']) ? $_GET['order'] : 'desc';
$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
if ($nb_per_page != $_GET['nb']) { if ($nb_per_page != $_GET['nb']) {
$show_filters = true; $show_filters = true;
} }
$nb_per_page = (integer) $_GET['nb']; $nb_per_page = (integer) $_GET['nb'];
} }
$params['limit'] = array((($page-1)*$nb_per_page), $nb_per_page); $params['limit'] = array((($page-1)*$nb_per_page), $nb_per_page);
if ($sortby !== '' && in_array($sortby,$sortby_combo)) { if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
if ($order !== '' && in_array($order,$order_combo)) { if ($order !== '' && in_array($order,$order_combo)) {
$params['order'] = $sortby.' '.$order; $params['order'] = $sortby.' '.$order;
} }
if ($sortby != 'post_dt' || $order != 'desc') { if ($sortby != 'post_dt' || $order != 'desc') {
$show_filters = true; $show_filters = true;
} }
} }
# Get posts with text widget # Get posts with text widget
try { try {
$posts = $pwt->getWidgets($params); $posts = $pwt->getWidgets($params);
$counter = $pwt->getWidgets($params, true); $counter = $pwt->getWidgets($params, true);
$posts_list = new postWidgetTextList( $posts_list = new postWidgetTextList(
$core, $core,
$posts, $posts,
$counter->f(0) $counter->f(0)
); );
} }
catch (Exception $e) { catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
# Display # Display
echo ' echo '
<html><head><title>'.__('Post widget text').'</title>'. <html><head><title>'.__('Post widget text').'</title>'.
dcPage::jsLoad( dcPage::jsLoad(
'js/filter-controls.js' 'js/filter-controls.js'
). ).
'<script type="text/javascript">'."\n". '<script type="text/javascript">'."\n".
"//<![CDATA["."\n". "//<![CDATA["."\n".
dcPage::jsVar( dcPage::jsVar(
'dotclear.msg.show_filters', 'dotclear.msg.show_filters',
$show_filters ? 'true':'false' $show_filters ? 'true':'false'
)."\n". )."\n".
dcPage::jsVar( dcPage::jsVar(
'dotclear.msg.filter_posts_list', 'dotclear.msg.filter_posts_list',
__('Show filters and display options') __('Show filters and display options')
)."\n". )."\n".
dcPage::jsVar( dcPage::jsVar(
'dotclear.msg.cancel_the_filter', 'dotclear.msg.cancel_the_filter',
__('Cancel filters and display options') __('Cancel filters and display options')
)."\n". )."\n".
"//]]>\n". "//]]>\n".
"</script>\n".' "</script>\n".'
@ -119,10 +118,10 @@ dcPage::jsVar(
<body>'. <body>'.
dcPage::breadcrumb( dcPage::breadcrumb(
array( array(
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Posts widgets') => '' __('Posts widgets') => ''
) )
). ).
dcPage::notices().' dcPage::notices().'
@ -151,20 +150,20 @@ form::hidden(array('p'), 'postWidgetText').'
</form>'. </form>'.
$posts_list->display($page, $nb_per_page, $posts_list->display($page, $nb_per_page,
'<form action="'.$p_url.'" method="post" id="form-periods">'. '<form action="'.$p_url.'" method="post" id="form-periods">'.
'%s'. '%s'.
'<div class="two-cols">'. '<div class="two-cols">'.
'<p class="col checkboxes-helpers"></p>'. '<p class="col checkboxes-helpers"></p>'.
'<p class="col right">'. '<p class="col right">'.
'<input type="submit" name="save" value="'.__('Delete selected widgets').'" /></p>'. '<input type="submit" name="save" value="'.__('Delete selected widgets').'" /></p>'.
form::hidden(array('sortby'), $sortby). form::hidden(array('sortby'), $sortby).
form::hidden(array('order'), $order). form::hidden(array('order'), $order).
form::hidden(array('page'), $page). form::hidden(array('page'), $page).
form::hidden(array('nb'), $nb_per_page). form::hidden(array('nb'), $nb_per_page).
form::hidden(array('p'), 'postWidgetText'). form::hidden(array('p'), 'postWidgetText').
$core->formNonce(). $core->formNonce().
'</div>'. '</div>'.
'</form>' '</form>'
); );
# Footer # Footer
@ -178,4 +177,4 @@ urlencode('plugin.php?p=postWidgetText').'">'.__('Configuration').'</a> -
postWidgetText - '.$core->plugins->moduleInfo('postWidgetText', 'version').'&nbsp; postWidgetText - '.$core->plugins->moduleInfo('postWidgetText', 'version').'&nbsp;
<img alt="'.__('postWidgetText').'" src="index.php?pf=postWidgetText/icon.png" /> <img alt="'.__('postWidgetText').'" src="index.php?pf=postWidgetText/icon.png" />
</p> </p>
</body></html>'; </body></html>';

View File

@ -76,6 +76,4 @@ $GLOBALS['__l10n']['Posts widgets successfully delete.'] = 'Widgets de billets e
$GLOBALS['__l10n']['Posts widgets'] = 'Widgets de billets'; $GLOBALS['__l10n']['Posts widgets'] = 'Widgets de billets';
#index.php:157 #index.php:157
$GLOBALS['__l10n']['Delete selected widgets'] = 'Effacer les widgets texte selectionnés'; $GLOBALS['__l10n']['Delete selected widgets'] = 'Effacer les widgets texte selectionnés';
?>