示例#1
0
 function _getRssItems($args)
 {
     // 날짜 형태
     $DATE_FORMAT = $args->date_format ? $args->date_format : "Y-m-d H:i:s";
     $buff = $this->requestFeedContents($args->rss_url);
     $encoding = preg_match("/<\\?xml.*encoding=\"(.+)\".*\\?>/i", $buff, $matches);
     if ($encoding && !preg_match("/UTF-8/i", $matches[1])) {
         $buff = Context::convertEncodingStr($buff);
     }
     $buff = preg_replace("/<\\?xml.*\\?>/i", "", $buff);
     $oXmlParser = new XmlParser();
     $xml_doc = $oXmlParser->parse($buff);
     if ($xml_doc->rss) {
         $rss->title = $xml_doc->rss->channel->title->body;
         $rss->link = $xml_doc->rss->channel->link->body;
         $items = $xml_doc->rss->channel->item;
         if (!$items) {
             return;
         }
         if ($items && !is_array($items)) {
             $items = array($items);
         }
         $content_items = array();
         foreach ($items as $key => $value) {
             if ($key >= $args->list_count * $args->page_count) {
                 break;
             }
             unset($item);
             foreach ($value as $key2 => $value2) {
                 if (is_array($value2)) {
                     $value2 = array_shift($value2);
                 }
                 $item->{$key2} = $this->_getRssBody($value2);
             }
             $content_item = new contentItem($rss->title);
             $content_item->setContentsLink($rss->link);
             $content_item->setTitle($item->title);
             $content_item->setNickName(max($item->author, $item->{'dc:creator'}));
             //$content_item->setCategory($item->category);
             $item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->description);
             $content_item->setContent($item->description);
             $content_item->setLink($item->link);
             $date = date('YmdHis', strtotime(max($item->pubdate, $item->pubDate, $item->{'dc:date'})));
             $content_item->setRegdate($date);
             $content_items[] = $content_item;
         }
     } elseif ($xml_doc->{'rdf:rdf'}) {
         // rss1.0 지원 (Xml이 대소문자를 구분해야 하는데 XE의 XML파서가 전부 소문자로 바꾸는 바람에 생긴 case) by misol
         $rss->title = $xml_doc->{'rdf:rdf'}->channel->title->body;
         $rss->link = $xml_doc->{'rdf:rdf'}->channel->link->body;
         $items = $xml_doc->{'rdf:rdf'}->item;
         if (!$items) {
             return;
         }
         if ($items && !is_array($items)) {
             $items = array($items);
         }
         $content_items = array();
         foreach ($items as $key => $value) {
             if ($key >= $args->list_count * $args->page_count) {
                 break;
             }
             unset($item);
             foreach ($value as $key2 => $value2) {
                 if (is_array($value2)) {
                     $value2 = array_shift($value2);
                 }
                 $item->{$key2} = $this->_getRssBody($value2);
             }
             $content_item = new contentItem($rss->title);
             $content_item->setContentsLink($rss->link);
             $content_item->setTitle($item->title);
             $content_item->setNickName(max($item->author, $item->{'dc:creator'}));
             //$content_item->setCategory($item->category);
             $item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->description);
             $content_item->setContent($item->description);
             $content_item->setLink($item->link);
             $date = date('YmdHis', strtotime(max($item->pubdate, $item->pubDate, $item->{'dc:date'})));
             $content_item->setRegdate($date);
             $content_items[] = $content_item;
         }
     } elseif ($xml_doc->feed && $xml_doc->feed->attrs->xmlns == 'http://www.w3.org/2005/Atom') {
         // Atom 1.0 spec 지원 by misol
         $rss->title = $xml_doc->feed->title->body;
         $links = $xml_doc->feed->link;
         if (is_array($links)) {
             foreach ($links as $value) {
                 if ($value->attrs->rel == 'alternate') {
                     $rss->link = $value->attrs->href;
                     break;
                 }
             }
         } elseif ($links->attrs->rel == 'alternate') {
             $rss->link = $links->attrs->href;
         }
         $items = $xml_doc->feed->entry;
         if (!$items) {
             return;
         }
         if ($items && !is_array($items)) {
             $items = array($items);
         }
         $content_items = array();
         foreach ($items as $key => $value) {
             if ($key >= $args->list_count * $args->page_count) {
                 break;
             }
             unset($item);
             foreach ($value as $key2 => $value2) {
                 if (is_array($value2)) {
                     $value2 = array_shift($value2);
                 }
                 $item->{$key2} = $this->_getRssBody($value2);
             }
             $content_item = new contentItem($rss->title);
             $links = $value->link;
             if (is_array($links)) {
                 foreach ($links as $val) {
                     if ($val->attrs->rel == 'alternate') {
                         $item->link = $val->attrs->href;
                         break;
                     }
                 }
             } elseif ($links->attrs->rel == 'alternate') {
                 $item->link = $links->attrs->href;
             }
             $content_item->setContentsLink($rss->link);
             if ($item->title) {
                 if (!preg_match("/html/i", $value->title->attrs->type)) {
                     $item->title = $value->title->body;
                 }
             }
             $content_item->setTitle($item->title);
             $content_item->setNickName(max($item->author, $item->{'dc:creator'}));
             $content_item->setAuthorSite($value->author->uri->body);
             //$content_item->setCategory($item->category);
             $item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->content);
             if ($item->description) {
                 if (!preg_match("/html/i", $value->content->attrs->type)) {
                     $item->description = htmlspecialchars($item->description);
                 }
             }
             if (!$item->description) {
                 $item->description = $item->summary;
                 if ($item->description) {
                     if (!preg_match("/html/i", $value->summary->attrs->type)) {
                         $item->description = htmlspecialchars($item->description);
                     }
                 }
             }
             $content_item->setContent($item->description);
             $content_item->setLink($item->link);
             $date = date('YmdHis', strtotime(max($item->published, $item->updated, $item->{'dc:date'})));
             $content_item->setRegdate($date);
             $content_items[] = $content_item;
         }
     }
     return $content_items;
 }
