Beispiel #1
0
    function index($json, $callback)
    {
        //echo $callback."({result: 'ok'})";
        //$json = json_encode($json); // 利用 PHP(5) 內建的 json_encode 將資料轉成 json 格式
        //echo urldecode($json).'<br />';
        $ary = null;
        $ary = json_to_object($json);
        //$ary = json_decode($json);
        $data = array('foo' => $ary->value, 'bar' => 'ABCDEFG', 'baz' => array(52, 97));
        $json = '{
  "foo": "The quick brown fox jumps over the lazy dog.",
  "bar": "ABCDEFG",
  "baz": [52, 97]
}';
        display_jsonp($callback, $data);
        //
        //        //$pos = stripos($_SERVER['QUERY_STRING'], '='); // 取得 = 號的位置
        //        $pos = stripos($a, '='); // 取得 = 號的位置
        //        //$jsonp = ($pos === false) ?  '' : substr($_SERVER['QUERY_STRING'], $pos+1);  // 擷取 = 後面的字串
        //        $jsonp = ($pos === false) ?  '' : substr($a, $pos+1);  // 擷取 = 後面的字串
        //        echo "{$jsonp}({$json})"; // 輸出
        /*
                ?>{
          "foo": "The quick brown fox jumps over the lazy dog.",
          "bar": "ABCDEFG",
          "baz": [52, 97]
        }<?php
        */
    }
Beispiel #2
0
 /**
  * 實際建立log的方法
  * @param String $json
  * @return type
  */
 private function _create_log($json)
 {
     if ($json === FALSE) {
         return FALSE;
     }
     //$this->output->enable_profiler(TRUE);
     //print_r($_POST);
     /*
             if (!isset($_POST["json"])) {
        $data = false;
        //$this->_display_jsonp($data, $callback);
        echo "aaaaaaaaaaaaaaaaaaaaa";
        return;
             }
             
             $json = $_POST["json"];
     */
     $data = json_to_object($json);
     //取得參考網址資料跟位於session的user
     //$url = $this->url;
     $user = $this->user;
     //取得來自$json的範圍資料
     $action = $data->action;
     $note = $data->note;
     //$t = "\u6578\u4f4d\u5716\u66f8\u9928\u6982\u8aaa";
     //test_msg(kals_json_encode($note));
     kals_log($this->db, $action, $note);
     context_complete();
     set_ignore_authorize(false);
     $data = true;
     //$this->_display_jsonp($data, $callback);
     return $data;
 }
Beispiel #3
0
 public function delete($json, $callback = NULL)
 {
     $annotation_id = json_to_object($json);
     if (is_null($annotation_id)) {
         $data = FALSE;
         return $this->_display_jsonp($data, $callback);
     }
     //set_ignore_authorize(true);
     $annotation = new Annotation($annotation_id);
     $this->_delete_annotation($annotation);
     set_ignore_authorize(true);
     context_complete();
     $data = true;
     return $this->_display_jsonp($data, $callback);
 }
Beispiel #4
0
 public function register($json, $callback)
 {
     $data = json_to_object($json);
     //test_msg('authentication.register before find_user');
     $user = $this->user->find_user($this->url, $data->email);
     //test_msg('authentication.register after find_user');
     //$output = NULL;
     //$output['login'] = FALSE;
     $output = $this->_create_default_data();
     //$action = 8;
     $action = "register.success";
     $user_id = NULL;
     if (isset($user) && $user->has_password() === FALSE) {
         //handle_error('user_already_exist');
         $output['error'] = 'user_already_existed';
         //$action = 9;
         $action = "register.fail";
     } else {
         $user = $this->user->create_user($this->url, $data->email);
         $user->set_password($data->password);
         //test_msg('auth.regiester after create_user', $user->get_id());
         $user->update();
         //test_msg('auth.regiester after update password', $user->get_id());
         $output = $this->_parse_user_output($user, FALSE);
         //test_msg('auth.regiester after _parse_user_output', $output['user']);
         $user_id = $user->get_id();
     }
     kals_log($this->db, $action, array('user_id' => $user_id));
     context_complete();
     $this->_display_jsonp($output, $callback);
 }
Beispiel #5
0
 public function like($json, $callback)
 {
     $data = json_to_object($json);
     $annotation_id = $data->annotation_id;
     $annotation = new Annotation($annotation_id);
     $is_like = $data->is_like;
     $user = $this->user;
     if (is_null($annotation_id) || is_null($is_like) || is_null($user) || $annotation->get_user()->equals($user)) {
         $data = show_error('Permission deny.');
         return $this->_display_jsonp($data, $callback);
     }
     //test_msg("before like", $annotation->get_like_count());
     set_ignore_authorize(true);
     if ($is_like === TRUE) {
         $annotation->add_like($user);
     } else {
         $annotation->remove_like($user);
     }
     //test_msg("after like", $annotation->get_like_count());
     //計算分數吧
     $this->_setup_scores($annotation);
     //log區
     $array_data = $annotation_id;
     $action = 22;
     if ($is_like == FALSE) {
         $action = 23;
     }
     $user_id = NULL;
     if (isset($user)) {
         $user_id = $user->get_id();
     }
     kals_log($this->db, $action, array('memo' => $array_data, 'user_id' => $user_id));
     //$annotation->update();
     context_complete();
     set_ignore_authorize(false);
     $data = TRUE;
     return $this->_display_jsonp($data, $callback);
 }
