move php code to PSR2 and short array

This commit is contained in:
Jean-Christian 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
* update license
* update php code to PSR-2 style and short array
periodical 2013.11.11
* Switch to Dotclear 2.6

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

485
index.php
View file

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

View file

@ -10,9 +10,8 @@
<p>If you want some help or contribute to the plugin periodical, follow these links.</p>
<ul>
<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://bitbucket.org/JcDenis/periodical">HG repository</a></li>
<li><a href="http://jcd.lv/q=periodical">Post on author's blog</a></li>
<li><a href="https://github.com/JcDenis/periodical">Github repository</a></li>
<li><a href="https://plugins.dotaddict.org/dc2/details/periodical">Dotaddict repository</a></li>
</ul>
</body>

View file

@ -12,8 +12,7 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
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>
<ul>
<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://bitbucket.org/JcDenis/periodical">Dépôt hg</a></li>
<li><a href="http://jcd.lv/q=periodical">Billet dédié sur le blog de l'auteur</a></li>
<li><a href="https://github.com/JcDenis/periodical">Dépôt Github</a></li>
<li><a href="https://plugins.dotaddict.org/dc2/details/periodical">Dépôt Dotaddict</a></li>
</ul>
</body>

View file

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