Ejemplo n.º 1
0
 public function index()
 {
     //编号,也就是下载第几个链接,有的是多文件下载用的!
     $k = I('get.k', 0, 'intval');
     //字段名称
     $f = I('get.f', '');
     if (empty($this->id) || empty($this->catid) || empty($f)) {
         $this->error("参数有误!");
     }
     //模型ID
     $modelid = getCategory($this->catid, 'modelid');
     $ModelField = cache('ModelField');
     $Model_field = $ModelField[$modelid];
     //判断字段类型
     if (!in_array($Model_field[$f]['formtype'], array('downfiles', 'downfile'))) {
         $this->error('下载地址错误!');
     }
     $this->db = \Content\Model\ContentModel::getInstance($modelid);
     $data = $this->db->relation(true)->where(array("id" => $this->id, 'status' => 99))->find();
     if (empty($data)) {
         $this->error("该信息不存在!");
     }
     $this->db->dataMerger($data);
     if (!empty($data)) {
         //取得下载字段信息
         $downfiles = $data[$f];
         $dowUnserialize = unserialize($downfiles);
         if ($dowUnserialize) {
             $info = $dowUnserialize[$k];
             if (empty($info)) {
                 $this->error("该下载地址已经失效!");
             }
         } else {
             $info = array();
             $info['filename'] = basename($downfiles);
             $info['point'] = 0;
             $info['groupid'] = 0;
         }
         //当前客户端标识
         $aut = md5($this->userid . $this->groupid . substr($_SERVER['HTTP_USER_AGENT'], 0, 254));
         //加密
         //格式:aut|栏目ID|信息id|下载编号|字段
         $key = \Libs\Util\Encrypt::authcode(implode('|', array($aut, $this->catid, $this->id, $k, $f)), '', '', 3600);
         $this->assign("info", $data);
         $this->assign("fileurl", U("Download/d", array('key' => urlencode($key))));
         $this->assign("filename", $info['filename']);
         $this->assign("point", $info['point']);
         $this->assign("groupid", $info['groupid']);
         $this->assign("Member_group", cache("Member_group"));
         $this->assign("SEO", seo($this->catid, urldecode($info['filename']), '', ''));
         $this->display("Public:download");
     } else {
         $this->error("该信息不存在!");
     }
 }
Ejemplo n.º 2
0
 /**
  * 推荐位数据获取
  * 参数名	 是否必须	 默认值	 说明
  * posid	 是	 null	 推荐位ID
  * catid	 否	 null	 调用栏目ID
  * thumb	 否	 0	 是否仅必须缩略图
  * order	 否	 null	 排序类型
  * num	 是	 null	 数据调用数量
  * @param type $data 
  */
 public function position($data)
 {
     //缓存时间
     $cache = (int) $data['cache'];
     $cacheID = to_guid_string($data);
     if ($cache && ($return = S($cacheID))) {
         return $return;
     }
     $posid = (int) $data['posid'];
     if ($posid < 1) {
         return false;
     }
     $catid = (int) $data['catid'];
     $thumb = isset($data['thumb']) ? $data['thumb'] : 0;
     $order = empty($data['order']) ? array("listorder" => "DESC", "id" => "DESC") : $data['order'];
     $num = (int) $data['num'];
     $db = M('PositionData');
     $Position = cache('Position');
     if ($num == 0) {
         $num = $Position[$posid]['maxnum'];
     }
     $where = array();
     //设置SQL where 部分
     if (isset($data['where']) && $data['where']) {
         $where['_string'] = $data['where'];
     }
     $where['posid'] = array("EQ", $posid);
     if ($thumb) {
         $where['thumb'] = array("EQ", 1);
     }
     if ($catid > 0) {
         $cat = getCategory($catid);
         if ($cat) {
             //是否包含子栏目
             if ($cat['child']) {
                 $where['catid'] = array("IN", $cat['arrchildid']);
             } else {
                 $where['catid'] = array("EQ", $catid);
             }
         }
     }
     $data = $db->where($where)->order($order)->limit($num)->select();
     foreach ($data as $k => $v) {
         $data[$k]['data'] = unserialize($v['data']);
         $data[$k]['data']['url'] = \Content\Model\ContentModel::getInstance($v['modelid'])->where(array("id" => $v['id']))->getField("url");
     }
     //结果进行缓存
     if ($cache) {
         S($cacheID, $data, $cache);
     }
     return $data;
 }
