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,54 +12,53 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
$core->blog->settings->addNamespace('periodical'); $core->blog->settings->addNamespace('periodical');
if ($core->blog->settings->periodical->periodical_active) { if ($core->blog->settings->periodical->periodical_active) {
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('Periodical'), __('Periodical'),
'plugin.php?p=periodical', 'plugin.php?p=periodical',
'index.php?pf=periodical/icon.png', 'index.php?pf=periodical/icon.png',
preg_match( preg_match(
'/plugin.php\?p=periodical(&.*)?$/', '/plugin.php\?p=periodical(&.*)?$/',
$_SERVER['REQUEST_URI'] $_SERVER['REQUEST_URI']
), ),
$core->auth->check('usage,contentadmin', $core->blog->id) $core->auth->check('usage,contentadmin', $core->blog->id)
); );
$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']
); );
/** /**
@ -69,326 +68,310 @@ $core->addBehavior(
*/ */
class adminPeriodical class adminPeriodical
{ {
public static $combo_period = null; public static $combo_period = null;
/** /**
* Favorites. * Favorites.
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @param arrayObject $favs Array of favorites * @param arrayObject $favs Array of favorites
*/ */
public static function 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',
'large-icon' => 'index.php?pf=periodical/icon-big.png', 'large-icon' => 'index.php?pf=periodical/icon-big.png',
'permissions' => $core->auth->check( 'permissions' => $core->auth->check(
'usage,contentadmin', 'usage,contentadmin',
$core->blog->id $core->blog->id
), ),
'active_cb' => array( 'active_cb' => [
'adminPeriodical', 'adminPeriodical',
'adminDashboardFavoritesActive' 'adminDashboardFavoritesActive'
) ]
)); ]);
} }
/** /**
* Favorites selection. * Favorites selection.
* *
* @param string $request Requested page * @param string $request Requested page
* @param array $params Requested parameters * @param array $params Requested parameters
*/ */
public static function adminDashboardFavoritesActive($request, $params) public static function adminDashboardFavoritesActive($request, $params)
{ {
return $request == 'plugin.php' return $request == 'plugin.php'
&& isset($params['p']) && isset($params['p'])
&& $params['p'] == 'periodical'; && $params['p'] == 'periodical';
} }
/** /**
* Add javascript for toggle * Add javascript for toggle
* *
* @return string HTML head * @return string HTML head
*/ */
public static function adminPostHeaders() public static function adminPostHeaders()
{ {
return dcPage::jsLoad('index.php?pf=periodical/js/toggle.js'); return dcPage::jsLoad('index.php?pf=periodical/js/toggle.js');
} }
/** /**
* Delete relation between post and period * Delete relation between post and period
* *
* @param integer $post_id Post id * @param integer $post_id Post id
*/ */
public static function adminBeforePostDelete($post_id) public static function adminBeforePostDelete($post_id)
{ {
self::delPeriod($GLOBALS['core'], $post_id); self::delPeriod($GLOBALS['core'], $post_id);
} }
/** /**
* Add actions to posts page combo * Add actions to posts page combo
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @param dcPostsActionsPage $ap dcPostsActionsPage instance * @param dcPostsActionsPage $ap dcPostsActionsPage instance
*/ */
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;
}
$pa->addAction(
[__('Periodical') => [__('Remove from periodical') => 'periodical_remove']],
['adminPeriodical', 'callbackRemove']
);
}
return null; /**
} * Posts actions callback to remove period
$pa->addAction( *
array( * @param dcCore $core dcCore instance
__('Periodical') => array( * @param dcPostsActionsPage $pa dcPostsActionsPage instance
__('Remove from periodical') => 'periodical_remove' * @param ArrayObject $post _POST actions
) */
), public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
array('adminPeriodical', 'callbackRemove') {
); # No entry
} $posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
}
/** # No right
* Posts actions callback to remove period if (!$core->auth->check('delete,contentadmin', $core->blog->id)) {
* throw new Exception(__('No enough right'));
* @param dcCore $core dcCore instance }
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param ArrayObject $post _POST actions
*/
public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
}
# No right # Remove linked period
if (!$core->auth->check('delete,contentadmin', $core->blog->id)) { foreach($posts_ids as $post_id) {
throw new Exception(__('No enough right')); self::delPeriod($core, $post_id);
} }
# Remove linked period dcPage::addSuccessNotice(__('Posts have been removed from periodical.'));
foreach($posts_ids as $post_id) { $pa->redirect(true);
self::delPeriod($core, $post_id); }
}
dcPage::addSuccessNotice(__('Posts have been removed from periodical.')); /**
$pa->redirect(true); * Posts actions callback to add period
} *
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param ArrayObject $post _POST actions
*/
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
}
/** //todo: check if selected posts is unpublished
* Posts actions callback to add period
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param ArrayObject $post _POST actions
*/
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
}
//todo: check if selected posts is unpublished # Save action
if (!empty($post['periodical'])) {
foreach($posts_ids as $post_id) {
self::delPeriod($core, $post_id);
self::addPeriod($core, $post_id, $post['periodical']);
}
# Save action dcPage::addSuccessNotice(__('Posts have been added to periodical.'));
if (!empty($post['periodical'])) { $pa->redirect(true);
foreach($posts_ids as $post_id) { }
self::delPeriod($core, $post_id);
self::addPeriod($core, $post_id, $post['periodical']);
}
dcPage::addSuccessNotice(__('Posts have been added to periodical.')); # Display form
$pa->redirect(true); else {
} $pa->beginPage(
dcPage::breadcrumb(array(
html::escapeHTML($core->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Add a period to this selection') => ''
))
);
# Display form echo
else { '<form action="' . $pa->getURI() . '" method="post">' .
$pa->beginPage( $pa->getCheckboxes() .
dcPage::breadcrumb(array(
html::escapeHTML($core->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Add a period to this selection') => ''
))
);
echo self::formPeriod($core) .
'<form action="'.$pa->getURI().'" method="post">'.
$pa->getCheckboxes().
self::formPeriod($core). '<p>'.
$core->formNonce() .
$pa->getHiddenFields() .
form::hidden(['action'], 'periodical_add') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';
'<p>'. $pa->endPage();
$core->formNonce(). }
$pa->getHiddenFields(). }
form::hidden(array('action'), 'periodical_add').
'<input type="submit" value="'.__('Save').'" /></p>'.
'</form>';
$pa->endPage(); /**
} * Add form to post sidebar
} *
* @param ArrayObject $main_items Main items
* @param ArrayObject $sidebar_items Sidebar items
* @param record $post Post record or null
*/
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{
global $core;
/** # Get existing linked period
* Add form to post sidebar $period = '';
* if ($post) {
* @param ArrayObject $main_items Main items $per = new periodical($core);
* @param ArrayObject $sidebar_items Sidebar items $rs = $per->getPosts(['post_id' => $post->post_id]);
* @param record $post Post record or null $period = $rs->isEmpty() ? '' : $rs->periodical_id;
*/ }
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{
global $core;
# Get existing linked period # Set linked period form items
$period = ''; $sidebar_items['options-box']['items']['period'] =
if ($post) { self::formPeriod($core, $period);
$per = new periodical($core); }
$rs = $per->getPosts(array('post_id' => $post->post_id));
$period = $rs->isEmpty() ? '' : $rs->periodical_id;
}
# Set linked period form items /**
$sidebar_items['options-box']['items']['period'] = * Save linked period
self::formPeriod($core, $period); *
} * @param cursor $cur Current post cursor
* @param integer $post_id Post id
*/
public static function adminAfterPostSave(cursor $cur, $post_id)
{
global $core;
/** if (!isset($_POST['periodical'])) {
* Save linked period return null;
* }
* @param cursor $cur Current post cursor
* @param integer $post_id Post id
*/
public static function adminAfterPostSave(cursor $cur, $post_id)
{
global $core;
if (!isset($_POST['periodical'])) { # Delete old linked period
self::delPeriod($core, $post_id);
return null; # Add new linked period
} self::addPeriod($core, $post_id, $_POST['periodical']);
}
# Delete old linked period /**
self::delPeriod($core, $post_id); * Posts period form field
*
* @param dcCore $core dcCore instance
* @param string $period Period
* @return string Period form content
*/
protected static function formPeriod(dcCore $core, $period='')
{
$combo = self::comboPeriod($core);
# Add new linked period if (empty($combo)) {
self::addPeriod($core, $post_id, $_POST['periodical']); return null;
} }
/** return
* Posts period form field '<p><label for="periodical">' .
* __('Periodical') . '</label>' .
* @param dcCore $core dcCore instance form::combo('periodical', $combo, $period) .
* @param string $period Period '</p>';
* @return string Period form content }
*/
protected static function formPeriod(dcCore $core, $period='')
{
$combo = self::comboPeriod($core);
if (empty($combo)) { /**
* Combo of available periods
*
* @param dcCore $core dcCore instance
* @return array List of period
*/
protected static function comboPeriod(dcCore $core)
{
if (adminPeriodical::$combo_period === null) {
return null; $per = new periodical($core);
} $periods = $per->getPeriods();
return if ($periods->isEmpty()) {
'<p><label for="periodical">'. adminPeriodical::$combo_period = [];
__('Periodical').'</label>'. } else {
form::combo('periodical', $combo, $period). $combo = ['-' => ''];
'</p>'; while ($periods->fetch()) {
} $combo[html::escapeHTML($periods->periodical_title)] = $periods->periodical_id;
}
}
adminPeriodical::$combo_period = $combo;
}
/** return adminPeriodical::$combo_period;
* Combo of available periods }
*
* @param dcCore $core dcCore instance
* @return array List of period
*/
protected static function comboPeriod(dcCore $core)
{
if (adminPeriodical::$combo_period === null) {
$per = new periodical($core); /**
$periods = $per->getPeriods(); * Remove period from posts.
*
* @param dcCore $core dcCore instance
* @param integer $post_id Post id
*/
protected static function delPeriod(dcCore $core, $post_id)
{
if ($post_id === null) {
return null;
}
if ($periods->isEmpty()) { $post_id = (integer) $post_id;
$per = new periodical($core);
$per->delPost($post_id);
}
adminPeriodical::$combo_period = array(); /**
} * Add period to posts
else { *
$combo = array('-' => ''); * @param dcCore $core dcCore instance
while ($periods->fetch()) { * @param integer $post_id Post id
$combo[html::escapeHTML($periods->periodical_title)] = $periods->periodical_id; * @param array $period Period
} */
} protected static function addPeriod($core, $post_id, $period)
adminPeriodical::$combo_period = $combo; {
} # Not saved
if ($post_id === null || empty($period)) {
return null;
}
return adminPeriodical::$combo_period; # Period object
} $per = new periodical($core);
/** # Get periods
* Remove period from posts. $period = $per->getPeriods(['periodical_id' => $period]);
*
* @param dcCore $core dcCore instance
* @param integer $post_id Post id
*/
protected static function delPeriod(dcCore $core, $post_id)
{
if ($post_id === null) {
return null; # No period
} if ($period->isEmpty()) {
return null;
}
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
$per = new periodical($core);
$per->delPost($post_id);
}
/** # Add relation
* Add period to posts $per->addPost($period->periodical_id, $post_id);
* }
* @param dcCore $core dcCore instance }
* @param integer $post_id Post id
* @param array $period Period
*/
protected static function addPeriod($core, $post_id, $period)
{
# Not saved
if ($post_id === null || empty($period)) {
return null;
}
# Period object
$per = new periodical($core);
# Get periods
$period = $per->getPeriods(array('periodical_id' => $period));
# No period
if ($period->isEmpty()) {
return null;
}
$post_id = (integer) $post_id;
# Add relation
$per->addPost($period->periodical_id, $post_id);
}
}

View File

@ -12,98 +12,94 @@
# -- 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');
$s = $core->blog->settings->periodical; $s = $core->blog->settings->periodical;
$s_active = (boolean) $s->periodical_active; $s_active = (boolean) $s->periodical_active;
$s_upddate = (boolean) $s->periodical_upddate; $s_upddate = (boolean) $s->periodical_upddate;
$s_updurl = (boolean) $s->periodical_updurl; $s_updurl = (boolean) $s->periodical_updurl;
$e_order = (string) $s->periodical_pub_order; $e_order = (string) $s->periodical_pub_order;
$e_order = explode(' ', $e_order); $e_order = explode(' ', $e_order);
$s_sortby = in_array($e_order[0], $sortby_combo) ? $e_order[0] : 'post_dt'; $s_sortby = in_array($e_order[0], $sortby_combo) ? $e_order[0] : 'post_dt';
$s_order = isset($e_order[1]) && strtolower($e_order[1]) == 'desc' ? 'desc' : 'asc'; $s_order = isset($e_order[1]) && strtolower($e_order[1]) == 'desc' ? 'desc' : 'asc';
# -- Set settings -- # -- Set settings --
if (!empty($_POST['save'])) { if (!empty($_POST['save'])) {
try {
$s_active = !empty($_POST['s_active']);
$s_upddate = !empty($_POST['s_upddate']);
$s_updurl = !empty($_POST['s_updurl']);
$s_sortby = $_POST['s_sortby'];
$s_order = $_POST['s_order'];
try { $s->put('periodical_active', $s_active);
$s_active = !empty($_POST['s_active']); $s->put('periodical_upddate', $s_upddate);
$s_upddate = !empty($_POST['s_upddate']); $s->put('periodical_updurl', $s_updurl);
$s_updurl = !empty($_POST['s_updurl']); $s->put('periodical_pub_order', $s_sortby . ' ' . $s_order);
$s_sortby = $_POST['s_sortby'];
$s_order = $_POST['s_order'];
$s->put('periodical_active', $s_active); $core->blog->triggerBlog();
$s->put('periodical_upddate', $s_upddate);
$s->put('periodical_updurl', $s_updurl);
$s->put('periodical_pub_order', $s_sortby.' '.$s_order);
$core->blog->triggerBlog(); dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
dcPage::addSuccessNotice( );
__('Configuration has been successfully updated.') http::redirect($list->getURL(
); 'module=periodical&conf=1&redir=' . $list->getRedir()
http::redirect( ));
$list->getURL('module=periodical&conf=1&redir='. } catch (Exception $e) {
$list->getRedir()) $core->error->add($e->getMessage());
); }
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
} }
# -- Display form -- # -- Display form --
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", 'permissions' => 'usage,contentadmin',
/* Version */ 'type' => 'plugin',
'2013.11.11', 'dc_min' => '2.19',
/* Properies */ 'support' => 'https://github.com/JcDenis/periodical',
array( 'details' => 'https://plugins.dotaddict.org/dc2/details/periodical'
'permissions' => 'usage,contentadmin', ]
'type' => 'plugin', );
'dc_min' => '2.6',
'support' => 'http://jcd.lv/q=periodical',
'details' => 'http://plugins.dotaddict.org/dc2/details/periodical'
)
);

