/**
  * The ping method modified to use our enclosure method over WordPress'
  */
 function do_all_pings()
 {
     global $wpdb;
     // Do pingbacks
     while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
         $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
         pingback($ping->post_content, $ping->ID);
     }
     # Do enclosures if enabled, and if doing enclosures, use our custom method
     if (get_option('pod_disable_enclose') != 'yes') {
         // Do Enclosures
         while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
             $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme';", $enclosure->ID));
             $this->do_enclose($enclosure->post_content, $enclosure->ID);
         }
     }
     // Do Trackbacks
     $trackbacks = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE to_ping <> '' AND post_status = 'publish'");
     if (is_array($trackbacks)) {
         foreach ($trackbacks as $trackback) {
             do_trackbacks($trackback);
         }
     }
     //Do Update Services/Generic Pings
     generic_ping();
 }
function ryo_old2new()
{
    global $wpdb;
    $hours = 24;
    /*
     * Set number of hours after which oldest will be made the newest
     * If you have a lot of posts, a daily rotation may be okay. Otherwise we suggest you
     * adjust this to a matter of days, weeks, or months.
     * Note: If you are caching with WP_Cache updates may not be immediately visible at time expiration.
     */
    // *** You Should Have No Need To Change Anything Below Here ***
    $now = abs(strtotime(current_time('mysql')));
    $newestposttime = $wpdb->get_var("SELECT post_date FROM {$wpdb->posts} WHERE post_date != '0000-00-00 00:00:00' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
    if ($newestposttime && $now - abs(strtotime($newestposttime)) > $hours * 3600) {
        $oldpost = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_date != '0000-00-00 00:00:00' AND post_status = 'publish' ORDER BY post_date LIMIT 1");
        if ($oldpost) {
            $timestamp = current_time('mysql');
            $gmtstamp = get_gmt_from_date($timestamp);
            $oldposttime = $wpdb->get_var("SELECT post_date FROM {$wpdb->posts} WHERE ID = {$oldpost} LIMIT 1");
            $wpdb->query("UPDATE {$wpdb->posts} SET post_date='{$timestamp}', post_date_gmt='{$gmtstamp}' WHERE ID='{$oldpost}'");
            generic_ping($oldpost);
        }
    }
}
/**
 * Perform all pingbacks, enclosures, trackbacks, and send to pingback services.
 *
 * @since 2.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 */
function do_all_pings()
{
    global $wpdb;
    // Do pingbacks
    while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
        delete_metadata_by_mid('post', $ping->meta_id);
        pingback($ping->post_content, $ping->ID);
    }
    // Do Enclosures
    while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
        delete_metadata_by_mid('post', $enclosure->meta_id);
        do_enclose($enclosure->post_content, $enclosure->ID);
    }
    // Do Trackbacks
    $trackbacks = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE to_ping <> '' AND post_status = 'publish'");
    if (is_array($trackbacks)) {
        foreach ($trackbacks as $trackback) {
            do_trackbacks($trackback);
        }
    }
    //Do Update Services/Generic Pings
    generic_ping();
}
function fwp_do_pings()
{
    if (!is_null($fwp_held_ping) and $post_id) {
        // Defer until we're done updating
        $fwp_held_ping = $post_id;
    } elseif (function_exists('do_all_pings')) {
        do_all_pings();
    } else {
        generic_ping($fwp_held_ping);
    }
}
/**
 * Perform all pingbacks, enclosures, trackbacks, and send to pingback services.
 *
 * @since 2.1.0
 * @uses $wpdb
 */
