Exemplo n.º 1
0
function wpi_get_post_meta($post_id, $key, $single = false)
{
    $post_id = (int) $post_id;
    $meta_cache = wp_cache_get($post_id, 'post_meta');
    if (!isset($meta_cache[$key])) {
        return false;
    }
    if (isset($meta_cache[$key])) {
        if ($single) {
            return maybe_unserialize($meta_cache[$key][0]);
        } else {
            return maybe_unserialize($meta_cache[$key]);
        }
    }
    if (!$meta_cache) {
        update_postmeta_cache($post_id);
        $meta_cache = wp_cache_get($post_id, 'post_meta');
    }
    if ($single) {
        if (isset($meta_cache[$key][0])) {
            return maybe_unserialize($meta_cache[$key][0]);
        } else {
            return '';
        }
    } else {
        return maybe_unserialize($meta_cache[$key]);
    }
}
 function pushpress_send_ping($callback, $post_id, $feed_type, $secret)
 {
     global $pushpress;
     // Need to make sure that the PuSHPress options are initialized
     $pushpress->init();
     do_action('pushpress_send_ping');
     $remote_opt = array('headers' => array('format' => $feed_type), 'sslverify' => FALSE, 'timeout' => $pushpress->http_timeout, 'user-agent' => $pushpress->http_user_agent);
     $post = get_post($post_id);
     do_enclose($post->post_content, $post_id);
     update_postmeta_cache(array($post_id));
     query_posts("p={$post_id}");
     ob_start();
     $feed_url = FALSE;
     if ($feed_type == 'rss2') {
         do_action('pushpress_send_ping_rss2');
         $feed_url = get_bloginfo('rss2_url');
         $remote_opt['headers']['Content-Type'] = 'application/rss+xml';
         $remote_opt['headers']['Content-Type'] .= '; charset=' . get_option('blog_charset');
         @load_template(ABSPATH . WPINC . '/feed-rss2.php');
     } elseif ($feed_type == 'atom') {
         do_action('pushpress_send_ping_atom');
         $feed_url = get_bloginfo('atom_url');
         $remote_opt['headers']['Content-Type'] = 'application/atom+xml';
         $remote_opt['headers']['Content-Type'] .= '; charset=' . get_option('blog_charset');
         @load_template(ABSPATH . WPINC . '/feed-atom.php');
     }
     $remote_opt['body'] = ob_get_contents();
     ob_end_clean();
     // Figure out the signatur header if we have a secret on
     // on file for this callback
     if (!empty($secret)) {
         $remote_opt['headers']['X-Hub-Signature'] = 'sha1=' . hash_hmac('sha1', $remote_opt['body'], $secret);
     }
     $response = wp_remote_post($callback, $remote_opt);
     // look for failures
     if (is_wp_error($result)) {
         do_action('pushpress_ping_wp_error');
         return FALSE;
     }
     if (isset($response->errors['http_request_failed'][0])) {
         do_action('pushpress_ping_http_failure');
         return FALSE;
     }
     $status_code = (int) $response['response']['code'];
     if ($status_code < 200 || $status_code > 299) {
         do_action('pushpress_ping_not_2xx_failure');
         $pushpress->unsubscribe_callback($feed_url, $callback);
         return FALSE;
     }
 }
Exemplo n.º 3
0
 /**
  * Set it Up
  */
 public function setUp()
 {
     parent::setUp();
     $payment_id = Give_Helper_Payment::create_simple_payment();
     $this->_payment_key = give_get_payment_key($payment_id);
     $this->_payment_id = $payment_id;
     $this->_key = $this->_payment_key;
     $this->_transaction_id = 'FIR3SID3';
     give_set_payment_transaction_id($payment_id, $this->_transaction_id);
     give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Transaction ID: %s', 'give'), $this->_transaction_id));
     // Make sure we're working off a clean object caching in WP Core.
     // Prevents some payment_meta from not being present.
     clean_post_cache($payment_id);
     update_postmeta_cache(array($payment_id));
 }
Exemplo n.º 4
0
/**
 * Call major cache updating functions for list of Post objects.
 *
 * @package WordPress
 * @subpackage Cache
 * @since 1.5.0
 *
 * @uses $wpdb
 * @uses update_post_cache()
 * @uses update_object_term_cache()
 * @uses update_postmeta_cache()
 *
 * @param array $posts Array of Post objects
 * @param string $post_type The post type of the posts in $posts. Default is 'post'.
 * @param bool $update_term_cache Whether to update the term cache. Default is true.
 * @param bool $update_meta_cache Whether to update the meta cache. Default is true.
 */
function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true)
{
    // No point in doing all this work if we didn't match any posts.
    if (!$posts) {
        return;
    }
    update_post_cache($posts);
    $post_ids = array();
    foreach ($posts as $post) {
        $post_ids[] = $post->ID;
    }
    if (empty($post_type)) {
        $post_type = 'post';
    }
    if (!is_array($post_type) && 'any' != $post_type && $update_term_cache) {
        update_object_term_cache($post_ids, $post_type);
    }
    if ($update_meta_cache) {
        update_postmeta_cache($post_ids);
    }
}
Exemplo n.º 5
0
/**
 * update_post_caches() - Call major cache updating functions for list of Post objects.
 *
 * @package WordPress
 * @subpackage Cache
 * @since 1.5
 *
 * @uses $wpdb
 * @uses update_post_cache()
 * @uses update_object_term_cache()
 * @uses update_postmeta_cache()
 *
 * @param array $posts Array of Post objects
 */