Ejemplo n.º 3
0
 public function index()
 {
     //栏目ID
     $catid = I('get.catid', 0, 'intval');
     //信息ID
     $id = I('get.id', 0, 'intval');
     //模型ID
     $modelid = (int) getCategory($catid, 'modelid');
     if (empty($modelid)) {
         exit;
     }
     $this->db = \Content\Model\ContentModel::getInstance($modelid);
     $r = $this->db->where(array('id' => $id))->field('catid,id,dayviews,monthviews,views,weekviews,yesterdayviews,viewsupdatetime')->find();
     if (empty($r)) {
         exit;
     }
     $r['modelid'] = $modelid;
     //增加点击率
     $this->hits($r);
     echo json_encode($r);
 }
 /**
  * 执行URL更新操作
  * @param type $data 数据
  * @return boolean
  */
 private function urls($data)
 {
     if (!$data['inputtime'] || !$data['id'] || !$data['catid']) {
         return false;
     }
     $urls = $this->Url->show($data);
     ContentModel::getInstance(getCategory($data['catid'], 'modelid'))->where(array('id' => $data['id']))->save(array('url' => $urls['url']));
     return $urls['url'];
 }
Ejemplo n.º 5
0
 /**
  * 生成内容页
  * @param  $data 数据
  * @param  $array_merge 是否合并
  */
 public function show($data = '', $array_merge = 1)
 {
     if (empty($data)) {
         if (!empty($this->data)) {
             $data = $this->data;
             // 重置数据
             $this->data = array();
         } else {
             $this->error = '没有数据';
             return false;
         }
     }
     //初始化一些模板分配变量
     $this->assignInitialize();
     //取得信息ID
     $id = $data['id'];
     //栏目ID
     $catid = $data['catid'];
     //获取当前栏目数据
     $category = getCategory($catid);
     //扩展配置
     $setting = $category['setting'];
     //是否生成静态
     if (empty($setting['content_ishtml'])) {
         return false;
     }
     //模型ID
     $this->modelid = $category['modelid'];
     //检查数据是否合并
     if (!$array_merge) {
         ContentModel::getInstance($this->modelid)->dataMerger($data);
     }
     //原始数据
     $this->assign('_original', $data);
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //tag
     tag('html_shwo_buildhtml', $data);
     $content_output = new \content_output($this->modelid);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     //SEO
     $seo_keywords = '';
     if (!empty($output_data['keywords'])) {
         $seo_keywords = implode(',', $output_data['keywords']);
     }
     $seo = seo($catid, $output_data['title'], $output_data['description'], $seo_keywords);
     //内容页模板
     $template = $output_data['template'] ? $output_data['template'] : $category['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode('.', $template);
     $template = "Show/{$newstempid[0]}";
     //获取模板文件地址
     $templatePath = parseTemplateFile($template);
     //分页处理
     $pages = $titles = '';
     //分配解析后的文章数据到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign('SEO', $seo);
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] > 0) {
         //分页表情出现次数
         $content_page_pos = strpos($output_data['content'], '[page]');
         if ($content_page_pos !== false) {
             $contents = array_filter(explode('[page]', $output_data['content']));
             $pagenumber = count($contents);
             for ($i = 1; $i <= $pagenumber; $i++) {
                 //URL地址处理
                 $urlrules = $this->generateShowUrl($data, $i);
                 //用于分页导航
                 if (!isset($pageurl['index'])) {
                     $pageurl['index'] = $urlrules['page']['index'];
                     $pageurl['list'] = $urlrules['page']['list'];
                 }
                 $pageurls[$i] = $urlrules;
             }
             $pages = '';
             //生成分页
             foreach ($pageurls as $page => $urls) {
                 //$pagenumber 分页总数
                 $_GET[C('VAR_PAGE')] = $page;
                 $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => $pageurl))->show();
                 $content = $contents[$page - 1];
                 //分页
                 $this->assign('pages', $pages);
                 $this->assign('content', $content);
                 $this->buildHtml($urls['path'], SITE_PATH, $templatePath);
             }
             return true;
         }
     }
     //对pages进行赋值null,解决由于上一篇有分页下一篇无分页的时候,会把上一篇的分页带到下一篇!
     $this->assign("pages", null);
     $this->assign("content", $output_data['content']);
     //当没有启用内容页分页时候(如果内容字段有启用分页,不会执行到此步骤),判断其他支持分页的标签进行分页处理
     unset($GLOBALS["Total_Pages"]);
     $page = 1;
     $j = 1;
     //开始生成列表
     do {
         $this->assign(C("VAR_PAGE"), $page);
         //生成路径
         $category_url = $this->generateShowUrl($data, $page);
         $GLOBALS['URLRULE'] = $category_url['page'];
         //生成
         $this->buildHtml($category_url["path"], SITE_PATH, $templatePath);
         $page++;
         $j++;
         $total_number = isset($_GET['total_number']) ? (int) $_GET['total_number'] : (int) $GLOBALS["Total_Pages"];
     } while ($j <= $total_number);
     return true;
 }
