Example #1
0
 public function save_foto($name, $fbid)
 {
     $path = $this->galleryConfig['gFolder'] . '/1/' . $this->galleryConfig['picturesDir'] . '/' . $name;
     $model = new FImage();
     $model->name = $name;
     $model->path = $path;
     $model->fbid = $fbid;
     $model->votes = 0;
     $model->save();
     //$sql = "INSERT INTO images(name,path,fbid,votes) VALUES('$name','$path','$fbid',0);";
     //$connection=Yii::app()->db;
     //$command=$connection->createCommand($sql);
     //$connection->active=true;
     //$command->execute();
     //$connection->active=false;  // close connection
 }
Example #2
0
 public static function makeThumbPic($pic_file, $size = '100x100')
 {
     if (!file_exists($pic_file)) {
         return 'thumb_error_for_src_pic_not_exits';
     }
     list($w, $h) = explode('x', $size);
     if (!$w || !$h) {
         throw new Exception("size 参数错误!必须是 100x100 这样的形式。");
     }
     $thumb_file = "{$pic_file}.{$size}.jpg";
     FFile::mkdir(dirname($thumb_file));
     $fImage = new FImage();
     $fImage->open($pic_file)->thumb($w, $h, FImage::THUMB_CENTER)->save($thumb_file);
     return true;
 }
Example #3
0
 public function actionNext()
 {
     Yii::import('application.extensions.FBGallery.GalleryConfig');
     //return json data: {'images':[{'id':'41','src':'galleries/1/thumb/12345678_test.jpg'},{'id':'47','src':'galleries/1/thumb/99856_test777.jpg'}]}
     $imageId = $_REQUEST['imageId'];
     if (isset($imageId)) {
         $criteria = new CDbCriteria();
         $criteria->condition = "state=0";
         $criteria->order = "votes desc";
         $models = FImage::model()->findAll($criteria);
         $prev = 0;
         $actu = $imageId;
         $next = 0;
         $thPrev = '';
         $thActu = '';
         $thNext = '';
         $galleryConfig = self::config("gallery");
         $siteUrlBase = Yii::app()->request->hostInfo . Yii::app()->baseUrl . '/';
         $gUrl = $siteUrlBase . $galleryConfig['gFolder'] . '/1';
         $thUrl = $gUrl . '/' . $galleryConfig['thumbsDir'] . '/';
         if ($models[0]->id == $imageId) {
             //first
             $next = $models[1]->id;
             $res = array('images' => array(array('id' => $prev, 'src' => ''), array('id' => $imageId, 'src' => $thUrl . $models[0]->name), array('id' => $next, 'src' => $thUrl . $models[1]->name)));
             echo json_encode($res);
             Yii::app()->end();
         }
         $last = count($models) - 1;
         if ($models[$last]->id == $imageId) {
             //last
             $prev = $prev = $models[$last - 1]->id;
             $res = array('images' => array(array('id' => $prev, 'src' => $thUrl . $models[$last - 1]->name), array('id' => $imageId, 'src' => $thUrl . $models[$last]->name), array('id' => $next, 'src' => '')));
             echo json_encode($res);
             Yii::app()->end();
         }
         for ($i = 0; $i < count($models); $i++) {
             $model = $models[$i];
             if ($model->id == $imageId) {
                 $prev = $models[$i - 1]->id;
                 $next = $models[$i + 1]->id;
                 break;
             }
         }
         $res = array('images' => array(array('id' => $prev, 'src' => $thUrl . $models[$i - 1]->name), array('id' => $imageId, 'src' => $thUrl . $models[$i]->name), array('id' => $next, 'src' => $thUrl . $models[$i + 1]->name)));
         echo json_encode($res);
         Yii::app()->end();
     }
     $res = array('error' => 'Obrázek nebyl nalezen.');
     echo json_encode($res);
     Yii::app()->end();
 }
 public static function getThumb($dir, $img, $type = 'small', $thumbDir = '.thumb', $showHost = true)
 {
     return FImage::getThumb($dir, $img, $type, $thumbDir, $showHost);
 }
Example #5
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = FImage::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #6
0
 /**
  * Sets @var $this->arrFiles with existing pictures
  * Render according to userType
  */
 private function renderer()
 {
     //$this->arrFiles();
     //$this->render('view');
     //$this->render('uploader', array('max'=>Uploader::maxLenghtUploader()));
     $images = FImage::model()->findAll(array('order' => 'votes DESC'));
     //$order = $this->imgsOrder;
     $rel = preg_replace('!\\-+!', '-', preg_replace("/[^a-z0-9-_.]/", "-", strtolower($this->pageTitle)));
     $text_field = ' text_field';
     $thTitleShow = true;
     $deleteIcon = '';
     if ($this->userType === 'admin') {
         $deleteIcon = '<img src="' . $this->assetUrl . 'delete16x16.png" alt="X" />';
     }
     $thUrl = $this->gUrl . '/' . $this->galleryConfig['thumbsDir'] . '/';
     $imgsUrl = $this->gUrl . '/' . $this->galleryConfig['picturesDir'] . '/';
     if (Yii::app()->user->isGuest) {
         $text_field = '';
         $thTitleShow = $this->galleryConfig['thTitleShow'];
         $deleteIcon = '';
     }
     foreach ($images as $img) {
         $this->item = array('id' => $img->id, 'votes' => $img->votes, 'fbid' => $img->fbid, 'thTitleShow' => $thTitleShow, 'title' => $img->caption, 'text_field' => $text_field, 'deleteIcon' => $deleteIcon, 'rel' => $rel, 'urlImg' => $imgsUrl . $img->name, 'imgSrc' => $thUrl . $img->name, 'fileName' => $img->name);
         $this->arrItems[$img->name] = $this->render('_item', array(), true);
     }
     if ($this->userType === 'visitor') {
         if ($this->pageName == "gallery") {
             $this->render('view');
         }
     }
     if ($this->userType === 'editor' || $this->userType === 'admin') {
         if ($this->pageName == "gallery") {
             $this->render('viewEditor');
         }
         if ($this->pageName == "newfoto") {
             $this->render('uploader', array('max' => Uploader::maxLenghtUploader()));
         }
         //$this->renderEditor();
     }
     if ($this->userType === 'admin') {
         FBAdmin::cpanel();
     }
 }