public function encode($data = self::UNDEFINED, $meta = self::UNDEFINED) { if ($data !== self::UNDEFINED) { $this->setOrigin($data); } if ($meta !== self::UNDEFINED) { $this->setMeta($meta); } $graph = array(); if ($this->_origin !== self::UNDEFINED) { $graph['origin'] = $this->_encodeVariable($this->_origin); } if ($this->_instances) { foreach ($this->_instances as $key => $value) { $graph['instances'][$key] = $value[1]; } } if ($this->getOption('includeLanguageMeta')) { if (!$this->_meta) { $this->_meta = array(); } if (!isset($this->_meta['lang.id'])) { $this->_meta['lang.id'] = 'registry.pinf.org/cadorn.org/github/renderers/packages/php/master'; } } // remove encoder options $meta = array(); foreach ($this->_meta as $name => $value) { if (!($name == "encoder" || substr($name, 0, 8) == "encoder.")) { $meta[$name] = $value; } } return array(Insight_Util::json_encode($graph), $meta ? $meta : false); }
public function encode($data = self::UNDEFINED, $meta = self::UNDEFINED) { if ($data !== self::UNDEFINED) { $this->setOrigin($data); } if ($meta !== self::UNDEFINED) { $this->setMeta($meta); } $graph = array(); if ($this->_origin !== self::UNDEFINED) { $graph = $this->_origin; } // remove encoder options foreach ($this->_meta as $name => $value) { if ($name == "encoder" || substr($name, 0, 8) == "encoder.") { unset($this->_meta[$name]); } } return array(Insight_Util::json_encode($graph), $this->_meta ? $this->_meta : false); }
public function respond($server, $request) { if ($request->getAction() == 'ToggleFilter') { $this->_loadFilters(); $key = $request->getArgument('key'); if (isset($this->filters[$key])) { if ($request->hasArgument('enabled')) { $this->filters[$key]['enabled'] = $request->getArgument('enabled'); } else { $this->filters[$key]['enabled'] = !$this->filters[$key]['enabled']; } } if (!$this->defaultFilters) { $this->defaultFilters[$key] = array(); } $this->defaultFilters[$key]['enabled'] = $this->filters[$key]['enabled']; $request->storeInClientCache('filters', $this->defaultFilters); $request->storeInClientUrlCache('filters', $this->filters); return array('type' => 'text/plain', 'data' => Insight_Util::json_encode(array('filters' => $this->filters))); } return false; }
public function send($data, $meta = array(), $receiver = false) { if ($receiver) { $this->setReceiverID($receiver); } list($data, $meta) = $this->getEncoder(isset($meta['encoder']) ? $meta['encoder'] : 'Default')->encode($data, $meta); if ($meta) { // remove helper options foreach ($meta as $name => $value) { if (substr($name, 0, 1) == ".") { unset($meta[$name]); } } } return $this->sendRaw($data, $meta ? Insight_Util::json_encode($meta) : ''); }
public function listen() { if (Insight_Util::getRequestHeader('x-insight') == 'serve' || isset($_GET['x-insight']) && $_GET['x-insight'] == 'serve') { // we can respond } else { return false; } // try { $response = false; if (isset($_POST['payload'])) { $payload = $_POST['payload']; if (get_magic_quotes_gpc()) { $payload = stripslashes($payload); } try { $response = $this->respond(Insight_Util::json_decode($payload)); } catch (Exception $e) { $response = array('type' => 'error', 'status' => 500); } } else { if (sizeof($_GET) > 0) { // TODO: Implement fetching via GET } } if (!$response) { header("HTTP/1.0 204 No Content"); header("Status: 204 No Content"); } else { if (is_string($response)) { echo $response; } else { switch ($response['type']) { case 'error': header("HTTP/1.0 " . $response['status']); header("Status: " . $response['status']); break; case 'json': header("Content-Type: application/json"); echo Insight_Util::json_encode($response['data']); break; default: echo $response['data']; break; } } } /* } catch(Exception $e) { throw $e; header("HTTP/1.0 500 Internal Server Error"); header("Status: 500 Internal Server Error"); echo($e->getMessage()); // TODO: Log error to insight client } */ return true; }
/** * Store in cache for client key + url */ public function storeInClientUrlCache($name, $object, $encode = true) { file_put_contents($this->cachePathForName($name, 'clienturl'), $encode ? Insight_Util::json_encode($object) : $object); }