<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[TNF : Tatter Network Foundation forum - rss 받아오는 소스좀 봐주세요]]></title>
		<link>http://forum.tattersite.com/ko/viewtopic.php?id=7773</link>
		<description><![CDATA[rss 받아오는 소스좀 봐주세요 의 최근 RSS 글들.]]></description>
		<lastBuildDate>Mon, 09 Feb 2009 08:18:37 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[RSS 답글: rss 받아오는 소스좀 봐주세요]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=33698#p33698</link>
			<description><![CDATA[<p>정말 감사합니다 ^^<br />딱 제가 원하는대로 결과가 나오네요</p><p>한가지만 더 여쭤봐도 될까요?<br />제가 등록하려는 rss가<br />다른 rss구독기로 보면 글이 많이 보이는데<br />이걸로 하면 4개밖에 안보이더라구요.<br />혹시 코드로 더 많이 긁어오게 할 수는 없을까요?</p>]]></description>
			<author><![CDATA[null@example.com (anaki_s)]]></author>
			<pubDate>Mon, 09 Feb 2009 08:18:37 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=33698#p33698</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: rss 받아오는 소스좀 봐주세요]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=33692#p33692</link>
			<description><![CDATA[<p><a href="http://dev.textcube.org/wiki/PluginCode">http://dev.textcube.org/wiki/PluginCode</a>를 보시면 아시겠지만 <br /></p><div class="codebox"><pre><code>&lt;?php
     function Helloworld_Show($target) {
          return $target.&#039;Hello World!&#039;;
     }
?&gt;</code></pre></div><p>요런식으로 $target을 받아온 후 $target에다가 쓰고 싶은걸 쓰고 돌려 주면 되요</p><p>근데 일단 만들어진 소스 많이 고치기 귀찮으니깐</p><br /><br /><p>index.php<br />&lt;?</p><p>include_once &#039;lib.php&#039;;</p><p>function get_rss(<strong>$target</strong>) {//target을 받아옵니다.<br />&nbsp; &nbsp; <strong>ob_start();</strong>//출력 버퍼를 켭니다. 일단 출력되려고 하는 내용은 출력하지말고 저장 해 둡니다.</p><br /><p>&nbsp; &nbsp; //가져올 RSS 주소를 지정하면됩니다. <br />&nbsp; &nbsp; $urls = array(&#039;http://site1.com/rss.php&#039;,&#039;http://site2.com/rss.php&#039;,&#039;http://site3.com/rss.php&#039;);</p><p>&nbsp; &nbsp; &nbsp;foreach ($urls as $url):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$handle = fopen($url, &#039;r&#039;);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($handle):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $document = &#039;&#039;;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (!feof($handle))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$document .= fgets($handle, 4096); </p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose($handle);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//파서 생성<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$rss = new RSSParser;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//파싱<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $rss-&gt;setRSS($document);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rssParse($rss);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $rss = NULL;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;endif;<br />&nbsp; &nbsp; endforeach;<br /><strong>$output=ob_get_contents();//출력버퍼에 있는 내용을 담습니다.<br />ob_end_clean();//출력버퍼를 지웁니다.<br />return $target.$output;</strong>//target과 함께 원하는걸 넘겨 줍니다.</p><p>}</p><br /><p>?&gt;</p><br /><p><a href="http://dev.textcube.org/wiki/PluginSidebar">http://dev.textcube.org/wiki/PluginSidebar</a> 요런식으로 만들면 위젯에서 드레그앤드롭으로 이 플러그인을 배치 할 수 있어요</p>]]></description>
			<author><![CDATA[null@example.com (hoyajigi)]]></author>
			<pubDate>Mon, 09 Feb 2009 06:48:13 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=33692#p33692</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: rss 받아오는 소스좀 봐주세요]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=33681#p33681</link>
			<description><![CDATA[<p>깜빡했네요.<br />대충 다른 플러그인보고 만들어봤구요.&nbsp; </p><p>사이드바에 [##_sr_rss_##] 삽입했습니다.<br />위에 말했다시피 결과는 제대로 출력되는데<br />사이드바가 아닌 문서의 맨 위에 출력이됩니다.</p><div class="codebox"><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;plugin version=&quot;1.0&quot;&gt;
    &lt;title&gt;@실버레인 rss&lt;/title&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;description&gt;
         silverain.org에서 rss feed in을 위한 플러그인입니다.
    &lt;/description&gt;
    &lt;license&gt;GPL&lt;/license&gt;
    &lt;safety changeData=&quot;no&quot; exposeData=&quot;no&quot; accessLocal=&quot;no&quot; accessRemote=&quot;no&quot; accessRaw=&quot;no&quot; /&gt;
    &lt;requirements&gt;
        &lt;tattertools&gt;1.1.*&lt;/tattertools&gt;
    &lt;/requirements&gt;
    &lt;binding&gt;
        &lt;tag name=&quot;sr_rss&quot; handler=&quot;get_rss&quot; /&gt;
        &lt;config dataValHandler=&quot;&quot; manifestHandler=&quot;sr_include_Config&quot;&gt;&lt;/config&gt;
    &lt;/binding&gt;
&lt;/plugin&gt;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (anaki_s)]]></author>
			<pubDate>Sun, 08 Feb 2009 23:55:25 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=33681#p33681</guid>
		</item>
		<item>
			<title><![CDATA[RSS 답글: rss 받아오는 소스좀 봐주세요]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=33679#p33679</link>
			<description><![CDATA[<p>index.xml은 없나요?</p><p>스킨에는 어떻게 삽입하셨나요?</p>]]></description>
			<author><![CDATA[null@example.com (hoyajigi)]]></author>
			<pubDate>Sun, 08 Feb 2009 22:00:58 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=33679#p33679</guid>
		</item>
		<item>
			<title><![CDATA[rss 받아오는 소스좀 봐주세요]]></title>
			<link>http://forum.tattersite.com/ko/viewtopic.php?pid=33678#p33678</link>
			<description><![CDATA[<p>기존의 rss 피딩하는 플러그인들이 다 동작하지 않아서<br />어렵게 인터넷을 뒤져서 rss를 긁어오는 소스로 플러그인을 만들어 보았습니다.<br />그냥 단순하게 제목 날짜 출력해서 링크시키려고 하거든요.<br />그런데 일단 출려은 되는데, 스킨에 삽입하면 원하는 자리가 아니라 문서의 맨 처음에 들어가더라구요.<br />어딜 고쳐야 제대로 삽입이 될런지, 도움좀 부탁드립니다.</p><p>index.php<br /></p><div class="codebox"><pre><code>&lt;?

include_once &#039;lib.php&#039;;

function get_rss() {
    //가져올 RSS 주소를 지정하면됩니다. 
    $urls = array(&#039;http://site.com/rss.php&#039;);

     foreach ($urls as $url):
         $handle = fopen($url, &#039;r&#039;);

         if ($handle):
              $document = &#039;&#039;;

              while (!feof($handle))
                   $document .= fgets($handle, 4096); 

              fclose($handle);

               //파서 생성
               $rss = new RSSParser;

               //파싱
              $rss-&gt;setRSS($document);
              rssParse($rss);

              $rss = NULL;
         endif;
    endforeach;


}


?&gt;</code></pre></div><p>lib.php<br /></p><div class="codebox"><pre><code>&lt;?php

 function rssParse($rss_obj)
 {  
      //내장 XML 파서 생성
     $xml_parser = xml_parser_create(&#039;UTF-8&#039;);
  
     xml_set_object($xml_parser, $rss_obj);   
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);

      //XML 파서에 이벤트 핸들러를 할당
     xml_set_element_handler($xml_parser, &quot;startElement&quot;, &quot;endElement&quot;);
     xml_set_character_data_handler($xml_parser, &quot;characterData&quot;);

      //XML 파싱
     xml_parse($xml_parser, $rss_obj-&gt;getRSS());
     xml_parser_free($xml_parser);
 }


 class RSSParser
{
     private $rss_doc;
 
     private $current_element;
     private $in_item = FALSE;
     private $in_description = FALSE;
     private $title;
     private $date;
     private $link;
     private $category;
     private $content;

 
     function setRSS($rss_text)
     {
          $this-&gt;rss_doc = $rss_text;
     }
 
     function getRSS()
     {
          return $this-&gt;rss_doc;
     }

     //태그가 시작하는 부분에서 처리할 내용  
     function startElement($parser, $element, $attrs)
     {
          if ($this-&gt;in_description) return;    

          $this-&gt;current_element = strtoupper($element);
  
          switch ($this-&gt;current_element):
               case &#039;ITEM&#039; :
                    $this-&gt;in_item = TRUE;
                    break;

               case &#039;DESCRIPTION&#039; :
                    if ($this-&gt;in_item) {
                         $this-&gt;in_description = TRUE;
                         $this-&gt;content = &#039;&#039;;
                    }
                    break;
    
               default: 
                    break;     
          endswitch;
     }
 
     function endElement($parser, $element)
     {
          $el = strtoupper($element);

          if ($this-&gt;in_description and &#039;DESCRIPTION&#039; != $el) return;

          switch (strtoupper($el)):
               case &#039;ITEM&#039; :
                    $this-&gt;in_item = FALSE;
//                    echo &quot;&lt;div class=&#039;rssbox&#039;&gt;&quot;;
                    $this-&gt;printItem();        // 저장된 포스트를 출력하거나 DB로 자장하면 됨.
//                    echo &quot;&lt;/div&gt;&quot;;
                     break;

               case &#039;DESCRIPTION&#039; :
                    if ($this-&gt;in_item) {
                         $this-&gt;in_description = FALSE;
                    } 
                    break;

               default: 
                    break;     
          endswitch;

          $this-&gt;current_element = &#039;&#039;;
     }
 
     function characterData($parser, $data)
     {   
          if (&#039;&#039; == trim($data)) return; 
 
          if ($this-&gt;in_item):
   
           switch ($this-&gt;current_element):
                case &#039;TITLE&#039; :
                     $this-&gt;title = $data;
                     break;

                case &#039;DESCRIPTION&#039; :
                     $this-&gt;content .= $data; //반드시 .= 연산자를 써야함!
                      break;

                case &#039;CATEGORY&#039; :
                     $this-&gt;category = $data;     
                     break;

                case &#039;PUBDATE&#039; :
                     $this-&gt;date = $data;
                     break;

                case &#039;LINK&#039; :
                     $this-&gt;link = $data;
                     break;
           endswitch;   
    
          endif;
     }      






      //여기서는 바로 출력을 하지만, DB에 저장하는 방식으로 구현할 수도 있습니다.
      private function printItem()
     {
          echo &quot;&lt;div class=&#039;date&#039;&gt;&quot;.$this-&gt;date.&quot;&lt;/div&gt;&quot;;
          echo &quot;&lt;div class=&#039;title&#039;&gt;&lt;a href=&quot;,$this-&gt;link,&quot;&gt;&quot;,$this-&gt;title,&quot;&lt;/a&gt;&lt;/div&gt;&quot;;
     }
   
 }//end of class







?&gt;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (anaki_s)]]></author>
			<pubDate>Sun, 08 Feb 2009 18:07:20 +0000</pubDate>
			<guid>http://forum.tattersite.com/ko/viewtopic.php?pid=33678#p33678</guid>
		</item>
	</channel>
</rss>
