Esempio n. 1
0
 /**
  * Find an image by provider and provider image ID
  * @since Version 3.8.7
  * @param string $provider
  * @param int $id
  * @throws \Exception if $provider is null
  * @throws \Exception if $photo_id is null
  */
 public function findImage($provider = NULL, $photo_id = NULL)
 {
     if (is_null($provider)) {
         throw new Exception("Cannot lookup image from image provider - no provider given (hint: Flickr, WestonLangford)");
     }
     if (!filter_var($photo_id, FILTER_VALIDATE_INT) || $photo_id === 0) {
         throw new Exception("Cannot lookup image from image provider - no provider image ID given");
     }
     if ($id = $this->db->fetchOne("SELECT id FROM image WHERE provider = ? AND photo_id = ?", array($provider, $photo_id))) {
         if (filter_var($id, FILTER_VALIDATE_INT)) {
             return new Image($id);
         }
     }
     $Image = new Image();
     $Image->provider = $provider;
     $Image->photo_id = $photo_id;
     $Image->populate();
     return $Image;
 }
Esempio n. 2
0
 /**
  * Find an image by provider and provider image ID
  * @since Version 3.8.7
  * @param string $provider
  * @param int $photoId
  * @param mixed $option
  * @throws \Exception if $provider is null
  * @throws \Exception if $photoId is null
  * @param int $option
  */
 public function findImage($provider = null, $photoId = null, $option = null)
 {
     if (is_null($provider)) {
         throw new Exception("Cannot lookup image from image provider - no provider given (hint: Flickr, WestonLangford)");
     }
     if (!preg_match("/([a-zA-Z0-9]+)/", $photoId) || $photoId === 0) {
         throw new Exception("Cannot lookup image from image provider - no provider image ID given");
     }
     $mckey = sprintf("railpage:image;provider=%s;id=%s", $provider, $photoId);
     if (defined("NOREDIS") && NOREDIS == true || $option != self::OPT_REFRESH && !($id = $this->Redis->fetch($mckey))) {
         Debug::LogCLI("Found photo ID " . $photoId . " in database");
         $id = $this->db->fetchOne("SELECT id FROM image WHERE provider = ? AND photo_id = ?", array($provider, $photoId));
         $this->Redis->save($mckey, $id, strtotime("+1 month"));
     }
     if (isset($id) && filter_var($id, FILTER_VALIDATE_INT)) {
         return new Image($id, $option);
     }
     Debug::LogCLI("Photo ID " . $photoId . " not found in local cache");
     $Image = new Image();
     $Image->provider = $provider;
     $Image->photo_id = $photoId;
     $Image->populate(true, $option);
     return $Image;
 }