diff --git a/inc/index.period.php b/inc/index.period.php
new file mode 100644
index 0000000..2e27545
--- /dev/null
+++ b/inc/index.period.php
@@ -0,0 +1,338 @@
+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));
+ }
+}
+
+# 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.')
+ );
+ }
+
+ if (!empty($_POST['redir'])) {
+ http::redirect($_POST['redir']);
+ } else {
+ $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period');
+ }
+ }
+}
+
+# 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.')
+ );
+
+ if (!empty($_POST['redir'])) {
+ http::redirect($_POST['redir']);
+ } else {
+ $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
+ }
+ } 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.')
+ );
+
+ if (!empty($_POST['redir'])) {
+ http::redirect($_POST['redir']);
+ } else {
+ $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
+ }
+ } 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.')
+ );
+
+ if (!empty($_POST['redir'])) {
+ http::redirect($_POST['redir']);
+ } else {
+ $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ }
+}
+
+# Prepare combos for posts list
+if ($period_id) {
+ # Filters
+ $post_filter = new adminPostFilter($core);
+ $post_filter->add('part', 'period');
+
+ $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);
+ $post_list = new adminPeriodicalList($core, $posts, $counter->f(0));
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+
+ $starting_script =
+ dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) .
+ $post_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts');
+}
+
+# Display
+echo '
+
' . __('Periodical') . '' .
+dcPage::jsLoad(dcPage::getPF('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 '
+' . (null === $period_id ? __('New period') : __('Edit period')) . '
+
+
';
+
+if ($period_id && !$core->error->flag()) {
+
+ # Actions combo box
+ $combo_action = [];
+ $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=' . $post_filter->user_id .
+ '&cat_id=' . $post_filter->cat_id .
+ '&status=' . $post_filter->status .
+ '&selected=' . $post_filter->selected .
+ '&attachment=' . $post_filter->attachment .
+ '&month=' . $post_filter->month .
+ '&lang=' . $post_filter->lang .
+ '&sortby=' . $post_filter->sortby .
+ '&order=' . $post_filter->order .
+ '&nb=' . $post_filter->nb .
+ '&page=%s' .
+ '#posts';
+
+ echo '
+ ' . __('Entries linked to this period') . '
';
+
+ # Filters
+ $post_filter->display(['admin.plugin.periodical', '#posts'],
+ $core->adminurl->getHiddenFormFields('admin.plugin.periodical', [
+ 'period_id' => $period_id,
+ 'part' => 'period'
+ ])
+ );
+
+ # Posts list
+ $post_list->postDisplay($post_filter, $base_url,
+ '
'
+ );
+
+ echo
+ '
';
+}
+
+dcPage::helpBlock('periodical');
+
+echo '';
\ No newline at end of file
diff --git a/inc/index.periods.php b/inc/index.periods.php
new file mode 100644
index 0000000..a131288
--- /dev/null
+++ b/inc/index.periods.php
@@ -0,0 +1,131 @@
+delPeriodPosts($id);
+ $per->delPeriod($id);
+ }
+
+ dcPage::addSuccessNotice(
+ __('Periods removed.')
+ );
+
+ if (!empty($_POST['redir'])) {
+ http::redirect($_POST['redir']);
+ } else {
+ $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
+ }
+ } 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.')
+ );
+
+ if (!empty($_POST['redir'])) {
+ http::redirect($_POST['redir']);
+ } else {
+ $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
+ }
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+}
+
+$combo_action = [
+ __('empty periods') => 'emptyperiods',
+ __('delete periods') => 'deleteperiods'
+];
+
+# Filters
+$p_filter = new adminGenericFilter($core, 'periodical');
+$p_filter->add('part', 'periods');
+
+$params = $p_filter->params();
+
+# 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(dcPage::getPF('periodical/js/checkbox.js')) .
+$p_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) .
+'' .
+'' .
+
+dcPage::breadcrumb([
+ html::escapeHTML($core->blog->name) => '',
+ __('Periodical') => ''
+]) .
+dcPage::notices() .
+
+'
+' . __('New period') . '
+
';
+
+# Filters
+$p_filter->display('admin.plugin.periodical', form::hidden('p', 'periodical') . form::hidden('part', 'periods'));
+
+# Periods list
+$period_list->periodDisplay($p_filter,
+ ''
+);
+
+dcPage::helpBlock('periodical');
+
+echo '';
\ No newline at end of file
diff --git a/index.php b/index.php
index aec75d1..387026b 100644
--- a/index.php
+++ b/index.php
@@ -15,445 +15,10 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
-dcPage::check('usage,contentadmin');
-
-# Objects
-$per = new periodical($core);
-
-# Default values
-$action = isset($_POST['action']) ? $_POST['action'] : '';
-
-############################################################
-#
-# One period
-#
-############################################################
-
-if ($_REQUEST['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([
- '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));
- }
- }
-
- # 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.')
- );
- }
-
- if (!empty($_POST['redir'])) {
- http::redirect($_POST['redir']);
- } else {
- $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period');
- }
- }
- }
-
- # 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.')
- );
-
- if (!empty($_POST['redir'])) {
- http::redirect($_POST['redir']);
- } else {
- $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
- }
- } 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.')
- );
-
- if (!empty($_POST['redir'])) {
- http::redirect($_POST['redir']);
- } else {
- $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
- }
- } 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.')
- );
-
- if (!empty($_POST['redir'])) {
- http::redirect($_POST['redir']);
- } else {
- $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
- }
- } catch (Exception $e) {
- $core->error->add($e->getMessage());
- }
- }
- }
-
- # Prepare combos for posts list
- if ($period_id) {
- # Filters
- $post_filter = new adminPostFilter($core);
- $post_filter->add('part', 'period');
-
- $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);
- $post_list = new adminPeriodicalList($core, $posts, $counter->f(0));
- } catch (Exception $e) {
- $core->error->add($e->getMessage());
- }
-
- $starting_script =
- dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) .
- $post_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts');
- }
-
- # Display
- echo '
- ' . __('Periodical') . '' .
- dcPage::jsLoad(dcPage::getPF('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 '
- ' . (null === $period_id ? __('New period') : __('Edit period')) . '
-
-
';
-
- if ($period_id && !$core->error->flag()) {
-
- # Actions combo box
- $combo_action = [];
- $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=' . $post_filter->user_id .
- '&cat_id=' . $post_filter->cat_id .
- '&status=' . $post_filter->status .
- '&selected=' . $post_filter->selected .
- '&attachment=' . $post_filter->attachment .
- '&month=' . $post_filter->month .
- '&lang=' . $post_filter->lang .
- '&sortby=' . $post_filter->sortby .
- '&order=' . $post_filter->order .
- '&nb=' . $post_filter->nb .
- '&page=%s' .
- '#posts';
-
- echo '
- ' . __('Entries linked to this period') . '
';
-
- # Filters
- $post_filter->display(['admin.plugin.periodical', '#posts'],
- $core->adminurl->getHiddenFormFields('admin.plugin.periodical', [
- 'period_id' => $period_id,
- 'part' => 'period'
- ])
- );
-
- # Posts list
- $post_list->postDisplay($post_filter, $base_url,
- '
'
- );
-
- echo
- '
';
- }
-
-############################################################
-#
-# All periods
-#
-############################################################
+$part = !empty($_REQUEST['part']) ? $_REQUEST['part'] : 'periods';
+if ($part == 'period') {
+ include dirname(__FILE__) . '/inc/index.period.php';
} 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);
- }
-
- dcPage::addSuccessNotice(
- __('Periods removed.')
- );
-
- if (!empty($_POST['redir'])) {
- http::redirect($_POST['redir']);
- } else {
- $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
- }
- } 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.')
- );
-
- if (!empty($_POST['redir'])) {
- http::redirect($_POST['redir']);
- } else {
- $core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
- }
- } catch (Exception $e) {
- $core->error->add($e->getMessage());
- }
- }
-
- $combo_action = [
- __('empty periods') => 'emptyperiods',
- __('delete periods') => 'deleteperiods'
- ];
-
- # Filters
- $p_filter = new adminGenericFilter($core, 'periodical');
- $p_filter->add('part', 'periods');
-
- $params = $p_filter->params();
-
- # 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(dcPage::getPF('periodical/js/checkbox.js')) .
- $p_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) .
- '' .
- '' .
-
- dcPage::breadcrumb([
- html::escapeHTML($core->blog->name) => '',
- __('Periodical') => ''
- ]) .
- dcPage::notices() .
-
- '
- ' . __('New period') . '
-
';
-
- # Filters
- $p_filter->display('admin.plugin.periodical', form::hidden('p', 'periodical') . form::hidden('part', 'periods'));
-
- # Periods list
- $period_list->periodDisplay($p_filter,
- ''
- );
-
-}
-
-dcPage::helpBlock('periodical');
-
-echo '';
\ No newline at end of file
+ include dirname(__FILE__) . '/inc/index.periods.php';
+}
\ No newline at end of file