PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/themes/zenko/page-insertintodb.php

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