function update_post_caches(&$posts)
{
    // No point in doing all this work if we didn't match any posts.
    if (!$posts) {
        return;
    }
    update_post_cache($posts);
    $post_ids = array();
    for ($i = 0; $i < count($posts); $i++) {
        $post_ids[] = $posts[$i]->ID;
    }
    update_object_term_cache($post_ids, 'post');
    update_postmeta_cache($post_ids);
}
function wpv_filter_extend_query_for_parametric_and_counters($post_query, $view_settings, $id)
{
    $dps_enabled = false;
    $counters_enabled = false;
    if (!isset($view_settings['dps']) || !is_array($view_settings['dps'])) {
        $view_settings['dps'] = array();
    }
    if (isset($view_settings['dps']['enable_dependency']) && $view_settings['dps']['enable_dependency'] == 'enable') {
        $dps_enabled = true;
        $controls_per_kind = wpv_count_filter_controls($view_settings);
        $controls_count = 0;
        $no_intersection = array();
        if (!isset($controls_per_kind['error'])) {
            //	$controls_count = array_sum( $controls_per_kind );
            $controls_count = $controls_per_kind['cf'] + $controls_per_kind['tax'] + $controls_per_kind['pr'] + $controls_per_kind['search'];
            if ($controls_per_kind['cf'] > 1 && (!isset($view_settings['custom_fields_relationship']) || $view_settings['custom_fields_relationship'] != 'AND')) {
                $no_intersection[] = __('custom field', 'wpv-views');
            }
            if ($controls_per_kind['tax'] > 1 && (!isset($view_settings['taxonomy_relationship']) || $view_settings['taxonomy_relationship'] != 'AND')) {
                $no_intersection[] = __('taxonomy', 'wpv-views');
            }
        } else {
            $dps_enabled = false;
        }
        if ($controls_count > 0) {
            if (count($no_intersection) > 0) {
                $dps_enabled = false;
            }
        } else {
            $dps_enabled = false;
        }
    }
    if (!isset($view_settings['filter_meta_html'])) {
        $view_settings['filter_meta_html'] = '';
    }
    if (strpos($view_settings['filter_meta_html'], '%%COUNT%%') !== false) {
        $counters_enabled = true;
    }
    global $WP_Views;
    if (!$dps_enabled && !$counters_enabled) {
        // Set the force value
        $WP_Views->set_force_disable_dependant_parametric_search(true);
        return $post_query;
    }
    // If after all we have dps, we need to populate the $wp_object_cache
    // Check if we need to create all the cache or just for the missing ones
    global $wp_object_cache;
    $cache_exclude_queried_posts = false;
    // we will only exclude already queried posts if there are any queried posts and the native cache exists (so they are already cached)
    $cache_use_native = true;
    if (is_object($wp_object_cache)) {
        if (isset($wp_object_cache->cache)) {
            // existing queried posts were already cached
            if (empty($post_query)) {
                $cache_exclude_queried_posts = false;
                // we passed an empty $post_query so there are no queried posts at all (surely coming from a form View shortcode)
            } else {
                $cache_exclude_queried_posts = true;
            }
        } else {
            $wp_object_cache->cache = array();
            $cache_exclude_queried_posts = false;
            // already queried posts were not cached where we need them
            $cache_use_native = false;
            // the native $wp_object_cache->cache property is not set, so we will recreate it instead of naturally caching metadata
        }
    }
    // In any case, we need to mimic the process that we used to generate the $query
    $view_settings_defaults = array('post_type' => 'any', 'orderby' => 'post-date', 'order' => 'DESC', 'paged' => '1', 'posts_per_page' => -1);
    extract($view_settings_defaults);
    $view_settings['view_id'] = $id;
    extract($view_settings, EXTR_OVERWRITE);
    $query = array('posts_per_page' => $posts_per_page, 'paged' => $paged, 'post_type' => $post_type, 'order' => $order, 'suppress_filters' => false, 'ignore_sticky_posts' => true);
    // Add special check for media (attachments) as their default status in not usually published
    if (sizeof($post_type) == 1 && $post_type[0] == 'attachment') {
        $query['post_status'] = 'any';
        // Note this can be overriden by adding a status filter.
    }
    $query = apply_filters('wpv_filter_query', $query, $view_settings, $id);
    // Now we have the $query as in the original one
    // We now need to overwrite the limit, offset, paged and pagination options
    // Also, we set it to just return the IDs
    $query['posts_per_page'] = -1;
    $query['ĺimit'] = -1;
    $query['paged'] = 1;
    $query['offset'] = 0;
    $query['fields'] = 'ids';
    if ($cache_exclude_queried_posts) {
        // do not query again already queried and cached posts
        $already = array();
        if (isset($post_query->posts) && !empty($post_query->posts)) {
            foreach ((array) $post_query->posts as $post_object) {
                $already[] = $post_object->ID;
            }
        }
        $WP_Views->returned_ids_for_parametric_search = $already;
        if (isset($query['pr_filter_post__in'])) {
            $query['post__in'] = $query['pr_filter_post__in'];
        } else {
            // If just for the missing ones, generate the post__not_in argument
            if (isset($query['post__not_in'])) {
                $query['post__not_in'] = array_merge((array) $query['post__not_in'], (array) $already);
            } else {
                $query['post__not_in'] = (array) $already;
            }
            // And adjust on the post__in argument
            if (isset($query['post__in'])) {
                $query['post__in'] = array_diff((array) $query['post__in'], (array) $query['post__not_in']);
                //unset( $query['post__in'] );
            }
        }
    }
    // Perform the query
    $aux_cache_query = new WP_Query($query);
    // In case we need to recreate our own cache object, we do not need to load there all the postmeta and taxonomy data, just for the elements involved in parametric search controls
    $filter_c_mode = isset($view_settings['filter_controls_mode']) && is_array($view_settings['filter_controls_mode']) ? $view_settings['filter_controls_mode'] : array();
    $filter_c_name = isset($view_settings['filter_controls_field_name']) && is_array($view_settings['filter_controls_field_name']) ? $view_settings['filter_controls_field_name'] : array();
    $f_taxes = array();
    $f_fields = array();
    foreach ($filter_c_mode as $f_index => $f_mode) {
        if (isset($filter_c_name[$f_index])) {
            switch ($f_mode) {
                case 'slug':
                    $f_taxes[] = $filter_c_name[$f_index];
                    break;
                case 'cf':
                    $f_fields[] = $filter_c_name[$f_index];
                    break;
                case 'rel':
                    if (function_exists('wpcf_pr_get_belongs')) {
                        $returned_post_types = $view_settings['post_type'];
                        $returned_post_type_parents = array();
                        if (empty($returned_post_types)) {
                            $returned_post_types = array('any');
                        }
                        foreach ($returned_post_types as $returned_post_type_slug) {
                            $parent_parents_array = wpcf_pr_get_belongs($returned_post_type_slug);
                            if ($parent_parents_array != false && is_array($parent_parents_array)) {
                                $returned_post_type_parents = array_merge($returned_post_type_parents, array_values(array_keys($parent_parents_array)));
                            }
                        }
                        foreach ($returned_post_type_parents as $parent_to_cache) {
                            $f_fields[] = '_wpcf_belongs_' . $parent_to_cache . '_id';
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
    // If we are using the native caching, update the cache for the posts returned by the aux query
    if (is_array($aux_cache_query->posts) && !empty($aux_cache_query->posts)) {
        $WP_Views->returned_ids_for_parametric_search = array_merge($WP_Views->returned_ids_for_parametric_search, $aux_cache_query->posts);
        $WP_Views->returned_ids_for_parametric_search = array_unique($WP_Views->returned_ids_for_parametric_search);
        if ($cache_use_native) {
            // If we are using the native caching, update the cache for the posts returned by the aux query
            update_postmeta_cache($aux_cache_query->posts);
            update_object_term_cache($aux_cache_query->posts, $view_settings['post_type']);
        } else {
            // Else, we need to fake an $wp_object_cache->cache
            $f_data = array('cf' => $f_fields, 'tax' => $f_taxes);
            $cache_combined = wpv_custom_cache_metadata($aux_cache_query->posts, $f_data);
            $wp_object_cache->cache = $cache_combined;
        }
    }
    return $post_query;
}
Exemplo n.º 7
0
function get_post_custom($post_id = 0) {
	global $id, $post_meta_cache, $wpdb, $blog_id;

	if ( !$post_id )
		$post_id = (int) $id;

	$post_id = (int) $post_id;

	if ( !isset($post_meta_cache[$blog_id][$post_id]) )
		update_postmeta_cache($post_id);

	return $post_meta_cache[$blog_id][$post_id];
}
Exemplo n.º 8
0
 function pushpress_send_ping($callback, $post_id, $feed_type, $secret)
 {
     global $pushpress, $current_user;
     // Do all WP_Query calcs and send feeds as logged-out user.
     $old_user_id = $current_user->ID;
     wp_set_current_user(0);
     // Need to make sure that the PuSHPress options are initialized
     $pushpress->init();
     do_action('pushpress_send_ping');
     $remote_opt = array('headers' => array('format' => $feed_type), 'sslverify' => FALSE, 'timeout' => $pushpress->http_timeout, 'user-agent' => $pushpress->http_user_agent);
     $post = get_post($post_id);
     $post_status_obj = get_post_status_object($post->post_status);
     if (!$post_status_obj->public) {
         do_action('pushpress_nonpublic_post', $post_id);
         wp_set_current_user($old_user_id);
         return false;
     }
     do_enclose($post->post_content, $post_id);
     update_postmeta_cache(array($post_id));
     // make sure the channel title stays consistent
     // without this it would append the post title as well
     add_filter('wp_title', '__return_false', 999);
     query_posts("p={$post_id}");
     ob_start();
     $feed_url = FALSE;
     if ($feed_type == 'rss2') {
         do_action('pushpress_send_ping_rss2');
         $feed_url = get_bloginfo('rss2_url');
         $remote_opt['headers']['Content-Type'] = 'application/rss+xml';
         $remote_opt['headers']['Content-Type'] .= '; charset=' . get_option('blog_charset');
         @load_template(ABSPATH . WPINC . '/feed-rss2.php');
     } elseif ($feed_type == 'atom') {
         do_action('pushpress_send_ping_atom');
         $feed_url = get_bloginfo('atom_url');
         $remote_opt['headers']['Content-Type'] = 'application/atom+xml';
         $remote_opt['headers']['Content-Type'] .= '; charset=' . get_option('blog_charset');
         @load_template(ABSPATH . WPINC . '/feed-atom.php');
     }
     $remote_opt['body'] = ob_get_contents();
     ob_end_clean();
     // Figure out the signatur header if we have a secret on
     // on file for this callback
     if (!empty($secret)) {
         $remote_opt['headers']['X-Hub-Signature'] = 'sha1=' . hash_hmac('sha1', $remote_opt['body'], $secret);
     }
     $response = wp_remote_post($callback, $remote_opt);
     // look for failures
     if (is_wp_error($response)) {
         do_action('pushpress_ping_wp_error');
         wp_set_current_user($old_user_id);
         return FALSE;
     }
     if (isset($response->errors['http_request_failed'][0])) {
         do_action('pushpress_ping_http_failure');
         wp_set_current_user($old_user_id);
         return FALSE;
     }
     $status_code = (int) $response['response']['code'];
     if ($status_code < 200 || $status_code > 299) {
         do_action('pushpress_ping_not_2xx_failure');
         $pushpress->unsubscribe_callback($feed_url, $callback);
         wp_set_current_user($old_user_id);
         return FALSE;
     }
     wp_set_current_user($old_user_id);
 }
 /**
  * Gets the event counts for individual days.
  *
  * @param array $args
  *
  * @return array The counts array.
  */
 public static function getEventCounts($args = array())
 {
     global $wpdb;
     do_action('log', 'getEventCounts() $args', 'tribe-events-query', $args);
     $date = date('Y-m-d');
     $defaults = array('post_type' => TribeEvents::POSTTYPE, 'start_date' => tribe_event_beginning_of_day($date), 'end_date' => tribe_event_end_of_day($date), 'display_type' => 'daily', 'hide_upcoming_ids' => null);
     $args = wp_parse_args($args, $defaults);
     $args['posts_per_page'] = -1;
     $args['fields'] = 'ids';
     // remove empty args and sort by key, this increases chance of a cache hit
     $args = array_filter($args, array(__CLASS__, 'filter_args'));
     ksort($args);
     $cache = new TribeEventsCache();
     $cache_key = 'daily_counts_and_ids_' . serialize($args);
     $found = $cache->get($cache_key, 'save_post');
     if ($found) {
         do_action('log', 'cache hit ' . __LINE__, 'tribe-events-cache', $args);
         return $found;
     }
     do_action('log', 'no cache hit ' . __LINE__, 'tribe-events-cache', $args);
     $cache_key = 'month_post_ids_' . serialize($args);
     $found = $cache->get($cache_key, 'save_post');
     if ($found && is_array($found)) {
         do_action('log', 'cache hit ' . __LINE__, 'tribe-events-cache', $args);
         $post_ids = $found;
     } else {
         do_action('log', 'no cache hit ' . __LINE__, 'tribe-events-cache', $args);
         $post_id_query = new WP_Query();
         $post_ids = $post_id_query->query($args);
         do_action('log', 'final args for month view post ids', 'tribe-events-query', $post_id_query->query_vars);
         do_action('log', 'Month view getEventCounts SQL', 'tribe-events-query', $post_id_query->request);
         $cache->set($cache_key, $post_ids, TribeEventsCache::NON_PERSISTENT, 'save_post');
     }
     do_action('log', 'Month view post ids found', 'tribe-events-query', $post_ids);
     $counts = array();
     $event_ids = array();
     if (!empty($post_ids)) {
         switch ($args['display_type']) {
             case 'daily':
             default:
                 global $wp_query;
                 $output_date_format = '%Y-%m-%d %H:%i:%s';
                 do_action('log', 'raw counts args', 'tribe-events-query', $args);
                 $raw_counts = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT \ttribe_event_start.post_id as ID, \n\t\t\t\t\t\t\t\t\ttribe_event_start.meta_value as EventStartDate, \n\t\t\t\t\t\t\t\t\tDATE_FORMAT( tribe_event_end_date.meta_value, '%1\$s') as EventEndDate,\n\t\t\t\t\t\t\t\t\t{$wpdb->posts}.menu_order as menu_order\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta} AS tribe_event_start\n\t\t\t\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} ON (tribe_event_start.post_id = {$wpdb->posts}.ID)\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} as tribe_event_end_date ON ( tribe_event_start.post_id = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = '_EventEndDate' )\n\t\t\t\t\t\t\tWHERE tribe_event_start.meta_key = '_EventStartDate'\n\t\t\t\t\t\t\tAND tribe_event_start.post_id IN ( %5\$s )\n\t\t\t\t\t\t\tAND ( (tribe_event_start.meta_value >= '%3\$s' AND  tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t\tOR (tribe_event_start.meta_value <= '%3\$s' AND tribe_event_end_date.meta_value >= '%3\$s')\n\t\t\t\t\t\t\t\tOR ( tribe_event_start.meta_value >= '%3\$s' AND  tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tORDER BY menu_order ASC, DATE(tribe_event_start.meta_value) ASC, TIME(tribe_event_start.meta_value) ASC;", $output_date_format, $output_date_format, $post_id_query->query_vars['start_date'], $post_id_query->query_vars['end_date'], implode(',', array_map('intval', $post_ids))));
                 do_action('log', 'raw counts query', 'tribe-events-query', $wpdb->last_query);
                 $start_date = new DateTime($post_id_query->query_vars['start_date']);
                 $end_date = new DateTime($post_id_query->query_vars['end_date']);
                 $days = TribeDateUtils::dateDiff($start_date->format('Y-m-d'), $end_date->format('Y-m-d'));
                 $term_id = isset($wp_query->query_vars[TribeEvents::TAXONOMY]) ? $wp_query->query_vars[TribeEvents::TAXONOMY] : null;
                 if (is_int($term_id)) {
                     $term = get_term_by('id', $term_id, TribeEvents::TAXONOMY);
                 } elseif (is_string($term_id)) {
                     $term = get_term_by('slug', $term_id, TribeEvents::TAXONOMY);
                 }
                 for ($i = 0, $date = $start_date; $i <= $days; $i++, $date->modify('+1 day')) {
                     $formatted_date = $date->format('Y-m-d');
                     $start_of_day = strtotime(tribe_event_beginning_of_day($formatted_date));
                     $end_of_day = strtotime(tribe_event_end_of_day($formatted_date)) + 1;
                     $count = 0;
                     $_day_event_ids = array();
                     foreach ($raw_counts as $record) {
                         $record_start = strtotime($record->EventStartDate);
                         $record_end = strtotime($record->EventEndDate);
                         /**
                          * conditions:
                          * event starts on this day (event start time is between start and end of day)
                          * event ends on this day (event end time is between start and end of day)
                          * event starts before start of day and ends after end of day (spans across this day)
                          * note:
                          * events that start exactly on the EOD cutoff will count on the following day
                          * events that end exactly on the EOD cutoff will count on the previous day
                          */
                         $event_starts_today = $record_start >= $start_of_day && $record_start < $end_of_day;
                         $event_ends_today = $record_end > $start_of_day && $record_end <= $end_of_day;
                         $event_spans_across_today = $record_start < $start_of_day && $record_end > $end_of_day;
                         if ($event_starts_today || $event_ends_today || $event_spans_across_today) {
                             if (isset($term->term_id)) {
                                 if (!has_term($term, TribeEvents::TAXONOMY, $record->ID)) {
                                     continue;
                                 }
                             }
                             if (count($_day_event_ids) < apply_filters('tribe_events_month_day_limit', tribe_get_option('monthEventAmount', '3'))) {
                                 $_day_event_ids[] = $record->ID;
                             }
                             $count++;
                         }
                     }
                     $event_ids[$formatted_date] = $_day_event_ids;
                     $counts[$formatted_date] = $count;
                 }
                 break;
         }
         // get a unique list of the event IDs that will be displayed, and update all their postmeta and term caches at once
         $final_event_ids = array();
         $final_event_ids = call_user_func_array('array_merge', $event_ids);
         $final_event_ids = array_unique($final_event_ids);
         do_action('log', 'updating term and postmeta caches for events', 'tribe-events-cache', $final_event_ids);
         update_object_term_cache($final_event_ids, TribeEvents::POSTTYPE);
         update_postmeta_cache($final_event_ids);
     }
     // return IDs per day and total counts per day
     $return = array('counts' => $counts, 'event_ids' => $event_ids);
     $cache = new TribeEventsCache();
     $cache_key = 'daily_counts_and_ids_' . serialize($args);
     $cache->set($cache_key, $return, TribeEventsCache::NON_PERSISTENT, 'save_post');
     do_action('log', 'final event counts result', 'tribe-events-query', $return);
     return $return;
 }
 /**
  * Gets the event counts for individual days.
  *
  * @param array $args
  *
  * @return array The counts array.
  */
 public static function getEventCounts($args = array())
 {
     _deprecated_function(__METHOD__, '3.10.1');
     global $wpdb;
     $date = date('Y-m-d');
     $defaults = array('post_type' => Tribe__Events__Main::POSTTYPE, 'start_date' => tribe_beginning_of_day($date), 'end_date' => tribe_end_of_day($date), 'display_type' => 'daily', 'hide_upcoming_ids' => null);
     $args = wp_parse_args($args, $defaults);
     $args['posts_per_page'] = -1;
     $args['fields'] = 'ids';
     // remove empty args and sort by key, this increases chance of a cache hit
     $args = array_filter($args, array(__CLASS__, 'filter_args'));
     ksort($args);
     $cache = new Tribe__Cache();
     $cache_key = 'daily_counts_and_ids_' . serialize($args);
     $found = $cache->get($cache_key, 'save_post');
     if ($found) {
         return $found;
     }
     $cache_key = 'month_post_ids_' . serialize($args);
     $found = $cache->get($cache_key, 'save_post');
     if ($found && is_array($found)) {
         $post_ids = $found;
     } else {
         $post_id_query = new WP_Query();
         $post_ids = $post_id_query->query($args);
         $cache->set($cache_key, $post_ids, Tribe__Cache::NON_PERSISTENT, 'save_post');
     }
     $counts = array();
     $event_ids = array();
     if (!empty($post_ids)) {
         switch ($args['display_type']) {
             case 'daily':
             default:
                 global $wp_query;
                 $output_date_format = '%Y-%m-%d %H:%i:%s';
                 $raw_counts = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT \ttribe_event_start.post_id as ID,\n\t\t\t\t\t\t\t\t\ttribe_event_start.meta_value as EventStartDate,\n\t\t\t\t\t\t\t\t\tDATE_FORMAT( tribe_event_end_date.meta_value, '%1\$s') as EventEndDate,\n\t\t\t\t\t\t\t\t\t{$wpdb->posts}.menu_order as menu_order\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta} AS tribe_event_start\n\t\t\t\t\t\t\t\t\tLEFT JOIN {$wpdb->posts} ON (tribe_event_start.post_id = {$wpdb->posts}.ID)\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->postmeta} as tribe_event_end_date ON ( tribe_event_start.post_id = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = '_EventEndDate' )\n\t\t\t\t\t\t\tWHERE tribe_event_start.meta_key = '_EventStartDate'\n\t\t\t\t\t\t\tAND tribe_event_start.post_id IN ( %5\$s )\n\t\t\t\t\t\t\tAND ( (tribe_event_start.meta_value >= '%3\$s' AND  tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t\tOR (tribe_event_start.meta_value <= '%3\$s' AND tribe_event_end_date.meta_value >= '%3\$s')\n\t\t\t\t\t\t\t\tOR ( tribe_event_start.meta_value >= '%3\$s' AND  tribe_event_start.meta_value <= '%4\$s')\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tORDER BY menu_order ASC, DATE(tribe_event_start.meta_value) ASC, TIME(tribe_event_start.meta_value) ASC;", $output_date_format, $output_date_format, $post_id_query->query_vars['start_date'], $post_id_query->query_vars['end_date'], implode(',', array_map('intval', $post_ids))));
                 $start_date = new DateTime($post_id_query->query_vars['start_date']);
                 $end_date = new DateTime($post_id_query->query_vars['end_date']);
                 $days = Tribe__Date_Utils::date_diff($start_date->format('Y-m-d'), $end_date->format('Y-m-d'));
                 $term_id = isset($wp_query->query_vars[Tribe__Events__Main::TAXONOMY]) ? $wp_query->query_vars[Tribe__Events__Main::TAXONOMY] : null;
                 $terms = array();
                 if (is_int($term_id)) {
                     $terms[0] = $term_id;
                 } elseif (is_string($term_id)) {
                     $term = get_term_by('slug', $term_id, Tribe__Events__Main::TAXONOMY);
                     if ($term) {
                         $terms[0] = $term->term_id;
                     }
                 }
                 if (!empty($terms) && is_tax(Tribe__Events__Main::TAXONOMY)) {
                     $terms = array_merge($terms, get_term_children($terms[0], Tribe__Events__Main::TAXONOMY));
                 }
                 for ($i = 0, $date = $start_date; $i <= $days; $i++, $date->modify('+1 day')) {
                     $formatted_date = $date->format('Y-m-d');
                     $count = 0;
                     $_day_event_ids = array();
                     foreach ($raw_counts as $record) {
                         $event = new stdClass();
                         $event->EventStartDate = $record->EventStartDate;
                         $event->EventEndDate = $record->EventEndDate;
                         $per_day_limit = apply_filters('tribe_events_month_day_limit', tribe_get_option('monthEventAmount', '3'));
                         if (tribe_event_is_on_date($formatted_date, $event)) {
                             if (!empty($terms) && !has_term($terms, Tribe__Events__Main::TAXONOMY, $record->ID)) {
                                 continue;
                             }
                             if (count($_day_event_ids) < $per_day_limit) {
                                 $_day_event_ids[] = $record->ID;
                             }
                             $count++;
                         }
                     }
                     $event_ids[$formatted_date] = $_day_event_ids;
                     $counts[$formatted_date] = $count;
                 }
                 break;
         }
         // get a unique list of the event IDs that will be displayed, and update all their postmeta and term caches at once
         $final_event_ids = call_user_func_array('array_merge', $event_ids);
         $final_event_ids = array_unique($final_event_ids);
         update_object_term_cache($final_event_ids, Tribe__Events__Main::POSTTYPE);
         update_postmeta_cache($final_event_ids);
     }
     // return IDs per day and total counts per day
     $return = array('counts' => $counts, 'event_ids' => $event_ids);
     $cache = new Tribe__Cache();
     $cache_key = 'daily_counts_and_ids_' . serialize($args);
     $cache->set($cache_key, $return, Tribe__Cache::NON_PERSISTENT, 'save_post');
     return $return;
 }
Exemplo n.º 11
0
function aioseop_list_pages($content)
{
    $matches = array();
    if (preg_match_all('/<li class="page_item page-item-(\\d+)/i', $content, $matches)) {
        update_postmeta_cache(array_values($matches[1]));
        unset($matches);
        $pattern = '/<li class="page_item page-item-(\\d+)([^\\"]*)"><a href=\\"([^\\"]+)" title="([^\\"]+)">([^<]+)<\\/a>/i';
        return preg_replace_callback($pattern, "aioseop_filter_callback", $content);
    }
    return $content;
}
function tdomf_upload_download_handler()
{
    global $current_user, $post_meta_cache, $blog_id;
    $post_ID = $_GET['tdomf_download'];
    $file_ID = $_GET['id'];
    $use_thumb = isset($_GET['thumb']);
    // Security check
    get_currentuserinfo();
    if (!current_user_can("publish_posts")) {
        $post = get_post($post_ID);
        if ($post->post_status != 'publish') {
            return;
        }
    }
    // For some reason, the post meta value cache does not include private
    // keys (those starting with _) so unset it and update it properly!
    //
    unset($post_meta_cache[$blog_id][$post_ID]);
    update_postmeta_cache($post_ID);
    if ($use_thumb) {
        $filepath = get_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_THUMB . $file_ID, true);
        // a previous version of TDOMF did not properly define
        // TDOMF_KEY_DOWNLOAD_THUMB so it used "TDOMF_KEY_DOWNLOAD_THUMB" as the
        // actually key, so double check here, just in case.
        if (!file_exists($filepath)) {
            tdomf_log_message("The key " . TDOMF_KEY_DOWNLOAD_THUMB . "{$file_ID} is not defined on {$post_ID}. Attempting to use " . 'TDOMF_KEY_DOWNLOAD_THUMB' . "{$file_ID}!", TDOMF_LOG_BAD);
            $filepath = get_post_meta($post_ID, 'TDOMF_KEY_DOWNLOAD_THUMB' . $file_ID, true);
        }
    } else {
        $filepath = get_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_PATH . $file_ID, true);
    }
    if (!empty($filepath)) {
        if (!$use_thumb) {
            $type = get_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_TYPE . $file_ID, true);
        }
        $name = get_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_NAME . $file_ID, true);
        // Check if file exists
        //
        if (file_exists($filepath)) {
            @ignore_user_abort();
            @set_time_limit(600);
            if (!empty($type)) {
                $mimetype = $type;
            } else {
                if (function_exists('mime_content_type')) {
                    // set mime-type
                    $mimetype = mime_content_type($filepath);
                } else {
                    // default
                    $mimetype = 'application/octet-stream';
                }
            }
            if (!$use_thumb) {
                // Other stuff we could track...
                //
                //$referer = $_SERVER['HTTP_REFERER'];
                //ip = $_SERVER['REMOTE_ADDR'];
                //$now = date('Y-m-d H:i:s');
                // Update count
                //
                // This includes partial downloads! If wanted only full downloads
                // we would track it afterwards
                //
                $count = intval(get_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_COUNT . $file_ID, true));
                $count++;
                update_post_meta($post_ID, TDOMF_KEY_DOWNLOAD_COUNT . $file_ID, $count);
            }
            // Pass file
            $handle = fopen($filepath, "rb");
            // now let's get the file!
            #header("Pragma: "); // Leave blank for issues with IE
            #header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Type: {$mimetype}");
            #header("Content-Disposition: attachment; filename=\"".basename($filepath)."\"");
            header("Content-Length: " . filesize($filepath));
            sleep(1);
            fpassthru($handle);
            return;
        } else {
            tdomf_log_message("File {$filepath} does not exist!", TDOMF_LOG_ERROR);
        }
    } else {
        if ($use_thumb) {
            tdomf_log_message("No thumb found on post with id {$post_ID}!", TDOMF_LOG_ERROR);
        } else {
            tdomf_log_message("No file found on post with id {$post_ID}!", TDOMF_LOG_ERROR);
        }
        tdomf_log_message("Post Meta Cache for {$post_ID} on {$blog_id} <pre>" . var_export($post_meta_cache[$blog_id][$post_ID], true) . "</pre>", TDOMF_LOG_BAD);
    }
    header("HTTP/1.0 404 Not Found");
    exit;
}
Exemplo n.º 13
0
 /**
  * self::load_multiple() must have been called before that because it loads
  * wp data from wp_ids found in $this->nodes_data.
  */
 public function load_wp_data($ids_wp = array(), $posts_already_loaded = array())
 {
     if (!empty($this->nodes_data)) {
         if (empty($ids_wp)) {
             $ids_wp = $this->get_wp_ids();
         }
         $posts = empty($posts_already_loaded) ? array() : $posts_already_loaded;
         $pages_found = array();
         if (empty($posts_already_loaded)) {
             /*
             //Old way to retrieve pages data, by separated requests (when coma separated post_status didn't seem
             //to work in get_pages() : 
             $posts = get_pages(array('include'=>array_values($ids_wp),'post_type'=>'page','post_status'=>'publish'));
             $posts_draft = get_pages(array('include'=>array_values($ids_wp),'post_type'=>'page','post_status'=>'draft'));
             $posts_pending = get_pages(array('include'=>array_values($ids_wp),'post_type'=>'page','post_status'=>'pending'));
             $posts_trash = get_pages(array('include'=>array_values($ids_wp),'post_type'=>'page','post_status'=>'trash'));
             $posts_private = get_pages(array('include'=>array_values($ids_wp),'post_type'=>'page','post_status'=>'private'));
             $posts_autodraft = get_pages(array('include'=>array_values($ids_wp),'post_type'=>'page','post_status'=>'auto-draft'));
             $posts = array_merge($posts,$posts_draft,$posts_pending,$posts_trash,$posts_private);
             */
             $allowed_post_status = ApmConfig::$allowed_post_status;
             //Note : we keep 'auto-draft' here to handle them in case there are some in $ids_wp,
             //which should not happen because 'auto-draft' are not retrieved at APM tree creation,
             //but can still happen if 'auto-draft' status is set outside the plugin.
             $allowed_post_status[] = 'auto-draft';
             $allowed_post_status = apply_filters('apm_allowed_post_status', $allowed_post_status, 'load_wp_data');
             $allowed_post_status = array_map("addslashes", $allowed_post_status);
             $posts = get_pages(array('include' => array_values($ids_wp), 'post_type' => 'page', 'post_status' => implode(',', $allowed_post_status)));
             /*
             				//If some problem occurs related to the use of the get_pages() function (for example if it is
             				//hooked by another plugin), keep in mind that we can do it by hand:
             				//To build the exact same query as in the native get_pages() function:
             				//Copied from the WP get_pages() function :
             				global $wpdb;
             				$inclusions = '';
             				$incpages = wp_parse_id_list(array_values($ids_wp));
             				if( !empty( $incpages ) ){
             					foreach( $incpages as $incpage ) {
             						if( empty($inclusions) ){
             							$inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage);
             						}else{
             							$inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage);
             						}
             					}
             				}
             				if( !empty($inclusions) ){
             					$inclusions .= ')';
             				}
             				
             				$sql = "SELECT * FROM $wpdb->posts   
             						WHERE post_type = 'page' AND post_status IN ('draft', 'publish', 'pending', 'trash', 'private', 'auto-draft')   
             							  $inclusions 
             						ORDER BY wp_posts.post_title ASC";
             				
             				//$posts = $wpdb->get_results($sql);
             				//_prime_post_caches($posts_ids);
             */
             //TODO : test performances issues when there is a lot of pages (>500) :
             //And commpare this to :
             //$posts = $wpdb->get_results($wpdb->prepare("SELECT * from $wpdb->posts WHERE post_type = 'page' AND ID IN ('". implode("','",$ids_wp) ."')"));
         }
         foreach ($posts as $k => $post) {
             $pages_found[$post->ID] = $post;
         }
         //Use this "apm_load_wp_data" hook to preload some data about WP pages before display :
         //Something like update_post_caches($pages_found,'page'); can be used in this hook to preload terms for example.
         //We don't do this update_post_caches() by default because we don't need pages terms info,
         //only meta data (see the following update_postmeta_cache).
         do_action('apm_load_wp_data', $pages_found);
         //Preload wp cached meta data, so they are not retrieved one by one in
         //the following loop of "load_data_from_wp_entity()" :
         update_postmeta_cache(array_keys($pages_found));
         foreach ($this->nodes_data as $apm_id => $node) {
             switch ($node->type) {
                 case 'root':
                     $this->nodes_data[$apm_id]->set(array('title' => 'Root'));
                     break;
                 case 'page':
                     $wp_id = $node->wp_id;
                     if (!empty($posts) && !empty($wp_id) && array_key_exists($wp_id, $pages_found)) {
                         $this->nodes_data[$apm_id]->load_data_from_wp_entity($pages_found[$wp_id]);
                     }
                     break;
             }
         }
     }
 }
