Skip to content

Commit

Permalink
Improve the Schedule date box #1632
Browse files Browse the repository at this point in the history
  • Loading branch information
olatechpro committed May 16, 2024
1 parent 03c144e commit cb63ee8
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 54 deletions.
130 changes: 89 additions & 41 deletions modules/content-board/content-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class PP_Content_Board extends PP_Module
/**
* Custom methods
*
* @var Array
* @var array
*/
private $terms_options = [];

Expand Down Expand Up @@ -150,6 +150,11 @@ public function __construct()
'content_board_custom_columns' => '',
'content_board_filters' => '',
'content_board_custom_filters' => '',

'content_board_scheduled_date' => [
'number' => 1,
'period' => 'weeks'
],

'post_types' => [
'post' => 'on',
Expand Down Expand Up @@ -190,6 +195,7 @@ public function init()
add_action('wp_ajax_publishpress_content_board_search_categories', [$this, 'sendJsonSearchCategories']);
add_action('wp_ajax_publishpress_content_board_get_form_fields', [$this, 'getFormFieldAjaxHandler']);
add_action('wp_ajax_publishpress_content_board_update_post_status', [$this, 'updatePostStatus']);
add_action('wp_ajax_publishpress_content_board_update_schedule_period', [$this, 'updateSchedulePeriod']);

// Menu
add_filter('publishpress_admin_menu_slug', [$this, 'filter_admin_menu_slug'], 20);
Expand Down Expand Up @@ -1499,7 +1505,36 @@ public function content_board_customize_filter_form() {
return ob_get_clean();

}

public function updateSchedulePeriod() {
global $publishpress;

$response['status'] = 'error';
$response['content'] = esc_html__('An error occured', 'publishpress');


if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_key($_POST['nonce']), 'content_board_action_nonce')) {
$response['content'] = esc_html__('Error validating nonce. Please reload this page and try again.', 'publishpress');
} elseif (empty($_POST['schedule_number']) || empty($_POST['schedule_period'])) {
$response['content'] = esc_html__('Invalid form request.', 'publishpress');
} else {
$schedule_number = (int) $_POST['schedule_number'];
$schedule_period = sanitize_text_field($_POST['schedule_period']);
$content_board_scheduled_date = [
'number' => $schedule_number,
'period' => $schedule_period
];
$publishpress->update_module_option($this->module->name, 'content_board_scheduled_date', $content_board_scheduled_date);
$response['status'] = 'success';
$response['content'] = esc_html__('Changes saved!', 'publishpress');
}

wp_send_json($response);
}

