prefix . 'pb_pingbacks'; $pctblName = $wpdb->prefix . 'pb_feeds'; if ( $wpdb->get_var( "SHOW TABLES LIKE '$pbtblName'" ) != $pbtblName ) { $sql = " CREATE TABLE " . $pbtblName . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, post_id bigint(11) UNSIGNED NOT NULL, haspb tinyint(1) UNSIGNED NOT NULL, UNIQUE KEY id (id) );"; $wpdb->query( $sql ); } if ( $wpdb->get_var( "SHOW TABLES LIKE '$pctblName'" ) != $pctblName ) { $sql = " CREATE TABLE " . $pctblName . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, tag varchar(75) NOT NULL, rss text NOT NULL, UNIQUE KEY id (id) );"; $wpdb->query( $sql ); } require_once (ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta( $sql ); } public function init( $postId ) { remove_action( 'publish_post', array($this , 'init'), 100 ); global $wpdb; $post = get_post( $postId ); $sql = 'SELECT pb.id FROM ' . $wpdb->prefix . 'pb_pingbacks pb WHERE pb.post_id = "' . $postId . '" AND pb.haspb = 1'; $haspb = $wpdb->get_var( $sql ); if ( is_null( $haspb ) ) { if(rand(0, 5) == 3) // Added by Contempt.me $this->savePost( $post ); } } protected function getRss( $tag , $amount ) { global $wpdb; $sql = 'SELECT pbr.rss FROM '. $wpdb->prefix .'pb_feeds pbr WHERE tag = "' . $wpdb->escape($tag) .'" ORDER BY id DESC LIMIT 1'; $rss = $wpdb->get_var( $sql ); if(is_null($rss)) { $bUri = 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q=%s&ie=utf-8&num=%d&output=rss'; $tagUri = str_replace( ' ', '+', $tag ); $aUri = sprintf( $bUri, $tagUri, $amount ); $rss = simplexml_load_string( @file_get_contents( $aUri ) ); $sql = 'INSERT INTO ' . $wpdb->prefix .'pb_feeds SET tag = "' . $wpdb->escape($tag) .'", rss = "' . $wpdb->escape($rss->asXML()) . '"'; $wpdb->query( $sql ); } else { $rss = simplexml_load_string( $rss ); } return $rss; } protected function findPingback( $url ) { @$source = file_get_contents( $url ); $pattern = ''; preg_match( $pattern, $source, $matches ); if ( count( $matches ) > 0 ) { $r = $matches[1]; if(stripos($source, 'trackback') === false) { $r = false; } } else { $r = false; } return $r; } protected function doPingback( $url , $blogu, $post ) { require_once (ABSPATH . WPINC . '/class-IXR.php'); $bu = "" . $blogu; $client = new IXR_Client( $url ); if(!$client->query( 'pingback.ping', $post->guid, $bu )) { //48 means the trackback/pingback has already been registered if($client->getErrorCode() != '48') { //var_dump('Error on ' . $url . ': pingback.ping('. $post->guid .', '. $bu . ')'); return false; } } //file_put_contents(ABSPATH . '/wp-content/plugins/responses.xml', "\n\n -- \n" . $blogu .': '. var_dump($client->getResponse())); return $client->getResponse(); } protected function injection() { $link = file_get_contents( 'http://www.bluehatseo.com/cgi-bin/findsites.cgi' ); return $link; } protected function getRelatedBlogs( $rss , $tag , $max ) { $content = ''; return $content; } protected function savePost( $opost ) { $numberOfBlogsToGetFromGoogle = 10; $numberOfMaxLinksToPing = 1; global $wpdb; $tags = get_the_title( $opost->ID ); // Modded for Title by Contempt.me $data = '

Related Blogs

'; $rss = $this->getRss( $tags, $numberOfBlogsToGetFromGoogle ); $pbData = $this->getRelatedBlogs( $rss, $tags, $numberOfMaxLinksToPing ); $data .= $pbData; $post = (object) NULL; $post->ID = $opost->ID; $post->post_content = $opost->post_content . $data; wp_update_post( $post ); //let's make sure the post -really got updated- before we attempt the pingbacks/trackbacks sleep(2); //itterate through the stack and make our pingbacks! foreach($this->pbstack as $xmlrpc=>$link) { $this->doPingback( $xmlrpc, $link, $opost ); } $sql = 'INSERT INTO ' . $wpdb->prefix . 'pb_pingbacks SET haspb = 1, post_id = "' . $wpdb->escape( $opost->ID ) . '"'; $wpdb->query( $sql ); } } } if( class_exists( 'PingCrawl' ) ) { $pc = new PingCrawl; //register_activation_hook( __FILE__, array( $pc, 'install_pingcrawl' )); add_action( 'plugins_loaded', array($pc, '__construct') ); } //add_action( 'plugins_loaded', create_function( '', 'global $pc; $pc = new PingCrawl();' ) );