posts} WHERE post_status='publish' AND post_type='post' ORDER BY post_modified_gmt DESC;"; $posts = $wpdb->get_results($sql); $updated = 0; foreach($posts as $post){ $object = get_post($post->id); if ( $object != false && $object != null ) { wbats_tag_posts($object->ID); $updated++; } } ?>

posts} WHERE post_status='publish' AND post_type='post' ORDER BY post_modified_gmt DESC;"; $posts = $wpdb->get_results($sql); $updated = 0; foreach($posts as $post){ $object = get_post($post->id); $posttags = get_the_tags($post->id); if ( $object != false && $object != null && !$posttags) { wbats_tag_posts($object->ID); $updated++; } } ?>

Re-Tagging Done.

', 'wbats'); } ?>

Web Ninja Auto Tagging System

Description: This plugin will automatically make tags with the tagthe.net and yahoo yql services when you save or update a post. Also has the option for re-tagging post.

Homepage: Web Ninja Auto Tagging System

Support: Web Ninja Forums

Developed by: Josh Fowler

Like the plugin? Then "Like" The Web Ninja!
Thanks: I wanted to say thanks for using my plugin and if you have any suggestions for new features head over to the Support Forum and just drop me a little note. You never know, it could be on the next version.


Option Settings

Check Yahoo: [?] /> # of tags:
Check tagthe.net: [?] /> # of tags:
Append Tags: [?] />
Remove Tags: [?]
Add Tags: [?]
API Timeout: [?]

Re-Tagging

*Warning: Depending on how many posts it has to do this could take a while. Also, this will only tag published posts.


'; else $out .= $json[$i]; } else $out .= $json[$i]; if ($json[$i] == '"') $comment = !$comment; } if (strlen($json) > 1) { eval($out . ';'); return $x; } else { return ''; } } function wbats_post_request($url, $referer, $_data) { $data = array(); while(list($n,$v) = each($_data)){ $data[] = "$n=$v"; } $data = implode('&', $data); $url = parse_url($url); if ($url['scheme'] != 'http') { die('Only HTTP request are supported !'); } $host = $url['host']; $path = $url['path']; if ($fp = @fsockopen($host, 80, $errno, $errstr, wbats_get_option('fsock_timeout'))){ fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while(!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); } $result = explode("\r\n\r\n", $result, 2); $content = isset($result[1]) ? $result[1] : ''; return $content; } function wbats_forbidden_tag($forbidden,$tag){ if (is_array($forbidden) && !empty($forbidden)){ foreach($forbidden as $forbid){ if ($forbid !='') if(strpos(strtolower($tag), strtolower($forbid))!==false) return true; } } return false; } function wbats_trim_tags(&$item,$q){ $item=trim($item); } function wbats_tag_yahoo($content,$num,$remove_tags){ $senddata=array('q'=>'select%20*%20from%20search.termextract%20where%20context%3D%22'.urlencode(utf8_decode(addslashes(strip_tags($content)))).'%22', 'format'=>'json', 'diagnostics'=>'false' ); $data = wbats_post_request('http://query.yahooapis.com/v1/public/yql', get_bloginfo('url'),$senddata); $ret=''; if($json=wbats_yql_ttn_json_decode($data)){ $i=0; if (is_array($json['query']['results']['Result']) && !empty($json['query']['results']['Result'])){ foreach($json['query']['results']['Result'] as $kw){ if ($i>=$num) break; if (!wbats_forbidden_tag($remove_tags,$kw)) { $ret.=$kw.', '; $i++; } } } } return substr($ret,0,-2); } function wbats_tag_the_net($content,$num,$remove_tags){ $senddata=array('text'=>urlencode(utf8_decode(strip_tags($content))), 'count'=>$num*3, 'view'=>'json' ); $data=wbats_post_request('http://tagthe.net/api/', get_bloginfo('url'), $senddata); $data=explode("\r\n",$data); $data=array_slice($data,1); $data=array_slice($data,0,-3); $data=implode("\r\n",$data); $ret=''; if($json=wbats_yql_ttn_json_decode($data)){ $i=0; if (is_array($json['memes'][0]['dimensions']['topic']) && !empty($json['memes'][0]['dimensions']['topic'])){ foreach($json['memes'][0]['dimensions']['topic'] as $topic){ if ($i>=$num) break; if (!wbats_forbidden_tag($remove_tags,$topic)){ $ret.=$topic.', '; $i++; } } } } return substr($ret,0,-2); } function wbats_tag_posts($postid){ global $wp_filter; $yahoo_num = wbats_get_option('yahoo_num'); $tagthenet_num = wbats_get_option('tagthenet_num'); $yahoo_enabled = wbats_get_option('enable_yahoo'); $tagthenet_enabled = wbats_get_option('enable_tagthenet'); $append = wbats_get_option('append'); $remove_tags = explode(',',strtolower(wbats_get_option('remove_tags'))); $add_tags = strtolower(wbats_get_option('add_tags')); array_walk($remove_tags,'wbats_trim_tags'); $post=get_post($postid, ARRAY_A); $content=$post['post_title']." ".$post['post_content']; if ($yahoo_enabled) { $yahoo_tags = wbats_tag_yahoo($content,$yahoo_num,$remove_tags); } if ($tagthenet_enabled) { $tagthenet_tags = wbats_tag_the_net($content,$tagthenet_num,$remove_tags); } $keywords = ''; if ($yahoo_enabled) { $keywords .= $yahoo_tags; } if ($yahoo_enabled && $tagthenet_enabled) { $keywords .= ', '; } if ($tagthenet_enabled) { $keywords .= $tagthenet_tags; } if (($yahoo_enabled || $tagthenet_enabled) && $add_tags != '') { $keywords .= ', '; } if ($add_tags != '') { $keywords .= $add_tags; } remove_action('wp_insert_post','wbats_tag_posts'); wp_set_post_tags( $postid,$keywords, $append ); } add_action('admin_menu', 'wbats_admin'); add_action('init', 'wbats_init'); add_action('wp_insert_post','wbats_tag_posts',1); add_action('shutdown', 'wbats_shutdown'); ?>