/** * Get an instance of the image provider * * @since Version 3.9.1 * @return object */ public function getProvider() { if (!is_null($this->ImageProvider)) { return $this->ImageProvider; } return ImageUtility::CreateImageProvider($this->provider, $this->providerOptions); }
/** * 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; }
/** * Fetch the latest information on an album from the relevant provider * @since Version 3.10.0 * @param array $album * @return void */ public static function ScrapeAlbum($album) { Debug::LogCLI("Scraping album ID " . $album['album_id'] . " from provider " . $album['provider']); set_time_limit(30); $Database = AppCore::GetDatabase(); $Provider = ImageUtility::CreateImageProvider($album['provider']); // Assume Flickr for now, we can update the internal code later $params = ["photoset_id" => $album['album_id']]; $albumdata = $Provider->execute("flickr.photosets.getInfo", $params); // Insert this shit into the database $data = ["scraped" => new Zend_Db_Expr("NOW()"), "meta" => json_encode($albumdata['photoset'])]; $where = ["id = ?" => $album['id']]; $Database->update("image_scrape_album", $data, $where); // Fetch the photos $params['user_id'] = $albumdata['photoset']['owner']; $photos = $Provider->execute("flickr.photosets.getPhotos", $params); foreach ($photos['photoset']['photo'] as $photo) { Debug::LogCLI("Scraping photo ID " . $photo['id']); set_time_limit(10); ImageFactory::CreateImage($photo['id'], $album['provider']); Debug::LogCLI("Sleeping for 2 seconds..."); sleep(2); } }