Beispiel #6
0
 /**
  * context所需資訊
  * @param String $json
  * @param String $callback
  */
 function info($json, $callback = NULL)
 {
     if (is_null($callback)) {
         $callback = $json;
         $json = NULL;
     }
     //分析json
     if (isset($json)) {
         $input_data = json_to_object($json);
         if (isset($input_data->anchor_navigation_type)) {
             $type = $input_data->anchor_navigation_type;
             $GLOBALS['context']->set_anchor_navigation_type($type);
         }
     }
     $data = array();
     $data['KALS_language'] = $this->_load_lang();
     $data['Window_profile'] = array('sex' => array(0, 1, 2), 'locale' => array('zh_tw', 'en_us'));
     require_once 'authentication.php';
     $authentication = new authentication();
     $data['KALS_authentication'] = $authentication->default_data();
     //$data['KALS_view_manager'] = $this->_load_viewes();
     // 20140517 Pulipuli Chen
     //$data['webpage_id'] = get_context_webpage()->get_id();
     /**
      * @author Pulipuli Chen <*****@*****.**> 20150117
      * 不,不能這樣做
      * 要把navigation data拆開來之後再做快取
      * 快取網址要搭配 webpage_id 跟 user_id
      */
     //$this->output->cache($this->config->item('output.cache.info.expiration'));
     $this->_display_jsonp($data, $callback);
 }
Beispiel #7
0
 public function update_profile($json, $callback)
 {
     $data = json_to_object($json);
     $user = get_context_user();
     $output = FALSE;
     if (isset($user)) {
         $user->set_name($data->name);
         $user->set_locale($data->locale);
         $user->set_sex($data->sex);
         $user->update();
         kals_log($this->db, 10, array('user_id' => $user->get_id(), 'memo' => array('name' => $data->name, 'locale' => $data->locale, 'sex' => $data->sex)));
         context_complete();
         $output = TRUE;
     }
     $this->_display_jsonp($output, $callback);
 }
