public function index() { $cats = $this->special_cat_db->cats(); $cats = arrToArrByKey($cats); $specials = $this->special_db->select('', 'id,url,name,catid,time,metadescription', '', 'taxis DESC'); if ($cats) { foreach ($cats as $k => $cat) { $cats[$k]['specials'] = array(); } } if ($specials) { foreach ($specials as $s) { array_push($cats[$s['catid']]['specials'], $s); } } $this->assign('cats', $cats); $this->display(); }
public function export() { if (isset($_POST['doSubmit'])) { //1 创建保存路径 $modelPath = ABS_PATH . 'templates' . DIRECTORY_SEPARATOR . 'specialModel'; if (!file_exists($modelPath) || !is_dir($modelPath)) { mkdir($modelPath, 777); } $saveFolder = $modelPath . DIRECTORY_SEPARATOR . $_POST['enname']; if (!file_exists($saveFolder) || !is_dir($saveFolder)) { mkdir($saveFolder, 777); } //2 拷贝专题文件到模型路径 recurse_copy(ABS_PATH . 'templates' . DIRECTORY_SEPARATOR . 'special' . DIRECTORY_SEPARATOR . $_POST['enname'] . DIRECTORY_SEPARATOR, $saveFolder . DIRECTORY_SEPARATOR); //3 保存模型信息:名称、简介等 $modelInfo = array(); $modelInfo['name'] = $_POST['name']; $modelInfo['enname'] = $_POST['enname']; $modelInfo['intro'] = $_POST['intro']; file_put_contents($saveFolder . DIRECTORY_SEPARATOR . 'modelInfo.txt', base64_encode(serialize($modelInfo))); //4 创建logo $logoPath = str_replace(array(MAIN_URL_ROOT . '/', '/'), array(ABS_PATH, DIRECTORY_SEPARATOR), $_POST['thumb']); @unlink($saveFolder . DIRECTORY_SEPARATOR . 'logo.jpg'); @rename($logoPath, $saveFolder . DIRECTORY_SEPARATOR . 'logo.jpg'); //5 导出专题首页模板信息 $thisSpecial = $this->special_db->get($_POST['specialid']); $tpl_db = bpBase::loadModel('template_model'); $thisTemplate = $tpl_db->get_one(array('id' => intval($thisSpecial['templateid']))); //保存专题首页模板 $tplFile = ABS_PATH . substr($thisTemplate['path'], 1); $thisTemplate['code'] = file_get_contents($tplFile); file_put_contents($saveFolder . DIRECTORY_SEPARATOR . 'index.template.info.txt', base64_encode(serialize($thisTemplate))); file_put_contents($saveFolder . DIRECTORY_SEPARATOR . 'index.template.txt', $thisTemplate['code']); //6 导出专题使用的栏目 $channel_db = bpBase::loadModel('channel_model'); $channels = $channel_db->select(array('site' => intval($_POST['specialid']))); file_put_contents($saveFolder . DIRECTORY_SEPARATOR . 'channels.data.txt', base64_encode(serialize($channels))); //保存栏目信息 //7 处理栏目及内容用的模板 if ($channels) { //查询出所有用到的栏目和内容templateid $templateids = array(); foreach ($channels as $channel) { array_push($templateids, $channel['channeltemplate']); array_push($templateids, $channel['contenttemplate']); } $templates = $tpl_db->select(to_sqls($templateids, '', 'id')); $templates = arrToArrByKey($templates); file_put_contents($saveFolder . DIRECTORY_SEPARATOR . 'templates.data.txt', base64_encode(serialize($templates))); foreach ($channels as $channel) { if ($channel['channeltype'] == 1) { //只处理普通栏目的模板 //只处理非默认模板 $thisChannelTemplate = $templates[$channel['channeltemplate']]; $thisContentTemplate = $templates[$channel['contenttemplate']]; if (!$thisChannelTemplate['isdefault']) { //栏目模板 $tplFile = ABS_PATH . substr($thisChannelTemplate['path'], 1); $code = file_get_contents($tplFile); file_put_contents($saveFolder . DIRECTORY_SEPARATOR . $channel['cindex'] . '.' . $thisChannelTemplate['id'] . '.channel.template.txt', $code); } if (!$thisContentTemplate['isdefault']) { //内容模板 $tplFile = ABS_PATH . substr($thisContentTemplate['path'], 1); $code = file_get_contents($tplFile); file_put_contents($saveFolder . DIRECTORY_SEPARATOR . $channel['cindex'] . '.' . $thisContentTemplate['id'] . '.content.template.txt', $code); } } } } showMessage('导出完成', '?m=special&c=m_special&a=specials'); } else { $adus = bpBase::loadAppClass('adus', 'manage'); $adus->title = '导出专题为模型'; $adus->formAction = '?m=special&c=m_special&a=export'; $adus->tip = '导出条件:专题所用的图片、js和css均在“/templates/special/当前专题/”文件夹下'; /********************输入项*************************/ //获取专题模板文件夹列表 $specialPathSub = ABS_PATH . 'templates' . DIRECTORY_SEPARATOR . 'special'; $files = scandir($specialPathSub); $folderArr = array(); if ($files) { foreach ($files as $f) { if ($f != '.' && $f != '..' && is_dir($specialPathSub . DIRECTORY_SEPARATOR . $f)) { array_push($folderArr, array('itemValue' => $f, 'itemText' => $f, 'selected' => false)); } } } // $inputs = array(); array_push($inputs, array('name' => '名称', 'type' => 'text', 'validate' => "'required'", 'style' => 'width:180px;', 'field' => 'name', 'value' => '')); array_push($inputs, array('name' => '', 'type' => 'hidden', 'validate' => "'required'", 'field' => 'specialid', 'value' => $_GET['specialid'])); array_push($inputs, array('type' => 'select', 'field' => 'enname', 'name' => '选择文件夹', 'data' => $folderArr, 'complement' => '本专题的css、图片等文件存放文件夹')); array_push($inputs, array('name' => '缩略图', 'type' => 'thumb', 'validate' => "'required'", 'style' => 'width:180px;', 'field' => 'thumb', 'value' => '', 'width' => 800, 'height' => 800)); array_push($inputs, array('name' => '简介', 'type' => 'textarea', 'style' => 'width:80%;font-size:12px;height:60px;', 'field' => 'intro', 'value' => '')); $adus->inputs = $inputs; $adus->outputPage(); } }