예제 #1
0
 public static function storage(Image $image, $file, $storage_id = 1)
 {
     $url = ImageStorage::upload($file, $storage_id);
     if ($url) {
         $image->increaseCopyCount();
         return static::create(['image_id' => $image->id, 'url' => $url, 'storage_id' => $storage_id]);
     }
     return false;
 }
예제 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $from = date('Y-m-d H:i:s', strtotime($this->argument('from') ?: 'today'));
     $to = date('Y-m-d H:i:s', strtotime($this->argument('to') ?: 'now'));
     while ($images = Image::whereBetween('created_at', [$from, $to])->where('copy_count', '<', ImageStorage::count())->where('copy_count', '>', 0)->take(10)->get()) {
         if ($images->isEmpty()) {
             $this->info('No image to process.');
             break;
         }
         foreach ($images as $image) {
             $image->checkMulti();
             $this->info("Image:{$image->id} processed.");
         }
     }
 }
예제 #3
0
 /**
  * Загрузка картинок статьи 
  * @param $id
  * @return \yii\web\Response
  */
 public function actionLoadArticlePictures($id)
 {
     $model = ArticlesContent::findOne($id);
     $dom = new \DOMDocument('1.0', 'UTF-8');
     // set error level
     $internalErrors = libxml_use_internal_errors(true);
     // load HTML
     $dom->loadHTML($model->body);
     // Restore error level
     libxml_use_internal_errors($internalErrors);
     $img = $dom->getElementsByTagName("img");
     foreach ($img as $node) {
         foreach ($node->attributes as $attr) {
             if ($attr->localName === 'src') {
                 $extension = '.png';
                 if (strstr($attr->localName, 'jpg')) {
                     $extension = '.jpg';
                 }
                 $imageFile = md5($attr->nodeValue) . $extension;
                 // var_dump($attr->nodeValue); exit;
                 //if()
                 copy($attr->nodeValue, '/home/romanych/public_html/plis/basic/web/uploads/article_img/' . $imageFile);
                 $image = new ImageStorage();
                 $image->img = '/home/romanych/public_html/plis/basic/web/uploads/article_img/' . $imageFile;
                 $image->orig_tag = $attr->nodeValue;
                 $image->cont_art_id = $id;
                 $image->save();
             }
         }
     }
     return $this->redirect(Url::toRoute('articles/index'));
 }
예제 #4
0
 public function duplicate()
 {
     $copy = $this->firstAvailableCopy();
     if (!$copy) {
         throw new \Exception("Boom! Image id: {$this->id}");
     }
     foreach (ImageStorage::getUploaders() as $id => $uploader) {
         if (!ImageCopies::avail()->where(['image_id' => $this->id, 'storage_id' => $id])->first()) {
             ImageCopies::storage($this, $copy->getUrl(), $id);
         }
     }
 }