Пример #1
0
 /**
  * Parse the avatar file in $tempPath,
  * by creating small square image from it,
  * save into file system and then add path to new avatar
  * in User object as 'avatar' element
  *
  *
  * @param User $User
  * @param unknown_type $tempPath
  * @throws \Lampcms\Exception
  *
  * @return bool false if unable to parse image | true if added image
  */
 public static function addIcon(Clientdata $o, $tempPath)
 {
     d('$tempPath: ' . $tempPath);
     $size = 72;
     $avatarDir = LAMPCMS_DATA_DIR . 'img' . DIRECTORY_SEPARATOR . 'avatar' . DIRECTORY_SEPARATOR . 'sqr' . DIRECTORY_SEPARATOR;
     d('$avatarDir: ' . $avatarDir);
     $savePath = Path::prepare($o['_id'], $avatarDir);
     d('$savePath: ' . $savePath);
     /**
      * Create avatar and save it
      * with compression level of 80% (small compression)
      */
     try {
         $ImgParser = \Lampcms\Image\Editor::factory($o->getRegistry())->loadImage($tempPath)->makeSquare($size);
         $savePath .= $ImgParser->getExtension();
         $ImgParser->save($avatarDir . $savePath, null, 80);
         d('avatar saved to ' . $savePath);
     } catch (\Lampcms\ImageException $e) {
         e('ImageException caught in: ' . $e->getFile() . ' on line: ' . $e->getLine() . ' error: ' . $e->getMessage());
         return false;
     }
     /**
      * Now remove tempPath file
      */
     @\unlink($tempPath);
     /**
      * Now add the path to avatar
      * to Clientdata object
      * save() is not invoked on Clientdata object here!
      * Either rely on auto-save  or call save()
      * from a function that invoked this method
      */
     $o['icon'] = $savePath;
     return true;
 }
Пример #2
0
 /**
  * Instanticate $this->oApi object
  * it will either contain empty values
  * in case this is new registration
  * or will have values from previous
  * application
  *
  * @return object $this
  */
 protected function setApi()
 {
     $appid = $this->Request->get('app_id', 'i', null);
     $this->oApi = Clientdata::factory($this->Registry);
     if ($appid) {
         $a = $this->Registry->Mongo->API_CLIENTS->findOne(array('_id' => $appid, 'i_uid' => $this->Registry->Viewer->getUid()));
         if (!empty($a)) {
             $this->oApi->reload($a);
         } else {
             d('not found by id ' . $appid);
         }
     }
     return $this;
 }
Пример #3
0
 /**
  * Instantiates $this->oApi object
  * it will either contain empty values
  * in case this is new registration
  * or will have values from previous
  * application
  *
  * @return object $this
  */
 protected function setApi()
 {
     $appid = $this->Router->getSegment(1, 'i', 0);
     $this->oApi = Clientdata::factory($this->Registry);
     if (!empty($appid)) {
         $a = $this->Registry->Mongo->API_CLIENTS->findOne(array('_id' => $appid, 'i_uid' => $this->Registry->Viewer->getUid()));
         if (!empty($a)) {
             $this->oApi->reload($a);
         } else {
             d('APP not found by id ' . $appid . ' for viewer ' . $this->Registry->Viewer->getUid());
         }
     }
     return $this;
 }