move php code to PSR2 and short array

master
Jean-Christian Paul Denis 2021-08-24 00:52:29 +02:00
parent b47931de50
commit 7ed5a1542c
15 changed files with 1916 additions and 1981 deletions

View File

@ -1,5 +1,6 @@
periodical 2021.08.xx periodical 2021.08.xx
* update license * update license
* update php code to PSR-2 style and short array
periodical 2013.11.11 periodical 2013.11.11
* Switch to Dotclear 2.6 * Switch to Dotclear 2.6

View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -33,33 +32,33 @@ if ($core->blog->settings->periodical->periodical_active) {
$core->addBehavior( $core->addBehavior(
'adminDashboardFavorites', 'adminDashboardFavorites',
array('adminPeriodical', 'adminDashboardFavorites') ['adminPeriodical', 'adminDashboardFavorites']
); );
$core->addBehavior( $core->addBehavior(
'adminPostHeaders', 'adminPostHeaders',
array('adminPeriodical', 'adminPostHeaders') ['adminPeriodical', 'adminPostHeaders']
); );
$core->addBehavior( $core->addBehavior(
'adminPostsActionsPage', 'adminPostsActionsPage',
array('adminPeriodical', 'adminPostsActionsPage') ['adminPeriodical', 'adminPostsActionsPage']
); );
$core->addBehavior( $core->addBehavior(
'adminPostFormItems', 'adminPostFormItems',
array('adminPeriodical', 'adminPostFormItems') ['adminPeriodical', 'adminPostFormItems']
); );
$core->addBehavior( $core->addBehavior(
'adminAfterPostUpdate', 'adminAfterPostUpdate',
array('adminPeriodical', 'adminAfterPostSave') ['adminPeriodical', 'adminAfterPostSave']
); );
$core->addBehavior( $core->addBehavior(
'adminAfterPostCreate', 'adminAfterPostCreate',
array('adminPeriodical', 'adminAfterPostSave') ['adminPeriodical', 'adminAfterPostSave']
); );
} }
$core->addBehavior( $core->addBehavior(
'adminBeforePostDelete', 'adminBeforePostDelete',
array('adminPeriodical', 'adminBeforePostDelete') ['adminPeriodical', 'adminBeforePostDelete']
); );
/** /**
@ -79,7 +78,7 @@ class adminPeriodical
*/ */
public static function adminDashboardFavorites(dcCore $core, $favs) public static function adminDashboardFavorites(dcCore $core, $favs)
{ {
$favs->register('periodical', array( $favs->register('periodical', [
'title' => __('Periodical'), 'title' => __('Periodical'),
'url' => 'plugin.php?p=periodical', 'url' => 'plugin.php?p=periodical',
'small-icon' => 'index.php?pf=periodical/icon.png', 'small-icon' => 'index.php?pf=periodical/icon.png',
@ -88,11 +87,11 @@ class adminPeriodical
'usage,contentadmin', 'usage,contentadmin',
$core->blog->id $core->blog->id
), ),
'active_cb' => array( 'active_cb' => [
'adminPeriodical', 'adminPeriodical',
'adminDashboardFavoritesActive' 'adminDashboardFavoritesActive'
) ]
)); ]);
} }
/** /**
@ -137,25 +136,16 @@ class adminPeriodical
public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa) public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa)
{ {
$pa->addAction( $pa->addAction(
array( [__('Periodical') => [__('Add to periodical') => 'periodical_add']],
__('Periodical') => array( ['adminPeriodical', 'callbackAdd']
__('Add to periodical') => 'periodical_add'
)
),
array('adminPeriodical', 'callbackAdd')
); );
if (!$core->auth->check('delete,contentadmin', $core->blog->id)) { if (!$core->auth->check('delete,contentadmin', $core->blog->id)) {
return null; return null;
} }
$pa->addAction( $pa->addAction(
array( [__('Periodical') => [__('Remove from periodical') => 'periodical_remove']],
__('Periodical') => array( ['adminPeriodical', 'callbackRemove']
__('Remove from periodical') => 'periodical_remove'
)
),
array('adminPeriodical', 'callbackRemove')
); );
} }
@ -227,16 +217,16 @@ class adminPeriodical
); );
echo echo
'<form action="'.$pa->getURI().'" method="post">'. '<form action="' . $pa->getURI() . '" method="post">' .
$pa->getCheckboxes(). $pa->getCheckboxes() .
self::formPeriod($core). self::formPeriod($core) .
'<p>'. '<p>'.
$core->formNonce(). $core->formNonce() .
$pa->getHiddenFields(). $pa->getHiddenFields() .
form::hidden(array('action'), 'periodical_add'). form::hidden(['action'], 'periodical_add') .
'<input type="submit" value="'.__('Save').'" /></p>'. '<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>'; '</form>';
$pa->endPage(); $pa->endPage();
@ -258,7 +248,7 @@ class adminPeriodical
$period = ''; $period = '';
if ($post) { if ($post) {
$per = new periodical($core); $per = new periodical($core);
$rs = $per->getPosts(array('post_id' => $post->post_id)); $rs = $per->getPosts(['post_id' => $post->post_id]);
$period = $rs->isEmpty() ? '' : $rs->periodical_id; $period = $rs->isEmpty() ? '' : $rs->periodical_id;
} }
@ -278,7 +268,6 @@ class adminPeriodical
global $core; global $core;
if (!isset($_POST['periodical'])) { if (!isset($_POST['periodical'])) {
return null; return null;
} }
@ -301,14 +290,13 @@ class adminPeriodical
$combo = self::comboPeriod($core); $combo = self::comboPeriod($core);
if (empty($combo)) { if (empty($combo)) {
return null; return null;
} }
return return
'<p><label for="periodical">'. '<p><label for="periodical">' .
__('Periodical').'</label>'. __('Periodical') . '</label>' .
form::combo('periodical', $combo, $period). form::combo('periodical', $combo, $period) .
'</p>'; '</p>';
} }
@ -326,11 +314,9 @@ class adminPeriodical
$periods = $per->getPeriods(); $periods = $per->getPeriods();
if ($periods->isEmpty()) { if ($periods->isEmpty()) {
adminPeriodical::$combo_period = [];
adminPeriodical::$combo_period = array(); } else {
} $combo = ['-' => ''];
else {
$combo = array('-' => '');
while ($periods->fetch()) { while ($periods->fetch()) {
$combo[html::escapeHTML($periods->periodical_title)] = $periods->periodical_id; $combo[html::escapeHTML($periods->periodical_title)] = $periods->periodical_id;
} }
@ -350,7 +336,6 @@ class adminPeriodical
protected static function delPeriod(dcCore $core, $post_id) protected static function delPeriod(dcCore $core, $post_id)
{ {
if ($post_id === null) { if ($post_id === null) {
return null; return null;
} }
@ -370,7 +355,6 @@ class adminPeriodical
{ {
# Not saved # Not saved
if ($post_id === null || empty($period)) { if ($post_id === null || empty($period)) {
return null; return null;
} }
@ -378,11 +362,10 @@ class adminPeriodical
$per = new periodical($core); $per = new periodical($core);
# Get periods # Get periods
$period = $per->getPeriods(array('periodical_id' => $period)); $period = $per->getPeriods(['periodical_id' => $period]);
# No period # No period
if ($period->isEmpty()) { if ($period->isEmpty()) {
return null; return null;
} }

View File

@ -12,23 +12,22 @@
# -- END LICENSE BLOCK ------------------------------------ # -- 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'];
# -- Combos -- # -- Combos --
$sortby_combo = array( $sortby_combo = [
__('Create date') => 'post_creadt', __('Create date') => 'post_creadt',
__('Date') => 'post_dt', __('Date') => 'post_dt',
__('Id') => 'post_id' __('Id') => 'post_id'
); ];
$order_combo = array( $order_combo = [
__('Descending') => 'desc', __('Descending') => 'desc',
__('Ascending') => 'asc' __('Ascending') => 'asc'
); ];
# -- Get settings -- # -- Get settings --
$core->blog->settings->addNamespace('periodical'); $core->blog->settings->addNamespace('periodical');
@ -44,7 +43,6 @@ $s_order = isset($e_order[1]) && strtolower($e_order[1]) == 'desc' ? 'desc' : '
# -- Set settings -- # -- Set settings --
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try { try {
$s_active = !empty($_POST['s_active']); $s_active = !empty($_POST['s_active']);
$s_upddate = !empty($_POST['s_upddate']); $s_upddate = !empty($_POST['s_upddate']);
@ -55,19 +53,17 @@ if (!empty($_POST['save'])) {
$s->put('periodical_active', $s_active); $s->put('periodical_active', $s_active);
$s->put('periodical_upddate', $s_upddate); $s->put('periodical_upddate', $s_upddate);
$s->put('periodical_updurl', $s_updurl); $s->put('periodical_updurl', $s_updurl);
$s->put('periodical_pub_order', $s_sortby.' '.$s_order); $s->put('periodical_pub_order', $s_sortby . ' ' . $s_order);
$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(
$list->getURL('module=periodical&conf=1&redir='. 'module=periodical&conf=1&redir=' . $list->getRedir()
$list->getRedir()) ));
); } catch (Exception $e) {
}
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -76,34 +72,34 @@ if (!empty($_POST['save'])) {
echo ' echo '
<div class="fieldset"> <div class="fieldset">
<h4>'.__('Activation').'</h4> <h4>' . __('Activation') . '</h4>
<p><label class="classic" for="s_active">'. <p><label class="classic" for="s_active">' .
form::checkbox('s_active', 1, $s_active). form::checkbox('s_active', 1, $s_active) .
__('Enable plugin').'</label></p> __('Enable plugin') . '</label></p>
</div> </div>
<div class="fieldset"> <div class="fieldset">
<h4>'.__('Dates of published entries').'</h4> <h4>' . __('Dates of published entries') . '</h4>
<p><label for="s_upddate">'. <p><label for="s_upddate">' .
form::checkbox('s_upddate', 1, $s_upddate). form::checkbox('s_upddate', 1, $s_upddate) .
__('Update post date').'</label></p> __('Update post date') . '</label></p>
<p><label for="s_updurl">'. <p><label for="s_updurl">' .
form::checkbox('s_updurl', 1, $s_updurl). form::checkbox('s_updurl', 1, $s_updurl) .
__('Update post url').'</label></p> __('Update post url') . '</label></p>
</div> </div>
<div class="fieldset"> <div class="fieldset">
<h4>'.__('Order of publication of entries').'</h4> <h4>' . __('Order of publication of entries') . '</h4>
<p><label for="s_sortby">'.__('Order by:').'</label>'. <p><label for="s_sortby">'.__('Order by:') . '</label>' .
form::combo('s_sortby', $sortby_combo, $s_sortby).'</p> form::combo('s_sortby', $sortby_combo, $s_sortby) . '</p>
<p><label for="s_order">'.__('Sort:').'</label>'. <p><label for="s_order">'.__('Sort:').'</label>' .
form::combo('s_order', $order_combo, $s_order).'</p> form::combo('s_order', $order_combo, $s_order) . '</p>
</div>'; </div>';

View File

@ -11,23 +11,20 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule( $this->registerModule(
/* Name */ 'Periodical',
"Periodical", 'Published periodically entries',
/* Description*/ 'Jean-Christian Denis and contributors',
"Published periodically entries", '2021.08.20',
/* Author */ [
"Jean-Christian Denis",
/* Version */
'2013.11.11',
/* Properies */
array(
'permissions' => 'usage,contentadmin', 'permissions' => 'usage,contentadmin',
'type' => 'plugin', 'type' => 'plugin',
'dc_min' => '2.6', 'dc_min' => '2.19',
'support' => 'http://jcd.lv/q=periodical', 'support' => 'https://github.com/JcDenis/periodical',
'details' => 'http://plugins.dotaddict.org/dc2/details/periodical' 'details' => 'https://plugins.dotaddict.org/dc2/details/periodical'
) ]
); );

