PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://ownerpress.googlecode.com/
PHP | 300 lines | 269 code | 11 blank | 20 comment | 29 complexity | fabf47615ecdf9e4306b87ea1fa4904a 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 insert_into_wpdb($url,$loginuserid,$date,$content,$title,$date_modified){
  13. global $wpdb;
  14. $post_id = $wpdb->get_var("select post_id from post_import where blog_url ='".$wpdb->escape($url)."'");
  15. if ($post_id == NULL){
  16. $result = FALSE;
  17. $sql = "begin transaction";
  18. mysql_query($sql);
  19. $sql = $wpdb->query("
  20. Insert into wp_posts
  21. SET
  22. post_author='".$wpdb->escape($loginuserid)."',
  23. post_date='".$wpdb->escape($date)."',
  24. post_date_gmt='".$wpdb->escape($date)."',
  25. post_content='".$wpdb->escape($content)."',
  26. post_title='".$wpdb->escape($title)."',
  27. post_excerpt='',
  28. post_status='draft',
  29. comment_status='open',
  30. ping_status='open',
  31. post_password='',
  32. post_name='".$wpdb->escape($title)."',
  33. to_ping='',
  34. pinged='',
  35. post_modified='".$wpdb->escape($date_modified)."',
  36. post_modified_gmt='".$wpdb->escape($date_modified)."',
  37. post_content_filtered=0,
  38. post_parent=0,
  39. guid='',
  40. menu_order=0,
  41. post_type='post',
  42. post_mime_type='',
  43. comment_count=0
  44. ");
  45. if ($sql){
  46. $rows =mysql_affected_rows();
  47. if ($rows == 1){
  48. $id = mysql_insert_id();
  49. $sql = $wpdb->query("
  50. Insert into post_import
  51. SET
  52. post_ID='".$wpdb->escape($id)."',
  53. author_ID='".$wpdb->escape($loginuserid)."',
  54. blog_url='".$wpdb->escape($url)."'
  55. ");
  56. if ($sql){
  57. $sql = "commit";
  58. mysql_query($sql);
  59. $result = TRUE;
  60. $motto= "???????????????????";
  61. }
  62. }
  63. }
  64. if (!$result){
  65. $sql ="rollback";
  66. mysql_query($sql);
  67. $motto= "??????????";
  68. }
  69. }
  70. else {
  71. $motto= "?????????????";
  72. }
  73. header("Content-type: text/html; charset=utf-8");
  74. ?>
  75. <div class="main_seachC"><?php echo $motto;?></div>
  76. <?php
  77. }
  78. function wt_get_user_id(){
  79. global $userdata;
  80. get_currentuserinfo();
  81. return $userdata->ID;
  82. }
  83. function blogsubmit($url,$userid){
  84. global $wpdb;
  85. $feed = new SimplePie();
  86. $feed->set_feed_url($url);
  87. $feed->enable_order_by_date(false);
  88. $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache');
  89. $feed->init();
  90. $feed->handle_content_type();
  91. $items = $feed->get_items();
  92. $flag = -1;
  93. $rss = $feed->feed_url;
  94. $bloguserlink = $feed->get_link();
  95. /**$feedtitle= $feed->get_title();
  96. $link_id = $wpdb->get_var("select link_id from wp_links where link_rss ='".$wpdb->escape($rss)."'");
  97. if($link_id == NULL)
  98. $wpdb->query("
  99. Insert into wp_links
  100. SET
  101. link_url='".$wpdb->escape($url)."',
  102. link_name='".$wpdb->escape($feedtitle)."',
  103. link_image='',
  104. link_target='',
  105. link_description='".$wpdb->escape($feedtitle)."',
  106. link_visible='Y',
  107. link_owner='1',
  108. link_rating='0',
  109. link_updated='0000-00-00 00:00:00',
  110. link_rel='',
  111. link_notes='',
  112. link_rss='".$wpdb->escape($rss)."'
  113. ");
  114. */
  115. for ($i=0;$i<sizeof($items);$i++){
  116. $link = $items[$i]->get_permalink();
  117. if(strcmp($link,$url) == 0)
  118. $flag = $i;
  119. }
  120. if ($flag != -1)
  121. $feedinfos = $items[$flag];
  122. else
  123. $feedinfos = $items;
  124. foreach ($feedinfos as $feedinfo):
  125. $links = $feedinfo->get_permalink();
  126. set_magic_quotes_runtime(1);
  127. $title = $feedinfo->get_title();
  128. $content = $feedinfo->get_content();
  129. $date_modified = $feedinfo->get_local_date($date_format='%Y-%m-%d %H:%M:%S');
  130. $date = getdate();
  131. $date = $date[0];
  132. $date = date('Y-m-d H:i:s',$date);
  133. $herfpattern = '/<a HREF="([\S]*)" TARGET="_blank">/i';
  134. $content = preg_replace($herfpattern," ",$content);
  135. $content = preg_replace('/TITLE=\"([^"]*)\"/i','TITLE=""',$content);
  136. $content = preg_replace('/ALT=\"([^"]*)\"/i',' ALT=""',$content);
  137. $content = preg_replace('/<span class=\'MASS(.*)\'>([^<])*<\/span>/','',$content);
  138. $body = $content;
  139. $img_array = array();
  140. preg_match_all('/<img([^>&^<])*(src|SRC)=\"([^"]*)\" ([^<&^>])*\/>/i',$body,$img_array);
  141. $img_array = array_unique($img_array[3]);
  142. set_time_limit(0);
  143. $img_dir ='wp-content/uploads';
  144. $base_dir = ABSPATH;
  145. $imgUrl = $img_dir."/".strftime("%Y/%m",time());
  146. $imgPath = $base_dir.$imgUrl;
  147. $milliSecond = strftime("%d%H%M%S",time());
  148. if(!is_dir($imgPath)) @mkdir($imgPath,0777);
  149. foreach($img_array as $key =>$value)
  150. {
  151. $value = trim($value);
  152. $get_file = @file_get_contents($value);
  153. if (!strcmp(substr($value,-3,3),'690')){
  154. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  155. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  156. }
  157. if (!strcmp(substr($value,-3,3),'jpg')){
  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),'gif')){
  162. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."gif";
  163. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."gif";
  164. }
  165. if($get_file)
  166. {
  167. $fp = @fopen($rndFileName,"w");
  168. @fwrite($fp,$get_file);
  169. @fclose($fp);
  170. }
  171. $body = ereg_replace($value,$fileurl,$body);
  172. }
  173. $content = $body;
  174. $content = 'from:<a href="'.$bloguserlink.'">'.$bloguserlink.'</a><br>'.$content;
  175. set_magic_quotes_runtime(1);
  176. $content = $content;
  177. $title = $title;
  178. insert_into_wpdb($links,$userid,$date,$content,$title,$date_modified);
  179. set_magic_quotes_runtime(0);
  180. endforeach;
  181. }
  182. function sinablogsubmitblog($url,$userid){
  183. global $wpdb;
  184. $snoopy = new Snoopy;
  185. $snoopy->fetch($url);
  186. $html = $snoopy->results;
  187. preg_match_all("/<div id=\"bloglink\" class=\"bloglink\"><a href=\"(.)*\">([^<^>]*)<\/a>/i",$html,$bloguserlink);
  188. $bloguserlink = $bloguserlink[2][0];
  189. preg_match_all("/<h2 id=\"(.*)\" class=\"titName SG_txta\">(.*)<\/h2>/i",$html,$title);
  190. $title = $title[2][0];
  191. preg_match_all("/<span class=\"time SG_txtc\">\((.*)\)<\/span>/i",$html,$date_modified);
  192. $date_modified = $date_modified[1][0];
  193. $date = getdate();
  194. $date = $date[0];
  195. $date = date('Y-m-d H:i:s',$date);
  196. preg_match_all("/<!-- ???? -->([\s\S]*)<!-- ???? -->/i",$html,$contentContainer);
  197. $content = $contentContainer[1][0];
  198. $content = preg_replace("/<div id=\"sina_keyword_ad_area2\" class=\"articalContent \">/","",$content
  199. );
  200. $content = preg_replace("/<\/div>/","",$content);
  201. $pattern = '/src=\".*\" real_src /';
  202. $content = preg_replace($pattern,"SRC",$content);
  203. $herfpattern = '/<a HREF="([\S]*)" TARGET="_blank">/i';
  204. $content = preg_replace($herfpattern," ",$content);
  205. $content = preg_replace('/TITLE=\"([^"]*)\"/i','TITLE=""',$content);
  206. $content = preg_replace('/ALT=\"([^"]*)\"/i',' ALT=""',$content);
  207. $content = preg_replace('/<span class=\'MASS(.*)\'>([^<])*<\/span>/','',$content);
  208. $body = $content;
  209. $img_array = array();
  210. preg_match_all('/<img([^>&^<])*(src|SRC)=\"([^"]*)\" ([^<&^>])*\/>/i',$body,$img_array);
  211. $img_array = array_unique($img_array[3]);
  212. set_time_limit(0);
  213. $img_dir ='wp-content/uploads';
  214. $base_dir = ABSPATH;
  215. $imgUrl = $img_dir."/".strftime("%Y/%m",time());
  216. $imgPath = $base_dir.$imgUrl;
  217. $milliSecond = strftime("%d%H%M%S",time());
  218. if(!is_dir($imgPath)) @mkdir($imgPath,0777);
  219. foreach($img_array as $key =>$value)
  220. {
  221. $value = trim($value);
  222. $get_file = @file_get_contents($value);
  223. if (!strcmp(substr($value,-3,3),'690')){
  224. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  225. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  226. }
  227. if (!strcmp(substr($value,-3,3),'jpg')){
  228. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."jpg";
  229. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."jpg";
  230. }
  231. if (!strcmp(substr($value,-3,3),'gif')){
  232. $rndFileName = $imgPath."/".$userid.'-'.$milliSecond.$key."."."gif";
  233. $fileurl = "http://www.stylepress.cn/".$imgUrl."/".$userid.'-'.$milliSecond.$key."."."gif";
  234. }
  235. if($get_file)
  236. {
  237. $fp = @fopen($rndFileName,"w");
  238. @fwrite($fp,$get_file);
  239. @fclose($fp);
  240. }
  241. $body = ereg_replace($value,$fileurl,$body);
  242. }
  243. $content = $body;
  244. $content = 'from:<a href="'.$bloguserlink.'">'.$bloguserlink.'</a><br>'.$content;
  245. set_magic_quotes_runtime(1);
  246. $content = $content;
  247. $title = $title;
  248. insert_into_wpdb($url,$userid,$date,$content,$title,$date_modified);
  249. set_magic_quotes_runtime(0);
  250. }
  251. function sinablogsubmitindex($url,$userid){
  252. $snoopy = new Snoopy;
  253. $snoopy->fetch($url);
  254. $html = $snoopy->results;
  255. preg_match_all("/<!--???start-->([\s\S]*)<!--???end-->/i",$html,$page);
  256. preg_match_all("/<div id=\"(.*)\" class=\"blog_title\">(\s)*<a href=\"(.*)\" target=\"_blank\">/i",$page[1][0],$link);
  257. $urls = $link[3];
  258. foreach($urls as $url):
  259. sinablogsubmitblog($url,$userid);
  260. endforeach;
  261. }
  262. function sinablogsubmitarticlelist($url,$userid){
  263. $snoopy = new Snoopy;
  264. $snoopy->fetch($url);
  265. $html = $snoopy->results;
  266. preg_match_all("/<!-- ?? START -->([\s\S]*)<!-- ??END -->/i",$html,$page);
  267. preg_match_all("/<a title=\"(.*)\" target=\"_blank\" href=\"(.*)\">/i",$page[1][0],$link);
  268. $urls = $link[2];
  269. foreach($urls as $url):
  270. sinablogsubmitblog($url,$userid);
  271. endforeach;
  272. }
  273. function explodeurlandinsert($blogurl,$userid){
  274. $url_s = explode("/",$blogurl);
  275. if (!strcmp($url_s[2],"blog.sina.com.cn")){
  276. if (!strcmp($url_s[3],"s")){
  277. $url_art = explode("_",$url_s[4]);
  278. if(!strcmp($url_art[0],"articlelist"))
  279. sinablogsubmitarticlelist($blogurl,$userid);
  280. else
  281. sinablogsubmitblog($blogurl,$userid);
  282. }
  283. else
  284. sinablogsubmitindex($blogurl,$userid);
  285. }
  286. else
  287. blogsubmit($blogurl,$userid);
  288. }
  289. ?>