Beispiel #8
0
 /**
  * 搜尋標註
  * @param string $json
  * @param type $callback
  * @return type
  */
 function search_annotation($json, $callback = NULL)
 {
     /**
      * @author Pulipuli Chen 20141111
      * 測試很長時間才回應搜尋結果用的
      */
     //sleep(3);
     /**
      * 檢查SQL用
      * @author Pulipuli Chen <*****@*****.**> 20141114
      */
     //$enable_profiler = true;
     $enable_profiler = false;
     if ($enable_profiler == TRUE) {
         $this->output->enable_profiler(TRUE);
     }
     if (is_string($json)) {
         $data = json_to_object($json);
         //把js丟過來的資料(search)包成物件data,內含
         // search_range,keyword,新增order_by
         //test_msg($json);
         //test_msg($data);
     } else {
         $data = $json;
     }
     $reuqest_scope_collection = isset($data->limit) && isset($data->offset) === false;
     //$reuqest_scope_collection = true;
     //test_msg("reuqest_scope_collection", array($reuqest_scope_collection)  );
     //        $user = get_context_user();
     $url = $this->url;
     //存放目前data來源的頁面連結
     //        $search = new Search_annotation_collection($url); //Search_annotation_collection→Search_engine
     $search = new Search_annotation_collection();
     //Search_annotation_collection→Search_engine
     if ($reuqest_scope_collection) {
         $search_all = new Search_annotation_collection();
     }
     /**
      * 限定搜尋範圍只在來源的網頁
      */
     $search->set_target_referer_webpage();
     if ($reuqest_scope_collection) {
         $search_all->set_target_referer_webpage();
     }
     //test_msg("輸入資料", $json);
     //$data->search_range = "annotation_anchor"; //測試用
     if (isset($data->query_field) === FALSE) {
         $data->query_field = "note";
     }
     switch ($data->query_field) {
         case "annotation_user_name":
             //示範用
             //$search->set_target_user(new User(1701));
             $search->set_search_user_name($data->query_value);
             if ($reuqest_scope_collection) {
                 $search_all->set_search_user_name($data->query_value);
             }
             break;
         case "note":
             //標註內容
             if ($data->query_value != "" && $data->query_value != "*") {
                 $search->set_search_note($data->query_value);
                 if ($reuqest_scope_collection) {
                     $search_all->set_search_note($data->query_value);
                 }
             }
             break;
         case "annotation_type":
             //標註類型
             if ($data->query_value !== "custom") {
                 $search->set_target_type($data->query_value);
                 if ($reuqest_scope_collection) {
                     $search_all->set_target_type($data->query_value);
                 }
             } else {
                 $exclude_type_list = $data->exclude_type_list;
                 $search->set_exclude_type_list($exclude_type_list);
                 if ($reuqest_scope_collection) {
                     $search_all->set_exclude_type_list($exclude_type_list);
                 }
             }
             break;
         case "annotation_anchor_text":
             $search->set_search_anchor_text($data->query_value);
             if ($reuqest_scope_collection) {
                 $search_all->set_search_anchor_text($data->query_value);
             }
             break;
     }
     // 6 [ order by ] 設定排序方式(order_by_id,大小|小大 )-data內要有order_by的選項
     //test_msg('6 [ order by ]', isset($data->order_by));
     //order_by的typ類型e在Search_order_collection
     if (isset($data->order_by) === FALSE) {
         $data->order_by = "update";
     }
     //test_msg($data->order_by);
     if ($data->order_by == 'update') {
         $search->add_order(6, TRUE);
     } else {
         if ($data->order_by == 'create') {
             $search->add_order(7);
         } else {
             if ($data->order_by == 'responded') {
                 $search->add_order(4);
                 $search->set_target_topic(true);
             } else {
                 if ($data->order_by == 'liked') {
                     $search->add_order(3);
                 } else {
                     if ($data->order_by == 'scope') {
                         $search->add_order(2);
                     } else {
                         $search->add_order(2, TRUE);
                     }
                 }
             }
         }
     }
     //
     //        if (isset($data->order_by) === FALSE OR $data->order_by != 'update')
     //        {
     //            $search->add_order (6, TRUE);
     //            if (isset($search_id)) {
     //                $search_id->add_order (6, TRUE);
     //            }
     //        }
     //輸出
     $totally_loaded = TRUE;
     if (isset($data->limit)) {
         $totally_loaded = FALSE;
     }
     // -------------------------------------------------------
     // 7 [ offset ]
     //test_msg('7 [ offset ]', isset($data->offset));
     if (isset($data->offset)) {
         $search->set_offset($data->offset);
     }
     // 8 [ limit ]
     //test_msg('8 [ limit ]', array(isset($data->limit),$data->limit));
     if (isset($data->limit)) {
         //test_msg("設定限制 limit", $data->limit);
         $search->set_limit($data->limit);
         //$search_id在此不作設限
     }
     // ------------------------------------------
     //不作limit的情況下讀完,表示完全讀取
     if (isset($data->limit) && ($reuqest_scope_collection && $search->length() == $search_all->length() || $search->length() === 0)) {
         $totally_loaded = TRUE;
     }
     //test_msg('Search Length', $search->length());
     //test_msg($url);
     //test_msg($this->webpage->filter_webpage_id($url));
     $annotation_collection = array();
     foreach ($search as $search_annotation) {
         $annotation_data = $search_annotation->export_webpage_data($url);
         //把Data export到目前的頁面上
         array_push($annotation_collection, $annotation_data);
     }
     // $search_annotation = new Annotation(783);
     // $annotation_data = $search_annotation->export_webpage_data($url); //把Data export到目前的頁面上
     // array_push($annotation_collection, $annotation_data);
     // --------------
     // --------------
     $output_data = array('annotation_collection' => $annotation_collection, 'totally_loaded' => $totally_loaded);
     /**
      * 取得搜尋結果的位置
      */
     if ($reuqest_scope_collection) {
         $scope_collection = $search_all->get_result_scope_coll();
         $scope_collection_json = $scope_collection->export_webpage_data(get_context_webpage());
         $output_data['scope_collection'] = $scope_collection_json;
     }
     if ($reuqest_scope_collection && isset($data->show_total_count) && $data->show_total_count === TRUE) {
         if ($reuqest_scope_collection) {
             $output_data['total_count'] = $search_all->length();
         } else {
             if (count($annotation_collection) === 0) {
                 $output_data['total_count'] = 0;
             } else {
                 $output_data['total_count'] = count($annotation_collection);
             }
         }
     }
     //log區
     $action = 30;
     switch ($data->query_field) {
         case "annotation_user_name":
             $action = 31;
             break;
         case "annotation_type":
             //標註類型
             $action = 32;
             break;
         case "annotation_anchor_text":
             $action = 33;
             break;
     }
     if ($data->query_field == "note" && $data->query_value == "*" && $data->order_by == "update") {
         // 搜尋最新標註
         $action = 34;
     }
     $log_message = array("query_value" => $data->query_value, "order_by" => $data->order_by);
     if (isset($output_data['total_count'])) {
         $log_message['total_count'] = $output_data['total_count'];
     }
     kals_log($this->db, $action, $log_message);
     context_complete();
     if ($enable_profiler != TRUE) {
         return $this->_display_jsonp($output_data, $callback);
     }
 }