View File

@ -12,64 +12,61 @@
# -- 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;
} }
try { try {
# Check Dotclear version # Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare') if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
throw new Exception(sprintf( throw new Exception(sprintf(
'%s requires Dotclear %s', 'periodical', $dc_min '%s requires Dotclear %s', 'periodical', $dc_min
)); ));
} }
# Tables # Tables
$t = new dbStruct($core->con,$core->prefix); $t = new dbStruct($core->con,$core->prefix);
# Table principale des sondages # Table principale des sondages
$t->periodical $t->periodical
->periodical_id ('bigint', 0, false) ->periodical_id ('bigint', 0, false)
->blog_id('varchar', 32, false) ->blog_id('varchar', 32, false)
->periodical_type ('varchar', 32, false, "'post'") ->periodical_type ('varchar', 32, false, "'post'")
->periodical_title ('varchar', 255, false, "''") ->periodical_title ('varchar', 255, false, "''")
->periodical_tz ('varchar', 128, false, "'UTC'") ->periodical_tz ('varchar', 128, false, "'UTC'")
->periodical_curdt ('timestamp', 0, false,' now()') ->periodical_curdt ('timestamp', 0, false,' now()')
->periodical_enddt ('timestamp', 0, false, 'now()') ->periodical_enddt ('timestamp', 0, false, 'now()')
->periodical_pub_int ('varchar', 32, false, "'day'") ->periodical_pub_int ('varchar', 32, false, "'day'")
->periodical_pub_nb ('smallint', 0, false, 1) ->periodical_pub_nb ('smallint', 0, false, 1)
->primary('pk_periodical', 'periodical_id') ->primary('pk_periodical', 'periodical_id')
->index('idx_periodical_type', 'btree', 'periodical_type'); ->index('idx_periodical_type', 'btree', 'periodical_type');
$ti = new dbStruct($core->con, $core->prefix); $ti = new dbStruct($core->con, $core->prefix);
$changes = $ti->synchronize($t); $changes = $ti->synchronize($t);
# Settings # Settings
$core->blog->settings->addNamespace('periodical'); $core->blog->settings->addNamespace('periodical');
$s = $core->blog->settings->periodical; $s = $core->blog->settings->periodical;
$s->put('periodical_active', false, 'boolean', 'Enable extension', false, true); $s->put('periodical_active', false, 'boolean', 'Enable extension', false, true);
$s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true); $s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true);
$s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true); $s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true);
$s->put('periodical_pub_order', 'post_dt asc', 'string', 'Order of publication', false, true); $s->put('periodical_pub_order', 'post_dt asc', 'string', 'Order of publication', false, true);
# Version # Version
$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());
} }
return false; return false;

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,20 +12,18 @@
# -- 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;
} }
$core->blog->settings->addNamespace('periodical'); $core->blog->settings->addNamespace('periodical');
$core->addBehavior( $core->addBehavior(
'publicBeforeDocument', 'publicBeforeDocument',
array('publicPeriodical', 'publicBeforeDocument') ['publicPeriodical', 'publicBeforeDocument']
); );
/** /**
@ -35,139 +33,138 @@ $core->addBehavior(
*/ */
class publicPeriodical class publicPeriodical
{ {
/** /**
* Publish periodical * Publish periodical
* *
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
*/ */
public static function publicBeforeDocument(dcCore $core) public static function publicBeforeDocument(dcCore $core)
{ {
try { try {
$per = new periodical($core); $per = new periodical($core);
$s = $core->blog->settings->periodical; $s = $core->blog->settings->periodical;
$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()) {
$per->unlockUpdate(); $per->unlockUpdate();
return null; return null;
} }
$now = dt::toUTC(time()); $now = dt::toUTC(time());
$posts_order = $s->periodical_pub_order; $posts_order = $s->periodical_pub_order;
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()) {
# Check if period is ongoing # Check if period is ongoing
$cur_tz = strtotime($periods->periodical_curdt); $cur_tz = strtotime($periods->periodical_curdt);
$end_tz = strtotime($periods->periodical_enddt); $end_tz = strtotime($periods->periodical_enddt);
$now_tz = $now + dt::getTimeOffset($periods->periodical_tz, $now); $now_tz = $now + dt::getTimeOffset($periods->periodical_tz, $now);
if ($now_tz > $cur_tz && $now_tz < $end_tz) { if ($now_tz > $cur_tz && $now_tz < $end_tz) {
$last_nb = 0; $last_nb = 0;
$last_tz = $cur_tz; $last_tz = $cur_tz;
$max_nb = $periods->periodical_pub_nb; $max_nb = $periods->periodical_pub_nb;
$max_tz = $end_tz < $now_tz ? $end_tz : $now_tz; $max_tz = $end_tz < $now_tz ? $end_tz : $now_tz;
# Calculate nb of posts to get # Calculate nb of posts to get
$loop_tz = $cur_tz; $loop_tz = $cur_tz;
$limit = 0; $limit = 0;
try { try {
while(1) { while(1) {
if ($loop_tz > $max_tz) { if ($loop_tz > $max_tz) {
break; break;
} }
$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 ($limit > 0) {
# Get posts to publish related to this period # If period need update
$posts_params = array(); if ($limit > 0) {
$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);
if (!$posts->isEmpty()) { # Get posts to publish related to this period
$cur_post = $core->con->openCursor($core->prefix.'post'); $posts_params = [];
$posts_params['periodical_id'] = $periods->periodical_id;
while($posts->fetch()) { $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([$per, 'getPosts'], $posts_params);
# Publish post with right date if (!$posts->isEmpty()) {
$cur_post->clean(); $cur_post = $core->con->openCursor($core->prefix . 'post');
$cur_post->post_status = 1;
while($posts->fetch()) {
# Update post date with right date # Publish post with right date
if ($s->periodical_upddate) { $cur_post->clean();
$cur_post->post_dt = date('Y-m-d H:i:s', $last_tz); $cur_post->post_status = 1;
$cur_post->post_tz = $periods->periodical_tz;
}
else {
$cur_post->post_dt = $posts->post_dt;
}
# Also update post url with right date # Update post date with right date
if ($s->periodical_updurl) { if ($s->periodical_upddate) {
$cur_post->post_url = $core->blog->getPostURL('', $cur_post->post_dt, $posts->post_title, $posts->post_id); $cur_post->post_dt = date('Y-m-d H:i:s', $last_tz);
} $cur_post->post_tz = $periods->periodical_tz;
} else {
$cur_post->post_dt = $posts->post_dt;
}
$cur_post->update( # Also update post url with right date
'WHERE post_id = '.$posts->post_id.' '. if ($s->periodical_updurl) {
"AND blog_id = '".$core->con->escape($core->blog->id)."' " $cur_post->post_url = $core->blog->getPostURL('', $cur_post->post_dt, $posts->post_title, $posts->post_id);
); }
# Delete post relation to this period $cur_post->update(
$per->delPost($posts->post_id); 'WHERE post_id = ' . $posts->post_id . ' ' .
"AND blog_id = '" . $core->con->escape($core->blog->id) . "' "
);
$last_nb++; # Delete post relation to this period
$per->delPost($posts->post_id);
# Increment upddt if nb of publishing is to the max $last_nb++;
if ($last_nb == $max_nb) {
$last_tz = $per->getNextTime($last_tz, $periods->periodical_pub_int);
$last_nb = 0;
}
# --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry # Increment upddt if nb of publishing is to the max
$core->callBehavior('periodicalAfterPublishedPeriodicalEntry', $core, $posts, $periods); if ($last_nb == $max_nb) {
$last_tz = $per->getNextTime($last_tz, $periods->periodical_pub_int);
$last_nb = 0;
}
} # --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
$core->blog->triggerBlog(); $core->callBehavior('periodicalAfterPublishedPeriodicalEntry', $core, $posts, $periods);
}
}
# Update last published date of this period even if there's no post to publish }
$cur_period->clean(); $core->blog->triggerBlog();
$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)."' "
);
}
}
$per->unlockUpdate();
}
catch (Exception $e) {
$per->unlockUpdate();
return null; # Update last published date of this period even if there's no post to publish
} $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) . "' "
);
}
}
$per->unlockUpdate();
} catch (Exception $e) {
$per->unlockUpdate();
return null;
}
}
}

