Esempio n. 1
0
 /**
  * 新闻批量添加
  * @author yangguofeng
  */
 public function batchAddAction()
 {
     $data = [];
     if ($_FILES['news']['name']) {
         $title = explode('.', $_FILES['news']['name']);
         $news = file_get_contents($_FILES['news']['tmp_name']);
         //新闻内容转编码
         $content = strcmp(mb_detect_encoding($news, ['UTF-8', 'GBK']), 'UTF-8') === 0 ? $news : mb_convert_encoding($news, "UTF-8", "GBK");
         //关键字(如果没写关键字,在标题中取。如果没取到,标题作为关键词)
         $keywords = empty($this->getRequest()->getPost('keywords', '')) ? implode('   ', misc::getKeywords($title[0])) : $this->getRequest()->getPost('keywords', '');
         $keywords = empty($keywords) ? $title[0] : $keywords;
         $ret = $this->topic->add("topic_data", ['title' => $title[0], 'tid' => intval($this->getRequest()->getQuery('tid')), 'sid' => intval($this->getRequest()->getQuery('sid')), 'keywords' => $keywords, 'status' => 1, 'attribute' => 0, 'userid' => $this->_user['uid'], 'username' => $data['username'] = $this->_user['username'], 'description' => mb_substr(strip_tags($content), 0, 78, 'UTF-8'), 'inputtime' => $_SERVER['REQUEST_TIME'], 'content' => $content]);
         if ($ret) {
             exit($ret);
         } else {
             header("HTTP/1.1 500 Internal Server Error");
             exit(0);
         }
     }
     $this->getView()->assign('tid', intval($this->getRequest()->getQuery('tid')));
     $this->getView()->assign('sid', intval($this->getRequest()->getQuery('sid')));
 }
Esempio n. 2
0
 /**
  * 新闻批量添加
  * @author cms
  */
 public function batchAddAction()
 {
     $data = [];
     $data['cid'] = $this->getRequest()->getQuery('cid');
     if ($_FILES['news']['name']) {
         //标题
         $title = explode('.', $_FILES['news']['name']);
         $data['title'] = $title[0];
         $news = file_get_contents($_FILES['news']['tmp_name']);
         //检测新闻内容并转编码
         $data['content'] = strcmp(mb_detect_encoding($news, ['UTF-8', 'GBK']), 'UTF-8') === 0 ? $news : mb_convert_encoding($news, "UTF-8", "GBK");
         unset($news);
         //关键字(如果没写关键字,在标题中取。如果没取到,标题作为关键词)
         $data['keywords'] = empty($this->getRequest()->getPost('keywords', '')) ? implode('   ', misc::getKeywords($data['title'])) : $this->getRequest()->getPost('keywords', '');
         $data['keywords'] = empty($data['keywords']) ? $title[0] : $data['keywords'];
         $ret = $this->db_document->addNews(['title' => $data['title'], 'catid' => intval($this->getRequest()->getQuery('cid')), 'keywords' => $data['keywords'], 'url' => '', 'description' => mb_substr(strip_tags($data['content']), 0, 78, 'UTF-8'), 'inputtime' => $_SERVER['REQUEST_TIME'], 'status' => 99, 'content' => $data['content']]);
         if ($ret) {
             echo json_encode(['msg' => 'ok', 'errcode' => 200], JSON_UNESCAPED_UNICODE);
             exit('ok');
         } else {
             header("HTTP/1.1 500 Internal Server Error");
             exit(0);
         }
     }
     $this->getView()->assign('data', $data);
 }