Example #1
0
 /**
  * Get EXIF data from an image
  * @since Version 3.10.0
  * @param \Railpage\Images\Image $imageObject
  * @param boolean $force
  * @return array
  */
 public function getImageExif(Image $imageObject, $force = false)
 {
     Debug::LogCLI("Fetching EIXF data for image ID " . $imageObject->id);
     if (!$force && isset($imageObject->meta['exif']) && $imageObject->meta['exif_format_version'] >= self::EXIF_FORMAT_VERSION) {
         $imageObject->meta['exif']['camera_make'] = self::normaliseCameraMake($imageObject->meta['exif']['camera_make']);
         $imageObject->meta['exif']['camera_model'] = self::normaliseCameraModel($imageObject->meta['exif']['camera_model']);
         $imageObject->meta['exif']['camera'] = ImageFactory::CreateCamera($imageObject->meta['exif']['camera_id'])->getArray();
         return $imageObject->meta['exif'];
     }
     /**
      * Fetch EXIF from the image provider API
      */
     $Provider = $imageObject->getProvider();
     $exif = $Provider->getExif($imageObject->photo_id);
     $exif_formatted = $this->getExifIDs($exif);
     $imageObject->meta['exif'] = $exif_formatted;
     $imageObject->meta['exif_format_version'] = self::EXIF_FORMAT_VERSION;
     $imageObject->commit();
     /**
      * Insert into our database
      */
     $query = "INSERT INTO image_exif ( \r\n                      image_id, camera_id, lens_id, lens_sn_id,\r\n                      aperture, exposure_id, exposure_program_id, \r\n                      focal_length, iso, white_balance_id\r\n                  ) VALUES (\r\n                      %d, %d, %d, %d, \r\n                      %s, %d, %d, \r\n                      %s, %s, %s\r\n                  ) ON DUPLICATE KEY UPDATE\r\n                      camera_id = VALUES(camera_id), lens_id = VALUES(lens_id),\r\n                      lens_sn_id = VALUES(lens_sn_id), aperture = VALUES(aperture),\r\n                      exposure_id = VALUES(exposure_id), exposure_program_id = VALUES(exposure_program_id),\r\n                      focal_length = VALUES(focal_length), iso = VALUES(iso), \r\n                      white_balance_id = VALUES(white_balance_id)";
     $query = sprintf($query, $this->db->quote($imageObject->id), $this->db->quote($exif_formatted['camera_id']), $this->db->quote($exif_formatted['lens_id']), $this->db->quote($exif_formatted['lens_sn_id']), $this->db->quote($exif_formatted['aperture']), $this->db->quote($exif_formatted['exposure_id']), $this->db->quote($exif_formatted['exposure_program_id']), $this->db->quote($exif_formatted['focal_length']), $this->db->quote($exif_formatted['iso_speed']), $this->db->quote($exif_formatted['white_balance_id']));
     $this->db->query($query);
     return $exif_formatted;
 }
Example #2
0
 /**
  * Update the author for a specific image
  * @since Version 3.10.0
  * @param \Railpage\Images\Image $imageObject
  * @return \Railpage\Images\Image
  */
 public static function updateAuthor(Image $imageObject)
 {
     if ($id = UserUtility::findFromFlickrNSID($imageObject->author->id)) {
         $imageObject->author->railpage_id = $id;
         $imageObject->author->User = UserFactory::CreateUser($imageObject->author->railpage_id);
         $imageObject->commit();
     }
     return $imageObject;
 }
Example #3
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;
 }
Example #4
0
 /**
  * Return a new instance of Image from a data array
  * @since Version 3.9.1
  * @param array $data
  * @return \Railpage\Images\Image
  */
 public static function CreateImageFromArray($data)
 {
     $Image = new Image();
     $Image->populateFromArray($data);
     return $Image;
 }
Example #5
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;
 }
Example #6
0
 /**
  * Set the hero image
  * @since Version 3.9.1
  * @param \Railpage\Images\Image $Image
  * @return \Railpage\Newsletters\Newsletter
  */
 public function setHeroImage(Image $Image)
 {
     $this->content['hero'] = $Image->getArray();
     if (strpos($this->content['hero']['url']['canonical'], ":///") !== false) {
         $this->content['hero']['url']['canonical'] = sprintf("http://www.railpage.com.au/photos/%d", $this->content['hero']['id']);
     }
     $this->content['hero']['url']['canonical'] = Utility\NewsletterUtility::CreateUTMParametersForLink($this, $this->content['hero']['url']['canonical']);
     return $this;
 }
