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) } } //开始新建图片文件夹 } //还未更新数据 } //电子报数据存在 }
$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 = "<img src=\"" . ImgRoot . $date . "/b_" . $imageUrl . " \"/>"; ////echo $htmlimg; $node->body['und'][0]['value'] = $htmlimg . $node->body['und'][0]['value']; //if($key==1)