Exemplo n.º 14
0
function powerpress_get_post_meta($post_id, $key)
{
    $pp_meta_cache = wp_cache_get($post_id, 'post_meta');
    if (!$pp_meta_cache) {
        update_postmeta_cache($post_id);
        $pp_meta_cache = wp_cache_get($post_id, 'post_meta');
    }
    $meta = false;
    if (isset($pp_meta_cache[$key])) {
        $meta = $pp_meta_cache[$key][0];
    }
    if (is_serialized($meta)) {
        if (false !== ($gm = @unserialize($meta))) {
            return $meta;
        }
    }
    return $meta;
}
 /**
  * Get all the events in the month by directly querying the postmeta table
  * Also caches the postmeta and terms for the found events
  */
 protected function set_events_in_month()
 {
     global $wpdb;
     $grid_start_datetime = tribe_beginning_of_day($this->first_grid_date);
     $grid_end_datetime = tribe_end_of_day($this->final_grid_date);
     $cache = new Tribe__Cache();
     $cache_key = 'events_in_month' . $grid_start_datetime . '-' . $grid_end_datetime;
     // if we have a cached result, use that
     $cached_events = $cache->get($cache_key, 'save_post');
     if ($cached_events !== false) {
         $this->events_in_month = $cached_events;
         return;
     }
     $post_stati = array('publish');
     if (is_user_logged_in()) {
         $post_stati[] = 'private';
     }
     $post_stati = implode("','", $post_stati);
     $ignore_hidden_events_AND = $this->hidden_events_fragment();
     $events_request = $wpdb->prepare("SELECT tribe_event_start.post_id as ID,\n\t\t\t\t\t\ttribe_event_start.meta_value as EventStartDate,\n\t\t\t\t\t\ttribe_event_end_date.meta_value as EventEndDate\n\t\t\t\tFROM {$wpdb->postmeta} AS tribe_event_start\n\t\t\t\tLEFT JOIN {$wpdb->posts} ON tribe_event_start.post_id = {$wpdb->posts}.ID\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} as tribe_event_end_date ON ( tribe_event_start.post_id = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = '_EventEndDate' )\n\t\t\t\tWHERE {$ignore_hidden_events_AND} tribe_event_start.meta_key = '_EventStartDate'\n\t\t\t\tAND ( (tribe_event_start.meta_value >= '%1\$s' AND  tribe_event_start.meta_value <= '%2\$s')\n\t\t\t\t\tOR (tribe_event_start.meta_value <= '%1\$s' AND tribe_event_end_date.meta_value >= '%1\$s')\n\t\t\t\t\tOR ( tribe_event_start.meta_value >= '%1\$s' AND  tribe_event_start.meta_value <= '%2\$s')\n\t\t\t\t)\n\t\t\t\tAND {$wpdb->posts}.post_status IN('{$post_stati}')\n\t\t\t\tORDER BY {$wpdb->posts}.menu_order ASC, DATE(tribe_event_start.meta_value) ASC, TIME(tribe_event_start.meta_value) ASC;\n\t\t\t\t", $grid_start_datetime, $grid_end_datetime);
     $this->events_in_month = $wpdb->get_results($events_request);
     // cache the postmeta and terms for all these posts in one go
     $event_ids_in_month = wp_list_pluck($this->events_in_month, 'ID');
     update_object_term_cache($event_ids_in_month, Tribe__Events__Main::POSTTYPE);
     update_postmeta_cache($event_ids_in_month);
     // cache the found events in the object cache
     $cache->set($cache_key, $this->events_in_month, 0, 'save_post');
 }