示例#2
0
 function _getRssItems($args)
 {
     // Date Format
     $DATE_FORMAT = $args->date_format ? $args->date_format : "Y-m-d H:i:s";
     $buff = $this->requestFeedContents($args->rss_url);
     $encoding = preg_match("/<\\?xml.*encoding=\"(.+)\".*\\?>/i", $buff, $matches);
     if ($encoding && stripos($matches[1], "UTF-8") === FALSE) {
         $buff = Context::convertEncodingStr($buff);
     }
     $buff = preg_replace("/<\\?xml.*\\?>/i", "", $buff);
     $oXmlParser = new XmlParser();
     $xml_doc = $oXmlParser->parse($buff);
     if ($xml_doc->rss) {
         $rss->title = $xml_doc->rss->channel->title->body;
         $rss->link = $xml_doc->rss->channel->link->body;
         $items = $xml_doc->rss->channel->item;
         if (!$items) {
             return;
         }
         if ($items && !is_array($items)) {
             $items = array($items);
         }
         $content_items = array();
         foreach ($items as $key => $value) {
             if ($key >= $args->list_count * $args->page_count) {
                 break;
             }
             unset($item);
             foreach ($value as $key2 => $value2) {
                 if (is_array($value2)) {
                     $value2 = array_shift($value2);
                 }
                 $item->{$key2} = $this->_getRssBody($value2);
             }
             $content_item = new contentItem($rss->title);
             $content_item->setContentsLink($rss->link);
             $content_item->setTitle($item->title);
             $content_item->setNickName(max($item->author, $item->{'dc:creator'}));
             //$content_item->setCategory($item->category);
             $item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->description);
             $content_item->setContent($this->_getSummary($item->description, $args->content_cut_size));
             $content_item->setThumbnail($this->_getRssThumbnail($item->description));
             $content_item->setLink($item->link);
             $date = date('YmdHis', strtotime(max($item->pubdate, $item->pubDate, $item->{'dc:date'})));
             $content_item->setRegdate($date);
             $content_items[] = $content_item;
         }
     } else {
         if ($xml_doc->{'rdf:rdf'}) {
             // rss1.0 supported (XE's XML is case-insensitive because XML parser converts all to small letters. Fixed by misol
             $rss->title = $xml_doc->{'rdf:rdf'}->channel->title->body;
             $rss->link = $xml_doc->{'rdf:rdf'}->channel->link->body;
             $items = $xml_doc->{'rdf:rdf'}->item;
             if (!$items) {
                 return;
             }
             if ($items && !is_array($items)) {
                 $items = array($items);
             }
             $content_items = array();
             foreach ($items as $key => $value) {
                 if ($key >= $args->list_count * $args->page_count) {
                     break;
                 }
                 unset($item);
                 foreach ($value as $key2 => $value2) {
                     if (is_array($value2)) {
                         $value2 = array_shift($value2);
                     }
                     $item->{$key2} = $this->_getRssBody($value2);
                 }
                 $content_item = new contentItem($rss->title);
                 $content_item->setContentsLink($rss->link);
                 $content_item->setTitle($item->title);
                 $content_item->setNickName(max($item->author, $item->{'dc:creator'}));
                 //$content_item->setCategory($item->category);
                 $item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->description);
                 $content_item->setContent($this->_getSummary($item->description, $args->content_cut_size));
                 $content_item->setThumbnail($this->_getRssThumbnail($item->description));
                 $content_item->setLink($item->link);
                 $date = date('YmdHis', strtotime(max($item->pubdate, $item->pubDate, $item->{'dc:date'})));
                 $content_item->setRegdate($date);
                 $content_items[] = $content_item;
             }
         } else {
             if ($xml_doc->feed && $xml_doc->feed->attrs->xmlns == 'http://www.w3.org/2005/Atom') {
                 // Atom 1.0 spec supported by misol
                 $rss->title = $xml_doc->feed->title->body;
                 $links = $xml_doc->feed->link;
                 if (is_array($links)) {
                     foreach ($links as $value) {
                         if ($value->attrs->rel == 'alternate') {
                             $rss->link = $value->attrs->href;
                             break;
                         }
                     }
                 } else {
                     if ($links->attrs->rel == 'alternate') {
                         $rss->link = $links->attrs->href;
                     }
                 }
                 $items = $xml_doc->feed->entry;
                 if (!$items) {
                     return;
                 }
                 if ($items && !is_array($items)) {
                     $items = array($items);
                 }
                 $content_items = array();
                 foreach ($items as $key => $value) {
                     if ($key >= $args->list_count * $args->page_count) {
                         break;
                     }
                     unset($item);
                     foreach ($value as $key2 => $value2) {
                         if (is_array($value2)) {
                             $value2 = array_shift($value2);
                         }
                         $item->{$key2} = $this->_getRssBody($value2);
                     }
                     $content_item = new contentItem($rss->title);
                     $links = $value->link;
                     if (is_array($links)) {
                         foreach ($links as $val) {
                             if ($val->attrs->rel == 'alternate') {
                                 $item->link = $val->attrs->href;
                                 break;
                             }
                         }
                     } else {
                         if ($links->attrs->rel == 'alternate') {
                             $item->link = $links->attrs->href;
                         }
                     }
                     $content_item->setContentsLink($rss->link);
                     if ($item->title) {
                         if (stripos($value->title->attrs->type, "html") === FALSE) {
                             $item->title = $value->title->body;
                         }
                     }
                     $content_item->setTitle($item->title);
                     $content_item->setNickName(max($item->author, $item->{'dc:creator'}));
                     $content_item->setAuthorSite($value->author->uri->body);
                     //$content_item->setCategory($item->category);
                     $item->description = $item->content ? $item->content : ($item->description = $item->summary);
                     $item->description = preg_replace('!<a href=!is', '<a onclick="window.open(this.href);return false" href=', $item->description);
                     if ($item->content && stripos($value->content->attrs->type, "html") === FALSE || !$item->content && stripos($value->summary->attrs->type, "html") === FALSE) {
                         $item->description = htmlspecialchars($item->description, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
                     }
                     $content_item->setContent($this->_getSummary($item->description, $args->content_cut_size));
                     $content_item->setThumbnail($this->_getRssThumbnail($item->description));
                     $content_item->setLink($item->link);
                     $date = date('YmdHis', strtotime(max($item->published, $item->updated, $item->{'dc:date'})));
                     $content_item->setRegdate($date);
                     $content_items[] = $content_item;
                 }
             }
         }
     }
     return $content_items;
 }