ไฟล์ index.php
Code
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="news.js" type="text/javascript"></script>
<div class="news">
     <div id="newsdiv"></div>
     <div class="newslink">[ <a href="javascript:newsdivx.nextnews('-1')">ก่อนหน้า</a> | <a href="javascript:newsdivx.nextnews('+1')">ถัดไป</a> ]</div>
</div>
<br />
<div class="news">
     <div id="newsdiv2"></div>
     <div class="newslink">[ <a href="javascript:newsdivx2.nextnews('-1')">ก่อนหน้า</a> | <a href="javascript:newsdivx2.nextnews('+1')">ถัดไป</a> ]</div>
</div>
<script type="text/javascript">
     var newsdivx=new rssthainews('http://www.rssthai.com/rss/entertain.xml', 'newsdiv', 6);
     var newsdivx2=new rssthainews('http://www.rssthai.com/rss/it.xml', 'newsdiv2', 4);
</script>
ไฟล์ reader.php
Code
<?
$feedURL = $_POST['url'];
$count = (int)$_POST['count'];
if ($count==0) $count = -1; //¶éÒäÁèä´é¡Ó˹´ÁÒãËé¤×¹¤èÒ¡ÅѺ·Ø¡ÃÒ¡ÒâèÒÇ
$imagewidth = 75; //¤ÇÒÁ¡ÇéÒ§¢Í§ÃÙ»·ÕèáÊ´§ (default)
$imageheight = 79; //¤ÇÒÁÊÙ§¢Í§ÃÙ»·ÕèáÊ´§ (default)
$detaillength = 170; //¤ÇÒÁÂÒǢͧ ÃÒÂÅÐàÍÕ´ ¶éÒà»ç¹ 0 ¨ÐäÁèäáÊ´§ÃÒÂÅÐàÍÕ´ -1 áÊ´§·Ñé§ËÁ´
if($feedURL && preg_match("/^https?:\/\/.+$/",$feedURL) && ($feedRef = @fopen($feedURL, 'rb'))) {
     $contents = ''; 
     while(!feof($feedRef)) { 
          $contents .= fread( $feedRef, 8192 ); 
     }
     fclose($feedRef);
     $charset=getXMLHeader($contents);
     if ($charset=="") $charset="UTF-8";
     header("content-type: application/x-javascript; charset=$charset"); //à¢Õ¹ header ¢Í§àÍ¡ÊÒà ¨Ò¡ XML ·Õèèä´éÃѺ
     $rss = RSStoArray($contents); //parse RSS ÍÍ¡à»ç¹ array
     
     $listcount = $count;
     for ($i=0; $i<count($rss) && ($listcount>0 || $count==-1); $i++) {
          echo getimage($rss[$i][link][data], "./", false, $imagewidth, $imageheight).chr(1); //¤×¹¤èÒÃÙ»
          echo $rss[$i][link][data].chr(1); //¤×¹¤èÒ link ¢Í§ÃÙ»
          echo $rss[$i][title][data].chr(1); //¤×¹¤èÒ ËÑÇ¢éÍ¢èÒÇ
          $description=$rss[$i][description][data];
          if (strlen($description)>$detaillength && $detaillength>0) $description=substr($description, 0, $detaillength)."...";
          if ($detaillength!=0) echo $description; //¤×¹¤èÒ à¹×éÍËҢͧ¢èÒÇ (¶éÒµéͧ¡ÒÃ)
          echo chr(2); //»Ô´ÃÒ¡ÒôéÇ chr(2)
          $listcount--;
     }
}
//ÍèÒ¹ header 
function getXMLHeader($xml) {
     $headers = explode("<?xml", $xml);
     $ret="";
     for ($i=0; $i<count($headers); $i++) {
          $ret.=parseXMLHeader(trim($headers[$i]));
     }
     return $ret;
}
//á¡àÍÒ attributies ÍÍ¡ 
function parseXMLHeader($data) {
     if ($data!="") {
          $EndPos = strpos($data, '?>'); //¤é¹ËÒ tag »Ô´¢Í§ header
          $datas = explode(" ", substr($data, 0, $EndPos));
          for ($i=0; $i<count($datas); $i++) {
               $temps = explode("=", $datas[$i]);
               if (trim($temps[0])=='encoding') {
                    $value = trim($temps[1]);
                    $value = str_replace('"', '', $value);
                    $value = str_replace("'", '', $value);
                    return $value;
               }
          };
     }
     return;
}
//ÍèÒ¹ÃÒ¡Òà item ·Ñé§ËÁ´
function RSStoArray($xml) {
     $items = preg_split('/<item[\s|>]/', $xml, -1, PREG_SPLIT_NO_EMPTY);
     array_shift($items);
     $i = 0;
     foreach ($items as $item) {
          $array[$i]['title']  = getTextBetweenTags($item, 'title');
          $array[$i]['link']  = getTextBetweenTags($item, 'link');
          $array[$i]['description'] = getTextBetweenTags($item, 'description');
          $array[$i]['author']  = getTextBetweenTags($item, 'author');
          $array[$i]['category']  = getTextBetweenTags($item, 'category');
          $array[$i]['comments']  = getTextBetweenTags($item, 'comments');
          $array[$i]['enclosure']  = getTextBetweenTags($item, 'enclosure');
          $array[$i]['guid']  = getTextBetweenTags($item, 'guid');
          $array[$i]['pubDate']  = getTextBetweenTags($item, 'pubDate');
          $array[$i]['source']  = getTextBetweenTags($item, 'source');
          $i++;
     }
  return $array;
}
//ÍèÒ¹ tag áÅÐ property
function getTextBetweenTags($text, $tag) {
     $StartTag = "<$tag";
     $EndTag = "</$tag";
 
     $StartPosTemp = strpos($text, $StartTag);
     $StartPos = strpos($text, '>', $StartPosTemp);
     $StartPos = $StartPos + 1;
     $EndPos = strpos($text, $EndTag);
     
     $StartAttr = $StartPosTemp + strlen($StartTag) + 1;
     $EndAttr = $StartPos;
     if ($EndAttr > $StartAttr) {
          $attribute = substr ($text, $StartAttr, $EndAttr - $StartAttr - 1);
          $datas = explode(" ", $attribute);
          for ($i=0; $i<count($datas); $i++) {
               $temps = explode("=", $datas[$i]);
               $name = trim($temps[0]);
               if ($name!="/" && $name!="") {
                    $value = trim($temps[1]);
                    $value = str_replace('"', '', $value);
                    $value = str_replace("'", '', $value);
                    $items[$name] = trim($value);
               }
          }
     };
 
     if($EndPos > $BeginPos) {
          $text = substr ($text, $StartPos, ($EndPos - $StartPos));
     } else {
          $text = '';
     }
     if (strpos($text, '[CDATA[')==false) {
          $text = str_replace('<', '<', $text);
          $text = str_replace('>', '>', $text);
          $text = str_replace('&', '&', $text);
          $text = str_replace('"', '"', $text);
     } else {
          $text = str_replace('<![CDATA[', '', $text);
          $text = str_replace(']]>', '', $text);
     }
     $items["data"] = trim($text);
     return $items;
}
function getimage($itemlink, $imagedir, $imageresize, $imagewidth, $imageheight) {
     $parsedlink = parse_url($itemlink);
     list($tx,$rx) = split("&",$parsedlink["query"]);
     list($t,$type) = split("=",$tx);
     list($r,$rid) = split("=",$rx);
     $urlquery = "http://www.rssthai.com/images/?t=$type&r=$rid";
     if (! (strpos($itemlink,"mreader.php") === false)) $urlquery = "http://www.rssthai.com/images/?u=$type&r=$rid";
  
     if (! file_exists($imagedir)) {
          mkdir($imagedir);
     }
  
     $imagefilename = $imagedir.$type."_".$rid."_" . $imagewidth . "x" . $imageheight .".jpg";
  
     if (! file_exists($imagefilename)) {
          $imgContents = null;
   
          $fileHandle = @fopen($urlquery, "r");
          $fileuri = fread($fileHandle, 8192);
          fclose($fileHandle);
          $fileHandle = @fopen($fileuri, "rb");
 
          if($fileHandle) {
               while (!feof($fileHandle)) {
                    $imgContents .= fread($fileHandle, 8192);
               }
               fclose($fileHandle);
    
               if ($imgContents) {
                    if ($imageresize==false || function_exists("imagecreatefromstring")==false) {
                         $handle = fopen($imagefilename, "wb");
                         fwrite($handle, $imgContents);
                         fclose($handle);
                    } else {
                         $source = imagecreatefromstring($imgContents);
                         $imageX = imagesx($source);
                         $imageY = imagesy($source);
                         if ($imagewidth >= $imageX) {
                              $handle = fopen($imagefilename, "wb");
                              fwrite($handle, $imgContents);
                              fclose($handle);
                         } else {
                              $thumbX = $imagewidth;
                              $thumbY = (int)(($thumbX*$imageY) / $imageX );
                              $dest   = imagecreatetruecolor($thumbX, $thumbY);
                              imagecopyresampled ($dest, $source, 0, 0, 0, 0, $thumbX, $thumbY, $imageX, $imageY);
                              imagejpeg($dest,$imagefilename,75);
                              imagedestroy($dest);
                         }
                         imagedestroy($source);
                    }
               }
          }
     }
     return $imagefilename;
}
?>
ไฟล์ news.js
Code
var path="" //path ¢Í§â»Ãá¡ÃÁ¹Ñº¨Ò¡Ë¹éÒ·ÕèàÃÕ¡ãªé µéͧÁÕ / »Ô´·éÒ ¶éÒà»ç¹ path à´ÕÂǡѹäÁèµéͧ¡Ó˹´ÍÐäÃàÅÂ
function rssthainews(url, newsdiv, count) {
     this.newsdiv=newsdiv
     this.divcurr='div1_'+newsdiv
     this.divnext='div2_'+newsdiv
     this.url=url
     this.count=count
     this.news=Array ()
     this.req=this.Inint_AJAX()
     var HInstance=this
     this.req.onreadystatechange=function(){HInstance.initialize()}
     this.req.open("POST", path+"reader.php", true); //ÊÃéÒ§ connection
     this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     this.req.send("url="+url+"&count="+count); //Ê觤èÒ
     if (navigator.userAgent.indexOf("MSIE")==-1) { //¶éÒäÁèãªè IE
          var obj=document.getElementById(newsdiv);
          obj.style.position="relative";
          obj.innerHTML='<div id="div1_'+newsdiv+'" style="position:Absolute;Left:0px;Top:0px;"></div><div id="div2_'+newsdiv+'" style="position:Absolute;Left:0px;Top:0px;"></div>';
     }
}
rssthainews.prototype.initialize=function(){ 
     if (this.req.readyState == 4) {
          if (this.req.status==200) {
               var ret=this.req.responseText //ÃѺ¤èÒ¡ÅѺÁÒ
               this.news=ret.split(String.fromCharCode(2)) //á¡ÍÍ¡à»ç¹¢èÒǵèÒ§æ
                    if (this.news.length>0) {
                         document.getElementById(this.newsdiv).style.backgroundImage  = "url()"
                         //áÊ´§¢èÒÇáá
                         this.displaynews(0)
                         //¨ÑºàÇÅÒáÊ´§¢èÒǤÃÑé§µèÍä»
                         var HInstance=this
                         this.newsinterval=window.setInterval(function(){HInstance.displaynews(HInstance.newsid)}, 10000)
                    }
          }
     }
}
     
