Example #1
0
 /**
  * Action範例
  * 
  * @param Array $data 由KALS_controller傳入的資料,組成是關連式的陣列
  * 
  * [Controller的JSON格式]
  * _data = {
  *  "field": "value"
  * };
  * 
  * //取用範例
  * _data["field];   //回傳value
  * 
  * [Model的Array格式]
  * $data = array(
  *  "field" => "value"
  * );
  * 
  * $data["field"];  //回傳value
  * 
  * @return Array 要回傳給KALS_controller的資料
  * 一樣是以關聯式陣列組成
  * 
  */
 public function open($data)
 {
     // -----------------------
     // 從現在的網頁來計算標註跟使用者
     $webpage = $this->get_current_webpage();
     $data["annotation_count"] = $webpage->get_written_annotations_count();
     $data["user_count"] = $webpage->get_written_users_count();
     // ------------------
     // 取出最近的標註
     $search = new Search_annotation_collection();
     $search->set_target_webpage($webpage->get_id());
     $search->set_check_authorize(FALSE);
     $limit = 5;
     $search->set_limit($limit);
     $order_type_id = 6;
     $desc = TRUE;
     $search->add_order($order_type_id, $desc);
     $data["last_annotation"] = array();
     foreach ($search as $index => $annotation) {
         //$json = $annotation->export_data();
         $json = $annotation;
         if ($index == 0) {
             //$last_annotation = $json;
             $data["last_annotation_id"] = $annotation->get_id();
             $data["last_annotation_timestamp"] = $annotation->get_update_timestamp();
         }
         // 一一加入標註
         $data["last_annotation"][] = $json;
     }
     // 也可以最後一口氣取出所有標註
     $data["last_annotation"] = $search;
     // -------------------
     // 依照標註數量來判斷熱門程度
     $activity = "bad";
     if ($data["annotation_count"] > 20) {
         $activity = "good";
     } else {
         if ($data["annotation_count"] > 5) {
             $activity = "normal";
         }
     }
     $data["activity"] = "Good";
     return $data;
 }
Example #2
0
 /**
  * 取得image_spot指定的標註
  * @param int $index 標註的位置
  * @param string $callback
  */
 public function get($index, $callback)
 {
     $output_data = array();
     $url = $this->url;
     $search = new Search_annotation_collection();
     // 設定範圍
     $scope_coll = $this->annotation_scope_collection->import_webpage_search_data($url, $index);
     $search->set_target_scope($scope_coll);
     foreach ($search as $search_annotation) {
         $annotation_data = $search_annotation->export_webpage_imape_spot_data($url);
         $output_data[] = $annotation_data;
     }
     //        $output_data[] = array(
     //            "top" => 286,
     //            "left" => 161,
     //            "width" => 52,
     //            "height" => 37,
     //            "text" => "Small people on the steps",
     //            "id" => "e69213d0-2eef-40fa-a04b-0ed998f9f1f5",
     //            "editable" => false ,
     //            "type" => "疑惑",
     //            "user" => "楊舜閔",
     //            "timestamp" => 1445172850
     //        );
     //
     //        $output_data[] = array(
     //            "top" => 134,
     //            "left" => 179,
     //            "width" => 68,
     //            "height" => 74,
     //            "text" => "National Gallery Dome<span style='color:red;'>color</span>",
     //            "id" => "e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe",
     //            "editable" => true,
     //            "type" => "重要",
     //            "user" => "布丁",
     //            "timestamp" => 1447201802
     //        );
     return $this->_display_jsonp($output_data, $callback);
 }
