Пример #1
0
 /**
  * Parse the Plurk JSON string into an array.
  *
  * @param string $data The array of json data (must be surrounded by '[' 
  * and ']').
  *
  * @return array The array (numeric) array of plurks (an associative 
  * subarray).
  */
 public static function dejsonize($data)
 {
     $data = substr($data, 1, strlen($data));
     $data = substr($data, 0, strlen($data) - 1);
     if (strlen($data) == 0) {
         return array();
     }
     $array_data = array();
     $array_json = explode("}, {", $data);
     foreach ($array_json as &$item) {
         if (substr($item, 0, 1) != '{') {
             $item = '{' . $item;
         }
         if (substr($item, strlen($item) - 1, strlen($item)) != '}') {
             $item = $item . '}';
         }
         $item = preg_replace("/karma': ([\\d\\.]+),/", "karma': '\$1',", $item);
         $item = preg_replace('/new Date\\((.*)\\)/', "\$1", $item);
         $item = preg_replace("/: u'/", ": '", $item);
         $item = preg_replace("/: u\"/", ": \"", $item);
         $item = preg_replace("/L, '/", ", '", $item);
         $item = preg_replace("/datetime\\.date\\((\\d+), (\\d+), (\\d+)\\), '/", "'\$1-\$2-\$3', '", $item);
         $item = preg_replace("/None, '/", "'', '", $item);
         $item = preg_replace("/True, '/", "1, '", $item);
         $item = preg_replace("/False, '/", "0, '", $item);
         $item = preg_replace("/\t/", "'", $item);
         $pattern = array();
         $pattern[0] = "/\\{'/";
         $pattern[1] = "/':/";
         $pattern[2] = "/, '/";
         $pattern[3] = "/: '/";
         $pattern[4] = "/',/";
         $pattern[5] = "/'\\}/";
         $replacement = array();
         $replacement[0] = "{\"";
         $replacement[1] = "\":";
         $replacement[2] = ", \"";
         $replacement[3] = ": \"";
         $replacement[4] = "\",";
         $replacement[5] = "\"}";
         $item = preg_replace($pattern, $replacement, $item);
         $dejsonized = Services_Json_Json_decode($item, true);
         if ($dejsonized == false) {
             echo "Error decoding: [{$item}]\n";
         } else {
             $array_data[] = $dejsonized;
         }
     }
     return $array_data;
 }
Пример #2
0
 /**
  * Retrieve a user's information given a plurk uid.
  * 
  * @param int $int_uid The uid of the plurk member.
  *
  * @return array The associative array of user information.
  */
 function uidToUserinfo($int_uid)
 {
     if (!is_int($int_uid)) {
         return array();
     }
     $this->http_client->get($this->plurk_paths['user_get_info'], array('user_id' => $int_uid));
     $array_profile = $this->http_client->currentResponse();
     if ($array_profile['code'] == 500) {
         return array();
     }
     return Services_Json_Json_decode($array_profile['body'], true);
 }