PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/themes/zenko/blogsubmitshow.php

http://ownerpress.googlecode.com/
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
  1. <?php
  2. require_once(ABSPATH . '/wp-load.php');
  3. require_once(ABSPATH . '/wp-config.php');
  4. require_once(ABSPATH . WPINC . '/functions.php');
  5. require_once(ABSPATH . WPINC . '/rss.php');
  6. require_once(ABSPATH . WPINC . '/feed.php');
  7. require_once(ABSPATH . WPINC . '/class-simplepie.php');
  8. require_once (ABSPATH . WPINC . '/class-feed.php');
  9. require_once(ABSPATH . '/wp-includes/class-snoopy.php');
  10. require_once (ABSPATH . WPINC . '/pluggable.php');
  11. //error_reporting(0);
  12. function wt_get_user_id(){
  13. global $userdata;
  14. get_currentuserinfo();
  15. return $userdata->ID;
  16. }
  17. function blogsubmit($url,$userid){
  18. global $wpdb;
  19. $feed = new SimplePie();
  20. $feed->set_feed_url($url);
  21. $feed->enable_order_by_date(false);
  22. $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache');
  23. $feed->init();
  24. $feed->handle_content_type();
  25. $items = $feed->get_items();
  26. $flag = -1;
  27. $rss = $feed->feed_url;
  28. $bloguserlink = $feed->get_link();
  29. /**$feedtitle= $feed->get_title();
  30. $link_id = $wpdb->get_var("select link_id from wp_links where link_rss ='".$wpdb->escape($rss)."'");
  31. if($link_id == NULL)
  32. $wpdb->query("
  33. Insert into wp_links
  34. SET
  35. link_url='".$wpdb->escape($url)."',
  36. link_name='".$wpdb->escape($feedtitle)."',
  37. link_image='',
  38. link_target='',
  39. link_description='".$wpdb->escape($feedtitle)."',
  40. link_visible='Y',
  41. link_owner='1',
  42. link_rating='0',
  43. link_updated='0000-00-00 00:00:00',
  44. link_rel='',
  45. link_notes='',
  46. link_rss='".$wpdb->escape($rss)."'
  47. ");
  48. */
  49. for ($i=0;$i<sizeof($items);$i++){
  50. $link = $items[$i]->get_permalink();
  51. if(strcmp($link,$url) == 0)
  52. $flag = $i;
  53. }
  54. if ($flag != -1)
  55. {$feedinfos = $items[$flag];}
  56. else
  57. {$feedinfos = $items[0];}
  58. $feedinfo = $feedinfos;
  59. $links = $feedinfo->get_permalink();
  60. $title = $feedinfo->get_title();
  61. $content = $feedinfo->get_content();
  62. $date_modified = $feedinfo->get_local_date($date_format='%Y-%m-%d %H:%M:%S');
  63. $date = getdate();
  64. $date = $date[0];
  65. $date = date('Y-m-d H:i:s',$date);
  66. $herfpattern = '/<a HREF="([\S]*)" TARGET="_blank">/i';
  67. $content = preg_replace($herfpattern," ",$content);
  68. $content = preg_replace('/TITLE=\"([^"]*)\"/i','TITLE=""',$content);
  69. $content = preg_replace('/ALT=\"([^"]*)\"/i',' ALT=""',$content);
  70. $content = preg_replace('/<span class=\'MASS(.*)\'>([^<])*<\/span>/','',$content);
  71. $body = $content;
  72. $img_array = array();
  73. preg_match_all('/<img([^>&^<])*(src|SRC)=\"([^"]*)\" ([^<&^>])*\/>/i',$body,$img_array);
  74. $img_array = array_unique($img_array[3]);
  75. set_time_limit(0);
  76. $img_dir ='wp-content/uploads';
  77. $base_dir = ABSPATH;
  78. $imgUrl = $img_dir."/".strftime("%Y/%m",time());
  79. $imgPath = $base_dir.$imgUrl;
  80. $milliSecond = strftime("%d%H%M%S",time());
  81. if(!is_dir($imgPath)) @mkdir($imgPath,0777);
  82. foreach($img_array as $key =>$value)
  83. {
  84. $value = trim($value);
  85. $get_file = @file_get_contents($value);
  86. if (!strcmp(substr($value,-3,3),'690')){
  87. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  88. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  89. }
  90. if (!strcmp(substr($value,-3,3),'jpg')){
  91. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  92. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  93. }
  94. if (!strcmp(substr($value,-3,3),'gif')){
  95. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."gif";
  96. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."gif";
  97. }
  98. if($get_file)
  99. {
  100. $fp = @fopen($rndFileName,"w");
  101. @fwrite($fp,$get_file);
  102. @fclose($fp);
  103. }
  104. $body = ereg_replace($value,$fileurl,$body);
  105. }
  106. $content = $body;
  107. $content = 'from:<a href="'.$bloguserlink.'">'.$bloguserlink.'</a><br>'.$content;
  108. $show['url'] = $links;
  109. $show['title'] = $title;
  110. $show['content'] = $content;
  111. $show['date'] = $date;
  112. $show['userid'] = $userid;
  113. $show['date_modified'] = $date_modified;
  114. return $show;
  115. }
  116. function sinablogsubmitblog($url,$userid){
  117. global $wpdb;
  118. $snoopy = new Snoopy;
  119. $snoopy->fetch($url);
  120. $html = $snoopy->results;
  121. preg_match_all("/<div id=\"bloglink\" class=\"bloglink\"><a href=\"(.)*\">([^<^>]*)<\/a>/i",$html,$bloguserlink);
  122. $bloguserlink = $bloguserlink[2][0];
  123. preg_match_all("/<h2 id=\"(.*)\" class=\"titName SG_txta\">(.*)<\/h2>/i",$html,$title);
  124. $title = $title[2][0];
  125. preg_match_all("/<span class=\"time SG_txtc\">\((.*)\)<\/span>/i",$html,$date_modified);
  126. $date_modified = $date_modified[1][0];
  127. $date = getdate();
  128. $date = $date[0];
  129. $date = date('Y-m-d H:i:s',$date);
  130. preg_match_all("/<!-- ???? -->([\s\S]*)<!-- ???? -->/i",$html,$contentContainer);
  131. $content = $contentContainer[1][0];
  132. $content = preg_replace("/<div id=\"sina_keyword_ad_area2\" class=\"articalContent \">/","",$content
  133. );
  134. $content = preg_replace("/<\/div>/","",$content);
  135. $pattern = '/src=\".*\" real_src /';
  136. $content = preg_replace($pattern,"SRC",$content);
  137. $herfpattern = '/<a HREF="([\S]*)" TARGET="_blank">/i';
  138. $content = preg_replace($herfpattern," ",$content);
  139. $content = preg_replace('/TITLE=\"([^"]*)\"/i','TITLE=""',$content);
  140. $content = preg_replace('/ALT=\"([^"]*)\"/i',' ALT=""',$content);
  141. $content = preg_replace('/<span class=\'MASS(.*)\'>([^<])*<\/span>/','',$content);
  142. $body = $content;
  143. $img_array = array();
  144. preg_match_all('/<img([^>&^<])*(src|SRC)=\"([^"]*)\" ([^<&^>])*\/>/i',$body,$img_array);
  145. $img_array = array_unique($img_array[3]);
  146. set_time_limit(0);
  147. $img_dir ='wp-content/uploads';
  148. $base_dir = ABSPATH;
  149. $imgUrl = $img_dir."/".strftime("%Y/%m",time());
  150. $imgPath = $base_dir.$imgUrl;
  151. $milliSecond = strftime("%d%H%M%S",time());
  152. if(!is_dir($imgPath)) @mkdir($imgPath,0777);
  153. foreach($img_array as $key =>$value)
  154. {
  155. $value = trim($value);
  156. $get_file = @file_get_contents($value);
  157. if (!strcmp(substr($value,-3,3),'690')){
  158. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  159. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  160. }
  161. if (!strcmp(substr($value,-3,3),'jpg')){
  162. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  163. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  164. }
  165. if (!strcmp(substr($value,-3,3),'gif')){
  166. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."gif";
  167. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."gif";
  168. }
  169. if($get_file)
  170. {
  171. $fp = @fopen($rndFileName,"w");
  172. @fwrite($fp,$get_file);
  173. @fclose($fp);
  174. }
  175. $body = ereg_replace($value,$fileurl,$body);
  176. }
  177. $content = $body;
  178. $content = 'from:<a href="'.$bloguserlink.'">'.$bloguserlink.'</a><br>'.$content;
  179. $show['url'] = $url;
  180. $show['title'] = $title;
  181. $show['content'] = $content;
  182. $show['date'] = $date;
  183. $show['userid'] = $userid;
  184. $show['date_modified'] = $date_modified;
  185. return $show;
  186. }
  187. function sinablogsubmitindex($url,$userid){
  188. $snoopy = new Snoopy;
  189. $snoopy->fetch($url);
  190. $html = $snoopy->results;
  191. preg_match_all("/<!--???start-->([\s\S]*)<!--???end-->/i",$html,$page);
  192. preg_match_all("/<div id=\"(.*)\" class=\"blog_title\">(\s)*<a href=\"(.*)\" target=\"_blank\">/i",$page[1][0],$link);
  193. $urls = $link[3];
  194. $url = $urls[0];
  195. $show = sinablogsubmitblog($url,$userid);
  196. return $show;
  197. }
  198. function sinablogsubmitarticlelist($url,$userid){
  199. $snoopy = new Snoopy;
  200. $snoopy->fetch($url);
  201. $html = $snoopy->results;
  202. preg_match_all("/<!-- ?? START -->([\s\S]*)<!-- ??END -->/i",$html,$page);
  203. preg_match_all("/<a title=\"(.*)\" target=\"_blank\" href=\"(.*)\">/i",$page[1][0],$link);
  204. $urls = $link[2];
  205. $url = $urls[0];
  206. $show = sinablogsubmitblog($url,$userid);
  207. return $show;
  208. }
  209. function explodeurlshow($blogurl,$loginuserid){
  210. $url_s = explode("/",$blogurl);
  211. if (!strcmp($url_s[2],"blog.sina.com.cn")){
  212. if (!strcmp($url_s[3],"s")){
  213. $url_art = explode("_",$url_s[4]);
  214. if(!strcmp($url_art[0],"articlelist")){
  215. $show = sinablogsubmitarticlelist($blogurl,$loginuserid);
  216. }
  217. else
  218. {
  219. $show = sinablogsubmitblog($blogurl,$loginuserid);
  220. }
  221. }
  222. else
  223. {
  224. $show = sinablogsubmitindex($blogurl,$loginuserid);
  225. }
  226. }
  227. else
  228. {
  229. $show = blogsubmit($blogurl,$loginuserid);
  230. }
  231. return $show;
  232. }
  233. ?>