Example #3
0
 /**
  * 讀取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;
 }
 /**
  * Action範例
  * 
  * @param Array $data 由KALS_controller傳入的資料,組成是關連式的陣列
  * 
  * [Controller的JSON格式]
  * _data = {
  *  "field": "value"
  * };
  * 
  * //取用範例
  * _data["field];   //回傳value
  * 
  * [Model的Array格式]
  * $data = array(
  *  "field" => "value"
  * );
  * 
  * $data["field"];  //回傳value
  * 
  * @return Array 要回傳給KALS_controller的資料
  * 一樣是以關聯式陣列組成
  * 
  */
 public function get_heading_annotation($data)
 {
     $structure = $data["structure"];
     // [14, 56, 70]
     $current_type = $data["current_type"];
     //test_msg($data);
     // 1. 搜尋指定類型的標註
     $search = new Search_annotation_collection();
     // 1.1. 指定現在的網頁
     $webpage = $this->get_current_webpage();
     $search->set_target_webpage($webpage->get_id());
     // 1.2. 指定現在要搜尋的標註類型
     //test_msg("current_type", $current_type);
     //$current_type = intval($current_type);
     $search->set_target_type($current_type);
     // 2. 取得一個Annotation_collection
     $annotation_collection = $search;
     //test_msg("Data found?", $search->length() );
     // 2.1. 準備一下待會要儲存標題與標註數量的陣列
     $heading_list = array();
     if (isset($data["order_by_article"]) && $data["order_by_article"] !== TRUE) {
     } else {
         for ($i = 0; $i < count($structure); $i++) {
             $heading_list[$i] = 0;
         }
     }
     // 3. 迴圈,一一檢查每一個Annotation
     $total_count = 0;
     foreach ($search as $index => $annotation) {
         // 4. 取出Annotation的位置,找出from_index
         $scope_coll = $annotation->get_scopes();
         $from_index = $scope_coll->get_first_index();
         //test_msg($from_index);
         // 5. 判斷他是位於哪一個章節
         // [14, 56, 70]
         $current_heading_number = 0;
         foreach ($structure as $heading_number => $last_index) {
             //test_msg("foreach", array($from_index, $last_index, $heading_number));
             if ($from_index < $last_index) {
                 $current_heading_number = $heading_number;
                 break;
             }
         }
         // 6. 組成回傳的資料
         $count = 1;
         if (key_exists($current_heading_number, $heading_list) === TRUE) {
             $count = $heading_list[$current_heading_number];
             $count = $count + 1;
         }
         //test_msg("heading_list", array($current_heading_number, $count));
         $heading_list[$current_heading_number] = $count;
         $total_count++;
     }
     // array(
     //      1 => 4,
     //      5 => 9,
     //      12 => 1
     // )
     // 7. 排序
     if (isset($data["order_by_article"]) && $data["order_by_article"] !== TRUE) {
         arsort($heading_list);
     }
     // array(
     //      5 => 9,
     //      1 => 4,
     //      12 => 1
     // )
     // 7.1. 排序之後,輸出成JavaScript要的data形式
     $heading_data = array();
     if (is_array($heading_list)) {
         foreach ($heading_list as $heading_number => $count) {
             $item = array("heading_number" => $heading_number, "type_count" => $count);
             //test_msg("item", $item);
             //$return_data[] = $item;
             array_push($heading_data, $item);
         }
     }
     $return_data = array('heading_data' => $heading_data, 'total_count' => $total_count);
     // 8. 回傳
     //test_msg($return_data);
     return $return_data;
     //test_msg($data);
     //return $heading_list;
 }
Example #5
0
 public function check_auth()
 {
     create_context(TRUE);
     $url = 'http://www.plurk.com/p/6dhwp7';
     $email = '*****@*****.**';
     $group_name = 'check_auth';
     $user = $this->user->create_user($url, $email);
     $group = $this->group->create_group($url, $group_name);
     $group->add_actor($user);
     $annotation = new Annotation(784);
     $this->authorize_manager->set_resource($annotation);
     $this->authorize_manager->policy_add_actor(5, $group);
     clear_context_user();
     $search = new Search_annotation_collection();
     $count = $search->length();
     $this->unit->run($count, 'is_int', '先找看看有沒有,應該是有的');
     set_context_user($user);
     $search = new Search_annotation_collection();
     $this->unit->run($search->length(), $count + 1, '設定權限之後,應該能找到被設定的那一個項目');
     unit_test_report($this);
 }
Example #6
0
 /**
  * 
  * @param Search_order $order 排序設定,留空等於預設排序
  * @return \Search_annotation_collection
  */
 public function get_appended_annotation($order = NULL, $desc = NULL)
 {
     $this->_CI_load('library', 'search/Search_annotation_collection', 'search_annotation_collection');
     $search = new Search_annotation_collection();
     $search->set_target_webpage($this->get_id());
     $search->set_check_authorize(FALSE);
     // 設定colllection的排序
     if (isset($order)) {
         $search->add_order($order, $desc);
     }
     $search->disable_limit();
     $search->disable_offset();
     return $search;
 }
