Example #1
0
 public function insert()
 {
     /** @var \app\services\GetArticle\ExtractorInterface $extractor */
     $extractor = null;
     switch ($this->provider) {
         case 'verhosvet':
             $extractor = new \app\services\GetArticle\Verhosvet($this->url);
             break;
         case 'youtube':
             $extractor = new \app\services\GetArticle\YouTube($this->url);
             break;
     }
     if (is_null($extractor)) {
         throw new Exception('Не верный extractor');
     }
     $row = $extractor->extract();
     $articleObject = Article::insert(['header' => $row['header'], 'content' => $row['content'], 'description' => $row['description'], 'source' => $this->url, 'id_string' => Str::rus2translit($row['header']), 'date_insert' => gmdate('YmdHis'), 'tree_node_id_mask' => (new BitMask($this->tree_node_id_mask))->getMask()]);
     $this->id = $articleObject->getId();
     $image = $row['image'];
     $imageContent = file_get_contents($image);
     $imageUrl = parse_url($image);
     $pathInfo = pathinfo($imageUrl['path']);
     $pathInfo['extension'];
     $fields = \cs\Widget\FileUpload2\FileUpload::save(File::content($imageContent), $pathInfo['extension'], ['image', 'Картинка', 0, 'string', 'widget' => [FileUpload::className(), ['options' => ['small' => \app\services\GsssHtml::$formatIcon]]]], $this);
     $articleObject->update($fields);
     return true;
 }
Example #2
0
 /**
  * Добавить послание из GetArticle
  *
  * @param \app\services\GetArticle\ExtractorInterface $extractor
  *
  * @return static
  * @throws \yii\base\Exception
  */
 public static function insertExtractorInterface($extractor)
 {
     $row = $extractor->extract();
     if (is_null($row['header'])) {
         throw new Exception('Нет заголовка');
     }
     if ($row['header'] == '') {
         throw new Exception('Нет заголовка');
     }
     if (is_null($row['description'])) {
         throw new Exception('Нет описания');
     }
     if ($row['description'] == '') {
         throw new Exception('Нет описания');
     }
     $fields = ['header' => $row['header'], 'content' => $row['content'], 'description' => $row['description'], 'source' => $extractor->getUrl(), 'id_string' => Str::rus2translit($row['header']), 'date_insert' => gmdate('YmdHis'), 'date' => gmdate('Ymd'), 'img' => ''];
     $articleObject = self::insert($fields);
     $model = new \app\models\Form\Chenneling();
     $model->id = $articleObject->getId();
     $image = $row['image'];
     if ($image) {
         try {
             $imageContent = file_get_contents($image);
             $imageUrl = parse_url($image);
             $pathInfo = pathinfo($imageUrl['path']);
             $pathInfo['extension'];
             $fields = FileUpload::save(File::content($imageContent), $pathInfo['extension'], ['img', 'Картинка', 0, 'string', 'widget' => [FileUpload::className(), ['options' => ['small' => \app\services\GsssHtml::$formatIcon]]]], $model);
             $articleObject->update($fields);
         } catch (\Exception $e) {
         }
     }
     return $articleObject;
 }