public function showThumbnails() { $json = $this->getParameter('value'); if (empty($json)) { return ''; } $json = JSONUtils::decode($json); $thumbs = $this->getParameter('thumbnails'); $tlist = array(); if (!empty($thumbs)) { $tlist = explode(',', $thumbs); } $xmod = StringUtils::strToBool($this->getParameter('xmod')); $markup = ''; if ($xmod) { foreach ($json as $thumb) { if (!empty($list) && in_array($thumb->value, $tlist) || empty($tlist)) { $markup .= '<image id="' . $thumb->url . '" width="full"/>'; } } } else { $markup .= '<ul class="thumbnail-list">'; foreach ($json as $thumb) { if (!empty($tlist) && in_array($thumb->value, $tlist) || empty($tlist)) { $markup .= '<li><p><img src="' . $thumb->url . '" alt="' . $this->getLocal('Title') . '" /></p><p><strong>Size:</strong> ' . $thumb->value . '</p></li>'; } } $markup .= '</ul>'; } return $markup; }
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)); }
/** @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 getDeploymentCache($aggregatePath) { return JSONUtils::decode(file_get_contents($aggregatePath), true); }
/** * Fetch the contents of a URL as a JSON array * * @param string $url Fully-qualified URL to request * @param bool $followRedirects If true, follow redirects to default max of 5 * @param string $username Username to use in http authentication header * @param string $password Password to use in http authentication header * @param array $headers Array of http headers to append to the existing headers list * * @return array PHP array version of JSON contents * @throws HttpRequestException If contents cannot be fetched */ public function fetchJSON($url, $followRedirects = true, $username = null, $password = null, $headers = array()) { $contents = $this->fetchURL($url, $followRedirects, $username, $password, $headers); return JSONUtils::decode($contents, true); }
/** * Build Node JSON structure with thumbnail information. */ protected function _buildNodeJSON(Node $node, $includeOriginal = false, $includeThumbnails = false) { $data = new stdClass(); $data->slug = $node->Slug; $data->element = $node->Element->Slug; $data->title = $node->Title; $data->status = $node->Status; $data->activeDate = $node->ActiveDate; $data->recordLink = $node->RecordLink; $data->sortOrder = $node->SortOrder; if ($includeOriginal) { $nodeRef = $node->getNodeRef(); if ($nodeRef->getElement()->hasAspect('images') || $nodeRef->getElement()->hasAspect('temporary-zipped-media')) { // Build the original and thumbnail info as well foreach (array('url', 'size', 'width', 'height') as $f) { $data->{$f} = $node->jump("#original.#{$f}"); if (is_numeric($data->{$f})) { $data->{$f} = intval($data->{$f}); } } } else { // Include the URL for non image media $data->url = $node->jump("#original.#url"); } } $json = $node->getMetaValue('#thumbnails-json'); if ($json != null) { $thumbnails = JSONUtils::decode($json); if ($includeThumbnails) { $data->thumbnails = $thumbnails; $data->thumbnailsPending = (array) $this->_getPendingThumbnails($node->getElement()->getSlug(), $thumbnails); } foreach ($thumbnails as $thmb) { if ($thmb->value == $this->imagesThumbnailCmsSize) { $data->thumbnailUrl = $thmb->url; break; } } } return $data; }
protected function _importPhotosFromJson($file) { try { $contents = file_get_contents($file); $json = JSONUtils::decode($contents); foreach ($json as $v) { echo "importing {$v->title}..."; $url = $v->src; $parts = parse_url($url); $slug = SlugUtils::createSlug(basename($parts['path'])); preg_match('/(\\.\\w*)$/', $parts['path'], $ext); $nodeRef = $this->NodeRefService->oneFromAspect('@images'); $nodeRef = $this->NodeRefService->generateNodeRef($nodeRef, $slug); $node = $nodeRef->generateNode(); if (!$this->NodeService->refExists($node->getNodeRef())) { // go fetch file from url $data = $this->HttpRequest->fetchURL($url); // create a unique output file name $sourceFile = FileSystemUtils::secureTmpname($this->workDir, 'urlfetch', !empty($ext[1]) ? strtolower($ext[1]) : null); file_put_contents($sourceFile, $data); $node->Title = rtrim($v->title); $node->Status = "published"; $node->ActiveDate = $this->DateFactory->newStorageDate(); $node = $this->ImageService->storeMedia($sourceFile, $node, basename($parts['path'])); $this->NodeService->add($node); echo "done\n"; } else { echo "exists\n"; } unset($nodeRef); unset($node); } } catch (Exception $e) { echo "Exception: " . $e->getMessage() . "\n"; } }
/** * @dataProvider getInvalidJsons * @expectedException \JSONException * * @param string $string */ public function testDecodeBadJsonString($string) { $rst = \JSONUtils::decode($string); }