Пример #1
0
 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post())) {
         $model->shared_with = implode(',', $model->shared_with);
         $file = UploadedFile::getInstances($model, 'filename');
         foreach ($file as $filename) {
             $model1 = new Photos();
             $model1->user_id = Yii::$app->user->id;
             $model1->shared_with = $model->shared_with;
             $model1->filename = date("Ymdhis") . $filename->name;
             $path = Yii::getAlias('@uploads/albums/' . $model1->filename);
             if ($model1->save()) {
                 $filename->saveAs($path);
                 Image::thumbnail($path, 120, 120)->save(Yii::getAlias('@uploads/albums/thumbs/' . $model1->filename), ['quality' => 50]);
             }
         }
         Yii::$app->session->setFlash('success', 'Photos successfully posted.');
         Yii::$app->notification->notify($model1->filename, $model1, $model1->user, Yii::$app->controller->id, $model1->shared_with);
         $this->redirect('index');
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('_form', ['model' => $model]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
Пример #2
0
 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($event = null)
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->event_id = $event;
         $model->save();
         return $this->redirect(['/admin/events/view', 'id' => $event]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #3
0
 /**
  * @inheritdoc
  * @return Result parsing group.
  */
 public static function parseAllSources()
 {
     $query = Sources::find();
     $sources = $query->active()->all();
     $i = 0;
     foreach ($sources as $source) {
         if ($source->ownerId) {
             $param['ownerId'] = $source->ownerId;
         } else {
             $param['ownerId'] = NULL;
         }
         $results = Yii::$app->vkApi->createRequest()->setUrl('wall.get')->setData(['owner_id' => $param['ownerId'], 'domain' => $source->domain, 'offset' => $source->postOffset, 'count' => $source->postCount, 'filter' => 'owner'])->send();
         if ($results->isOk) {
             $responses = $results->data['response'];
             foreach ($responses as $response) {
                 if (is_array($response)) {
                     $post = new Posts();
                     $post->recordId = $response['id'];
                     $post->sources_id = $source->id;
                     $prepare_content = preg_replace("/([^&]#[a-zA-zа-яА-я0-9]*)/", "", stripcslashes($response['text']));
                     $prepare_content = preg_replace("/\\[(.+?)\\]/", "", $prepare_content);
                     $post->content = $prepare_content;
                     $title = mb_substr($post->content, 0, mb_stripos($post->content, "<br"));
                     if (!$title) {
                         $title = $post->content;
                     }
                     $post->title = $title ? $title : NULL;
                     $post->slug = Inflector::slug($post->title);
                     if ($response['post_type'] != 'post') {
                         break;
                     }
                     try {
                         if ($post->save()) {
                             foreach ($response['attachments'] as $attachment) {
                                 if ($attachment['type'] == 'photo') {
                                     $photo = new Photos();
                                     $photo->id_posts = $post->id;
                                     $photo->text = $attachment['photo']['text'];
                                     if (isset($attachment['photo']['src'])) {
                                         $photo->link = $attachment['photo']['src'];
                                     }
                                     if (isset($attachment['photo']['src_small'])) {
                                         $photo->link = $attachment['photo']['src_small'];
                                     }
                                     if (isset($attachment['photo']['src_big'])) {
                                         $photo->link = $attachment['photo']['src_big'];
                                     }
                                     if (isset($attachment['photo']['src_xbig'])) {
                                         $photo->link = $attachment['photo']['src_xbig'];
                                     }
                                     if (isset($attachment['photo']['src_xxbig'])) {
                                         $photo->link = $attachment['photo']['src_xxbig'];
                                     }
                                     if (isset($attachment['photo']['src_xxxbig'])) {
                                         $photo->link = $attachment['photo']['src_xxxbig'];
                                     }
                                     $photo->save();
                                 } else {
                                     $post->delete();
                                     $i--;
                                 }
                             }
                             $i++;
                         }
                         $post->slug = $post->id . "-" . $post->slug;
                         $post->save();
                     } catch (yii\db\IntegrityException $e) {
                         //nothing
                     }
                 }
             }
         }
         sleep(5);
     }
     if ($i < 0) {
         $i = 0;
     }
     return Yii::t("app", '{n, plural, =0{Not added new records} =1{# record added} few{# records added} other{# added records}}', ['n' => $i]);
 }
Пример #4
0
 /**
  * Updates an existing Cars model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $fileName = 'file';
     $imgs = \yii\web\UploadedFile::getInstancesByName($fileName);
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (count($imgs > 0)) {
             foreach ($imgs as $img) {
                 $mysqlName = time() . '_' . $img->name;
                 $url = getcwd() . '/src/upload/' . $mysqlName;
                 $kaboom = explode(".", $img->tempName);
                 // Split file name into an array using the dot
                 $fileExt = end($kaboom);
                 // Now target the last array element to get the file extension
                 self::ak_img_resize($img->tempName, $url, 600, 394, $fileExt);
                 //if (rename($img->tempName, $url));
                 chmod($url, 0755);
                 $photo = new Photos();
                 $photo->car_id = $model->id;
                 $photo->url = $mysqlName;
                 $photo->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Пример #5
0
 /**
  * Метод загружает фото на удаленный сервер на GoDaddy
  *
  * @return bool
  */
 public function uploadOnDaddyPhoto()
 {
     try {
         // Разбираем архив
         //Создаём объект для работы с ZIP-архивами
         $zip = new ZipArchive();
         if ($this->photosUpload != null && $zip->open($this->photosUpload->tempName) === true) {
             $zip->extractTo("../web/uploads/temp");
             //Извлекаем файлы в указанную директорию
             $arrFiles = [];
             $count = $zip->numFiles;
             for ($i = 0; $i < $count; $i++) {
                 $arrFiles[] = $zip->getNameIndex($i);
             }
             sort($arrFiles);
             for ($i = 0; $i < $count; $i++) {
                 $nameFile = time() . '_' . $arrFiles[$i];
                 // сохраняем превьюшки
                 // Сохраняем оригинал фотки в temp папку
                 Image::getImagine()->open("../web/uploads/temp/" . $arrFiles[$i])->flipHorizontally()->save("../web/uploads/temp/" . $nameFile);
                 // Вешаем ваатермарку
                 $size = getimagesize("../web/uploads/temp/" . $nameFile);
                 Image::watermark('../web/uploads/temp/' . $nameFile, "../web/uploads/watermark/LogoForNewPhoto.png", [$size[0] - 218, 0])->save('../web/uploads/temp/' . $nameFile);
                 $this->ftpUpload('../web/uploads/temp/' . $nameFile, 'photos', $nameFile);
                 // сохраняем превьюшки
                 Image::thumbnail('../web/uploads/temp/' . $nameFile, 255, 340)->save('../web/uploads/temp/' . $nameFile, ['quality' => 80]);
                 //$preview = Image::thumbnail('../web/uploads/temp/'.$nameFile, 255, 340);
                 //                    echo "START".$count; die();
                 $this->ftpUpload('../web/uploads/temp/' . $nameFile, 'thumbnail', $nameFile);
                 unlink("../web/uploads/temp/" . $arrFiles[$i]);
                 $photos = new Photos();
                 $photos->url = "http://loveporno.net/uploads/photos/" . $nameFile;
                 $photos->catalog_id = $this->id;
                 $photos->url_thumbnail = 'http://loveporno.net/uploads/thumbnail/' . $nameFile;
                 $photos->sort = $i;
                 $photos->save();
                 unlink("../web/uploads/temp/" . $nameFile);
             }
             $zip->close();
             //Завершаем работу с архивом
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         Yii::$app->session->setFlash('error', $e->getMessage());
     }
     return true;
 }
Пример #6
0
 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreatePhoto()
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id_posts, "#" => 'photos']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }