Esempio n. 1
0
 public static function getNewsFromCronAuto()
 {
     $result = 0;
     $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'cron-import.json';
     if (file_exists($file)) {
         $data = file_get_contents($file);
         $data = unserialize($data);
         if ($data) {
             foreach ($data as $row) {
                 $duble = Blog::getDublicateByTitle(mb_convert_encoding($row['title'], 'UTF-8', 'Windows-1251'));
                 if (!$duble) {
                     $model = new Blog();
                     $model->title = mb_convert_encoding($row['title'], 'UTF-8', 'Windows-1251');
                     $model->image = $row['image'] ? $row['image'] : '';
                     $model->content = mb_convert_encoding($row['content'], 'UTF-8', 'Windows-1251');
                     $model->updated_at = time();
                     $model->author = (int) 1;
                     $model->save();
                     $result = 1;
                 }
                 $result = 2;
             }
         }
     }
     return $result;
 }
Esempio n. 2
0
 public static function getFreshNews()
 {
     $quantity = 0;
     $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json';
     if (file_exists($file)) {
         $ImportModel = file_get_contents(Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json');
         $obj = json_decode($ImportModel);
         $quantity = 0;
         if ($ImportModel) {
             foreach ($obj as $row) {
                 $duble = Blog::getDublicateByTitle($row->title);
                 if (!$duble) {
                     $quantity++;
                 }
             }
         }
     }
     return $quantity;
 }
Esempio n. 3
0
 public function actionAddNewsFromParser()
 {
     $result = 0;
     $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json';
     if (file_exists($file)) {
         $ImportModel = file_get_contents($file);
         $obj = json_decode($ImportModel);
         //vd($obj);
         if ($ImportModel) {
             foreach ($obj as $row) {
                 $duble = Blog::getDublicateByTitle($row->title);
                 if (!$duble) {
                     $model = new Article();
                     $model->title = $row->title;
                     $model->image = $row->image ? $row->image : '';
                     $model->content = $row->content;
                     $model->created_at = $row->created_at;
                     $model->updated_at = $row->updated_at;
                     $model->author = $row->author;
                     $model->save();
                     $result = 1;
                 } else {
                     //echo "It is Dublicate", PHP_EOL;
                 }
             }
         }
     }
     return $result;
 }