/wordpress/wp-content/themes/zenko/page-insertintodb.php
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
- <?php
- global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
- $dateformat = get_option('date_format');
- $timeformat = get_option('time_format');
- get_header();
- require_once(ABSPATH . '/wp-load.php');
- require_once(ABSPATH . '/wp-config.php');
- require_once(ABSPATH . WPINC . '/functions.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 insert_into_wpdb($url,$loginuserid,$date,$content,$title,$date_modified){
- global $wpdb;
- $post_id = $wpdb->get_var("select post_id from tb_post_import where blog_url ='".$wpdb->escape($url)."'");
- if ($post_id == NULL){
- $result = FALSE;
- $sql = "begin transaction";
- mysql_query($sql);
- $sql = $wpdb->query("
- Insert into wp_posts
- SET
- post_author='".$wpdb->escape($loginuserid)."',
- post_date='".$wpdb->escape($date)."',
- post_date_gmt='".$wpdb->escape($date)."',
- post_content='".$wpdb->escape($content)."',
- post_title='".$wpdb->escape($title)."',
- post_excerpt='',
- post_status='draft',
- comment_status='open',
- ping_status='open',
- post_password='',
- post_name='".$wpdb->escape($title)."',
- to_ping='',
- pinged='',
- post_modified='".$wpdb->escape($date_modified)."',
- post_modified_gmt='".$wpdb->escape($date_modified)."',
- post_content_filtered=0,
- post_parent=0,
- guid='',
- menu_order=0,
- post_type='post',
- post_mime_type='',
- comment_count=0
- ");
- if ($sql){
- $rows =mysql_affected_rows();
- if ($rows == 1){
- $id = mysql_insert_id();
- $sql = $wpdb->query("
- Insert into tb_post_import
- SET
- post_ID='".$wpdb->escape($id)."',
- author_ID='".$wpdb->escape($loginuserid)."',
- blog_url='".$wpdb->escape($url)."'
- ");
- if ($sql){
- $sql = "commit";
- mysql_query($sql);
- $result = TRUE;
-
- $motto= "???????????????????";
- }
- }
- }
-
- if (!$result){
- $sql ="rollback";
- mysql_query($sql);
-
- $motto= "??????????";
- }
- }
- else {
- $motto= "?????????????";
- }
- header("Content-type: text/html; charset=utf-8");
- ?>
- <div class="main_seachC"><?php echo $motto;?></div>
- <?php
- }
-
- 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;
- $bloguserlink = $feed->get_link();
- 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;
- foreach ($feedinfos as $feedinfo):
- $links = $feedinfo->get_permalink();
- set_magic_quotes_runtime(1);
- $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;
- set_magic_quotes_runtime(1);
- $content = $content;
- $title = $title;
- insert_into_wpdb($links,$userid,$date,$content,$title,$date_modified);
- set_magic_quotes_runtime(0);
- endforeach;
- }
-
- 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;
- set_magic_quotes_runtime(1);
- $content = $content;
- $title = $title;
- insert_into_wpdb($url,$userid,$date,$content,$title,$date_modified);
- set_magic_quotes_runtime(0);
- }
-
- 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];
- foreach($urls as $url):
- sinablogsubmitblog($url,$userid);
- endforeach;
- }
-
- 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];
- foreach($urls as $url):
- sinablogsubmitblog($url,$userid);
- endforeach;
- }
-
- function explodeurlandinsert($blogurl,$userid){
- $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"))
- sinablogsubmitarticlelist($blogurl,$userid);
- else
- sinablogsubmitblog($blogurl,$userid);
- }
- else
- sinablogsubmitindex($blogurl,$userid);
- }
- else
- blogsubmit($blogurl,$userid);
- }
- ?>
- <link rel="stylesheet" type="text/css" href="/wp-content/themes/zenko/external.css" />
- <div id="Container">
- <div class="db_blog">
- <div class="s_t_a">
- <h3 class="db_blogT">??????????</h3>
- <a href="http://www.stylepress.cn/wp-admin/edit.php">??????</a>
- </div>
- <div id="return_status">
- <?php
- $loginuserid = wt_get_user_id();
-
- $blogurl = $_REQUEST['blog_url'];
- $blogindexurl = $_REQUEST['blogindexurl'];
- $ttl = $_REQUEST['ttl'];
- $time = time();
- $updated = date('Y-m-d H:i:s',$time);
- if ($blogindexurl == NULL)
- {
- explodeurlandinsert($blogurl,$loginuserid);
- }
- else
- {
- explodeurlandinsert($blogindexurl,$loginuserid);
- $link_id = $wpdb->get_var("select link_id from wp_links where link_url ='".$wpdb->escape($blogindexurl)."'");
- $name = $wpdb->get_var("select user_login from wp_users where ID ='".$wpdb->escape($loginuserid)."'");
- if($link_id == NULL)
- $wpdb->query("
- Insert into wp_links
- SET
- link_url='".$wpdb->escape($blogindexurl)."',
- link_name='".$wpdb->escape($name)."',
- link_image='',
- link_target='',
- link_description='".$wpdb->escape($feedtitle)."',
- link_visible='Y',
- link_owner='".$wpdb->escape($loginuserid)."',
- link_rating='0',
- link_updated='".$wpdb->escape($updated)."',
- link_rel='',
- link_notes='".$wpdb->escape($ttl)."',
- link_rss='".$wpdb->escape($blogindexurl)."'
- ");
- }
- ?>
- </div>
- </div>
- </div>
- <?php
- get_footer();
- ?>