src/libraries/controllers/ApiPhotoController.php
/**
    * Retrieve a photo from the remote datasource.
    *
    * @param string $id ID of the photo to be viewed.
    * @return string Standard JSON envelope
    */
Retrieve a photo from the remote datasource.
@param string $id ID of the photo to be viewed.
@return string Standard JSON envelope
Retrieve a photo from the remote datasource . @param string $id ID of the photo to be viewed . @return string Standard JSON envelope
public function view($id)
  {
    $db = getDb();
    $getActions = isset($_GET['actions']) && $_GET['actions'] == 'true';
    if($getActions)
      $photo = $db->getPhotoWithActions($id);
    else
      $photo = $db->getPhoto($id);
    if(!isset($photo['id']))
    {
      return $this->notFound("Photo {$id} not found", false);
    }
    elseif(!$this->user->isOwner())
    {
      if($photo['permission'] == 0)
      {
        if(!$this->user->isLoggedIn() || (isset($photo['groups']) && empty($photo['groups'])))
          return $this->notFound("Photo {$id} not found", false);
        $userGroups = $db->getGroups($this->user->getEmailAddress());
        $isInGroup = false;
        foreach($userGroups as $group)
        {
          if(in_array($group['id'], $photo['groups']))
          {
            $isInGroup = true;
            break;;
          }
        }
        if(!$isInGroup)
          return $this->notFound("Photo {$id} not found", false);
      }
    }
    $sizes = array();
    if(isset($_GET['returnSizes']))
    {
      $sizes = (array)explode(',', $_GET['returnSizes']);
    }
    $photo = $this->pruneSizes($photo, $sizes);
    if(!empty($sizes))
    {
      $protocol = $this->utility->getProtocol(false);
      if(isset($_GET['protocol']))
        $protocol = $_GET['protocol'];
      $generate = $requery = false;
      if(isset($_GET['generate']) && $_GET['generate'] == 'true')
        $generate = true;
      foreach($sizes as $size)
      {
        $options = $this->photo->generateFragmentReverse($size);
        if($generate && !isset($photo["path{$size}"]))
        {
          $hash = $this->photo->generateHash($id, $options['width'], $options['height'], $options['options']);
          $this->photo->generate($id, $hash, $options['width'], $options['width'], $options['options']);
          $requery = true;
        }
      }
      if($requery)
      {
        if($getActions)
          $photo = $db->getPhotoWithActions($id);
        else
          $photo = $db->getPhoto($id);
        $photo = $this->pruneSizes($photo, $sizes);
      }
    }
    $photo = $this->photo->addApiUrls($photo, $sizes);
    return $this->success("Photo {$id}", $photo);
  }
public function view ( $ id ) { $ db = getDb ( ) ; $ getActions = isset ( $ _GET [ 'actions' ] ) && $ _GET [ 'actions' ] == 'true' ; if ( $ getActions ) $ photo = $ db -> getPhotoWithActions ( $ id ) ; else $ photo = $ db -> getPhoto ( $ id ) ; if ( ! isset ( $ photo [ 'id' ] ) ) { return $ this -> notFound ( " Photo  { $ id }  not found " , false ) ; } elseif ( ! $ this -> user -> isOwner ( ) ) { if ( $ photo [ 'permission' ] == 0 ) { if ( ! $ this -> user -> isLoggedIn ( ) || ( isset ( $ photo [ 'groups' ] ) && empty ( $ photo [ 'groups' ] ) ) ) return $ this -> notFound ( " Photo  { $ id }  not found " , false ) ; $ userGroups = $ db -> getGroups ( $ this -> user -> getEmailAddress ( ) ) ; $ isInGroup = false ; foreach ( $ userGroups as $ group ) { if ( in_array ( $ group [ 'id' ] , $ photo [ 'groups' ] ) ) { $ isInGroup = true ; break ; ; } } if ( ! $ isInGroup ) return $ this -> notFound ( " Photo  { $ id }  not found " , false ) ; } } $ sizes = array ( ) ; if ( isset ( $ _GET [ 'returnSizes' ] ) ) { $ sizes = ( array ) explode ( ',' , $ _GET [ 'returnSizes' ] ) ; } $ photo = $ this -> pruneSizes ( $ photo , $ sizes ) ; if ( ! empty ( $ sizes ) ) { $ protocol = $ this -> utility -> getProtocol ( false ) ; if ( isset ( $ _GET [ 'protocol' ] ) ) $ protocol = $ _GET [ 'protocol' ] ; $ generate = $ requery = false ; if ( isset ( $ _GET [ 'generate' ] ) && $ _GET [ 'generate' ] == 'true' ) $ generate = true ; foreach ( $ sizes as $ size ) { $ options = $ this -> photo -> generateFragmentReverse ( $ size ) ; if ( $ generate && ! isset ( $ photo [ " path { $ size } " ] ) ) { $ hash = $ this -> photo -> generateHash ( $ id , $ options [ 'width' ] , $ options [ 'height' ] , $ options [ 'options' ] ) ; $ this -> photo -> generate ( $ id , $ hash , $ options [ 'width' ] , $ options [ 'width' ] , $ options [ 'options' ] ) ; $ requery = true ; } } if ( $ requery ) { if ( $ getActions ) $ photo = $ db -> getPhotoWithActions ( $ id ) ; else $ photo = $ db -> getPhoto ( $ id ) ; $ photo = $ this -> pruneSizes ( $ photo , $ sizes ) ; } } $ photo = $ this -> photo -> addApiUrls ( $ photo , $ sizes ) ; return $ this -> success ( " Photo  { $ id } " , $ photo ) ; }
Retrieve a photo from the remote datasource.
Retrieve a photo from the remote datasource .
// check permissions // can't call API since we're not the owner // if specific sizes are requested then make sure we return them // requery to get generated paths