diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb7dc8..b6e3935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/_admin.php b/_admin.php index 61b752a..e4e13fa 100644 --- a/_admin.php +++ b/_admin.php @@ -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 + '
' . + $pa->getCheckboxes() . - echo - ''. - $pa->getCheckboxes(). + self::formPeriod($core) . - self::formPeriod($core). + '

'. + $core->formNonce() . + $pa->getHiddenFields() . + form::hidden(['action'], 'periodical_add') . + '

' . + '
'; - '

'. - $core->formNonce(). - $pa->getHiddenFields(). - form::hidden(array('action'), 'periodical_add'). - '

'. - ''; + $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 + '

' . + form::combo('periodical', $combo, $period) . + '

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

'. - form::combo('periodical', $combo, $period). - '

'; - } + 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); + } +} \ No newline at end of file diff --git a/_config.php b/_config.php index 2d2c461..7c1ab18 100644 --- a/_config.php +++ b/_config.php @@ -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 '
-

'.__('Activation').'

+

' . __('Activation') . '

-

+

-

'.__('Dates of published entries').'

+

' . __('Dates of published entries') . '

-

+

-

+

-

'.__('Order of publication of entries').'

+

' . __('Order of publication of entries') . '

-

'. -form::combo('s_sortby', $sortby_combo, $s_sortby).'

+

' . +form::combo('s_sortby', $sortby_combo, $s_sortby) . '

-

'. -form::combo('s_order', $order_combo, $s_order).'

+

' . +form::combo('s_order', $order_combo, $s_order) . '

-
'; +'; \ No newline at end of file diff --git a/_define.php b/_define.php index c139b2e..687fdaa 100644 --- a/_define.php +++ b/_define.php @@ -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' + ] +); \ No newline at end of file diff --git a/_install.php b/_install.php index 50b77c5..62acd48 100644 --- a/_install.php +++ b/_install.php @@ -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; \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index 296e18c..cf6080b 100644 --- a/_prepend.php +++ b/_prepend.php @@ -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'] +); \ No newline at end of file diff --git a/_public.php b/_public.php index ec39cf1..4b12c8e 100644 --- a/_public.php +++ b/_public.php @@ -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; + } + } +} \ No newline at end of file diff --git a/inc/class.periodical.php b/inc/class.periodical.php index b5c6562..caff7fe 100644 --- a/inc/class.periodical.php +++ b/inc/class.periodical.php @@ -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; - } -} -?> \ No newline at end of file + 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; + } +} \ No newline at end of file diff --git a/inc/lib.index.pager.php b/inc/lib.index.pager.php index 9bf8ade..2e79ea6 100644 --- a/inc/lib.index.pager.php +++ b/inc/lib.index.pager.php @@ -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 .= '

'.__('No period').'

'; - } - 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 .= '

' .__('No period') .'

'; + } 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 = - '
'. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - ''. - '%s
'.__('Name').''.__('Next update').''.__('Frequency').''.__('Publications').''.__('Entries').''.__('End date').'
'. - '
'; + $html_block = + '
' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '%s
' . __('Name') . '' . __('Next update') . '' . __('Frequency') . '' . __('Publications') . '' . __('Entries') . '' . __('End date') . '
' . + '
'; - 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' : - ''.$nb_posts.''; + 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' : + '' . $nb_posts . ''; - $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 = - ''. - ''.form::checkbox(array('periods[]'), $this->rs->periodical_id).''. - ''.html::escapeHTML($this->rs->periodical_title).''. - ''.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt).''. - ''.$pub_int.''. - ''.$this->rs->periodical_pub_nb.''. - ''.$posts_links.''. - ''.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt).''. - ''; + $res = + '' . + '' . form::checkbox(['periods[]'], $this->rs->periodical_id) . '' . + '' . html::escapeHTML($this->rs->periodical_title) . '' . + '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '' . + '' . $pub_int . '' . + '' . $this->rs->periodical_pub_nb .'' . + '' . $posts_links . '' . + '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '' . + ''; - return $res; - } + return $res; + } - public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='') - { - $echo = ''; - if ($this->rs->isEmpty()) { - $echo .= '

'.__('No entry').'

'; - } - 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 .= '

' . __('No entry') . '

