/** * The callback that adds Twitter metabox content * @param object $post The post object * @return void Displays the metabox content */ function ppp_tw_add_metabox_content($post) { global $ppp_options, $ppp_share_settings; $default_text = !empty($ppp_options['default_text']) ? $ppp_options['default_text'] : __('Social Text', 'ppp-txt'); $ppp_post_exclude = get_post_meta($post->ID, '_ppp_post_exclude', true); $ppp_share_on_publish = get_post_meta($post->ID, '_ppp_share_on_publish', true); $show_share_on_publish = false; $share_by_default = empty($ppp_share_settings['twitter']['share_on_publish']) ? false : true; if ($ppp_share_on_publish == '1' || $ppp_share_on_publish == '' && $share_by_default) { $show_share_on_publish = true; } $ppp_share_on_publish_text = get_post_meta($post->ID, '_ppp_share_on_publish_text', true); $ppp_share_on_publish_include_image = get_post_meta($post->ID, '_ppp_share_on_publish_include_image', true); ?> <p> <p> <?php $disabled = $post->post_status === 'publish' && time() > strtotime($post->post_date) ? true : false; ?> <input <?php if ($disabled) { ?> readonly<?php } ?> type="checkbox" name="_ppp_share_on_publish" id="ppp_share_on_publish" value="1" <?php checked(true, $show_share_on_publish, true); ?> /> <label for="ppp_share_on_publish"><?php _e('Tweet this post at the time of publishing?', 'ppp-txt'); ?> </label> <p class="ppp_share_on_publish_text"<?php if (false === $show_share_on_publish) { ?> style="display: none;"<?php } ?> > <input <?php if ($disabled) { ?> readonly<?php } ?> class="ppp-share-text" type="text" placeholder="<?php echo esc_attr($default_text); ?> " name="_ppp_share_on_publish_text" <?php if (isset($ppp_share_on_publish_text)) { ?> value="<?php echo esc_attr($ppp_share_on_publish_text); ?> "<?php } ?> <?php $length = !empty($ppp_share_on_publish_text) ? strlen($ppp_share_on_publish_text) : 0; ?> /> <span class="ppp-text-length"><?php echo $length; ?> </span> <br /> <span> <input class="ppp-tw-featured-image-input" <?php if ($disabled) { ?> readonly<?php } ?> id="ppp-share-on-publish-image" type="checkbox" name="_ppp_share_on_publish_include_image" value="1" <?php checked('1', $ppp_share_on_publish_include_image, true); ?> /> <label for="ppp-share-on-publish-image"><?php _e('Attach Featured Image In Tweet', 'ppp-txt'); ?> </label> </span> </p> </p> <div class="ppp-post-override-wrap"> <p><h3><?php _e('Scheduled Tweets', 'ppp-txt'); ?> </h3></p> <div id="ppp-tweet-fields" class="ppp-tweet-fields"> <input type="hidden" id="edd-variable-prices" class="edd-variable-prices-name-field" value=""/> <div id="ppp-tweet-fields" class="ppp-meta-table-wrap"> <table class="widefat ppp-repeatable-table" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th style="width: 100px"><?php _e('Date', 'ppp-txt'); ?> </th> <th style="width: 75px;"><?php _e('Time', 'ppp-txt'); ?> </th> <th><?php _e('Text', 'ppp-txt'); ?> </th> <th style"width: 200px;"><?php _e('Image', 'ppp-txt'); ?> </th> <th style="width: 10px;"></th> </tr> </thead> <tbody> <?php $tweets = get_post_meta($post->ID, '_ppp_tweets', true); ?> <?php if (!empty($tweets)) { ?> <?php foreach ($tweets as $key => $value) { $date = isset($value['date']) ? $value['date'] : ''; $time = isset($value['time']) ? $value['time'] : ''; $text = isset($value['text']) ? $value['text'] : ''; $image = isset($value['image']) ? $value['image'] : ''; $attachment_id = isset($value['attachment_id']) ? $value['attachment_id'] : ''; $args = apply_filters('ppp_tweet_row_args', compact('date', 'time', 'text', 'image', 'attachment_id'), $value); ?> <?php ppp_render_tweet_row($key, $args, $post->ID); ?> <?php } ?> <?php } else { ?> <?php ppp_render_tweet_row(1, array('date' => '', 'time' => '', 'text' => '', 'image' => '', 'attachment_id' => ''), $post->ID, 1); ?> <?php } ?> <tr> <td class="submit" colspan="4" style="float: none; clear:both; background:#fff;"> <a class="button-secondary ppp-add-repeatable" style="margin: 6px 0;"><?php _e('Add New Tweet', 'ppp-txt'); ?> </a> </td> </tr> </tbody> </table> </div> </div><!--end #edd_variable_price_fields--> <p><?php _e('Do not include links in your text, this will be added automatically.', 'ppp-txt'); ?> </p> <p style="display: none;" id="ppp-show-conflict-warning"><?php printf(__('Items highlighted in red have a time assigned that is within %d minutes of an already scheduled Tweet', 'ppp-txt'), floor(ppp_get_default_conflict_window() / 60)); ?> </p> </div> </p> <?php }
/** * Given a time, see if there are any tweets scheduled within the range of the within * * @since 2.2.3 * @param int $time The timestamp to check for * @param int $within The number of seconds to check, before and after a given time * @return bool If there are any tweets scheduled within this timeframe * */ function ppp_has_cron_within($time = 0, $within = 0) { if (empty($time)) { $time = current_time('timestamp'); } if (empty($within)) { $within = ppp_get_default_conflict_window(); } $crons = ppp_get_shceduled_crons(); if (empty($crons)) { return false; } $scheduled_times = wp_list_pluck($crons, 'timestamp'); $found_time = false; foreach ($scheduled_times as $key => $scheduled_time) { $found_time = ppp_is_time_within($scheduled_time, $time, $within); if ($found_time) { break; } } return $found_time; }