Ejemplo n.º 6
0
 public function create()
 {
     if (IS_POST || isset($_GET['modelid'])) {
         $modelid = I('request.modelid', 0, 'intval');
         $_GET['modelid'] = $modelid;
         $lun = I('get.lun', 0, 'intval');
         //第几轮 0=>1
         if ($lun > (int) $_GET['zlun'] - 1) {
             $lun = (int) $_GET['zlun'] - 1;
         }
         $lun = $lun < 0 ? 0 : $lun;
         $mlun = 100;
         $firstRow = $mlun * ($lun < 0 ? 0 : $lun);
         $db = M('TagsContent');
         $tagdb = M('Tags');
         if (isset($_GET['delete'])) {
             //清空
             $db->query('TRUNCATE TABLE  `' . C("DB_PREFIX") . 'tags_content`');
             $tagdb->query('TRUNCATE TABLE  `' . C("DB_PREFIX") . 'tags`');
         }
         unset($_GET['delete']);
         $model = cache('Model');
         if ((int) $_GET['mo'] == 1) {
         } else {
             //模型总数
             $_GET['mocount'] = 1;
         }
         //当全部模型重建时处理
         if (!$modelid) {
             $modelCONUT = M("Model")->count();
             $modelDATA = M("Model")->where(array('type' => 0))->order(array('modelid' => 'ASC'))->find();
             $modelid = $modelDATA['modelid'];
             $_GET['mo'] = 1;
             $_GET['mocount'] = $modelCONUT;
             $_GET['modelid'] = $modelid;
         }
         $models_v = $model[$modelid];
         if (!is_array($models_v)) {
             $this->error("该模型不存在!");
             exit;
         }
         $count = \Content\Model\ContentModel::getInstance($modelid)->count();
         if ($count == 0) {
             if (isset($_GET['mo'])) {
                 $where = array();
                 $where['type'] = 0;
                 $where['modelid'] = array('GT', $modelid);
                 $modelDATA = M('Model')->where($where)->order(array('modelid' => 'ASC'))->find();
                 if (!$modelDATA) {
                     $this->success('Tags重建结束!', U('index'));
                     exit;
                 }
                 unset($_GET['zlun']);
                 unset($_GET['lun']);
                 $modelid = $modelDATA['modelid'];
                 $_GET['modelid'] = $modelid;
                 $this->assign("waitSecond", 200);
                 $this->success("模型:{$models_v['name']},第 " . ($lun + 1) . "/{$zlun} 轮更新成功,进入下一轮更新中...", U('create', $_GET));
                 exit;
             } else {
                 $this->error('该模型下没有信息!');
                 exit;
             }
         }
         //总轮数
         $zlun = ceil($count / $mlun);
         $_GET['zlun'] = $zlun;
         $this->createUP($models_v, $firstRow, $mlun);
         if ($lun == (int) $_GET['zlun'] - 1) {
             if (isset($_GET['mo'])) {
                 $where = array();
                 $where['type'] = 0;
                 $where['modelid'] = array('GT', $modelid);
                 $modelDATA = M('Model')->where($where)->order(array('modelid' => 'ASC'))->find();
                 if (!$modelDATA) {
                     $this->success("Tags重建结束!", U('index'));
                     exit;
                 }
                 unset($_GET['zlun']);
                 unset($_GET['lun']);
                 $modelid = $modelDATA['modelid'];
                 $_GET['modelid'] = $modelid;
             } else {
                 $this->success("Tags重建结束!", U('index'));
                 exit;
             }
         } else {
             $_GET['lun'] = $lun + 1;
         }
         $this->assign('waitSecond', 200);
         $this->success("模型:" . $models_v['name'] . ",第 " . ($lun + 1) . "/{$zlun} 轮更新成功,进入下一轮更新中...", U('create', $_GET));
         exit;
     } else {
         $model = cache('Model');
         $mo = array();
         foreach ($model as $k => $v) {
             if ($v['type'] == 0) {
                 $mo[$k] = $v['name'];
             }
         }
         $this->assign('Model', $mo)->display();
     }
 }