Example #7
0
 /**
  * Suggest locos to tag
  * Ported from \Railpage\Images\Image
  * @since Version 3.10.0
  * @param \Railpage\Images\Image $imageObject
  * @param bool|null $skipTagged
  * @return array
  */
 public static function suggestLocos(Image $imageObject, $skipTagged = null)
 {
     $locolookup = array();
     $locos = array();
     $title = self::getCleanedTitleOrDesc($imageObject->title);
     $desc = self::getCleanedTitleOrDesc($imageObject->description);
     /**
      * Loop through all our possible regexes and search
      */
     $regexes = array("[a-zA-Z0-9\\w+]{4,6}", "[0-9\\w+]{3,5}", "[a-zA-Z0-9\\w+]{2}", "[a-zA-Z0-9\\s\\w+]{4,6}");
     foreach ($regexes as $regex) {
         $regex = "/\\b(" . $regex . ")\\b/";
         preg_match_all($regex, $title, $matches['title']);
         preg_match_all($regex, $desc, $matches['description']);
         if (isset($imageObject->meta['tags']) && count($imageObject->meta['tags'])) {
             foreach ($imageObject->meta['tags'] as $tag) {
                 // strip the tags
                 #$tag = trim(preg_replace($stripetc, "", $tag));
                 $tag = self::getCleanedTitleOrDesc($tag);
                 if (empty($tag)) {
                     continue;
                 }
                 preg_match_all($regex, $tag, $matches[]);
             }
         }
         foreach ($matches as $matched) {
             foreach ($matched as $array) {
                 foreach ($array as $v) {
                     if (empty($v) || !preg_match("/([0-9])/", $v) || preg_match("/(and|to|or|for)/", $v)) {
                         continue;
                     }
                     if (in_array(trim($v), $locolookup)) {
                         continue;
                     }
                     $locolookup[] = trim($v);
                     /*
                     if (!empty( $v ) && preg_match("/([0-9])/", $v) && !preg_match("/(and|to|or|for)/", $v)) {
                         if (!in_array(trim($v), $locolookup)) {
                             $locolookup[] = trim($v);
                         }
                     }
                     */
                 }
             }
         }
     }
     /**
      * Try to include loco numbers with spaces (eg RT 40 vs RT40) in the lookup
      */
     foreach ($locolookup as $num) {
         if (preg_match("/(\\s)/", $num)) {
             preg_match("/([a-zA-Z0-9]+)(\\s)([a-zA-Z0-9]+)/", $num, $matches);
             if (isset($matches[3])) {
                 $prop = sprintf("%s%s", $matches[1], $matches[3]);
                 if (!in_array($prop, $locolookup)) {
                     $locolookup[] = $prop;
                 }
             }
         } elseif (strlen($num) == 5) {
             preg_match("/([a-zA-Z0-9]{2})([0-9]{3})/", $num, $matches);
             if (isset($matches[2])) {
                 $prop = sprintf("%s %s", $matches[1], $matches[2]);
                 if (!in_array($prop, $locolookup)) {
                     $locolookup[] = $prop;
                 }
             }
         }
     }
     $locolookup = array_unique($locolookup);
     /**
      * Prepare the SQL query
      */
     $query = "SELECT l.loco_id, l.loco_num, l.class_id, c.name AS class_name, s.name AS status_name, s.id AS status_id, t.id AS type_id, t.title AS type_name, g.gauge_id, CONCAT(g.gauge_name, ' ', g.gauge_imperial) AS gauge_formatted, o.operator_id, o.operator_name\r\n            FROM loco_unit AS l \r\n                LEFT JOIN loco_class AS c ON l.class_id = c.id \r\n                LEFT JOIN loco_type AS t ON c.loco_type_id = t.id\r\n                LEFT JOIN loco_status AS s ON l.loco_status_id = s.id\r\n                LEFT JOIN loco_gauge AS g ON g.gauge_id = l.loco_gauge_id\r\n                LEFT JOIN operators AS o ON l.operator_id = o.operator_id\r\n            WHERE l.loco_num IN ('" . implode("','", $locolookup) . "') \r\n                AND l.loco_status_id NOT IN (2)";
     /**
      * Remove existing tags from our DB query
      */
     if ($skipTagged === true) {
         $tags = $imageObject->getObjects("railpage.locos.loco");
         if (count($tags)) {
             $ids = array();
             foreach ($tags as $tag) {
                 $ids[] = $tag['namespace_key'];
             }
             $query .= " AND l.loco_id NOT IN (" . implode(",", $ids) . ")";
         }
         $query .= " ORDER BY CHAR_LENGTH(l.loco_num) DESC";
     }
     /**
      * Loop through the DB results
      */
     $i = 0;
     foreach (AppCore::GetDatabase()->fetchAll($query) as $row) {
         $row['object'] = "Railpage\\Locos\\Locomotive";
         $locos[$row['loco_id']] = $row;
         $i++;
         if ($i == 5) {
             break;
         }
     }
     return $locos;
 }