rssthainews.prototype.displaynews=function(id) {
     if (id>=this.news.length-1) id=0 //¶Ö§¢èÒÇÊØ´·éÒ¡ÅѺä»áÊ´§¢èÒÇáá
     var datas=this.news[id].split(String.fromCharCode(1)) //á¡ÍÍ¡à»ç¹ÃÒ¡ÒõèÒ§æ
     var data="<div class='rss_image'><img src='"+path+datas[0]+"' alt='' /></div><div class='rss_detail'><a href='"+datas[1]+"' target='_blank'>"+datas[2]+"</a><br />"+datas[3]+"</div>" //à¹×éÍËÒ¢èÒÇ
     this.displaynewsdata(data) //áÊ´§¢èÒÇ·Õè¡Ó˹´
     this.newsid=id+1 //¢èÒǵèÍä»
}
     
rssthainews.prototype.displaynewsdata=function(val) {
     if (document.getElementById) {
          if (navigator.userAgent.indexOf("MSIE")>-1) { //¶éÒà»ç¹ IE áÊ´§ effect
               //ÊØèÁ effect
               switch (Math.floor(Math.random()*7)) {
               case 6: filterstring="progid:DXImageTransform.Microsoft.Checkerboard(squaresX=24, squaresY=16, direction='right', duration=1)"; break
               case 5: filterstring="progid:DXImageTransform.Microsoft.Pixelate(duration=2)"; break
               case 4: filterstring="progid:DXImageTransform.Microsoft.Fade(duration=3,overlap=1.0)"; break
               case 3: filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0, Duration=3, Motion=reverse, wipeStyle=1)"; break
               case 2: filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0, Duration=3, wipeStyle=1)"; break
               case 1: filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0, Duration=3, Motion=reverse)"; break
               default: filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0, Duration=3)"; break
               }
               var imgobj=document.getElementById(this.newsdiv)
               if (imgobj.filters && window.createPopup) {
                    imgobj.style.filter=filterstring
                    imgobj.filters[0].Apply()
               }
               imgobj.innerHTML=val
               if (imgobj.filters && window.createPopup) imgobj.filters[0].Play()
          } else { //Browser Í×è¹æ áÊ´§ ¢èÒÇ´éÇ fade Effect
               this.blenddiv(val)
          }
     }
}
//áÊ´§¼Å ¨Ñ´¡ÒÃáÊ´§¼Å
rssthainews.prototype.blenddiv=function(val) {
     var newsdiv=this.newsdiv
     //ÊÅѺ Layer
     this.divcurr=this.divnext
     this.divnext=(this.divcurr=='div1_'+newsdiv) ? 'div2_'+newsdiv : 'div1_'+newsdiv;
     //«è͹ Layer divcurr ¡è͹
     this.changeOpac(0, this.divcurr);
     document.getElementById(this.divcurr).innerHTML=val;
     document.getElementById(this.divcurr).style.visibility='visible'
     //fade in divcurr áÅÐ fade out divnext
     this.fade(0, this.divcurr, this.divnext)
}
//áÊ´§ effect äÁèãªè ie
rssthainews.prototype.fade=function(val, divcurr, divnext) {
     this.changeOpac(val, divcurr);
     this.changeOpac(100-val, divnext);
     if (val<=100) {
          var HInstance=this
          HInstance.val=val+5
          HInstance.divcurr=divcurr
          HInstance.divnext=divnext
          setTimeout(function() {HInstance.fade(HInstance.val, HInstance.divcurr, HInstance.divnext)}, 50);
     } else {
          document.getElementById(divnext).style.visibility='hidden'
     }
}
//áÊ´§¢èÒÇ¶Ñ´ä» +1 ¡è͹˹éÒ -1
rssthainews.prototype.nextnews=function(id) {
     clearInterval(this.newsinterval) //¡àÅÔ¡¡ÒÃáÊ´§¢èÒÇàÁ×èÍÁÕ¡ÒÃàÅ×Í¡¢èÒÇ
     if (id=='-1') { //áÊ´§¢èÒǶÍÂËÅѧ
          this.newsid=this.newsid-2
          if (this.newsid==-1) this.newsid=this.news.length-2 //¶ÍÂËÅѧ¶Ö§ÃÒ¡ÒÃÊØ´·éÒ¡ÅѺä»áÊ´§¢èÒÇËÅÑ§ÊØ´
     }
     this.displaynews(this.newsid)
     //¨ÑºàÇÅÒáÊ´§¢èÒǤÃÑé§µèÍä»
     var HInstance=this
     this.newsinterval=window.setInterval(function(){HInstance.displaynews(HInstance.newsid)}, 10000)
}
//AJAX function
rssthainews.prototype.Inint_AJAX=function() {
     try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
     try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
     try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
     alert("XMLHttpRequest not supported");
     return null;
}
//change the opacity for different browsers
rssthainews.prototype.changeOpac=function(opacity, id) {
     var object=document.getElementById(id).style
     object.opacity=(opacity/100)
     object.MozOpacity=(opacity/100)
     object.KhtmlOpacity=(opacity/100)
     object.filter="alpha(opacity="+opacity+")"
}
มันดึงไม่มาครับ ผิดตรงไหนช่วยบอกทีครับ
Tag : - - - -