Ejemplo n.º 7
0
 public function shows()
 {
     $catid = I('get.catid', 0, 'intval');
     $id = I('get.id', 0, 'intval');
     $page = intval($_GET[C("VAR_PAGE")]);
     $page = max($page, 1);
     //获取当前栏目数据
     $category = getCategory($catid);
     if (empty($category)) {
         send_http_status(404);
         exit;
     }
     //反序列化栏目配置
     $category['setting'] = $category['setting'];
     //检查是否禁止访问动态页
     if ($category['setting']['showoffmoving']) {
         send_http_status(404);
         exit;
     }
     //模型ID
     $modelid = $category['modelid'];
     $data = ContentModel::getInstance($modelid)->relation(true)->where(array("id" => $id, 'status' => 99))->find();
     if (empty($data)) {
         send_http_status(404);
         exit;
     }
     ContentModel::getInstance($modelid)->dataMerger($data);
     //分页方式
     if (isset($data['paginationtype'])) {
         //分页方式
         $paginationtype = $data['paginationtype'];
         //自动分页字符数
         $maxcharperpage = (int) $data['maxcharperpage'];
     } else {
         //默认不分页
         $paginationtype = 0;
     }
     //tag
     tag('html_shwo_buildhtml', $data);
     $content_output = new \content_output($modelid);
     //获取字段类型处理以后的数据
     $output_data = $content_output->get($data);
     $output_data['id'] = $id;
     $output_data['title'] = strip_tags($output_data['title']);
     //SEO
     $seo_keywords = '';
     if (!empty($output_data['keywords'])) {
         $seo_keywords = implode(',', $output_data['keywords']);
     }
     $seo = seo($catid, $output_data['title'], $output_data['description'], $seo_keywords);
     //内容页模板
     $template = $output_data['template'] ? $output_data['template'] : $category['setting']['show_template'];
     //去除模板文件后缀
     $newstempid = explode(".", $template);
     $template = $newstempid[0];
     unset($newstempid);
     //分页处理
     $pages = $titles = '';
     //分配解析后的文章数据到模板
     $this->assign($output_data);
     //seo分配到模板
     $this->assign("SEO", $seo);
     //栏目ID
     $this->assign("catid", $catid);
     //分页生成处理
     //分页方式 0不分页 1自动分页 2手动分页
     if ($data['paginationtype'] > 0) {
         $urlrules = $this->Url->show($data, $page);
         //手动分页
         $CONTENT_POS = strpos($output_data['content'], '[page]');
         if ($CONTENT_POS !== false) {
             $contents = array_filter(explode('[page]', $output_data['content']));
             $pagenumber = count($contents);
             $pages = page($pagenumber, 1, $page, array('isrule' => true, 'rule' => $urlrules['page']))->show("default");
             //判断[page]出现的位置是否在第一位
             if ($CONTENT_POS < 7) {
                 $content = $contents[$page];
             } else {
                 $content = $contents[$page - 1];
             }
             //分页
             $this->assign("pages", $pages);
             $this->assign("content", $content);
         }
     } else {
         $this->assign("content", $output_data['content']);
     }
     $this->display("Show/{$template}");
 }
