getContentMenu(); //$this->model_id = $model_id = $this->request->param('model_id'); $this->model_id = $model_id = 1; $list = db('Model')->column('*', 'id'); if (empty($list[$model_id])) { return $this->error("无此模型!"); } else { $this->modelInfo = $list[$model_id]; $this->model = M($this->modelInfo['name']); } $this->assign('model_id', $model_id); $this->assign('model_list', $list); } /** * 内容列表 * @return [html] [页面内容] * @author netlife <40150501@qq.com> */ public function index() { if ($this->modelInfo['list_grid'] == '') { return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id']))); } $grid_list = get_grid_list($this->modelInfo['list_grid']); $order = "id desc"; $map = $this->buildMap(); $field = array_filter($grid_list['fields']); $list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']); $data = array( 'grid' => $grid_list, 'list' => $list, 'page' => $list->render(), ); $this->assign($data); $this->setMeta($this->modelInfo['title'] . "列表"); return $this->fetch(); } /** * 内容添加 * @author netlife <40150501@qq.com> */ public function add() { if (IS_POST) { $this->param['uid'] = session('user_auth.uid'); $result = $this->model->save($this->param); if ($result) { //记录行为 action_log('add_content', 'content', $result, session('user_auth.uid')); return $this->success("添加成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error($this->model->getError(), url('admin/novel/add', array('model_id' => $this->modelInfo['id']))); } } else { $info = array( 'model_id' => $this->modelInfo['id'], ); $data = array( 'info' => $info, 'fieldGroup' => $this->getField($this->modelInfo), ); if ($this->modelInfo['template_add']) { $template = 'content/' . $this->modelInfo['template_add']; } else { $template = 'novel/edit'; } $this->assign($data); $this->setMeta("添加" . $this->modelInfo['title']); return $this->fetch($template); } } /** * uploadbook [上传小说] * * @return type **/ public function uploadbook() { if (IS_POST) { $ebook = input('post.ebook'); $result = $this->model->save($this->param); $articleid = $this->model->getLastInsID(); if ($result) { //增加章节 if($articleid){ $bookList = $this->readList($ebook); $i = 1; foreach($bookList as $k=>$v){ $chapterdata['articleid'] = $articleid; $chapterdata['uid'] = session("user_auth.uid"); $chapterdata['chaptername'] = $v["name"]; $chapterdata['content'] = $v["content"]; $chapterdata['create_time'] = time(); $chapterdata['update_time'] = time(); $chapterdata['size'] = round(strlen(preg_replace('/\\s/', '', strip_tags($v['content'])))/3); $chapterdata['saleprice'] = round($chapterdata['size']/1000*config('wordsperegold')); $chapterdata['chapterorder'] = $i; db('chapter')->insert($chapterdata); $size += $chapterdata['size']; $i++; } //更新小说总字数 db('novel')->where(array('id'=>$articleid))->update(array('size'=>array('exp', '`size`+'.$size))); } //记录行为 action_log('add_content', 'content', $result, session('user_auth.uid')); return $this->success("添加成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error($this->model->getError(), url('admin/novel/add', array('model_id' => $this->modelInfo['id']))); } } else { $info = array( 'model_id' => $this->modelInfo['id'], ); $data = array( 'info' => $info, 'fieldGroup' => $this->getField($this->modelInfo), ); $this->assign($data); $this->setMeta("上传小说"); return $this->fetch(); } } /** * 内容修改 * @author netlife <40150501@qq.com> */ public function edit($id) { if (IS_POST) { $result = $this->model->save($this->param, array('id'=> $id)); if ($result !== false) { //记录行为 action_log('update_content', 'content', $result, session('user_auth.uid')); return $this->success("更新成功!", url('admin/novel/index', array('model_id' => $this->modelInfo['id']))); } else { return $this->error($this->model->getError(), url('admin/novel/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id))); } } else { if (!$id) { return $this->error("非法操作!"); } $info = $this->model->find($id); if (!$info) { return $this->error($this->model->getError()); } $info['model_id'] = $this->modelInfo['id']; $data = array( 'info' => $info, 'fieldGroup' => $this->getField($this->modelInfo), ); if ($this->modelInfo['template_edit']) { $template = 'content/' . $this->modelInfo['template_edit']; } else { $template = 'public/edit'; } $this->assign($data); $this->setMeta("编辑" . $this->modelInfo['title']); return $this->fetch($template); } } /** * 内容删除 * @author netlife <40150501@qq.com> */ public function del() { $id = $this->getArrayParam('id'); if (empty($id)) { return $this->error("非法操作!"); } $map['id'] = array('IN', $id); $result = $this->model->where($map)->delete(); if (false !== $result) { //记录行为 action_log('delete_content', 'content', $result, session('user_auth.uid')); return $this->success("删除成功!"); } else { return $this->error("删除失败!"); } } /** * 设置状态 * @author netlife <40150501@qq.com> */ public function status($id, $status) { $map['id'] = $id; $result = $this->model->where($map)->setField('status', $status); if (false !== $result) { return $this->success("操作成功!"); } else { return $this->error("操作失败!!"); } } /** * 设置置顶 * @author netlife <40150501@qq.com> */ public function settop($id, $is_top) { /** $map['id'] = $id; $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!"); } else { return $this->error("操作失败!!"); } **/ $map['id'] = $id; $top = $this->model->where($map)->value('is_top'); if($top){ $top = explode(',',$top); $top[] = $is_top; array_unique($top); $is_top = implode(",",$top); } $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!"); } else { return $this->error("操作失败!!"); } } /****取消推荐******/ public function unsettop($id, $is_top) { $map['id'] = $id; $top = $this->model->where($map)->value('is_top'); if($top){ $top = explode(',',$top); foreach($top as $k=>$v){ if($v ==$is_top){ unset($top[$k]); } } $is_top = implode(",",$top); } $result = $this->model->where($map)->setField('is_top', $is_top); if (false !== $result) { return $this->success("操作成功!"); } else { return $this->error("操作失败!!"); } } /** * 获取字段信息 * @return array 字段数组 * @author netlife <40150501@qq.com> */ protected function getField() { $field_group = parse_config_attr($this->modelInfo['attribute_group']); $map['model_id'] = $this->modelInfo['id']; if ($this->request->action() == 'add') { $map['is_show'] = array('in', array('1', '2')); } elseif ($this->request->action() == 'edit') { $map['is_show'] = array('in', array('1', '3')); } //获得数组的第一条数组 $rows = model('Attribute')->getFieldlist($map, 'id'); if (!empty($rows)) { foreach ($rows as $key => $value) { $list[$value['group_id']][] = $value; } foreach ($field_group as $key => $value) { $fields[$value] = isset($list[$key]) ? $list[$key] : array(); } }else{ $fields = array(); } return $fields; } /** * 创建搜索 * @return [array] [查询条件] */ protected function buildMap() { $map = array(); $data = $this->request->param(); foreach ($data as $key => $value) { if ($value) { if ($key == 'keyword') { $map['title'] = array("LIKE", "%$value%"); } elseif ($key == 'category') { $map['category_id'] = $value; } elseif ($key == 'create_time') { $map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1]))); } else { $map[$key] = $value; } } } if (isset($map['page'])) { unset($map['page']); } if (isset($map['model_id'])) { unset($map['model_id']); } $this->assign($data); return $map; } /** * 检测需要动态判断的文档类目有关的权限 * * @return boolean|null * 返回true则表示当前访问有权限 * 返回false则表示当前访问无权限 * 返回null,则会进入checkRule根据节点授权判断权限 * * @author 朱亚杰 */ protected function checkDynamic() { $model_id = $this->request->param('model_id'); if (IS_ROOT) { return true; //管理员允许访问任何页面 } $models = model('AuthGroup')->getAuthModels(session('user_auth.uid')); if (!$model_id) { return false; } elseif (in_array($model_id, $models)) { //返回null继续判断操作权限 return null; } else { return false; //无权限 } return false; } public function readList($file) { $list = array(); $content = $this->clearContent(file_get_contents($file)); $content = preg_replace('/\n(?:(?:VIP|最新|防采集|网友上传)\s*(?:卷|分卷|章节)|正文|作品相关)\s*/i', "\n", $content); $content = $this->replacePlus($jieqiConfigs['article']['banwords'], '***', $content); if (preg_match_all('/\n.{0,20}(第(?:一|二|三|四|五|六|七|八|九|十|百|千|万|两|壹|廿|卅|卌|零|〇|1|2|3|4|5|6|7|8|9|0|①|⑴|㈠|[0-9])+(?:章|节|回).{0,50})\n/', $content, $match, PREG_OFFSET_CAPTURE) || preg_match_all('/\n((?:d|第|弟|递|滴|低|地|底|帝|的)*(?:一|二|三|四|五|六|七|八|九|十|百|千|万|两|壹|廿|卅|卌|零|〇|1|2|3|4|5|6|7|8|9|0|①|⑴|㈠|[0-9])+(?:部|卷|集|篇|册|章|节|回).{0,50})\n/', $content, $match, PREG_OFFSET_CAPTURE)) { if ($match[0][0][1] > 1000) { array_unshift($match[0], array('作品相关', -8)); array_unshift($match[1], array('作品相关', -8)); } $c = 0; foreach ($match[1] as $key => $val) { $start = $match[0][$key][1] + strlen($match[0][$key][0]); $end = isset($match[0][$key + 1]) ? $match[0][$key + 1][1] : strlen($content); $chapter = $this->splitword(substr($content, $start, $end - $start), $jieqiConfigs['article']['minwords'], $jieqiConfigs['article']['maxwords']); if (is_array($chapter)) { foreach ($chapter as $k => $v) { $list[$c] = array('name' => trim($val[0])." (".($k+1).")", 'size' => strlen($v), 'content' => " ".str_replace("\n", "\r\n\r\n ", $v)); $c++; } } else { if (empty($chapter)) continue; $list[$c] = array('name' => trim($val[0]), 'size' => $end - $start, 'content' => " ".str_replace("\n", "\r\n\r\n ", $chapter)); $c++; } } } else { $chapter = $this->splitword($content, 0, $jieqiConfigs['article']['splitwords']); if (!empty($chapter)) { $chapter = is_array($chapter) ? $chapter : array($chapter); foreach ($chapter as $key => $val) { $list[] = array('name' => "第 ".($key+1)." 章节", 'size' => strlen($val), 'content' => " ".str_replace("\n", "\r\n\r\n ", $val)); } } } return $list; } protected function clearContent($string) { $string = iconv('GBK', 'UTF-8//IGNORE', $string); $string = str_replace("\t", ' ', $string); $string = str_replace("\r", "\n", $string); $string = $this->replacePlus('\\', '', $string); $string = $this->replacePlus(' ', ' ', $string); $string = $this->replacePlus(';', ";\r", $string); while(stripos($string, '&') !== false) { $string = str_ireplace('&', '&', $string); } $string = str_ireplace(array('&', '&', 'amp;'), '&', $string); $string = preg_replace(array('/&(apos|#39);/i', '/&(quot|#34);/i', '/&(nbsp|#160);/i', '/&(lt|#60);/i', '/&(gt|#62);/i'), array("'", '"', ' ', '<', '>'), $string); $string = html_entity_decode($string, ENT_QUOTES, 'GB2312'); $string = str_ireplace(array('&apos', 'apos;', 'apos', '"', 'quot;', 'quot', ' ', 'nbsp;', 'nbsp', '<', 'lt;', '>', 'gt;'), array("'", "'", "'", '"', '"', '"', ' ', ' ', ' ', '<', '<', '>', '>'), $string); $string = preg_replace('/&#?[a-zA-Z0-9]+;/', '', $string); $string = str_replace(";\r", ';', $string); $string = str_replace("\r", '', $string); $string = preg_replace('//i', "\n", $string); $string = preg_replace('/<\/?p>/i', "\n", $string); $string = preg_replace('/|<\?|\?>|<%|%>|<@|@>/', '', $string); $string = preg_replace('/<(script|style).*\/\1>/is', '', $string); $string = preg_replace('/<\/?(?:html|head|meta|link|base|basefont|body|bgsound|title|style|script|noscript|object|form|select|option|iframe|frame|frameset|applet|button|code|event|id|input|ilayer|layer|name|xml|userprofile|table|tbody|thead|tfoot|th|tr|td|i|b|u|strong|img|p|br|div|em|ul|ol|li|dl|dd|dt|a|font|span|embed|hr|blockquote|h1|h2|h3|h4|h5|h6|sub|sup|strike)[^><]*>/i', '', $string); $string = strip_tags($string); while(strpos($string, ' ')) { $string = str_replace(' ', ' ', $string); } $line = explode("\n", trim($string)); $string = ''; foreach($line as $row) { $row = trim($row); if(strlen($row) > 1) $string .= "\n$row"; } return rtrim($string); } protected function replacePlus($find, $replace, $string) { error_reporting(0); $find = is_array($find) ? $find : array($find); $replace = is_array($replace) ? array_unshift($replace, false) : array_pad(array(false), count($find) + 1, $replace); foreach ($find as $row) { $key = iconv('GBK', 'UTF-8//IGNORE', $row); $val = iconv('GBK', 'UTF-8//IGNORE', next($replace)); if (strpos($string, $key) === false) continue; $string = str_replace($key, $val, $string); } return $string; } protected function splitword($string, $minwords, $maxwords) { $wordnum = $this->strlenPlus($string); if ($minwords > 0 && $wordnum <= $minwords) return false; if ($maxwords <= 0 || $this->strlenPlus($string) <= $maxwords) return $string; preg_match_all('/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/', $string, $match); return array_map('implode', array_chunk($match[0], $maxwords)); } protected function strlenPlus($string) { if(function_exists('iconv_strlen')) return iconv_strlen($string, 'gbk'); if(function_exists('mb_strlen')) return mb_strlen($string, 'gbk'); preg_match_all('/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/', $string, $match); return count($match[0]); } public function zip() { header('Content-Type: text/event-stream'); // 以事件流的形式告知浏览器进行显示 header('Cache-Control: no-cache'); // 告知浏览器不进行缓存 header('X-Accel-Buffering: no'); // 关闭加速缓冲 $this->setMeta("生成小说"); return $this->fetch(); } public function makezip() { /****添加内容进行压缩****** $zipFile ->addFromString("1.txt", "Is file content") ->setPassword($password) ->saveAsFile("/data/www/m.youyandm.com/uploads/zip/1.zip") ->close();*/ /******添加文件压缩****/ $pageli = input('key')>0?input('key'):1; $password = "213147dcfd8@..2018.03.28.##NETLIFE##"; $cartoon = db('novel')->where(['status'=>1])->field("id,title")->select(); ob_start();//打开缓冲区 echo str_repeat(" ",1024*64); echo "本次总共需要生成".count($cartoon)."个,第".($pageli-1)."个正在生成,请稍等...\r\n
"; if($pageli<=count($cartoon)){ $cartoonid = $cartoon[$pageli-1]['id']; $chapter = db('chapter')->where(['articleid'=>$cartoonid,'status'=>1])->order('chapterorder ASC')->field('id,chaptername')->select(); if($chapter){ checkdir(ROOT_PATH."/uploads/zip/novel/".$cartoonid,1); foreach ($chapter as $k=>$v){ if(!file_exists(ROOT_PATH."/uploads/zip/novel/".$cartoonid."/".$v['id'].".zip")){ $content = db('novel_content')->where("chapterid = ".$v['id'])->value('content'); $zipFile = new \PhpZip\ZipFile(); $zipFile->addFromString("1.txt", str_replace(array('

','

','

'),array(PHP_EOL,'',''),$content)); $zipFile->setPassword($password); $zipFile->saveAsFile(ROOT_PATH."/uploads/zip/novel/".$cartoonid."/".$v['id'].".zip"); $zipFile->close(); } } } echo str_repeat(" ",1024*64); echo "《".$cartoon[$pageli-1]["title"]."》生成ZIP完成\r\n
"; ob_flush(); flush(); $pageli++; $jumpUrl = url('appnovel/makezip',array('key'=>$pageli)); echo ""; } } }