diff --git a/_admin.php b/_admin.php index fb78a55..64b4915 100644 --- a/_admin.php +++ b/_admin.php @@ -1,16 +1,15 @@ addBehavior( ); if (dcCore::app()->blog->settings->periodical->periodical_active) { - dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Periodical'), dcCore::app()->adminurl->get('admin.plugin.periodical'), @@ -94,14 +92,14 @@ dcCore::app()->addBehavior( class adminPeriodical { public static $combo_period = null; - protected static $per = null; + protected static $per = null; public static function sortbyCombo() { return [ __('Next update') => 'periodical_curdt', __('End date') => 'periodical_enddt', - __('Frequence') => 'periodical_pub_int' + __('Frequence') => 'periodical_pub_int', ]; } @@ -110,19 +108,20 @@ class adminPeriodical if (self::$per === null) { self::$per = new periodical(); } + return self::$per; } /** * Add settings to blog preference - * + * * @param dcSettings $blog_settings dcSettings instance */ public static function adminBlogPreferencesForm(dcSettings $blog_settings) { - $s_active = (boolean) $blog_settings->periodical->periodical_active; - $s_upddate = (boolean) $blog_settings->periodical->periodical_upddate; - $s_updurl = (boolean) $blog_settings->periodical->periodical_updurl; + $s_active = (bool) $blog_settings->periodical->periodical_active; + $s_upddate = (bool) $blog_settings->periodical->periodical_upddate; + $s_updurl = (bool) $blog_settings->periodical->periodical_updurl; echo '
'. + '
' . dcCore::app()->formNonce() . $pa->getHiddenFields() . form::hidden(['action'], 'periodical_add') . @@ -398,7 +398,7 @@ class adminPeriodical /** * Add form to post sidebar - * + * * @param ArrayObject $main_items Main items * @param ArrayObject $sidebar_items Sidebar items * @param record $post Post record or null @@ -408,18 +408,17 @@ class adminPeriodical # Get existing linked period $period = ''; if ($post) { - $rs = self::period()->getPosts(['post_id' => $post->post_id]); + $rs = self::period()->getPosts(['post_id' => $post->post_id]); $period = $rs->isEmpty() ? '' : $rs->periodical_id; } # Set linked period form items - $sidebar_items['options-box']['items']['period'] = - self::formPeriod($period); + $sidebar_items['options-box']['items']['period'] = self::formPeriod($period); } /** * Save linked period - * + * * @param cursor $cur Current post cursor * @param integer $post_id Post id */ @@ -438,11 +437,11 @@ class adminPeriodical /** * Posts period form field - * + * * @param string $period Period - * @return string Period form content + * @return null|string Period form content */ - protected static function formPeriod($period='') + protected static function formPeriod($period = '') { $combo = self::comboPeriod(); @@ -450,7 +449,7 @@ class adminPeriodical return null; } - return + return '
' . form::combo('periodical', $combo, $period) . @@ -459,23 +458,22 @@ class adminPeriodical /** * Combo of available periods - * + * * @return array List of period */ protected static function comboPeriod() { if (adminPeriodical::$combo_period === null) { - $periods = self::period()->getPeriods(); + $periods = self::period()->getPeriods(); + adminPeriodical::$combo_period = []; - if ($periods->isEmpty()) { - adminPeriodical::$combo_period = []; - } else { + if (!$periods->isEmpty()) { $combo = ['-' => '']; while ($periods->fetch()) { $combo[html::escapeHTML($periods->periodical_title)] = $periods->periodical_id; } + adminPeriodical::$combo_period = $combo; } - adminPeriodical::$combo_period = $combo; } return adminPeriodical::$combo_period; @@ -483,7 +481,7 @@ class adminPeriodical /** * Remove period from posts. - * + * * @param integer $post_id Post id */ protected static function delPeriod($post_id) @@ -492,13 +490,13 @@ class adminPeriodical return null; } - $post_id = (integer) $post_id; + $post_id = (int) $post_id; self::period()->delPost($post_id); } /** * Add period to posts - * + * * @param integer $post_id Post id * @param array $period Period */ @@ -517,9 +515,9 @@ class adminPeriodical return null; } - $post_id = (integer) $post_id; + $post_id = (int) $post_id; # Add relation self::period()->addPost($period->periodical_id, $post_id); } -} \ No newline at end of file +} diff --git a/_define.php b/_define.php index 3cf8417..115e6c3 100644 --- a/_define.php +++ b/_define.php @@ -1,16 +1,15 @@ registerModule( dcAuth::PERMISSION_CONTENT_ADMIN, ]), 'usage,contentadmin', - 'type' => 'plugin', - 'support' => 'https://github.com/JcDenis/periodical', - 'details' => 'https://plugins.dotaddict.org/dc2/details/periodical', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/periodical/master/dcstore.xml', - 'settings' => [ - 'blog' => '#params.periodical_params' - ] + 'type' => 'plugin', + 'support' => 'https://github.com/JcDenis/periodical', + 'details' => 'https://plugins.dotaddict.org/dc2/details/periodical', + 'repository' => 'https://raw.githubusercontent.com/JcDenis/periodical/master/dcstore.xml', + 'settings' => [ + 'blog' => '#params.periodical_params', + ], ] -); \ No newline at end of file +); diff --git a/_install.php b/_install.php index a57f797..6524348 100644 --- a/_install.php +++ b/_install.php @@ -1,21 +1,20 @@ plugins->moduleInfo('periodical', 'version'); $old_version = dcCore::app()->getVersion('periodical'); @@ -25,33 +24,35 @@ if (version_compare($old_version, $new_version, '>=')) { try { # Check Dotclear version - if (!method_exists('dcUtils', 'versionsCompare') + if (!method_exists('dcUtils', 'versionsCompare') || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false) ) { throw new Exception(sprintf( - '%s requires Dotclear %s', 'periodical', $dc_min + '%s requires Dotclear %s', + 'periodical', + $dc_min )); } # Tables - $t = new dbStruct(dcCore::app()->con,dcCore::app()->prefix); + $t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); # Table principale des sondages $t->periodical - ->periodical_id ('bigint', 0, false) + ->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) + ->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'); - $ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); + $ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $changes = $ti->synchronize($t); # Settings @@ -70,4 +71,4 @@ try { dcCore::app()->error->add($e->getMessage()); } -return false; \ No newline at end of file +return false; diff --git a/_prepend.php b/_prepend.php index 43a3de5..db30048 100644 --- a/_prepend.php +++ b/_prepend.php @@ -1,21 +1,20 @@ autoload(['periodical' => __DIR__ . '/inc/class.periodical.php']); +Clearbricks::lib()->autoload(['periodical' => __DIR__ . '/inc/class.periodical.php']); # Admin list and pagers -Clearbricks::lib()->autoload(['adminPeriodicalList' => __DIR__ . '/inc/lib.index.pager.php']); \ No newline at end of file +Clearbricks::lib()->autoload(['adminPeriodicalList' => __DIR__ . '/inc/lib.index.pager.php']); diff --git a/_public.php b/_public.php index ff8dd2d..2db10e2 100644 --- a/_public.php +++ b/_public.php @@ -1,16 +1,15 @@ url->type, ['default', 'feed'])) { return null; } -dcCore::app()->blog->settings->addNamespace('periodical'); +dcCore::app()->blog->settings->addNamespace('periodical'); dcCore::app()->addBehavior( 'publicBeforeDocumentV2', @@ -35,18 +34,17 @@ class publicPeriodical { /** * Publish periodical - * */ public static function publicBeforeDocument() { try { $per = new periodical(); - $s = dcCore::app()->blog->settings->periodical; + $s = dcCore::app()->blog->settings->periodical; $per->lockUpdate(); # Get periods - $periods = dcCore::app()->auth->sudo([$per, 'getPeriods']); + $periods = dcCore::app()->auth->sudo([$per, 'getPeriods']); # No period if ($periods->isEmpty()) { @@ -55,14 +53,14 @@ class publicPeriodical return null; } - $now = dt::toUTC(time()); + $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 = dcCore::app()->con->openCursor(dcCore::app()->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); @@ -77,9 +75,10 @@ class publicPeriodical # Calculate nb of posts to get $loop_tz = $cur_tz; - $limit = 0; + $limit = 0; + try { - while(1) { + while (1) { if ($loop_tz > $max_tz) { break; } @@ -92,18 +91,18 @@ class publicPeriodical # If period need update if ($limit > 0) { # Get posts to publish related to this period - $posts_params = []; + $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 = dcCore::app()->auth->sudo([$per, 'getPosts'], $posts_params); + $posts = dcCore::app()->auth->sudo([$per, 'getPosts'], $posts_params); if (!$posts->isEmpty()) { $cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'post'); - while($posts->fetch()) { + while ($posts->fetch()) { # Publish post with right date $cur_post->clean(); $cur_post->post_status = 1; @@ -139,7 +138,6 @@ class publicPeriodical # --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry dcCore::app()->callBehavior('periodicalAfterPublishedPeriodicalEntry', $posts, $periods); - } dcCore::app()->blog->triggerBlog(); } @@ -156,9 +154,11 @@ class publicPeriodical } $per->unlockUpdate(); } catch (Exception $e) { - $per->unlockUpdate(); + if (isset($per)) { + $per->unlockUpdate(); + } return null; } } -} \ No newline at end of file +} diff --git a/inc/class.periodical.php b/inc/class.periodical.php index caf80f2..71192f7 100644 --- a/inc/class.periodical.php +++ b/inc/class.periodical.php @@ -1,17 +1,16 @@ con = dcCore::app()->con; $this->table = dcCore::app()->con->escape(dcCore::app()->prefix . 'periodical'); - $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); + $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); } public function openCursor() @@ -47,8 +46,7 @@ class periodical if (!empty($params['columns']) && is_array($params['columns'])) { $q .= implode(', ', $params['columns']) . ', '; } - $q .= - 'T.periodical_title, T.periodical_tz, ' . + $q .= 'T.periodical_title, T.periodical_tz, ' . 'T.periodical_curdt, T.periodical_enddt, ' . 'T.periodical_pub_int, T.periodical_pub_nb '; } @@ -73,7 +71,7 @@ class periodical 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['periodical_id'] = [(int) $params['periodical_id']]; } $q .= 'AND T.periodical_id ' . $this->con->in($params['periodical_id']); } @@ -81,11 +79,11 @@ class periodical $q .= "AND T.periodical_title = '" . $this->con->escape($params['periodical_title']) . "' "; } if (!empty($params['sql'])) { - $q .= $params['sql'].' '; + $q .= $params['sql'] . ' '; } if (!$count_only) { if (!empty($params['order'])) { - $q .= 'ORDER BY ' . $this->con->escape($params['order']).' '; + $q .= 'ORDER BY ' . $this->con->escape($params['order']) . ' '; } else { $q .= 'ORDER BY T.periodical_id ASC '; } @@ -109,42 +107,44 @@ class periodical 'SELECT MAX(periodical_id) FROM ' . $this->table )->f(0) + 1; - $cur->periodical_id = $id; - $cur->blog_id = $this->blog; + $cur->periodical_id = $id; + $cur->blog_id = $this->blog; $cur->periodical_type = 'post'; - $cur->periodical_tz = dcCore::app()->auth->getInfo('user_tz'); + $cur->periodical_tz = dcCore::app()->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) + public function updPeriod($period_id, $cur) { - $period_id = (integer) $period_id; + $period_id = (int) $period_id; - if ($cur->periodical_tz == '' + if ($cur->periodical_tz == '' && ($cur->periodical_curdt != '' || $cur->periodical_enddt != '')) { $cur->periodical_tz = dcCore::app()->auth->getInfo('user_tz'); } $cur->update( "WHERE blog_id = '" . $this->blog . "' " . - "AND periodical_id = " . $period_id . " " + 'AND periodical_id = ' . $period_id . ' ' ); } # Delete a period public function delPeriod($period_id) { - $period_id = (integer) $period_id; + $period_id = (int) $period_id; - $params = []; + $params = []; $params['periodical_id'] = $period_id; - $params['post_status'] = ''; - $rs = $this->getPosts($params); + $params['post_status'] = ''; + $rs = $this->getPosts($params); if (!$rs->isEmpty()) { throw new Exception('Periodical is not empty'); @@ -153,16 +153,16 @@ class periodical $this->con->execute( 'DELETE FROM ' . $this->table . ' ' . "WHERE blog_id = '" . $this->blog . "' " . - "AND periodical_id = " . $period_id . " " + '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; + $params = []; + $params['post_status'] = ''; + $params['periodical_id'] = (int) $period_id; $rs = $this->getPosts($params); @@ -170,9 +170,8 @@ class periodical return; } - $ids = array(); - while($rs->fetch()) - { + $ids = []; + while ($rs->fetch()) { $ids[] = $rs->post_id; } @@ -183,7 +182,7 @@ class periodical $this->con->execute( 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' . "WHERE meta_type = 'periodical' " . - "AND post_id " . $this->con->in($ids) + 'AND post_id ' . $this->con->in($ids) ); } @@ -220,9 +219,9 @@ class periodical if (!empty($params['periodical_id'])) { if (is_array($params['periodical_id'])) { - array_walk($params['periodical_id'], function ($v) { if ($v !== null) { $v = (integer) $v; } }); + array_walk($params['periodical_id'], function ($v) { if ($v !== null) { $v = (int) $v; } }); } else { - $params['periodical_id'] = [(integer) $params['periodical_id']]; + $params['periodical_id'] = [(int) $params['periodical_id']]; } $params['sql'] .= 'AND T.periodical_id ' . $this->con->in($params['periodical_id']); unset($params['periodical_id']); @@ -230,7 +229,7 @@ class periodical if (dcCore::app()->auth->check('admin', dcCore::app()->blog->id)) { if (isset($params['post_status'])) { if ($params['post_status'] != '') { - $params['sql'] .= 'AND P.post_status = ' . (integer) $params['post_status'] . ' '; + $params['sql'] .= 'AND P.post_status = ' . (int) $params['post_status'] . ' '; } unset($params['post_status']); } @@ -238,7 +237,7 @@ class periodical $params['sql'] .= 'AND P.post_status = -2 '; } - $rs = dcCore::app()->blog->getPosts($params, $count_only); + $rs = dcCore::app()->blog->getPosts($params, $count_only); $rs->periodical = $this; return $rs; @@ -247,26 +246,27 @@ class periodical # Add post to periodical public function addPost($period_id, $post_id) { - $period_id = (integer) $period_id; - $post_id = (integer) $post_id; + $period_id = (int) $period_id; + $post_id = (int) $post_id; # Check if exists - $rs = $this->getPosts(array('post_id' => $post_id, 'periodical_id' => $period_id)); + $rs = $this->getPosts(['post_id' => $post_id, 'periodical_id' => $period_id]); if (!$rs->isEmpty()) { return; } - $cur = $this->con->openCursor(dcCore::app()->prefix .'meta'); + $cur = $this->con->openCursor(dcCore::app()->prefix . 'meta'); $this->con->writeLock(dcCore::app()->prefix . 'meta'); try { - $cur->post_id = $post_id; - $cur->meta_id = $period_id; + $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; } } @@ -274,24 +274,25 @@ class periodical # Delete post from periodical public function delPost($post_id) { - $post_id = (integer) $post_id; + $post_id = (int) $post_id; $this->con->execute( 'DELETE FROM ' . dcCore::app()->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 = []; $params['post_status'] = ''; - $params['sql'] = 'AND post_status != -2 '; + $params['sql'] = 'AND post_status != -2 '; if ($period_id !== null) { - $params['periodical_id'] = (integer) $period_id; + $params['periodical_id'] = (int) $period_id; } $rs = $this->getPosts($params); @@ -299,8 +300,8 @@ class periodical return; } - $ids = array(); - while($rs->fetch()) { + $ids = []; + while ($rs->fetch()) { $ids[] = $rs->post_id; } @@ -311,7 +312,7 @@ class periodical $this->con->execute( 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' . "WHERE meta_type = 'periodical' " . - "AND post_id " . $this->con->in($ids) + 'AND post_id ' . $this->con->in($ids) ); } @@ -322,41 +323,48 @@ class periodical __('twice a day') => 'halfday', __('Daily') => 'day', __('Weekly') => 'week', - __('Monthly') => 'month' + __('Monthly') => 'month', ]; } public static function getNextTime($ts, $period) { - $ts = (integer) $ts; - $e = explode(',', date('H,i,s,n,j,Y', $ts)); - switch($period) - { + $ts = (int) $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; + + break; case 'halfday': $new_ts = mktime($e[0] + 12, $e[1], $e[2], $e[3], $e[4], $e[5]); - break; + + break; case 'day': - $new_ts = mktime($e[0], $e[1] ,$e[2], $e[3], $e[4] + 1, $e[5]); - break; + $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; + + break; case 'month': $new_ts = mktime($e[0], $e[1], $e[2], $e[3] + 1, $e[4], $e[5]); - break; + + break; default: $new_ts = 0; + throw new Exception(__('Unknow frequence')); - break; + + break; } + return $new_ts; } @@ -366,14 +374,14 @@ class periodical try { # Need flock function if (!function_exists('flock')) { - throw New Exception("Can't call php function named 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); + $f_md5 = md5($this->blog); $cached_file = sprintf( '%s/%s/%s/%s/%s.txt', DC_TPL_CACHE, @@ -386,30 +394,32 @@ class periodical $cached_file = path::real($cached_file, false); # Make dir if (!is_dir(dirname($cached_file))) { - files::makeDir(dirname($cached_file), true); + files::makeDir(dirname($cached_file), true); } # Make file if (!file_exists($cached_file)) { !$fp = @fopen($cached_file, 'w'); if ($fp === false) { - throw New Exception("Can't create file"); + 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"); + throw new Exception("Can't open file"); } # Lock file if (!flock($fp, LOCK_EX)) { - throw New Exception("Can't lock file"); + throw new Exception("Can't lock file"); } $this->lock = $fp; + return true; } catch (Exception $e) { throw $e; } + return false; } @@ -418,4 +428,4 @@ class periodical @fclose($this->lock); $this->lock = null; } -} \ No newline at end of file +} diff --git a/inc/index.period.php b/inc/index.period.php index 02b4405..cb00293 100644 --- a/inc/index.period.php +++ b/inc/index.period.php @@ -1,16 +1,15 @@ auth->makePermissions([dcAuth::PERMISSION_USAGE, dc $per = new periodical(); # Default values -$action = isset($_POST['action']) ? $_POST['action'] : ''; +$action = $_POST['action'] ?? ''; $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', time()); -$period_enddt = date('Y-m-d H:i', time() + 31536000); //one year +$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', time()); +$period_enddt = date('Y-m-d H:i', time() + 31536000); //one year $bad_period_curdt = false; $bad_period_enddt = false; # Get period if (!empty($_REQUEST['period_id'])) { $rs = $per->getPeriods([ - 'periodical_id' => $_REQUEST['period_id'] + 'periodical_id' => $_REQUEST['period_id'], ]); if ($rs->isEmpty()) { dcCore::app()->error->add(__('This period does not exist.')); @@ -60,9 +59,9 @@ if ($action == 'setperiod') { $period_title = $_POST['period_title']; } if (!empty($_POST['period_pub_nb'])) { - $period_pub_nb = abs((integer) $_POST['period_pub_nb']); + $period_pub_nb = abs((int) $_POST['period_pub_nb']); } - if (!empty($_POST['period_pub_int']) + if (!empty($_POST['period_pub_int']) && in_array($_POST['period_pub_int'], $per->getTimesCombo()) ) { $period_pub_int = $_POST['period_pub_int']; @@ -96,10 +95,10 @@ if ($action == 'setperiod') { # Check period title and dates $old_titles = $per->getPeriods([ - 'periodical_title' => $period_title + 'periodical_title' => $period_title, ]); if (!$old_titles->isEmpty()) { - while($old_titles->fetch()) { + while ($old_titles->fetch()) { if (!$period_id || $old_titles->periodical_id != $period_id) { dcCore::app()->error->add(__('Period title is already taken')); } @@ -114,7 +113,7 @@ if ($action == 'setperiod') { # If no error, set period if (!dcCore::app()->error->flag()) { - $cur = $per->openCursor(); + $cur = $per->openCursor(); $cur->periodical_title = $period_title; $cur->periodical_curdt = $period_curdt; $cur->periodical_enddt = $period_enddt; @@ -150,8 +149,8 @@ if (!dcCore::app()->error->flag() && $period_id && $action && !empty($_POST['per # Publish posts if ($action == 'publish') { try { - foreach($_POST['periodical_entries'] as $id) { - $id = (integer) $id; + foreach ($_POST['periodical_entries'] as $id) { + $id = (int) $id; dcCore::app()->blog->updPostStatus($id, 1); $per->delPost($id); } @@ -173,9 +172,9 @@ if (!dcCore::app()->error->flag() && $period_id && $action && !empty($_POST['per # Unpublish posts if ($action == 'unpublish') { try { - foreach($_POST['periodical_entries'] as $id) { - $id = (integer) $id; - dcCore::app()->blog->updPostStatus($id,0); + foreach ($_POST['periodical_entries'] as $id) { + $id = (int) $id; + dcCore::app()->blog->updPostStatus($id, 0); $per->delPost($id); } @@ -196,8 +195,8 @@ if (!dcCore::app()->error->flag() && $period_id && $action && !empty($_POST['per # Remove posts from periodical if ($action == 'remove_post_periodical') { try { - foreach($_POST['periodical_entries'] as $id) { - $id = (integer) $id; + foreach ($_POST['periodical_entries'] as $id) { + $id = (int) $id; $per->delPost($id); } @@ -222,22 +221,21 @@ if ($period_id) { $post_filter = new adminPostFilter(); $post_filter->add('part', 'period'); - $params = $post_filter->params(); + $params = $post_filter->params(); $params['periodical_id'] = $period_id; $params['no_content'] = true; # Get posts try { - $posts = $per->getPosts($params); - $counter = $per->getPosts($params, true); + $posts = $per->getPosts($params); + $counter = $per->getPosts($params, true); $post_list = new adminPeriodicalList(dcCore::app(), $posts, $counter->f(0)); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } - $starting_script = - dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) . - $post_filter->js(dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts'); + $starting_script = dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) . + $post_filter->js(dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&') . '#posts'); } # Display @@ -252,9 +250,9 @@ dcPage::jsPageTabs() . echo dcPage::breadcrumb([ - __('Plugins') => '', - __('Periodical') => dcCore::app()->admin->getPageURL() . '&part=periods', - (null === $period_id ? __('New period') : __('Edit period')) => '' + __('Plugins') => '', + __('Periodical') => dcCore::app()->admin->getPageURL() . '&part=periods', + (null === $period_id ? __('New period') : __('Edit period')) => '', ]) . dcPage::notices(); @@ -278,12 +276,12 @@ form::datetime('period_curdt', [ form::datetime('period_enddt', [ 'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', strtotime($period_enddt))), 'class' => ($bad_period_enddt ? 'invalid' : ''), -]) .'
+]) . '' . -form::combo('period_pub_int',$per->getTimesCombo(), $period_pub_int) . '
+form::combo('period_pub_int', $per->getTimesCombo(), $period_pub_int) . '' . form::number('period_pub_nb', ['min' => 1, 'max' => 20, 'default' => $period_pub_nb]) . '
@@ -295,22 +293,21 @@ form::number('period_pub_nb', ['min' => 1, 'max' => 20, 'default' => $period_pub dcCore::app()->formNonce() . form::hidden(['action'], 'setperiod') . form::hidden(['period_id'], $period_id) . -form::hidden(['part'], 'period') .' +form::hidden(['part'], 'period') . '