'; + } 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 = - ''. - ''. - ''. - ''. - ''. - ''. - ''. - '%s
'.__('Title').''.__('Date').''.__('Category').''.__('Author').''.__('Status').''.__('Create date').'
'; + $html_block = + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '%s
' . __('Title') . '' . __('Date') . '' . __('Category') . '' . __('Author') . '' . __('Status') . '' . __('Create date') . '
'; - 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 = '%s'; - } - else { - $cat_link = '%2$s'; - } + return $echo; + } + + private function postLine() + { + if ($this->core->auth->check('categories', $this->core->blog->id)) { + $cat_link = '%s'; + } 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 = '%1$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 = '%1$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 = - ''. - ''.form::checkbox(array('periodical_entries[]'), $this->rs->post_id,0).''. - ''. - html::escapeHTML($this->rs->post_title).''. - ''.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt).''. - ''.$cat_title.''. - ''.$this->rs->user_id.''. - ''.$img_status.' '.$selected.' '.$protected.' '.$attach.''. - ''.dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_creadt, $this->rs->core->auth->getInfo('user_tz')).''. - ''; + $res = + '' . + '' . form::checkbox(['periodical_entries[]'], $this->rs->post_id, 0) . '' . + '' . + html::escapeHTML($this->rs->post_title) . '' . + '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '' . + '' . $cat_title . '' . + '' . $this->rs->user_id . '' . + '' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '' . + '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_creadt, $this->rs->core->auth->getInfo('user_tz')) . '' . + ''; - return $res; - } -} + return $res; + } +} \ No newline at end of file diff --git a/inc/lib.periodical.socialmewriter.php b/inc/lib.periodical.socialmewriter.php index 07fa993..01d395f 100644 --- a/inc/lib.periodical.socialmewriter.php +++ b/inc/lib.periodical.socialmewriter.php @@ -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 - } -} -?> \ No newline at end of file + 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 + } +} \ No newline at end of file diff --git a/index.php b/index.php index 72f6973..830c448 100644 --- a/index.php +++ b/index.php @@ -12,8 +12,7 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + return null; } dcPage::check('usage,contentadmin'); @@ -35,596 +34,577 @@ $part = isset($_REQUEST['part']) && $_REQUEST['part'] == 'period' ? 'period' : ' if ($part == 'period') { - $starting_script = ''; - - # Default value for period - $period_id = null; - $period_title = __('One post per day'); - $period_pub_nb = 1; - $period_pub_int = 'day'; - $period_curdt = date('Y-m-d H:i:00', time()); - $period_enddt = date('Y-m-d H:i:00', time() + 31536000); //one year - - # Get period - if (!empty($_REQUEST['period_id'])) { - $rs = $per->getPeriods(array( - 'periodical_id' => $_REQUEST['period_id'] - )); - if ($rs->isEmpty()) { - $core->error->add(__('This period does not exist.')); - $period_id = null; - } - else { - $period_id = $rs->periodical_id; - $period_title = $rs->periodical_title; - $period_pub_nb = $rs->periodical_pub_nb; - $period_pub_int = $rs->periodical_pub_int; - $period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt)); - $period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt)); - - //todo load related posts - } - } - - # Set period - if ($action == 'setperiod') { - - # Get POST values - if (!empty($_POST['period_title'])) { - $period_title = $_POST['period_title']; - } - if (!empty($_POST['period_pub_nb'])) { - $period_pub_nb = abs((integer) $_POST['period_pub_nb']); - } - if (!empty($_POST['period_pub_int']) - && in_array($_POST['period_pub_int'], $per->getTimesCombo()) - ) { - $period_pub_int = $_POST['period_pub_int']; - } - if (!empty($_POST['period_curdt'])) { - $period_curdt = date('Y-m-d H:i:00', strtotime($_POST['period_curdt'])); - } - if (!empty($_POST['period_enddt'])) { - $period_enddt = date('Y-m-d H:i:00', strtotime($_POST['period_enddt'])); - } - - # Check period title and dates - $old_titles = $per->getPeriods(array( - 'periodical_title' => $period_title - )); - if (!$old_titles->isEmpty()) { - while($old_titles->fetch()) { - if (!$period_id || $old_titles->periodical_id != $period_id) { - $core->error->add(__('Period title is already taken')); - } - } - } - if (empty($period_title)) { - $core->error->add(__('Period title is required')); - } - if (strtotime($period_curdt) > strtotime($period_enddt)) { - $core->error->add(__('Start date must be older than end date')); - } - - # If no error, set period - if (!$core->error->flag()) { - - $cur = $per->openCursor(); - $cur->periodical_title = $period_title; - $cur->periodical_curdt = $period_curdt; - $cur->periodical_enddt = $period_enddt; - $cur->periodical_pub_int = $period_pub_int; - $cur->periodical_pub_nb = $period_pub_nb; - - # Update period - if ($period_id) { - - $per->updPeriod($period_id, $cur); - - dcPage::addSuccessNotice( - __('Period successfully updated.') - ); - } - # Create period - else { - - $period_id = $per->addPeriod($cur); - - dcPage::addSuccessNotice( - __('Period successfully created.') - ); - } - - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=period&period_id='.$period_id.'#period' : - $_POST['redir'] - ); - } - } - - # Actions on related posts - if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) { - - # Publish posts - if ($action == 'publish') { - try { - foreach($_POST['periodical_entries'] as $id) { - $id = (integer) $id; - $core->blog->updPostStatus($id, 1); - $per->delPost($id); - } - - dcPage::addSuccessNotice( - __('Entries successfully published.') - ); - - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=period&period_id='.$period_id.'#posts' : - $_POST['redir'] - ); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } - - # Unpublish posts - if ($action == 'unpublish') { - try { - foreach($_POST['periodical_entries'] as $id) { - $id = (integer) $id; - $core->blog->updPostStatus($id,0); - $per->delPost($id); - } - - dcPage::addSuccessNotice( - __('Entries successfully unpublished.') - ); - - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=period&period_id='.$period_id.'#posts' : - $_POST['redir'] - ); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } - - # Remove posts from periodical - if ($action == 'remove_post_periodical') { - try { - foreach($_POST['periodical_entries'] as $id) { - $id = (integer) $id; - $per->delPost($id); - } - - dcPage::addSuccessNotice( - __('Entries successfully removed.') - ); - - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=period&period_id='.$period_id.'#posts' : - $_POST['redir'] - ); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } - } - - # Prepare combos for posts list - if ($period_id) { - - try { - # Getting categories - $categories = $core->blog->getCategories(array('post_type' => 'post')); - - # Getting authors - $users = $core->blog->getPostsUsers(); - - # Getting dates - $dates = $core->blog->getDates(array('type' => 'month')); - - # Getting langs - $langs = $core->blog->getLangs(); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } - - # Creating filter combo boxes - if ($period_id && !$core->error->flag()) { - - # Users combo - $users_combo = array_merge( - array('-' => ''), - dcAdminCombos::getUsersCombo($users) - ); - - # Categories combo - $categories_combo = array_merge( - array( - new formSelectOption('-', ''), - new formSelectOption(__('(No cat)'), 'NULL')), - dcAdminCombos::getCategoriesCombo($categories, false) - ); - $categories_values = array(); - foreach ($categories_combo as $cat) { - if (isset($cat->value)) { - $categories_values[$cat->value] = true; - } - } - - # Status combo - $status_combo = array_merge( - array('-' => ''), - dcAdminCombos::getPostStatusesCombo() - ); - - # Selection combo - $selected_combo = array( - '-' => '', - __('Selected') => '1', - __('Not selected') => '0' - ); - - # Attachments combo - $attachment_combo = array( - '-' => '', - __('With attachments') => '1', - __('Without attachments') => '0' - ); - - # Months combo - $dt_m_combo = array_merge( - array('-' => ''), - dcAdminCombos::getDatesCombo($dates) - ); - - # Langs combo - $lang_combo = array_merge( - array('-' => ''), - dcAdminCombos::getLangsCombo($langs, false) - ); - - # Sort_by combo - $sortby_combo = array( - __('Date') => 'post_dt', - __('Title') => 'post_title', - __('Category') => 'cat_title', - __('Author') => 'user_id', - __('Status') => 'post_status', - __('Selected') => 'post_selected', - __('Number of comments') => 'nb_comment', - __('Number of trackbacks') => 'nb_trackback' - ); - - # order combo - $order_combo = array( - __('Descending') => 'desc', - __('Ascending') => 'asc' - ); - - # parse filters - $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; - $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; - $status = isset($_GET['status']) ? $_GET['status'] : ''; - $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; - $attachment = isset($_GET['attachment']) ? $_GET['attachment'] : ''; - $month = !empty($_GET['month']) ? $_GET['month'] : ''; - $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; - $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; - - $show_filters = false; - - $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; - $nb_per_page = 30; - - if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != $_GET['nb']) { - $show_filters = true; - } - $nb_per_page = (integer) $_GET['nb']; - } - - $params['limit'] = array((($page-1)*$nb_per_page), $nb_per_page); - $params['no_content'] = true; - $params['periodical_id'] = $period_id; - - # - User filter - if ($user_id !== '' && in_array($user_id, $users_combo)) { - $params['user_id'] = $user_id; - $show_filters = true; - } - else { - $user_id=''; - } - - # - Categories filter - if ($cat_id !== '' && isset($categories_values[$cat_id])) { - $params['cat_id'] = $cat_id; - $show_filters = true; - } - else { - $cat_id=''; - } - - # - Status filter - if ($status !== '' && in_array($status, $status_combo)) { - $params['post_status'] = $status; - $show_filters = true; - } - else { - $status=''; - } - - # - Selected filter - if ($selected !== '' && in_array($selected, $selected_combo)) { - $params['post_selected'] = $selected; - $show_filters = true; - } - else { - $selected=''; - } - - # - Selected filter - if ($attachment !== '' && in_array($attachment, $attachment_combo)) { - $params['media'] = $attachment; - $params['link_type'] = 'attachment'; - $show_filters = true; - } - else { - $attachment=''; - } - - # - Month filter - if ($month !== '' && in_array($month, $dt_m_combo)) { - $params['post_month'] = substr($month, 4, 2); - $params['post_year'] = substr($month, 0, 4); - $show_filters = true; - } - else { - $month=''; - } - - # - Lang filter - if ($lang !== '' && in_array($lang, $lang_combo)) { - $params['post_lang'] = $lang; - $show_filters = true; - } - else { - $lang=''; - } - - # - Sortby and order filter - if ($sortby !== '' && in_array($sortby, $sortby_combo)) { - if ($order !== '' && in_array($order, $order_combo)) { - $params['order'] = $sortby.' '.$order; - } - else { - $order='desc'; - } - - if ($sortby != 'post_dt' || $order != 'desc') { - $show_filters = true; - } - } - else { - $sortby='post_dt'; - $order='desc'; - } - - # Get posts - try { - $posts = $per->getPosts($params); - $counter = $per->getPosts($params, true); - $post_list = new adminPeriodicalList($core, $posts, $counter->f(0)); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - - $starting_script = - dcPage::jsLoad( - 'index.php?pf=periodical/js/postsfilter.js' - ). - '\n"; - } - - # Display - echo ' - '.__('Periodical').''. - dcPage::jsLoad('index.php?pf=periodical/js/dates.js'). - $starting_script. - dcPage::jsDatePicker(). - dcPage::jsPageTabs(). - ' - '; - - echo - dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Periodical') => $p_url.'&part=periods', - (null === $period_id ? __('New period') : __('Edit period')) => '' - ) - ). - dcPage::notices(); - - # Period form - echo ' -
-
- -

'. - form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal').'