View File

@ -11,411 +11,410 @@
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')){
return;
}
class periodical class periodical
{ {
public $core; public $core;
public $con; public $con;
protected $table;
protected $blog;
private $lock = null;
public function __construct($core)
{
$this->core = $core;
$this->con = $core->con;
$this->table = $core->con->escape($core->prefix.'periodical');
$this->blog = $core->con->escape($core->blog->id);
}
public function openCursor()
{
return $this->con->openCursor($this->table);
}
# Get periods
public function getPeriods($params=array(),$count_only=false)
{
if ($count_only) {
$q = 'SELECT count(T.periodical_id) ';
}
else
{
$q = 'SELECT T.periodical_id, T.periodical_type, ';
if (!empty($params['columns']) && is_array($params['columns'])) { protected $table;
$q .= implode(', ',$params['columns']).', '; protected $blog;
} private $lock = null;
$q .=
'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 ';
if (!empty($params['from'])) {
$q .= $params['from'].' ';
}
$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']);
}
elseif ($params['periodical_type'] != '') {
$q .= "AND T.periodical_type = '".$this->con->escape($params['periodical_type'])."' ";
}
}
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;}'));
}
else {
$params['periodical_id'] = array((integer) $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'])."' ";
}
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 T.periodical_id ASC ';
}
}
if (!$count_only && !empty($params['limit'])) {
$q .= $this->con->limit($params['limit']);
}
$rs = $this->con->select($q);
$rs->core = $this->core;
$rs->periodical = $this;
return $rs;
}
public function addPeriod($cur)
{
$this->con->writeLock($this->table);
try
{
$id = $this->con->select(
'SELECT MAX(periodical_id) FROM '.$this->table
)->f(0) + 1;
$cur->periodical_id = $id; public function __construct($core)
$cur->blog_id = $this->blog; {
$cur->periodical_type = 'post'; $this->core = $core;
$cur->periodical_tz = $this->core->auth->getInfo('user_tz'); $this->con = $core->con;
$cur->insert();
$this->con->unlock();
}
catch (Exception $e)
{
$this->con->unlock();
throw $e;
}
return $cur->periodical_id;
}
public function updPeriod($period_id,$cur)
{
$period_id = (integer) $period_id;
if ($cur->periodical_tz == ''
&& ($cur->periodical_curdt != '' || $cur->periodical_enddt != '')) {
$cur->periodical_tz = $this->core->auth->getInfo('user_tz');
}
$cur->update(
"WHERE blog_id = '".$this->blog."' ".
"AND periodical_id = ".$period_id." "
);
}
# Delete a period $this->table = $core->con->escape($core->prefix . 'periodical');
public function delPeriod($period_id) $this->blog = $core->con->escape($core->blog->id);
{ }
$period_id = (integer) $period_id;
$params = array();
$params['periodical_id'] = $period_id;
$params['post_status'] = '';
$rs = $this->getPosts($params);
if (!$rs->isEmpty()) { public function openCursor()
throw new Exception('Periodical is not empty'); {
} return $this->con->openCursor($this->table);
}
$this->con->execute(
'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['post_status'] = '';
$params['periodical_id'] = (integer) $period_id;
$rs = $this->getPosts($params);
if ($rs->isEmpty()) return;
$ids = array();
while($rs->fetch())
{
$ids[] = $rs->post_id;
}
if (empty($ids)) return;
$this->con->execute(
'DELETE FROM '.$this->core->prefix.'meta '.
"WHERE meta_type = 'periodical' ".
"AND post_id ".$this->con->in($ids)
);
}
# Get posts related to periods # Get periods
public function getPosts($params=array(),$count_only=false) public function getPeriods($params = [], $count_only = false)
{ {
if (!isset($params['columns'])) $params['columns'] = array(); if ($count_only) {
if (!isset($params['from'])) $params['from'] = ''; $q = 'SELECT count(T.periodical_id) ';
if (!isset($params['sql'])) $params['sql'] = ''; } else {
$q = 'SELECT T.periodical_id, T.periodical_type, ';
$params['columns'][] = 'T.periodical_id';
$params['columns'][] = 'T.periodical_title';
$params['columns'][] = 'T.periodical_type';
$params['columns'][] = 'T.periodical_tz';
$params['columns'][] = 'T.periodical_curdt';
$params['columns'][] = 'T.periodical_enddt';
$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['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;}'));
}
else {
$params['periodical_id'] = array((integer) $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 (isset($params['post_status'])) {
if ($params['post_status'] != '') {
$params['sql'] .= 'AND P.post_status = '.(integer) $params['post_status'].' ';
}
unset($params['post_status']);
}
}
else {
$params['sql'] .= 'AND P.post_status = -2 ';
}
$rs = $this->core->blog->getPosts($params,$count_only);
$rs->periodical = $this;
return $rs;
}
# Add post to periodical
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;
$cur = $this->con->openCursor($this->core->prefix.'meta');
$this->con->writeLock($this->core->prefix.'meta');
try
{
$cur->post_id = $post_id;
$cur->meta_id = $period_id;
$cur->meta_type = 'periodical';
$cur->insert();
$this->con->unlock();
}
catch (Exception $e)
{
$this->con->unlock();
throw $e;
}
}
# Delete post from periodical
public function delPost($post_id)
{
$post_id = (integer) $post_id;
$this->con->execute(
'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 if (!empty($params['columns']) && is_array($params['columns'])) {
public function cleanPosts($period_id=null) $q .= implode(', ', $params['columns']) . ', ';
{ }
$params = array(); $q .=
$params['post_status'] = ''; 'T.periodical_title, T.periodical_tz, ' .
$params['sql'] = 'AND post_status != -2 '; 'T.periodical_curdt, T.periodical_enddt, ' .
if ($period_id !== null) { 'T.periodical_pub_int, T.periodical_pub_nb ';
$params['periodical_id'] = (integer) $period_id; }
}
$rs = $this->getPosts($params);
if ($rs->isEmpty()) return;
$ids = array();
while($rs->fetch())
{
$ids[] = $rs->post_id;
}
if (empty($ids)) return;
$this->con->execute(
'DELETE FROM '.$this->core->prefix.'meta '.
"WHERE meta_type = 'periodical' ".
"AND post_id ".$this->con->in($ids)
);
}
public static function getTimesCombo()
{
return array(
__('Hourly') => 'hour',
__('twice a day') => 'halfday',
__('Daily') => 'day',
__('Weekly') => 'week',
__('Monthly') => 'month'
);
}
public static function getNextTime($ts,$period)
{
$ts = (integer) $ts;
$e = explode(',',date('H,i,s,n,j,Y',$ts));
switch($period)
{
case 'hour':
$new_ts = mktime($e[0] + 1,$e[1],$e[2],$e[3],$e[4],$e[5]);
break;
case 'halfday': $q .= 'FROM ' . $this->table . ' T ';
$new_ts = mktime($e[0],$e[1] + 12,$e[2],$e[3],$e[4],$e[5]);
break;
case 'day': if (!empty($params['from'])) {
$new_ts = mktime($e[0],$e[1],$e[2],$e[3],$e[4] + 1,$e[5]); $q .= $params['from'] . ' ';
break; }
$q .= "WHERE T.blog_id = '" . $this->blog . "' ";
case 'week': if (isset($params['periodical_type'])) {
$new_ts = mktime($e[0],$e[1],$e[2],$e[3],$e[4] + 7,$e[5]); if (is_array($params['periodical_type']) && !empty($params['periodical_type'])) {
break; $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']) . "' ";
}
} 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;}'));
} else {
$params['periodical_id'] = [(integer) $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']) . "' ";
}
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 T.periodical_id ASC ';
}
}
if (!$count_only && !empty($params['limit'])) {
$q .= $this->con->limit($params['limit']);
}
$rs = $this->con->select($q);
$rs->core = $this->core;
$rs->periodical = $this;
case 'month': return $rs;
$new_ts = mktime($e[0],$e[1],$e[2],$e[3] + 1,$e[4],$e[5]); }
break;
default: public function addPeriod($cur)
$new_ts = 0; {
throw new Exception(__('Unknow frequence')); $this->con->writeLock($this->table);
break;
}
return $new_ts;
}
# Lock a file to see if an update is ongoing try {
public function lockUpdate() $id = $this->con->select(
{ 'SELECT MAX(periodical_id) FROM ' . $this->table
try )->f(0) + 1;
{
# Need flock function
if (!function_exists('flock')) {
throw New Exception("Can't call php function named flock");
}
# Cache writable ?
if (!is_writable(DC_TPL_CACHE)) {
throw new Exception("Can't write in cache fodler");
}
# Set file path
$f_md5 = md5($this->blog);
$cached_file = sprintf('%s/%s/%s/%s/%s.txt',
DC_TPL_CACHE,
'periodical',
substr($f_md5,0,2),
substr($f_md5,2,2),
$f_md5
);
# Real path
$cached_file = path::real($cached_file,false);
# Make dir
if (!is_dir(dirname($cached_file))) {
files::makeDir(dirname($cached_file),true); $cur->periodical_id = $id;
} $cur->blog_id = $this->blog;
# Make file $cur->periodical_type = 'post';
if (!file_exists($cached_file)) { $cur->periodical_tz = $this->core->auth->getInfo('user_tz');
!$fp = @fopen($cached_file, 'w'); $cur->insert();
if ($fp === false) { $this->con->unlock();
throw New Exception("Can't create file"); } catch (Exception $e) {
} $this->con->unlock();
fwrite($fp,'1',strlen('1')); throw $e;
fclose($fp); }
} return $cur->periodical_id;
# Open file }
if (!($fp = @fopen($cached_file, 'r+'))) {
throw New Exception("Can't open file");
}
# Lock file
if (!flock($fp,LOCK_EX)) {
throw New Exception("Can't lock file");
}
$this->lock = $fp;
return true;
}
catch (Exception $e)
{
throw $e;
}
return false;
}
public function unlockUpdate() public function updPeriod($period_id,$cur)
{ {
@fclose($this->lock); $period_id = (integer) $period_id;
$this->lock = null;
} if ($cur->periodical_tz == ''
} && ($cur->periodical_curdt != '' || $cur->periodical_enddt != '')) {
?> $cur->periodical_tz = $this->core->auth->getInfo('user_tz');
}
$cur->update(
"WHERE blog_id = '" . $this->blog . "' " .
"AND periodical_id = " . $period_id . " "
);
}
# Delete a period
public function delPeriod($period_id)
{
$period_id = (integer) $period_id;
$params = [];
$params['periodical_id'] = $period_id;
$params['post_status'] = '';
$rs = $this->getPosts($params);
if (!$rs->isEmpty()) {
throw new Exception('Periodical is not empty');
}
$this->con->execute(
'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 = [];
$params['post_status'] = '';
$params['periodical_id'] = (integer) $period_id;
$rs = $this->getPosts($params);
if ($rs->isEmpty()) {
return;
}
$ids = array();
while($rs->fetch())
{
$ids[] = $rs->post_id;
}
if (empty($ids)) [
return;
}
$this->con->execute(
'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 = [], $count_only = false)
{
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';
$params['columns'][] = 'T.periodical_type';
$params['columns'][] = 'T.periodical_tz';
$params['columns'][] = 'T.periodical_curdt';
$params['columns'][] = 'T.periodical_enddt';
$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['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;}'));
} else {
$params['periodical_id'] = [(integer) $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 (isset($params['post_status'])) {
if ($params['post_status'] != '') {
$params['sql'] .= 'AND P.post_status = ' . (integer) $params['post_status'] . ' ';
}
unset($params['post_status']);
}
} else {
$params['sql'] .= 'AND P.post_status = -2 ';
}
$rs = $this->core->blog->getPosts($params, $count_only);
$rs->periodical = $this;
return $rs;
}
# Add post to periodical
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;
}
$cur = $this->con->openCursor($this->core->prefix .'meta');
$this->con->writeLock($this->core->prefix . 'meta');
try {
$cur->post_id = $post_id;
$cur->meta_id = $period_id;
$cur->meta_type = 'periodical';
$cur->insert();
$this->con->unlock();
} catch (Exception $e) {
$this->con->unlock();
throw $e;
}
}
# Delete post from periodical
public function delPost($post_id)
{
$post_id = (integer) $post_id;
$this->con->execute(
'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)
{
$params = [];
$params['post_status'] = '';
$params['sql'] = 'AND post_status != -2 ';
if ($period_id !== null) {
$params['periodical_id'] = (integer) $period_id;
}
$rs = $this->getPosts($params);
if ($rs->isEmpty()) {
return;
}
$ids = array();
while($rs->fetch()) {
$ids[] = $rs->post_id;
}
if (empty($ids)) {
return;
}
$this->con->execute(
'DELETE FROM ' . $this->core->prefix . 'meta ' .
"WHERE meta_type = 'periodical' " .
"AND post_id " . $this->con->in($ids)
);
}
public static function getTimesCombo()
{
return []
__('Hourly') => 'hour',
__('twice a day') => 'halfday',
__('Daily') => 'day',
__('Weekly') => 'week',
__('Monthly') => 'month'
];
}
public static function getNextTime($ts, $period)
{
$ts = (integer) $ts;
$e = explode(',', date('H,i,s,n,j,Y', $ts));
switch($period)
{
case 'hour':
$new_ts = mktime($e[0] + 1,$e[1],$e[2],$e[3],$e[4],$e[5]);
break;
case 'halfday':
$new_ts = mktime($e[0],$e[1] + 12,$e[2],$e[3],$e[4],$e[5]);
break;
case 'day':
$new_ts = mktime($e[0],$e[1],$e[2],$e[3],$e[4] + 1,$e[5]);
break;
case 'week':
$new_ts = mktime($e[0],$e[1],$e[2],$e[3],$e[4] + 7,$e[5]);
break;
case 'month':
$new_ts = mktime($e[0],$e[1],$e[2],$e[3] + 1,$e[4],$e[5]);
break;
default:
$new_ts = 0;
throw new Exception(__('Unknow frequence'));
break;
}
return $new_ts;
}
# Lock a file to see if an update is ongoing
public function lockUpdate()
{
try {
# Need flock function
if (!function_exists('flock')) {
throw New Exception("Can't call php function named flock");
}
# Cache writable ?
if (!is_writable(DC_TPL_CACHE)) {
throw new Exception("Can't write in cache fodler");
}
# Set file path
$f_md5 = md5($this->blog);
$cached_file = sprintf(
'%s/%s/%s/%s/%s.txt',
DC_TPL_CACHE,
'periodical',
substr($f_md5, 0, 2),
substr($f_md5, 2, 2),
$f_md5
);
# Real path
$cached_file = path::real($cached_file, false);
# Make dir
if (!is_dir(dirname($cached_file))) {
files::makeDir(dirname($cached_file), true);
}
# Make file
if (!file_exists($cached_file)) {
!$fp = @fopen($cached_file, 'w');
if ($fp === false) {
throw New Exception("Can't create file");
}
fwrite($fp, '1', strlen('1'));
fclose($fp);
}
# Open file
if (!($fp = @fopen($cached_file, 'r+'))) {
throw New Exception("Can't open file");
}
# Lock file
if (!flock($fp, LOCK_EX)) {
throw New Exception("Can't lock file");
}
$this->lock = $fp;
return true;
} catch (Exception $e) {
throw $e;
}
return false;
}
public function unlockUpdate()
{
@fclose($this->lock);
$this->lock = null;
}
}