function do_all_pings()
{
    global $wpdb;
    // Do pingbacks
    while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
        $mid = $wpdb->get_var("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme' LIMIT 1");
        do_action('delete_postmeta', $mid);
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id = %d", $mid));
        do_action('deleted_postmeta', $mid);
        pingback($ping->post_content, $ping->ID);
    }
    // Do Enclosures
    while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
        $mid = $wpdb->get_var($wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme'", $enclosure->ID));
        do_action('delete_postmeta', $mid);
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id =  %d", $mid));
        do_action('deleted_postmeta', $mid);
        do_enclose($enclosure->post_content, $enclosure->ID);
    }
    // Do Trackbacks
    $trackbacks = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE to_ping <> '' AND post_status = 'publish'");
    if (is_array($trackbacks)) {
        foreach ($trackbacks as $trackback) {
            do_trackbacks($trackback);
        }
    }
    //Do Update Services/Generic Pings
    generic_ping();
}
function csyn_generic_ping($post_id)
{
    global $wpdb, $csyn_syndicator;
    $dates = $wpdb->get_row("SELECT post_date, post_modified FROM {$wpdb->posts} WHERE id={$post_id}");
    if ($csyn_syndicator->count <= 1 && $dates->post_modified == $dates->post_date && (strtotime($dates->post_modified < time()) || strtotime($dates->post_date) < time())) {
        if (function_exists('_publish_post_hook')) {
            _publish_post_hook($post_id);
        } else {
            generic_ping();
        }
    }
}
function do_all_pings() {
	global $wpdb;

	// Do pingbacks
	while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
		$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
		pingback($ping->post_content, $ping->ID);
	}

	// Do Enclosures
	while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
		$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");
		do_enclose($enclosure->post_content, $enclosure->ID);
	}

	// Do Trackbacks
	$trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'");
	if ( is_array($trackbacks) ) {
		foreach ( $trackbacks as $trackback )
			do_trackbacks($trackback->ID);
	}

	//Do Update Services/Generic Pings
	generic_ping();
}
Beispiel #8
0
/**
 * 依据给定的地址和规则采集并发表文章
 * @package WordPress
 * @subpackage Auto-Post-News
 * @since 0.0.1
 * @param array $news_args 所有需要用到的参数,参考示例
 * @return bool 成功则返回文章ID,失败则返回具体原因
 */