- -
- -

'. - form::field('period_curdt', 16, 16, date('Y-m-d H:i', strtotime($period_curdt))).'

- -

'. - form::field('period_enddt', 16, 16, date('Y-m-d H:i', strtotime($period_enddt))).'

- -
- -

'. - form::combo('period_pub_int',$per->getTimesCombo(),$period_pub_int).'

- -

'. - form::field('period_pub_nb', 10, 3, html::escapeHTML($period_pub_nb)).'

- -
- -
-

'. - $core->formNonce(). - form::hidden(array('action'), 'setperiod'). - form::hidden(array('period_id'), $period_id). - form::hidden(array('part'), 'period').' -

-
-
-
'; - - if ($period_id && !$core->error->flag()) { - - # Actions combo box - $combo_action = array(); - $combo_action[__('Entries')][__('Publish')] = 'publish'; - $combo_action[__('Entries')][__('Unpublish')] = 'unpublish'; - $combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical'; - - $base_url = $p_url. - '&period_id='.$period_id. - '&part=period'. - '&user_id='.$user_id. - '&cat_id='.$cat_id. - '&status='.$status. - '&selected='.$selected. - '&attachment='.$attachment. - '&month='.$month. - '&lang='.$lang. - '&sortby='.$sortby. - '&order='.$order. - '&nb='.$nb_per_page. - '&page=%s'. - '#posts'; - - echo ' -
'; - - # Filters - echo - '
'. - - '

