src/libraries/models/Photo.php
/**
    * Uploads a new photo to the remote file system and database.
    *
    * @param string $localFile The local file system path to the photo.
    * @param string $name The file name of the photo.
    * @param array $attributes The attributes to save
    * @return mixed string on success, false on failure
    */
Uploads a new photo to the remote file system and database.
@param string $localFile The local file system path to the photo.
@param string $name The file name of the photo.
@param array $attributes The attributes to save
@return mixed string on success, false on failure
Uploads a new photo to the remote file system and database . @param string $localFile The local file system path to the photo . @param string $name The file name of the photo . @param array $attributes The attributes to save @return mixed string on success false on failure
public function upload($localFile, $name, $attributes = array())
  {
    if(!$this->utility->isValidMimeType($localFile))
    {
      $this->logger->warn(sprintf('Invalid mime type for %s', $localFile));
      return false;
    }
    $id = $this->user->getNextId('photo');
    if($id === false)
    {
      $this->logger->crit('Could not fetch next photo ID');
      return false;
    }
    $tagObj = new Tag;
    $filenameOriginal = $name;
    $attributes = $this->whitelistParams($attributes);
    $resp = $this->createAndStoreBaseAndOriginal($name, $localFile);
    $paths = $resp['paths'];
    if($resp['status'])
    {
      $this->logger->info("Photo ({$id}) successfully stored on the file system");
      $exif = $this->readExif($localFile);
      $iptc = $this->readIptc($localFile);
      $defaults = array('title', 'description', 'tags', 'latitude', 'longitude');
      foreach($iptc as $iptckey => $iptcval)
      {
        if(empty($iptcval))
          continue;
        if($iptckey == 'tags')
        {
          $iptcval = implode(',', $iptcval);
        }
        $attributes[$iptckey] = $iptcval;
      }
      foreach($defaults as $default)
      {
        if(!isset($attributes[$default]))
          $attributes[$default] = null;
      }
      if(isset($attributes['dateUploaded']) && !empty($attributes['dateUploaded']))
        $dateUploaded = $attributes['dateUploaded'];
      else
        $dateUploaded = time();
      if(isset($attributes['dateTaken']) && !empty($attributes['dateTaken']))
        $dateTaken = $attributes['dateTaken'];
      else
        $dateTaken = @$exif['dateTaken'];
      if($this->config->photos->autoTagWithDate == 1)
      {
        $dateTags = sprintf('%s,%s', date('F', $dateTaken), date('Y', $dateTaken));
        if(!isset($attributes['tags']) || empty($attributes['tags']))
          $attributes['tags'] = $dateTags;
        else
          $attributes['tags'] .= ",{$dateTags}";
      }
      if(isset($exif['latitude']))
        $attributes['latitude'] = floatval($exif['latitude']);
      if(isset($exif['longitude']))
        $attributes['longitude'] = floatval($exif['longitude']);
      if(isset($attributes['tags']) && !empty($attributes['tags']))
      {
        $attributes['tags'] = $tagObj->sanitizeTagsAsString($attributes['tags']);
      }
      $attributes = array_merge(
        $this->getDefaultAttributes(),
        array(
          'hash' => sha1_file($localFile), 
          'size' => intval(filesize($localFile)/1024),
          'exifCameraMake' => @$exif['cameraMake'],
          'exifCameraModel' => @$exif['cameraModel'],
          'exifFNumber' => @$exif['FNumber'],
          'exifExposureTime' => @$exif['exposureTime'],
          'exifISOSpeed' => @$exif['ISO'],
          'exifFocalLength' => @$exif['focalLength'],
          'filenameOriginal' => $filenameOriginal,
          'width' => @$exif['width'],
          'height' => @$exif['height'],
          'dateTaken' => $dateTaken,
          'dateTakenDay' => date('d', $dateTaken),
          'dateTakenMonth' => date('m', $dateTaken),
          'dateTakenYear' => date('Y', $dateTaken),
          'dateUploaded' => $dateUploaded,
          'dateUploadedDay' => date('d', $dateUploaded),
          'dateUploadedMonth' => date('m', $dateUploaded),
          'dateUploadedYear' => date('Y', $dateUploaded),
          'pathOriginal' => $paths['pathOriginal'],
          'pathBase' => $paths['pathBase']
        ),
        $attributes
      );
      $stored = $this->db->putPhoto($id, $attributes);
      unlink($localFile);
      unlink($resp['localFileCopy']);
      if($stored)
      {
        if(isset($attributes['tags']) && !empty($attributes['tags']))
          $tagObj->updateTagCounts(array(), (array)explode(',', $attributes['tags']), $attributes['permission'], $attributes['permission']);
        $this->logger->info("Photo ({$id}) successfully stored to the database");
        return $id;
      }
      else
      {
        $this->logger->warn("Photo ({$id}) could NOT be stored to the database");
        return false;
      }
    }
    $this->logger->warn("Photo ({$id}) could NOT be stored to the file system");
    return false;
  }
