/wordpress/wp-content/themes/zenko/blogsubmitshow.php
PHP | 240 lines | 212 code | 7 blank | 21 comment | 21 complexity | 40f517cdea23afdec7005fdcc846dddd MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
- <?php
- require_once(ABSPATH . '/wp-load.php');
- require_once(ABSPATH . '/wp-config.php');
- require_once(ABSPATH . WPINC . '/functions.php');
- require_once(ABSPATH . WPINC . '/rss.php');
- require_once(ABSPATH . WPINC . '/feed.php');
- require_once(ABSPATH . WPINC . '/class-simplepie.php');
- require_once (ABSPATH . WPINC . '/class-feed.php');
- require_once(ABSPATH . '/wp-includes/class-snoopy.php');
- require_once (ABSPATH . WPINC . '/pluggable.php');
-
- //error_reporting(0);
-
- function wt_get_user_id(){
- global $userdata;
- get_currentuserinfo();
- return $userdata->ID;
- }
-
- function blogsubmit($url,$userid){
- global $wpdb;
- $feed = new SimplePie();
- $feed->set_feed_url($url);
- $feed->enable_order_by_date(false);
- $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache');
- $feed->init();
- $feed->handle_content_type();
- $items = $feed->get_items();
- $flag = -1;
- $rss = $feed->feed_url;
- $bloguserlink = $feed->get_link();
- /**$feedtitle= $feed->get_title();
- $link_id = $wpdb->get_var("select link_id from wp_links where link_rss ='".$wpdb->escape($rss)."'");
- if($link_id == NULL)
- $wpdb->query("
- Insert into wp_links
- SET
- link_url='".$wpdb->escape($url)."',
- link_name='".$wpdb->escape($feedtitle)."',
- link_image='',
- link_target='',
- link_description='".$wpdb->escape($feedtitle)."',
- link_visible='Y',
- link_owner='1',
- link_rating='0',
- link_updated='0000-00-00 00:00:00',
- link_rel='',
- link_notes='',
- link_rss='".$wpdb->escape($rss)."'
- ");
- */
- for ($i=0;$i<sizeof($items);$i++){
- $link = $items[$i]->get_permalink();
- if(strcmp($link,$url) == 0)
- $flag = $i;
- }
- if ($flag != -1)
- {$feedinfos = $items[$flag];}
- else
- {$feedinfos = $items[0];}
- $feedinfo = $feedinfos;
- $links = $feedinfo->get_permalink();
- $title = $feedinfo->get_title();
- $content = $feedinfo->get_content();
- $date_modified = $feedinfo->get_local_date($date_format='%Y-%m-%d %H:%M:%S');
- $date = getdate();
- $date = $date[0];
- $date = date('Y-m-d H:i:s',$date);
- $herfpattern = '/<a HREF="([\S]*)" TARGET="_blank">/i';
- $content = preg_replace($herfpattern," ",$content);
- $content = preg_replace('/TITLE=\"([^"]*)\"/i','TITLE=""',$content);
- $content = preg_replace('/ALT=\"([^"]*)\"/i',' ALT=""',$content);
- $content = preg_replace('/<span class=\'MASS(.*)\'>([^<])*<\/span>/','',$content);
- $body = $content;
- $img_array = array();
- preg_match_all('/<img([^>&^<])*(src|SRC)=\"([^"]*)\" ([^<&^>])*\/>/i',$body,$img_array);
- $img_array = array_unique($img_array[3]);
- set_time_limit(0);
- $img_dir ='wp-content/uploads';
- $base_dir = ABSPATH;
- $imgUrl = $img_dir."/".strftime("%Y/%m",time());
- $imgPath = $base_dir.$imgUrl;
- $milliSecond = strftime("%d%H%M%S",time());
- if(!is_dir($imgPath)) @mkdir($imgPath,0777);
- foreach($img_array as $key =>$value)
- {
- $value = trim($value);
- $get_file = @file_get_contents($value);
- if (!strcmp(substr($value,-3,3),'690')){
- $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
- $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
- }
- if (!strcmp(substr($value,-3,3),'jpg')){
- $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
- $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
- }
- if (!strcmp(substr($value,-3,3),'gif')){
- $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."gif";
- $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."gif";
- }
- if($get_file)
- {
- $fp = @fopen($rndFileName,"w");
- @fwrite($fp,$get_file);
- @fclose($fp);
- }
- $body = ereg_replace($value,$fileurl,$body);
- }
- $content = $body;
- $content = 'from:<a href="'.$bloguserlink.'">'.$bloguserlink.'</a><br>'.$content;
- $show['url'] = $links;
- $show['title'] = $title;
- $show['content'] = $content;
- $show['date'] = $date;
- $show['userid'] = $userid;
- $show['date_modified'] = $date_modified;
- return $show;
- }
-
- function sinablogsubmitblog($url,$userid){
- global $wpdb;
- $snoopy = new Snoopy;
- $snoopy->fetch($url);
- $html = $snoopy->results;
- preg_match_all("/<div id=\"bloglink\" class=\"bloglink\"><a href=\"(.)*\">([^<^>]*)<\/a>/i",$html,$bloguserlink);
- $bloguserlink = $bloguserlink[2][0];
- preg_match_all("/<h2 id=\"(.*)\" class=\"titName SG_txta\">(.*)<\/h2>/i",$html,$title);
- $title = $title[2][0];
- preg_match_all("/<span class=\"time SG_txtc\">\((.*)\)<\/span>/i",$html,$date_modified);
- $date_modified = $date_modified[1][0];
- $date = getdate();
- $date = $date[0];
- $date = date('Y-m-d H:i:s',$date);
- preg_match_all("/<!-- ???? -->([\s\S]*)<!-- ???? -->/i",$html,$contentContainer);
- $content = $contentContainer[1][0];
- $content = preg_replace("/<div id=\"sina_keyword_ad_area2\" class=\"articalContent \">/","",$content
- );
- $content = preg_replace("/<\/div>/","",$content);
- $pattern = '/src=\".*\" real_src /';
- $content = preg_replace($pattern,"SRC",$content);
- $herfpattern = '/<a HREF="([\S]*)" TARGET="_blank">/i';
- $content = preg_replace($herfpattern," ",$content);
- $content = preg_replace('/TITLE=\"([^"]*)\"/i','TITLE=""',$content);
- $content = preg_replace('/ALT=\"([^"]*)\"/i',' ALT=""',$content);
- $content = preg_replace('/<span class=\'MASS(.*)\'>([^<])*<\/span>/','',$content);
- $body = $content;
- $img_array = array();
- preg_match_all('/<img([^>&^<])*(src|SRC)=\"([^"]*)\" ([^<&^>])*\/>/i',$body,$img_array);
- $img_array = array_unique($img_array[3]);
- set_time_limit(0);
- $img_dir ='wp-content/uploads';
- $base_dir = ABSPATH;
- $imgUrl = $img_dir."/".strftime("%Y/%m",time());
- $imgPath = $base_dir.$imgUrl;
- $milliSecond = strftime("%d%H%M%S",time());
- if(!is_dir($imgPath)) @mkdir($imgPath,0777);
- foreach($img_array as $key =>$value)
- {
- $value = trim($value);
- $get_file = @file_get_contents($value);
- if (!strcmp(substr($value,-3,3),'690')){
- $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
- $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
- }
- if (!strcmp(substr($value,-3,3),'jpg')){
- $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
- $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
- }
- if (!strcmp(substr($value,-3,3),'gif')){
- $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."gif";
- $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."gif";
- }
- if($get_file)
- {
- $fp = @fopen($rndFileName,"w");
- @fwrite($fp,$get_file);
- @fclose($fp);
- }
- $body = ereg_replace($value,$fileurl,$body);
- }
- $content = $body;
- $content = 'from:<a href="'.$bloguserlink.'">'.$bloguserlink.'</a><br>'.$content;
- $show['url'] = $url;
- $show['title'] = $title;
- $show['content'] = $content;
- $show['date'] = $date;
- $show['userid'] = $userid;
- $show['date_modified'] = $date_modified;
- return $show;
- }
-
- function sinablogsubmitindex($url,$userid){
- $snoopy = new Snoopy;
- $snoopy->fetch($url);
- $html = $snoopy->results;
- preg_match_all("/<!--???start-->([\s\S]*)<!--???end-->/i",$html,$page);
- preg_match_all("/<div id=\"(.*)\" class=\"blog_title\">(\s)*<a href=\"(.*)\" target=\"_blank\">/i",$page[1][0],$link);
- $urls = $link[3];
- $url = $urls[0];
- $show = sinablogsubmitblog($url,$userid);
- return $show;
- }
-
- function sinablogsubmitarticlelist($url,$userid){
- $snoopy = new Snoopy;
- $snoopy->fetch($url);
- $html = $snoopy->results;
- preg_match_all("/<!-- ?? START -->([\s\S]*)<!-- ??END -->/i",$html,$page);
- preg_match_all("/<a title=\"(.*)\" target=\"_blank\" href=\"(.*)\">/i",$page[1][0],$link);
- $urls = $link[2];
- $url = $urls[0];
- $show = sinablogsubmitblog($url,$userid);
- return $show;
- }
-
- function explodeurlshow($blogurl,$loginuserid){
- $url_s = explode("/",$blogurl);
- if (!strcmp($url_s[2],"blog.sina.com.cn")){
- if (!strcmp($url_s[3],"s")){
- $url_art = explode("_",$url_s[4]);
- if(!strcmp($url_art[0],"articlelist")){
- $show = sinablogsubmitarticlelist($blogurl,$loginuserid);
- }
- else
- {
- $show = sinablogsubmitblog($blogurl,$loginuserid);
- }
- }
- else
- {
- $show = sinablogsubmitindex($blogurl,$loginuserid);
- }
- }
- else
- {
- $show = blogsubmit($blogurl,$loginuserid);
- }
- return $show;
- }
- ?>