View File

@ -12,16 +12,14 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$dc_min = '2.6'; $dc_min = '2.19';
$new_version = $core->plugins->moduleInfo('periodical', 'version'); $new_version = $core->plugins->moduleInfo('periodical', 'version');
$old_version = $core->getVersion('periodical'); $old_version = $core->getVersion('periodical');
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return null; return null;
} }
@ -67,8 +65,7 @@ try {
$core->setVersion('periodical', $new_version); $core->setVersion('periodical', $new_version);
return true; return true;
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }

View File

@ -12,32 +12,30 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
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.18', '<', false)) {
) {
return null; return null;
} }
$d = dirname(__FILE__).'/inc/'; $d = dirname(__FILE__) . '/inc/';
# DB class # DB class
$__autoload['periodical'] = $d.'class.periodical.php'; $__autoload['periodical'] = $d . 'class.periodical.php';
# Admin list and pagers # Admin list and pagers
$__autoload['adminPeriodicalList'] = $d.'lib.index.pager.php'; $__autoload['adminPeriodicalList'] = $d . 'lib.index.pager.php';
# Add to plugn soCialMe (writer part) # Add to plugn soCialMe (writer part)
$__autoload['periodicalSoCialMeWriter'] = $d.'lib.periodical.socialmewriter.php'; $__autoload['periodicalSoCialMeWriter'] = $d . 'lib.periodical.socialmewriter.php';
$core->addBehavior( $core->addBehavior(
'soCialMeWriterMarker', 'soCialMeWriterMarker',
array('periodicalSoCialMeWriter', 'soCialMeWriterMarker') ['periodicalSoCialMeWriter', 'soCialMeWriterMarker']
); );
$core->addBehavior( $core->addBehavior(
'periodicalAfterPublishedPeriodicalEntry', 'periodicalAfterPublishedPeriodicalEntry',
array('periodicalSoCialMeWriter', 'periodicalAfterPublishedPeriodicalEntry') ['periodicalSoCialMeWriter', 'periodicalAfterPublishedPeriodicalEntry']
); );

View File

