コード例 #1
0
    /**
     * Load the widget code
     *
     * @since  2.2.3
     */
    public static function widget()
    {
        $number = self::get_count();
        $shares = ppp_get_shceduled_crons();
        if (!empty($shares)) {
            $limited_shares = array_slice($shares, 0, $number, true);
            ?>
			<div id="future-tweets" class="activity-block">
				<h4><?php 
            _e('Post-Related Tweets', 'ppp-tweets');
            ?>
</h4>
				<ul>
				<?php 
            foreach ($limited_shares as $key => $share) {
                $ppp_data = $share;
                $timestamp = $ppp_data['timestamp'];
                $name_parts = explode('_', $ppp_data['args'][1]);
                $service = isset($name_parts[3]) ? $name_parts[3] : 'tw';
                $builder = 'ppp_' . $service . '_build_share_message';
                $post_id = $ppp_data['args'][0];
                $date = $timestamp + get_option('gmt_offset') * 3600;
                $content = $builder($ppp_data['args'][0], $ppp_data['args'][1], false);
                $regex = "@(https?://([-\\w\\.]+[-\\w])+(:\\d+)?(/([\\w/_\\.#-]*(\\?\\S+)?[^\\.\\s])?)?)@";
                $content = preg_replace($regex, '', $content);
                ?>
					<li>
						<span class="meta"><?php 
                echo date_i18n('M jS, ' . get_option('time_format'), $date);
                ?>
</span>
						<a href="<?php 
                echo admin_url('post.php?post=' . $post_id . '&action=edit');
                ?>
"><?php 
                echo $content;
                ?>
</a>
					</li>
				<?php 
            }
            ?>
				</ul>
				<p>
					<a class="button-primary" href="<?php 
            echo admin_url('admin.php?page=ppp-schedule-info');
            ?>
"><?php 
            _e('View Full Schedule', 'ppp-txt');
            ?>
</a>
				</p>
			</div>
			<?php 
        } else {
            $args = array('numberposts' => 1, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => ppp_allowed_post_types(), 'post_status' => array('draft', 'publish', 'future'));
            $recent_posts = wp_get_recent_posts($args, ARRAY_A);
            $recent_post = $recent_posts[0];
            $post_type = get_post_type_object($recent_post['post_type']);
            $post_type_name = $post_type->labels->singular_name;
            $edit_url = admin_url('post.php?post=' . $recent_post['ID'] . '&action=edit');
            switch ($recent_post['post_status']) {
                case 'draft':
                    $relative_time = __('<a href="%s">Configure them</a> for your draft ' . $post_type_name, 'ppp-txt');
                    break;
                case 'future':
                    $relative_time = __('<a href="%s">Schedule one</a> for your upcoming ' . $post_type_name, 'ppp-txt');
                    break;
                case 'publish':
                default:
                    $relative_time = __('<a href="%s">Schedule one</a> for your most recent ' . $post_type_name, 'ppp-txt');
                    break;
            }
            ?>
<span><em>
				<?php 
            _e('No scheduled tweets at this time.', 'ppp-txt');
            ?>
				<?php 
            printf($relative_time, $edit_url);
            ?>
			</em></span><?php 
        }
        do_action('ppp_dashboard_tweets_after');
    }
コード例 #2
0
 public function test_get_scheduled_crons()
 {
     $scheduled_crons = ppp_get_shceduled_crons();
     $this->assertInternalType('array', $scheduled_crons);
     $this->assertTrue(!empty($scheduled_crons));
 }
コード例 #3
0
/**
 * 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;
}
コード例 #4
0
 /**
  * Prepare the data for the WP List Table
  * @return void
  */
 public function prepare_items()
 {
     $columns = $this->get_columns();
     $hidden = array();
     $data = array();
     $sortable = false;
     $this->_column_headers = array($columns, $hidden, $sortable);
     $per_page = 25;
     $crons = ppp_get_shceduled_crons();
     $cron_tally = array();
     foreach ($crons as $key => $cron) {
         $ppp_data = $cron;
         $timestamp = $ppp_data['timestamp'];
         $cron_tally[$timestamp] = isset($cron_tally[$timestamp]) ? $cron_tally[$timestamp] + 1 : 1;
         $name_parts = explode('_', $ppp_data['args'][1]);
         $index = $name_parts[1];
         $service = isset($name_parts[3]) ? $name_parts[3] : 'tw';
         $builder = 'ppp_' . $service . '_build_share_message';
         $post_meta = get_post_meta($ppp_data['args'][0], '_ppp_tweets', true);
         $image_url = '';
         if (!empty($post_meta[$index]['attachment_id'])) {
             $image_url = ppp_post_has_media($ppp_data['args'][0], 'tw', true, $post_meta[$index]['attachment_id']);
         } elseif (!empty($post_meta[$index]['image'])) {
             $image_url = $post_meta[$index]['image'];
         }
         $conflict = $cron_tally[$timestamp] > 1 ? true : false;
         $data[$key] = array('post_id' => $ppp_data['args'][0], 'post_title' => get_the_title($ppp_data['args'][0]), 'service' => $service, 'index' => $index, 'date' => $timestamp + get_option('gmt_offset') * 3600, 'content' => $builder($ppp_data['args'][0], $ppp_data['args'][1], false), 'name' => 'sharedate_' . $index . '_' . $ppp_data['args'][0], 'conflict' => $conflict);
         if (!empty($image_url)) {
             $data[$key]['image_url'] = $image_url;
         }
     }
     $total_items = count($data);
     $offset = isset($_GET['paged']) ? $_GET['paged'] : 1;
     $data = array_slice($data, ($offset - 1) * $per_page, $per_page, true);
     $this->items = $data;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
     $this->items = $data;
 }
コード例 #5
0
<?php

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}
/**
 * Runs whenever the 'uninstall' link is clicked in the Plugins List
 *
 * Removes our settings if the option to 'delete on uninstall is set'
 */
$options = get_option('ppp_options');
if (isset($options['delete_on_uninstall'])) {
    require_once 'includes/cron-functions.php';
    $crons = ppp_get_shceduled_crons();
    foreach ($crons as $cron) {
        $ppp_data = $cron['ppp_share_post_event'];
        $array_keys = array_keys($ppp_data);
        $hash_key = $array_keys[0];
        $event_info = $ppp_data[$hash_key];
        ppp_remove_scheduled_shares($event_info['args'][0]);
    }
    delete_option('ppp_options');
    delete_option('_ppp_license_key');
    delete_option('ppp_social_settings');
    delete_option('ppp_share_settings');
    delete_option('_ppp_license_key_status');
    delete_transient('ppp_social_tokens');
}