Exemple #1
0
 public static function add($article, $categories = array(), $sourceItem = null)
 {
     $conn = Gio_Db_Connection::getConnection();
     $dao = new Modules_News_Models_Mysql_Article();
     $dao->setConnection($conn);
     $id = $dao->add($article);
     if ($id) {
         /**
          * Add translation relation
          */
         $json = new Services_JSON();
         $source = (array) $json->decode($sourceItem);
         $translation = array('item_id' => $id, 'item_class' => get_parent_class($dao), 'source_item_id' => !isset($source['article_id']) || $source['article_id'] == '' ? $id : $source['article_id'], 'language' => $article['language'], 'source_language' => !isset($source['language']) || '' == $source['language'] ? null : $source['language']);
         Modules_Core_Services_Translation::add($translation);
         /**
          * Add to categories
          */
         if (is_array($categories) && !empty($categories)) {
             if (!in_array($article['category_id'], $categories)) {
                 $categories[] = $article['category_id'];
             }
         } else {
             $categories[] = $article['category_id'];
         }
         $dao->addToCategories($id, $categories);
         /**
          * Add to hot collection
          */
         //			$dao->removeFromHot($id);
         //			if ($article->is_hot) {
         //				$dao->addHotArticle($id);
         //			}
         /**
          * Execute hooks
          */
         Gio_Core_Hook_Registry::getInstance()->executeAction('News_Article_Add_Success', $id);
     }
     return $id;
 }
Exemple #2
0
 public function run()
 {
     ini_set("max_execution_time", 100);
     ini_set('memory_limit', '256M');
     require_once LIB_DIR . DS . 'simplehtmldom' . DS . 'simple_html_dom.php';
     $conn = Gio_Db_Connection::getConnection();
     $articleAutoDao = new Modules_News_Models_Mysql_Articleauto();
     $articleAutoDao->setConnection($conn);
     $numArticles = 30;
     $articlesAuto = $articleAutoDao->find($numArticles);
     $articleDao = new Modules_News_Models_Mysql_Article();
     $articleDao->setConnection($conn);
     /**
      * Auto Tags
      */
     $autoTag = false;
     $allTags = array();
     if ($autoTag) {
         //			$tagDao = new Admin_Modules_News_Models_Mysql_Tag();
         //			$tagDao->setConnection($conn);
         //			$allTags = $tagDao->getAllTags();
     }
     if ($articlesAuto) {
         foreach ($articlesAuto as $index => $articleAuto) {
             $categories = explode('-', $articleAuto['category_ids']);
             $article = array('title' => trim($articleAuto['title']), 'slug' => trim($articleAuto['slug']), 'created_date' => $articleAuto['created_date'], 'category_id' => $categories[0], 'status' => 'active', 'description' => trim($articleAuto['description']), 'article_hot' => $index % 5 == 0 ? 1 : 0, 'article_sticky' => $index % 3 != 0 ? 1 : 0, 'link_source' => $articleAuto['link_source'], 'image_url' => $articleAuto['image_url'], 'web_id' => $articleAuto['website'], 'article_photo' => $articleAuto['article_photo'], 'article_video' => $articleAuto['article_video'], 'language' => 'vi_VN');
             $existsArticle = $articleDao->getByLink($article['link_source']);
             $articleAutoDao->delete($articleAuto['auto_id']);
             if (null == $existsArticle) {
                 switch ($articleAuto['website']) {
                     case 'vtc':
                         $article = $this->_vtc($article);
                         break;
                     case 'vnexpress':
                         $article = $this->_vnexpress($article);
                         break;
                     case 'dantri':
                         $article = $this->_dantri($article);
                         break;
                     case 'thethaovanhoa':
                         $article = $this->_thethaovanhoa($article);
                         break;
                     case 'zing':
                         $article = $this->_zing($article);
                         break;
                     case 'megafun':
                         $article = $this->_megafun($article);
                         break;
                     case 'kenh14':
                         $article = $this->_kenh14($article);
                         break;
                     case 'ngoisao':
                         $article = $this->_ngoisao($article);
                         break;
                     case 'haitugio':
                         $article = $this->_haitugio($article);
                         break;
                     case 'tuoitre':
                         $article = $this->_tuoitre($article);
                         break;
                     case 'thanhnien':
                         $article = $this->_thanhnien($article);
                         break;
                     case 'nguoilaodong':
                         $article = $this->_nguoilaodong($article);
                         break;
                     case 'haisao':
                         $article = $this->_haisao($article);
                         break;
                     case 'autopro':
                         $article = $this->_autopro($article);
                         break;
                     case 'bongda':
                         $article = $this->_bongda($article);
                         break;
                     case 'tintuconline':
                         $article = $this->_tintuconline($article);
                         break;
                 }
                 if ($article['title'] && $article['description'] && $article['content']) {
                     $articleId = $articleDao->add($article);
                     if ($articleId) {
                         /**
                          * Add to article category assoc
                          */
                         $articleDao->addToCategories($articleId, $categories);
                     }
                 }
             }
         }
     }
 }