/** * Echoes a list of members for a given slug in json. */ public function getMembersAction() { $this->getLock($slug = $this->Request->getParameter('slug')); $members = $this->updateMembersToCache($slug, $this->loadMembersFromCache($slug)); $this->releaseLock($slug); echo \JSONUtils::encode($members); }
protected function _failureBulkaction($msg, $element, $slug) { $json = array('Message' => $msg, 'Element' => $element, 'Slug' => $slug); $json = JSONUtils::encode($json); $s = "<script type=\"text/javascript\" language=\"JavaScript\">parent.BulkActionToolbar.updateProgress(false," . $json . ");</script>\n"; echo $s; flush(); usleep(10000); }
/** * Escapes the specified parameter in 'value' for use in json * * Expected Param: * value mixed if is a string, this is what will be converted * index string if specified and value is an array, then value[index] will be converted * * @return string */ public function encode() { if (is_null($this->getParameter('value'))) { return '""'; } $value = $this->getParameter('value'); $index = $this->getParameter('index'); if ($index != null && is_array($value)) { return JSONUtils::encode($value[$index]); } return JSONUtils::encode($value); }
public function removeTag(NodeRef $imageNodeRef, NodeRef $thumbnailFileNodeRef, Tag $tag) { $image = $this->NodeService->getByNodeRef($imageNodeRef, new NodePartials('#thumbnails-json')); $json = $image->getMetaValue('#thumbnails-json'); if ($json == null) { return; } $json = JSONUtils::decode($json); foreach ($json as $i => $thumb) { if ($thumb->value == $tag->TagValue) { array_splice($json, $i, 1); break; } } $this->NodeService->updateMeta($imageNodeRef, '#thumbnails-json', JSONUtils::encode($json)); }
public function apiJson() { $errors = $this->getGlobal('Errors'); //array of FieldValidationError or ValidationError $s = array(); if (empty($errors)) { $s[] = array('Code' => '-1', 'Message' => 'no data'); } else { foreach ($errors as $error) { if ($error instanceof FieldValidationError) { $s[] = array('Code' => $error->getFailureCode(), 'Resolved' => $error->getFieldResolved(), 'Type' => $error->getFieldType(), 'Title' => $error->getFieldTitle(), 'Value' => $error->getValue(), 'Message' => $this->errorCodeResolver->resolveMessageCode($error->getFailureCode(), $error->getFieldResolved(), $error->getFieldType(), array($error->getFieldTitle(), $error->getValue(), $error->getFieldType()), $error->getDefaultErrorMessage())); } else { if ($error instanceof ValidationError) { $s[] = array('Code' => $error->getErrorCode(), 'Message' => $this->errorCodeResolver->resolveMessageCode($error->getErrorCode(), null, null, null, $error->getDefaultErrorMessage())); } } } } return JSONUtils::encode($s); }
/** * populates #thumbnails-json for the node * * @param NodeRef $nodeRef * @return void */ public function syncJsonThumbnails(NodeRef $nodeRef) { $node = $this->NodeService->getByNodeRef($nodeRef, new NodePartials(null, '#thumbnails.fields', null)); /* @var Node $node */ $tags = $node->getOutTags('#thumbnails'); $thumbs = array(); foreach ($tags as $tag) { /* @var Tag $tag */ $thumb = new stdClass(); $thumb->value = $tag->TagValue; $thumb->url = $tag->TagLinkNode->jump('#url'); $thumb->size = intval($tag->TagLinkNode->jump('#size')); $thumb->height = intval($tag->TagLinkNode->jump('#height')); $thumb->width = intval($tag->TagLinkNode->jump('#width')); $thumbs[] = $thumb; } $this->NodeService->updateMeta($node->NodeRef, '#thumbnails-json', JSONUtils::encode($thumbs)); }
protected function storeDeploymentCache($aggregatePath, $cacheArray) { FileSystemUtils::safeFilePutContents($aggregatePath, JSONUtils::encode($cacheArray, true)); }
public static function encodeFlat($obj, $pretty = false, $html = false) { return JSONUtils::encode(ArrayUtils::flattenObjects($obj), $pretty, $html); }
/** * Returns debugging information about all passed parameters * * @return string */ public function debug() { return '<pre>' . JSONUtils::encode($this->getParameters(), true, false) . '</pre>'; }
/** * Writes a standard JSON error response. * * @param array $errors The error info - $errors[]['code'], $errors[]['message'] */ protected function sendErrors($errors) { $response = new stdClass(); $response->Errors = array(); foreach ($errors as $error) { $e = new stdClass(); $e->Code = $error['code']; $e->Message = $error['message']; $response->Errors[] = $e; } $this->Response->sendStatus(Response::SC_BAD_REQUEST); // convert to JSON & write out die(JSONUtils::encode($response)); }
/** * populates the #thumbnails-json meta on media nodes * * Parameters: * interval - # of nodes to process per pass, defaults to 25 * limit - # of nodes to process per run, defaults to 0 (all) * offset - starting offset, defaults to 0 * * @return void */ public function syncJsonThumbnails() { $interval = $this->Request->getParameter('interval') or $interval = 25; $nodeLimit = $this->Request->getParameter('limit') or $nodeLimit = 0; $offset = $this->Request->getParameter('offset') or $offset = 0; $nq = new NodeQuery(); $nq->setParameter('Elements.in', '@images'); $nq->setParameter('OutTags.select', '#thumbnails.fields'); $nq->setOrderBy('ActiveDate', 'DESC'); $nq->setLimit($interval); $nq->setOffset($offset); $nq = $this->NodeService->findAll($nq, true); $nodes = $nq->getResults(); $processedNodes = 0; while (count($nodes) > 0) { foreach ($nodes as $node) { /* @var Node $node */ $tags = $node->getOutTags('#thumbnails'); $thumbs = array(); foreach ($tags as $tag) { /* @var Tag $tag */ $thumb = new stdClass(); $thumb->value = $tag->TagValue; $thumb->url = $tag->TagLinkNode->jump('#url'); $thumb->size = intval($tag->TagLinkNode->jump('#size')); $thumb->height = intval($tag->TagLinkNode->jump('#height')); $thumb->width = intval($tag->TagLinkNode->jump('#width')); $thumbs[] = $thumb; } $this->NodeService->updateMeta($node->NodeRef, '#thumbnails-json', JSONUtils::encode($thumbs)); echo $node->Slug . "\n"; } $this->TransactionManager->commit()->begin(); $processedNodes += count($nodes); if ($nodeLimit > 0 && $processedNodes >= $nodeLimit) { break; } $offset = $offset + $interval; unset($nodes); $nq->setLimit($interval); $nq->setOffset($offset); $nq->clearResults(); $nq = $this->NodeService->findAll($nq, true); $nodes = $nq->getResults(); } }
/** * Encodes the current records (from the locals array) into a JSON object. * * Expected Params: * keys string A single string or a list of comma-separated strings representing the keys to encode * from the locals array. If this param is not provided a default list of well-known keys is used. * * @return string */ public function jsonEncode() { $keys = $this->getEncodeKeys(); return JSONUtils::encode(ArrayUtils::flattenObjectsUsingKeys($this->locals, $keys)); }
protected function datewidget() { extract($attributes = array_merge(array('id' => '', 'width' => 'quarter', 'edit_perms' => null, 'view_perms' => null, 'node_edit_perms' => null, 'node_view_perms' => null), $this->_attributes())); $this->attributes = $attributes; if (empty($id)) { throw new Exception('Missing id attribute on datewidget'); } if (substr($id, 0, 1) != '#') { throw new Exception('The id attribute must be a valid role beginning with #'); } if (!$this->__hasPermission($view_perms) || !$this->__hasNodePermission($node_view_perms)) { return; } $id = ltrim($id, '#'); $schemafield = $this->schema->getMetaDef($id); $vArray = $schemafield->Validation->getValidationArray(); if (!empty($vArray['dateonly']) && $vArray['dateonly'] == 'true') { $attributes['dateOnly'] = true; } $uid = $this->_generateUniqueID($id); $fullid = "#{$id}"; $fulluid = "#{$uid}"; $this->xhtml[] = " <li class=\"input-{$width}-width field {$this->_fieldClasses($schemafield)}\">"; $this->xhtml[] = " <label for=\"{$uid}\">{$schemafield->Title}</label>"; if ($this->__hasPermission($edit_perms) && $this->__hasNodePermission($node_edit_perms)) { $this->xhtml[] = " <div id=\"{$uid}-holder\">"; $this->xhtml[] = " <input id=\"{$uid}\" type=\"text\" value=\"{% filter date?value=Data:{$fullid}&format=Y-m-d H:i:s %}\" name=\"{$fulluid}\" class=\"datewidget\"/>"; $this->xhtml[] = " </div>"; $this->xhtml[] = " <script type=\"text/javascript\">"; $this->xhtml[] = " new DateWidget('{$uid}', '{% filter date?value=Data:{$fullid}&format=Y-m-d %}', '{% filter date?value=Data:{$fullid}&format=g:i A %}', " . JSONUtils::encode($attributes) . ");"; $this->xhtml[] = " </script>"; } else { $this->xhtml[] = " <div><p class=\"read-only\">{% filter date?value=Data:{$fullid}&format=Y-m-d %}</p></div>"; } }
/** @see http://swfupload.org/forum/generaldiscussion/1717 */ public function postHandleQuickAdd(Transport $transport) { if (!$this->triggered) { return; } $controls = $this->RequestContext->getControls(); if ((stripos($this->Request->getUserAgent(), 'Flash') !== FALSE || stripos($this->Request->getServerAttribute('HTTP_X_REQUESTED_WITH'), 'XMLHttpRequest') !== FALSE) && $controls->getControl('action') == 'node-quick-add') { $arr = JSONUtils::decode($transport->Content, true); if (!isset($arr['Cheaters'])) { return; } $newarr = array(); //COPY NON-TAG FIELDS foreach (array('Slug', 'Title', 'Status', 'Element', 'RecordLink') as $key) { $newarr[$key] = $arr[$key]; } //COPY ORIGINAL FILE TAG DATA $newarr['#original'] = array('url' => $arr['Cheaters']['#original']['TagLinkNode']['Metas']['url']['MetaValue'], 'width' => $arr['Cheaters']['#original']['TagLinkNode']['Metas']['width']['MetaValue'], 'height' => $arr['Cheaters']['#original']['TagLinkNode']['Metas']['height']['MetaValue']); //COPY THUMBNAIL FILE TAG DATA $newarr['#thumbnails'] = array(); $thumbs = $arr['Cheaters']['#thumbnails']; if (isset($thumbs['TagDirection'])) { $thumbs = array($thumbs); } foreach ($thumbs as $thumb) { $newarr['#thumbnails'][] = array('value' => $thumb['TagValue'], 'url' => $thumb['TagLinkNode']['Metas']['url']['MetaValue'], 'width' => $thumb['TagLinkNode']['Metas']['width']['MetaValue'], 'height' => $thumb['TagLinkNode']['Metas']['height']['MetaValue']); } //ADD FORMAT SO TAG WIDGET CLASS CAN INTERPRET $newarr['Format'] = 'media/compact'; $transport->Content = JSONUtils::encode($newarr); } }
protected function noresultsResponse() { $handler = $this->RequestContext->getControls()->getControl('view_handler'); switch ($handler) { case 'xml': $s .= '<?xml version="1.0"?> <API> <TotalRecords>0</TotalRecords> <Nodes /> </API>'; return $s; case 'json': default: $s = array('TotalRecords' => 0, 'Nodes' => array()); return JSONUtils::encode($s); } }
public function tagWidgetScript() { /* * Assemble chunks of js for each tag */ $widgetInstantiations = ''; $tagUpdateEvents = ''; $domChangeEvents = array('Out' => '', 'In' => ''); foreach ($this->tagWidgets as $tagArr) { extract($tagArr); $optionsJson = JSONUtils::encode($options); $directionLc = strtolower($direction); // // $widgetInstantiations .= <<<EOT document.{$id}FilterPartial = new TagPartial('{$partial}'); new NodeTagWidget( document.tempRecord, document.{$id}FilterPartial, '#{$id}-filter', {$optionsJson} ); EOT; // // $tagUpdateEvents .= <<<EOT if ( typeof this.get{$direction}Tags( document.{$id}FilterPartial )[0] != 'undefined') { tags.{$direction}.push(this.get{$direction}Tags( document.{$id}FilterPartial)[0].toString()); } EOT; // // $domChangeEvents[$direction] .= <<<EOT document.tempRecord.removeTags('{$directionLc}', document.{$id}FilterPartial); EOT; } /* * Assemble chunks of js for each tag direction */ $tagsInitializeArray = array(); $fireFilter = ''; $domChangeFunctions = ''; $onloadTriggers = ''; foreach ($this->directions as $direction) { $tagsInitializeArray[] = "'{$direction}' : []"; $directionLc = strtolower($direction); // // $fireFilter .= <<<EOT List.filter(\$('#{$direction}TagsFilter'), '{$direction}Tags.exist', tags.{$direction}.join(',')); EOT; // // $domChangeFunctions .= <<<EOT \$('#{$direction}TagsFilter').bind('init', function() { document.tempRecord.init{$direction}Mode = true; var tags = \$(this).val(); {$domChangeEvents[$direction]} if(tags != '') { tags = tags.split(','); \$(tags).each(function(i,tag){ document.tempRecord.add{$direction}Tag( new Tag(new TagPartial(tag)) ); }); } document.tempRecord.init{$direction}Mode = false; }); EOT; // // $onloadTriggers .= <<<EOT \$('#{$direction}TagsFilter').trigger('init'); EOT; } // each direction $tagsInitialize = implode(',', $tagsInitializeArray); /* * Return script tag */ return <<<EOT <script language="JavaScript" type="text/javascript"> document.tempRecord = new NodeObject({}); {$widgetInstantiations} document.tempRecord.bind(Taggable.EVENTS.TAGS_UPDATED,function(){ if(document.tempRecord.init{$direction}Mode) return; var tags = { {$tagsInitialize} }; {$tagUpdateEvents} {$fireFilter} }); {$domChangeFunctions} \$(document).ready(function() { document.tempRecord.init{$direction}Mode = true; // this need to be tur to persist intags document.tempRecord.init(); {$onloadTriggers} }); </script> EOT; }
/** * @dataProvider getTestTypes * * @param array $phpArray * @param string $json * @param string $pretty */ public function testCompareTypes(array $phpArray, $json, $pretty) { $this->assertJsonStringEqualsJsonString(\JSONUtils::encode($phpArray), $json); $this->assertJsonStringEqualsJsonString(\JSONUtils::encode($phpArray, true), $pretty); $this->assertJsonStringEqualsJsonString(\JSONUtils::format($json), $pretty); }