View File

@ -12,8 +12,7 @@
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
} }
/** /**
@ -23,194 +22,191 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class adminPeriodicalList extends adminGenericList class adminPeriodicalList extends adminGenericList
{ {
public function periodDisplay($page, $nb_per_page, $enclose_block='') public function periodDisplay($page, $nb_per_page, $enclose_block='')
{ {
$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) {
$html_block = sprintf($enclose_block, $html_block); $html_block = sprintf($enclose_block, $html_block);
} }
$echo .= $pager->getLinks(); $echo .= $pager->getLinks();
$blocks = explode('%s', $html_block); $blocks = explode('%s', $html_block);
$echo .= $blocks[0]; $echo .= $blocks[0];
while ($this->rs->fetch()) { while ($this->rs->fetch()) {
$echo .= $this->periodLine(); $echo .= $this->periodLine();
} }
$echo .= $blocks[1]; $echo .= $blocks[1];
$echo .= $pager->getLinks(); $echo .= $pager->getLinks();
} }
return $echo; return $echo;
} }
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>' .
'</tr>'; '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '</td>' .
'</tr>';
return $res; return $res;
} }
public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='') public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='')
{ {
$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) {
$html_block = sprintf($enclose_block, $html_block); $html_block = sprintf($enclose_block, $html_block);
} }
$echo .= $pager->getLinks(); $echo .= $pager->getLinks();
$blocks = explode('%s', $html_block); $blocks = explode('%s', $html_block);
$echo .= $blocks[0]; $echo .= $blocks[0];
while ($this->rs->fetch()) { while ($this->rs->fetch()) {
$echo .= $this->postLine(); $echo .= $this->postLine();
} }
$echo .= $blocks[1]; $echo .= $blocks[1];
$echo .= $pager->getLinks(); $echo .= $pager->getLinks();
} }
return $echo; return $echo;
} }
private function postLine() private function postLine()
{ {
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'; }
}
if ($this->rs->cat_title) { if ($this->rs->cat_title) {
$cat_title = sprintf( $cat_title = sprintf(
$cat_link, $cat_link,
$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'); }
}
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
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 = '';
$nb_media = $this->rs->countMedia(); $nb_media = $this->rs->countMedia();
if ($nb_media > 0) { if ($nb_media > 0) {
$attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
$attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png'); $attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png');
} }
$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,82 +11,80 @@
# #
# -- 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 }
if (!$core->blog->settings->soCialMeWriter->active) return; # Is active
if (!$core->blog->settings->soCialMeWriter->active) {
# Load services return;
$soCialMeWriter = new soCialMeWriter($core); }
# Load services
# List of service per action $soCialMeWriter = new soCialMeWriter($core);
$actions = $soCialMeWriter->getMarker('action');
# List of service per action
# List of format per type $actions = $soCialMeWriter->getMarker('action');
$formats = $soCialMeWriter->getMarker('format');
# List of format per type
# prepare data $formats = $soCialMeWriter->getMarker('format');
$shortposturl = soCialMeWriter::reduceURL($post->getURL());
$shortposturl = $shortposturl ? $shortposturl : $post->getURL(); # prepare data
$shortposturl = soCialMeWriter::reduceURL($post->getURL());
$shortsiteurl = soCialMeWriter::reduceURL($core->blog->url); $shortposturl = $shortposturl ? $shortposturl : $post->getURL();
$shortsiteurl = $shortsiteurl ? $shortsiteurl : $core->blog->url;
$shortsiteurl = soCialMeWriter::reduceURL($core->blog->url);
# sendMessage $shortsiteurl = $shortsiteurl ? $shortsiteurl : $core->blog->url;
if (!empty($formats[$key]['Message']) && !empty($actions[$key]['Message']))
{ # sendMessage
// parse message if (!empty($formats[$key]['Message']) && !empty($actions[$key]['Message'])) {
$message_txt = str_replace( // parse message
array('%posttitle%','%posturl%','%shortposturl%','%postauthor%','%sitetitle%','%siteurl%','%shortsiteurl%'), $message_txt = str_replace(
array($post->post_title,$post->getURL(),$shortposturl,$post->getUserCN(),$core->blog->name,$core->blog->url,$shortsiteurl), ['%posttitle%', '%posturl%', '%shortposturl%', '%postauthor%', '%sitetitle%', '%siteurl%', '%shortsiteurl%'],
$formats[$key]['Message'] [$post->post_title, $post->getURL(), $shortposturl, $post->getUserCN(), $core->blog->name, $core->blog->url, $shortsiteurl],
); $formats[$key]['Message']
);
// send message
if (!empty($message_txt)) // send message
{ 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) {
{ $soCialMeWriter->play($service_id, 'Link', 'Content', $post->post_title, $shortposturl);
foreach($actions[$key]['Link'] as $service_id) }
{ }
$soCialMeWriter->play($service_id,'Link','Content',$post->post_title,$shortposturl);
} # sendData
} // not yet implemented
# sendData #sendArticle
// not yet implemented // not yet implemented
}
#sendArticle }
// not yet implemented
}
}
?>

1501
index.php

File diff suppressed because it is too large Load Diff

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';