function post_news()
{
    $news_args = array('lock_file' => dirname(__FILE__) . '/post.lock', 'news_list_type' => 'rss', 'news_rss' => 'http://feeds.bbci.co.uk/news/business/rss.xml', 'news_max' => 2, 'auto_matche' => FALSE, 'news_pattern' => array(array('<!-- / story-body -->', '|<h1 class="story-header">([\\W\\w]*?)</h1>([\\W\\w]*?)</div><!-- / story-body -->|i'), array('<div id="page-bookmark-links-foot"', '|<h1 class="story-header">([\\W\\w]*?)</h1>([\\W\\w]*?)<div id="page-bookmark-links-foot"|i'), array('<table class="storycontent"', '|<table class="storycontent"[\\W\\w]*?<h1>([\\W\\w]*?)</h1>([\\W\\w]*?)<!-- body - End -->|i')), 'preg_replace' => array('|<noscript>[\\W\\w]*?</noscript>|i', '|<script[\\W\\w]*?</script>|i', '|<form[\\W\\w]*?</form>|i', '|<ul class="related-links-list">[\\W\\w]*?</ul>|i', '|<!--[\\W\\w]*?-->|i', '|<[a-z][^>]*></[^>]*>|i', '|<div class="read-more">[\\W\\w]*?</div>|i'), 'str_replace' => array("\n", "\t", "\r", "", "\v", '  ', 'Continue reading the main story'), 'has_content_post' => 'publish', 'no_content_post' => 'draft', 'author' => '1', 'category_name' => 'Business', 'rss_time' => FALSE, 'add_more' => array(TRUE, 1000, 500), 'publish_time' => TRUE, 'orgin_link' => TRUE);
    if (lock('check', $news_args['lock_file']) == 'locked') {
        return 'Locked';
    }
    ignore_user_abort(TRUE);
    $rss = fetch_feed($news_args['news_rss']);
    if (!is_wp_error($rss)) {
        $items = $rss->get_items();
    } else {
        lock('delete', $news_args['lock_file']);
        return $rss;
    }
    $post_guids = get_guids('numberposts=50&post_status=publish,draft');
    $allowedposttags = array('address' => array(), 'a' => array('href' => array(), 'id' => array(), 'title' => array(), 'rel' => array(), 'rev' => array(), 'name' => array(), 'target' => array()), 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), 'article' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'aside' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'b' => array(), 'big' => array(), 'blockquote' => array('id' => array(), 'cite' => array(), 'lang' => array(), 'xml:lang' => array()), 'br' => array('class' => array()), 'caption' => array('align' => array(), 'class' => array()), 'cite' => array('dir' => array(), 'lang' => array(), 'title' => array()), 'code' => array(), 'col' => array('align' => array(), 'char' => array(), 'charoff' => array(), 'span' => array(), 'dir' => array(), 'valign' => array(), 'width' => array()), 'del' => array('datetime' => array()), 'dd' => array(), 'details' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'open' => array(), 'xml:lang' => array()), 'dl' => array(), 'dt' => array(), 'em' => array(), 'figure' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'figcaption' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'font' => array('color' => array(), 'face' => array(), 'size' => array()), 'footer' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'h1' => array('align' => array(), 'id' => array()), 'h2' => array('align' => array(), 'id' => array()), 'h3' => array('align' => array(), 'id' => array()), 'h4' => array('align' => array(), 'id' => array()), 'h5' => array('align' => array(), 'id' => array()), 'h6' => array('align' => array(), 'id' => array()), 'header' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'hgroup' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'hr' => array('align' => array(), 'noshade' => array(), 'size' => array(), 'width' => array()), 'i' => array(), 'img' => array('alt' => array(), 'align' => array(), 'border' => array(), 'height' => array(), 'hspace' => array(), 'longdesc' => array(), 'vspace' => array(), 'src' => array(), 'width' => array()), 'ins' => array('datetime' => array(), 'cite' => array()), 'kbd' => array(), 'li' => array('align' => array(), 'class' => array()), 'menu' => array('type' => array()), 'p' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'pre' => array('width' => array()), 'q' => array('cite' => array()), 's' => array(), 'span' => array('dir' => array(), 'align' => array(), 'lang' => array(), 'title' => array(), 'xml:lang' => array()), 'section' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'strike' => array(), 'strong' => array(), 'sub' => array(), 'summary' => array('align' => array(), 'dir' => array(), 'lang' => array(), 'xml:lang' => array()), 'sup' => array(), 'table' => array('align' => array(), 'bgcolor' => array(), 'border' => array(), 'cellpadding' => array(), 'cellspacing' => array(), 'dir' => array(), 'id' => array(), 'rules' => array(), 'summary' => array(), 'width' => array()), 'tbody' => array('align' => array(), 'char' => array(), 'charoff' => array(), 'valign' => array()), 'td' => array('abbr' => array(), 'align' => array(), 'axis' => array(), 'bgcolor' => array(), 'char' => array(), 'charoff' => array(), 'colspan' => array(), 'dir' => array(), 'headers' => array(), 'height' => array(), 'nowrap' => array(), 'rowspan' => array(), 'scope' => array(), 'valign' => array(), 'width' => array()), 'tfoot' => array('align' => array(), 'char' => array(), 'charoff' => array(), 'valign' => array()), 'th' => array('abbr' => array(), 'align' => array(), 'axis' => array(), 'bgcolor' => array(), 'char' => array(), 'charoff' => array(), 'colspan' => array(), 'headers' => array(), 'height' => array(), 'nowrap' => array(), 'rowspan' => array(), 'scope' => array(), 'valign' => array(), 'width' => array()), 'thead' => array('align' => array(), 'char' => array(), 'charoff' => array(), 'valign' => array()), 'title' => array(), 'tr' => array('align' => array(), 'bgcolor' => array(), 'char' => array(), 'charoff' => array(), 'valign' => array()), 'tt' => array(), 'u' => array(), 'ul' => array('type' => array()), 'ol' => array('start' => array(), 'type' => array()), 'video' => array('autoplay' => array(), 'controls' => array(), 'height' => array(), 'loop' => array()), 'preload' => array(), 'src' => array(), 'width' => array());
    $count_post = 0;
    foreach ($items as $item) {
        $news_matche = array();
        $post = array();
        if (in_array($item->get_id(), $post_guids)) {
            continue;
        }
        $news = get_news($item->get_id());
        //提取正文
        if ($news == FALSE) {
            $post_content = $item->get_content();
            $post_status = $news_args['no_content_post'];
        } else {
            foreach ($news_args['news_pattern'] as $pattern) {
                if (!$news_args['auto_matche'] && stripos($news, $pattern['0'])) {
                    preg_match($pattern['1'], $news, $news_matche);
                    break;
                } else {
                    preg_match($pattern['1'], $news, $news_matche);
                }
            }
            //	    print_r($news_matche);
            if (!empty($news_matche)) {
                $post_content = $news_matche['2'];
                $post_status = $news_args['has_content_post'];
            } elseif ($item->get_content()) {
                $post_content = $item->get_content();
                $post_status = $news_args['no_content_post'];
            } else {
                continue;
            }
        }
        $post_content = custom_replace($post_content, $news_args['str_replace'], $news_args['preg_replace']);
        $post_content = wp_kses($post_content, $allowedposttags);
        $post_content = wptexturize($post_content);
        $post_content = popuplinks($post_content);
        $post_content = make_link_absolute($post_content, $item->get_id());
        if ($news_args['add_more']['0'] && strlen($post_content) > max(600, $news_args['add_more']['1'])) {
            $post_content = substr_replace($post_content, '<!--more-->', stripos($post_content, '</p>', max(300, $news_args['add_more']['2'])) + 4, 0);
        }
        if ($news_args['publish_time']) {
            $post_content .= '<br />Published at ' . $item->get_date(get_option('date_format') . ' ' . get_option('time_format')) . ' GMT';
        }
        if ($news_args['orgin_link']) {
            $post_content .= '<br />From: <a target="_blank"  title="' . $item->get_title() . '" href="' . $item->get_id() . '">' . $item->get_title() . '</a>';
        }
        //	echo $post_content . '<hr />';
        $post_category = term_exists($news_args['category_name'], 'category');
        if (!$post_category && $news_args['category_name']) {
            $post_category = wp_insert_term($news_args['category_name'], 'category');
        }
        $post = array('post_status' => $post_status, 'post_author' => $news_args['author'], 'post_category' => $post_category ? array($post_category['term_id']) : '', 'post_date' => $news_args['rss_time'] ? $item->get_date() : '', 'post_content' => $post_content, 'post_excerpt' => $item->get_description(), 'post_title' => $item->get_title(), 'tags_input' => '', 'guid' => $item->get_id());
        generic_ping(wp_insert_post($post));
        if (++$count_post >= $news_args['news_max']) {
            break;
        }
        sleep('1');
    }
    lock('delete', $news_args['lock_file']);
}
function fwp_do_pings () {
	if (!is_null($fwp_held_ping) and $post_id) : // Defer until we're done updating
		$fwp_held_ping = $post_id;
	elseif (function_exists('do_all_pings')) :
		do_all_pings();
	else :
		generic_ping($fwp_held_ping);
	endif;
}
            while ($enclosure = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
                delete_metadata_by_mid('post', $enclosure->meta_id);
                do_enclose($enclosure->post_content, $enclosure->ID);
            }
        }
        // Do Trackbacks
        if (apply_filters('vip_do_trackbacks', false)) {
            $trackbacks = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE to_ping <> '' AND post_status = 'publish' LIMIT 10");
            if (is_array($trackbacks)) {
                foreach ($trackbacks as $trackback) {
                    do_trackbacks($trackback);
                }
            }
        }
        // Do Update Services/Generic Pings
        generic_ping();
    });
}
/**
 * On Go, all API usage must be over HTTPS for security
 *
 * Filter `rest_url` to always return the https:// version
 *
 * If this must be disabled for local development, the filter
 * can be removed, but be aware that HTTPS is enforced at the web server
 * level in production, meaning non-HTTPS API calls will result in a 406 error.
 */
add_filter('rest_url', '_vip_filter_rest_url_for_ssl');
function _vip_filter_rest_url_for_ssl($url)
{
    $url = set_url_scheme($url, 'https');