Example #7
0
 public function get_consensus_coll()
 {
     $this->_CI_load('library', 'search/Search_annotation_collection', 'search_annotation_collection');
     $type = 'Search_annotation_collection';
     $key = 'annotation_get_consensus_coll';
     $value = $this->get_id();
     $search = get_cache($type, $key, $value);
     if (is_null($search)) {
         $search = new Search_annotation_collection();
         $search->set_check_authorize(false);
         $search->set_limit(NULL);
         $search->set_target_scope($this->scope_coll);
         $search->set_exclude_annotation($this->get_id());
         $search->set_exclude_user($this->get_user());
         $search->set_target_topic(TRUE);
         //只有topic才有分數
         $search->add_order(1);
         set_cache($search, $key, $value);
     }
     return $search;
 }
Example #8
0
 /**
  * 回傳所有標註的範圍,以句子切割
  * 
  * @param Array $data 傳入sentence_structure
  * @return Array 要回傳給KALS_controller的資料
  * 一樣是以關聯式陣列組成
  */
 public function whole_annotations_by_sentence($data)
 {
     $sentence_structure = $data["sentence_structure"];
     $sentence_scopes = $this->_create_division_scopes($sentence_structure);
     // -------------------------
     $webpage = $this->get_current_webpage();
     $search = new Search_annotation_collection();
     $search->set_target_webpage($webpage->get_id());
     //$limit = 5;
     //$search->set_limit($limit);
     $order_type_id = 6;
     $desc = FALSE;
     $search->add_order($order_type_id, $desc);
     $is_topic = true;
     $search->set_target_topic($is_topic);
     //print_r($data["sentence_structure"]);
     // ---------------------------
     $from_index_array = array();
     $steps = array();
     foreach ($search as $index => $annotation) {
         $scopes = $annotation->get_scopes();
         $from_index = $scopes->get_first_index();
         $scope = $this->_match_division_scope_by_from_index($sentence_scopes, $from_index);
         $from_index_array[] = $from_index;
         // 比對是否跟上一個scope相同
         if ($this->_match_last_scope($steps, $scope) === FALSE) {
             $steps[] = $scope;
         }
     }
     $data = array();
     $data["steps"] = $steps;
     $data["from_index_array"] = $from_index_array;
     //$data["steps"] = $sentence_scopes;
     return $data;
 }
Example #9
0
 private function _find_recommend_annotation(Annotation $annotation)
 {
     $scope_coll = $annotation->get_scopes();
     $user = $annotation->get_user();
     $recommend_scope = $annotation->get_recommend_by_scopes();
     if (is_null($recommend_scope)) {
         $recommend_scope = $scope_coll;
     }
     $target_over_score = $this->_get_recommend_by_threshold();
     $this->_CI_load('library', 'search/Search_order_score', 'search_order_score');
     $order_type_id = $this->CI->search_order_score->get_type_id();
     $this->_CI_load('library', 'search/Search_annotation_collection', 'search_annotation_collection');
     $search = new Search_annotation_collection();
     $search->set_limit(1);
     $search->add_order($order_type_id, TRUE);
     $search->set_overlap_scope($recommend_scope);
     $search->set_exclude_scope($scope_coll);
     $search->set_exclude_user($user);
     $search->set_target_over_score($target_over_score);
     if ($search->length() == 1) {
         return $search->get_item(0);
     } else {
         return NULL;
     }
 }
Example #10
0
 /**
  * 取得tooltip指定的標註
  * @param int $annotation_index 標註的位置
  * @param string $callback
  */
 public function tooltip($annotation_index, $callback)
 {
     // -------------
     // 搜尋
     //$annotation_index = 100000;
     $search = new Search_annotation_collection();
     // 限定範圍
     $search->set_overlap_scope_index($annotation_index, $annotation_index);
     // 依照分數排序,由高到低
     $search->add_order(1, TRUE);
     // 只輸出一份
     //$search->set_limit(1);
     // 限定該網頁
     $search->set_target_referer_webpage();
     //--------------
     // 轉換資料
     //$annotation = new Annotation();
     //$annotation = null;
     $annotation = null;
     $output_data = array();
     $result = null;
     foreach ($search as $search_annotation) {
         $annotation = $search_annotation;
         $result = $annotation->get_id();
         $output_data["annotation"] = $annotation->export_data();
         break;
     }
     $output_data["count"] = $search->length();
     //--------------
     // 記錄
     $action = 35;
     $log_note = array('index' => $annotation_index, 'result' => $result);
     kals_log($this->db, $action, $log_note);
     context_complete();
     // -------------
     // 輸出
     return $this->_display_jsonp($output_data, $callback);
 }