/** * Generate the JSON data string * * @return $this */ public function getJSON() { if (isset($this->author)) { $author = clone $this->author; if (isset($author->User) && $author->User instanceof User) { $author->User = $author->User->getArray(); } } $data = array("id" => $this->id, "title" => $this->title, "description" => $this->description, "score" => $this->getScore(), "provider" => array("name" => $this->provider, "photo_id" => $this->photo_id), "sizes" => Images::NormaliseSizes($this->sizes), "srcset" => implode(", ", Utility\ImageUtility::generateSrcSet($this)), "author" => isset($author) ? $author : false, "url" => $this->url instanceof Url ? $this->url->getURLs() : array(), "dates" => array()); $times = ["posted", "taken"]; #printArray($this->meta['dates']);die; foreach ($times as $time) { if (isset($this->meta['dates'][$time])) { $Date = filter_var($this->meta['dates'][$time], FILTER_VALIDATE_INT) ? new DateTime("@" . $this->meta['dates'][$time]) : new DateTime($this->meta['dates'][$time]); $data['dates'][$time] = array("absolute" => $Date->format("Y-m-d H:i:s"), "nice" => $Date->Format("d H:i:s") == "01 00:00:00" ? $Date->Format("F Y") : $Date->format("F j, Y, g:i a"), "relative" => ContentUtility::RelativeTime($Date)); } } if ($this->Place instanceof Place) { $data['place'] = array("url" => $this->Place->url, "lat" => $this->Place->lat, "lon" => $this->Place->lon, "name" => $this->Place->name, "country" => array("code" => $this->Place->Country->code, "name" => $this->Place->Country->name, "url" => $this->Place->Country->url)); } $this->json = json_encode($data); return $this; }