public function actiongoPhotoFB() { ignore_user_abort(1); set_time_limit(0); $urlPhoto = $_POST['urlPhoto']; $f = $_POST['filter']; $capPhoto = $_POST['capPhoto']; Helper::debugConsole("post ok"); $namePhoto = Helper::getLastPath($urlPhoto); $min_rand = rand(0, 1000); $max_rand = rand(100000000000, 10000000000000000); $name_file = rand($min_rand, $max_rand); //this part is for creating random name for image $ext = end(explode(".", $namePhoto)); //gets extension $file = Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext; // Save Photo From Facebook And Add Filter Helper::save_image($urlPhoto, $file); $filter = Instagraph::factory($file, $file); $filter->{$f}(); Helper::debugConsole("Save Photo From Facebook And Add Filter ok"); // 320 Show Preview $immid = new Imagick($file); if ($immid->getimagewidth() > 320) { $immid->thumbnailImage(320, null); $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext); $immid->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777); } else { $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext); $immid->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777); } Helper::debugConsole("320 Show Preview ok"); // null x 230 show last upload $imlast = new Imagick($file); $imlast->thumbnailimage(null, 230); $imlast->writeImage(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext); $imlast->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext, 0777); Helper::debugConsole("null x 230 show last upload ok"); // 130 x 110 thumbmail $im = new Imagick($file); $im->thumbnailImage(130, 110); $im->writeImage(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext); chmod(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext, 0777); $im->destroy(); Helper::debugConsole("130 x 110 thumbmail ok"); $photo = new Photo(); $photo->link = $file; $photo->fbid = Yii::app()->facebook->getUser(); $photo->ip = $_SERVER['REMOTE_ADDR']; Helper::debugConsole("set data ok"); if ($photo->save()) { $id = $photo->id; $cr = "\n" . "http://www.pla2gram.com/?p=" . $id . "&theater=1"; $capFB = $capPhoto . $cr; Helper::debugConsole("set fb ok"); // Post to Facebook $args = array('message' => $capFB); $args['image'] = '@' . realpath($file); Yii::app()->facebook->api('/me/photos', 'post', $args); Helper::debugConsole("save fb ok"); Helper::redir("/?p=" . $id, 0); } else { print_r($photo->getErrors()); } }
public function actionPostPhotos() { if (Yii::app()->user->hasState('images')) { $userImages = Yii::app()->user->getState('images'); // Create model and save model foreach ($userImages as $image) { $photo = new Photo(); $photo->picture = $image["filename"]; $photo->description = $image["description"]; if ($photo->save()) { if (Yii::app()->user->hasState('addPhotosTo')) { $addPhotosTo = Yii::app()->user->getState('addPhotosTo'); $addPhotosToType = $addPhotosTo[0]; $addPhotosToId = $addPhotosTo[1]; Yii::log('addphotototype is ' . $addPhotosToType); Yii::log('addphototoid is ' . $addPhotosToId); if ($addPhotosToType == 'menu') { $photoMenu = new PhotosMenu(); $photoMenu->photo_id = $photo->id; $photoMenu->menu_id = $addPhotosToId; $photoMenu->save(); } } } else { // Log error Yii::log("Could not save photo to DB:\n" . CVarDumper::dumpAsString($photo->getErrors()), CLogger::LEVEL_ERROR); // This exception will rollback the transaction throw new Exception('Could not save photos'); } } $this->redirect(array('menu/view', 'id' => $_GET['bid'])); } }