0byt3m1n1
Path:
/
home1
/
aserty
/
public_html
/
appartsoft.info
/
wp-content
/
plugins
/
content revenge
/
[
Home
]
File: index.php
<?php /* Plugin Name: Content Revenge Version: 2.06 Author: IM Revenge Description: Content Revenge is a revolutionary content generation plugin that can instantly create thousands of high quality / high ranking posts with just a click of a button. */ function bossContent_Generate() { global $wpdb; // GET OPTIONS DATA FROM wp_options TABLE $content_revenge_options = get_option('ContentRevenge'); // Build date YYYY-MM-DD $post_date_var = $content_revenge_options['start_y'].'2000'.$content_revenge_options['start_m'].'-'.$content_revenge_options['start_d']; //$phpBay = $content_revenge_options['php_bay']; // v2.0 //$phpBayCat = $content_revenge_options['php_bay_cat']; // v2.0 // DEFINE BAD CHARACTERS TO BE STRIPPED $stripChrsName = array('`','~','!','@','#','$','%','^','&','*','(',')','+','=','{','}','[',']',':',';','"','’','\'','\\','|',',','.','?'); // GENERATE KEYWORDS ARRAY $keywordsArray = explode("\r\n", $content_revenge_options['keywords']); // INITIALIZE POST COUNTERS (DAILY AND TOTAL) AND RANDOMLY SET NUMBER OF POSTS PER DATE $p = 0; $pTotal = 0; if ($content_revenge_options['ag_posts_from'] === $content_revenge_options['ag_posts_to']) { $ppd = $content_revenge_options['ag_posts_from']; } else { $ppd = mt_rand($content_revenge_options['ag_posts_from'], $content_revenge_options['ag_posts_to']); } // BEGIN POST GENERATION LOOP foreach($keywordsArray as $keywords) { $post_title = trim($keywords); // CHECK wp_posts TABLE FOR DUPLICATE/EXISTING POST TITLES $sql = $wpdb->prepare("SELECT * FROM `".$wpdb->posts."` WHERE `post_title` = %s AND ( `post_status` = 'publish' OR `post_status` = 'future' )", array( $post_title ) ); $result = $wpdb->get_results($sql, ARRAY_A); // IF THERE ARE NO DUPLICATE TITLES if ($wpdb->num_rows == 0) { // GENERATE RANDOM POST TIMES $post_time_hour = mt_rand(0, 23); if ($post_time_hour <= 9) $post_time_hour = '0'.$post_time_hour; $post_time_min = mt_rand(0, 59); if ($post_time_min <= 9) $post_time_min = '0'.$post_time_min; $post_time_sec = mt_rand(0, 59); if ($post_time_sec <= 9) $post_time_sec = '0'.$post_time_sec; $post_time = $post_time_hour.':'.$post_time_min.':'.$post_time_sec; // WRITE NEW POST DATA TO wp_posts TABLE // ASSIGN TABLE VARIABLES $post_author = '1'; $post_date = $post_date_var.' '.$post_time; $post_date_gmt = date('Y-m-d H:i:s', strtotime($post_date) + (mt_rand(5, 12) * 3600)); $post_title = ucwords($post_title); $post_content = '[cr]'; // PREPEND phpBAY USING SHORT TAGS (!! THIS WILL BE A v.2.0 FEATURE !!) /*if ($phpBay == 'on') { $post_content .= '[phpbay]'.$post_title.', 50, \"'.$phpBayCat.'\"[/phpbay] <div style=\"clear: both;\"></div>'; }*/ $post_excerpt = ''; if ($post_date <= date('Y-m-d H:i:s')) $post_status = 'publish'; if ($post_date > date('Y-m-d H:i:s')) $post_status = 'future'; $comment_status = 'open'; $ping_status = 'open'; $post_password = ''; $post_name = str_replace(' ', '-', strtolower($post_title)); $post_name = str_replace(' ', '-', $post_name); $post_name = str_replace($stripChrsName, '', $post_name); $to_ping = ''; $pinged = ''; $post_modified = $post_date; $post_modified_gmt = $post_date_gmt; $post_content_filtered = ''; $post_parent = '0'; $guid = ''; $menu_order = '0'; $post_type = 'post'; $post_mime_type = ''; $comment_count = '0'; // Insert new post $wpdb->insert( $wpdb->posts, array( 'post_author' => $post_author, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_content' => $post_content, 'post_title' => $post_title, 'post_excerpt' => $post_excerpt, 'post_status' => $post_status, 'comment_status' => $comment_status, 'ping_status' => $ping_status, 'post_password' => $post_password, 'post_name' => $post_name, 'to_ping' => $to_ping, 'pinged' => $pinged, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt, 'post_content_filtered' => $post_content_filtered, 'post_parent' => $post_parent, 'guid' => $guid, 'menu_order' => $menu_order, 'post_type' => $post_type, 'post_mime_type' => $post_mime_type, 'comment_count' => $comment_count ), array( '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%s', '%s', '%d', ) ); // GET AUTO-INCREMENTED ID FOR POST JUST GENERATED $ID = $wpdb->insert_id; // UPDATE wp_posts TABLE WITH NEW guid $guid = site_url().'/?p='.$ID; $wpdb->update( $wpdb->posts, array( 'guid' => $guid ), array('ID' => $ID), array('%s'), array('%d') ); // WRITE NEW POST CATEGORY TO wp_terms, wp_term_relationships AND wp_term_taxonomy TABLES // ASSIGN THE CATEGORY ASSOCIATION // GET POST CATEGORY ID (term_id) $term_id = $content_revenge_options['post_cat']; // GET EXISTING POST COUNT PER CATGORY FROM wp_term_taxonomy TABLE $sql = $wpdb->prepare(" SELECT * FROM `".$wpdb->term_taxonomy."` WHERE `term_id` = %d AND `taxonomy` = 'category'", array( $term_id )); $term_taxs = array(); $term_taxs = $wpdb->get_row($sql, ARRAY_A); if (count($term_taxs) > 0) { $term_taxonomy_id = $term_taxs['term_taxonomy_id']; $countTerm = $term_taxs['count']; $countNew = $countTerm + 1; // UPDATE wp_term_taxonomy TABLE WITH NEW POST COUNT $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $countNew ), array('term_taxonomy_id' => $term_taxonomy_id, 'taxonomy' => 'category'), array('%d'), array('%d') ); // INSERT POST ID (object_id) AND term_taxonomy_id INTO wp_term_relationships TABLE $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $ID, 'term_taxonomy_id' => $term_taxonomy_id, 'term_order' => 0 ), array( '%d', '%d', '%d' ) ); } // ADD 1 TO THE DAILY AND TOTAL POST COUNTERS $p++; $pTotal++; // LIMIT POST GENERATION PROCESS TO 1000 POSTS if ($pTotal == 1000) break; if ($p == $ppd) { // ADD ONE DAY TO THE POST DATE $post_date_var = date('Y-m-d', strtotime($post_date_var) + 86400); // RANDOMLY RE-SET NUMBER OF POSTS PER DATE if ($content_revenge_options['ag_posts_from'] === $content_revenge_options['ag_posts_to']) { $ppd = $content_revenge_options['ag_posts_from']; } else { $ppd = mt_rand($content_revenge_options['ag_posts_from'], $content_revenge_options['ag_posts_to']); } $p = 0; } } // END if($rows == 0) [NO DUPLICATE TITLES] } // OUTPUT MESSAGE AT TOP OF ADMIN PANEL WHEN SAVED echo '<div class="updated"><p><strong>Options Saved & '.$pTotal.' Posts Generated</strong></p></div>'; } function bossContent_get_it($post_id, $content, $query_type) { global $post; // Load options $content_revenge_options = get_option('ContentRevenge'); // GET POST INFO FROM POST ARRAY $postID = get_the_ID(); $title = $post->post_title; //$title = get_the_title(); $origContent = $content; $keywords = $title; // GET OPTIONS DATA FROM wp_options TABLE $key = $content_revenge_options['oauth_key']; $secret = $content_revenge_options['oauth_secret']; $countFrom = $content_revenge_options['count_from']; $countTo = $content_revenge_options['count_to']; $prepend = $content_revenge_options['prepend']; // Wikipedia, About, YouTube and News checkboxes $wikipedia = $content_revenge_options['wikipedia_results']; $about = $content_revenge_options['about_results']; $youtube = $content_revenge_options['youtube_results']; $news = $content_revenge_options['news_results']; $docIcons = $content_revenge_options['doc_icons']; #$phpBay = $content_revenge_options['php_bay']; // V2 #$phpBayCat = $content_revenge_options['php_bay_cat']; // V2 $adult = $content_revenge_options['adult']; // Check if wikipedia is checked if ($wikipedia !== 'on' && $query_type == 'wikipedia') { return array(); } // Check if about is checked if ($about !== 'on' && $query_type == 'about') { return array(); } // Check if youtube is checked if ($youtube !== 'on' && $query_type == 'youtube') { return array(); } // Check if youtube is checked if ($news !== 'on' && $query_type == 'news') { return array(); } if ($adult == 'on') { $filter = '-porn,-hate'; } else { $filter = ''; } $images = $content_revenge_options['images']; // SET OTHER REQUIRED API PARAMETERS $startWeb = '0'; $startImages = '0'; $countWeb = '50'; $countImages = '50'; // Set negative keywords filter $negative_keywords_filter_array = explode("\r\n", $content_revenge_options['negative_keywords']); $negative_keywords_filter = ''; $negative_keywords = ''; foreach ($negative_keywords_filter_array as $value) { if (trim($value) !== '') { $negative_keywords .= ' -'.$value; } } // CONSTRUCT THE API cURL if ($query_type !== 'news') { $args = array(); $args['format'] = 'json'; $args['filter'] = $filter; $args['q'] = $keywords.' -torrent'.$negative_keywords; $args['web.start'] = $startWeb; $args['web.count'] = $countWeb; $args['abstract'] = 'long'; } else { $args = array(); $args['format'] = 'json'; $args['q'] = $keywords.' -torrent'.$negative_keywords; $args['start'] = $startWeb; $args['count'] = $countWeb; $args['abstract'] = 'long'; } if ($query_type != 'wikipedia' && $query_type != 'about' && $query_type != 'youtube' && $query_type != 'news') { $args['type'] = 'pdf,xl,msword,ppt'; } $args['sites'] = '-lycos.com,-tripod.com'; // Check if wikipedia is checked if ($wikipedia == 'on' && $query_type == 'wikipedia') { $args['sites'] = 'wikipedia.org'; } // Check if about is checked if ($about == 'on' && $query_type == 'about') { $args['sites'] = 'about.com'; } // Check if youtube is checked if ($youtube == 'on' && $query_type == 'youtube') { $args['sites'] = 'youtube.com'; } // IF IMAGES OPTION IS 'on' if ($images == 'on') { $args['images.start'] = $startImages; $args['images.count'] = $countImages; if ($query_type == 'news') { $apiURL = 'http://yboss.yahooapis.com/ysearch/news,images'; } else { $apiURL = 'http://yboss.yahooapis.com/ysearch/web,images'; } } else { if ($query_type == 'news') { $apiURL = 'http://yboss.yahooapis.com/ysearch/news'; } else { $apiURL = 'http://yboss.yahooapis.com/ysearch/web'; } } // LOAD OAuth PHP LIBRARY require('OAuth.php'); // CALL TO THE OAuth FUNCTIONS $consumer = new OAuthConsumer($key, $secret); $request = OAuthRequest::from_consumer_and_token($consumer, NULL,'GET', $apiURL, $args); $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL); $apiURL = sprintf('%s?%s', $apiURL, OAuthUtil::build_http_query($args)); // cURL FUNCTIONS $ch = curl_init(); $headers = array($request->to_header()); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $apiURL); $rsp = curl_exec($ch); // FILL THE COMPLETE $results ARRAY WITH THE JSON RESPONSE $results = json_decode($rsp); curl_close($ch); // FILL RESULTS ARRAYS FOR EACH CATEGORY if ($query_type == 'news') { $resultsWeb = $results->bossresponse->news; } else { $resultsWeb = $results->bossresponse->web; } if ($images == 'on') { $resultsImages = $results->bossresponse->images; } // PARSE THE TOTAL RESULTS COUNT FOR EACH CATEGORY $totalResultsWeb = $resultsWeb->totalresults; if ($images == 'on') { $totalResultsImages = $resultsImages->totalresults; } // GET IMAGE RESULTS if ($images == 'on' && empty($resultsImages->results) == FALSE) { // INITIALIZE IMAGE COUNTER $i = 0; // ITERATE THROUGH IMAGE RESULTS ARRAY foreach ($resultsImages->results as $result) { $clickurl = $result->clickurl; $thumbnailurl = $result->thumbnailurl; //$filename = substr(($result->filename), 0, 22); $width = $result->width; $height = $result->height; $size = $result->size; $format = $result->format; $url = substr(($result->url), 0, 25); // GENERATE RANDOM ALT TAGS FOR IMAGES $alt_rand = mt_rand(1,7); switch ($alt_rand) { case 1: $alt = $keywords; break; case 2: $alt = $keywords.' images'; break; case 3: $alt = 'images of '.$keywords; break; case 4: $alt = $keywords.' photos'; break; case 5: $alt = 'photos of '.$keywords; break; case 6: $alt = $keywords.' pictures'; break; case 7: $alt = 'pictures of '.$keywords; break; } // GENERATE IMAGE HTML TO BE EMBEDDED WITH WEB RESULTS $imageHTML[$i] = '<a href="'.$clickurl.'" target="_blank">'; $imageHTML[$i] .= '<img src="'.$thumbnailurl.'" style="float:'; // GENERATE LEFT - RIGHT RANDOM IMAGE ALIGNMENT $align = mt_rand(1,2); if ($align == 1) { $imageHTML[$i] .= 'left'; } elseif ($align == 2) { $imageHTML[$i] .= 'right'; } $imageHTML[$i] .= '; margin:10px; max-width:25%;" alt="'.$alt.'" title="'.$alt.'" />'; $imageHTML[$i] .= '</a> '; // ADD 1 TO THE IMAGE COUNTER $i++; } } // END if ($images == 'on') // In case there are no web results $bossContentArray = array(); // GET WEB RESULTS if (!empty($resultsWeb->results)) { // INITIALIZE WEB RESULTS COUNTER $w = 0; // GENERATE RESULTS HTML // ITERATE THROUGH WEB RESULTS ARRAY foreach($resultsWeb->results as $result) { if ($query_type !== 'news') { $clickurl = $result->clickurl; } else { $clickurl = $result->url; } $title = $result->title; $title = utf8_encode(ucwords($title)); $abstract = utf8_encode($result->abstract); $abstract = str_replace('...','',$abstract); $abstract = trim($abstract); // CAPITALIZE THE FIRST CHARACTER OF $abstract (FOR SOME REASON, ucfirst() is not reliable) $abstractFirst = substr($abstract, 0, 1); $abstractFirstCap = strtoupper($abstractFirst); $abstract = substr($abstract, 1); $abstract = $abstractFirstCap.$abstract; if ($query_type !== 'news') { $dispurl = $result->dispurl; } if ($query_type === '') { $retreive = array( 'Retrieve Document', 'Document Retrieval', 'Retrieve Here', 'Retrieve Doc', 'Doc Retrieval', 'Retrieve Content', 'Content Retrieval', 'Fetch Document', 'Fetch Here', 'Fetch Doc', 'Fetch Content', 'Fetch This Document', 'Get Document', 'Get Content Here', 'Get Doc', 'View This Document', 'View Document', 'View Doc', 'Doc Viewer', 'Document Viewer', 'Visit Document', 'Read More', 'Read Document', 'Read Content', 'Read Here', 'Return Document', 'Return Doc', 'Access Document', 'Access Content', 'Access Doc', 'Access This Document', 'View Full Source', 'Retrieve Full Source', 'Read Full Source', 'Fetch Full Source', 'Access Full Source' ); } else if ($query_type == 'wikipedia') { $retreive = array( 'Read Article' ); } else if ($query_type == 'about') { $retreive = array( 'Read Article' ); } else if ($query_type == 'youtube') { $retreive = array( 'View Video' ); } else if ($query_type == 'news') { $retreive = array( 'Read News' ); } $webHTML[$w] = '<p style="float:left; width: 70%;">'; $webHTML[$w] .= '<a href="'.$clickurl.'" target="_blank">'; if ($docIcons == 'on') { // EMBED FILE-TYPE ICONS $pluginURL = WP_PLUGIN_URL.'/'.str_replace(basename(__FILE__),'',plugin_basename(__FILE__)); if (stripos($clickurl,'.pdf')) { $webHTML[$w] .= '<img src="'.$pluginURL.'images/pdf.png" alt="PDF file" title="PDF file" /> '; } if (stripos($clickurl,'.doc')) { $webHTML[$w] .= '<img src="'.$pluginURL.'images/doc.png" alt="Word file" title="Word file" /> '; } if (stripos($clickurl,'.xls')) { $webHTML[$w] .= '<img src="'.$pluginURL.'images/xl.png" alt="Excel file" title="Excel file" /> '; } if (stripos($clickurl,'.ppt')) { $webHTML[$w] .= '<img src="'.$pluginURL.'images/ppt.png" alt="PowerPoint file" title="PowerPoint file" /> '; } if ($query_type == 'wikipedia') { $webHTML[$w] .= '<img src="'.$pluginURL.'images/wikipedia.png" alt="Wikipedia" title="Wikipedia" /> '; } if ($query_type == 'about') { $webHTML[$w] .= '<img src="'.$pluginURL.'images/about.png" alt="About" title="About" /> '; } if ($query_type == 'youtube') { $webHTML[$w] .= '<img src="'.$pluginURL.'images/youtube.png" alt="YouTube" title="YouTube" /> '; } if ($query_type == 'news') { $webHTML[$w] .= '<img src="'.$pluginURL.'images/news.png" alt="News" title="News" /> '; } } $webHTML[$w] .= '<span style="font-weight:bold; text-transform:capitalize;">'.$title.'</span></a><br />'; $webHTML[$w] .= '<span>'.$abstract.' </span>'; $webHTML[$w] .= '<a href="'.$clickurl.'" target="_blank"> ... '.$retreive[array_rand($retreive)].'</a><br />'; $webHTML[$w] .= '</p>'; // ADD 1 TO THE WEB RESULTS COUNTER $w++; } // INITIALIZE BOSS CONTENT $bossContent = '<div style="margin: 10px 0;">'; // CALCULATE $start AND $count $countResults = count($resultsWeb->results); // 50 // Set 1 to 3 for wikipedia, about, youtube and news if ($wikipedia == 'on' && $query_type == 'wikipedia' || $about == 'on' && $query_type == 'about' || $youtube == 'on' && $query_type == 'youtube' || $news == 'on' && $query_type == 'news') { $countFrom = 1; $countTo = 3; $countOption = mt_rand($countFrom, $countTo); } else { $countOption = mt_rand($countFrom, $countTo); // 5 } if ($countResults <= $countOption) { $count = $countResults; } else { $count = $countOption; } $start = mt_rand(0,$countResults) - $count; if ($start < 0) { $start = 0; } $end = $start + $count - 1; if ($count < $countFrom) { $countBal = $countFrom - $count; $start = $start - $countBal; if ($start < 0) { $start = 0; } } for ($c = $start; $c <= $end; $c++) { $bossContent = ''; if ($bossContent != '<div style="margin: 10px 0;">') { $bossContent .= '<div style="margin: 10px 0;">'; } // EMBED IMAGE HTML INTO RESULTS if (isset($imageHTML[$c]) == TRUE) { $bossContent .= $imageHTML[$c]; } // EMBED WEB HTML INTO RESULTS $bossContent .= $webHTML[$c]; $bossContent .= '</div>'; $bossContent .= '<div style="clear: both;"></div>'; // Add each HTML post into array that we will return $bossContentArray[] = $bossContent; } } return $bossContentArray; } function bossContent_Populate($content) { global $wpdb; // DEFINE BAD CHARACTERS TO BE STRIPPED $stripChrsSlug = array('`','~','!','@','#','$','%','^','&','*','(',')','+','=','{','}','[',']',':',';','"','’','\'','\\','|',',','<','.','>','/','?','–','_',' '); // GET POST TYPE TO FILTER OUT 'PAGES' $post_type = get_post_type(); // IF POST IS NOT A 'PAGE' if ($post_type != 'page' && strpos($content, '[cr]') > '-1') { // Load options $content_revenge_options = get_option('ContentRevenge'); // GET POST INFO FROM POST ARRAY $postID = get_the_ID(); //$title = $post->post_title; $title = get_the_title(); $origContent = $content; $keywords = $title; // GET OPTIONS DATA FROM wp_options TABLE $termsAPI = $content_revenge_options['terms_api']; $prepend = stripslashes($content_revenge_options['prepend']); if ($prepend != '') { $prepend = str_replace('\"', '"', $prepend); $prepend = '<div>'.$prepend.'</div>'; } $bossContentArray = array(); $bossContentArray = array_merge( bossContent_get_it($postID, $content, ''), bossContent_get_it($postID, $content, 'wikipedia'), bossContent_get_it($postID, $content, 'about'), bossContent_get_it($postID, $content, 'youtube'), bossContent_get_it($postID, $content, 'news') ); shuffle($bossContentArray); $bossContent = implode('', $bossContentArray); // CONSTRUCT FINAL POST STRING if ($bossContent != '') { $content = str_replace('[cr]', $prepend.$bossContent, $origContent); } else if ($bossContent == '') { //$content = $origContent; // If the returned content is blank, simply delete this post // and add the keyword to the array that will be saved to options. wp_delete_post($postID, TRUE); // Save keyword to deleted list $content_revenge_options['deleted_keywords'][] = array('date' => date("Y-m-d"), 'keyword' => $title); // Save the array update_option('ContentRevenge', $content_revenge_options); // Stop here return $content; } $wpdb->update( $wpdb->posts, array( 'post_content' => $content ), array('ID' => $postID), array('%s'), array('%d') ); // ASSIGN THE TAG ASSOCIATIONS // CONSTRUCT APIcURL $apiURL = 'http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction'; $context = $content; $output = 'json'; $post_values = array( 'appid' => $termsAPI, 'context' => $context, 'output' => $output ); $post_string = ''; foreach($post_values as $key => $value) { $post_string .= $key.'='.urlencode($value).'&'; } $post_string = rtrim($post_string, '& '); // cURL FUNCTIONS $request = curl_init($apiURL); curl_setopt($request, CURLOPT_HEADER, 0); curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); $rsp = curl_exec($request); // FILL THE COMPLETE $results ARRAY WITH THE JSON RESPONSE $results = json_decode($rsp); curl_close ($request); // PARSE THE $results ARRAY // SET RANDOM NUMBER OF TERMS PER POST $termCount = 0; $termsMax = rand(7,12); $resultsTerms = $results->ResultSet->Result; if (empty($resultsTerms) == FALSE) { foreach ($resultsTerms as $resultsTerm) { $termCount++; // CHECK wp_terms TABLE FOR EXISTING/DUPLICATE TAGS $sql = $wpdb->prepare("SELECT * FROM `".$wpdb->terms."` WHERE `name` = %s", array( $resultsTerm )); $terms = $wpdb->get_results($sql, ARRAY_A); $termsCount = $wpdb->insert_id; // IF THERE ARE EXISTING/DUPLICATE TAGS if ($termsCount > 0) { // GET POST TAG ID (term_id) FROM wp_terms TABLE foreach ($terms as $term) { $term_id = $term['term_id']; // GET EXISTING POST COUNT PER TAG FROM wp_term_taxonomy TABLE $sql = $wpdb->prepare(" SELECT * FROM `".$wpdb->term_taxonomy."` WHERE `term_id` = %d AND `taxonomy` = 'post_tag'", array( $term_id )); $term_taxs = array(); $term_taxs = $wpdb->get_row($sql, ARRAY_A); $term_taxonomy_id = $term_taxs['term_taxonomy_id']; $countTerm = $term_taxs['count']; $countNew = $countTerm + 1; // UPDATE wp_term_taxonomy TABLE WITH NEW POST COUNT $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $countNew ), array('term_taxonomy_id' => $term_taxonomy_id, 'taxonomy' => 'post_tag'), array('%d'), array( '%d' ) ); // INSERT POST ID (object_id) AND term_taxonomy_id INTO wp_term_relationships TABLE $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $ID, 'term_taxonomy_id' => $term_taxonomy_id, 'term_order' => 0 ), array( '%d', '%d', '%d' ) ); } } else if ($termsCount == 0) { // WRITE THE NEW TAG NAME TO THE wp_terms TABLE $resultsTermSlug = strtolower($resultsTerm); $resultsTermSlug = str_replace($stripChrsSlug, '-', $resultsTermSlug); $wpdb->insert( $wpdb->terms, array( 'name' => $resultsTerm, 'slug' => $resultsTermSlug, 'term_group' => 0 ), array( '%s', '%s', '%d' ) ); // GET AUTO-INCREMENTED term_id FOR TAG JUST GENERATED $term_id = $wpdb->insert_id; // WRITE THE NEW TAG DATA TO wp_term_taxonomy TABLE (NEW POST COUNT) $wpdb->insert( $wpdb->term_taxonomy, array( 'term_id' => $term_id, 'taxonomy' => 'post_tag', 'parent' => 0, 'count' => 1 ), array( '%d', '%s', '%d', '%d' ) ); // GET AUTO-INCREMENTED term_taxonomy_id FOR TAG JUST GENERATED $term_taxonomy_id = $wpdb->insert_id; // INSERT POST ID (object_id) AND term_taxonomy_id INTO wp_term_relationships TABLE $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $postID, 'term_taxonomy_id' => $term_taxonomy_id ), array( '%d', '%d' ) ); } // IF RANDOM MAX TAG COUNT IS REACHED if ($termCount == $termsMax) break; } } } return $content; } add_filter('the_content', 'bossContent_Populate', '1'); // Adds a new sub menu page under Settings menu function bossContent_admin_actions() { add_options_page('Content Revenge', 'Content Revenge', 'manage_options', 'Content_Revenge', 'bossContent_admin'); } add_action('admin_menu', 'bossContent_admin_actions'); // Include the admin page function bossContent_admin() { include('contentRevenge_admin.php'); } // Load the JS file function ContentRevenge_js() { wp_enqueue_script('loadjs', plugins_url('content-revenge').'/functions.js'); } add_action('admin_enqueue_scripts', 'ContentRevenge_js'); // Sets AJAX in the admin area function ContentRevenge_ajax_calls() { ?> <script type="text/javascript"> /* <![CDATA[ */ $j = jQuery.noConflict(); $j(document).ready(function() { $j('#cr_validate_keys').live('click', function(){ var key = $j('#ContentRevenge_key').val(); var secret = $j('#ContentRevenge_secret').val(); var termsAPI = $j('#ContentRevenge_termsAPI').val(); if (key == '') { alert('<?php _e('Please enter OAuth Consumer Key', 'ContentRevenge_trdom'); ?>'); } else if (secret == '') { alert('<?php _e('Please enter OAuth Consumer Secret', 'ContentRevenge_trdom'); ?>'); } else if (termsAPI == '') { alert('<?php _e('Please enter Yahoo! Term Extraction App ID', 'ContentRevenge_trdom'); ?>'); } else { var url_data = 'action=cr_validate&security=<?php echo wp_create_nonce('cr_check_validation'); ?>&key=' + encodeURIComponent(key) + '&secret=' + encodeURIComponent(secret); $j('#cr_validate_status').html('<img src="<?php echo admin_url(); ?>images/wpspin_light.gif" alt=""/> <?php _e('Please wait...', 'ContentRevenge_trdom'); ?>'); $j.ajax({ url: ajaxurl, type: "POST", data: url_data, cache: false, dataType: "json", success: function (respond) { if (respond.status == 'success') { $j('#cr_validate_status').html('<?php _e('Validation was successful!', 'ContentRevenge_trdom'); ?> <a href="#" id="cr_validate_keys"><?php _e('Try Again.', 'ContentRevenge_trdom'); ?></a>'); } else if (respond.status == 'error_wrong_boss_keys') { $j('#cr_validate_status').html('<span style="color: #FF0000;"><?php _e('Invalid OAuth Key and/or Secret!', 'ContentRevenge_trdom'); ?> <a href="#" id="cr_validate_keys"><?php _e('Try Again.', 'ContentRevenge_trdom'); ?></a></span>'); } } }); } return false; }); $j('#cr_clear_keywords').live('click', function(){ $j.ajax({ url: ajaxurl, type: "POST", data: 'action=cr_clear_deleted_keywords&security=<?php echo wp_create_nonce('cr_clear_keywords'); ?>', cache: false, dataType: "json", success: function (respond) { if (respond.status == 'error_not_cleared') { alert('<?php _e('Deleted keywords not cleared. Please try again.', 'ContentRevenge_trdom'); ?>'); } else if (respond.status == 'success') { $j('#cr_deleted_keywords_textarea').val(''); } } }); }); }); </script> <?php } add_action('admin_head', 'ContentRevenge_ajax_calls'); // Callback function for AJAX. // Makes a general call to yahoo boss and check if the result was successful or not. function ContentRevenge_validate_ajax_respond() { check_ajax_referer('cr_check_validation', 'security'); // Get the OAuth key $key = isset($_POST['key']) == TRUE ? $_POST['key'] : FALSE; // Only a-z and 0-9 chars are valid. if (preg_match('/^([-a-z0-9_]+)$/i', $key) == FALSE) { // Just kill the ajax call right away. die(); } // Get the OAuth secret $secret = isset($_POST['secret']) == TRUE ? $_POST['secret'] : FALSE; // Only a-z and 0-9 chars are valid. if (preg_match('/^([a-z0-9]+)$/i', $secret) == FALSE) { // Just kill the ajax call right away. die(); } // Yahoo BOSS API url $apiURL = 'http://yboss.yahooapis.com/ysearch/web'; // CONSTRUCT THE API cURL $args = array(); $args['format'] = 'json'; $args['q'] = 'yahoo'; // LOAD OAuth PHP LIBRARY require('OAuth.php'); // CALL TO THE OAuth FUNCTIONS $consumer = new OAuthConsumer($key, $secret); $request = OAuthRequest::from_consumer_and_token($consumer, NULL, 'GET', $apiURL, $args); $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL); $apiURL = sprintf('%s?%s', $apiURL, OAuthUtil::build_http_query($args)); // cURL FUNCTIONS $ch = curl_init(); $headers = array($request->to_header()); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $apiURL); $rsp = curl_exec($ch); // FILL THE COMPLETE $results ARRAY WITH THE JSON RESPONSE $results = json_decode($rsp); curl_close($ch); // Check if the error object exist if (isset($results->error->description) == TRUE) { // Looks like the API keys are wrong. ?> { "status" : "error_wrong_boss_keys" } <?php // Also kill the ajax here. die(); } // If we came to this point, it means that both validations were successful! ?> { "status" : "success" } <?php die(); } add_action('wp_ajax_cr_validate', 'ContentRevenge_validate_ajax_respond'); // Function that brings dead posts back to life function ContentRevenge_bring_back_mia_posts() { global $wpdb; $delay = 1; // Load options $content_revenge_options = get_option('ContentRevenge'); if (isset($content_revenge_options['mia_post_time']) == FALSE) { $content_revenge_options['mia_post_time'] = ''; } // Remove action remove_action('publish_future_post', 'check_and_publish_future_post'); // Let's see if enough time passed from last publish $last_time = $content_revenge_options['mia_post_time']; if (($last_time !== false) && ($last_time > (time() - ($delay * 60)))) { return; // Too little time passed, bail here } // Update to the current time $content_revenge_options['mia_post_time'] = time(); update_option('ContentRevenge', $content_revenge_options); // Find MIA post_IDs, try both LOCAL datetime and GMT datetime $scheduledIDs = $wpdb->get_col($wpdb->prepare( "SELECT `ID` FROM `$wpdb->posts` WHERE ( ((`post_date` > 0 ) && (`post_date` <= CURRENT_TIMESTAMP())) OR ((`post_date_gmt` > 0) && (`post_date_gmt` <= UTC_TIMESTAMP())) ) AND `post_status` = 'future'")); if(count($scheduledIDs) == FALSE) { return; // None found ... bail } $scheduledIDsU = array_unique($scheduledIDs); foreach($scheduledIDsU as $scheduledID) { if($scheduledID == FALSE) { continue; // Just in case } // Publish each post_ID the Wordpress friendly way wp_publish_post($scheduledID); } } add_action('init', 'ContentRevenge_bring_back_mia_posts', 0); // Callback function for AJAX. // Clears the deleted keyword list from options. function ContentRevenge_clear_deleted_keywords_ajax_respond() { check_ajax_referer('cr_clear_keywords', 'security'); // Load options $content_revenge_options = get_option('ContentRevenge'); if (isset($content_revenge_options['deleted_keywords']) == TRUE) { unset($content_revenge_options['deleted_keywords']); update_option('ContentRevenge', $content_revenge_options); ?> { "status" : "success" } <?php die(); } ?> { "status" : "" } <?php die(); } add_action('wp_ajax_cr_clear_deleted_keywords', 'ContentRevenge_clear_deleted_keywords_ajax_respond'); ?>