@ -12,12 +12,10 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
if (!in_array($core->url->type, array('default', 'feed'))) { if (!in_array($core->url->type, ['default', 'feed'])) {
return null; return null;
} }
@ -25,7 +23,7 @@ $core->blog->settings->addNamespace('periodical');
$core->addBehavior( $core->addBehavior(
'publicBeforeDocument', 'publicBeforeDocument',
array('publicPeriodical', 'publicBeforeDocument') ['publicPeriodical', 'publicBeforeDocument']
); );
/** /**
@ -49,7 +47,7 @@ class publicPeriodical
$per->lockUpdate(); $per->lockUpdate();
# Get periods # Get periods
$periods = $core->auth->sudo(array($per, 'getPeriods')); $periods = $core->auth->sudo([$per, 'getPeriods']);
# No period # No period
if ($periods->isEmpty()) { if ($periods->isEmpty()) {
@ -63,7 +61,7 @@ class publicPeriodical
if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) { if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) {
$posts_order = 'post_dt asc'; $posts_order = 'post_dt asc';
} }
$cur_period = $core->con->openCursor($core->prefix.'periodical'); $cur_period = $core->con->openCursor($core->prefix . 'periodical');
while($periods->fetch()) { while($periods->fetch()) {
@ -91,23 +89,24 @@ class publicPeriodical
$loop_tz = $per->getNextTime($loop_tz, $periods->periodical_pub_int); $loop_tz = $per->getNextTime($loop_tz, $periods->periodical_pub_int);
$limit += 1; $limit += 1;
} }
} catch (Exception $e) {
} }
catch (Exception $e) { }
# If period need update # If period need update
if ($limit > 0) { if ($limit > 0) {
# Get posts to publish related to this period # Get posts to publish related to this period
$posts_params = array(); $posts_params = [];
$posts_params['periodical_id'] = $periods->periodical_id; $posts_params['periodical_id'] = $periods->periodical_id;
$posts_params['post_status'] = '-2'; $posts_params['post_status'] = '-2';
$posts_params['order'] = $posts_order; $posts_params['order'] = $posts_order;
$posts_params['limit'] = $limit * $max_nb; $posts_params['limit'] = $limit * $max_nb;
$posts_params['no_content'] = true; $posts_params['no_content'] = true;
$posts = $core->auth->sudo(array($per, 'getPosts'), $posts_params); $posts = $core->auth->sudo([$per, 'getPosts'], $posts_params);
if (!$posts->isEmpty()) { if (!$posts->isEmpty()) {
$cur_post = $core->con->openCursor($core->prefix.'post'); $cur_post = $core->con->openCursor($core->prefix . 'post');
while($posts->fetch()) { while($posts->fetch()) {
@ -119,8 +118,7 @@ class publicPeriodical
if ($s->periodical_upddate) { if ($s->periodical_upddate) {
$cur_post->post_dt = date('Y-m-d H:i:s', $last_tz); $cur_post->post_dt = date('Y-m-d H:i:s', $last_tz);
$cur_post->post_tz = $periods->periodical_tz; $cur_post->post_tz = $periods->periodical_tz;
} } else {
else {
$cur_post->post_dt = $posts->post_dt; $cur_post->post_dt = $posts->post_dt;
} }
@ -130,8 +128,8 @@ class publicPeriodical
} }
$cur_post->update( $cur_post->update(
'WHERE post_id = '.$posts->post_id.' '. 'WHERE post_id = ' . $posts->post_id . ' ' .
"AND blog_id = '".$core->con->escape($core->blog->id)."' " "AND blog_id = '" . $core->con->escape($core->blog->id) . "' "
); );
# Delete post relation to this period # Delete post relation to this period
@ -157,14 +155,13 @@ class publicPeriodical
$cur_period->clean(); $cur_period->clean();
$cur_period->periodical_curdt = date('Y-m-d H:i:s', $loop_tz); $cur_period->periodical_curdt = date('Y-m-d H:i:s', $loop_tz);
$cur_period->update( $cur_period->update(
'WHERE periodical_id = '.$periods->periodical_id.' '. 'WHERE periodical_id = ' . $periods->periodical_id . ' ' .
"AND blog_id = '".$core->con->escape($core->blog->id)."' " "AND blog_id = '" . $core->con->escape($core->blog->id) . "' "
); );
} }
} }
$per->unlockUpdate(); $per->unlockUpdate();
} } catch (Exception $e) {
catch (Exception $e) {
$per->unlockUpdate(); $per->unlockUpdate();
return null; return null;

View File

@ -11,7 +11,9 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')){
return;
}
class periodical class periodical
{ {
@ -27,7 +29,7 @@ class periodical
$this->core = $core; $this->core = $core;
$this->con = $core->con; $this->con = $core->con;
$this->table = $core->con->escape($core->prefix.'periodical'); $this->table = $core->con->escape($core->prefix . 'periodical');
$this->blog = $core->con->escape($core->blog->id); $this->blog = $core->con->escape($core->blog->id);
} }
@ -37,62 +39,56 @@ class periodical
} }
# Get periods # Get periods
public function getPeriods($params=array(),$count_only=false) public function getPeriods($params = [], $count_only = false)
{ {
if ($count_only) { if ($count_only) {
$q = 'SELECT count(T.periodical_id) '; $q = 'SELECT count(T.periodical_id) ';
} } else {
else
{
$q = 'SELECT T.periodical_id, T.periodical_type, '; $q = 'SELECT T.periodical_id, T.periodical_type, ';
if (!empty($params['columns']) && is_array($params['columns'])) { if (!empty($params['columns']) && is_array($params['columns'])) {
$q .= implode(', ',$params['columns']).', '; $q .= implode(', ', $params['columns']) . ', ';
} }
$q .= $q .=
'T.periodical_title, T.periodical_tz, '. 'T.periodical_title, T.periodical_tz, ' .
'T.periodical_curdt, T.periodical_enddt, '. 'T.periodical_curdt, T.periodical_enddt, ' .
'T.periodical_pub_int, T.periodical_pub_nb '; 'T.periodical_pub_int, T.periodical_pub_nb ';
} }
$q .= 'FROM '.$this->table.' T '; $q .= 'FROM ' . $this->table . ' T ';
if (!empty($params['from'])) { if (!empty($params['from'])) {
$q .= $params['from'].' '; $q .= $params['from'] . ' ';
} }
$q .= "WHERE T.blog_id = '".$this->blog."' "; $q .= "WHERE T.blog_id = '" . $this->blog . "' ";
if (isset($params['periodical_type'])) { if (isset($params['periodical_type'])) {
if (is_array($params['periodical_type']) && !empty($params['periodical_type'])) { if (is_array($params['periodical_type']) && !empty($params['periodical_type'])) {
$q .= 'AND T.periodical_type '.$this->con->in($params['periodical_type']); $q .= 'AND T.periodical_type ' . $this->con->in($params['periodical_type']);
} elseif ($params['periodical_type'] != '') {
$q .= "AND T.periodical_type = '" . $this->con->escape($params['periodical_type']) . "' ";
} }
elseif ($params['periodical_type'] != '') { } else {
$q .= "AND T.periodical_type = '".$this->con->escape($params['periodical_type'])."' ";
}
}
else {
$q .= "AND T.periodical_type = 'post' "; $q .= "AND T.periodical_type = 'post' ";
} }
if (!empty($params['periodical_id'])) { if (!empty($params['periodical_id'])) {
if (is_array($params['periodical_id'])) { if (is_array($params['periodical_id'])) {
array_walk($params['periodical_id'],create_function('&$v,$k','if($v!==null){$v=(integer)$v;}')); array_walk($params['periodical_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
} else {
$params['periodical_id'] = [(integer) $params['periodical_id']];
} }
else { $q .= 'AND T.periodical_id ' . $this->con->in($params['periodical_id']);
$params['periodical_id'] = array((integer) $params['periodical_id']);
}
$q .= 'AND T.periodical_id '.$this->con->in($params['periodical_id']);
} }
if (!empty($params['periodical_title'])) { if (!empty($params['periodical_title'])) {
$q .= "AND T.periodical_title = '".$this->con->escape($params['periodical_title'])."' "; $q .= "AND T.periodical_title = '" . $this->con->escape($params['periodical_title']) . "' ";
} }
if (!empty($params['sql'])) { if (!empty($params['sql'])) {
$q .= $params['sql'].' '; $q .= $params['sql'].' ';
} }
if (!$count_only) { if (!$count_only) {
if (!empty($params['order'])) { if (!empty($params['order'])) {
$q .= 'ORDER BY '.$this->con->escape($params['order']).' '; $q .= 'ORDER BY ' . $this->con->escape($params['order']).' ';
} } else {
else {
$q .= 'ORDER BY T.periodical_id ASC '; $q .= 'ORDER BY T.periodical_id ASC ';
} }
} }
@ -110,10 +106,9 @@ class periodical
{ {
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
try try {
{
$id = $this->con->select( $id = $this->con->select(
'SELECT MAX(periodical_id) FROM '.$this->table 'SELECT MAX(periodical_id) FROM ' . $this->table
)->f(0) + 1; )->f(0) + 1;
$cur->periodical_id = $id; $cur->periodical_id = $id;
@ -122,9 +117,7 @@ class periodical
$cur->periodical_tz = $this->core->auth->getInfo('user_tz'); $cur->periodical_tz = $this->core->auth->getInfo('user_tz');
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} } catch (Exception $e) {
catch (Exception $e)
{
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -140,8 +133,8 @@ class periodical
$cur->periodical_tz = $this->core->auth->getInfo('user_tz'); $cur->periodical_tz = $this->core->auth->getInfo('user_tz');
} }
$cur->update( $cur->update(
"WHERE blog_id = '".$this->blog."' ". "WHERE blog_id = '" . $this->blog . "' " .
"AND periodical_id = ".$period_id." " "AND periodical_id = " . $period_id . " "
); );
} }
@ -150,7 +143,7 @@ class periodical
{ {
$period_id = (integer) $period_id; $period_id = (integer) $period_id;
$params = array(); $params = [];
$params['periodical_id'] = $period_id; $params['periodical_id'] = $period_id;
$params['post_status'] = ''; $params['post_status'] = '';
$rs = $this->getPosts($params); $rs = $this->getPosts($params);
@ -160,22 +153,24 @@ class periodical
} }
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->table.' '. 'DELETE FROM ' . $this->table . ' ' .
"WHERE blog_id = '".$this->blog."' ". "WHERE blog_id = '" . $this->blog . "' " .
"AND periodical_id = ".$period_id." " "AND periodical_id = " . $period_id . " "
); );
} }
# Remove all posts related to a period # Remove all posts related to a period
public function delPeriodPosts($period_id) public function delPeriodPosts($period_id)
{ {
$params = array(); $params = [];
$params['post_status'] = ''; $params['post_status'] = '';
$params['periodical_id'] = (integer) $period_id; $params['periodical_id'] = (integer) $period_id;
$rs = $this->getPosts($params); $rs = $this->getPosts($params);
if ($rs->isEmpty()) return; if ($rs->isEmpty()) {
return;
}
$ids = array(); $ids = array();
while($rs->fetch()) while($rs->fetch())
@ -183,21 +178,29 @@ class periodical
$ids[] = $rs->post_id; $ids[] = $rs->post_id;
} }
if (empty($ids)) return; if (empty($ids)) [
return;
}
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->core->prefix.'meta '. 'DELETE FROM ' . $this->core->prefix . 'meta ' .
"WHERE meta_type = 'periodical' ". "WHERE meta_type = 'periodical' " .
"AND post_id ".$this->con->in($ids) "AND post_id " . $this->con->in($ids)
); );
} }
# Get posts related to periods # Get posts related to periods
public function getPosts($params=array(),$count_only=false) public function getPosts($params = [], $count_only = false)
{ {
if (!isset($params['columns'])) $params['columns'] = array(); if (!isset($params['columns'])) {
if (!isset($params['from'])) $params['from'] = ''; $params['columns'] = [];
if (!isset($params['sql'])) $params['sql'] = ''; }
if (!isset($params['from'])) {
$params['from'] = '';
}
if (!isset($params['sql'])) {
$params['sql'] = '';
}
$params['columns'][] = 'T.periodical_id'; $params['columns'][] = 'T.periodical_id';
$params['columns'][] = 'T.periodical_title'; $params['columns'][] = 'T.periodical_title';
@ -208,63 +211,60 @@ class periodical
$params['columns'][] = 'T.periodical_pub_int'; $params['columns'][] = 'T.periodical_pub_int';
$params['columns'][] = 'T.periodical_pub_nb'; $params['columns'][] = 'T.periodical_pub_nb';
$params['from'] .= 'LEFT JOIN '.$this->core->prefix.'meta R ON P.post_id = R.post_id '; $params['from'] .= 'LEFT JOIN ' . $this->core->prefix . 'meta R ON P.post_id = R.post_id ';
$params['from'] .= 'LEFT JOIN '.$this->table.' T ON CAST(T.periodical_id as char)=R.meta_id '; $params['from'] .= 'LEFT JOIN ' . $this->table . ' T ON CAST(T.periodical_id as char)=R.meta_id ';
$params['sql'] .= "AND R.meta_type = 'periodical' "; $params['sql'] .= "AND R.meta_type = 'periodical' ";
$params['sql'] .= "AND T.periodical_type = 'post' "; $params['sql'] .= "AND T.periodical_type = 'post' ";
if (!empty($params['periodical_id'])) { if (!empty($params['periodical_id'])) {
if (is_array($params['periodical_id'])) { if (is_array($params['periodical_id'])) {
array_walk($params['periodical_id'],create_function('&$v,$k','if($v!==null){$v=(integer)$v;}')); array_walk($params['periodical_id'], create_function('&$v,$k', 'if($v!==null){$v=(integer)$v;}'));
} else {
$params['periodical_id'] = [(integer) $params['periodical_id']];
} }
else { $params['sql'] .= 'AND T.periodical_id ' . $this->con->in($params['periodical_id']);
$params['periodical_id'] = array((integer) $params['periodical_id']);
}
$params['sql'] .= 'AND T.periodical_id '.$this->con->in($params['periodical_id']);
unset($params['periodical_id']); unset($params['periodical_id']);
} }
if ($this->core->auth->check('admin',$this->core->blog->id)) { if ($this->core->auth->check('admin', $this->core->blog->id)) {
if (isset($params['post_status'])) { if (isset($params['post_status'])) {
if ($params['post_status'] != '') { if ($params['post_status'] != '') {
$params['sql'] .= 'AND P.post_status = '.(integer) $params['post_status'].' '; $params['sql'] .= 'AND P.post_status = ' . (integer) $params['post_status'] . ' ';
} }
unset($params['post_status']); unset($params['post_status']);
} }
} } else {
else {
$params['sql'] .= 'AND P.post_status = -2 '; $params['sql'] .= 'AND P.post_status = -2 ';
} }
$rs = $this->core->blog->getPosts($params,$count_only); $rs = $this->core->blog->getPosts($params, $count_only);
$rs->periodical = $this; $rs->periodical = $this;
return $rs; return $rs;
} }
# Add post to periodical # Add post to periodical
public function addPost($period_id,$post_id) public function addPost($period_id, $post_id)
{ {
$period_id = (integer) $period_id; $period_id = (integer) $period_id;
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
# Check if exists # Check if exists
$rs = $this->getPosts(array('post_id' => $post_id,'periodical_id' => $period_id)); $rs = $this->getPosts(array('post_id' => $post_id, 'periodical_id' => $period_id));
if (!$rs->isEmpty()) return; if (!$rs->isEmpty()) {
return;
}
$cur = $this->con->openCursor($this->core->prefix.'meta'); $cur = $this->con->openCursor($this->core->prefix .'meta');
$this->con->writeLock($this->core->prefix.'meta'); $this->con->writeLock($this->core->prefix . 'meta');
try try {
{
$cur->post_id = $post_id; $cur->post_id = $post_id;
$cur->meta_id = $period_id; $cur->meta_id = $period_id;
$cur->meta_type = 'periodical'; $cur->meta_type = 'periodical';
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} } catch (Exception $e) {
catch (Exception $e)
{
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -276,17 +276,17 @@ class periodical
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->core->prefix.'meta '. 'DELETE FROM ' . $this->core->prefix . 'meta ' .
"WHERE meta_type = 'periodical' ". "WHERE meta_type = 'periodical' " .
"AND post_id = '".$post_id."' " "AND post_id = '" . $post_id . "' "
); );
return true; return true;
} }
# Remove all posts without pending status from periodical # Remove all posts without pending status from periodical
public function cleanPosts($period_id=null) public function cleanPosts($period_id = null)
{ {
$params = array(); $params = [];
$params['post_status'] = ''; $params['post_status'] = '';
$params['sql'] = 'AND post_status != -2 '; $params['sql'] = 'AND post_status != -2 ';
if ($period_id !== null) { if ($period_id !== null) {
@ -294,38 +294,41 @@ class periodical
} }
$rs = $this->getPosts($params); $rs = $this->getPosts($params);
if ($rs->isEmpty()) return; if ($rs->isEmpty()) {
return;
}
$ids = array(); $ids = array();
while($rs->fetch()) while($rs->fetch()) {
{
$ids[] = $rs->post_id; $ids[] = $rs->post_id;
} }
if (empty($ids)) return; if (empty($ids)) {
return;
}
$this->con->execute( $this->con->execute(
'DELETE FROM '.$this->core->prefix.'meta '. 'DELETE FROM ' . $this->core->prefix . 'meta ' .
"WHERE meta_type = 'periodical' ". "WHERE meta_type = 'periodical' " .
"AND post_id ".$this->con->in($ids) "AND post_id " . $this->con->in($ids)
); );
} }
public static function getTimesCombo() public static function getTimesCombo()
{ {
return array( return []
__('Hourly') => 'hour', __('Hourly') => 'hour',
__('twice a day') => 'halfday', __('twice a day') => 'halfday',
__('Daily') => 'day', __('Daily') => 'day',
__('Weekly') => 'week', __('Weekly') => 'week',
__('Monthly') => 'month' __('Monthly') => 'month'
); ];
} }
public static function getNextTime($ts,$period) public static function getNextTime($ts, $period)
{ {
$ts = (integer) $ts; $ts = (integer) $ts;
$e = explode(',',date('H,i,s,n,j,Y',$ts)); $e = explode(',', date('H,i,s,n,j,Y', $ts));
switch($period) switch($period)
{ {
case 'hour': case 'hour':
@ -359,8 +362,7 @@ class periodical
# Lock a file to see if an update is ongoing # Lock a file to see if an update is ongoing
public function lockUpdate() public function lockUpdate()
{ {
try try {
{
# Need flock function # Need flock function
if (!function_exists('flock')) { if (!function_exists('flock')) {
throw New Exception("Can't call php function named flock"); throw New Exception("Can't call php function named flock");
@ -371,19 +373,19 @@ class periodical
} }
# Set file path # Set file path
$f_md5 = md5($this->blog); $f_md5 = md5($this->blog);
$cached_file = sprintf('%s/%s/%s/%s/%s.txt', $cached_file = sprintf(
'%s/%s/%s/%s/%s.txt',
DC_TPL_CACHE, DC_TPL_CACHE,
'periodical', 'periodical',
substr($f_md5,0,2), substr($f_md5, 0, 2),
substr($f_md5,2,2), substr($f_md5, 2, 2),
$f_md5 $f_md5
); );
# Real path # Real path
$cached_file = path::real($cached_file,false); $cached_file = path::real($cached_file, false);
# Make dir # Make dir
if (!is_dir(dirname($cached_file))) { if (!is_dir(dirname($cached_file))) {
files::makeDir(dirname($cached_file), true);
files::makeDir(dirname($cached_file),true);
} }
# Make file # Make file
if (!file_exists($cached_file)) { if (!file_exists($cached_file)) {
@ -391,7 +393,7 @@ class periodical
if ($fp === false) { if ($fp === false) {
throw New Exception("Can't create file"); throw New Exception("Can't create file");
} }
fwrite($fp,'1',strlen('1')); fwrite($fp, '1', strlen('1'));
fclose($fp); fclose($fp);
} }
# Open file # Open file
@ -399,14 +401,12 @@ class periodical
throw New Exception("Can't open file"); throw New Exception("Can't open file");
} }
# Lock file # Lock file
if (!flock($fp,LOCK_EX)) { if (!flock($fp, LOCK_EX)) {
throw New Exception("Can't lock file"); throw New Exception("Can't lock file");
} }
$this->lock = $fp; $this->lock = $fp;
return true; return true;
} } catch (Exception $e) {
catch (Exception $e)
{
throw $e; throw $e;
} }
return false; return false;
@ -418,4 +418,3 @@ class periodical
$this->lock = null; $this->lock = null;
} }
} }
?>

View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -27,25 +26,24 @@ class adminPeriodicalList extends adminGenericList
{ {
$echo = ''; $echo = '';
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
$echo .= '<p><strong>'.__('No period').'</strong></p>'; $echo .= '<p><strong>' .__('No period') .'</strong></p>';
} } else {
else {
$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';
$html_block = $html_block =
'<div class="table-outer">'. '<div class="table-outer">' .
'<table class="clear">'. '<table class="clear">' .
'<tr>'. '<tr>' .
'<th colspan="2" class="nowrap">'.__('Name').'</th>'. '<th colspan="2" class="nowrap">' . __('Name') . '</th>' .
'<th class="nowrap">'.__('Next update').'</th>'. '<th class="nowrap">' . __('Next update') . '</th>' .
'<th class="nowrap">'.__('Frequency').'</th>'. '<th class="nowrap">' . __('Frequency') . '</th>' .
'<th class="nowrap">'.__('Publications').'</th>'. '<th class="nowrap">' . __('Publications') . '</th>' .
'<th class="nowrap">'.__('Entries').'</th>'. '<th class="nowrap">' . __('Entries') . '</th>' .
'<th class="nowrap">'.__('End date').'</th>'. '<th class="nowrap">' . __('End date') . '</th>' .
'</tr>%s</table>'. '</tr>%s</table>' .
'</div>'; '</div>';
if ($enclose_block) { if ($enclose_block) {
@ -72,25 +70,26 @@ class adminPeriodicalList extends adminGenericList
private function periodLine() private function periodLine()
{ {
$nb_posts = $this->rs->periodical->getPosts(array('periodical_id' => $this->rs->periodical_id), true); $nb_posts = $this->rs->periodical->getPosts(['periodical_id' => $this->rs->periodical_id], true);
$nb_posts = $nb_posts->f(0); $nb_posts = $nb_posts->f(0);
$style = !$nb_posts ? ' offline' : ''; $style = !$nb_posts ? ' offline' : '';
$posts_links = !$nb_posts ? $posts_links = !$nb_posts ?
'0' : '0' :
'<a href="plugin.php?p=periodical&amp;part=period&amp;period_id='.$this->rs->periodical_id.'#posts" title="'.__('view related entries').'">'.$nb_posts.'</a>'; '<a href="plugin.php?p=periodical&amp;part=period&amp;period_id=' . $this->rs->periodical_id . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>';
$pub_int = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ? $pub_int = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ?
__(array_search($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo())) : __('Unknow frequence'); __(array_search($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo())) : __('Unknow frequence');
$res = $res =
'<tr class="line'.$style.'">'. '<tr class="line' . $style . '">' .
'<td class="nowrap">'.form::checkbox(array('periods[]'), $this->rs->periodical_id).'</td>'. '<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->periodical_id) . '</td>' .
'<td class="maximal"><a href="plugin.php?p=periodical&amp;part=period&amp;period_id='.$this->rs->periodical_id.'#period" title="'.__('edit period').'">'.html::escapeHTML($this->rs->periodical_title).'</a></td>'. '<td class="maximal"><a href="plugin.php?p=periodical&amp;part=period&amp;period_id=' . $this->rs->periodical_id . '#period" title="' .
'<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt).'</td>'. __('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a></td>' .
'<td class="nowrap">'.$pub_int.'</td>'. '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '</td>' .
'<td class="nowrap">'.$this->rs->periodical_pub_nb.'</td>'. '<td class="nowrap">' . $pub_int . '</td>' .
'<td class="nowrap">'.$posts_links.'</td>'. '<td class="nowrap">' . $this->rs->periodical_pub_nb .'</td>' .
'<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt).'</td>'. '<td class="nowrap">' . $posts_links . '</td>' .
'<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '</td>' .
'</tr>'; '</tr>';
return $res; return $res;
@ -100,23 +99,22 @@ class adminPeriodicalList extends adminGenericList
{ {
$echo = ''; $echo = '';
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
$echo .= '<p><strong>'.__('No entry').'</strong></p>'; $echo .= '<p><strong>' . __('No entry') . '</strong></p>';
} } else {
else { $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->base_url = $base_url; $pager->base_url = $base_url;
$pager->var_page = 'page'; $pager->var_page = 'page';
$html_block = $html_block =
'<table class="clear"><tr>'. '<table class="clear"><tr>' .
'<th colspan="2">'.__('Title').'</th>'. '<th colspan="2">' . __('Title') . '</th>' .
'<th class="nowrap">'.__('Date').'</th>'. '<th class="nowrap">' . __('Date') . '</th>' .
'<th class="nowrap">'.__('Category').'</th>'. '<th class="nowrap">' . __('Category') . '</th>' .
'<th class="nowrap">'.__('Author').'</th>'. '<th class="nowrap">' . __('Author') . '</th>' .
'<th class="nowrap">'.__('Status').'</th>'. '<th class="nowrap">' . __('Status') . '</th>' .
'<th class="nowrap">'.__('Create date').'</th>'. '<th class="nowrap">' . __('Create date') . '</th>' .
'</tr>%s</table>'; '</tr>%s</table>';
if ($enclose_block) { if ($enclose_block) {
@ -145,8 +143,7 @@ class adminPeriodicalList extends adminGenericList
{ {
if ($this->core->auth->check('categories', $this->core->blog->id)) { if ($this->core->auth->check('categories', $this->core->blog->id)) {
$cat_link = '<a href="category.php?id=%s">%s</a>'; $cat_link = '<a href="category.php?id=%s">%s</a>';
} } else {
else {
$cat_link = '%2$s'; $cat_link = '%2$s';
} }
@ -156,8 +153,7 @@ class adminPeriodicalList extends adminGenericList
$this->rs->cat_id, $this->rs->cat_id,
html::escapeHTML($this->rs->cat_title) html::escapeHTML($this->rs->cat_title)
); );
} } else {
else {
$cat_title = __('None'); $cat_title = __('None');
} }
@ -165,30 +161,30 @@ class adminPeriodicalList extends adminGenericList
switch ($this->rs->post_status) switch ($this->rs->post_status)
{ {
case 1: case 1:
$img_status = sprintf($img,__('published'), 'check-on.png'); $img_status = sprintf($img, __('published'), 'check-on.png');
break; break;
case 0: case 0:
$img_status = sprintf($img,__('unpublished'), 'check-off.png'); $img_status = sprintf($img, __('unpublished'), 'check-off.png');
break; break;
case -1: case -1:
$img_status = sprintf($img,__('scheduled'), 'scheduled.png'); $img_status = sprintf($img, __('scheduled'), 'scheduled.png');
break; break;
case -2: case -2:
$img_status = sprintf($img,__('pending'), 'check-wrn.png'); $img_status = sprintf($img, __('pending'), 'check-wrn.png');
break; break;
} }
$protected = ''; $protected = '';
if ($this->rs->post_password) { if ($this->rs->post_password) {
$protected = sprintf($img,__('protected'), 'locker.png'); $protected = sprintf($img, __('protected'), 'locker.png');
} }
$selected = ''; $selected = '';
if ($this->rs->post_selected) { if ($this->rs->post_selected) {
$selected = sprintf($img,__('selected'), 'selected.png'); $selected = sprintf($img, __('selected'), 'selected.png');
} }
$attach = ''; $attach = '';
@ -199,16 +195,16 @@ class adminPeriodicalList extends adminGenericList
} }
$res = $res =
'<tr class="line">'. '<tr class="line">' .
'<td class="minimal">'.form::checkbox(array('periodical_entries[]'), $this->rs->post_id,0).'</td>'. '<td class="minimal">' . form::checkbox(['periodical_entries[]'], $this->rs->post_id, 0) . '</td>' .
'<td class="maximal"><a href="'.$this->rs->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id).'" '. '<td class="maximal"><a href="' . $this->rs->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '" ' .
'title="'.html::escapeHTML($this->rs->getURL()).'">'. 'title="' . html::escapeHTML($this->rs->getURL()) . '">' .
html::escapeHTML($this->rs->post_title).'</a></td>'. 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">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>' .
'<td class="nowrap">'.$cat_title.'</td>'. '<td class="nowrap">' . $cat_title . '</td>' .
'<td class="nowrap">'.$this->rs->user_id.'</td>'. '<td class="nowrap">' . $this->rs->user_id . '</td>' .
'<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>' .
'<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_creadt, $this->rs->core->auth->getInfo('user_tz')).'</td>'. '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_creadt, $this->rs->core->auth->getInfo('user_tz')) . '</td>' .
'</tr>'; '</tr>';
return $res; return $res;

View File

@ -11,32 +11,36 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')){
return;
}
# Add ability to send social messages when a feed is update # Add ability to send social messages when a feed is update
class periodicalSoCialMeWriter class periodicalSoCialMeWriter
{ {
public static function soCialMeWriterMarker($rs) public static function soCialMeWriterMarker($rs)
{ {
$rs['periodicalcreate'] = array( $rs['periodicalcreate'] = [
'name' => __('New periodical publication'), 'name' => __('New periodical publication'),
'description' => __('When an entry is published on a period'), 'description' => __('When an entry is published on a period'),
'action' => array('Message','Link'), 'action' => ['Message', 'Link'],
'format' => array('Message'), 'format' => ['Message'],
'wildcards' => array('Message' => array('%posttitle%','%posturl%','%shortposturl%','%postauthor%','%sitetitle%','%siteurl%','%shortsiteurl%')) 'wildcards' => ['Message' => ['%posttitle%','%posturl%','%shortposturl%','%postauthor%','%sitetitle%','%siteurl%','%shortsiteurl%']]
); ];
} }
public static function periodicalAfterPublishedPeriodicalEntry($core,$post,$period) public static function periodicalAfterPublishedPeriodicalEntry($core, $post, $period)
{ {
$key = 'periodicalcreate'; $key = 'periodicalcreate';
# Is install # Is install
if (!$core->plugins->moduleExists('soCialMe')) return; if (!$core->plugins->moduleExists('soCialMe')) {
return;
}
# Is active # Is active
if (!$core->blog->settings->soCialMeWriter->active) return; if (!$core->blog->settings->soCialMeWriter->active) {
return;
}
# Load services # Load services
$soCialMeWriter = new soCialMeWriter($core); $soCialMeWriter = new soCialMeWriter($core);
@ -54,31 +58,26 @@ class periodicalSoCialMeWriter
$shortsiteurl = $shortsiteurl ? $shortsiteurl : $core->blog->url; $shortsiteurl = $shortsiteurl ? $shortsiteurl : $core->blog->url;
# sendMessage # sendMessage
if (!empty($formats[$key]['Message']) && !empty($actions[$key]['Message'])) if (!empty($formats[$key]['Message']) && !empty($actions[$key]['Message'])) {
{
// parse message // parse message
$message_txt = str_replace( $message_txt = str_replace(
array('%posttitle%','%posturl%','%shortposturl%','%postauthor%','%sitetitle%','%siteurl%','%shortsiteurl%'), ['%posttitle%', '%posturl%', '%shortposturl%', '%postauthor%', '%sitetitle%', '%siteurl%', '%shortsiteurl%'],
array($post->post_title,$post->getURL(),$shortposturl,$post->getUserCN(),$core->blog->name,$core->blog->url,$shortsiteurl), [$post->post_title, $post->getURL(), $shortposturl, $post->getUserCN(), $core->blog->name, $core->blog->url, $shortsiteurl],
$formats[$key]['Message'] $formats[$key]['Message']
); );
// send message // send message
if (!empty($message_txt)) if (!empty($message_txt)) {
{ foreach($actions[$key]['Message'] as $service_id) {
foreach($actions[$key]['Message'] as $service_id) $soCialMeWriter->play($service_id, 'Message', 'Content', $message_txt);
{
$soCialMeWriter->play($service_id,'Message','Content',$message_txt);
} }
} }
} }
# sendLink # sendLink
if (!empty($actions[$key]['Link'])) if (!empty($actions[$key]['Link'])) {
{ foreach($actions[$key]['Link'] as $service_id) {
foreach($actions[$key]['Link'] as $service_id) $soCialMeWriter->play($service_id, 'Link', 'Content', $post->post_title, $shortposturl);
{
$soCialMeWriter->play($service_id,'Link','Content',$post->post_title,$shortposturl);
} }
} }
@ -89,4 +88,3 @@ class periodicalSoCialMeWriter
// not yet implemented // not yet implemented
} }
} }
?>

485
index.php
View File

@ -12,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
@ -47,14 +46,13 @@ if ($part == 'period') {
# Get period # Get period
if (!empty($_REQUEST['period_id'])) { if (!empty($_REQUEST['period_id'])) {
$rs = $per->getPeriods(array( $rs = $per->getPeriods([
'periodical_id' => $_REQUEST['period_id'] 'periodical_id' => $_REQUEST['period_id']
)); ]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
$core->error->add(__('This period does not exist.')); $core->error->add(__('This period does not exist.'));
$period_id = null; $period_id = null;
} } else {
else {
$period_id = $rs->periodical_id; $period_id = $rs->periodical_id;
$period_title = $rs->periodical_title; $period_title = $rs->periodical_title;
$period_pub_nb = $rs->periodical_pub_nb; $period_pub_nb = $rs->periodical_pub_nb;
@ -77,8 +75,7 @@ if ($part == 'period') {
$period_pub_nb = abs((integer) $_POST['period_pub_nb']); $period_pub_nb = abs((integer) $_POST['period_pub_nb']);
} }
if (!empty($_POST['period_pub_int']) if (!empty($_POST['period_pub_int'])
&& in_array($_POST['period_pub_int'], $per->getTimesCombo()) && in_array($_POST['period_pub_int'], $per->getTimesCombo())) {
) {
$period_pub_int = $_POST['period_pub_int']; $period_pub_int = $_POST['period_pub_int'];
} }
if (!empty($_POST['period_curdt'])) { if (!empty($_POST['period_curdt'])) {
@ -89,9 +86,9 @@ if ($part == 'period') {
} }
# Check period title and dates # Check period title and dates
$old_titles = $per->getPeriods(array( $old_titles = $per->getPeriods([
'periodical_title' => $period_title 'periodical_title' => $period_title
)); ]);
if (!$old_titles->isEmpty()) { if (!$old_titles->isEmpty()) {
while($old_titles->fetch()) { while($old_titles->fetch()) {
if (!$period_id || $old_titles->periodical_id != $period_id) { if (!$period_id || $old_titles->periodical_id != $period_id) {
@ -124,9 +121,8 @@ if ($part == 'period') {
dcPage::addSuccessNotice( dcPage::addSuccessNotice(
__('Period successfully updated.') __('Period successfully updated.')
); );
}
# Create period # Create period
else { } else {
$period_id = $per->addPeriod($cur); $period_id = $per->addPeriod($cur);
@ -136,7 +132,7 @@ if ($part == 'period') {
} }
http::redirect(empty($_POST['redir']) ? http::redirect(empty($_POST['redir']) ?
$p_url.'&part=period&period_id='.$period_id.'#period' : $p_url . '&part=period&period_id=' . $period_id . '#period' :
$_POST['redir'] $_POST['redir']
); );
} }
@ -159,11 +155,10 @@ if ($part == 'period') {
); );
http::redirect(empty($_POST['redir']) ? http::redirect(empty($_POST['redir']) ?
$p_url.'&part=period&period_id='.$period_id.'#posts' : $p_url . '&part=period&period_id=' . $period_id . '#posts' :
$_POST['redir'] $_POST['redir']
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -182,11 +177,10 @@ if ($part == 'period') {
); );
http::redirect(empty($_POST['redir']) ? http::redirect(empty($_POST['redir']) ?
$p_url.'&part=period&period_id='.$period_id.'#posts' : $p_url . '&part=period&period_id=' . $period_id . '#posts' :
$_POST['redir'] $_POST['redir']
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -204,11 +198,10 @@ if ($part == 'period') {
); );
http::redirect(empty($_POST['redir']) ? http::redirect(empty($_POST['redir']) ?
$p_url.'&part=period&period_id='.$period_id.'#posts' : $p_url . '&part=period&period_id=' . $period_id . '#posts' :
$_POST['redir'] $_POST['redir']
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -216,21 +209,19 @@ if ($part == 'period') {
# Prepare combos for posts list # Prepare combos for posts list
if ($period_id) { if ($period_id) {
try { try {
# Getting categories # Getting categories
$categories = $core->blog->getCategories(array('post_type' => 'post')); $categories = $core->blog->getCategories(['post_type' => 'post']);
# Getting authors # Getting authors
$users = $core->blog->getPostsUsers(); $users = $core->blog->getPostsUsers();
# Getting dates # Getting dates
$dates = $core->blog->getDates(array('type' => 'month')); $dates = $core->blog->getDates(['type' => 'month']);
# Getting langs # Getting langs
$langs = $core->blog->getLangs(); $langs = $core->blog->getLangs();
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -240,18 +231,19 @@ if ($part == 'period') {
# Users combo # Users combo
$users_combo = array_merge( $users_combo = array_merge(
array('-' => ''), ['-' => ''],
dcAdminCombos::getUsersCombo($users) dcAdminCombos::getUsersCombo($users)
); );
# Categories combo # Categories combo
$categories_combo = array_merge( $categories_combo = array_merge(
array( [
new formSelectOption('-', ''), new formSelectOption('-', ''),
new formSelectOption(__('(No cat)'), 'NULL')), new formSelectOption(__('(No cat)'), 'NULL')
],
dcAdminCombos::getCategoriesCombo($categories, false) dcAdminCombos::getCategoriesCombo($categories, false)
); );
$categories_values = array(); $categories_values = [];
foreach ($categories_combo as $cat) { foreach ($categories_combo as $cat) {
if (isset($cat->value)) { if (isset($cat->value)) {
$categories_values[$cat->value] = true; $categories_values[$cat->value] = true;
@ -260,38 +252,38 @@ if ($part == 'period') {
# Status combo # Status combo
$status_combo = array_merge( $status_combo = array_merge(
array('-' => ''), ['-' => ''],
dcAdminCombos::getPostStatusesCombo() dcAdminCombos::getPostStatusesCombo()
); );
# Selection combo # Selection combo
$selected_combo = array( $selected_combo = [
'-' => '', '-' => '',
__('Selected') => '1', __('Selected') => '1',
__('Not selected') => '0' __('Not selected') => '0'
); ];
# Attachments combo # Attachments combo
$attachment_combo = array( $attachment_combo = [
'-' => '', '-' => '',
__('With attachments') => '1', __('With attachments') => '1',
__('Without attachments') => '0' __('Without attachments') => '0'
); ];
# Months combo # Months combo
$dt_m_combo = array_merge( $dt_m_combo = array_merge(
array('-' => ''), ['-' => ''],
dcAdminCombos::getDatesCombo($dates) dcAdminCombos::getDatesCombo($dates)
); );
# Langs combo # Langs combo
$lang_combo = array_merge( $lang_combo = array_merge(
array('-' => ''), ['-' => ''],
dcAdminCombos::getLangsCombo($langs, false) dcAdminCombos::getLangsCombo($langs, false)
); );
# Sort_by combo # Sort_by combo
$sortby_combo = array( $sortby_combo = [
__('Date') => 'post_dt', __('Date') => 'post_dt',
__('Title') => 'post_title', __('Title') => 'post_title',
__('Category') => 'cat_title', __('Category') => 'cat_title',
@ -300,13 +292,13 @@ if ($part == 'period') {
__('Selected') => 'post_selected', __('Selected') => 'post_selected',
__('Number of comments') => 'nb_comment', __('Number of comments') => 'nb_comment',
__('Number of trackbacks') => 'nb_trackback' __('Number of trackbacks') => 'nb_trackback'
); ];
# order combo # order combo
$order_combo = array( $order_combo = [
__('Descending') => 'desc', __('Descending') => 'desc',
__('Ascending') => 'asc' __('Ascending') => 'asc'
); ];
# parse filters # parse filters
$user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
@ -331,7 +323,7 @@ if ($part == 'period') {
$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'] = [(($page-1)*$nb_per_page), $nb_per_page];
$params['no_content'] = true; $params['no_content'] = true;
$params['periodical_id'] = $period_id; $params['periodical_id'] = $period_id;
@ -339,8 +331,7 @@ if ($part == 'period') {
if ($user_id !== '' && in_array($user_id, $users_combo)) { if ($user_id !== '' && in_array($user_id, $users_combo)) {
$params['user_id'] = $user_id; $params['user_id'] = $user_id;
$show_filters = true; $show_filters = true;
} } else {
else {
$user_id=''; $user_id='';
} }
@ -348,8 +339,7 @@ if ($part == 'period') {
if ($cat_id !== '' && isset($categories_values[$cat_id])) { if ($cat_id !== '' && isset($categories_values[$cat_id])) {
$params['cat_id'] = $cat_id; $params['cat_id'] = $cat_id;
$show_filters = true; $show_filters = true;
} } else {
else {
$cat_id=''; $cat_id='';
} }
@ -357,8 +347,7 @@ if ($part == 'period') {
if ($status !== '' && in_array($status, $status_combo)) { if ($status !== '' && in_array($status, $status_combo)) {
$params['post_status'] = $status; $params['post_status'] = $status;
$show_filters = true; $show_filters = true;
} } else {
else {
$status=''; $status='';
} }
@ -366,8 +355,7 @@ if ($part == 'period') {
if ($selected !== '' && in_array($selected, $selected_combo)) { if ($selected !== '' && in_array($selected, $selected_combo)) {
$params['post_selected'] = $selected; $params['post_selected'] = $selected;
$show_filters = true; $show_filters = true;
} } else {
else {
$selected=''; $selected='';
} }
@ -376,8 +364,7 @@ if ($part == 'period') {
$params['media'] = $attachment; $params['media'] = $attachment;
$params['link_type'] = 'attachment'; $params['link_type'] = 'attachment';
$show_filters = true; $show_filters = true;
} } else {
else {
$attachment=''; $attachment='';
} }
@ -386,8 +373,7 @@ if ($part == 'period') {
$params['post_month'] = substr($month, 4, 2); $params['post_month'] = substr($month, 4, 2);
$params['post_year'] = substr($month, 0, 4); $params['post_year'] = substr($month, 0, 4);
$show_filters = true; $show_filters = true;
} } else {
else {
$month=''; $month='';
} }
@ -395,8 +381,7 @@ if ($part == 'period') {
if ($lang !== '' && in_array($lang, $lang_combo)) { if ($lang !== '' && in_array($lang, $lang_combo)) {
$params['post_lang'] = $lang; $params['post_lang'] = $lang;
$show_filters = true; $show_filters = true;
} } else {
else {
$lang=''; $lang='';
} }
@ -404,16 +389,14 @@ if ($part == 'period') {
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;
} } else {
else {
$order='desc'; $order='desc';
} }
if ($sortby != 'post_dt' || $order != 'desc') { if ($sortby != 'post_dt' || $order != 'desc') {
$show_filters = true; $show_filters = true;
} }
} } else {
else {
$sortby='post_dt'; $sortby='post_dt';
$order='desc'; $order='desc';
} }
@ -423,87 +406,86 @@ if ($part == 'period') {
$posts = $per->getPosts($params); $posts = $per->getPosts($params);
$counter = $per->getPosts($params, true); $counter = $per->getPosts($params, true);
$post_list = new adminPeriodicalList($core, $posts, $counter->f(0)); $post_list = new adminPeriodicalList($core, $posts, $counter->f(0));
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
$starting_script = $starting_script =
dcPage::jsLoad( dcPage::jsLoad(
'index.php?pf=periodical/js/postsfilter.js' 'index.php?pf=periodical/js/postsfilter.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";
} }
# Display # Display
echo ' echo '
<html><head><title>'.__('Periodical').'</title>'. <html><head><title>' . __('Periodical') . '</title>' .
dcPage::jsLoad('index.php?pf=periodical/js/dates.js'). dcPage::jsLoad('index.php?pf=periodical/js/dates.js') .
$starting_script. $starting_script .
dcPage::jsDatePicker(). dcPage::jsDatePicker() .
dcPage::jsPageTabs(). dcPage::jsPageTabs() .
'</head> '</head>
<body>'; <body>';
echo echo
dcPage::breadcrumb( dcPage::breadcrumb(
array( [
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Periodical') => $p_url.'&amp;part=periods', __('Periodical') => $p_url . '&amp;part=periods',
(null === $period_id ? __('New period') : __('Edit period')) => '' (null === $period_id ? __('New period') : __('Edit period')) => ''
) ]
). ) .
dcPage::notices(); dcPage::notices();
# Period form # Period form
echo ' echo '
<div class="multi-part" title="'. <div class="multi-part" title="' .
(null === $period_id ? __('New period') : __('Edit period')). (null === $period_id ? __('New period') : __('Edit period')) .
'" id="period"> '" id="period">
<form method="post" action="'.$p_url.'"> <form method="post" action="' . $p_url . '">
<p><label for="period_title">'.__('Title:').'</label>'. <p><label for="period_title">' . __('Title:') . '</label>' .
form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal').'</p> form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal') . '</p>
<div class="two-boxes"> <div class="two-boxes">
<p><label for="period_curdt">'.__('Next update:').'</label>'. <p><label for="period_curdt">' . __('Next update:') . '</label>' .
form::field('period_curdt', 16, 16, date('Y-m-d H:i', strtotime($period_curdt))).'</p> form::field('period_curdt', 16, 16, date('Y-m-d H:i', strtotime($period_curdt))) . '</p>
<p><label for="period_enddt">'.__('End date:').'</label>'. <p><label for="period_enddt">' . __('End date:') . '</label>' .
form::field('period_enddt', 16, 16, date('Y-m-d H:i', strtotime($period_enddt))).'</p> form::field('period_enddt', 16, 16, date('Y-m-d H:i', strtotime($period_enddt))) . '</p>
</div><div class="two-boxes"> </div><div class="two-boxes">
<p><label for="period_pub_int">'.__('Publication frequency:').'</label>'. <p><label for="period_pub_int">' . __('Publication frequency:') . '</label>' .
form::combo('period_pub_int',$per->getTimesCombo(),$period_pub_int).'</p> form::combo('period_pub_int',$per->getTimesCombo(), $period_pub_int) . '</p>
<p><label for="period_pub_nb">'.__('Number of entries to publish every time:').'</label>'. <p><label for="period_pub_nb">' . __('Number of entries to publish every time:') . '</label>' .
form::field('period_pub_nb', 10, 3, html::escapeHTML($period_pub_nb)).'</p> form::field('period_pub_nb', 10, 3, html::escapeHTML($period_pub_nb)) . '</p>
</div> </div>
<div class="clear"> <div class="clear">
<p><input type="submit" name="save" value="'.__('Save').'" />'. <p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce(). $core->formNonce() .
form::hidden(array('action'), 'setperiod'). form::hidden(['action'], 'setperiod') .
form::hidden(array('period_id'), $period_id). form::hidden(['period_id'], $period_id) .
form::hidden(array('part'), 'period').' form::hidden(['part'], 'period') .'
</p> </p>
</div> </div>
</form> </form>
@ -517,106 +499,106 @@ if ($part == 'period') {
$combo_action[__('Entries')][__('Unpublish')] = 'unpublish'; $combo_action[__('Entries')][__('Unpublish')] = 'unpublish';
$combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical'; $combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical';
$base_url = $p_url. $base_url = $p_url .
'&amp;period_id='.$period_id. '&amp;period_id=' .$period_id .
'&amp;part=period'. '&amp;part=period' .
'&amp;user_id='.$user_id. '&amp;user_id=' . $user_id .
'&amp;cat_id='.$cat_id. '&amp;cat_id=' . $cat_id .
'&amp;status='.$status. '&amp;status=' . $status .
'&amp;selected='.$selected. '&amp;selected=' . $selected .
'&amp;attachment='.$attachment. '&amp;attachment=' . $attachment .
'&amp;month='.$month. '&amp;month=' . $month .
'&amp;lang='.$lang. '&amp;lang=' . $lang .
'&amp;sortby='.$sortby. '&amp;sortby=' . $sortby .
'&amp;order='.$order. '&amp;order=' . $order .
'&amp;nb='.$nb_per_page. '&amp;nb=' . $nb_per_page .
'&amp;page=%s'. '&amp;page=%s' .
'#posts'; '#posts';
echo ' echo '
<div class="multi-part" title="'. <div class="multi-part" title="' .
__('Entries linked to this period'). __('Entries linked to this period') .
'" id="posts">'; '" id="posts">';
# Filters # Filters
echo echo
'<form action="'.$p_url.'#posts" method="get" id="filters-form">'. '<form action="' . $p_url . '#posts" method="get" id="filters-form">' .
'<h3 class="out-of-screen-if-js">'. '<h3 class="out-of-screen-if-js">' .
__('Cancel filters and display options'). __('Cancel filters and display options') .
'</h3>'. '</h3>' .
'<div class="table">'. '<div class="table">' .
'<div class="cell">'. '<div class="cell">' .
'<h4>'.__('Filters').'</h4>'. '<h4>' . __('Filters') . '</h4>' .
'<p><label for="user_id" class="ib">'.__('Author:').'</label> '. '<p><label for="user_id" class="ib">' . __('Author:') . '</label> ' .
form::combo('user_id',$users_combo,$user_id).'</p>'. form::combo('user_id', $users_combo, $user_id) . '</p>' .
'<p><label for="cat_id" class="ib">'.__('Category:').'</label> '. '<p><label for="cat_id" class="ib">' . __('Category:') . '</label> ' .
form::combo('cat_id',$categories_combo,$cat_id).'</p>'. form::combo('cat_id', $categories_combo, $cat_id) . '</p>' .
'<p><label for="status" class="ib">'.__('Status:').'</label> ' . '<p><label for="status" class="ib">' . __('Status:') . '</label> ' .
form::combo('status',$status_combo,$status).'</p> '. form::combo('status', $status_combo, $status) . '</p> ' .
'</div>' .
'<div class="cell filters-sibling-cell">' .
'<p><label for="selected" class="ib">' . __('Selected:') . '</label> ' .
form::combo('selected', $selected_combo, $selected) .'</p>' .
'<p><label for="attachment" class="ib">' . __('Attachments:') . '</label> ' .
form::combo('attachment', $attachment_combo, $attachment) . '</p>' .
'<p><label for="month" class="ib">' . __('Month:') . '</label> ' .
form::combo('month', $dt_m_combo,$month) . '</p>' .
'<p><label for="lang" class="ib">' . __('Lang:') . '</label> ' .
form::combo('lang', $lang_combo, $lang) . '</p> ' .
'</div>'. '</div>'.
'<div class="cell filters-sibling-cell">'. '<div class="cell filters-options">' .
'<p><label for="selected" class="ib">'.__('Selected:').'</label> '. '<h4>' . __('Display options') . '</h4>' .
form::combo('selected',$selected_combo,$selected).'</p>'. '<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' .
'<p><label for="attachment" class="ib">'.__('Attachments:').'</label> '. form::combo('sortby', $sortby_combo, $sortby) . '</p>' .
form::combo('attachment',$attachment_combo,$attachment).'</p>'. '<p><label for="order" class="ib">' . __('Sort:') . '</label> ' .
'<p><label for="month" class="ib">'.__('Month:').'</label> '. form::combo('order', $order_combo, $order) . '</p>' .
form::combo('month',$dt_m_combo,$month).'</p>'. '<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' .
'<p><label for="lang" class="ib">'.__('Lang:').'</label> '. form::field('nb', 3, 3, $nb_per_page) . ' ' .
form::combo('lang',$lang_combo,$lang).'</p> '. __('entries per page') . '</label></p>' .
'</div>'. '</div>' .
'</div>' .
'<div class="cell filters-options">'. '<p><input type="submit" value="' . __('Apply filters and display options') . '" />' .
'<h4>'.__('Display options').'</h4>'. form::hidden(['p'], 'periodical') .
'<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. form::hidden(['part'], 'period') .
form::combo('sortby',$sortby_combo,$sortby).'</p>'. form::hidden(['period_id'], $period_id) .
'<p><label for="order" class="ib">'.__('Sort:').'</label> '. '<br class="clear" /></p>' . //Opera sucks
form::combo('order',$order_combo,$order).'</p>'.
'<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'.
form::field('nb', 3, 3, $nb_per_page).' '.
__('entries per page').'</label></p>'.
'</div>'.
'</div>'.
'<p><input type="submit" value="'.__('Apply filters and display options').'" />'.
form::hidden(array('p'), 'periodical').
form::hidden(array('part'), 'period').
form::hidden(array('period_id'), $period_id).
'<br class="clear" /></p>'. //Opera sucks
'</form>'; '</form>';
# Posts list # Posts list
echo echo
$post_list->postDisplay($page, $nb_per_page, $base_url, $post_list->postDisplay($page, $nb_per_page, $base_url,
'<form action="'.$p_url.'" method="post" id="form-entries">'. '<form action="' . $p_url . '" method="post" id="form-entries">' .
'%s'. '%s' .
'<div class="two-cols">'. '<div class="two-cols">' .
'<p class="col checkboxes-helpers"></p>'. '<p class="col checkboxes-helpers"></p>' .
'<p class="col right">'.__('Selected entries action:').' '. '<p class="col right">' . __('Selected entries action:') . ' ' .
form::combo('action', $combo_action). form::combo('action', $combo_action) .
'<input type="submit" value="'.__('ok').'" /></p>'. '<input type="submit" value="' . __('ok') . '" /></p>' .
form::hidden(array('period_id'), $period_id). form::hidden(['period_id'], $period_id) .
form::hidden(array('user_id'), $user_id). form::hidden(['user_id'], $user_id) .
form::hidden(array('cat_id'), $cat_id). form::hidden(['cat_id'], $cat_id) .
form::hidden(array('status'), $status). form::hidden(['status'], $status) .
form::hidden(array('selected'), $selected). form::hidden(['selected'], $selected) .
form::hidden(array('attachment'), $attachment). form::hidden(['attachment'], $attachment) .
form::hidden(array('month'), $month). form::hidden(['month'], $month) .
form::hidden(array('lang'), $lang). form::hidden(['lang'], $lang) .
form::hidden(array('sortby'), $sortby). form::hidden(['sortby'], $sortby) .
form::hidden(array('order'), $order). form::hidden(['order'], $order) .
form::hidden(array('page'), $page). form::hidden(['page'], $page) .
form::hidden(array('nb'), $nb_per_page). form::hidden(['nb'], $nb_per_page) .
form::hidden(array('p'), 'periodical'). form::hidden(['p'], 'periodical') .
form::hidden(array('part'), 'period'). form::hidden(['part'], 'period') .
form::hidden(array('redir'), sprintf($base_url, $page)). form::hidden(['redir'], sprintf($base_url, $page)) .
$core->formNonce(). $core->formNonce() .
'</div>'. '</div>' .
'</form>' '</form>'
); );
@ -624,15 +606,13 @@ if ($part == 'period') {
'</div>'; '</div>';
} }
}
############################################################ ############################################################
# #
# All periods # All periods
# #
############################################################ ############################################################
else { } else {
# Delete periods and related posts links # Delete periods and related posts links
if ($action == 'deleteperiods' && !empty($_POST['periods'])) { if ($action == 'deleteperiods' && !empty($_POST['periods'])) {
@ -651,8 +631,7 @@ else {
$p_url.'&part=periods' : $p_url.'&part=periods' :
$_POST['redir'] $_POST['redir']
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -672,25 +651,24 @@ else {
$p_url.'&part=periods' : $p_url.'&part=periods' :
$_POST['redir'] $_POST['redir']
); );
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
# Combos # Combos
$sortby_combo = array( $sortby_combo = [
__('Next update') => 'periodical_curdt', __('Next update') => 'periodical_curdt',
__('End date') => 'periodical_enddt', __('End date') => 'periodical_enddt',
__('Frequence') => 'periodical_pub_int' __('Frequence') => 'periodical_pub_int'
); ];
$order_combo = array( $order_combo = [
__('Descending') => 'desc', __('Descending') => 'desc',
__('Ascending') => 'asc' __('Ascending') => 'asc'
); ];
$combo_action = array(); $combo_action = [];
$combo_action[__('empty periods')] = 'emptyperiods'; $combo_action[__('empty periods')] = 'emptyperiods';
$combo_action[__('delete periods')] = 'deleteperiods'; $combo_action[__('delete periods')] = 'deleteperiods';
@ -710,11 +688,11 @@ else {
$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'] = [(($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 != 'periodical_curdt' || $order != 'desc') { if ($sortby != 'periodical_curdt' || $order != 'desc') {
@ -725,106 +703,105 @@ else {
# Get periods # Get periods
try { try {
$periods = $per->getPeriods($params); $periods = $per->getPeriods($params);
$counter = $per->getPeriods($params,true); $counter = $per->getPeriods($params, true);
$period_list = new adminPeriodicalList($core,$periods,$counter->f(0)); $period_list = new adminPeriodicalList($core, $periods, $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>'.__('Periodical').'</title>'. '<html><head><title>' . __('Periodical') . '</title>' .
dcPage::jsLoad( dcPage::jsLoad(
'index.php?pf=periodical/js/periodsfilter.js' 'index.php?pf=periodical/js/periodsfilter.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" .
'</head>'. '</head>' .
'<body>'. '<body>' .
dcPage::breadcrumb( dcPage::breadcrumb(
array( [
html::escapeHTML($core->blog->name) => '', html::escapeHTML($core->blog->name) => '',
__('Periodical') => '' __('Periodical') => ''
) ]
). ) .
dcPage::notices(). dcPage::notices() .
'<p class="top-add"> '<p class="top-add">
<a class="button add" href="'.$p_url.'&amp;part=period">'.__('New period').'</a> <a class="button add" href="' . $p_url . '&amp;part=period">' . __('New period') . '</a>
</p>'; </p>';
# Filter # Filter
echo echo
'<form action="'.$p_url.'" method="get" id="filters-form">'. '<form action="' . $p_url . '" method="get" id="filters-form">' .
'<h3 class="out-of-screen-if-js">'. '<h3 class="out-of-screen-if-js">' .
__('Show filters and display options'). __('Show filters and display options') .
'</h3>'. '</h3>' .
'<div class="table">'. '<div class="table">' .
'<div class="cell">'. '<div class="cell">' .
'<p><label for="sortby">'.__('Order by:').'</label>'. '<p><label for="sortby">' . __('Order by:') . '</label>' .
form::combo('sortby', $sortby_combo, $sortby).'</p>'. form::combo('sortby', $sortby_combo, $sortby) . '</p>' .
'</div>'. '</div>' .
'<div class="cell">'. '<div class="cell">' .
'<p><label for="order">'.__('Sort:').'</label>'. '<p><label for="order">' . __('Sort:') . '</label>' .
form::combo('order', $order_combo, $order).'</p>'. form::combo('order', $order_combo, $order) . '</p>' .
'</div>'. '</div>' .
'<div class="cell">'. '<div class="cell">' .
'<p><label for="nb">'.__('Results per page :').'</label>'. '<p><label for="nb">' . __('Results per page :') . '</label>' .
form::field('nb', 3, 3, $nb_per_page).'</p>'. form::field('nb', 3, 3, $nb_per_page) . '</p>' .
'</div>'. '</div>' .
'</div>'. '</div>' .
'<p>'. '<p>' .
'<input type="submit" value="'.__('Apply filters and display options').'" />'. '<input type="submit" value="' . __('Apply filters and display options') . '" />' .
form::hidden(array('p'), 'periodical'). form::hidden(['p'], 'periodical') .
form::hidden(array('part'), 'periods'). form::hidden(['part'], 'periods') .
'<br class="clear" />'. //Opera sucks '<br class="clear" />' . //Opera sucks
'</p>'. '</p>' .
'</form>'; '</form>';
# Posts list # Posts list
echo $period_list->periodDisplay($page, $nb_per_page, echo $period_list->periodDisplay($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">'.__('Selected periods action:').' '. '<p class="col right">' . __('Selected periods action:') . ' ' .
form::combo('action', $combo_action). form::combo('action', $combo_action) .
'<input type="submit" value="'.__('ok').'" /></p>'. '<input type="submit" value="' . __('ok') . '" /></p>' .
form::hidden(array('sortby'), $sortby). form::hidden(['sortby'], $sortby) .
form::hidden(array('order'), $order). form::hidden(['order'], $order) .
form::hidden(array('page'), $page). form::hidden(['page'], $page) .
form::hidden(array('nb'), $nb_per_page). form::hidden(['nb'], $nb_per_page) .
form::hidden(array('p'), 'periodical'). form::hidden(['p'], 'periodical') .
form::hidden(array('part'), 'periods'). form::hidden(['part'], 'periods') .
$core->formNonce(). $core->formNonce() .
'</div>'. '</div>' .
'</form>' '</form>'
); );
@ -835,10 +812,10 @@ dcPage::helpBlock('periodical');
# Page footer # Page footer
echo echo
'<hr class="clear"/><p class="right modules"> '<hr class="clear"/><p class="right modules">
<a class="module-config" '. <a class="module-config" ' .
'href="plugins.php?module=periodical&amp;conf=1&amp;redir='. 'href="plugins.php?module=periodical&amp;conf=1&amp;redir=' .
urlencode('plugin.php?p=periodical').'">'.__('Configuration').'</a> - urlencode('plugin.php?p=periodical') . '">' . __('Configuration') . '</a> -
periodical - '.$core->plugins->moduleInfo('periodical', 'version').'&nbsp; periodical - '. $core->plugins->moduleInfo('periodical', 'version') . '&nbsp;
<img alt="'.__('periodical').'" src="index.php?pf=periodical/icon.png" /> <img alt="' . __('periodical') . '" src="index.php?pf=periodical/icon.png" />
</p> </p>
</body></html>'; </body></html>';

View File

@ -10,9 +10,8 @@
<p>If you want some help or contribute to the plugin periodical, follow these links.</p> <p>If you want some help or contribute to the plugin periodical, follow these links.</p>
<ul> <ul>
<li><a href="http://forum.dotclear.org/viewtopic.php?id=42289">Post on Dotclear's forum</a></li> <li><a href="http://forum.dotclear.org/viewtopic.php?id=42289">Post on Dotclear's forum</a></li>
<li><a href="http://lab.dotclear.org/wiki/plugin/periodical">SVN repository</a></li> <li><a href="https://github.com/JcDenis/periodical">Github repository</a></li>
<li><a href="https://bitbucket.org/JcDenis/periodical">HG repository</a></li> <li><a href="https://plugins.dotaddict.org/dc2/details/periodical">Dotaddict repository</a></li>
<li><a href="http://jcd.lv/q=periodical">Post on author's blog</a></li>
</ul> </ul>
</body> </body>

View File

@ -12,8 +12,7 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__resources['help']['periodical'] = dirname(__FILE__).'/help/help.html'; $__resources['help']['periodical'] = dirname(__FILE__) . '/help/help.html';

View File

@ -10,9 +10,8 @@
<p>Si vous souhaitez plus d'aide ou apporter votre contribution à l'extension periodical, voici quelques liens utiles.</p> <p>Si vous souhaitez plus d'aide ou apporter votre contribution à l'extension periodical, voici quelques liens utiles.</p>
<ul> <ul>
<li><a href="http://forum.dotclear.org/viewtopic.php?id=42289">Sujet sur le forum Dotclear</a></li> <li><a href="http://forum.dotclear.org/viewtopic.php?id=42289">Sujet sur le forum Dotclear</a></li>
<li><a href="http://lab.dotclear.org/wiki/plugin/periodical">Dépôt svn</a></li> <li><a href="https://github.com/JcDenis/periodical">Dépôt Github</a></li>
<li><a href="https://bitbucket.org/JcDenis/periodical">Dépôt hg</a></li> <li><a href="https://plugins.dotaddict.org/dc2/details/periodical">Dépôt Dotaddict</a></li>
<li><a href="http://jcd.lv/q=periodical">Billet dédié sur le blog de l'auteur</a></li>
</ul> </ul>
</body> </body>

View File

@ -12,8 +12,7 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__resources['help']['periodical'] = dirname(__FILE__).'/help/help.html'; $__resources['help']['periodical'] = dirname(__FILE__) . '/help/help.html';