'. - __('Cancel filters and display options'). - '

'. - - '
'. - '
'. - '

'.__('Filters').'

'. - '

'. - form::combo('user_id',$users_combo,$user_id).'

'. - '

'. - form::combo('cat_id',$categories_combo,$cat_id).'

'. - '

' . - form::combo('status',$status_combo,$status).'

'. - '
'. - - '
'. - '

'. - form::combo('selected',$selected_combo,$selected).'

'. - '

'. - form::combo('attachment',$attachment_combo,$attachment).'

'. - '

'. - form::combo('month',$dt_m_combo,$month).'

'. - '

'. - form::combo('lang',$lang_combo,$lang).'

'. - '
'. - - '
'. - '

'.__('Display options').'

'. - '

'. - form::combo('sortby',$sortby_combo,$sortby).'

'. - '

'. - form::combo('order',$order_combo,$order).'

'. - '

'.__('Show').'

'. - '
'. - '
'. - - '

'. - form::hidden(array('p'), 'periodical'). - form::hidden(array('part'), 'period'). - form::hidden(array('period_id'), $period_id). - '

'. //Opera sucks - '
'; - - # Posts list - echo - $post_list->postDisplay($page, $nb_per_page, $base_url, - '
'. - - '%s'. - - '
'. - '

'. - - '

'.__('Selected entries action:').' '. - form::combo('action', $combo_action). - '