Exemplo n.º 16
0
function tdomf_notify_admins($post_ID, $form_id)
{
    global $wpdb, $tdomf_form_widgets_adminemail, $post_meta_cache, $blog_id;
    // grab email addresses
    $email_list = tdomf_get_admin_emails($form_id);
    if ($email_list == "") {
        tdomf_log_message("Could not get any email addresses to notify. No moderation notification email sent.", TDOMF_LOG_BAD);
        return false;
    }
    // For some reason, the post meta value cache does not include private
    // keys (those starting with _) so unset it and update it properly!
    //
    unset($post_meta_cache[$blog_id][$post_ID]);
    update_postmeta_cache($post_ID);
    // Submitter Info
    //
    $can_ban_user = false;
    $submitter_string = "N/A";
    $user_ID = get_post_meta($post_ID, TDOMF_KEY_USER_ID, true);
    $submitter_name = get_post_meta($post_ID, TDOMF_KEY_NAME, true);
    if ($user_ID) {
        $submitter_string = get_post_meta($post_ID, TDOMF_KEY_USER_NAME, true);
        $can_ban_user = true;
    } else {
        if ($submitter_name) {
            $submitter_email = get_post_meta($post_ID, TDOMF_KEY_EMAIL, true);
            $submitter_string = $submitter_name;
            if ($submitter_email) {
                $submitter_string .= " (" . $submitter_email . ")";
            }
        }
    }
    // IP info
    //
    $ip = get_post_meta($post_ID, TDOMF_KEY_IP, true);
    // Title and content of post
    //
    $post = get_post($post_ID);
    $content = $post->post_content;
    $title = $post->post_title;
    $status = $post->post_status;
    // Admin links
    //
    $moderate_all_link = tdomf_get_mod_posts_url(array());
    $publish_post_link = tdomf_get_mod_posts_url(array('action' => 'publish', 'post_id' => $post_ID, 'nonce' => 'tdomf-publish_' . $post_ID));
    $delete_post_link = wp_nonce_url(get_bloginfo('wpurl') . "/wp-admin/post.php?action=delete&post={$post_ID}", 'delete-post_' . $post_ID);
    $edit_post_link = get_bloginfo('wpurl') . "/wp-admin/post.php?action=edit&amp;post={$post_ID}";
    // View link
    //
    $view_post_link = get_permalink($post_ID);
    $is_spam = get_post_meta($post_ID, TDOMF_KEY_SPAM) && get_option(TDOMF_OPTION_SPAM);
    // Spam links
    //
    $spam_link = tdomf_get_mod_posts_url(array('action' => 'spamit', 'post_id' => $post_ID, 'nonce' => 'tdomf-spamit_' . $post_ID));
    $ham_link = tdomf_get_mod_posts_url(array('action' => 'hamit', 'post_id' => $post_ID, 'nonce' => 'tdomf-spamit_' . $post_ID));
    if ($can_ban_user) {
        $ban_user_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_manage_menu&action=ban&user={$user_ID}";
    }
    $ban_ip_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_manage_menu&mode=ip&action=ban&ip={$ip}";
    // Subject line
    //
    if ($is_spam) {
        $subject = sprintf(__("[SPAM] [%s] Please moderate this spam post", "tdomf"), get_bloginfo('title'));
    } else {
        if ($status == 'publish' || $status == 'future') {
            $subject = sprintf(__("[%s] Post '%s' has been published", "tdomf"), get_bloginfo('title'), $title);
        } else {
            $subject = sprintf(__("[%s] Please moderate this new post request from '%s'", "tdomf"), get_bloginfo('title'), $submitter_name);
        }
    }
    // Email Body
    //
    if ($status == 'publish' || $status == 'future') {
        $email_msg = sprintf(__("Post \"%s\" from %s has been published.\n\n", "tdomf"), $title, $submitter_name);
    } else {
        $email_msg = sprintf(__("A new post with title \"%s\" from %s is awaiting your approval.\n\n", "tdomf"), $title, $submitter_string);
    }
    if ($is_spam) {
        $email_msg = __("This post is considered SPAM\n\n", "tdomf");
    }
    $email_msg .= sprintf(__("Form ID: %d (\"%s\")\n", "tdomf"), $form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $form_id));
    $email_msg .= sprintf(__("Submitter IP: %s\n\n", "tdomf"), $ip);
    $email_msg .= sprintf(__("View Post: %s\n", "tdomf"), $view_post_link);
    if ($status != 'publish' && $status != 'future') {
        $email_msg .= sprintf(__("Publish Post (will also flag post as not SPAM): %s.\n", "tdomf"), $publish_post_link);
        $email_msg .= sprintf(__("Edit Post: %s\n", "tdomf"), $edit_post_link);
        if (!$is_spam && get_option(TDOMF_OPTION_SPAM)) {
            $email_msg .= sprintf(__("Flag Post as SPAM: %s\n", "tdomf"), $spam_link);
        } else {
            if ($is_spam) {
                $email_msg .= sprintf(__("Flag Post as not SPAM: %s\n", "tdomf"), $ham_link);
            }
        }
        $email_msg .= sprintf(__("Ban IP: %s\n", "tdomf"), $ban_ip_link);
        if ($can_ban_user) {
            $email_msg .= sprintf(__("Ban User: %s\n", "tdomf"), $ban_user_link);
        }
        $email_msg .= sprintf(__("Delete Post: %s\n", "tdomf"), $delete_post_link);
    }
    $email_msg .= sprintf(__("You can moderate all submissions from %s.\n", "tdomf"), $moderate_all_link);
    if ($is_spam) {
        $email_msg .= sprintf(__("\nTitle of the post: %s", "tdomf"), $title);
    }
    $email_msg .= sprintf(__("\nContent of the post: \n\n %s \n\n", "tdomf"), $content);
    // Widgets:adminemail
    //
    $widget_args = array("post_ID" => $post_ID, "before_widget" => "", "after_widget" => "\n\n", "before_title" => "", "after_title" => "\n\n", "tdomf_form_id" => $form_id, "tdomf_post_id" => $post_ID);
    $widget_order = tdomf_get_widget_order($form_id);
    foreach ($widget_order as $w) {
        if (isset($tdomf_form_widgets_adminemail[$w])) {
            $temp_message = call_user_func($tdomf_form_widgets_adminemail[$w]['cb'], $widget_args, $tdomf_form_widgets_adminemail[$w]['params']);
            if ($temp_message != NULL && trim($temp_message) != "") {
                $email_msg .= $temp_message;
            }
        }
    }
    $email_msg .= sprintf(__("Best Regards\nTDOMF @ %s", "tdomf"), get_bloginfo("title"));
    // prepare body
    //
    $email_msg = str_replace("\n", "\r\n", $email_msg);
    // Use custom from field
    //
    if (tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id)) {
        // We can modify the "from" field by using the "header" option at the end!
        //
        $headers = "MIME-Version: 1.0\n" . "From: " . tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id) . "\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
        return @wp_mail($email_list, $subject, $email_msg, $headers);
    } else {
        return @wp_mail($email_list, $subject, $email_msg);
    }
}
Exemplo n.º 17
0
 function aioseop_list_pages($content)
 {
     global $wp_version;
     $matches = array();
     if (preg_match_all('/<li class="page_item page-item-(\\d+)/i', $content, $matches)) {
         update_postmeta_cache(array_values($matches[1]));
         unset($matches);
         if ($wp_version >= 3.3) {
             $pattern = '@<li class="page_item page-item-(\\d+)([^\\"]*)"><a href=\\"([^\\"]+)">@is';
         } else {
             $pattern = '@<li class="page_item page-item-(\\d+)([^\\"]*)"><a href=\\"([^\\"]+)" title="([^\\"]+)">@is';
         }
         return preg_replace_callback($pattern, "aioseop_filter_callback", $content);
     }
     return $content;
 }