public function upload ( $ localFile , $ name , $ attributes = array ( ) ) { if ( ! $ this -> utility -> isValidMimeType ( $ localFile ) ) { $ this -> logger -> warn ( sprintf ( 'Invalid mime type for %s' , $ localFile ) ) ; return false ; } $ id = $ this -> user -> getNextId ( 'photo' ) ; if ( $ id === false ) { $ this -> logger -> crit ( 'Could not fetch next photo ID' ) ; return false ; } $ tagObj = new Tag ; $ filenameOriginal = $ name ; $ attributes = $ this -> whitelistParams ( $ attributes ) ; $ resp = $ this -> createAndStoreBaseAndOriginal ( $ name , $ localFile ) ; $ paths = $ resp [ 'paths' ] ; if ( $ resp [ 'status' ] ) { $ this -> logger -> info ( " Photo ( { $ id } ) successfully stored on the file system " ) ; $ exif = $ this -> readExif ( $ localFile ) ; $ iptc = $ this -> readIptc ( $ localFile ) ; $ defaults = array ( 'title' , 'description' , 'tags' , 'latitude' , 'longitude' ) ; foreach ( $ iptc as $ iptckey => $ iptcval ) { if ( empty ( $ iptcval ) ) continue ; if ( $ iptckey == 'tags' ) { $ iptcval = implode ( ',' , $ iptcval ) ; } $ attributes [ $ iptckey ] = $ iptcval ; } foreach ( $ defaults as $ default ) { if ( ! isset ( $ attributes [ $ default ] ) ) $ attributes [ $ default ] = null ; } if ( isset ( $ attributes [ 'dateUploaded' ] ) && ! empty ( $ attributes [ 'dateUploaded' ] ) ) $ dateUploaded = $ attributes [ 'dateUploaded' ] ; else $ dateUploaded = time ( ) ; if ( isset ( $ attributes [ 'dateTaken' ] ) && ! empty ( $ attributes [ 'dateTaken' ] ) ) $ dateTaken = $ attributes [ 'dateTaken' ] ; else $ dateTaken = @ $ exif [ 'dateTaken' ] ; if ( $ this -> config -> photos -> autoTagWithDate == 1 ) { $ dateTags = sprintf ( '%s,%s' , date ( 'F' , $ dateTaken ) , date ( 'Y' , $ dateTaken ) ) ; if ( ! isset ( $ attributes [ 'tags' ] ) || empty ( $ attributes [ 'tags' ] ) ) $ attributes [ 'tags' ] = $ dateTags ; else $ attributes [ 'tags' ] .= " , { $ dateTags } " ; } if ( isset ( $ exif [ 'latitude' ] ) ) $ attributes [ 'latitude' ] = floatval ( $ exif [ 'latitude' ] ) ; if ( isset ( $ exif [ 'longitude' ] ) ) $ attributes [ 'longitude' ] = floatval ( $ exif [ 'longitude' ] ) ; if ( isset ( $ attributes [ 'tags' ] ) && ! empty ( $ attributes [ 'tags' ] ) ) { $ attributes [ 'tags' ] = $ tagObj -> sanitizeTagsAsString ( $ attributes [ 'tags' ] ) ; } $ attributes = array_merge ( $ this -> getDefaultAttributes ( ) , array ( 'hash' => sha1_file ( $ localFile ) , 'size' => intval ( filesize ( $ localFile ) / 1024 ) , 'exifCameraMake' => @ $ exif [ 'cameraMake' ] , 'exifCameraModel' => @ $ exif [ 'cameraModel' ] , 'exifFNumber' => @ $ exif [ 'FNumber' ] , 'exifExposureTime' => @ $ exif [ 'exposureTime' ] , 'exifISOSpeed' => @ $ exif [ 'ISO' ] , 'exifFocalLength' => @ $ exif [ 'focalLength' ] , 'filenameOriginal' => $ filenameOriginal , 'width' => @ $ exif [ 'width' ] , 'height' => @ $ exif [ 'height' ] , 'dateTaken' => $ dateTaken , 'dateTakenDay' => date ( 'd' , $ dateTaken ) , 'dateTakenMonth' => date ( 'm' , $ dateTaken ) , 'dateTakenYear' => date ( 'Y' , $ dateTaken ) , 'dateUploaded' => $ dateUploaded , 'dateUploadedDay' => date ( 'd' , $ dateUploaded ) , 'dateUploadedMonth' => date ( 'm' , $ dateUploaded ) , 'dateUploadedYear' => date ( 'Y' , $ dateUploaded ) , 'pathOriginal' => $ paths [ 'pathOriginal' ] , 'pathBase' => $ paths [ 'pathBase' ] ) , $ attributes ) ; $ stored = $ this -> db -> putPhoto ( $ id , $ attributes ) ; unlink ( $ localFile ) ; unlink ( $ resp [ 'localFileCopy' ] ) ; if ( $ stored ) { if ( isset ( $ attributes [ 'tags' ] ) && ! empty ( $ attributes [ 'tags' ] ) ) $ tagObj -> updateTagCounts ( array ( ) , ( array ) explode ( ',' , $ attributes [ 'tags' ] ) , $ attributes [ 'permission' ] , $ attributes [ 'permission' ] ) ; $ this -> logger -> info ( " Photo ( { $ id } ) successfully stored to the database " ) ; return $ id ; } else { $ this -> logger -> warn ( " Photo ( { $ id } ) could NOT be stored to the database " ) ; return false ; } } $ this -> logger -> warn ( " Photo ( { $ id } ) could NOT be stored to the file system " ) ; return false ; }
Uploads a new photo to the remote file system and database.
Uploads a new photo to the remote file system and database .
// check if file type is valid // fallback if not in $attributes