'. - form::hidden(array('period_id'), $period_id). - form::hidden(array('user_id'), $user_id). - form::hidden(array('cat_id'), $cat_id). - form::hidden(array('status'), $status). - form::hidden(array('selected'), $selected). - form::hidden(array('attachment'), $attachment). - form::hidden(array('month'), $month). - form::hidden(array('lang'), $lang). - form::hidden(array('sortby'), $sortby). - form::hidden(array('order'), $order). - form::hidden(array('page'), $page). - form::hidden(array('nb'), $nb_per_page). - form::hidden(array('p'), 'periodical'). - form::hidden(array('part'), 'period'). - form::hidden(array('redir'), sprintf($base_url, $page)). - $core->formNonce(). - '
'. - '
' - ); - - echo - '
'; - } - -} + $starting_script = ''; + + # Default value for period + $period_id = null; + $period_title = __('One post per day'); + $period_pub_nb = 1; + $period_pub_int = 'day'; + $period_curdt = date('Y-m-d H:i:00', time()); + $period_enddt = date('Y-m-d H:i:00', time() + 31536000); //one year + + # Get period + if (!empty($_REQUEST['period_id'])) { + $rs = $per->getPeriods([ + 'periodical_id' => $_REQUEST['period_id'] + ]); + if ($rs->isEmpty()) { + $core->error->add(__('This period does not exist.')); + $period_id = null; + } else { + $period_id = $rs->periodical_id; + $period_title = $rs->periodical_title; + $period_pub_nb = $rs->periodical_pub_nb; + $period_pub_int = $rs->periodical_pub_int; + $period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt)); + $period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt)); + + //todo load related posts + } + } + + # Set period + if ($action == 'setperiod') { + + # Get POST values + if (!empty($_POST['period_title'])) { + $period_title = $_POST['period_title']; + } + if (!empty($_POST['period_pub_nb'])) { + $period_pub_nb = abs((integer) $_POST['period_pub_nb']); + } + if (!empty($_POST['period_pub_int']) + && in_array($_POST['period_pub_int'], $per->getTimesCombo())) { + $period_pub_int = $_POST['period_pub_int']; + } + if (!empty($_POST['period_curdt'])) { + $period_curdt = date('Y-m-d H:i:00', strtotime($_POST['period_curdt'])); + } + if (!empty($_POST['period_enddt'])) { + $period_enddt = date('Y-m-d H:i:00', strtotime($_POST['period_enddt'])); + } + + # Check period title and dates + $old_titles = $per->getPeriods([ + 'periodical_title' => $period_title + ]); + if (!$old_titles->isEmpty()) { + while($old_titles->fetch()) { + if (!$period_id || $old_titles->periodical_id != $period_id) { + $core->error->add(__('Period title is already taken')); + } + } + } + if (empty($period_title)) { + $core->error->add(__('Period title is required')); + } + if (strtotime($period_curdt) > strtotime($period_enddt)) { + $core->error->add(__('Start date must be older than end date')); + } + + # If no error, set period + if (!$core->error->flag()) { + + $cur = $per->openCursor(); + $cur->periodical_title = $period_title; + $cur->periodical_curdt = $period_curdt; + $cur->periodical_enddt = $period_enddt; + $cur->periodical_pub_int = $period_pub_int; + $cur->periodical_pub_nb = $period_pub_nb; + + # Update period + if ($period_id) { + + $per->updPeriod($period_id, $cur); + + dcPage::addSuccessNotice( + __('Period successfully updated.') + ); + # Create period + } else { + + $period_id = $per->addPeriod($cur); + + dcPage::addSuccessNotice( + __('Period successfully created.') + ); + } + + http::redirect(empty($_POST['redir']) ? + $p_url . '&part=period&period_id=' . $period_id . '#period' : + $_POST['redir'] + ); + } + } + + # Actions on related posts + if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) { + + # Publish posts + if ($action == 'publish') { + try { + foreach($_POST['periodical_entries'] as $id) { + $id = (integer) $id; + $core->blog->updPostStatus($id, 1); + $per->delPost($id); + } + + dcPage::addSuccessNotice( + __('Entries successfully published.') + ); + + http::redirect(empty($_POST['redir']) ? + $p_url . '&part=period&period_id=' . $period_id . '#posts' : + $_POST['redir'] + ); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } + + # Unpublish posts + if ($action == 'unpublish') { + try { + foreach($_POST['periodical_entries'] as $id) { + $id = (integer) $id; + $core->blog->updPostStatus($id,0); + $per->delPost($id); + } + + dcPage::addSuccessNotice( + __('Entries successfully unpublished.') + ); + + http::redirect(empty($_POST['redir']) ? + $p_url . '&part=period&period_id=' . $period_id . '#posts' : + $_POST['redir'] + ); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } + + # Remove posts from periodical + if ($action == 'remove_post_periodical') { + try { + foreach($_POST['periodical_entries'] as $id) { + $id = (integer) $id; + $per->delPost($id); + } + + dcPage::addSuccessNotice( + __('Entries successfully removed.') + ); + + http::redirect(empty($_POST['redir']) ? + $p_url . '&part=period&period_id=' . $period_id . '#posts' : + $_POST['redir'] + ); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } + } + + # Prepare combos for posts list + if ($period_id) { + try { + # Getting categories + $categories = $core->blog->getCategories(['post_type' => 'post']); + + # Getting authors + $users = $core->blog->getPostsUsers(); + + # Getting dates + $dates = $core->blog->getDates(['type' => 'month']); + + # Getting langs + $langs = $core->blog->getLangs(); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } + + # Creating filter combo boxes + if ($period_id && !$core->error->flag()) { + + # Users combo + $users_combo = array_merge( + ['-' => ''], + dcAdminCombos::getUsersCombo($users) + ); + + # Categories combo + $categories_combo = array_merge( + [ + new formSelectOption('-', ''), + new formSelectOption(__('(No cat)'), 'NULL') + ], + dcAdminCombos::getCategoriesCombo($categories, false) + ); + $categories_values = []; + foreach ($categories_combo as $cat) { + if (isset($cat->value)) { + $categories_values[$cat->value] = true; + } + } + + # Status combo + $status_combo = array_merge( + ['-' => ''], + dcAdminCombos::getPostStatusesCombo() + ); + + # Selection combo + $selected_combo = [ + '-' => '', + __('Selected') => '1', + __('Not selected') => '0' + ]; + + # Attachments combo + $attachment_combo = [ + '-' => '', + __('With attachments') => '1', + __('Without attachments') => '0' + ]; + + # Months combo + $dt_m_combo = array_merge( + ['-' => ''], + dcAdminCombos::getDatesCombo($dates) + ); + + # Langs combo + $lang_combo = array_merge( + ['-' => ''], + dcAdminCombos::getLangsCombo($langs, false) + ); + + # Sort_by combo + $sortby_combo = [ + __('Date') => 'post_dt', + __('Title') => 'post_title', + __('Category') => 'cat_title', + __('Author') => 'user_id', + __('Status') => 'post_status', + __('Selected') => 'post_selected', + __('Number of comments') => 'nb_comment', + __('Number of trackbacks') => 'nb_trackback' + ]; + + # order combo + $order_combo = [ + __('Descending') => 'desc', + __('Ascending') => 'asc' + ]; + + # parse filters + $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; + $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : ''; + $status = isset($_GET['status']) ? $_GET['status'] : ''; + $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; + $attachment = isset($_GET['attachment']) ? $_GET['attachment'] : ''; + $month = !empty($_GET['month']) ? $_GET['month'] : ''; + $lang = !empty($_GET['lang']) ? $_GET['lang'] : ''; + $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'post_dt'; + $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; + + $show_filters = false; + + $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; + $nb_per_page = 30; + + if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { + if ($nb_per_page != $_GET['nb']) { + $show_filters = true; + } + $nb_per_page = (integer) $_GET['nb']; + } + + $params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page]; + $params['no_content'] = true; + $params['periodical_id'] = $period_id; + + # - User filter + if ($user_id !== '' && in_array($user_id, $users_combo)) { + $params['user_id'] = $user_id; + $show_filters = true; + } else { + $user_id=''; + } + + # - Categories filter + if ($cat_id !== '' && isset($categories_values[$cat_id])) { + $params['cat_id'] = $cat_id; + $show_filters = true; + } else { + $cat_id=''; + } + + # - Status filter + if ($status !== '' && in_array($status, $status_combo)) { + $params['post_status'] = $status; + $show_filters = true; + } else { + $status=''; + } + + # - Selected filter + if ($selected !== '' && in_array($selected, $selected_combo)) { + $params['post_selected'] = $selected; + $show_filters = true; + } else { + $selected=''; + } + + # - Selected filter + if ($attachment !== '' && in_array($attachment, $attachment_combo)) { + $params['media'] = $attachment; + $params['link_type'] = 'attachment'; + $show_filters = true; + } else { + $attachment=''; + } + + # - Month filter + if ($month !== '' && in_array($month, $dt_m_combo)) { + $params['post_month'] = substr($month, 4, 2); + $params['post_year'] = substr($month, 0, 4); + $show_filters = true; + } else { + $month=''; + } + + # - Lang filter + if ($lang !== '' && in_array($lang, $lang_combo)) { + $params['post_lang'] = $lang; + $show_filters = true; + } else { + $lang=''; + } + + # - Sortby and order filter + if ($sortby !== '' && in_array($sortby, $sortby_combo)) { + if ($order !== '' && in_array($order, $order_combo)) { + $params['order'] = $sortby.' '.$order; + } else { + $order='desc'; + } + + if ($sortby != 'post_dt' || $order != 'desc') { + $show_filters = true; + } + } else { + $sortby='post_dt'; + $order='desc'; + } + + # Get posts + try { + $posts = $per->getPosts($params); + $counter = $per->getPosts($params, true); + $post_list = new adminPeriodicalList($core, $posts, $counter->f(0)); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + + $starting_script = + dcPage::jsLoad( + 'index.php?pf=periodical/js/postsfilter.js' + ) . + '\n"; + } + + # Display + echo ' + ' . __('Periodical') . '' . + dcPage::jsLoad('index.php?pf=periodical/js/dates.js') . + $starting_script . + dcPage::jsDatePicker() . + dcPage::jsPageTabs() . + ' + '; + + echo + dcPage::breadcrumb( + [ + html::escapeHTML($core->blog->name) => '', + __('Periodical') => $p_url . '&part=periods', + (null === $period_id ? __('New period') : __('Edit period')) => '' + ] + ) . + dcPage::notices(); + + # Period form + echo ' +
+
+ +