Ejemplo n.º 8
0
 public function rebuilding()
 {
     $action = I('get.action', 0, 'intval');
     $posid = I('get.posid', 0, 'intval');
     if (empty($posid)) {
         $this->error('请指定需要进行重建数据的推荐位!');
     }
     $model = M('PositionData');
     if ($action == 0) {
         //初始化
         $count = $model->where(array('posid' => $posid))->count();
         $lun = ceil($count / 20);
         $_GET['lun'] = $lun;
         $_GET['count'] = $count;
         $_GET['action'] = 1;
         $_GET['i'] = 0;
         $this->assign('waitSecond', 100);
         $this->success('开始准备进行数据重建工作!', U('rebuilding', $_GET));
         exit;
     } else {
         if ($action == 1) {
             $lun = I('get.lun', 1, 'intval');
             $i = I('get.i', 0, 'intval');
             $cid = I('get.cid', 0, 'intval');
             if ($i > $lun) {
                 $this->success('数据重建完毕!', U('index'));
                 exit;
             }
             $dataList = $model->where(array('posid' => $posid, 'id' => array('GT', $cid)))->order(array('id' => 'ASC'))->limit(20)->select();
             if (empty($dataList)) {
                 $this->success('数据重建完毕!', U('index'));
                 exit;
             }
             $modelList = cache('Model');
             $modelField = cache('ModelField');
             foreach ($dataList as $rs) {
                 $modelid = $rs['modelid'];
                 $data = \Content\Model\ContentModel::getInstance($modelid)->relation(true)->where(array('id' => $rs['id']))->find();
                 if (!$modelList[$modelid] || !$modelField[$modelid]) {
                     continue;
                 }
                 \Content\Model\ContentModel::getInstance($modelid)->dataMerger($data);
                 $textcontent = array();
                 foreach ($modelField[$modelid] as $fieldInfo) {
                     $field = $fieldInfo['field'];
                     if ($fieldInfo['isposition']) {
                         $textcontent[$field] = $data[$field];
                     }
                 }
                 $textcontent['style'] = $data['style'] ?: '';
                 $newsData = array('id' => $rs['id'], 'catid' => $rs['catid'], 'modelid' => $modelid, 'thumb' => $textcontent['thumb'] ? 1 : 0, 'data' => serialize($textcontent));
                 $model->where(array('posid' => $posid, 'id' => $rs['id'], 'catid' => $rs['catid'], 'modelid' => $modelid))->save($newsData);
                 $cid = $rs['id'];
             }
             $i++;
             $_GET['lun'] = $lun;
             $_GET['i'] = $i;
             $_GET['cid'] = $cid;
             $jindu = round($i / $lun * 100, 3);
             $this->assign('waitSecond', 100);
             $this->success("数据重建中..总共<font color=\"#FF0000\">{$lun}</font>轮,当前第<font color=\"#FF0000\">{$i}</font>轮,进度:<font color=\"#FF0000\">{$jindu}%</font>", U('rebuilding', $_GET));
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * 数据入库前处理
  * @param type $data
  * @param type $type 状态1插入数据,2更新数据,3包含以上两种
  * @return boolean|string 
  */
 public function get($data, $type = 3)
 {
     //数据
     $this->data = $data;
     //栏目id
     $this->catid = (int) $data['catid'];
     //获取内容模型对象
     $this->ContentModel = \Content\Model\ContentModel::getInstance($this->modelid);
     foreach ($this->fields as $fieldInfo) {
         $field = $fieldInfo['field'];
         //如果是更新状态下,没有数据的,跳过
         if ($type == 2) {
             if (!isset($this->data[$field])) {
                 continue;
             }
         }
         //字段内容
         $value = $this->data[$field];
         //字段别名
         $name = $fieldInfo['name'];
         //最小值
         $minlength = (int) $fieldInfo['minlength'];
         //最大值
         $maxlength = (int) $fieldInfo['maxlength'];
         //数据校验正则
         $pattern = $fieldInfo['pattern'];
         //数据校验未通过的提示信息
         $errortips = empty($fieldInfo['errortips']) ? $name . ' 不符合要求!' : $fieldInfo['errortips'];
         //配置
         $setting = unserialize($fieldInfo['setting']);
         //是否主表
         $issystem = $fieldInfo['issystem'] ? true : false;
         //验证条件
         if (in_array($type, array(1, 3))) {
             //新增时,必须验证
             $condition = 1;
         } else {
             //当存在值时验证
             $condition = 2;
         }
         //进行长度验证
         if ($minlength) {
             $this->ContentModel->addValidate(array($field, 'require', $name . ' 不能为空!', $condition, 'regex', 3), $issystem);
             $this->ContentModel->addValidate(array($field, 'isMin', $name . ' 不得小于 ' . $minlength . "个字符!", $condition, 'function', 3, array($minlength)), $issystem);
         }
         if ($maxlength) {
             $this->ContentModel->addValidate(array($field, 'isMax', $name . ' 不得多于 ' . $maxlength . "个字符!", $condition, 'function', 3, array($maxlength)), $issystem);
         }
         //数据校验正则
         if ($pattern) {
             $this->ContentModel->addValidate(array($field, $pattern, $errortips, 2, 'regex', 3), $issystem);
         }
         //值唯一
         if ($fieldInfo['isunique']) {
             $this->ContentModel->addValidate(array($field, '', $name . " 该值必须不重复!", 2, 'unique', 3), $issystem);
         }
         //字段类型
         $func = $fieldInfo['formtype'];
         //检测对应字段方法是否存在,存在则执行此方法,并传入字段名和字段值
         if (method_exists($this, $func)) {
             $value = $this->{$func}($field, $value);
         }
         //字段扩展,可以对字段内容进行再次处理,类似ECMS字段处理函数
         if ($setting['backstagefun'] || $setting['frontfun']) {
             load("@.treatfun");
             $backstagefun = explode("###", $setting['backstagefun']);
             $usfun = $backstagefun[0];
             $usparam = $backstagefun[1];
             //前后台
             if (defined("IN_ADMIN") && IN_ADMIN) {
                 //检查方法是否存在
                 if (function_exists($usfun)) {
                     //判断是入库执行类型
                     if ((int) $setting['backstagefun_type'] == 1 || (int) $setting['backstagefun_type'] == 3) {
                         //调用自定义函数,参数传入:模型id,栏目ID,信息ID,字段内容,字段名,操作类型,附加参数
                         try {
                             $value = call_user_func($usfun, $this->modelid, $this->catid, 0, $value, $field, ACTION_NAME, $usparam);
                         } catch (Exception $exc) {
                             //记录日志
                             \Think\Log::record("模型id:" . $this->modelid . ",错误信息:调用自定义函数" . $usfun . "出现错误!");
                         }
                     }
                 }
             } else {
                 //前台投稿处理自定义函数处理
                 //判断当前用户组是否拥有使用字段处理函数的权限,该功能暂时木有,以后加上
                 if (true) {
                     $backstagefun = explode("###", $setting['frontfun']);
                     $usfun = $backstagefun[0];
                     $usparam = $backstagefun[1];
                     //检查方法是否存在
                     if (function_exists($usfun)) {
                         //判断是入库执行类型
                         if ((int) $setting['backstagefun_type'] == 1 || (int) $setting['backstagefun_type'] == 3) {
                             //调用自定义函数,参数传入:模型id,栏目ID,信息ID,字段内容,字段名,操作类型,附加参数
                             try {
                                 $value = call_user_func($usfun, $this->modelid, $this->catid, 0, $value, $field, ACTION_NAME, $usparam);
                             } catch (Exception $exc) {
                                 //记录日志
                                 \Think\Log::record("模型id:" . $this->modelid . ",错误信息:调用自定义函数" . $usfun . "出现错误!");
                             }
                         }
                     }
                 }
             }
         }
         //除去已经处理过的字段
         unset($data[$field]);
         //当没有返回时,或者为 null 时,等于空字符串,null有时会出现mysql 语法错误。
         if (is_null($value)) {
             continue;
         }
         //把系统字段和模型字段分开
         if ($issystem) {
             $this->infoData[$field] = $value;
         } else {
             $this->infoData[$this->ContentModel->getRelationName()][$field] = $value;
         }
     }
     //取得标题颜色
     if (isset($_POST['style_color'])) {
         //颜色选择为隐藏域 在这里进行取值
         $this->infoData['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
         //标题加粗等样式
         if (isset($_POST['style_font_weight'])) {
             $this->infoData['style'] = $this->infoData['style'] . ($_POST['style_font_weight'] ? ';' : '') . strip_tags($_POST['style_font_weight']);
         }
     }
     //如果$data还有存在模型字段以外的值,进行合并
     if (!empty($data)) {
         $this->infoData = array_merge($data, $this->infoData);
     }
     //如果副表没有字段,加个关联ID字段。不然不会在副表插入一条记录
     if (!isset($this->infoData[$this->ContentModel->getRelationName()]) && $this->model[$this->modelid]['type'] == 0) {
         $this->infoData[$this->ContentModel->getRelationName()] = array('id' => 0);
     }
     return $this->infoData;
 }
Ejemplo n.º 10
0
 /**
  * 列表(lists)
  * 参数名	 是否必须	 默认值	 说明
  * tag	 否	 null	 tag名称
  * tagid	 否	 null	 tagID
  * num	 否	 10	 返回数量
  * order	 否	 null	 排序类型
  * 
  * @param $data
  */
 public function lists($data)
 {
     //缓存时间
     $cache = (int) $data['cache'];
     $cacheID = to_guid_string($data);
     if ($cache && ($return = S($cacheID))) {
         return $return;
     }
     //查询条件
     $this->where($data);
     //判断是否启用分页,如果没启用分页则显示指定条数的内容
     if (!isset($data['limit'])) {
         $data['limit'] = (int) $data['num'] == 0 ? 10 : (int) $data['num'];
     }
     //排序
     if (empty($data['order'])) {
         $data['order'] = array("updatetime" => "DESC");
     }
     $db = M('TagsContent');
     $return = $db->where($this->where)->order($data['order'])->limit($data['limit'])->select();
     //读取文章信息
     foreach ($return as $k => $v) {
         $r = \Content\Model\ContentModel::getInstance($v['modelid'])->where(array('id' => $v['contentid']))->find();
         if ($r) {
             $return[$k] = array_merge($v, $r);
         }
     }
     if ($cache) {
         S($cacheID, $return, $cache);
     }
     return $return;
 }
Ejemplo n.º 11
0
 /**
  * 相关文章标签
  * 参数名	 是否必须	 默认值	 说明
  * catid	 否	 null	 调用栏目ID
  * where	 否	 null	 sql语句的where部分
  * nid	 否	 null	 排除id 一般是 $id,排除当前文章
  * relation	 否	 $relation	 无需更改
  * keywords	 否	 null	 内容页面取值:$rs[keywords]
  * num	 是	 null	 数据调用数量
  * @param $data
  */
 public function relation($data)
 {
     //缓存时间
     $cache = (int) $data['cache'];
     $cacheID = to_guid_string($data);
     if ($cache && ($key_array = S($cacheID))) {
         return $key_array;
     }
     $getLastSql = array();
     $catid = intval($data['catid']);
     if (!$catid) {
         return false;
     }
     if (!$this->set_modelid($catid)) {
         return false;
     }
     //调用数量
     $data['num'] = (int) $data['num'];
     if (!$data['num']) {
         $data['num'] = 10;
     }
     $where = array();
     //设置SQL where 部分
     if (isset($data['where']) && $data['where']) {
         $where['_string'] = $data['where'];
     }
     $where['status'] = array("EQ", 99);
     $order = $data['order'];
     $limit = $data['nid'] ? $data['num'] + 1 : $data['num'];
     //数据
     $key_array = array();
     $number = 0;
     //是否经过ContentOutput处理
     if ($data['output']) {
         ShuipFCMS()->ContentOutput->setModelid($this->modelid);
     }
     //根据手动添加的相关文章
     if ($data['relation']) {
         //跨模型
         if (strpos($data['relation'], ',')) {
             $relations = explode('|', $data['relation']);
             $newRela = array();
             $i = 1;
             foreach ($relations as $rs) {
                 if ($i >= $limit) {
                     break;
                 }
                 if (strpos($rs, ',')) {
                     $rs = explode(',', $rs);
                 } else {
                     $rs = array($this->modelid, $rs);
                 }
                 $newRela[$rs[0]][] = $rs[1];
                 $i++;
             }
             $_key_array = array();
             foreach ($newRela as $modelid => $catidList) {
                 $where['id'] = array('IN', $catidList);
                 $_list = \Content\Model\ContentModel::getInstance($modelid)->relation($data['moreinfo'] ? true : false)->where($where)->order($order)->select();
                 if (!empty($_list)) {
                     $_key_array = array_merge($_key_array, $_list);
                 }
                 $getLastSql[] = \Content\Model\ContentModel::getInstance($modelid)->getLastSql();
             }
         } else {
             $relations = explode('|', $data['relation']);
             $relations = array_diff($relations, array(null));
             $where['id'] = array('IN', $relations);
             $_key_array = $this->db->relation($data['moreinfo'] ? true : false)->where($where)->limit($limit)->order($order)->select();
             $getLastSql[] = $this->db->getLastSql();
         }
         foreach ($_key_array as $r) {
             $key = $r['catid'] . '_' . $r['id'];
             $key_array[$key] = $r;
             //调用副表的数据
             if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
                 $this->db->dataMerger($key_array[$key]);
             }
             if ($data['output']) {
                 $_original = $key_array[$key];
                 $key_array[$key] = ShuipFCMS()->ContentOutput->get($key_array[$key]);
                 $key_array[$key]['_original'] = $_original;
             }
         }
         $number = count($key_array);
         //删除id条件
         if (isset($where['id'])) {
             unset($where['id']);
         }
     }
     //根据关键字,进行标题匹配
     if ($data['keywords'] && $limit > $number) {
         //根据关键字的相关文章
         $limit = $limit - $number <= 0 ? 0 : $limit - $number;
         $keywords_arr = $data['keywords'];
         if ($keywords_arr && !is_array($keywords_arr)) {
             if (strpos($data['keywords'], ',') === false) {
                 $keywords_arr = explode(' ', $data['keywords']);
             } else {
                 $keywords_arr = explode(',', $data['keywords']);
             }
         }
         $i = 1;
         foreach ($keywords_arr as $_k) {
             $_k = str_replace('%', '', $_k);
             $where['keywords'] = array("LIKE", '%' . $_k . '%');
             $_r = $this->db->relation($data['moreinfo'] ? true : false)->where($where)->limit($limit)->order($order)->select();
             $getLastSql[] = $this->db->getLastSql();
             //数据重组
             $r = array();
             foreach ($_r as $rs) {
                 $r[$rs['id']] = $rs;
                 //调用副表的数据
                 if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) {
                     $this->db->dataMerger($r[$rs['id']]);
                 }
                 if ($data['output']) {
                     $_original = $r[$rs['id']];
                     $r[$rs['id']] = ShuipFCMS()->ContentOutput->get($r[$rs['id']]);
                     $r[$rs['id']]['_original'] = $_original;
                 }
             }
             $number += count($r);
             foreach ($r as $id => $v) {
                 $key = $v['catid'] . '_' . $v['id'];
                 if ($i <= $data['num'] && !in_array($id, $key_array)) {
                     $key_array[$key] = $v;
                 }
                 $i++;
             }
             if ($data['num'] < $number) {
                 break;
             }
         }
         unset($where['keywords']);
     }
     //去除排除信息
     if ($data['nid']) {
         $key = $data['catid'] . '_' . $data['nid'];
         unset($key_array[$key]);
     }
     //结果进行缓存
     if ($cache) {
         S($cacheID, $key_array, $cache);
     }
     if (APP_DEBUG) {
         $msg = "Content标签->relation:参数:catid={$catid} ,modelid={$modelid} ,order={$data['order']}\n";
         $msg .= "SQL:" . implode("\n", $getLastSql);
         \Think\Log::record($msg, \Think\Log::DEBUG);
     }
     return $key_array;
 }
Ejemplo n.º 12
0
 /**
  * 获取标题图片
  * @param type $data
  */
 protected function getThumb(&$data)
 {
     $model = ContentModel::getInstance($this->modelid);
     //取得副表下标
     $getRelationName = $model->getRelationName();
     //自动提取缩略图,从content 中提取
     if (empty($data['thumb'])) {
         $isContent = isset($data['content']) ? 1 : 0;
         $content = $isContent ? $data['content'] : $data[$getRelationName]['content'];
         $auto_thumb_no = I('.auto_thumb_no', 1, 'intval') - 1;
         if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+\\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
             $data['thumb'] = $matches[3][$auto_thumb_no];
         }
     }
 }
Ejemplo n.º 13
0
/**
 * 标题链接获取
 * @param type $catid 栏目id
 * @param type $id 信息ID
 * @return type 链接地址
 */
function titleurl($catid, $id)
{
    return \Content\Model\ContentModel::getInstance(getCategory($catid, 'modelid'))->where(array('id' => $id))->getField("url");
}
Ejemplo n.º 14
0
 /**
  * 更新信息推荐位状态
  * @param type $id 信息id
  * @param type $modelid 模型id
  * @return type
  */
 public function contentPos($id, $modelid)
 {
     $id = intval($id);
     $modelid = intval($modelid);
     $info = $this->where(array('id' => $id, 'modelid' => $modelid))->find();
     if ($info) {
         $posids = 1;
     } else {
         $posids = 0;
     }
     //更改文章推荐位状态
     $status = ContentModel::getInstance($modelid)->where(array('id' => $id))->save(array('posid' => $posids));
     if (false !== $status && $status > 0) {
         return true;
     } else {
         //有可能副表
         $tablename = ucwords(getModel($modelid, 'tablename'));
         if ($this->field_exists("{$tablename}_data", 'posid')) {
             return M($tablename . 'Data')->where(array('id' => $id))->save(array('posid' => $posids)) !== false ? true : false;
         }
         return false;
     }
 }
Ejemplo n.º 15
0
 public function push()
 {
     if (IS_POST) {
         $id = I('post.id');
         $modelid = I('post.modelid');
         $catid = I('post.catid');
         $action = I('get.action');
         if (!$id || !$action || !$modelid || !$catid) {
             $this->error('参数不正确');
         }
         switch ($action) {
             //推荐位
             case "position_list":
                 $posid = $_POST['posid'];
                 if ($posid && is_array($posid)) {
                     $position_data_db = D('Content/Position');
                     $ModelField = cache('ModelField');
                     $fields = $ModelField[$modelid];
                     $ids = explode('|', $id);
                     $model = ContentModel::getInstance($modelid);
                     foreach ($ids as $k => $aid) {
                         //取得信息
                         $re = $model->relation(true)->where(array('id' => $aid))->find();
                         if ($re) {
                             $model->dataMerger($re);
                             //推送数据
                             $textcontent = array();
                             foreach ($fields as $_value) {
                                 $field = $_value['field'];
                                 //判断字段是否入库到推荐位字段
                                 if ($_value['isposition']) {
                                     $textcontent[$field] = $re[$field];
                                 }
                             }
                             //样式进行特别处理
                             $textcontent['style'] = $re['style'];
                             //推送到推荐位
                             $position_data_db->positionUpdate($aid, $modelid, $catid, $posid, $textcontent, 0, 1);
                             $r = $re = null;
                         }
                     }
                     $this->success('推送到推荐位成功!');
                 } else {
                     $this->error('请选择推荐位!');
                 }
                 break;
                 //同步发布到其他栏目
             //同步发布到其他栏目
             case 'push_to_category':
                 $ids = explode('|', $id);
                 $relation = I('post.relation');
                 if (!$relation) {
                     $this->error('请选择需要推送的栏目!');
                 }
                 $relation = explode('|', $relation);
                 if (is_array($relation)) {
                     //过滤相同栏目和自身栏目
                     foreach ($relation as $k => $classid) {
                         if ($classid == $catid) {
                             $this->error('推送的栏目不能是当前栏目!');
                         }
                     }
                     //去除重复
                     $relation = array_unique($relation);
                     if (count($relation) < 1) {
                         $this->error('请选择需要推送的栏目!');
                     }
                     $model = ContentModel::getInstance($modelid);
                     foreach ($ids as $k => $aid) {
                         //取得信息
                         $r = $model->relation(true)->where(array('id' => $aid))->find();
                         $linkurl = $r['url'];
                         if ($r) {
                             $this->Content->othor_catid($relation, $linkurl, $r, $modelid);
                         }
                     }
                     $this->success('推送其他栏目成功!');
                 } else {
                     $this->error('请选择需要推送的栏目!');
                 }
                 break;
             default:
                 $this->error('请选择操作!');
                 break;
         }
     } else {
         $id = I('get.id');
         $action = I('get.action');
         $modelid = I('get.modelid');
         $catid = I("get.catid");
         if (!$id || !$action || !$modelid || !$catid) {
             $this->error('参数不正确!');
         }
         $tpl = $action == 'position_list' ? 'push_list' : 'push_to_category';
         switch ($action) {
             //推荐位
             case 'position_list':
                 $position = cache('Position');
                 if (!empty($position)) {
                     $array = array();
                     foreach ($position as $_key => $_value) {
                         //如果有设置模型,检查是否有该模型
                         if ($_value['modelid'] && !in_array($modelid, explode(',', $_value['modelid']))) {
                             continue;
                         }
                         //如果设置了模型,又设置了栏目
                         if ($_value['modelid'] && $_value['catid'] && !in_array($catid, explode(',', $_value['catid']))) {
                             continue;
                         }
                         //如果设置了栏目
                         if ($_value['catid'] && !in_array($catid, explode(',', $_value['catid']))) {
                             continue;
                         }
                         $array[$_key] = $_value['name'];
                     }
                     $this->assign('Position', $array);
                 }
                 break;
                 //同步发布到其他栏目
             //同步发布到其他栏目
             case 'push_to_category':
                 break;
             default:
                 $this->error('请选择操作!');
                 break;
         }
         $this->assign('id', $id)->assign('action', $action)->assign('modelid', $modelid)->assign('catid', $catid)->assign('show_header', true)->display($tpl);
     }
 }