Exemplo n.º 1
0
 /**
  * 以JSONP顯示資料
  * 
  * 不需要變動了
  * @param Array $data 以關聯式陣列組成的回傳資料
  * @param String $callback
  */
 private function _display_jsonp($data, $callback = NULL)
 {
     send_js_header($this->output);
     if (is_null($callback)) {
         return $this->_display_data($data);
     } else {
         $data = kals_json_encode($data);
         $pos = stripos($callback, '=');
         // 取得 = 號的位置
         $callback_hash = $pos === false ? '' : substr($callback, $pos + 1);
         // 擷取 = 後面的字串
         $vars = array('callback_hash' => $callback_hash, 'json' => $data);
         $this->load->view($this->dir . 'display_jsonp', $vars);
     }
 }
Exemplo n.º 2
0
 protected function _display_jsonp($object, $callback = NULL)
 {
     if (is_null($callback)) {
         return $object;
     }
     send_js_header($this->output);
     //test_msg($object['policy']['my_custom']);
     $json = kals_json_encode($object);
     $pos = stripos($callback, '=');
     // 取得 = 號的位置
     $callback_hash = $pos === false ? '' : substr($callback, $pos + 1);
     // 擷取 = 後面的字串
     //echo "{$jsonp}({$json})"; // 輸出
     $vars = array('callback_hash' => $callback_hash, 'json' => $json);
     $this->load->view($this->dir . 'display_jsonp', $vars);
 }
Exemplo n.º 3
0
 function test_msg($title, $msg = NULL)
 {
     if ($title == '----' && is_null($msg)) {
         echo '<br />
             <hr />
             <br />
             ';
         return;
     }
     if (NULL != $title && is_null($msg)) {
         $msg = $title;
         $title = NULL;
     }
     echo '[[[<pre>
         ';
     if ($title != NULL or $msg != NULL) {
         if ($title !== NULL) {
             echo $title . ': ';
         }
         if (is_array($msg)) {
             //print_r($msg);
             //echo test_array($msg);
             echo kals_json_encode($msg);
         } else {
             if (is_object($msg)) {
                 /*
                                 if (defined("JSON_UNESCAPED_UNICODE")) {
                    echo json_encode($msg, JSON_UNESCAPED_UNICODE);
                                 }
                                 else {
                    echo json_encode($msg);
                                 }
                 */
                 echo kals_json_encode($msg);
             } else {
                 echo $msg;
             }
         }
     }
     echo '
         </pre>]]]<br />
         ';
 }
Exemplo n.º 4
0
 function kals_mobile_log($db, $webpage_id, $action, $data = array())
 {
     /* 不使用get_context_webpage()->get_id()來取webpage_id 
        $url = get_referer_url(FALSE);
        $webpage_id = NULL;
        if ($url !== FALSE)
        {
            
            //$CI =& get_instance();
            //if (isset($CI->webpage) == FALSE || is_null($CI->webpage))
            //    $CI->load->library('kals_resource/Webpage');
            //$webpage_id = $CI->webpage->filter_webpage_id($url);
             
            $webpage_id = get_context_webpage()->get_id();
        }*/
     $user_id = NULL;
     $note = NULL;
     if (is_array($data) && (isset($data['user_id']) || isset($data['memo']))) {
         if (isset($data['user_id'])) {
             $user_id = $data['user_id'];
         }
         if (isset($data['memo'])) {
             $note = $data['memo'];
             if (is_array($note) || is_object($note)) {
                 $note = json_encode($note);
             }
             if ($note === '') {
                 $note = NULL;
             }
         }
     } else {
         if (defined("JSON_UNESCAPED_UNICODE")) {
             $note = json_encode($data, JSON_UNESCAPED_UNICODE);
         } else {
             $note = kals_json_encode($data);
         }
     }
     if (is_null($user_id) || $user_id == '') {
         $user = get_context_user();
         if (isset($user)) {
             $user_id = $user->get_id();
         }
         if (is_null($user_id) || $user_id == "") {
             $user_id = NULL;
         }
     }
     $db->insert('log', array('webpage_id' => $webpage_id, 'user_id' => $user_id, 'user_ip' => get_client_ip(), 'action' => $action, 'note' => $note));
 }