' . + form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal') . '

+ +
+ +

' . + form::field('period_curdt', 16, 16, date('Y-m-d H:i', strtotime($period_curdt))) . '

+ +

' . + form::field('period_enddt', 16, 16, date('Y-m-d H:i', strtotime($period_enddt))) . '

+ +
+ +

' . + form::combo('period_pub_int',$per->getTimesCombo(), $period_pub_int) . '

+ +

' . + form::field('period_pub_nb', 10, 3, html::escapeHTML($period_pub_nb)) . '

+ +
+ +
+

' . + $core->formNonce() . + form::hidden(['action'], 'setperiod') . + form::hidden(['period_id'], $period_id) . + form::hidden(['part'], 'period') .' +

+
+
+
'; + + if ($period_id && !$core->error->flag()) { + + # Actions combo box + $combo_action = array(); + $combo_action[__('Entries')][__('Publish')] = 'publish'; + $combo_action[__('Entries')][__('Unpublish')] = 'unpublish'; + $combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical'; + + $base_url = $p_url . + '&period_id=' .$period_id . + '&part=period' . + '&user_id=' . $user_id . + '&cat_id=' . $cat_id . + '&status=' . $status . + '&selected=' . $selected . + '&attachment=' . $attachment . + '&month=' . $month . + '&lang=' . $lang . + '&sortby=' . $sortby . + '&order=' . $order . + '&nb=' . $nb_per_page . + '&page=%s' . + '#posts'; + + echo ' +
'; + + # Filters + echo + '
' . + + '

' . + __('Cancel filters and display options') . + '

' . + + '
' . + '
' . + '

' . __('Filters') . '

' . + '

' . + form::combo('user_id', $users_combo, $user_id) . '

' . + '

' . + form::combo('cat_id', $categories_combo, $cat_id) . '

' . + '

