/** * 列出指定網頁的標註列表 * @param type $wepage_id * @param type $page */ public function webpage_id($webpage_id, $page = 0) { //$topic_id = NULL $this->load->library('kals_resource/Webpage'); $this->load->library('kals_resource/Annotation'); $data = array(); $webpage = new Webpage($webpage_id); $data["webpage"] = $webpage; // 取得文章標題 $title = $webpage->get_title(); $data['webpage_title'] = $title; // rss->user_id /*$session_user = $this->session->userdata('user_id'); if (isset($session_user)) { $user_id = get_context_user()->get_id(); } else { $user_id = 0; }*/ $user = get_context_user(); //echo 'get_context_user ='******'//'; //echo $this->session->userdata('logged_in').'//'; //echo 'session_user_id ='.$this->session->userdata('user_id'); // 取得網頁中所有的標註並設定collection的排序方式 $written_annotations = $this->_get_written_annotations_from_webpage($webpage); // 查詢未讀過的annotation $unread_topics = $this->_get_unread_topcis($webpage); $data['written_annotations'] = $this->_filter_written_annotations($written_annotations, $unread_topics); $data["webpage_url"] = $webpage->get_url(); // log區 -使用mobile裝置瀏覽topic list- action = 40 $this->_log($webpage); return $this->_display_view($data); }
/** * 讀取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; }
/** * annotation_topics * @param Int $webpage_id 不可以是空值 */ public function annotation_topics($webpage_id) { //$topic_id = NULL $this->load->library('kals_resource/Webpage'); $this->load->library('kals_resource/Annotation'); $data = array(); $webpage = new Webpage($webpage_id); // 取得文章標題 $title = $webpage->get_title(); $data['title'] = $title; // 取得網頁中所有的標註並設定collection的排序方式 $annotation_order = 10; $annotation_desc = TRUE; $written_annotations = $webpage->get_written_annotations($annotation_order, $annotation_desc); $data['written_annotations'] = array(); $array = array(); // rss->user_id /*$session_user = $this->session->userdata('user_id'); if (isset($session_user)) { $user_id = get_context_user()->get_id(); } else { $user_id = 0; }*/ $user = get_context_user(); //echo 'get_context_user ='******'//'; //echo $this->session->userdata('logged_in').'//'; //echo 'session_user_id ='.$this->session->userdata('user_id'); // 查詢未讀過的annotation //if ( $user_id !== 0 ){ if (isset($user)) { $user_id = $user->get_id(); $unread_annotation = $this->db->query("SELECT topic_annotation.webpage_id, topic_annotation.is_topic_id, annotation_timestamp, max(log_timestamp) as log_timestamp\n FROM \n (SELECT webpage2annotation.webpage_id, annotation_id AS is_topic_id,\n MAX(CASE WHEN res.update_timestamp IS NULL THEN annotation.update_timestamp\n ELSE res.update_timestamp\n END)AS annotation_timestamp \n FROM annotation JOIN webpage2annotation using (annotation_id) \n LEFT JOIN ( \n SELECT webpage_id, annotation_id AS res_id, annotation.topic_id AS res_topic_id, annotation.update_timestamp\n FROM annotation JOIN webpage2annotation using (annotation_id) \n WHERE topic_id IS NOT NULL AND webpage_id = '" . $webpage_id . "') AS res ON (annotation.annotation_id = res.res_topic_id)\n WHERE annotation.topic_id IS NULL AND webpage2annotation.webpage_id = '" . $webpage_id . "' \n GROUP BY webpage2annotation.webpage_id, is_topic_id) AS topic_annotation\n LEFT JOIN\n (SELECT user_id, webpage_id, note, max(log_timestamp) AS log_timestamp\n FROM log\n WHERE user_id = '" . $user_id . "' AND webpage_id = '" . $webpage_id . "' AND (action = '16' OR action = '41') \n GROUP BY user_id, webpage_id, note) AS log_view_thread\n ON log_view_thread.note like concat('%\"topic_id\":' , topic_annotation.is_topic_id , '%')\n GROUP BY topic_annotation.webpage_id, is_topic_id, annotation_timestamp\n HAVING max(log_timestamp) < annotation_timestamp OR max(log_timestamp) IS NULL"); $unread_array = array(); // 存放unread topic id(topic and res) foreach ($unread_annotation->result_array() as $row) { $unread_id = $row['is_topic_id']; $unread_array[$unread_id] = $row['is_topic_id']; } } //if (isset($user)) { foreach ($written_annotations as $annotation) { $anchor_text = $annotation->get_anchor_text(); //topic //$array['note'] = $annotation->get_note(); //note // get annotation id $annotation_id = $annotation->get_id(); $array['annotation_id'] = $annotation_id; // 控制anchor text顯示長度 $anchor_length = $annotation->get_scope_length(); if ($anchor_length > 10) { $array['anchor_text'] = mb_substr($anchor_text, 0, 8, "utf-8"); } else { $array['anchor_text'] = $anchor_text; } $respond_collection = $annotation->get_topic_respond_length(); //response $array['respond_count'] = $respond_collection; //取得長度(only res) // get last response timestamp if ($array['respond_count'] != 0) { $last_respond = $annotation->get_last_respond(); $last_respond_id = $last_respond->get_id(); $last_item = new $annotation($last_respond_id); $last_timestamp = $last_item->get_create_timestamp(); } else { $last_timestamp = $annotation->get_create_timestamp(); } $last_short_timestamp = substr($last_timestamp, 0, 10); $array['timestamp'] = $last_short_timestamp; //是否為訪客 //if ( $user_id !== 0 ){ if (isset($user)) { $user_id = $user->get_id(); // 判斷有無unread annotation if (isset($unread_array[$annotation_id])) { $array['is_unread'] = 'inline'; //echo $annotation_id; //echo 'Y <br>'; } else { $array['is_unread'] = 'none'; //echo $annotation_id; //echo 'N <br>'; } } else { $array['is_unread'] = 'none'; } //else { $data['written_annotations'][] = $array; } // log區 -使用mobile裝置瀏覽topic list- action = 40 $this->_log_annotation_thread($webpage_id); // 把語系檔存入變數中,傳入view $data['lang'] = $this->lang; $this->load->view('mobile/mobile_views_header'); $this->load->view('mobile/annotation_topic_view', $data); $this->load->view('mobile/mobile_views_footer'); }