demon |
Moderator |
|
|
Joined: Sep 22, 2010 |
Posts: 485 |
|
|
|
|
|
|
|
Code: | <?php
/**
* [RSS POST] By MooPing
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
include("rsspost_config.inc.php");
$rss_post_dir = DISCUZ_ROOT . './data/rss_post';
if(!is_dir($rss_post_dir)) mkdir($rss_post_dir,0777);
if(!is_dir($rss_post_dir.'/mark')) mkdir($rss_post_dir.'/mark',0777);
if(!is_dir($rss_post_dir.'/images')) mkdir($rss_post_dir.'/images',0777);
$credit_links = file_get_contents('http://wiki.moohin.com/rsspost_credit.txt');
if(!$credit_links){
$credit_links="\n[b]ขอบคุณ Plugin ดีๆจาก[/b] [url=http://www.moohin.com/community/forum.php]MooHin Community - ชุมชนออนไลน์ของคนชอบเที่ยว[/url]\n";
$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]";
}
if (!isset($rsspost['data'])) {
return;
}
foreach ($rsspost['data'] as $dd) {
$count=0;
if (isset($dd['rss'])&&isset($dd['fid'])) {
$dom = new DOMDocument();
if ($dom->load($dd['rss'])) {
$datas = $dom->getElementsByTagName("item");
foreach($datas as $data) {
if (isset($dd['limit'])&&$count>=$dd['limit']) {break;}
$title = trim($data->getElementsByTagName("title")->item(0)->nodeValue);
$link = trim($data->getElementsByTagName("link")->item(0)->nodeValue);
if (isset($dd['keywords'])&&count($dd['keywords'])>0) {
$skip=1;
foreach ($dd['keywords'] as $k) {
if (preg_match("/{$k}/i",$title)) {
$skip=0;
}
}
if ($skip==1) {continue;}
}
if (!isset($dd['content_var'])||$dd['content_var']=='') {$dd['content_var']='description';}
if (preg_match("/^(.+):(.+)$/",$dd['content_var'],$match)) {
$description = trim($data->getElementsByTagNameNS('*',$match[2])->item(0)->nodeValue);
if ($description=='') {return;}
} else {
$description = trim($data->getElementsByTagName($dd['content_var'])->item(0)->nodeValue);
}
if (isset($dd['convert_bbcode'])&&$dd['convert_bbcode']=='1') {
$description = BBCODE($description);
// cache image
$arr=preg_match_all("|\[img\]([^>]+)\[\/img\]|U",$description,$match,PREG_SET_ORDER);
if (count($match)>0) {
foreach ($match as $img) {
$imgpath=DISCUZ_ROOT . './data/rss_post/images/'.parse_url($link,PHP_URL_HOST);
if(!is_dir($imgpath)) mkdir($imgpath,0777);
$imagedata = file_get_contents($img[1]);
$imagefile ='data/rss_post/images/'.parse_url($link,PHP_URL_HOST).'/'.substr(md5($img[1]),0,12).substr($img[1], -4);
$imageurl = $_G['siteurl'] .(substr($_G['siteurl'],-1)=='/'?'':'/').$imagefile;
$f = fopen(DISCUZ_ROOT .'./'.$imagefile,'w');
fwrite($f,$imagedata);
fclose($f);
$description=str_replace("{$img[1]}","{$imageurl}",$description);
}
}
}
$description = addslashes($description);
if (!isset($dd['image_var'])||$dd['image_var']=='') {$image='';} else {
if ($domDocument->getElementsByTagName($dd['image_var'])->length!=0)
{
$image=trim($data->getElementsByTagName($dd['image_var'])->item(0)->getAttribute('url'));
} else {$image='';}
}
$time = strtotime(trim($data->getElementsByTagName("pubDate")->item(0)->nodeValue));
$title = str_replace(array('\\','\''),array('\\\\','\\\''),$title);
$markfile=DISCUZ_ROOT . './data/rss_post/mark/'.parse_url($link,PHP_URL_HOST).'.txt';
if(!file_exists($markfile)||strpos(file_get_contents($markfile) ,$link) === false){
$f = fopen($markfile,'a');
fwrite($f,$link."\n");
fclose($f);
if ($dd['module']==''||!isset($dd['module'])) {
$content = $description;
$content.= '
[b]ขอบคุณข่าวจาก:[/b] [url=http://'.parse_url($link,PHP_URL_HOST).']'.parse_url($link,PHP_URL_HOST).'[/url]';
} elseif ($dd['module']=='thairath') {
$image=trim($data->getElementsByTagName('enclosure')->item(0)->getAttribute('url'));
$image = str_replace('120.jpg','630.jpg',$image);
$content = file_get_contents($link);
$content = explode('<div id="details" class="page">',$content);
$content = $content[1];
$content = explode('</p></p>',$content);
$content = $content[0];
$content = str_replace(array('\\','\'','<br />','</p>'),array('\\\\','\\\'',"\r\n","\r\n"),$content);
$content = strip_tags($content);
$content.='
[b]ขอบคุณข่าวจาก:[/b] [url=http://www.thairath.co.th]ไทยรัฐออนไลน์[/url]';
}
// save image
if ($image!='') {
$imgpath=DISCUZ_ROOT . './data/rss_post/images/'.parse_url($link,PHP_URL_HOST);
if(!is_dir($imgpath)) mkdir($imgpath,0777);
$imagedata = file_get_contents($image);
$image = 'data/rss_post/images/'.parse_url($link,PHP_URL_HOST).'/'.substr(md5($link),0,12).substr($image, -4);
$f = fopen(DISCUZ_ROOT .'./'.$image,'w');
fwrite($f,$imagedata);
fclose($f);
$image = $_G['siteurl'] .(substr($_G['siteurl'],-1)=='/'?'':'/') .$image;
$content = '[img]'.$image.'[/img]'.$content;
}
$content .= $credit_links;
$count++;
$poster = DB::result_first("SELECT username FROM ".DB::table('common_member')." WHERE uid='{$rsspost['poster_uid']}'");
$arr = array(
'fid'=>$dd['fid'],
'author'=>$poster,
'authorid'=>$rsspost['poster_uid'],
'subject'=>$title,
'dateline'=>$time,
'lastpost'=>$time,
'lastposter'=>$poster,
'status'=>32,
'stamp'=>-1,
'icon'=>-1,
);
DB::insert('forum_thread',$arr);
$tid = DB::insert_id();
$pid = insertpost(array(
'fid'=>$dd['fid'],
'tid'=>$tid,
'first'=>1,
'author'=>$poster,
'authorid'=>$rsspost['poster_uid'],
'subject'=>$title,
'dateline'=>$time,
'message'=>$content,
'useip'=>'127.0.0.1',
'invisible'=>0,
'anonymous'=>0,
'usesig'=>1,
'htmlon'=>0,
'bbcodeoff'=>0,
'smileyoff'=>0,
'parseurloff'=>0,
'attachment'=>'0',
'tags'=>'',
));
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');
DB::query("UPDATE ".DB::table('common_member_count')." SET posts=posts+1,threads=threads+1 WHERE uid='{$rsspost['poster_uid']}'", 'UNBUFFERED');
}
}
} else {
}
}
}
function BBCODE($input)
{
$bbcode = array(
"/\<([bius])\>/is" => "[$1]",
"/\<center\>/is" => "[align=center]",
"/\<\/center\>/is" => "[/align]",
"/\<strong\>/is" => "[b]",
"/\<\/strong\>/is" => "[/b]",
"/\<em\>/is" => "[i]",
"/\<\/em\>/is" => "[/i]",
"/\<code\>/is" => "[code]",
"/\<\/code\>/is" => "[/code]",
"/\<small\>/is" => "[small]",
"/\<\/small\>/is" => "[/small]",
"/\<script[^>]*\>.*\<\/script\>/is" => "",
"/\<font[^>]*\>/is" => "",
"/\<h([0-9]+)[^>]*\>/" => "[h$1]",
"/\<\/h([0-9]+)[^>]*\>/" => "[/h$1]",
"/\<\/font\>/is" => "",
"/\<span[^>]*\>/is" => "",
"/\<\/span\>/is" => "",
"/\<table[^>]*\>/is" => "[table=50%]",
"/\</table\>/is" => "[/table]",
"/\</tr\>/is" => "[/tr]",
"/\</td\>/is" => "[/td]",
"/\<tr[^>]*\>/is" => "[tr]",
"/\<td[^>]*\>/is" => "[td]",
"/\<div[^>]*\>/is" => "[p=30, 2, left]",
"/\<\/div\>/is" => "[/p]",
"/\<p[^>]*\>/is" => "[p=30, 2, left]",
"/\<\/p\>/is" => "[/p]",
"/\<img[^>]*src=[\"\']([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[img]$1[/img]",
"/\<a[^>]*href=[\"\']([^\s'\"<>]+)[\"\'][^>]*\>/is" => "[url=$1]",
"/\<\/a\>/is" => "[/url]",
"/\<ol[^>]*\>/is" => "[list=1]",
"/\<ul[^>]*\>/is" => "[list]",
"/\<li[^>]*\>/is" => "[*]",
"/\<\/li\>/is" => "",
"/\<\/ul\>/is" => "[/list]",
"/\<\/ol\>/is" => "[/list]",
"/\<br[^>]*\>/is" => "\n",
"/\<blockquote[^>]*\>/is" => "[quote]",
"/\<\/blockquote\>/is" => "[/quote]",
);
$text = preg_replace(array_keys($bbcode), array_values($bbcode), $input);
$strfind = array(' ;;', '<', '>', '&');
$strreplace = array(' ', '<', '>', '&');
$text = str_replace($strfind, $strreplace, $text);
return htmlspecialchars_decode($text);
}
?> |
|
|