Example #1
0
 public function actionPno($date)
 {
     date_default_timezone_set('Asia/Shanghai');
     $img_file = '../epaper2/assets/article_img/' . $date;
     $count = 1;
     while (!is_dir($img_file)) {
         if ($count == 1) {
             $date = date('Ymd');
         }
         $date = strtotime($date);
         $beforedate = strtotime("-1 day", $date);
         $date = date('Ymd', $beforedate);
         $img_file = '../epaper2/assets/article_img/' . $date;
         $count = $count + 1;
     }
     $pageNos = new Pnos();
     $criteria = new CDbCriteria();
     $criteria->select = array('pageNo');
     $criteria->condition = 'create_time=:create_time';
     $criteria->params = array(':create_time' => $date);
     $criteria->order = 'pageNo ASC';
     //
     $pnames = Pname::model()->findAll($criteria);
     $easys = array();
     foreach ($pnames as $pname) {
         $pageNo = new Pno();
         $pageNo->pageNo = $pname->pageNo;
         array_push($easys, $pageNo);
     }
     $pageNos->pageNos = $easys;
     $jsonObj = CJSON::encode($pageNos);
     echo $jsonObj;
 }
Example #2
0
 public function run($args)
 {
     date_default_timezone_set('Asia/Shanghai');
     //$date=date('Ymd');
     $date = '20150414';
     //echo $date;
     //echo date('Ymd',strtotime('-1 day'));
     $dir = DISK . 'npsite/tyrb/' . $date . '/';
     //echo $dir;
     if (is_dir($dir)) {
         //创建存放文件的文件夹
         $img_file = PC . '/epaper2/assets/article_img/' . $date;
         if (is_dir($img_file)) {
             echo 'exist ' . $date . ' epaper data';
         } else {
             if ($dh = opendir($dir)) {
                 // echo $img_file.'<bf>';
                 if (mkdir($img_file, 0777)) {
                     $filenames = scandir($dir);
                     $fl_array1 = preg_grep("/\\w*.xml/", $filenames);
                     $fl_array = preg_grep("/^((?!pages.xml).)*\$/", $fl_array1);
                     $xmlfile = array_values($fl_array);
                     //$xml=$xmlfile[0];
                     $pageCount = new Pagecount();
                     $pageCount->setAttributes(array('create_time' => $date, 'pageCount' => count($xmlfile)));
                     $pageCount->save(true);
                     foreach ($xmlfile as $xml) {
                         if (file_exists($dir . $xml)) {
                             $xml = simplexml_load_file($dir . $xml);
                             $PageNo = $xml->PageInfo[0]->attributes()[0];
                             $PageName = $xml->PageInfo[0]->attributes()[1];
                             $ppname = new Pname();
                             $ppname->setAttributes(array('create_time' => $date, 'pageNo' => $PageNo, 'pageName' => $PageName));
                             $ppname->save(true);
                             $ArticleList = $xml->children()[1];
                             foreach ($ArticleList->children() as $child) {
                                 //echo count($ArticleList->children());
                                 //$IntroTitle= $child->IntroTitle[0];
                                 $Title = $child->Title[0];
                                 //echo $Title;
                                 $Title = preg_replace('/(\\n)/', '', $Title);
                                 $SubTitle = $child->SubTitle[0];
                                 $SubTitle = preg_replace('/(\\n)/', '', $SubTitle);
                                 $Content = $child->Content[0];
                                 //$Content = preg_replace('/(\\n\s*){2,}/','',$Content);
                                 //$Content = preg_replace('/(\\n\s*){2,}/','',$Content);
                                 //$Content=nl2br($Content);
                                 $ImageList = $child->ImageList[0];
                                 $imageCount = count($ImageList->children());
                                 //$Image= $ImageList->Image[0]->attributes()[0];
                                 //echo $Title."<br>";
                                 $PointList = $child->PointList[0];
                                 $x1 = intval($PointList->Point[0]->attributes()[0]);
                                 $y1 = intval($PointList->Point[0]->attributes()[1]);
                                 $x2 = intval($PointList->Point[2]->attributes()[0]);
                                 $y2 = intval($PointList->Point[2]->attributes()[1]);
                                 //echo "x1=".$x1.",y1=".$y1."x2=".$x2.",y2=".$y2;
                                 $node = new stdClass();
                                 $node->title = $Title;
                                 $node->body['und'][0]['value'] = "<p>" . $Content . "</p>";
                                 $node->uid = 1;
                                 $node->type = '_xinwen';
                                 $node->language = 'zh-hans';
                                 $node->status = 1;
                                 //(1 or 0): published or not
                                 $node->promote = 0;
                                 //(1 or 0): promoted to front page
                                 $node->comment = 2;
                                 // 0 = comments disabled, 1 = read only, 2 = read/write
                                 $node->field_pageno['und'][0]['value'] = $PageNo;
                                 $node->field_pagename['und'][0]['value'] = $PageName;
                                 $SubTitle = str_replace(" ", "", $SubTitle);
                                 $node->field_subtitle['und'][0]['value'] = $SubTitle;
                                 $node->field_riq['und'][0]['value'] = $date;
                                 foreach ($ImageList->children() as $key => $image) {
                                     $imageUrl = $image->attributes()[0];
                                     $imageData = new Img();
                                     $imageData->setAttributes(array('url' => $imageUrl, 'article_id' => $article->id));
                                     $imageData->save(true);
                                     if (file_exists($dir . $imageUrl)) {
                                         $url = $dir . $imageUrl;
                                     } else {
                                         if (file_exists($dir . 'm_' . $imageUrl)) {
                                             $url = $dir . 'm_' . $imageUrl;
                                         }
                                     }
                                     Image::thumb($url, $img_file . '/s_' . $imageUrl, 137, 109);
                                     Image::thumb($url, $img_file . '/b_' . $imageUrl, 600, 400);
                                     //$htmlimg="<img  src=http://localhost/admin/assets/article_img/".$date.'/b_'.$imageUrl." style=\"width:100%\"/></a>";
                                     $htmlimg = "<p style=\"text-align: center;\"><img src=\"" . ImgRoot . $date . "/b_" . $imageUrl . " \" style=\"width: 100%;\"/></p>";
                                     //echo $htmlimg;
                                     $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value'];
                                     //if($key==1)
                                     $node->field_suoluetu['und'][0]['value'] = ImgRoot . $date . '/b_' . $imageUrl;
                                     //echo $imageUrl;
                                 }
                                 //存完图片
                                 $node = node_submit($node);
                                 // Prepare node for saving
                                 //print_r($node);
                                 node_save($node);
                                 $coor = new Coor();
                                 $coor->setAttributes(array('create_time' => $date, 'pageNo' => $PageNo, 'nid' => $node->nid, 'x1' => $x1, 'x2' => $x2, 'y1' => $y1, 'y2' => $y2));
                                 $coor->save(true);
                             }
                             //处理完一版的新闻
                         }
                     }
                     //foreach ($xmlfile as $xml)
                 }
             }
             //开始新建图片文件夹
         }
         //还未更新数据
     }
     //电子报数据存在
 }
 public function actionListAll($date)
 {
     date_default_timezone_set('Asia/Shanghai');
     $img_file = '../epaper2/assets/article_img/' . $date;
     $count = 1;
     while (!is_dir($img_file)) {
         if ($count == 1) {
             $date = date('Ymd');
         }
         if ($count == 10) {
             die;
         }
         $date = strtotime($date);
         $beforedate = strtotime("-1 day", $date);
         $date = date('Ymd', $beforedate);
         $img_file = '../epaper2/assets/article_img/' . $date;
         $count = $count + 1;
     }
     //是否定义了缓存组件
     /* 		if(($cache=Yii::app()->cache)!=null)
     		{
     			//标识字段,用来指向缓存中存储的一部分数据。
     			$key='ArticleListAll'.$date;
     			if(($jsonObj=$cache->get($key))!=false)
     			{
     				echo $jsonObj ;
     				return;
     			}
     		} */
     $criteria = new CDbCriteria();
     $criteria->select = array('pageNo', 'pageName');
     $criteria->condition = 'create_time=:create_time';
     $criteria->params = array(':create_time' => $date);
     $criteria->order = 'pageNo ASC';
     $pNames = Pname::model()->findAll($criteria);
     $menu = new Menu();
     //包含 pages
     $pages = array();
     foreach ($pNames as $pName) {
         $page = new page();
         $page->pageName = $pName->pageName;
         $page->pageNo = $pName->pageNo;
         //该版面的文章
         $MenuArticles = array();
         $query = new EntityFieldQuery();
         $query->entityCondition('entity_type', 'node')->entityCondition('bundle', '_xinwen')->fieldCondition('field_riq', 'value', $date)->fieldCondition('field_pageno', 'value', $pName->pageNo);
         $result = $query->execute();
         if (isset($result['node'])) {
             $news_items_nids = array_keys($result['node']);
             $nodes = node_load_multiple($news_items_nids);
         }
         $newslists = array();
         foreach ($nodes as $node) {
             $menuArticle = new MenuArticle();
             $menuArticle->id = $node->nid;
             $menuArticle->title = $node->title;
             $menuArticle->ccount = $node->comment_count;
             $field_fubiaoti = str_replace(" ", "", $node->field_subtitle['und'][0]['value']);
             $menuArticle->subtitle = $field_fubiaoti;
             $menuArticle->img = $node->field_suoluetu['und'][0]['value'];
             array_push($MenuArticles, $menuArticle);
         }
         $page->articles = $MenuArticles;
         array_push($pages, $page);
     }
     $menu->pages = $pages;
     $jsonObj = CJSON::encode($menu);
     /* 		if(isset($key))
     		   $cache->set($key,$jsonObj,0,new CDbCacheDependency('select max(id) from tbl_dblogs'));	 */
     echo $jsonObj;
 }
 public function actionListAll($date)
 {
     date_default_timezone_set('Asia/Shanghai');
     $img_file = '../admin/assets/article_img/' . $date;
     $count = 1;
     while (!is_dir($img_file)) {
         if ($count == 1) {
             $date = date('Ymd');
         }
         $date = strtotime($date);
         $beforedate = strtotime("-1 day", $date);
         $date = date('Ymd', $beforedate);
         $img_file = '../admin/assets/article_img/' . $date;
         $count = $count + 1;
     }
     //是否定义了缓存组件
     if (($cache = Yii::app()->cache) != null) {
         //标识字段,用来指向缓存中存储的一部分数据。
         $key = 'ArticleListAll' . $date;
         if (($jsonObj = $cache->get($key)) != false) {
             echo $jsonObj;
             return;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->select = array('pageNo', 'pageName');
     $criteria->condition = 'create_time=:create_time';
     $criteria->params = array(':create_time' => $date);
     $criteria->order = 'pageNo ASC';
     $pNames = Pname::model()->findAll($criteria);
     $menu = new Menu();
     //包含 pages
     $pages = array();
     foreach ($pNames as $pName) {
         //每一版面
         $criteria = new CDbCriteria();
         $criteria->select = array('id', 'title', 'pageNo', 'pageName');
         $criteria->condition = 'create_time=:create_time' . ' AND pageNo=:pageNo';
         $criteria->params = array(':create_time' => $date, ':pageNo' => $pName->pageNo);
         $articles = Article::model()->findAll($criteria);
         $page = new page();
         $page->pageName = $pName->pageName;
         $page->pageNo = $pName->pageNo;
         //该版面的文章
         $MenuArticles = array();
         foreach ($articles as $article) {
             $menuArticle = new MenuArticle();
             $menuArticle->id = $article->id;
             $menuArticle->title = $article->title;
             $comment = Comment::model()->findAll('article_id=:article_id', array(':article_id' => $article->id));
             $menuArticle->ccount = count($comment) . "";
             array_push($MenuArticles, $menuArticle);
         }
         $page->articles = $MenuArticles;
         array_push($pages, $page);
     }
     $menu->pages = $pages;
     $jsonObj = CJSON::encode($menu);
     if (isset($key)) {
         $cache->set($key, $jsonObj, 0, new CDbCacheDependency('select max(id) from tbl_dblogs'));
     }
     echo $jsonObj;
 }
Example #5
0
 if (opendir($dir)) {
     if (mkdir($img_file, 0777)) {
         $filenames = scandir($dir);
         $fl_array1 = preg_grep("/\\w*.xml/", $filenames);
         $fl_array = preg_grep("/^((?!pages.xml).)*\$/", $fl_array1);
         $xmlfile = array_values($fl_array);
         //$xml=$xmlfile[0];
         $pageCount = new Pagecount();
         $pageCount->setAttributes(array('create_time' => $date, 'pageCount' => count($xmlfile)));
         $pageCount->save(true);
         foreach ($xmlfile as $xml) {
             if (file_exists($dir . $xml)) {
                 $xml = simplexml_load_file($dir . $xml);
                 $PageNo = $xml->PageInfo[0]->attributes()[0];
                 $PageName = $xml->PageInfo[0]->attributes()[1];
                 $ppname = new Pname();
                 $ppname->setAttributes(array('create_time' => $date, 'pageNo' => $PageNo, 'pageName' => $PageName));
                 $ppname->save(true);
                 $ArticleList = $xml->children()[1];
                 foreach ($ArticleList->children() as $child) {
                     ////echo count($ArticleList->children());
                     //$IntroTitle= $child->IntroTitle[0];
                     $Title = $child->Title[0];
                     ////echo $Title;
                     $Title = preg_replace('/(\\n)/', '', $Title);
                     $SubTitle = $child->SubTitle[0];
                     $SubTitle = preg_replace('/(\\n)/', '', $SubTitle);
                     $Content = $child->Content[0];
                     //$Content = preg_replace('/(\\n\s*){2,}/','',$Content);
                     //$Content = preg_replace('/(\\n\s*){2,}/','',$Content);
                     //$Content=nl2br($Content);