public function updatePostStatus() {
global $publishpress;

$response['status'] = 'error';
$response['content'] = esc_html__('An error occured', 'publishpress');

Expand All @@ -1510,7 +1545,8 @@ public function updatePostStatus() {
$response['content'] = esc_html__('Invalid form request.', 'publishpress');
} else {
$post_status = sanitize_text_field($_POST['post_status']);
$schedule_date = sanitize_text_field($_POST['schedule_date']);
$schedule_number = (int) $_POST['schedule_number'];
$schedule_period = sanitize_text_field($_POST['schedule_period']);
$post_id = (int) $_POST['post_id'];
$post_data = get_post($post_id);
if (!is_object($post_data) || !isset($post_data->post_type)) {
Expand All @@ -1531,8 +1567,16 @@ public function updatePostStatus() {
$post_args['post_date_gmt'] = get_gmt_from_date($current_date_time);
} elseif ($post_status === 'future') {
// set future date if new status is schedule
$timestamp = strtotime($schedule_date);
$current_timestamp = time();
$timestamp = strtotime($schedule_number . ' ' . $schedule_period, $current_timestamp);
$content_board_scheduled_date = [
'number' => $schedule_number,
'period' => $schedule_period
];
$publishpress->update_module_option($this->module->name, 'content_board_scheduled_date', $content_board_scheduled_date);

$future_date = date('Y-m-d H:i:s', $timestamp);

$post_args['post_date'] = $future_date;
$post_args['post_date_gmt'] = get_gmt_from_date($future_date);
}
Expand Down Expand Up @@ -2504,13 +2548,20 @@ public function printPostForPostType($postType)
$post_statuses_slugs = array_column($post_statuses, 'slug');
if (!in_array('future', $post_statuses_slugs)) {
// Add Scheduled status
$post_statuses[] = (object) [
/*$post_statuses[] = (object) [
'label' => __('Scheduled', 'publishpress'),
'description' => '',
'name' => 'future',
'slug' => 'future',
'position' => count($post_statuses) + 1
];
];*/
$post_statuses = array_merge([(object) [
'label' => __('Scheduled', 'publishpress'),
'description' => '',
'name' => 'future',
'slug' => 'future',
'position' => count($post_statuses) + 1
]], $post_statuses);
}

// Group posts by status
Expand All @@ -2531,44 +2582,41 @@ public function printPostForPostType($postType)

$post_status_options = $this->get_post_status_options($post_status_object->slug);
if ($post_status_object->slug === 'future') {
$current_time = current_time('timestamp');
$time_in_two_weeks = strtotime('+1 weeks', $current_time);
$formatted_date = date_i18n('F j, Y H:i', $time_in_two_weeks);

$metadata_start_name = 'content_board_scheduled_date';
$date_markup =
sprintf(
'<input
type="text"
id="%s"
name="%1$s"
value="%2$s"
class="date-time-pick future-date"
data-alt-field="%1$s_hidden"
data-alt-format="%3$s"
placeholder="%4$s"
autocomplete="off"
/>',
esc_attr($metadata_start_name),
esc_attr($formatted_date),
esc_attr(pp_convert_date_format_to_jqueryui_datepicker('Y-m-d H:i:s')),
''
);
$date_markup .= sprintf(
'<input
type="hidden"
name="%s_hidden"
value="%s"
/>',
esc_attr($metadata_start_name),
esc_attr($formatted_date)
);
$content_board_scheduled_date = $this->module->options->content_board_scheduled_date;
$number_select = '<select class="schedule-content-number">';
for ($i = 1; $i <= 31; $i++) {
$number_select .= '<option value="'. $i .'" '. selected($i, $content_board_scheduled_date['number'], false).'>'. $i .'</option>';
}
$number_select .= '<select>';

$period_options = ['days', 'weeks', 'months', 'years'];
$period_select = '<select class="schedule-content-period">';
foreach ($period_options as $period_option) {
$period_select .= '<option value="'. $period_option .'" '. selected($period_option, $content_board_scheduled_date['period'], false).'>'. ucfirst($period_option) .'</option>';
}
$period_select .= '<select>';

$date_markup = '<div class="metadata-item-filter">
<div class="filter-title">'. esc_html__("Default Date", "publishpress") .'</div>
<div class="filter-content">
<div class="schedule-date-options">
'. $number_select .'
'. $period_select .'
</div>
<p class="description">'. esc_html__("This is the default publish date from today for posts moving to the Scheduled status.", "publishpress") .'</p>
<div class="filter-apply">
<input type="submit" id="filter-submit" class="button button-primary" value="'. esc_html__("Apply", "publishpress") .'">
</div>
</div>
</div>';

$modal_id = time();
$output_markup = '&nbsp; <div data-target="#content_board_modal_'. esc_attr($modal_id) .'" class="co-filter">
'. esc_html__("Schedule Date", "publishpress") .'
'. esc_html__("Default Date", "publishpress") .'
</div>
<div id="content_board_modal_'. esc_attr($modal_id) .'" class="content-board-modal" style="display: none;">
<div id="content_board_modal_'. esc_attr($modal_id) .'" class="content-board-modal schedule-date-modal" style="display: none;">
<div class="content-board-modal-content">
<span class="close">&times;</span>
<div>'. $date_markup .'</div>
Expand Down Expand Up @@ -2638,11 +2686,11 @@ class="date-time-pick future-date"
$post_title = _draft_or_post_title($status_post->ID);

if ($can_edit_post) {
$title_output = '<strong class="post-title-text"><a href="'. esc_url(get_edit_post_link($status_post->ID)) . '" title="". esc_attr($post_title) ."">'. esc_html(
$title_output = '<strong class="post-title-text"><a href="'. esc_url(get_edit_post_link($status_post->ID)) . '" title="'. esc_attr($post_title) .'">'. esc_html(
$post_title
) . '</a></strong>';
} else {
$title_output = '<strong class="post-title-text" title="". esc_attr($post_title) ."">'. esc_html($post_title) . '</strong>';
$title_output = '<strong class="post-title-text" title="'. esc_attr($post_title) .'">'. esc_html($post_title) . '</strong>';
}
$statuses_content_markup .= $title_output;
$statuses_content_markup .= '</div>';
Expand Down
161 changes: 152 additions & 9 deletions modules/content-board/lib/content-board-print.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ footer,
.change-date,
#pp-content-filters .clear-filter,
.pp-content-board-manage,
.pp-version-notice-bold-purple {
.pp-version-notice-bold-purple,
.board-title-content .co-filter,
.board-title-content .content-board-modal,
.content-board-table-wrap .statuses-contents .status-content[data-counts="0"],
.content-board-table-wrap .board-content .content-item .post-action {
display: none;
}

Expand Down Expand Up @@ -104,19 +108,22 @@ a {
text-shadow: none;
}

table.content-board {
.content-board-table-wrap {
background: white;
padding: 15px;
border: 1px solid rgb( 101, 111, 125 );
border-radius: 0.5rem;
border-left-width: 1px;
margin-top: 10px;
padding-top: 5px;
}

table.content-board tr td {
border-top: 1px solid rgb(240, 241, 243);
border-bottom: 1px solid rgb(240, 241, 243);
.content-board-table-wrap .statuses-contents .content-wrap {
display: flex;
column-gap: 30px;
}

.content-board-table-wrap .statuses-contents .status-content {
width: 100%;
min-width: 234px;
max-width: 234px;
margin-right: 15px;
}

.pp-content-board-filters {
Expand All @@ -127,6 +134,142 @@ table.content-board tr td {
width: 100%;
}

.content-board-table-wrap .statuses-contents .status-content {
width: 100%;
min-width: 234px;
max-width: 234px;
margin-right: 15px;
}

.content-board-table-wrap .board-title {
width: 100%;
border-radius: .25rem .25rem;
box-shadow: 0 .0625rem .1875rem rgba(0, 0, 0, .106), 0 .0625rem .125rem -.0625rem rgba(0, 0, 0, .106);
background-color: rgb(255, 255, 255);
border-top: 2px solid;
border-top-color: rgb(135, 144, 158);
position: relative;
align-items: center;
flex-basis: 169px;
overflow: hidden;
margin-bottom: 15px;
margin-right: 20px;
}

.content-board-table-wrap .board-title .board-title-content {
display: flex;
justify-content: space-between;
padding: 12px;
padding-left: 0;
}

.content-board-table-wrap .board-title .status-title-count {
font-size: 11px;
font-weight: 500;
line-height: 1;
height: 20px;
border-radius: 20px;
display: flex;
align-items: center;
justify-content: center;
padding: 0 6px;
min-width: 25px;
background-color: transparent;
}

.content-board-table-wrap .board-title .title-text {
display: flex;
align-items: center;
overflow: hidden;
margin-right: 8px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 13px;
font-weight: 500;
line-height: 1.3;
margin: 0;
color: rgb(42, 46, 52);
text-transform: uppercase;
}

.content-board-table-wrap .statuses-contents .content-wrap {
display: flex;
column-gap: 30px;
}

.content-board-table-wrap .statuses-contents .status-content {
width: 100%;
min-width: 234px;
max-width: 234px;
margin-right: 15px;
}

.content-board-table-wrap .board-content {
width: 100%;
flex-grow: 1;
display: flex;
flex-direction: column;
}

.content-board-table-wrap .board-content .content-item {
background-color: rgb(255, 255, 255);
box-shadow: 0 .0625rem .125rem rgba(0, 0, 0, .055), 0 .0625rem .125rem rgba(0, 0, 0, .055);
border-radius: .25rem;
border: 1px solid rgb(232, 234, 237);
margin: 6px 0 6px 0;
border-end-start-radius: .25rem;
border-end-end-radius: .25rem;
}

.content-board-table-wrap .board-content .content-item .content-item-post {
padding: 7px 10px 2px;
min-width: 0;
flex-grow: 1;
}

.content-board-table-wrap .board-content .content-item .content-item-post .post-date {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: flex;
align-items: center;
margin: 0 0 7px;
font-size: 10px;
font-weight: 400;
line-height: 1.2;
color: #544d61;
}

.content-board-table-wrap .board-content .content-item .content-item-post .post-title {
margin: 0;
color: #544d61;
font-size: 0;
position: relative;
}

.content-board-table-wrap .board-content .content-item .content-item-post .post-title .post-title-text {
cursor: pointer;
font-size: .875rem;
font-weight: 500;
line-height: 1.5;
margin-right: 4px;
border-radius: 4px;
color: rgb(42, 46, 52);
}

.content-board-table-wrap .board-content .content-item .content-item-post .post-meta {
display: flex;
justify-content: space-between;
border-bottom: 1px solid rgb(240, 241, 243);
padding: 5px 0 5px 0;
color: #bcc0c7;
font-size: 13px;
color: #50575e;
column-gap: 15px;
}


.pp-content-board-filters button.clear-filter, .pp-content-board-filters button.co-filter {
white-space: nowrap;
display: inline-block;
Expand Down
Loading

0 comments on commit cb63ee8

Please sign in to comment.