move php code to PSR2 and short array

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

View File

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

View File

@ -12,98 +12,94 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_MODULE')) {
return null;
return null;
}
$redir = empty($_REQUEST['redir']) ?
$list->getURL().'#plugins' : $_REQUEST['redir'];
$list->getURL() . '#plugins' : $_REQUEST['redir'];
# -- Combos --
$sortby_combo = array(
__('Create date') => 'post_creadt',
__('Date') => 'post_dt',
__('Id') => 'post_id'
);
$order_combo = array(
__('Descending') => 'desc',
__('Ascending') => 'asc'
);
$sortby_combo = [
__('Create date') => 'post_creadt',
__('Date') => 'post_dt',
__('Id') => 'post_id'
];
$order_combo = [
__('Descending') => 'desc',
__('Ascending') => 'asc'
];
# -- Get settings --
$core->blog->settings->addNamespace('periodical');
$s = $core->blog->settings->periodical;
$s_active = (boolean) $s->periodical_active;
$s_upddate = (boolean) $s->periodical_upddate;
$s_updurl = (boolean) $s->periodical_updurl;
$e_order = (string) $s->periodical_pub_order;
$e_order = explode(' ', $e_order);
$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_active = (boolean) $s->periodical_active;
$s_upddate = (boolean) $s->periodical_upddate;
$s_updurl = (boolean) $s->periodical_updurl;
$e_order = (string) $s->periodical_pub_order;
$e_order = explode(' ', $e_order);
$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';
# -- Set settings --
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_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'];
$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_active', $s_active);
$s->put('periodical_upddate', $s_upddate);
$s->put('periodical_updurl', $s_updurl);
$s->put('periodical_pub_order', $s_sortby.' '.$s_order);
$core->blog->triggerBlog();
$core->blog->triggerBlog();
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
);
http::redirect(
$list->getURL('module=periodical&conf=1&redir='.
$list->getRedir())
);
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
);
http::redirect($list->getURL(
'module=periodical&conf=1&redir=' . $list->getRedir()
));
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# -- Display form --
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>';
</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(
'permissions' => 'usage,contentadmin',
'type' => 'plugin',
'dc_min' => '2.6',
'support' => 'http://jcd.lv/q=periodical',
'details' => 'http://plugins.dotaddict.org/dc2/details/periodical'
)
);
'Periodical',
'Published periodically entries',
'Jean-Christian Denis and contributors',
'2021.08.20',
[
'permissions' => 'usage,contentadmin',
'type' => 'plugin',
'dc_min' => '2.19',
'support' => 'https://github.com/JcDenis/periodical',
'details' => 'https://plugins.dotaddict.org/dc2/details/periodical'
]
);

View File

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

View File

@ -12,32 +12,30 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
return null;
}
# Check Dotclear version
if (!method_exists('dcUtils', 'versionsCompare')
|| dcUtils::versionsCompare(DC_VERSION, '2.6', '<', false)
) {
return null;
|| 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')
'soCialMeWriterMarker',
['periodicalSoCialMeWriter', 'soCialMeWriterMarker']
);
$core->addBehavior(
'periodicalAfterPublishedPeriodicalEntry',
array('periodicalSoCialMeWriter', 'periodicalAfterPublishedPeriodicalEntry')
);
'periodicalAfterPublishedPeriodicalEntry',
['periodicalSoCialMeWriter', 'periodicalAfterPublishedPeriodicalEntry']
);

View File

