Advertisement
jaideejung007

cron_rsspost.php

Aug 27th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.00 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  *      [RSS POST] By MooPing
  5. */
  6.  
  7. if(!defined('IN_DISCUZ')) {
  8.     exit('Access Denied');
  9. }
  10.  
  11. include("rsspost_config.inc.php");
  12.  
  13. $rss_post_dir = DISCUZ_ROOT . './data/rss_post';
  14. if(!is_dir($rss_post_dir)) mkdir($rss_post_dir,0777);
  15. if(!is_dir($rss_post_dir.'/mark')) mkdir($rss_post_dir.'/mark',0777);
  16. //if(!is_dir($rss_post_dir.'/images')) mkdir($rss_post_dir.'/images',0777);
  17.  
  18. $credit_links = file_get_contents('http://wiki.moohin.com/rsspost_credit.txt');
  19.  
  20. if(!$credit_links){
  21. $credit_links="\n[b]ขอบคุณ Plugin ดีๆจาก[/b] [url=http://www.moohin.com/community/forum.php]MooHin Community - ชุมชนออนไลน์ของคนชอบเที่ยว[/url]\n";
  22. $credit_links.="[b]สถานที่ท่องเที่ยวแนะนำ[/b] - [url=http://wiki.moohin.com/wiki/ปางอุ๋ง]ปางอุ๋ง[/url], [url=http://wiki.moohin.com/wiki/เกาะล้าน]เกาะล้าน[/url], [url=http://wiki.moohin.com/wiki/เกาะสีชัง]เกาะสีชัง[/url]";
  23. }
  24. if (!isset($rsspost['data'])) {
  25. return;
  26. }
  27.  
  28.  
  29.  
  30. foreach ($rsspost['data'] as $dd) {
  31.     $count=0;
  32.     if (isset($dd['rss'])&&isset($dd['fid'])) {
  33.     $dom = new DOMDocument();
  34.         if ($dom->load($dd['rss'])) {
  35.             $datas = $dom->getElementsByTagName("item");
  36.             foreach($datas as $data) {
  37.                 $attach_img=array();
  38.                 if (isset($dd['limit'])&&$count>=$dd['limit']) {break;}
  39.                 $title =  trim($data->getElementsByTagName("title")->item(0)->nodeValue);
  40.                 $link =  trim($data->getElementsByTagName("link")->item(0)->nodeValue);
  41.                 if (isset($dd['keywords'])&&count($dd['keywords'])>0) {
  42.                     $skip=1;
  43.                     foreach ($dd['keywords'] as $k) {
  44.                     if (preg_match("/{$k}/i",$title)) {
  45.                         $skip=0;
  46.                     }
  47.                     }
  48.                     if ($skip==1) {continue;}
  49.                 }
  50.                 if (!isset($dd['content_var'])||$dd['content_var']=='') {$dd['content_var']='description';}
  51.                 if (preg_match("/^(.+):(.+)$/",$dd['content_var'],$match)) {
  52.                 $description =  trim($data->getElementsByTagNameNS('*',$match[2])->item(0)->nodeValue);            
  53.                 if ($description=='') {return;}
  54.                 } else {
  55.                 $description =  trim($data->getElementsByTagName($dd['content_var'])->item(0)->nodeValue);
  56.                 }
  57.                 if (isset($dd['convert_bbcode'])&&$dd['convert_bbcode']=='1') {            
  58.                 $description = BBCODE($description);               
  59.                 // cache image
  60.                 $arr=preg_match_all("|(\[img\]([^>]+)\[\/img\])|U",$description,$match,PREG_SET_ORDER);
  61.                 if (count($match)>0)  {
  62.                     $markfile=DISCUZ_ROOT . './data/rss_post/mark/'.parse_url($link,PHP_URL_HOST).'.txt';
  63.                     if(!file_exists($markfile)||strpos(file_get_contents($markfile) ,$link) === false){        
  64.  
  65.                     foreach ($match as $img) {
  66.                         $imgpath=DISCUZ_ROOT . './data/attachment/forum';
  67.                         if(!is_dir($imgpath.'/'.date('Ym'))) make_dir($imgpath.'/'.date('Ym'));
  68.                         if(!is_dir($imgpath.'/'.date('Ym').'/'.date('d'))) make_dir($imgpath.'/'.date('Ym').'/'.date('d'));
  69.                         $imagedata = file_get_contents($img[2]);
  70.                         $ext = addslashes(strtolower(substr(strrchr($img[2], '.'), 1, 10)));   
  71.                         $filename = strtolower(substr(strrchr($img[2], '/'), 1));
  72.                         $attachment=date('Ym').'/'.date('d').'/'.date('His').strtolower(random(16)).'.'.$ext;
  73.                         $imagefile = $imgpath.'/'.$attachment;
  74.                         $imageurl = $_G['siteurl'] .(substr($_G['siteurl'],-1)=='/'?'':'/').$imagefile;                    
  75.                         $f = fopen($imagefile,'w');
  76.                         fwrite($f,$imagedata);
  77.                         fclose($f);                    
  78.                         list($width, $height, $type, $attr) = getimagesize($imagefile);
  79.                         // insert new image
  80.                        
  81.                         $arr = array(
  82.                             'tid'=>0,
  83.                             'pid'=>0,
  84.                             'uid'=>0,
  85.                             'tableid'=>0,
  86.                             'downloads'=>0,
  87.                         );
  88.                         DB::insert('forum_attachment',$arr);
  89.                         $aid = DB::insert_id();                
  90.                        
  91.                         // edit content
  92.                         $description=str_replace("{$img[1]}","[attach]{$aid}[/attach]",$description);
  93.                         // queue order
  94.                         $attach_img[] = array(
  95.                             'aid'=>$aid,
  96.                             'filename'=>$filename,
  97.                             'filesize'=>filesize($imagefile),
  98.                             'attachment'=>$attachment,
  99.                             'width'=>$width
  100.                         );
  101.                     }
  102.                     }
  103.                    
  104.                 }
  105.                 }
  106.                 $description = addslashes($description);
  107.                
  108.                 if (!isset($dd['image_var'])||$dd['image_var']=='') {$image='';} else {
  109.                 if ($domDocument->getElementsByTagName($dd['image_var'])->length!=0)
  110.                 {
  111.                     $image=trim($data->getElementsByTagName($dd['image_var'])->item(0)->getAttribute('url'));
  112.                 } else {$image='';}
  113.                 }
  114.                 $time = strtotime(trim($data->getElementsByTagName("pubDate")->item(0)->nodeValue));
  115.                 $title = str_replace(array('\\','\''),array('\\\\','\\\''),$title);
  116.                 $markfile=DISCUZ_ROOT . './data/rss_post/mark/'.parse_url($link,PHP_URL_HOST).'.txt';
  117.                 if(!file_exists($markfile)||strpos(file_get_contents($markfile) ,$link) === false){        
  118.                 $f = fopen($markfile,'a');
  119.                 fwrite($f,$link."\n");
  120.                 fclose($f);            
  121.                 if ($dd['module']==''||!isset($dd['module'])) {
  122.                     $content = $description;
  123.                     $content.= '
  124.                    
  125. [b]ขอบคุณข่าวจาก:[/b] [url=http://'.parse_url($link,PHP_URL_HOST).']'.parse_url($link,PHP_URL_HOST).'[/url]';
  126.                 } elseif ($dd['module']=='thairath') {         
  127.                     $image=trim($data->getElementsByTagName('enclosure')->item(0)->getAttribute('url'));
  128.                     $image = str_replace('120.jpg','630.jpg',$image);
  129.                     $content = file_get_contents($link);
  130.                     $content = explode('<div id="details" class="page">',$content);
  131.                     $content = $content[1];
  132.                     $content = explode('</p></p>',$content);
  133.                     $content = $content[0];
  134.                     $content = str_replace(array('\\','\'','<br />','</p>'),array('\\\\','\\\'',"\r\n","\r\n"),$content);
  135.                     $content = strip_tags($content);
  136.                     $content.='
  137.                    
  138. [b]ขอบคุณข่าวจาก:[/b] [url=http://www.thairath.co.th]ไทยรัฐออนไลน์[/url]';
  139.                 }
  140.                                
  141.                
  142.                 // save image
  143.                 if ($image!='') {          
  144.                         $imgpath=DISCUZ_ROOT . './data/attachment/forum';
  145.                         if(!is_dir($imgpath.'/'.date('Ym'))) make_dir($imgpath.'/'.date('Ym'));
  146.                         if(!is_dir($imgpath.'/'.date('Ym').'/'.date('d'))) make_dir($imgpath.'/'.date('Ym').'/'.date('d'));
  147.                         $imagedata = file_get_contents($image);
  148.                         $ext = addslashes(strtolower(substr(strrchr($image, '.'), 1, 10)));
  149.                         $filename = strtolower(substr(strrchr($img[2], '/'), 1));
  150.                         $attachment=date('Ym').'/'.date('d').'/'.date('His').strtolower(random(16)).'.'.$ext;
  151.                         $imagefile = $imgpath.'/'.$attachment;
  152.                         $imageurl = $_G['siteurl'] .(substr($_G['siteurl'],-1)=='/'?'':'/').$imagefile;
  153.                         $f = fopen($imagefile,'w');
  154.                         fwrite($f,$imagedata);
  155.                         fclose($f);            
  156.                         list($width, $height, $type, $attr) = getimagesize($imagefile);                    
  157.                         // insert new image
  158.                         $arr = array(
  159.                             'tid'=>0,
  160.                             'pid'=>0,
  161.                             'uid'=>0,
  162.                             'tableid'=>0,
  163.                             'downloads'=>0,
  164.                         );
  165.                         DB::insert('forum_attachment',$arr);
  166.                         $aid = DB::insert_id();                
  167.                         // edit content
  168.                         $content = '[attach]'.$aid.'[/attach]'.$content;                       
  169.                         // queue order                     
  170.                         $attach_img[] = array(
  171.                             'aid'=>$aid,
  172.                             'filename'=>$filename,
  173.                             'filesize'=>filesize($imagefile),
  174.                             'attachment'=>$attachment,
  175.                             'width'=>$width
  176.                         );
  177.  
  178.                 }
  179.                
  180.                 $content .= $credit_links;
  181.                 $count++;
  182.                 $poster = DB::result_first("SELECT username FROM ".DB::table('common_member')." WHERE uid='{$rsspost['poster_uid']}'");
  183.                 $arr = array(
  184.                     'fid'=>$dd['fid'],
  185.                     'author'=>$poster,
  186.                     'authorid'=>$rsspost['poster_uid'],
  187.                     'subject'=>$title,
  188.                     'dateline'=>$time,
  189.                     'lastpost'=>$time,
  190.                     'lastposter'=>$poster,
  191.                     'status'=>32,
  192.                     'stamp'=>-1,
  193.                     'icon'=>-1,
  194.                 );
  195.                 DB::insert('forum_thread',$arr);
  196.                 $tid = DB::insert_id();
  197.                
  198.                 $pid = insertpost(array(
  199.                     'fid'=>$dd['fid'],
  200.                     'tid'=>$tid,
  201.                     'first'=>1,
  202.                     'author'=>$poster,
  203.                     'authorid'=>$rsspost['poster_uid'],
  204.                     'subject'=>$title,
  205.                     'dateline'=>$time,
  206.                     'message'=>$content,
  207.                     'useip'=>'127.0.0.1',
  208.                     'invisible'=>0,
  209.                     'anonymous'=>0,
  210.                     'usesig'=>1,
  211.                     'htmlon'=>1,
  212.                     'bbcodeoff'=>0,
  213.                     'smileyoff'=>0,
  214.                     'parseurloff'=>0,
  215.                     'attachment'=>'0',
  216.                     'tags'=>'',
  217.                 ));
  218.                 DB::query("UPDATE ".DB::table('forum_forum')." SET threads=threads+1,posts=posts+1,todayposts=todayposts+1,lastpost='".strval($tid) .' '.$title .' '.$time .' '.$poster."' WHERE fid='{$dd['fid']}'", 'UNBUFFERED');
  219.                 DB::query("UPDATE ".DB::table('common_member_count')." SET posts=posts+1,threads=threads+1 WHERE uid='{$rsspost['poster_uid']}'", 'UNBUFFERED');   
  220.                 $first_img=0;
  221.                 // insert image
  222.                 foreach ($attach_img as $ai) {
  223.                    
  224.                     $tableid=$tid%10;
  225.                     DB::query("UPDATE ".DB::table('forum_attachment')." SET tid='{$tid}',pid='{$pid}',uid={$rsspost['poster_uid']},tableid='{$tableid}' WHERE aid='{$ai['aid']}'", 'UNBUFFERED');  
  226.                     $arr = array(
  227.                         'aid'=>$ai['aid'],
  228.                         'tid'=>$tid,
  229.                         'pid'=>$pid,
  230.                         'uid'=>$rsspost['poster_uid'],
  231.                         'dateline'=>$_G['timestamp'],
  232.                         'filename'=>$ai['filename'],
  233.                         'filesize'=>$ai['filesize'],
  234.                         'attachment'=>$ai['attachment'],
  235.                         'remote'=>0,
  236.                         'description'=>'',
  237.                         'readperm'=>0,
  238.                         'price'=>0,
  239.                         'isimage'=>1,
  240.                         'width'=>$ai['width'],
  241.                         'thumb'=>0,
  242.                         'picid'=>0
  243.                     );
  244.                     DB::insert('forum_attachment_'.$tableid,$arr);
  245.                     DB::query("UPDATE ".DB::table('forum_post')." SET attachment=attachment+1 WHERE pid='{$pid}'", 'UNBUFFERED');
  246.                     DB::query("UPDATE ".DB::table('forum_thread')." SET attachment=attachment+1 WHERE tid='{$tid}'", 'UNBUFFERED');
  247.                     if ($first_img==0) {
  248.                     DB::insert('forum_threadimage', array(
  249.                             'tid' => $tid,
  250.                             'attachment' => $ai['attachment'],
  251.                             'remote' => 0
  252.                     ));
  253.                     $first_img=1;
  254.                     }
  255.  
  256.                 }
  257.                 }
  258.             }
  259.         } else {
  260.         }
  261.     }
  262. }
  263.  
  264. function BBCODE($input)
  265. {
  266. $bbcode = array(
  267. "/\<([bius])\>/is" => "[$1]",
  268. "/\<center\>/is" => "[align=center]",
  269. "/\<\/center\>/is" => "[/align]",
  270. "/\<strong\>/is" => "[b]",
  271. "/\<\/strong\>/is" => "[/b]",
  272. "/\<em\>/is" => "[i]",
  273. "/\<\/em\>/is" => "[/i]",
  274. "/\<code\>/is" => "[code]",
  275. "/\<\/code\>/is" => "[/code]",
  276. "/\<small\>/is" => "[small]",
  277. "/\<\/small\>/is" => "[/small]",
  278. "/\<script[^>]*\>.*\<\/script\>/is" => "",
  279. "/\<font[^>]*\>/is" => "",
  280. "/\<h([0-9]+)[^>]*\>/" => "[h$1]",
  281. "/\<\/h([0-9]+)[^>]*\>/" => "[/h$1]",
  282. "/\<\/font\>/is" => "",
  283. "/\<span[^>]*\>/is" => "",
  284. "/\<\/span\>/is" => "",
  285. "/\<table[^>]*\>/is" => "[table=50%]",
  286. "/\<\/table\>/is" => "[/table]",
  287. "/\<\/tr\>/is" => "[/tr]",
  288. "/\<\/td\>/is" => "[/td]",
  289. "/\<tr[^>]*\>/is" => "[tr]",
  290. "/\<td[^>]*\>/is" => "[td]",
  291. "/\<div[^>]*\>/is" => "[p=30, 2, left]",
  292. "/\<\/div\>/is" => "[/p]",
  293. "/\<p[^>]*\>/is" => "[p=30, 2, left]",
  294. "/\<\/p\>/is" => "[/p]",
  295. "/\<img[^>]*src=[\"\']([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[img]$1[/img]",
  296. "/\<a[^>]*href=[\"\']([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[url=$1]",
  297. "/\<\/a\>/is" => "[/url]",
  298. "/\<ol[^>]*\>/is" => "[list=1]",
  299. "/\<ul[^>]*\>/is" => "[list]",
  300. "/\<li[^>]*\>/is" => "[*]",
  301. "/\<\/li\>/is" => "",
  302. "/\<\/ul\>/is" => "[/list]",
  303. "/\<\/ol\>/is" => "[/list]",
  304. "/\<br[^>]*\>/is" => "\n",
  305. "/\<blockquote[^>]*\>/is" => "[quote]",
  306. "/\<\/blockquote\>/is" => "[/quote]",
  307. "/\<\/blockquote\>/is" => "[/quote]",
  308. "/\<object[^>]*\>/is" => "",
  309. "/\<\/object\>/is" => "",
  310. "/\<param[^>]*\>/is" => "",
  311. "/\<\/param\>/is" => "",
  312. "/\<embed[^>]*src=[\"\'](http\:\/\/www\.youtube\.com\/watch\?v\=\/[^\s'\"<>]+)[\"\'][^>]*\>/is" => "[media=x,500,375]$1[/media]",
  313. "/\<embed[^>]*src=[\"\']http\:\/\/www\.youtube\.com\/v\/([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[media=x,500,375]http://www.youtube.com/watch?v=$1[/media]"
  314. );
  315.  
  316. $text = preg_replace(array_keys($bbcode), array_values($bbcode), $input);
  317.  
  318. $strfind = array(' ', '<', '>', '&');
  319. $strreplace = array(' ', '<', '>', '&');
  320. $text = str_replace($strfind, $strreplace, $text);
  321.  
  322. return  htmlspecialchars_decode($text);
  323. }
  324.  
  325.  
  326. function make_dir($dir, $index = true) {
  327.         $res = true;
  328.         if(!is_dir($dir)) {
  329.             $res = @mkdir($dir, 0777);
  330.             $index && @touch($dir.'/index.html');
  331.         }
  332.         return $res;
  333. }
  334. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement