function json_decode($arg, $is_array = true) { global $services_json; if (!isset($services_json)) { $services_json = new Services_JSON(); } return $is_array ? get_object_vars($services_json->decode($arg)) : $services_json->decode($arg); }
static function loginTeacher($class, $pass, $ignoreNonexistent = false) { $json = new Services_JSON(); if (!$class) { return "クラス名を入力してください。"; } if (!$pass) { return "パスワードを入力してください。"; } if (!file_exists("fs/home/{$class}") && !$ignoreNonexistent) { return "存在しないクラスIDが入力されています。"; } if (preg_match('/^[a-zA-Z0-9\\-_]+$/', $pass)) { $fp = fopen("user/list.txt", "r"); while ($line = fgets($fp)) { $classlist = $json->decode($line); if ($classlist["classid"] == $class) { break; } } fclose($fp); if (isset($classlist) && $classlist["pass"] == $pass) { // Success MySession::set("class", $class); MySession::set("user", self::TEACHER); setcookie("class", $class, time() + 60 * 60 * 24 * 30); return true; } else { return "クラスIDかパスワードが間違っています。"; } } else { return "パスワードは半角英数とハイフン、アンダースコアだけが使えます。"; } }
/** * Smarty {json} plugin * * Type: function * Name: json * Purpose: fetch json file and assign result as a template variable (array) * @param url (url to fetch) * @param assign (element to assign to) * @return array|null if the assign parameter is passed, Smarty assigns the * result to a template variable */ function smarty_function_json($params, &$smarty) { if (empty($params['url'])) { $smarty->_trigger_fatal_error("[json] parameter 'url' cannot be empty"); return; } $content = array(); $data = file_get_contents($params['url']); if (empty($data)) { return false; } if (!is_callable('json_decode')) { require_once 'JSON.php'; $json = new Services_JSON(); $content = $json->decode(trim(file_get_contents($params['url']))); } else { $content = json_decode(trim(file_get_contents($params['url']))); } if ($params['debug'] === true) { echo "<pre>"; print_r($content); echo "</pre>"; } if (!empty($params['assign'])) { $smarty->assign($params['assign'], $content); } else { return $content; } }
public function __construct($result, $httpStatusCode, $request) { if (function_exists('json_decode')) { $this->body = json_decode($result, true); } else { require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php'; $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $this->body = $json->decode($result); } $this->httpStatusCode = $httpStatusCode; // If there is an error we want to build out an error string. if ($this->httpStatusCode !== 200) { $this->error = $this->body['error']; $this->errorMessage = $this->error . ': ' . $this->body['description']; if (array_key_exists('issues', $this->body)) { $this->errorIssues = $this->body['issues']; foreach ($this->errorIssues as &$issue) { $this->errorMessage .= array_search($issue, $this->errorIssues) . ': ' . $issue; } unset($issue); } } if (array_key_exists('request', $this->body)) { $this->request = $this->body['request']; } else { $this->request = null; } $this->request = $request; $this->result = $result; }
function get_tree_html($jsontree) { $this->EE->output->enable_profiler(FALSE); $cpurl = $this->EE->config->item('cp_url'); $pieces = explode("/", $cpurl); $cpurl_index = $pieces[count($pieces) - 1]; $jsontree = str_replace("'", '"', (string) $jsontree); $jsontree = $this->my_strip_tags($jsontree); //$jsontree = str_replace('EDIT', '', $jsontree); $jsontree = str_replace('DELETE', '', $jsontree); $jsontree = str_replace(' ', '', $jsontree); $json = new Services_JSON(); $json_decoded = $json->decode($jsontree); $navhtml = ''; foreach ($json_decoded as $item) { $id = isset($item->id) ? $item->id : ''; $className = isset($item->className) ? $item->className : ''; $navhtml .= '<li class="' . $className . '" id="' . $id . '" ><a href="' . $item->url . '" class="first_level">' . str_replace("http://", "", str_replace($_SERVER['HTTP_HOST'], "", str_replace('"', '\\"', $item->title))) . '</a>'; $navhtml .= $this->get_tree_ul($item); $navhtml .= '</li>'; } $navhtml = str_replace('[IMG]', '<img src="', $navhtml); $navhtml = str_replace('[/IMG]', '"/>', $navhtml); return $navhtml; }
function diffapplydiff($base, $diff) { if (function_exists('json_encode')) { $diffs = json_decode($diff); } else { require_once "JSON.php"; $jsonser = new Services_JSON(); return $jsonser->decode($diff); } for ($i = count($diffs) - 1; $i >= 0; $i--) { if ($diffs[$i][0] == 2) { //replace array_splice($base, $diffs[$i][1], $diffs[$i][2], $diffs[$i][3]); } else { if ($diffs[$i][0] == 0) { //insert array_splice($base, $diffs[$i][1], 0, $diffs[$i][2]); } else { if ($diffs[$i][0] == 1) { //delete array_splice($base, $diffs[$i][1], $diffs[$i][2]); } } } } return $base; }
function display($persona) { $json = new Services_JSON(); $persona->get_configuration_data(); $properties =& PersonaProperty::load_persona_properties($persona->persona_id); $propertyCount = count($properties); // echo "<pre>" . print_r($persona, true) . "</pre>"; if (!$propertyCount) { echo "No status info available"; } else { foreach ($properties as $k => $property) { if ($property->name == 'Status') { $content = $json->decode($property->content); if ($content->friendly) { echo $content->friendly; echo '<br />'; echo 'Last fetch on: ' . date("H:i D jS M", strtotime($content->date)); } else { echo "No status info available"; } /* echo '<!-- ' . "\n"; echo print_r($property, true) . "\n"; echo print_r($content, true) . "\n"; echo ' -->'; */ } } } }
function json($file) { global $fs, $word, $around; $j = new Services_JSON(); $a = explode("T", $word); $date = preg_replace("/-/", "/", $a[0]); $time = $a[1]; echo "{$time} --- {$date}<BR>"; $lines = explode("\n", $fs->getContent("{$file}-data.log")); $a = array(); $around = $around / 10; $found = false; foreach ($lines as $line) { $e = $j->decode($line); if ($e) { $a[] = toHTML($e); //echo $e["date"]." ".$e["time"]. "<BR>"; if ($found) { if (count($a) > $around * 2) { break; } } else { if (count($a) > $around) { array_shift($a); } if ($e["date"] == $date && $e["time"] == $time) { array_push($a, "<a name='center'/><font color=red>-----------------------------------</font><BR>"); $found = TRUE; } } } } print join("<BR>", $a); }
public function __construct($result, $httpStatusCode, $request) { $this->body = null; $this->apiStatus = null; $this->apiErrorMessage = null; if (function_exists('json_decode')) { $this->body = json_decode($result, true); } else { require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php'; $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $this->body = $json->decode($result); } $this->httpStatusCode = $httpStatusCode; $this->request = $request; $this->rawResponse = $result; // Only attempt to get our response body if the http status code expects a body if (!in_array($this->httpStatusCode, array(204, 304))) { $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $this->body = $json->decode($result); // NOTE: Responses from /v3 endpoints don't contain status or error_message. if (array_key_exists('status', $this->body)) { $this->apiStatus = intval($this->body['status']); } if (array_key_exists('error_message', $this->body)) { $this->apiErrorMessage = $this->body['error_message']; } } }
/** * Load les infos depuis une string JSON * * @access public * @param string $json La string JSON * @return TafelTree Le TafelTree créé */ public function loadJSON($json, $id, $imgs = 'imgs/', $width = '100%', $height = 'auto', $options = array()) { $tree = new TafelTree($id, $imgs, $width, $height, $options); $service = new Services_JSON(); $tree->items = TafelTree::loadServiceJSON($service->decode($json)); return $tree; }
function make_short_url($restURL) { $out = "GET " . $restURL . " HTTP/1.1\r\n"; $out .= "Host: api.bit.ly\r\n"; $out .= "Content-type: application/x-www-form-urlencoded\r\n"; $out .= "Connection: Close\r\n\r\n"; $handle = @fsockopen('api.bit.ly', 80, $errno, $errstr, 30); fwrite($handle, $out); $body = false; $contents = ''; while (!feof($handle)) { $return = fgets($handle, 1024); if ($body) { $contents .= $return; } if ($return == "\r\n") { $body = true; } } fclose($handle); $json = new Services_JSON(); $data = $json->decode($contents); //for issues with unable to authenticate error, somehow they return errors instead of error. if (!isset($data->status_code)) { return false; } if ($data->status_code != '200') { return false; } return $data->data->url; }
function getFiltersFor($msg, $id = null) { $json = new Services_JSON(); if ($id !== null) { $this->id = $id; } $this->find(); $res = array(); while ($this->fetch()) { $fltrs = $json->decode($this->filter); // Serach for "from" and "subject" foreach ($fltrs as $f) { $from = !isset($f->from) || trim($f->from) == ""; $subj = !isset($f->subject) || trim($f->subject) == ""; if ($from && $subj) { continue; } if (!$from) { $from = strpos($msg->from, $f->from) !== false; } if (!$subj) { $subj = strpos($msg->subject, $f->subject) !== false; } if ($from && $subj) { $res[] = $this->toArray(); break; } } } return $res; }
function decode($str) { //$lib='native'; // $lib='services_JSON'; // $lib='jsonrpc'; // dirty trick to correct bad json for photos //$str = preg_replace('/\t} {/','}, {', $str); // remove trailing , //$str = preg_replace('/,[ \r\n\t]+}/',' }', $str); // echo "Using $lib<BR>"; // echo $str; if (function_exists('json_decode') && JSON_LIB_DECODE == 'native') { $arr = json_decode($str, true); } else { if (JSON_LIB_DECODE == 'services_JSON') { require_once dirname(__FILE__) . '/json.php'; $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $arr = $json->decode($str); } else { if (JSON_LIB_DECODE == 'jsonrpc') { require_once dirname(__FILE__) . '/jsonrpc/xmlrpc.php'; require_once dirname(__FILE__) . '/jsonrpc/jsonrpc.php'; $GLOBALS['xmlrpc_internalencoding'] = 'UTF-8'; //require_once dirname(__FILE__).'/jsonrpc/json_extension_api.php'; //$arr=json_decode($str, true); $value = php_jsonrpc_decode_json($str); if ($value) { $arr = php_jsonrpc_decode($value, array()); } } } } // print_r($arr); return $arr; }
/** * Transforma el texto enviado en formato JSON a un objeto PHP * * @param string $html texto JSON a decodear * @return object objeto PHP */ public function decode($html) { // include_once("classes/JSON.class.php"); $json = new Services_JSON(); $data = stripslashes($html); return $json->decode($data); }
function json_decode($jsonString) { static $jsonobj; if (!isset($jsonobj)) { include_once (IA_ROOT . '/source/library/json/JSON.php'); $jsonobj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); } return $jsonobj->decode($jsonString); }
/** * @param $targetUrl * @return unknown_type */ function query($targetUrl) { $requestUrl = "http://api.postrank.com/v1/postrank?appkey=" . $this->appKey . '&format=json'; $resp = $this->getUrl($requestUrl, 'url[]=' . $targetUrl . '&'); $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $data = $json->decode($resp); return $data; }
function json_decode($value) { if (!class_exists('Services_JSON', false)) { include 'Services_JSON.php'; } $inst = new Services_JSON(); return $inst->decode($value); }
function json_decode($arg) { global $services_json; if (!isset($services_json)) { $services_json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); } return $services_json->decode($arg); }
static function decode($data) { if (function_exists('json_decode')) { return json_decode($data); } $json = new Services_JSON(); return $json->decode($data); }
/** * Decode JSON string into PHP data. * * @param string JSON-encoded data. * @return mixed PHP data. */ public static function decode($data, $asHash = true) { if (function_exists('json_decode')) { return json_decode($data, $asHash); } else { return Services_JSON::decode($data); } }
function delq($params) { $json = new Services_JSON(); $item = DB_DataObject::factory("item"); $item->whereAdd("id IN (" . implode(",", $json->decode($params["ids"])) . ")"); $res = $item->delete(DB_DATAOBJECT_WHEREADD_ONLY); print $json->encode(array("error" => !$res)); }
public function _use($path) { $scr = $this->fs->getContent($path); $j = new Services_JSON(); $vmc = $j->decode($scr); $root = $this->root; return Dtl::run($root, $vmc); }
/** * Uses _call to get a response and JSON decodes it. * * @param (str) URL to hit, without the protocol (e.g. no http://) * @param (array) (optional) Arguments to send. * @param (str) (optional) HTTP transfer type ('POST' or 'GET'). Defaults to GET. * @param (str) (optional) Username for basic authentication. * @param (str) (optional) Password for basic authentication. * @param (str) (optional) Referer URL. * * @return Decoded JSON result of cURL call. * @author Aral Balkan **/ function _jsonCall($url, $args = NULL, $type = 'GET', $user = NULL, $pass = NULL, $referer = NULL) { $response = $this->_call($url, $args, $type, $user, $pass, $referer); // Decode the returned JSON value $j = new Services_JSON(); $response = $j->decode($response); return $response; }
function test_json_encode_decode() { require_once ABSPATH . WPINC . '/class-json.php'; $json = new Services_JSON(); // Super basic test to verify Services_JSON is intact and working. $this->assertEquals('["foo"]', $json->encodeUnsafe(array('foo'))); $this->assertEquals(array('foo'), $json->decode('["foo"]')); }
function json_decode($arg) { global $services_json; if (!isset($services_json)) { $services_json = new Services_JSON(); } return $services_json->decode($arg); }
function json_decode($data = null) { $json = new Services_JSON(); if ($data == null) { return false; } return $json->decode($data); }
function json_decode($R6157E037F7BEFDE0C4AA5FE57C53D296) { global $RD1E8304B4C9A69B93907A71DE55AD040; if (!isset($RD1E8304B4C9A69B93907A71DE55AD040)) { $RD1E8304B4C9A69B93907A71DE55AD040 = new Services_JSON(); } return $RD1E8304B4C9A69B93907A71DE55AD040->decode($R6157E037F7BEFDE0C4AA5FE57C53D296); }
function internal_parse_json($json) { if (version_compare(PHP_VERSION, "5.2.0", ">=")) { return json_decode($json, true); } include_once 'JSON.php'; $json_parser = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); return $json_parser->decode($json); }
public function getBlogImages($theme) { require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'json.php'; $file = EBLOG_THEMES . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'image.ini'; $contents = JFile::read($file); $json = new Services_JSON(); $sizes = $json->decode($contents); return $sizes; }
public static function FromJSON($json) { if (function_exists('json_decode')) { return json_decode($json); } else { $jsonConverter = new Services_JSON(); return $jsonConverter->decode($json); } }