@ -12,20 +12,18 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
return null;
}
if (!in_array($core->url->type, array('default', 'feed'))) {
return null;
if (!in_array($core->url->type, ['default', 'feed'])) {
return null;
}
$core->blog->settings->addNamespace('periodical');
$core->addBehavior(
'publicBeforeDocument',
array('publicPeriodical', 'publicBeforeDocument')
'publicBeforeDocument',
['publicPeriodical', 'publicBeforeDocument']
);
/**
@ -35,139 +33,138 @@ $core->addBehavior(
*/
class publicPeriodical
{
/**
* Publish periodical
*
* @param dcCore $core dcCore instance
*/
public static function publicBeforeDocument(dcCore $core)
{
try {
$per = new periodical($core);
$s = $core->blog->settings->periodical;
/**
* Publish periodical
*
* @param dcCore $core dcCore instance
*/
public static function publicBeforeDocument(dcCore $core)
{
try {
$per = new periodical($core);
$s = $core->blog->settings->periodical;
$per->lockUpdate();
$per->lockUpdate();
# Get periods
$periods = $core->auth->sudo(array($per, 'getPeriods'));
# Get periods
$periods = $core->auth->sudo([$per, 'getPeriods']);
# No period
if ($periods->isEmpty()) {
$per->unlockUpdate();
# No period
if ($periods->isEmpty()) {
$per->unlockUpdate();
return null;
}
return null;
}
$now = dt::toUTC(time());
$posts_order = $s->periodical_pub_order;
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');
$now = dt::toUTC(time());
$posts_order = $s->periodical_pub_order;
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');
while($periods->fetch()) {
while($periods->fetch()) {
# Check if period is ongoing
$cur_tz = strtotime($periods->periodical_curdt);
$end_tz = strtotime($periods->periodical_enddt);
$now_tz = $now + dt::getTimeOffset($periods->periodical_tz, $now);
# Check if period is ongoing
$cur_tz = strtotime($periods->periodical_curdt);
$end_tz = strtotime($periods->periodical_enddt);
$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_tz = $cur_tz;
$max_nb = $periods->periodical_pub_nb;
$max_tz = $end_tz < $now_tz ? $end_tz : $now_tz;
# Calculate nb of posts to get
$loop_tz = $cur_tz;
$limit = 0;
try {
while(1) {
if ($loop_tz > $max_tz) {
break;
}
$loop_tz = $per->getNextTime($loop_tz, $periods->periodical_pub_int);
$limit += 1;
}
}
catch (Exception $e) { }
$last_nb = 0;
$last_tz = $cur_tz;
$max_nb = $periods->periodical_pub_nb;
$max_tz = $end_tz < $now_tz ? $end_tz : $now_tz;
# Calculate nb of posts to get
$loop_tz = $cur_tz;
$limit = 0;
try {
while(1) {
if ($loop_tz > $max_tz) {
break;
}
$loop_tz = $per->getNextTime($loop_tz, $periods->periodical_pub_int);
$limit += 1;
}
} catch (Exception $e) {
# If period need update
if ($limit > 0) {
}
# Get posts to publish related to this period
$posts_params = array();
$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 period need update
if ($limit > 0) {
if (!$posts->isEmpty()) {
$cur_post = $core->con->openCursor($core->prefix.'post');
while($posts->fetch()) {
# Get posts to publish related to this period
$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([$per, 'getPosts'], $posts_params);
# Publish post with right date
$cur_post->clean();
$cur_post->post_status = 1;
if (!$posts->isEmpty()) {
$cur_post = $core->con->openCursor($core->prefix . 'post');
while($posts->fetch()) {
# Update post date with right date
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 {
$cur_post->post_dt = $posts->post_dt;
}
# Publish post with right date
$cur_post->clean();
$cur_post->post_status = 1;
# Also update post url with right date
if ($s->periodical_updurl) {
$cur_post->post_url = $core->blog->getPostURL('', $cur_post->post_dt, $posts->post_title, $posts->post_id);
}
# Update post date with right date
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 {
$cur_post->post_dt = $posts->post_dt;
}
$cur_post->update(
'WHERE post_id = '.$posts->post_id.' '.
"AND blog_id = '".$core->con->escape($core->blog->id)."' "
);
# Also update post url with right date
if ($s->periodical_updurl) {
$cur_post->post_url = $core->blog->getPostURL('', $cur_post->post_dt, $posts->post_title, $posts->post_id);
}
# Delete post relation to this period
$per->delPost($posts->post_id);
$cur_post->update(
'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
if ($last_nb == $max_nb) {
$last_tz = $per->getNextTime($last_tz, $periods->periodical_pub_int);
$last_nb = 0;
}
$last_nb++;
# --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
$core->callBehavior('periodicalAfterPublishedPeriodicalEntry', $core, $posts, $periods);
# Increment upddt if nb of publishing is to the max
if ($last_nb == $max_nb) {
$last_tz = $per->getNextTime($last_tz, $periods->periodical_pub_int);
$last_nb = 0;
}
}
$core->blog->triggerBlog();
}
}
# --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
$core->callBehavior('periodicalAfterPublishedPeriodicalEntry', $core, $posts, $periods);
# 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();
}
$core->blog->triggerBlog();
}
}
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 ------------------------------------
if (!defined('DC_RC_PATH')){return;}
if (!defined('DC_RC_PATH')){
return;
}
class periodical
{
public $core;
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, ';
public $core;
public $con;
if (!empty($params['columns']) && is_array($params['columns'])) {
$q .= implode(', ',$params['columns']).', ';
}
$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;
protected $table;
protected $blog;
private $lock = null;
$cur->periodical_id = $id;
$cur->blog_id = $this->blog;
$cur->periodical_type = 'post';
$cur->periodical_tz = $this->core->auth->getInfo('user_tz');
$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." "
);
}
public function __construct($core)
{
$this->core = $core;
$this->con = $core->con;
# Delete a period
public function delPeriod($period_id)
{
$period_id = (integer) $period_id;
$params = array();
$params['periodical_id'] = $period_id;
$params['post_status'] = '';
$rs = $this->getPosts($params);
$this->table = $core->con->escape($core->prefix . 'periodical');
$this->blog = $core->con->escape($core->blog->id);
}
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 = 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)
);
}
public function openCursor()
{
return $this->con->openCursor($this->table);
}
# Get posts related to periods
public function getPosts($params=array(),$count_only=false)
{
if (!isset($params['columns'])) $params['columns'] = array();
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'] = 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;
}
# Get periods
public function getPeriods($params = [], $count_only = false)
{
if ($count_only) {
$q = 'SELECT count(T.periodical_id) ';
} else {
$q = 'SELECT T.periodical_id, T.periodical_type, ';
# Remove all posts without pending status from periodical
public function cleanPosts($period_id=null)
{
$params = array();
$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 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;
if (!empty($params['columns']) && is_array($params['columns'])) {
$q .= implode(', ', $params['columns']) . ', ';
}
$q .=
'T.periodical_title, T.periodical_tz, ' .
'T.periodical_curdt, T.periodical_enddt, ' .
'T.periodical_pub_int, T.periodical_pub_nb ';
}
case 'halfday':
$new_ts = mktime($e[0],$e[1] + 12,$e[2],$e[3],$e[4],$e[5]);
break;
$q .= 'FROM ' . $this->table . ' T ';
case 'day':
$new_ts = mktime($e[0],$e[1],$e[2],$e[3],$e[4] + 1,$e[5]);
break;
if (!empty($params['from'])) {
$q .= $params['from'] . ' ';
}
$q .= "WHERE T.blog_id = '" . $this->blog . "' ";
case 'week':
$new_ts = mktime($e[0],$e[1],$e[2],$e[3],$e[4] + 7,$e[5]);
break;
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'] = [(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':
$new_ts = mktime($e[0],$e[1],$e[2],$e[3] + 1,$e[4],$e[5]);
break;
return $rs;
}
default:
$new_ts = 0;
throw new Exception(__('Unknow frequence'));
break;
}
return $new_ts;
}
public function addPeriod($cur)
{
$this->con->writeLock($this->table);
# 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))) {
try {
$id = $this->con->select(
'SELECT MAX(periodical_id) FROM ' . $this->table
)->f(0) + 1;
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;
}
$cur->periodical_id = $id;
$cur->blog_id = $this->blog;
$cur->periodical_type = 'post';
$cur->periodical_tz = $this->core->auth->getInfo('user_tz');
$cur->insert();
$this->con->unlock();
} catch (Exception $e) {
$this->con->unlock();
throw $e;
}
return $cur->periodical_id;
}
public function unlockUpdate()
{
@fclose($this->lock);
$this->lock = null;
}
}
?>
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
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 ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
return null;
}
/**
@ -23,194 +22,191 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/
class adminPeriodicalList extends adminGenericList
{
public function periodDisplay($page, $nb_per_page, $enclose_block='')
{
$echo = '';
if ($this->rs->isEmpty()) {
$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';
public function periodDisplay($page, $nb_per_page, $enclose_block='')
{
$echo = '';
if ($this->rs->isEmpty()) {
$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>';
$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>';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
if ($enclose_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()) {
$echo .= $this->periodLine();
}
while ($this->rs->fetch()) {
$echo .= $this->periodLine();
}
$echo .= $blocks[1];
$echo .= $blocks[1];
$echo .= $pager->getLinks();
}
$echo .= $pager->getLinks();
}
return $echo;
}
private function periodLine()
{
$nb_posts = $this->rs->periodical->getPosts(array('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>';
return $echo;
}
private function periodLine()
{
$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>';
$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');
$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>';
$res =
'<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;
}
return $res;
}
public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='')
{
$echo = '';
if ($this->rs->isEmpty()) {
$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';
public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='')
{
$echo = '';
if ($this->rs->isEmpty()) {
$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>'.
'</tr>%s</table>';
$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>' .
'</tr>%s</table>';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
if ($enclose_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];
while ($this->rs->fetch()) {
$echo .= $this->postLine();
}
$echo .= $blocks[1];
$echo .= $blocks[0];
while ($this->rs->fetch()) {
$echo .= $this->postLine();
}
$echo .= $blocks[1];
$echo .= $pager->getLinks();
}
$echo .= $pager->getLinks();
}
return $echo;
}
private function postLine()
{
if ($this->core->auth->check('categories', $this->core->blog->id)) {
$cat_link = '<a href="category.php?id=%s">%s</a>';
}
else {
$cat_link = '%2$s';
}
return $echo;
}
private function postLine()
{
if ($this->core->auth->check('categories', $this->core->blog->id)) {
$cat_link = '<a href="category.php?id=%s">%s</a>';
} else {
$cat_link = '%2$s';
}
if ($this->rs->cat_title) {
$cat_title = sprintf(
$cat_link,
$this->rs->cat_id,
html::escapeHTML($this->rs->cat_title)
);
}
else {
$cat_title = __('None');
}
if ($this->rs->cat_title) {
$cat_title = sprintf(
$cat_link,
$this->rs->cat_id,
html::escapeHTML($this->rs->cat_title)
);
} else {
$cat_title = __('None');
}
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
switch ($this->rs->post_status)
{
case 1:
$img_status = sprintf($img,__('published'), 'check-on.png');
break;
case 0:
$img_status = sprintf($img,__('unpublished'), 'check-off.png');
break;
case -1:
$img_status = sprintf($img,__('scheduled'), 'scheduled.png');
break;
case -2:
$img_status = sprintf($img,__('pending'), 'check-wrn.png');
break;
}
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
switch ($this->rs->post_status)
{
case 1:
$img_status = sprintf($img, __('published'), 'check-on.png');
break;
case 0:
$img_status = sprintf($img, __('unpublished'), 'check-off.png');
break;
case -1:
$img_status = sprintf($img, __('scheduled'), 'scheduled.png');
break;
case -2:
$img_status = sprintf($img, __('pending'), 'check-wrn.png');
break;
}
$protected = '';
if ($this->rs->post_password) {
$protected = sprintf($img,__('protected'), 'locker.png');
}
$protected = '';
if ($this->rs->post_password) {
$protected = sprintf($img, __('protected'), 'locker.png');
}
$selected = '';
if ($this->rs->post_selected) {
$selected = sprintf($img,__('selected'), 'selected.png');
}
$selected = '';
if ($this->rs->post_selected) {
$selected = sprintf($img, __('selected'), 'selected.png');
}
$attach = '';
$nb_media = $this->rs->countMedia();
if ($nb_media > 0) {
$attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
$attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png');
}
$attach = '';
$nb_media = $this->rs->countMedia();
if ($nb_media > 0) {
$attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
$attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png');
}
$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>';
$res =
'<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;
}
}
return $res;
}
}

View File

@ -11,82 +11,80 @@
#
# -- 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(
'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%'))
);
}
public static function periodicalAfterPublishedPeriodicalEntry($core,$post,$period)
{
$key = 'periodicalcreate';
# Is install
if (!$core->plugins->moduleExists('soCialMe')) return;
# Is active
if (!$core->blog->settings->soCialMeWriter->active) return;
# Load services
$soCialMeWriter = new soCialMeWriter($core);
# List of service per action
$actions = $soCialMeWriter->getMarker('action');
# List of format per type
$formats = $soCialMeWriter->getMarker('format');
# prepare data
$shortposturl = soCialMeWriter::reduceURL($post->getURL());
$shortposturl = $shortposturl ? $shortposturl : $post->getURL();
$shortsiteurl = soCialMeWriter::reduceURL($core->blog->url);
$shortsiteurl = $shortsiteurl ? $shortsiteurl : $core->blog->url;
# sendMessage
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),
$formats[$key]['Message']
);
// send message
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);
}
}
# sendData
// not yet implemented
#sendArticle
// not yet implemented
}
}
?>
public static function soCialMeWriterMarker($rs)
{
$rs['periodicalcreate'] = [
'name' => __('New periodical publication'),
'description' => __('When an entry is published on a period'),
'action' => ['Message', 'Link'],
'format' => ['Message'],
'wildcards' => ['Message' => ['%posttitle%','%posturl%','%shortposturl%','%postauthor%','%sitetitle%','%siteurl%','%shortsiteurl%']]
];
}
public static function periodicalAfterPublishedPeriodicalEntry($core, $post, $period)
{
$key = 'periodicalcreate';
# Is install
if (!$core->plugins->moduleExists('soCialMe')) {
return;
}
# Is active
if (!$core->blog->settings->soCialMeWriter->active) {
return;
}
# Load services
$soCialMeWriter = new soCialMeWriter($core);
# List of service per action
$actions = $soCialMeWriter->getMarker('action');
# List of format per type
$formats = $soCialMeWriter->getMarker('format');
# prepare data
$shortposturl = soCialMeWriter::reduceURL($post->getURL());
$shortposturl = $shortposturl ? $shortposturl : $post->getURL();
$shortsiteurl = soCialMeWriter::reduceURL($core->blog->url);
$shortsiteurl = $shortsiteurl ? $shortsiteurl : $core->blog->url;
# sendMessage
if (!empty($formats[$key]['Message']) && !empty($actions[$key]['Message'])) {
// parse message
$message_txt = str_replace(
['%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);
}
}
}
# sendLink
if (!empty($actions[$key]['Link'])) {
foreach($actions[$key]['Link'] as $service_id) {
$soCialMeWriter->play($service_id, 'Link', 'Content', $post->post_title, $shortposturl);
}
}
# sendData
// 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>
<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;
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;
return null;
}
$__resources['help']['periodical'] = dirname(__FILE__).'/help/help.html';
$__resources['help']['periodical'] = dirname(__FILE__) . '/help/help.html';