' . + form::combo('status', $status_combo, $status) . '

' . + '
' . + + '
' . + '

' . + form::combo('selected', $selected_combo, $selected) .'

' . + '

' . + form::combo('attachment', $attachment_combo, $attachment) . '

' . + '

' . + form::combo('month', $dt_m_combo,$month) . '

' . + '

' . + form::combo('lang', $lang_combo, $lang) . '

' . + '
'. + + '
' . + '

' . __('Display options') . '

' . + '

' . + form::combo('sortby', $sortby_combo, $sortby) . '

' . + '

' . + form::combo('order', $order_combo, $order) . '

' . + '

' . __('Show') . '

' . + '
' . + '
' . + + '

' . + form::hidden(['p'], 'periodical') . + form::hidden(['part'], 'period') . + form::hidden(['period_id'], $period_id) . + '

' . //Opera sucks + '
'; + + # Posts list + echo + $post_list->postDisplay($page, $nb_per_page, $base_url, + '
' . + + '%s' . + + '
' . + '

' . + + '

' . __('Selected entries action:') . ' ' . + form::combo('action', $combo_action) . + '

' . + form::hidden(['period_id'], $period_id) . + form::hidden(['user_id'], $user_id) . + form::hidden(['cat_id'], $cat_id) . + form::hidden(['status'], $status) . + form::hidden(['selected'], $selected) . + form::hidden(['attachment'], $attachment) . + form::hidden(['month'], $month) . + form::hidden(['lang'], $lang) . + form::hidden(['sortby'], $sortby) . + form::hidden(['order'], $order) . + form::hidden(['page'], $page) . + form::hidden(['nb'], $nb_per_page) . + form::hidden(['p'], 'periodical') . + form::hidden(['part'], 'period') . + form::hidden(['redir'], sprintf($base_url, $page)) . + $core->formNonce() . + '
' . + '
' + ); + + echo + '
'; + } ############################################################ # @@ -632,201 +612,198 @@ if ($part == 'period') { # ############################################################ -else { +} else { - # Delete periods and related posts links - if ($action == 'deleteperiods' && !empty($_POST['periods'])) { - try { - foreach($_POST['periods'] as $id) { - $id = (integer) $id; - $per->delPeriodPosts($id); - $per->delPeriod($id); - } + # Delete periods and related posts links + if ($action == 'deleteperiods' && !empty($_POST['periods'])) { + try { + foreach($_POST['periods'] as $id) { + $id = (integer) $id; + $per->delPeriodPosts($id); + $per->delPeriod($id); + } - dcPage::addSuccessNotice( - __('Periods removed.') - ); + dcPage::addSuccessNotice( + __('Periods removed.') + ); - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=periods' : - $_POST['redir'] - ); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } - # Delete periods related posts links (without delete periods) - if ($action == 'emptyperiods' && !empty($_POST['periods'])) { - try { - foreach($_POST['periods'] as $id) { - $id = (integer) $id; - $per->delPeriodPosts($id); - } + http::redirect(empty($_POST['redir']) ? + $p_url.'&part=periods' : + $_POST['redir'] + ); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } + # Delete periods related posts links (without delete periods) + if ($action == 'emptyperiods' && !empty($_POST['periods'])) { + try { + foreach($_POST['periods'] as $id) { + $id = (integer) $id; + $per->delPeriodPosts($id); + } - dcPage::addSuccessNotice( - __('Periods emptied.') - ); + dcPage::addSuccessNotice( + __('Periods emptied.') + ); - http::redirect(empty($_POST['redir']) ? - $p_url.'&part=periods' : - $_POST['redir'] - ); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } + http::redirect(empty($_POST['redir']) ? + $p_url.'&part=periods' : + $_POST['redir'] + ); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } - # Combos - $sortby_combo = array( - __('Next update') => 'periodical_curdt', - __('End date') => 'periodical_enddt', - __('Frequence') => 'periodical_pub_int' - ); + # Combos + $sortby_combo = [ + __('Next update') => 'periodical_curdt', + __('End date') => 'periodical_enddt', + __('Frequence') => 'periodical_pub_int' + ]; - $order_combo = array( - __('Descending') => 'desc', - __('Ascending') => 'asc' - ); + $order_combo = [ + __('Descending') => 'desc', + __('Ascending') => 'asc' + ]; - $combo_action = array(); - $combo_action[__('empty periods')] = 'emptyperiods'; - $combo_action[__('delete periods')] = 'deleteperiods'; + $combo_action = []; + $combo_action[__('empty periods')] = 'emptyperiods'; + $combo_action[__('delete periods')] = 'deleteperiods'; - # Filters - $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'periodical_curdt'; - $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; + # Filters + $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'periodical_curdt'; + $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; - $show_filters = false; + $show_filters = false; - $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; - $nb_per_page = 30; + $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; + $nb_per_page = 30; - if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { - if ($nb_per_page != $_GET['nb']) { - $show_filters = true; - } - $nb_per_page = (integer) $_GET['nb']; - } + if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { + if ($nb_per_page != $_GET['nb']) { + $show_filters = true; + } + $nb_per_page = (integer) $_GET['nb']; + } - $params['limit'] = array((($page-1)*$nb_per_page), $nb_per_page); + $params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page]; - if ($sortby !== '' && in_array($sortby, $sortby_combo)) { - if ($order !== '' && in_array($order, $order_combo)) { - $params['order'] = $sortby.' '.$order; - } - - if ($sortby != 'periodical_curdt' || $order != 'desc') { - $show_filters = true; - } - } + if ($sortby !== '' && in_array($sortby, $sortby_combo)) { + if ($order !== '' && in_array($order, $order_combo)) { + $params['order'] = $sortby . ' ' . $order; + } + + if ($sortby != 'periodical_curdt' || $order != 'desc') { + $show_filters = true; + } + } - # Get periods - try { - $periods = $per->getPeriods($params); - $counter = $per->getPeriods($params,true); - $period_list = new adminPeriodicalList($core,$periods,$counter->f(0)); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } + # Get periods + try { + $periods = $per->getPeriods($params); + $counter = $per->getPeriods($params, true); + $period_list = new adminPeriodicalList($core, $periods, $counter->f(0)); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } - # Display - echo - ''.__('Periodical').''. - dcPage::jsLoad( - 'index.php?pf=periodical/js/periodsfilter.js' - ). - '\n". - ''. - ''. + # Display + echo + '' . __('Periodical') . '' . + dcPage::jsLoad( + 'index.php?pf=periodical/js/periodsfilter.js' + ) . + '\n" . + '' . + '' . - dcPage::breadcrumb( - array( - html::escapeHTML($core->blog->name) => '', - __('Periodical') => '' - ) - ). - dcPage::notices(). + dcPage::breadcrumb( + [ + html::escapeHTML($core->blog->name) => '', + __('Periodical') => '' + ] + ) . + dcPage::notices() . - '

