function read($url) { $feed = new Feed(); //gets xml from url $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $raw = curl_exec($ch); $feed->feed_url($url); $feed->time_to_live(500); //$feed->save(); $xml = new SimpleXMLElement($raw); $items = array(); foreach ($xml->channel->item as $xml_item) { //var_dump($xml_item); $item = new Item(); $item->title((string) $xml_item->title); $item->body((string) $xml_item->description); //var_dump($item); $items[] = $item; } $feed->items($items); $feed->save(); }
/** * 讀取RSS * * 範例:http://localhost/kals/web_apps/rss/webpage/1573 */ public function webpage($webpage_id = NULL) { if (is_null($webpage_id)) { $webpage = get_context_webpage(); $webpage_id = $webpage->get_id(); redirect("/web_apps/rss/webpage/" . $webpage_id); return; } $this->load->library('kals_resource/Webpage'); $this->load->library('kals_resource/Annotation'); $this->load->library('search/Search_annotation_collection'); $this->lang->load('kals_web_apps'); //語系 //echo $webpage_id; $webpage = new Webpage($webpage_id); //$search = $webpage->get_search_annotation(); $search = new Search_annotation_collection(); $search->set_target_webpage($webpage_id); $search->set_limit(10); $order_type_id = 6; $desc = TRUE; $search->add_order($order_type_id, $desc); // ------------------------------ // 以下開始建立RSS清單 // // 請使用php-rss-writer來建立 // // 專案首頁:https://github.com/suin/php-rss-writer // 程式碼位置:https://github.com/suin/php-rss-writer/tree/master/Source/Suin/RSSWriter // ------------------------------ $this->load->library("web_apps/Suin/RSSWriter/Feed"); $this->load->library("web_apps/Suin/RSSWriter/Channel"); $this->load->library("web_apps/Suin/RSSWriter/Item"); $feed = new Feed(); $webpage_title = $webpage->get_title(); //$webpage_topics_path = '/mobile_apps/annotation_topics/webpade_id/'.$webpage_id; //$webpage_topics_url = get_kals_base_url($webpage_topics_path); //$webpage_topics_url = site_url('/mobile_apps/annotation_topics/webpade_id/'.$webpage_id); //$webpage_topics_url = $webpage->get_url() . "#mobile=true"; $webpage_topics_url = get_kals_base_url("mobile_apps/redirect/load/" . $webpage_id); $channel = new Channel(); $channel->title($webpage_title)->description("Channel Description")->url($webpage_topics_url)->appendTo($feed); foreach ($search as $annotation) { $item = new Item(); $type = $annotation->get_type(); $type_name = $type->get_name(); $type_show; if ($type_name != 'annotation.type.custom') { //自定標註顯示 $type_show = $this->lang->line("web_apps." . $type_name); } else { $type_show = $type->get_custom_name(); } // anchor text // user name // date // annotation type // note $annotation_id = $annotation->get_id(); if (isset($annotation_id)) { //$topic_array = $this->db->query("SELECT topic_id // FROM annotation // WHERE annotation_id ='".$annotation_id."'"); $topic_array = $this->db->select("topic_id")->from("annotation")->where("annotation_id", $annotation_id)->where("deleted", "false")->get(); } foreach ($topic_array->result_array() as $row) { $topic_id = $row['topic_id']; } /** * @author Pulipuli Chen 20140429 * 要記得沒有topic的標註啊…… */ $topic_id = trim($topic_id); if ($topic_id == "") { $topic_id = $annotation_id; } //$item_url = 'http://140.119.61.137/kals/mobile/annotation_thread/'.$topic_id.'#annotation_'.$annotation_id; //$annotation_thread_path = "mobile_apps/annotation_thread/topic_id/".$topic_id."#annotation_".$annotation_id; //$item_url = site_url($annotation_thread_path); //$item_url = get_kals_base_url($annotation_thread_path); //$item_url = $webpage->get_url() . "#mobile=true&topic_id=" . $topic_id . "&annotation_id=" . $annotation_id; $item_url = get_kals_base_url("mobile_apps/redirect/load/" . $webpage_id . "/" . $topic_id . "/" . $annotation_id); //$item_url = $_SERVER["HTTP_HOST"] //test_msg($_SERVER["HTTP_HOST"]); $item->title("[" . $type_show . "] " . '"' . $annotation->get_anchor_text() . '"')->description("<div> " . $this->lang->line("web_apps.window.content.search.field.author") . ": " . $annotation->get_user()->get_name() . " </div>" . "<div> " . $this->lang->line("web_apps.window.content.search.field.author") . ": " . $annotation->get_user()->get_name() . " </div>" . "<div>" . $annotation->get_note() . " </div> \n ")->url($item_url)->appendTo($channel); } echo $feed; }
public function test_fail_safe_against_invalid_string() { $item = new Item(); $item->title("testtest")->url("urltest")->description("descdesc"); $expect = '<?xml version="1.0" encoding="UTF-8"?> <item><title>test</title><link>url</link><description>desc</description></item> '; $this->assertSame($expect, $item->asXML()->asXML()); }
function link(Item $item) { return $this->view_helper->anchor_tag($item->title(), 'item.php?id=' . $item->id(), 'blank', array('class' => 'item_link')); }