Exemplo n.º 18
0
function update_post_caches(&$posts)
{
    global $post_cache;
    global $wpdb, $blog_id;
    // No point in doing all this work if we didn't match any posts.
    if (!$posts) {
        return;
    }
    // Get the categories for all the posts
    for ($i = 0; $i < count($posts); $i++) {
        $post_id_array[] = $posts[$i]->ID;
        $post_cache[$blog_id][$posts[$i]->ID] =& $posts[$i];
    }
    $post_id_list = implode(',', $post_id_array);
    update_object_term_cache($post_id_list, 'post');
    update_postmeta_cache($post_id_list);
}
Exemplo n.º 19
0
/**
 * Call major cache updating functions for list of Post objects.
 *
 * @package WordPress
 * @subpackage Cache
 * @since 1.5.0
 *
 * @uses $wpdb
 * @uses update_post_cache()
 * @uses update_object_term_cache()
 * @uses update_postmeta_cache()
 *
 * @param array $posts Array of Post objects
 * @param string $post_type The post type of the posts in $posts. Default is 'post'.
 * @param bool $update_term_cache Whether to update the term cache. Default is true.
 * @param bool $update_meta_cache Whether to update the meta cache. Default is true.
 */
function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true)
{
    // No point in doing all this work if we didn't match any posts.
    if (!$posts) {
        return;
    }
    update_post_cache($posts);
    $post_ids = array();
    foreach ($posts as $post) {
        $post_ids[] = $post->ID;
    }
    if (empty($post_type)) {
        $post_type = 'post';
    }
    if ($update_term_cache) {
        if (is_array($post_type)) {
            $ptypes = $post_type;
        } elseif ('any' == $post_type) {
            // Just use the post_types in the supplied posts.
            foreach ($posts as $post) {
                $ptypes[] = $post->post_type;
            }
            $ptypes = array_unique($ptypes);
        } else {
            $ptypes = array($post_type);
        }
        if (!empty($ptypes)) {
            update_object_term_cache($post_ids, $ptypes);
        }
    }
    if ($update_meta_cache) {
        update_postmeta_cache($post_ids);
    }
}
Exemplo n.º 20
0
function departure_load_new_tweets()
{
    global $post;
    static $field_hashtag = 'departure_blogtrip_hashtag';
    static $field_tweets_data = 'departure_tweets_cache_data';
    static $field_tweet_since_id = '_departure_tweet_since_id';
    static $field_date_start = 'departure_date_start';
    static $field_date_end = 'departure_date_end';
    static $field_image_cache = '_departure_tweet_image_cache';
    static $media_sizes = array('large', 'medium', 'small', 'thumb');
    add_filter('posts_join', 'departure_load_tweets_join');
    add_filter('posts_where', 'departure_load_tweets_where');
    add_filter('post_limits', 'departure_load_tweets_limit');
    $args = array('post_type' => 'departure', 'post_status' => 'publish');
    query_posts($args);
    remove_filter('posts_join', 'departure_load_tweets_join');
    remove_filter('posts_where', 'departure_load_tweets_where');
    remove_filter('post_limits', 'departure_load_tweets_limit');
    if (have_posts()) {
        while (have_posts()) {
            the_post();
            // get hashtag, since, last load time
            update_postmeta_cache(get_the_ID());
            $custom_meta = get_post_custom();
            $hash_tag = $custom_meta[$field_hashtag][0];
            // get tweets
            $tweets = unserialize($custom_meta[$field_tweets_data][0]);
            if (!is_array($tweets) || !$tweets) {
                $tweets = array();
            }
            $tweet_images = unserialize($custom_meta[$field_image_cache][0]);
            if (!is_array($tweet_images) || !$tweet_images) {
                $tweet_images = array();
            }
            $since_id = $custom_meta[$field_tweet_since_id][0];
            $date_start = $custom_meta[$field_date_start][0];
            $date_end = $custom_meta[$field_date_end][0];
            // store tweets
            $new_tweets = get_new_tweets($hash_tag, $since_id, $date_start, $date_end, $tweets);
            // get and attach photos
            // use media_sideload_image();
            foreach ($new_tweets as $twit) {
                if (isset($tweets[$twit->id_str])) {
                    continue;
                }
                if (!isset($twit->entities->media)) {
                    continue;
                }
                foreach ($twit->entities->media as $media) {
                    if ('photo' == $media->type) {
                        foreach ($media_sizes as $size) {
                            if (isset($media->sizes->{$size}) && !isset($tweet_images[$media->media_url])) {
                                // $html = "<img src='$src' alt='$alt' />";
                                $html_str = media_sideload_image($media->media_url . ':' . $size, get_the_ID(), urldecode($twit->text));
                                if (is_string($html_str)) {
                                    // attachment processed success
                                    $src = substr($html_str, strpos($html_str, 'src=\'') + 5, strpos($html_str, '\'', strpos($html_str, 'src=\'') + 5) - strpos($html_str, 'src=\'') - 5);
                                    // get attachments id
                                    $id = get_attachment_id_from_guid($src);
                                    // add to post id custom fields
                                    add_post_meta($id, '_twits_id_str', $twit->id_str);
                                    add_post_meta($id, '_twits_url_str', sprintf('http://twitter.com/%s/status/%s', $twit->from_user, $twit->id_str));
                                    $tweet_images[$media->media_url] = array('_twits_id_str' => $twit->id_str, 'attachment_id' => $id);
                                    break;
                                } else {
                                    // attachment failed - delete them
                                    wp_delete_attachment($html_str);
                                }
                            }
                        }
                    }
                }
            }
            ksort($new_tweets);
            $new_tweets = array_reverse($new_tweets);
            // add to custom tweet field twits and images
            $tweets = array_merge($new_tweets, $tweets);
            update_post_meta(get_the_ID(), $field_tweets_data, $tweets);
            update_post_meta(get_the_ID(), $field_image_cache, $tweet_images);
            // set new last time
            $since_id = max(array_keys($tweets));
            update_post_meta(get_the_ID(), $field_tweet_since_id, $since_id);
        }
    }
}