- '.__('New period').' -

'; + '

+ ' . __('New period') . ' +

'; - # Filter - echo - '
'. + # Filter + echo + '' . - '

'. - __('Show filters and display options'). - '

'. + '

' . + __('Show filters and display options') . + '

' . - '
'. + '
' . - '
'. - '

'. - form::combo('sortby', $sortby_combo, $sortby).'

'. - '
'. + '
' . + '

' . + form::combo('sortby', $sortby_combo, $sortby) . '

' . + '
' . - '
'. - '

'. - form::combo('order', $order_combo, $order).'

'. - '
'. + '
' . + '

' . + form::combo('order', $order_combo, $order) . '

' . + '
' . - '
'. - '

'. - form::field('nb', 3, 3, $nb_per_page).'

'. - '
'. + '
' . + '

' . + form::field('nb', 3, 3, $nb_per_page) . '

' . + '
' . - '
'. + '
' . - '

'. - ''. - form::hidden(array('p'), 'periodical'). - form::hidden(array('part'), 'periods'). - '
'. //Opera sucks - '

'. + '

' . + '' . + form::hidden(['p'], 'periodical') . + form::hidden(['part'], 'periods') . + '
' . //Opera sucks + '

' . - '
'; + ''; - # Posts list - echo $period_list->periodDisplay($page, $nb_per_page, - '
'. + # Posts list + echo $period_list->periodDisplay($page, $nb_per_page, + '' . - '%s'. + '%s' . - '
'. - '

'. + '
' . + '

' . - '

'.__('Selected periods action:').' '. - form::combo('action', $combo_action). - '

'. - form::hidden(array('sortby'), $sortby). - form::hidden(array('order'), $order). - form::hidden(array('page'), $page). - form::hidden(array('nb'), $nb_per_page). - form::hidden(array('p'), 'periodical'). - form::hidden(array('part'), 'periods'). - $core->formNonce(). - '
'. - '' - ); + '

' . __('Selected periods action:') . ' ' . + form::combo('action', $combo_action) . + '

' . + form::hidden(['sortby'], $sortby) . + form::hidden(['order'], $order) . + form::hidden(['page'], $page) . + form::hidden(['nb'], $nb_per_page) . + form::hidden(['p'], 'periodical') . + form::hidden(['part'], 'periods') . + $core->formNonce() . + '
' . + '' + ); } @@ -835,10 +812,10 @@ dcPage::helpBlock('periodical'); # Page footer echo '

-'.__('Configuration').' - -periodical - '.$core->plugins->moduleInfo('periodical', 'version').'  -'.__('periodical').' +' . __('Configuration') . ' - +periodical - '. $core->plugins->moduleInfo('periodical', 'version') . '  +' . __('periodical') . '

-'; +'; \ No newline at end of file diff --git a/locales/en/help/help.html b/locales/en/help/help.html index 319e121..448a202 100644 --- a/locales/en/help/help.html +++ b/locales/en/help/help.html @@ -10,9 +10,8 @@

If you want some help or contribute to the plugin periodical, follow these links.

diff --git a/locales/en/resources.php b/locales/en/resources.php index 996a871..71c7abb 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -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'; \ No newline at end of file diff --git a/locales/fr/help/help.html b/locales/fr/help/help.html index acda6a4..372d637 100644 --- a/locales/fr/help/help.html +++ b/locales/fr/help/help.html @@ -10,9 +10,8 @@

Si vous souhaitez plus d'aide ou apporter votre contribution à l'extension periodical, voici quelques liens utiles.

diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 996a871..71c7abb 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -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'; \ No newline at end of file