This commit is contained in:
2025-12-17 10:18:58 +08:00
commit ad4cb058fc
4112 changed files with 750772 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Db;
use think\Config;
use think\AjaxPage;
use think\Request;
class Ajax extends Base
{
public function _initialize() {
parent::_initialize();
}
/**
* 获取评论列表
* @return mixed
*/
public function product_comment()
{
\think\Session::pause(); // 暂停session防止session阻塞机制
$post = input('post.');
$post['aid'] = !empty($post['aid']) ? $post['aid'] : input('param.aid/d');
if (isMobile() && 1 < $post['p']) {
$Result = [];
} else {
$Result = cache('EyouHomeAjaxComment_' . $post['aid']);
if (empty($Result)) {
/*商品评论数计算*/
$where = [
'is_show' => 1,
'product_id' => $post['aid']
];
$count = Db::name('shop_order_comment')
->field('count(*) as count, total_score')
->group('total_score')
->where($where)
->select();
$Result['total'] = 0;
$Result['good'] = 0;
$Result['middle'] = 0;
$Result['bad'] = 0;
foreach ($count as $k => $v) {
$Result['total'] += $v['count'];
switch ($v['total_score']) {
case 1:
$Result['good'] = $v['count'];
break;
case 2:
$Result['middle'] = $v['count'];
break;
case 3:
$Result['bad'] = $v['count'];
break;
default:
break;
}
}
$Result['good_percent'] = $Result['good'] > 0 ? round($Result['good'] / $Result['total'] * 100) : 0;
$Result['middle_percent'] = $Result['middle'] > 0 ? round($Result['middle'] / $Result['total'] * 100) : 0;
$Result['bad_percent'] = $Result['bad'] > 0 ? 100 - $Result['good_percent'] - $Result['middle_percent'] : 0;
// $Result['good_percent'] = $Result['good_percent'] . "%";
// $Result['middle_percent'] = $Result['middle_percent'] . "%";
// $Result['bad_percent'] = $Result['bad_percent'] . "%";
// 存在评论则执行
if (!empty($Result)) cache('EyouHomeAjaxComment_' . $post['aid'], $Result, null, 'shop_order_comment');
}
/*选中状态*/
$Result['Class_1'] = 0 == $post['score'] ? 'check' : '';
$Result['Class_2'] = 1 == $post['score'] ? 'check' : '';
$Result['Class_3'] = 2 == $post['score'] ? 'check' : '';
$Result['Class_4'] = 3 == $post['score'] ? 'check' : '';
}
// 调用评价列表
$this->GetCommentList($post);
$this->assign('Result', $Result);
return $this->fetch('system/product_comment');
}
// 手机端加载更多时调用
public function comment_list()
{
\think\Session::pause(); // 暂停session防止session阻塞机制
// 调用评价列表
$this->GetCommentList(input('post.'));
return $this->fetch('system/comment_list');
}
// 调用评价列表
private function GetCommentList($post = [])
{
/*商品评论数据处理*/
$field = 'a.*, u.nickname, u.head_pic, l.level_name';
$where = [
'is_show' => 1,
'a.product_id' => $post['aid']
];
if (!empty($post['score'])) $where['a.total_score'] = $post['score'];
$count = Db::name('shop_order_comment')->alias('a')->where($where)->count();
$Page = new AjaxPage($count, 5);
$Comment = Db::name('shop_order_comment')
->alias('a')
->field($field)
->where($where)
->join('__USERS__ u', 'a.users_id = u.users_id', 'LEFT')
->join('__USERS_LEVEL__ l', 'u.level = l.level_id', 'LEFT')
->order('a.comment_id desc')
->limit($Page->firstRow . ',' . $Page->listRows)
->select();
$Comment = !empty($Comment) ? $Comment : [];
foreach ($Comment as &$value) {
// 会员头像处理
$value['head_pic'] = handle_subdir_pic(get_head_pic($value['head_pic']));
// 评价转换星级评分
$value['total_score'] = GetScoreArray($value['total_score']);
// 评价上传的图片
$value['upload_img'] = !empty($value['upload_img']) ? explode(',', unserialize($value['upload_img'])) : '';
// 评价的内容
$value['content'] = !empty($value['content']) ? htmlspecialchars_decode(unserialize($value['content'])) : '';
}
// 加载渲染模板
$this->assign('Page', $Page->show());
$this->assign('Comment', $Comment);
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Article extends Base
{
// 模型标识
public $nid = 'article';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$result = model('Article')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
}

View File

@@ -0,0 +1,916 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 陈风任 <491085389@qq.com>
* Date: 2019-7-30
*/
namespace app\home\controller;
use think\Db;
use think\Config;
use app\home\logic\AskLogic;
class Ask extends Base
{
public $users = [
'users_id' => 0,
'admin_id' => 0,
'nickname' => '游客',
];
public $users_id = 0;
public $nickname = '游客';
public $parent_id = -1;
public $users_money = 0;
public $AskModel;
public function _initialize()
{
parent::_initialize();
$this->AskModel = new \app\home\model\Ask;
/*问答本身的URL模式*/
$ask_seo_pseudo = tpCache('ask.seo_pseudo');
/*切换伪静态之后动态URL跳到伪静态问答首页*/
// if ('index' == $this->request->action()) {
// $url = $this->request->url();
// if (3 == $ask_seo_pseudo && stristr($url, '&c=') && stristr($url, '&a=')) {
// $url = url('home/Ask/index');
// $this->redirect($url);
// }
// }
/*end*/
// 头像处理
$this->users['head_pic'] = get_head_pic();
// 问题表
$this->ask_db = Db::name('ask');
// 答案表
$this->ask_answer_db = Db::name('ask_answer');
// 问题回答点赞表
$this->ask_answer_like_db = Db::name('ask_answer_like');
// 问答业务层
$this->AskLogic = new AskLogic;
// 问答数据层
$this->AskModel = model('Ask');
/*获取最新的会员信息*/
$LatestData = $this->GetUsersLatestData();
if (!empty($LatestData)) {
// 会员全部信息
$this->users = $LatestData;
// 会员ID
$this->users_id = $LatestData['users_id'];
// 会员昵称
$this->nickname = $LatestData['nickname'];
$this->users_money = $LatestData['users_money'];
// 后台管理员信息
$this->parent_id = session('admin_info.parent_id');
} else {
//过滤不需要登陆的行为
$ctl_act = CONTROLLER_NAME . '@' . ACTION_NAME;
$ctl_all = CONTROLLER_NAME . '@*';
$filter_login_action = [
'Lists@index', // 问答内容列表
'Ask@index', // 问答内容列表
'Ask@details', // 问答详情
];
if (!in_array($ctl_act, $filter_login_action) && !in_array($ctl_all, $filter_login_action)) {
if (IS_AJAX) {
if (empty($this->users)) {
$this->error('请先登录!');
}
} else {
if (isWeixin()) {
//微信端
$this->redirect('user/Users/users_select_login');
exit;
} else {
// 其他端
$this->redirect('user/Users/login');
exit;
}
}
}
}
/* END */
/*加载到模板*/
$this->assign('users', $this->users);
$this->assign('nickname', $this->nickname);
$this->assign('AdminParentId', $this->parent_id);
/* END */
/*会员功能是否开启*/
$logut_redirect_url = '';
$msg = '';
$this->usersConfig = getUsersConfigData('all');
$web_users_switch = tpCache('web.web_users_switch');
if (empty($web_users_switch) || isset($this->usersConfig['users_open_register']) && $this->usersConfig['users_open_register'] == 1) {
// 前台会员中心已关闭
$logut_redirect_url = ROOT_DIR . '/';
$msg = '会员中心尚未开启!';
} else if (session('?users_id') && empty($this->users)) {
// 登录的会员被后台删除,立马退出会员中心
$logut_redirect_url = url('user/Users/centre');
$msg = '当前用户名不存在!';
}
if (!empty($logut_redirect_url)) {
// 清理session并回到首页
session('users_id', null);
session('users', null);
$this->error($msg, $logut_redirect_url);
exit;
}
/* END */
}
/**
* 问答首页
*/
public function index()
{
$functionLogic = new \app\common\logic\FunctionLogic;
$functionLogic->validate_authorfile(2);
$param = input('param.');
// 查询条件处理
$Where = $this->AskLogic->GetAskWhere($param, $this->parent_id);
// Url处理
$UrlData = $this->AskLogic->GetUrlData($param);
// 最新问题默认读取20条可传入条数及字段名称进行获取
$ResultAsk = $this->AskModel->GetNewAskData($Where);
// 栏目处理
$TypeData = $this->AskModel->GetAskTypeData($param);
//贡献榜(积分)score
$ScoreList = $this->AskModel->GetOrderList();
//财富榜(金币)money
$MoneyList = $this->AskModel->GetOrderList('money');
//QQ群信息
$QqInfo = $this->AskModel->getQq();
// 主页SEO信息
$type_id = !empty($param['type_id']) ? intval($param['type_id']) : 0;
$SeoData = $this->AskLogic->GetSeoData($type_id);
// 数组合并加载到模板
$result = array_merge($ResultAsk, $UrlData, $TypeData, $SeoData);
// dump($result);exit();
$result['ScoreList'] = $ScoreList;
$result['MoneyList'] = $MoneyList;
$result['Qq'] = $QqInfo;
$eyou = array(
'field' => $result,
);
$this->assign('eyou', $eyou);
return $this->fetch(TEMPLATE_PATH . $this->theme_style_path . DS . 'ask' . DS . 'index.' . $this->view_suffix);
}
/**
* 问题详情页
*/
public function details()
{
$param = input('param.');
if (empty($param['ask_id'])) $this->error('请选择浏览的问题');
// 增加问题浏览点击量
$this->AskModel->UpdateAskClick($param['ask_id']);
// 问题详情数据
$AskDetails = $this->AskModel->GetAskDetailsData($param, $this->parent_id, $this->users_id);
if (0 == $AskDetails['code']) $this->error($AskDetails['msg']);
// 问题回答数据,包含最佳答案
$AskReplyData = $this->AskModel->GetAskReplyData($param, $this->parent_id);
// 栏目处理
$TypeData = $this->AskModel->GetAskTypeData($param);
// 热门帖子,周榜
$WeekList = $this->AskModel->GetAskWeekListData();
// 热门帖子,总榜
$TotalList = $this->AskModel->GetAskTotalListData();
// Url处理
$UrlData = $this->AskLogic->GetUrlData($param);
//QQ群信息
$QqInfo = $this->AskModel->getQq();
// 数组合并加载到模板
$result = array_merge($AskDetails, $AskReplyData, $TypeData, $WeekList, $TotalList, $UrlData);
$result['Qq'] = $QqInfo;
$eyou = array(
'field' => $result,
);
$this->assign('eyou', $eyou);
// return $this->fetch($this->Code . THEME_STYLE . '/details');
return $this->fetch(TEMPLATE_PATH . $this->theme_style_path . DS . 'ask' . DS . 'details.' . $this->view_suffix);
}
// 提交问题
public function add_ask()
{
if (IS_AJAX_POST || IS_POST) {
$param = input('param.');
// 是否登录、是否允许发布问题、数据判断及处理,返回内容数据
$content = $this->ParamDealWith($param);
/*添加数据*/
$AddAsk = [
'type_id' => $param['ask_type_id'],
'users_id' => $this->users_id,
'ask_title' => $param['title'],
'money' => $param['money'],
'content' => $content,
'users_ip' => clientIP(),
'add_time' => getTime(),
'update_time' => getTime(),
];
// 如果这个会员组属于需要审核的,则追加
if (1 == $this->users['ask_is_review']) $AddAsk['is_review'] = 0;
/* END */
if ($param['money'] > 0 && $param['money'] > $this->users['users_money']){
$this->error('余额不足以抵扣悬赏金额,请充值!');
}
$ResultId = $this->ask_db->add($AddAsk);
if (!empty($ResultId)) {
// //悬赏 积分奖励记录
$this->AskModel->setScore($this->users_id, $ResultId,0,1,$param['money']);
$url = $this->AskLogic->GetUrlData($param, 'NewDateUrl');
if (1 == $this->users['ask_is_review']) {
$this->success('回答成功,但你的回答需要管理员审核!', $url, ['review' => true]);
} else {
$this->success('发布成功!', $url);
}
} else {
$this->error('发布的信息有误,请检查!');
}
}
// 是否允许发布问题
$this->IsRelease();
// 栏目处理
$result = $this->AskModel->GetAskTypeData(null, 'add_ask');
$result['SubmitAddAsk'] = $this->AskLogic->GetUrlData(null, 'SubmitAddAsk');
$result['users_money'] = $this->users_money;
// 主页SEO信息
$SeoData = $this->AskLogic->GetSeoData(0);
// 数组合并加载到模板
$result = array_merge($result, $SeoData);
$eyou = array(
'field' => $result,
);
$this->assign('eyou', $eyou);
return $this->fetch(TEMPLATE_PATH . $this->theme_style_path . DS . 'ask' . DS . 'add_ask.' . $this->view_suffix);
}
// 编辑问题
public function edit_ask()
{
if (IS_AJAX_POST || IS_POST) {
$param = input('param.');
// 是否登录、是否允许发布问题、数据判断及处理,返回内容数据
$content = $this->ParamDealWith($param, false);
$ori_money = Db::name('ask')->where('ask_id', $param['ask_id'])->getField('money');
if ($ori_money > $param['money']) {
$this->error('悬赏金额不能小于' . $ori_money . '元!');
}
if ($param['money'] > 0 && $param['money'] > $this->users['users_money']){
$this->error('余额不足以抵扣悬赏金额,请充值!');
}
/*添加数据*/
$UpAsk = [
'type_id' => $param['ask_type_id'],
'ask_title' => $param['title'],
'money' => $param['money'],
'content' => $content,
'users_ip' => clientIP(),
'update_time' => getTime(),
];
// 如果这个会员组属于需要审核的,则追加
if (1 == $this->users['ask_is_review']) $UpAsk['is_review'] = 0;
/* END */
/*条件处理*/
$where['ask_id'] = $param['ask_id'];
// 不是后台管理则只能修改自己的问题
if (empty($this->users['admin_id'])) $where['users_id'] = $this->users_id;
/* END */
$ResultId = $this->ask_db->where($where)->update($UpAsk);
if (!empty($ResultId)) {
if ($ori_money < $param['money']) {
$this->AskModel->updateMoney($this->users_id, $param['money'], $ori_money, $param['ask_id']);
}
$url = $this->AskLogic->GetUrlData($param, 'AskDetailsUrl');
$this->success('编辑成功!', $url);
} else {
$this->error('编辑的信息有误,请检查!');
}
}
// 是否允许发布问题
$this->IsRelease(false);
$ask_id = input('ask_id/d');
$where['ask_id'] = $ask_id;
// 不是后台管理则只能修改自己的问题
if (empty($this->users['admin_id'])) $where['users_id'] = $this->users_id;
$Info = $this->ask_db->where($where)->find();
if (empty($Info)) $this->error('请选择编辑的问题!');
// 栏目处理
$result = $this->AskModel->GetAskTypeData($Info, 'edit_ask');
$result['Info'] = $Info;
$result['EditAskUrl'] = $this->AskLogic->GetUrlData(['ask_id' => $ask_id], 'EditAskUrl');
$result['users_money'] = $this->users_money;
$eyou = array(
'field' => $result,
);
$this->assign('eyou', $eyou);
// return $this->fetch($this->Code . THEME_STYLE . '/edit_ask');
return $this->fetch(TEMPLATE_PATH . $this->theme_style_path . DS . 'ask' . DS . 'edit_ask.' . $this->view_suffix);
}
// 采纳最佳答案
public function ajax_best_answer()
{
if (IS_AJAX_POST) {
if (!empty($this->users['admin_id']) || $this->users_id = input('post.users_id/d')) {
$param = input('param.');
// 数据判断处理
if (empty($param['answer_id']) || empty($param['ask_id'])) $this->error('请选择采纳的回答!');
// 更新问题数据表
$Updata = [
'ask_id' => $param['ask_id'],
'status' => 1,
'solve_time' => getTime(),
'bestanswer_id' => $param['answer_id'],
'update_time' => getTime(),
];
$ResultId = $this->ask_db->update($Updata);
if (!empty($ResultId)) {
// 将这个问题下的所有答案设置为非最佳答案
$this->ask_answer_db->where('ask_id', $param['ask_id'])->update(['is_bestanswer' => 0]);
// 设置当前问题为最佳答案
$this->ask_answer_db->where('answer_id', $param['answer_id'])->update(['is_bestanswer' => 1]);
$money = $this->ask_db->where('ask_id', $param['ask_id'])->value('money');
if (0 < $money) {
$answer_user_id = $this->ask_answer_db->where('answer_id', $param['answer_id'])->value('users_id');
//悬赏金额插入记录
$this->AskModel->setMoney($answer_user_id, $money, $param['ask_id'], $param['answer_id']);
}
$this->success('已采纳!');
} else {
$this->error('请选择采纳的回答!');
}
} else {
$this->error('无操作权限!');
}
}
}
// 添加回答
public function ajax_add_answer()
{
if (IS_AJAX_POST || IS_POST) {
$param = input('param.');
// 是否登录、是否允许发布问题、数据判断及处理,返回内容数据
$content = $this->AnswerDealWith($param, false);
/*添加数据*/
$AddAnswer = [
'ask_id' => $param['ask_id'],
// 如果这个会员组属于需要审核的,则追加。 默认1为已审核
'is_review' => 1 == $this->users['ask_is_review'] ? 0 : 1,
'type_id' => $param['type_id'],
'users_id' => $this->users_id,
'username' => $this->users['username'],
'users_ip' => clientIP(),
'content' => $content,
// 若是回答答案则追加数据
'answer_pid' => !empty($param['answer_id']) ? $param['answer_id'] : 0,
// 用户则追加数据
'at_users_id' => !empty($param['at_users_id']) ? $param['at_users_id'] : 0,
'at_answer_id' => !empty($param['at_answer_id']) ? $param['at_answer_id'] : 0,
'add_time' => getTime(),
'update_time' => getTime(),
];
$ResultId = $this->ask_answer_db->add($AddAnswer);
/* END */
if (!empty($ResultId)) {
$ask_users_id = Db::name('ask')->where('ask_id',$param['ask_id'])->getField('users_id');
if ($ask_users_id != $this->users_id){
//回答加积分 自问自答不加积分
$this->AskModel->setScore($this->users_id, $param['ask_id'], $ResultId, 2);
}
// 增加问题回复数
$this->AskModel->UpdateAskReplies($param['ask_id'], true);
if (1 == $this->users['ask_is_review']) {
$this->success('回答成功,但你的回答需要管理员审核!', null, ['review' => true]);
} else {
$AddAnswer['answer_id'] = $ResultId;
$AddAnswer['head_pic'] = $this->users['head_pic'];
$AddAnswer['at_usersname'] = '';
if (!empty($AddAnswer['at_users_id'])) {
$FindData = Db::name('users')->field('nickname, username')->where('users_id', $AddAnswer['at_users_id'])->find();
$AddAnswer['at_usersname'] = empty($FindData['nickname']) ? $FindData['username'] : $FindData['nickname'];
}
$ResultData = $this->AskLogic->GetReplyHtml($AddAnswer);
$this->success('回答成功!', null, $ResultData);
}
} else {
$this->error('提交信息有误,请刷新重试!');
}
}
}
// 编辑回答
public function ajax_edit_answer()
{
if (IS_AJAX_POST || IS_POST) {
$param = input('param.');
// 是否登录、是否允许发布问题、数据判断及处理,返回内容数据
$content = $this->AnswerDealWith($param, false);
/*编辑数据*/
$UpAnswerData = [
'content' => $content,
'users_ip' => clientIP(),
'update_time' => getTime(),
];
// 如果这个会员组属于需要审核的,则追加
if (1 == $this->users['ask_is_review']) $UpAnswerData['is_review'] = 0;
/* END */
// 更新条件
$where = [
'answer_id' => $param['answer_id'],
'ask_id' => $param['ask_id'],
];
if (empty($this->users['admin_id'])) $where['users_id'] = $this->users_id;
// 更新数据
$ResultId = $this->ask_answer_db->where($where)->update($UpAnswerData);
if (!empty($ResultId)) {
$url = $this->AskLogic->GetUrlData($param, 'AskDetailsUrl');
if (1 == $this->users['ask_is_review']) {
$this->success('编辑成功,但你的回答需要管理员审核!', $url, ['review' => true]);
} else {
$this->success('编辑成功!', $url);
}
} else {
$this->error('编辑的信息有误,请检查!');
}
}
// 是否允许发布问题
$this->IsAnswer(false);
$answer_id = input('param.answer_id/d');
$where = [
'a.answer_id' => $answer_id,
];
if (empty($this->users['admin_id'])) {
$where['a.users_id'] = $this->users_id;
}
$AnswerData = $this->ask_answer_db->field('a.answer_id, a.ask_id, a.content, b.ask_title')
->alias('a')
->join('ask b', 'a.ask_id = b.ask_id', 'LEFT')
->where($where)
->find();
if (empty($AnswerData)) $this->error('要修改的回答不存在!');
// 更新人
$AnswerData['nickname'] = $this->nickname;
$result['Info'] = $AnswerData;
$result['EditAnswerUrl'] = $this->AskLogic->GetUrlData(['answer_id' => $answer_id], 'EditAnswer');
$eyou = array(
'field' => $result,
);
$this->assign('eyou', $eyou);
// return $this->fetch($this->Code . THEME_STYLE . '/edit_answer');
return $this->fetch(TEMPLATE_PATH . $this->theme_style_path . DS . 'ask' . DS . 'edit_answer.' . $this->view_suffix);
}
// 删除问题、回答
public function ajax_del_answer()
{
if (IS_AJAX_POST) {
// 是否登录
$this->UsersIsLogin();
/*数据判断*/
$type = input('param.type/d');
$ask_id = input('param.ask_id/d');
$answer_id = input('param.answer_id/d');
if (isset($type) && 3 == $type) {
// 删除整条回复内容
$answer_id = input('param.id/d');
} else if (isset($type) && 1 == $type) {
// 删除整个提问问题则执行
$this->DelAsk(input('param.'));
}
if (empty($answer_id) || empty($ask_id)) $this->error('请选择删除信息!');
/* END */
/*删除条件*/
$Where = [
'ask_id' => $ask_id,
'answer_id' => $answer_id,
];
// 若操作人为后台管理员则允许删除所有人的评论回答
if (empty($this->users['admin_id'])) $where['users_id'] = $this->users_id;
/* END */
/*执行删除*/
if (isset($type) && 3 == $type) {
// 整条评论回答,算计整个评论有多少条数量
$CountWhere['answer_pid'] = $answer_id;
// 查询整条回答的评论数量
$DelNum = $this->ask_answer_db->where($Where)->whereOr($CountWhere)->count();
// 删除
$ResultId = $this->ask_answer_db->where($Where)->whereOr($CountWhere)->delete();
} else {
$DelNum = 0;
// 删除
$ResultId = $this->ask_answer_db->where($Where)->delete();
}
/* END */
if (!empty($ResultId)) {
// 减少问题回复数
$this->AskModel->UpdateAskReplies($ask_id, false, $DelNum);
$this->success('删除成功!');
} else {
$this->error('删除信息错误,请刷新重试!');
}
}
}
// 删除整个提问问题
public function DelAsk($param = array())
{
if (empty($param['ask_id']) || empty($param['id'])) $this->error('请选择要删除的提问问题!');
if (empty($this->users['admin_id'])) $this->error('无操作权限!');
/*执行删除*/
$Where['ask_id'] = $param['ask_id'];
$ResultId = $this->ask_db->where($Where)->delete();
if (!empty($ResultId)) {
// 同步删除对应问题下所有回答
$this->ask_answer_db->where($Where)->delete();
// 同步删除对应问题下所有点赞
$this->ask_answer_like_db->where($Where)->delete();
$url = $this->AskLogic->GetUrlData($param, 'NewDateUrl');
$url = $this->AskModel->RebackDel($param['ask_id']);
$this->success('删除成功!', $url);
} else {
$this->error('删除信息错误,请刷新重试!');
}
/* END */
}
// 点赞
public function ajax_click_like()
{
if (IS_AJAX_POST) {
// 是否登录
$this->UsersIsLogin();
$ask_id = input('param.ask_id/d');
$answer_id = input('param.answer_id/d');
if (empty($answer_id) || empty($ask_id)) $this->error('请选择点赞信息!');
$Where = [
'ask_id' => $ask_id,
'users_id' => $this->users_id,
'answer_id' => $answer_id,
];
$IsCount = $this->ask_answer_like_db->where($Where)->count();
if (!empty($IsCount)) {
$this->error('您已赞过!');
} else {
// 添加新的点赞记录
$AddData = [
'click_like' => 1,
'users_ip' => clientIP(),
'add_time' => getTime(),
'update_time' => getTime(),
];
$AddData = array_merge($Where, $AddData);
$ResultId = $this->ask_answer_like_db->add($AddData);
if (!empty($ResultId)) {
unset($Where['users_id']);
$LikeCount = $this->ask_answer_like_db->where($Where)->count();
if (1 == $LikeCount) {
$LikeName = '<a href="javascript:void(0);">' . $this->nickname . '</a>';
} else {
$LikeName = '<a href="javascript:void(0);">' . $this->nickname . '</a>、 ';
}
$data = [
// 点赞数
'LikeCount' => $LikeCount,
// 点赞人
'LikeName' => $LikeName,
];
// 同步点赞次数到答案表
$UpdataNew = [
'click_like' => $LikeCount,
'update_time' => getTime(),
];
$this->ask_answer_db->where($Where)->update($UpdataNew);
$this->success('点赞成功!', null, $data);
}
}
}
}
// 审核问题,仅创始人有权限
public function ajax_review_ask()
{
if (IS_AJAX_POST) {
// 创始人才有权限在前台审核评论
if (0 == $this->parent_id) {
$this->UsersIsLogin();
$param = input('param.');
if (empty($param['ask_id'])) $this->error('请选择需要审核的问题!');
// 更新审核问题
$UpAakData = [
'is_review' => 1,
'update_time' => getTime(),
];
$ResultId = $this->ask_db->where('ask_id', $param['ask_id'])->update($UpAakData);
if (!empty($ResultId)) $this->success('审核成功!');
$this->error('审核失败!');
} else {
$this->error('没有操作权限!');
}
}
}
// 审核评论,仅管理员有权限
public function ajax_review_comment()
{
if (IS_AJAX_POST) {
// 创始人才有权限在前台审核评论
if (0 == $this->parent_id) {
$this->UsersIsLogin();
$param = input('param.');
if (empty($param['ask_id']) || empty($param['answer_id'])) $this->error('提交信息有误,请刷新重试!');
// 更新审核评论
$where = [
'ask_id' => $param['ask_id'],
'answer_id' => $param['answer_id'],
];
$UpAnswerData = [
'is_review' => 1,
'update_time' => getTime(),
];
$ResultId = $this->ask_answer_db->where($where)->update($UpAnswerData);
if (!empty($ResultId)) $this->success('审核成功!');
$this->error('审核失败!');
} else {
$this->error('没有操作权限!');
}
}
}
// 获取指定数量的评论数据(分页)
public function ajax_show_comment()
{
if (IS_AJAX_POST) {
$param = input('param.');
$Comment = $this->AskModel->GetAskReplyData($param, $this->parent_id);
$Data = !empty($param['is_comment']) ? $Comment['AnswerData'][0]['AnswerSubData'] : $Comment['BestAnswer'][0]['AnswerSubData'];
if (!empty($Data)) {
$ResultData = $this->AskLogic->ForeachReplyHtml($Data, $this->parent_id);
if (empty($ResultData['htmlcode'])) $this->error('没有更多数据');
$this->success('查询成功!', null, $ResultData);
} else {
$this->error('没有更多数据');
}
}
}
// 加载会员中心所需数据
private function AssignData($param = array())
{
// 是否登录
$this->UsersIsLogin();
// 主题颜色
$this->assign('usersConfig', $this->usersConfig);
$this->usersConfig['theme_color'] = $theme_color = !empty($this->usersConfig['theme_color']) ? $this->usersConfig['theme_color'] : '#ff6565'; // 默认主题颜色
$this->assign('theme_color', $theme_color);
// 是否为手机端
$is_mobile = isMobile() ? 1 : 2;
$this->assign('is_mobile', $is_mobile);
// 是否为端微信
$is_wechat = isWeixin() ? 1 : 2;
$this->assign('is_wechat', $is_wechat);
// 是否为微信端小程序
$is_wechat_applets = isWeixinApplets() ? 1 : 0;
$this->assign('is_wechat_applets', $is_wechat_applets);
// 焦点
$Focus = empty($param['method']) ? 1 : 2;
$this->assign('Focus', $Focus);
// 菜单名称
$this->MenuTitle = Db::name('users_menu')->where([
'mca' => 'home/Ask/ask_index',
'lang' => $this->home_lang,
])->getField('title');
$this->assign('MenuTitle', $this->MenuTitle);
}
// 是否登录
private function UsersIsLogin()
{
if (empty($this->users) || empty($this->users_id)) $this->error('请先登录!');
}
// 是否允许发布、编辑问题
private function IsRelease($is_add = true)
{
if (empty($this->users['ask_is_release'])) {
if (!empty($is_add)) {
$this->error($this->users['level_name'] . '不允许发布问题!');
} else {
$this->error($this->users['level_name'] . '不允许编辑问题!');
}
}
}
// 问题数据判断及处理,返回问题内容数据
private function ParamDealWith($param = [], $is_add = true)
{
// 是否登录
$this->UsersIsLogin();
// 是否允许发布、编辑
$this->IsRelease($is_add);
/*数据判断*/
$content = '';
if (empty($param)) $this->error('请提交完整信息!');
if (empty($param['title'])) $this->error('请填写问题标题!');
if (empty($param['ask_type_id'])) $this->error('请选择问题分类!');
$content = $this->AskLogic->ContentDealWith($param);
if (empty($content)) $this->error('请填写问题描述!');
// 编辑时执行判断
if (empty($is_add) && empty($param['ask_id'])) $this->error('请确认编辑问题!');
/* END */
return $content;
}
// 是否允许发布、编辑评论回复
private function IsAnswer($is_add = true)
{
if (empty($this->users['ask_is_release'])) {
if (!empty($is_add)) {
$this->error($this->users['level_name'] . '不允许回复答案!');
} else {
$this->error($this->users['level_name'] . '不允许编辑答案!');
}
}
}
// 评论回复数据处理,返回评论回复内容数据
private function AnswerDealWith($param = [], $is_add = true)
{
// 是否登录
$this->UsersIsLogin();
// 是否允许发布、编辑
$this->IsAnswer($is_add);
/*数据判断*/
if (!empty($is_add)) {
// 添加时执行判断
if (empty($param) || empty($param['ask_id'])) $this->error('提交信息有误,请刷新重试!');
} else {
// 编辑时执行判断
if (empty($is_add) && empty($param['ask_id'])) $this->error('请确认编辑问题!');
}
$content = '';
$content = $this->AskLogic->ContentDealWith($param);
if (empty($content)) $this->error('请写下你的回答!');
/* END */
return $content;
}
/**
* 获取登录的会员最新数据
*/
private function GetUsersLatestData($users_id = null)
{
$users_id = empty($users_id) ? session('users_id') : $users_id;
if (!empty($users_id)) {
/*读取的字段*/
$field = 'a.*, b.*, b.discount as level_discount';
/* END */
/*查询数据*/
$users = \think\Db::name('users')->field($field)
->alias('a')
->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
->where([
'a.users_id' => $users_id,
'a.lang' => get_home_lang(),
'a.is_activation' => 1,
'a.is_del' => 0,
])->find();
// 会员不存在则返回空
if (empty($users)) return false;
/* END */
/*会员数据处理*/
// 头像处理
$users['head_pic'] = get_head_pic($users['head_pic']);
// 昵称处理
$users['nickname'] = empty($users['nickname']) ? $users['username'] : $users['nickname'];
// 密码为空并且存在openid则表示微信注册登录密码字段更新为0可重置密码一次。
$users['password'] = empty($users['password']) && !empty($users['open_id']) ? 0 : 1;
// 删除登录密码及支付密码
unset($users['paypwd']);
// 级别处理
$LevelData = [];
if (intval($users['level_maturity_days']) >= 36600) {
$users['maturity_code'] = 1;
$users['maturity_date'] = '终身';
} else if (0 == $users['open_level_time'] && 0 == $users['level_maturity_days']) {
$users['maturity_code'] = 0;
$users['maturity_date'] = '';// 没有升级会员,置空
} else {
/*计算剩余天数*/
$days = $users['open_level_time'] + ($users['level_maturity_days'] * 86400);
// 取整
$days = ceil(($days - getTime()) / 86400);
if (0 >= $days) {
/*更新会员的级别*/
$LevelData = model('EyouUsers')->UpUsersLevelData($users_id);
/* END */
$users['maturity_code'] = 2;
$users['maturity_date'] = '';// 会员过期,置空
} else {
$users['maturity_code'] = 3;
$users['maturity_date'] = $days . ' 天';
}
/* END */
}
/* END */
// 合并数据
$LatestData = array_merge($users, $LevelData);
/*更新session*/
session('users', $LatestData);
// session('open_id', $LatestData['open_id']);
session('users_id', $LatestData['users_id']);
setcookie('users_id', $LatestData['users_id'], null);
/* END */
// 返回数据
return $LatestData;
} else {
// session中不存在会员ID则返回空
return false;
}
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Controller;
use app\common\controller\Common;
use think\Db;
use think\Request;
use app\home\logic\FieldLogic;
class Base extends Common {
public $fieldLogic;
/**
* 初始化操作
*/
public function _initialize() {
parent::_initialize();
$this->fieldLogic = new FieldLogic();
// 设置URL模式
set_home_url_mode();
// 子目录
$this->assign('RootDir', ROOT_DIR);
}
/**
* 301重定向到新的伪静态格式针对被搜索引擎收录的旧伪静态URL
* @param intval $id 栏目ID/文档ID
* @param string $dirname 目录名称
* @param string $type 栏目页/文档页
* @return void
*/
public function jumpRewriteFormat($id, $dirname = null, $type = 'lists')
{
$seo_pseudo = config('ey_config.seo_pseudo');
$seo_rewrite_format = config('ey_config.seo_rewrite_format');
if (3 == $seo_pseudo && 1 == $seo_rewrite_format) {
if ('lists' == $type) {
$url = typeurl('home/Lists/index', array('dirname'=>$dirname));
} else {
$url = arcurl('home/View/index', array('dirname'=>$dirname, 'aid'=>$id));
}
//重定向到指定的URL地址 并且使用301
$this->redirect($url, 301);
}
}
}

View File

@@ -0,0 +1,792 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Db;
use think\template\driver\File;
class Buildhtml extends Base
{
public function _initialize()
{
parent::_initialize();
}
/*
* 清理缓存
*/
private function clearCache()
{
cache("channel_page_total_serialize", null);
cache("channel_info_serialize", null);
cache("has_children_Row_serialize", null);
cache("article_info_serialize", null);
cache("article_page_total_serialize", null);
cache("article_tags_serialize", null);
cache("article_attr_info_serialize", null);
cache("article_children_row_serialize", null);
}
/*
* 获取全站生成时,需要生成的页面的个数
*/
public function buildIndexAll()
{
$this->clearCache();
$channelData = $this->getChannelData(0);
$articleData = $this->getArticleData(0, 0);
$msg = $this->handleBuildIndex();
$allpagetotal = 1 + $channelData['pagetotal'] + $articleData['pagetotal'];
$this->success($msg, null, ["achievepage" => 1, "channelpagetotal" => $channelData['pagetotal']
, "articlepagetotal" => $articleData['pagetotal'], "allpagetotal" => $allpagetotal]);
}
/*
* 生成首页静态页面
*/
public function buildIndex()
{
$msg = $this->handleBuildIndex();
$this->success($msg);
}
/*
* 处理生成首页
*/
private function handleBuildIndex()
{
/*获取当前页面URL*/
$result['pageurl'] = $this->request->domain() . ROOT_DIR;
/*--end*/
$eyou = array(
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
$msg = '';
try {
$savepath = './index.html';
$tpl = 'index';
$this->request->get(['m' => 'Index']); // 首页焦点
$this->filePutContents($savepath, $tpl, 'pc', 0, '/', 0, 1, $result);
// $msg .= '<span>index.html生成成功</span><br>';
} catch (\Exception $e) {
$msg .= '<span>index.html生成失败' . $e->getMessage() . '</span><br>';
}
return $msg;
}
/*
* 写入静态页面
*/
private function filePutContents($savepath, $tpl, $model = 'pc', $pages = 0, $dir = '/', $tid = 0, $top = 1, $result = [])
{
ob_start();
static $templateConfig = null;
null === $templateConfig && $templateConfig = \think\Config::get('template');
$templateConfig['view_path'] = "./template/".TPL_THEME."pc/";
$template = "./template/".TPL_THEME."{$model}/{$tpl}.{$templateConfig['view_suffix']}";
$content = $this->fetch($template, [], [], $templateConfig);
/*解决模板里没有设置编码的情况*/
if (!stristr($content, 'utf-8')) {
$content = str_ireplace('<head>', "<head>\n<meta charset='utf-8'>", $content);
}
/*end*/
if ($pages > 0) {
$page = "/<a(.*?)href(\s*)=(\s*)[\'|\"](.*?)page=([0-9]*)(.*?)data-ey_fc35fdc=[\'|\"]html[\'|\"](.*?)>/i";
preg_match_all($page, $content, $matchpage);
$dir = trim($dir, '.');
foreach ($matchpage[0] as $key1 => $value1) {
if ($matchpage[5][$key1] == 1) {
if ($top == 1) {
$url = $dir;
} elseif ($top == 2) {
$url = $dir . '/lists_' . $tid . '.html';
} else {
$url = $dir . '/lists_' . $tid . '.html';
}
} else {
$url = $dir . '/lists_' . $tid . '_' . $matchpage[5][$key1] . '.html';
}
$url = ROOT_DIR . '/' . trim($url, '/');
$value1_new = preg_replace('/href(\s*)=(\s*)[\'|\"]([^\'\"]*)[\'|\"]/i', '', $value1);
$value1_new = str_replace('data-ey_fc35fdc=', " href=\"{$url}\" data-ey_fc35fdc=", $value1_new);
$content = str_ireplace($value1, $value1_new, $content);
}
}
$content = $this->pc_to_mobile_js($content, $result); // 生成静态模式下自动加上PC端跳转移动端的JS代码
echo $content;
$_cache = ob_get_contents();
ob_end_clean();
static $File = null;
null === $File && $File = new File;
$File->fwrite($savepath, $_cache);
}
/*
* 生成文档静态页面
*/
public function buildArticle()
{
function_exists('set_time_limit') && set_time_limit(0);
$typeid = input("param.id/d", 0); // 栏目ID
$fid = input("param.fid/d", 0);
$achievepage = input("param.achieve/d", 0); // 已完成文档数
$this->clearCache();
$data = $this->handelBuildArticle($typeid, 0, $fid, $achievepage);
$this->success($data[0], null, $data[1]);
}
/**
* 获取详情页数据
* $typeid 栏目id
* $aid 文章id
* $type 类型0aid指定的内容1上一篇2下一篇
*/
private function getArticleData($typeid, $aid, $type = 0)
{
$info_serialize = cache("article_info_serialize", "");
if (empty($info_serialize)) {
if ($type == 0) {
$data = getAllArchives($this->home_lang, $typeid, $aid);
} else if ($type == 1) {
$data = getPreviousArchives($this->home_lang, $typeid, $aid);
} else if ($type == 2) {
$data = getNextArchives($this->home_lang, $typeid, $aid);
}
$info = $data['info'];
$pagetotal = count($info);
$aid_arr = get_arr_column($info, 'aid');
$allTags = getAllTags($aid_arr);
$allAttrInfo = getAllAttrInfo($aid_arr);
/*获取所有栏目是否有子栏目的数组*/
$has_children_Row = model('Arctype')->hasChildren(get_arr_column($info, 'typeid'));
cache("article_info_serialize", serialize($data));
cache("article_page_total_serialize", $pagetotal);
cache("article_tags_serialize", serialize($allTags));
cache("article_attr_info_serialize", serialize($allAttrInfo));
cache("article_children_row_serialize", serialize($has_children_Row));
} else {
$data = unserialize($info_serialize);
$pagetotal = cache("article_page_total_serialize", "");
$allTags = unserialize(cache("article_tags_serialize", ""));
$allAttrInfo = unserialize(cache("article_attr_info_serialize", ""));
$has_children_Row = unserialize(cache("article_children_row_serialize", ""));
}
return ['data' => $data, 'pagetotal' => $pagetotal, 'allTags' => $allTags, 'allAttrInfo' => $allAttrInfo, 'has_children_Row' => $has_children_Row];
}
/**
* 处理生成内容页
* $typeid 栏目id
* $aid 内容页id
* $fid 下一次执行栏目id
* $achievepage 已完成文档数
* $batch 是否分批次执行true分批false不分批
* limit 每次执行多少条数据
* type 执行类型0aid指定的文档页1上一篇2下一篇
*
*/
private function handelBuildArticle($typeid, $aid = 0, $nextid = 0, $achievepage = 0, $batch = true, $limit = 20, $type = 0)
{
$msg = "";
$globalConfig = $this->eyou['global'];
$result = $this->getArticleData($typeid, $aid, $type);
$info = $result['data']['info'];
$arctypeRow = $result['data']['arctypeRow'];
$allTags = $result['allTags'];
$has_children_Row = $result['has_children_Row'];
$allAttrInfo = $result['allAttrInfo'];
$data['allpagetotal'] = $pagetotal = $result['pagetotal'];
$data['achievepage'] = $achievepage;
$data['pagetotal'] = 0;
if ($batch && $pagetotal > $achievepage) {
while ($limit && isset($info[$nextid])) {
$row = $info[$nextid];
$msg .= $msg_temp = $this->createArticle($row, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $allAttrInfo);
$data['achievepage'] += 1;
$limit--;
$nextid++;
}
$data['fid'] = $nextid;
} else if (!$batch) {
foreach ($info as $key => $row) {
$msg .= $msg_temp = $this->createArticle($row, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $allAttrInfo);
$data['achievepage'] += 1;
$data['fid'] = $key;
}
}
if ($data['allpagetotal'] == $data['achievepage']) { //生成完全部页面,删除缓存
cache("article_info_serialize", null);
cache("article_page_total_serialize", null);
cache("article_tags_serialize", null);
cache("article_attr_info_serialize", null);
cache("article_children_row_serialize", null);
}
return [$msg, $data];
}
/*
* 生成详情页静态页面
*/
private function createArticle($result, $globalConfig, $arctypeRow, $allTags, $has_children_Row, $allAttrInfo)
{
$msg = "";
$aid = $result['aid'];
static $arc_seo_description_length = null;
null === $arc_seo_description_length && $arc_seo_description_length = config('global.arc_seo_description_length');
$this->request->post(['aid' => $aid]);
$this->request->post(['tid' => $result['typeid']]);
// tags标签
$result['tags'] = empty($allTags[$aid]) ? '' : implode(',', $allTags[$aid]);
$arctypeInfo = $arctypeRow[$result['typeid']];
/*排除文档模型与栏目模型对不上的文档*/
if ($arctypeInfo['current_channel'] != $result['channel']) {
return false;
}
if (51 == $result['channel']) return false; // 问答模型
/*--end*/
$arctypeInfo = model('Arctype')->parentAndTopInfo($result['typeid'], $arctypeInfo);
/*自定义字段的数据格式处理*/
$arctypeInfo = $this->fieldLogic->getTableFieldList($arctypeInfo, config('global.arctype_channel_id'));
/*是否有子栏目,用于标记【全部】选中状态*/
$arctypeInfo['has_children'] = !empty($has_children_Row[$result['typeid']]) ? 1 : 0;
/*--end*/
// 文档模板文件,不指定文档模板,默认以栏目设置的为主
empty($result['tempview']) && $result['tempview'] = $arctypeInfo['tempview'];
/*给没有type前缀的字段新增一个带前缀的字段并赋予相同的值*/
foreach ($arctypeInfo as $key => $val) {
if (!preg_match('/^type/i', $key)) {
$key_new = 'type' . $key;
!array_key_exists($key_new, $arctypeInfo) && $arctypeInfo[$key_new] = $val;
}
}
/*--end*/
$result = array_merge($arctypeInfo, $result);
// 获取当前页面URL
$result['arcurl'] = $result['pageurl'] = '';
if ($result['is_jump'] != 1) {
$result['arcurl'] = $result['pageurl'] = arcurl('home/View/index', $result, true, true);
}
/*--end*/
// seo
$result['seo_title'] = set_arcseotitle($result['title'], $result['seo_title'], $result['typename']);
$result['seo_description'] = @msubstr(checkStrHtml($result['seo_description']), 0, $arc_seo_description_length, false);
/*支持子目录*/
$result['litpic'] = handle_subdir_pic($result['litpic']);
/*--end*/
$result = view_logic($aid, $result['channel'], $result, $allAttrInfo); // 模型对应逻辑
/*自定义字段的数据格式处理*/
$result = $this->fieldLogic->getChannelFieldList($result, $result['channel']);
/*--end*/
$eyou = array(
'type' => $arctypeInfo,
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
/*模板文件*/
$tpl = !empty($result['tempview'])
? str_replace('.' . $this->view_suffix, '', $result['tempview'])
: 'view_' . $result['nid'];
/*--end*/
$dir = $this->getArticleDir($result['dirpath']);
if (!empty($result['htmlfilename'])) {
$aid = $result['htmlfilename'];
}
$savepath = $dir . '/' . $aid . '.html';
try {
$this->filePutContents('./' . $savepath, $tpl, 'pc', 0, '/', 0, 1, $result);
} catch (\Exception $e) {
$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
}
return $msg;
}
private function getArticleDir($dirpath)
{
$dir = "";
$seo_html_pagename = $this->eyou['global']['seo_html_pagename'];
$seo_html_arcdir = $this->eyou['global']['seo_html_arcdir'];
if ($seo_html_pagename == 1) {//存放顶级目录
$dirpath_arr = explode('/', $dirpath);
if (count($dirpath_arr) > 2) {
$dir = '.' . $seo_html_arcdir . '/' . $dirpath_arr[1];
} else {
$dir = '.' . $seo_html_arcdir . $dirpath;
}
} else if ($seo_html_pagename == 3) { //存放子级目录
$dirpath_arr = explode('/', $dirpath);
if (count($dirpath_arr) > 2) {
$dir = '.' . $seo_html_arcdir . '/' . end($dirpath_arr);
} else {
$dir = '.' . $seo_html_arcdir . $dirpath;
}
} else { //存放父级目录
$dir = '.' . $seo_html_arcdir . $dirpath;
}
return $dir;
}
/*
* 生成栏目静态页面
* $id tpyeid 栏目id
* $fid 下一次执行栏目id
* $achievepage 已完成页数
*$batch 是否分批次执行true分批false不分批
*
*/
public function buildChannel()
{
function_exists('set_time_limit') && set_time_limit(0);
$id = input("param.id/d", 0); // 栏目ID
$fid = input("param.fid/d", 0);
$achievepage = input("param.achieve/d", 0);
$this->clearCache();
$data = $this->handleBuildChannel($id, $fid, $achievepage);
$this->success($data[0], null, $data[1]);
}
/*
* 获取栏目数据
* $id 栏目id
* $parent 是否获取下级栏目 true获取false不获取
*/
private function getChannelData($id, $parent = true, $aid = 0)
{
$info_serialize = cache("channel_info_serialize", "");
if (empty($info_serialize)) {
$result = getAllArctype($this->home_lang, $id, $this->view_suffix, $parent, $aid);
$info = $result["info"];
$pagetotal = $result["pagetotal"];
$has_children_Row = model('Arctype')->hasChildren(get_arr_column($info, 'typeid'));
cache("channel_page_total_serialize", $pagetotal);
cache("channel_info_serialize", serialize($info));
cache("has_children_Row_serialize", serialize($has_children_Row));
} else {
$info = unserialize($info_serialize);
$pagetotal = cache("channel_page_total_serialize", "");
$has_children_Row = unserialize(cache("has_children_Row_serialize", ""));
}
return ['info' => $info, 'pagetotal' => $pagetotal, 'has_children_Row' => $has_children_Row];
}
/*
* 处理生成栏目页
* $id typeid
* $fid 下一次执行栏目id
* $achievepage 已完成页数
* $batch 是否分批次执行true分批false不分批
* $parent 是否获取下级栏目 true获取false不获取
* $aid 文章页id不等于0时表示只获取文章页所在的列表页重新生成静态(在添加或者编辑文档内容时使用)
*/
private function handleBuildChannel($id, $fid = 0, $achievepage = 0, $batch = true, $parent = true, $aid = 0)
{
$msg = '';
$globalConfig = $this->eyou['global'];
$result = $this->getChannelData($id, $parent, $aid);
$info = $result['info'];
$has_children_Row = $result['has_children_Row'];
$data['allpagetotal'] = $pagetotal = $result['pagetotal'];
$data['achievepage'] = $achievepage;
/***********2020 05 19 过滤并删除外部链接生成的静态页面 s*************/
foreach ($info as $k => $v) {
if ($v['is_part'] == 1 || $v['nid'] == 'ask') {//外部链接或问答模型
unset($info[$k]);//从数组里移除
$dir = ROOT_PATH . trim($v['dirpath'], '/');
if (!empty($v['dirpath']) && true == is_dir($dir)) {//判断是否生成过文件夹,文件夹存在则删除
$this->deldir($dir);
}
}
}
$info = array_values($info);//重组数组
/***********2020 05 19 新增 e*************/
if ($batch && $data['allpagetotal'] > $data['achievepage']) {
$row = !empty($info[$fid]) ? $info[$fid] : [];
!empty($row) && $msg .= $msg_temp = $this->createChannel($row, $globalConfig, $has_children_Row);
$data['pagetotal'] = !empty($row['pagetotal']) ? $row['pagetotal'] : 1;
$data['achievepage'] += !empty($row['pagetotal']) ? $row['pagetotal'] : 1;
$data['fid'] = $fid + 1;
$data['typeid'] = !empty($row['typeid']) ? $row['typeid'] : 0;
} else if (!$batch) {
foreach ($info as $key => $row) {
$msg .= $msg_temp = $this->createChannel($row, $globalConfig, $has_children_Row, $aid);
$data['pagetotal'] = $row['pagetotal'];
$data['achievepage'] += $row['pagetotal'];
$data['fid'] = $key;
$data['typeid'] = $row['typeid'];
}
}
if ($data['allpagetotal'] == $data['achievepage']) { //生成完全部页面,删除缓存
cache("channel_page_total_serialize", null);
cache("channel_info_serialize", null);
cache("has_children_Row_serialize", null);
}
return [$msg, $data];
}
/*
* 生成栏目页面
*/
private function createChannel($row, $globalConfig, $has_children_Row, $aid = 0)
{
$msg = "";
$seo_html_listname = $this->eyou['global']['seo_html_listname'];
$seo_html_arcdir = $this->eyou['global']['seo_html_arcdir'];
$tid = $row['typeid'];
$this->request->post(['tid' => $tid]);
$row = $this->lists_logic($row, $has_children_Row); // 模型对应逻辑
$eyou = array(
'field' => $row,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
$tpl = !empty($row['templist']) ? str_replace('.' . $this->view_suffix, '', $row['templist']) : 'lists_' . $row['nid'];
if (in_array($row['current_channel'], [6, 8])) { //留言模型或单页模型,不存在多页
$this->request->get(['page' => '']);
$dirpath = explode('/', $eyou['field']['dirpath']);
$dirpath_end = end($dirpath);
if ($seo_html_listname == 1) { //存放顶级目录
$savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'] . ".html";
} else if ($seo_html_listname == 3) { // //存放子级目录
$savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'] . ".html";
} else {
$savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'] . ".html";
}
try {
$this->filePutContents($savepath, $tpl, 'pc', 0, '/', 0, 1, $row);
if ($seo_html_listname == 3) {
@copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
@unlink($savepath);
} else if ($seo_html_listname == 2 || count($dirpath) < 3) {
@copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
@unlink($savepath);
}
} catch (\Exception $e) {
$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
}
} else if (!empty($aid)) { //只更新aid所在的栏目页码
$orderby = getOrderBy($row['orderby'], $row['orderway']);
$limit = getLocationPages($tid, $aid, $orderby);
$i = !empty($limit) ? ceil($limit / $row['pagesize']) : 1;
$msg .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
} else { //多条信息的栏目
$totalpage = $row['pagetotal'];
for ($i = 1; $i <= $totalpage; $i++) {
$msg .= $this->createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl);
}
}
return $msg;
}
/*
* 创建有文档列表模型的静态栏目页面
*/
private function createMultipageChannel($i, $tid, $row, $has_children_Row, $seo_html_listname, $seo_html_arcdir, $tpl)
{
$msg = "";
$this->request->get(['page' => $i]);
$row = $this->lists_logic($row, $has_children_Row); // 模型对应逻辑
$eyou = array(
'field' => $row,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
$dirpath = explode('/', $eyou['field']['dirpath']);
$dirpath_end = end($dirpath);
if ($seo_html_listname == 1) { //存放顶级目录
$dir = '.' . $seo_html_arcdir . '/' . $dirpath[1];
$savepath = '.' . $seo_html_arcdir . '/' . $dirpath[1] . "/lists_" . $eyou['field']['typeid'];
} else if ($seo_html_listname == 3) { //存放子级目录
$dir = '.' . $seo_html_arcdir . '/' . $dirpath_end;
$savepath = '.' . $seo_html_arcdir . '/' . $dirpath_end . "/lists_" . $eyou['field']['typeid'];
} else {
$dir = '.' . $seo_html_arcdir . $eyou['field']['dirpath'];
$savepath = '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/' . 'lists_' . $eyou['field']['typeid'];
}
if ($i > 1) {
$savepath .= '_' . $i . '.html';;
} else {
$savepath .= '.html';
}
$top = 1;
if ($i > 1 && $seo_html_listname == 1 && count($dirpath) > 2) {
$top = 2;
} else if ($i > 1 && $seo_html_listname == 3) {
$top = 1;
}
try {
$this->filePutContents($savepath, $tpl, 'pc', $i, $dir, $tid, $top, $row);
if ($i == 1 && $seo_html_listname == 3) {
@copy($savepath, '.' . $seo_html_arcdir . '/' . $dirpath_end . '/index.html');
@unlink($savepath);
} else if ($i == 1 && ($seo_html_listname == 2 || count($dirpath) < 3)) {
@copy($savepath, '.' . $seo_html_arcdir . $eyou['field']['dirpath'] . '/index.html');
@unlink($savepath);
}
} catch (\Exception $e) {
$msg .= '<span>' . $savepath . '生成失败!' . $e->getMessage() . '</span><br>';
}
return $msg;
}
/**
* 更新静态生成页
* @param int $aid 文章id
* @param int $typeid 栏目id
* @return boolean
* $del_ids 删除的文章数组
*/
public function upHtml()
{
$aid = input("param.aid/d");
$typeid = input("param.typeid/d");
$del_ids = input('param.del_ids/a');
$type = input('param.type/s');
$lang = input("param.lang/s", 'cn');
/*由于全站共用删除JS代码这里排除不能发布文档的模型的控制器*/
$ctl_name = input("param.ctl_name/s");
$channeltypeRow = Db::name('channeltype')
->where('nid', 'NOT IN', ['guestbook', 'single'])
->column('ctl_name');
array_push($channeltypeRow, 'Archives', 'Arctype', 'Custom');
if (!in_array($ctl_name, $channeltypeRow)) {
$this->error("排除非发布文档的模型");
}
/*end*/
$seo_pseudo = $this->eyou['global']['seo_pseudo'];
$this->clearCache();
if ($seo_pseudo != 2) {
$this->error("当前非静态模式,不做静态处理");
}
if (!empty($del_ids)) { //删除文章页面
$info = Db::name('archives')->field('a.*,b.dirpath')
->alias('a')
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
->where([
'a.aid' => ['in', $del_ids],
'a.lang' => $lang,
])
->select();
foreach ($info as $key => $row) {
$dir = $this->getArticleDir($row['dirpath']);
$filename = $row['aid'];
$path = $dir . "/" . $filename . ".html";
if (file_exists($path)) {
@unlink($path);
}
}
} else if (!empty($aid) && !empty($typeid)) { //变更文档信息,更新文档页及相关的栏目页
if ('view' == $type) {
$this->handelBuildArticle($typeid, $aid, 0, 0, false, 1, 0);
$this->handelBuildArticle($typeid, $aid, 0, 0, false, 1, 1); // 更新上篇
$this->handelBuildArticle($typeid, $aid, 0, 0, false, 1, 2); // 更新下篇
} else if ('lists' == $type) {
$data = $this->handleBuildChannel($typeid, 0, 0, false, false, $aid);
// $this->handelBuildArticle($typeid,$aid,0,0,false,1,1); // 更新上篇
// $this->handelBuildArticle($typeid,$aid,0,0,false,1,2); // 更新下篇
} else {
$this->handleBuildChannel($typeid, 0, 0, false, false, $aid);
$this->handelBuildArticle($typeid, $aid, 0, 0, false);
}
} else if (!empty($typeid)) { //变更栏目信息,更新栏目页
$this->handleBuildIndex();
$data = $this->handleBuildChannel($typeid, 0, 0, false, false);
}
$this->success("静态页面生成完成");
}
/*
* 拓展页面相关信息
*/
private function lists_logic($result = [], $has_children_Row = [])
{
if (empty($result)) {
return [];
}
$tid = $result['typeid'];
switch ($result['current_channel']) {
case '6': // 单页模型
{
$arctype_info = model('Arctype')->parentAndTopInfo($tid, $result);
if ($arctype_info) {
// 读取当前栏目的内容,否则读取每一级第一个子栏目的内容,直到有内容或者最后一级栏目为止。
$archivesModel = new \app\home\model\Archives();
$result_new = $archivesModel->readContentFirst($tid);
// 阅读权限 或 外部链接跳转
if ($result_new['arcrank'] == -1 || $result_new['is_part'] == 1) {
return false;
}
/*自定义字段的数据格式处理*/
$result_new = $this->fieldLogic->getChannelFieldList($result_new, $result_new['current_channel']);
/*--end*/
$result = array_merge($arctype_info, $result_new);
$result['templist'] = !empty($arctype_info['templist']) ? $arctype_info['templist'] : 'lists_' . $arctype_info['nid'];
$result['dirpath'] = $arctype_info['dirpath'];
$result['typeid'] = $arctype_info['typeid'];
}
break;
}
default:
{
$result = model('Arctype')->parentAndTopInfo($tid, $result);
break;
}
}
if (!empty($result)) {
/*自定义字段的数据格式处理*/
$result = $this->fieldLogic->getTableFieldList($result, config('global.arctype_channel_id'));
/*--end*/
}
/*是否有子栏目,用于标记【全部】选中状态*/
$result['has_children'] = !empty($has_children_Row[$tid]) ? 1 : 0;
/*--end*/
// seo
$result['seo_title'] = set_typeseotitle($result['typename'], $result['seo_title']);
/*获取当前页面URL*/
$result['pageurl'] = $result['typeurl'];
/*--end*/
/*给没有type前缀的字段新增一个带前缀的字段并赋予相同的值*/
foreach ($result as $key => $val) {
if (!preg_match('/^type/i', $key)) {
$key_new = 'type' . $key;
!array_key_exists($key_new, $result) && $result[$key_new] = $val;
}
}
/*--end*/
return $result;
}
/**
* 生成静态模式下且PC和移动端模板分离就自动给PC端加上跳转移动端的JS代码
* @access public
*/
private function pc_to_mobile_js($html = '', $result = [])
{
if (file_exists('./template/'.TPL_THEME.'mobile')) { // 分离式模板
/*是否开启手机站域名,并且配置*/
if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
$domain = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
}
/*end*/
$aid = input('param.aid/d');
$tid = input('param.tid/d');
if (!empty($aid)) { // 内容页
$url = url('home/View/index', ['aid' => $aid], true, true, 1, 1, 0);
} else if (!empty($tid)) { // 列表页
$url = url('home/Lists/index', ['tid' => $tid], true, true, 1, 1, 0);
} else { // 首页
$url = $this->request->domain() . ROOT_DIR . '/index.php';
}
$jsStr = <<<EOF
<meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){window.location.href="{$url}";}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
EOF;
$html = str_ireplace('</head>', $jsStr . "\n</head>", $html);
} else { // 响应式模板
// 开启手机站域名,且配置
if (!empty($this->eyou['global']['web_mobile_domain_open']) && !empty($this->eyou['global']['web_mobile_domain'])) {
if (empty($result['pageurl'])) {
$url = $this->request->subDomain($this->eyou['global']['web_mobile_domain']) . ROOT_DIR . '/index.php';
} else {
$url = !preg_match('/^(http(s?):)?\/\/(.*)$/i', $result['pageurl']) ? $this->request->domain() . $result['pageurl'] : $result['pageurl'];
$url = preg_replace('/^(.*)(\/\/)([^\/]*)(\.?)(' . $this->request->rootDomain() . ')(.*)$/i', '${1}${2}' . $this->eyou['global']['web_mobile_domain'] . '.${5}${6}', $url);
}
$mobileDomain = $this->eyou['global']['web_mobile_domain'] . '.' . $this->request->rootDomain();
$jsStr = <<<EOF
<meta http-equiv="mobile-agent" content="format=xhtml;url={$url}">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/applewebkit.*mobile/i.test(navigator.userAgent.toLowerCase()) || (/midp|symbianos|nokia|samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|philips|haier|lenovo|mot-|nokia|sonyericsson|sie-|amoi|zte/.test(navigator.userAgent.toLowerCase()))){try{if(/android|windows phone|webos|iphone|ipod|blackberry/i.test(navigator.userAgent.toLowerCase())){if(window.location.toString().indexOf('{$mobileDomain}') == -1){window.location.href="{$url}";}}else if(/ipad/i.test(navigator.userAgent.toLowerCase())){}else{}}catch(e){}}}</script>
EOF;
$html = str_ireplace('</head>', $jsStr . "\n</head>", $html);
}
}
return $html;
}
/**
* 删除文件夹
* @param $dir
* @return bool
*/
public function deldir($dir)
{
//先删除目录下的文件:
$fileArr = glob($dir.'/*.html');
if (!empty($fileArr)) {
foreach ($fileArr as $key => $val) {
!empty($val) && @unlink($val);
}
}
$fileArr = glob($dir.'/*');
if(empty($fileArr)){ //目录为空
rmdir($dir); // 删除空目录
}
return true;
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Download extends Base
{
// 模型标识
public $nid = 'download';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$param = I('param.');
$aid = !empty($param['aid']) ? intval($param['aid']) : '';
if (empty($aid)) {
abort(404,'页面不存在');
}
$result = model('Download')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Cache;
class Guestbook extends Base
{
// 模型标识
public $nid = 'guestbook';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Images extends Base
{
// 模型标识
public $nid = 'images';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$result = model('Images')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
}

View File

@@ -0,0 +1,159 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use app\user\logic\PayLogic;
class Index extends Base
{
public function _initialize() {
parent::_initialize();
$this->wechat_return();
$this->alipay_return();
$this->Express100();
$this->ey_agent();
}
public function index()
{
/*处理多语言首页链接最后带斜杆进行301跳转*/
$lang = input('param.lang/s');
if (preg_match("/\?lang=".$this->home_lang."\/$/i", $this->request->url(true)) && $lang == $this->home_lang.'/') {
$langurl = $this->request->url(true);
$langurl = rtrim($langurl, '/');
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$langurl);
exit;
}
/*end*/
/*首页焦点*/
$m = input('param.m/s');
if (empty($m)) {
$this->request->get(['m'=>'Index']);
}
/*end*/
$filename = 'index.html';
$seo_pseudo = config('ey_config.seo_pseudo');
if (file_exists($filename) && 2 == $seo_pseudo && !isset($_GET['clear'])) {
if ((isMobile() && !file_exists('./template/'.TPL_THEME.'mobile')) || !isMobile()) {
header('HTTP/1.1 301 Moved Permanently');
header('Location:index.html');
exit;
}
}
/*获取当前页面URL*/
$result['pageurl'] = request()->url(true);
/*--end*/
$eyou = array(
'field' => $result,
);
//主流平台
$list = M('platform')->field('*')->where([])->order('sort desc')->select();
$this->assign('list', $list);
//案例
$case = M('casevideo')->field('*')->where([])->order('id asc')->select();
$this->assign('case', $case);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
/*模板文件*/
$viewfile = 'index';
/*--end*/
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile."_{$this->home_lang}.".$this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
}
}
/*--end*/
$html = $this->fetch(":{$viewfile}");
return $html;
}
/**
* 微信支付回调
*/
private function wechat_return()
{
// 获取回调的参数
$InputXml = file_get_contents("php://input");
if (!empty($InputXml)) {
// 解析参数
$JsonXml = json_encode(simplexml_load_string($InputXml, 'SimpleXMLElement', LIBXML_NOCDATA));
// 转换数组
$JsonArr = json_decode($JsonXml, true);
// 是否与支付成功
if (!empty($JsonArr) && 'SUCCESS' == $JsonArr['result_code'] && 'SUCCESS' == $JsonArr['return_code']) {
// 解析判断参数是否为微信支付
$attach = explode('|,|', $JsonArr['attach']);
if (!empty($attach) && 'wechat' == $attach[0] && 'is_notify' == $attach[1] && !empty($attach[2])) {
// 跳转处理回调信息
$pay_logic = new PayLogic();
$pay_logic->wechat_return($JsonArr);
}
}
}
}
/**
* 支付宝支付回调
*/
private function alipay_return()
{
$param = input('param.');
if (isset($param['transaction_type']) && isset($param['is_notify'])) {
// 跳转处理回调信息
$pay_logic = new PayLogic();
$pay_logic->alipay_return();
}
}
/**
* 快递100返回时重定向关闭父级弹框
*/
private function Express100()
{
$coname = input('param.coname/s', '');
$m = input('param.m/s', '');
if (!empty($coname) || 'user' == $m) {
if (isWeixin()) {
$this->redirect(url('user/Shop/shop_centre'));
exit;
}else{
$this->redirect(url('api/Rewrite/close_parent_layer'));
exit;
}
}
}
/**
* 无效链接跳转404
*/
private function ey_agent()
{
$ey_agent = input('param.ey_agent/d', 0);
if (!IS_AJAX && !empty($ey_agent) && 'home' == MODULE_NAME) {
abort(404, '页面不存在');
}
}
}

View File

@@ -0,0 +1,486 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Db;
use think\Verify;
class Lists extends Base
{
// 模型标识
public $nid = '';
// 模型ID
public $channel = '';
public function _initialize()
{
parent::_initialize();
}
/**
* 栏目列表
*/
public function index($tid = '')
{
$param = input('param.');
/*获取当前栏目ID以及模型ID*/
$page_tmp = input('param.page/s', 0);
if (empty($tid) || !is_numeric($page_tmp)) {
abort(404, '页面不存在');
}
$map = [];
/*URL上参数的校验*/
/* $seo_pseudo = config('ey_config.seo_pseudo');
$url_screen_var = config('global.url_screen_var');
if (!isset($param[$url_screen_var]) && 3 == $seo_pseudo)
{
if (stristr($this->request->url(), '&c=Lists&a=index&')) {
abort(404,'页面不存在');
}
$map = array('a.dirname'=>$tid);
}
else if (isset($param[$url_screen_var]) || 1 == $seo_pseudo || (2 == $seo_pseudo && isMobile()))
{
$seo_dynamic_format = config('ey_config.seo_dynamic_format');
if (1 == $seo_pseudo && 2 == $seo_dynamic_format && stristr($this->request->url(), '&c=Lists&a=index&')) {
abort(404,'页面不存在');
} else if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('a.id'=>$tid);
}else if (2 == $seo_pseudo){ // 生成静态页面代码
$map = array('a.id'=>$tid);
}*/
/*--end*/
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
$map = array('a.dirname' => $tid);
} else {
$map = array('a.id' => intval($tid));
}
$map['a.is_del'] = 0; // 回收站功能
$map['a.lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('a.id, a.current_channel, b.nid')
->alias('a')
->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
->where($map)
->find();
if (empty($row)) {
abort(404, '页面不存在');
}
$tid = $row['id'];
$this->nid = $row['nid'];
$this->channel = intval($row['current_channel']);
/*--end*/
$result = $this->logic($tid); // 模型对应逻辑
$eyou = array(
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
// dump($result);exit;
/*模板文件*/
$viewfile = !empty($result['templist'])
? str_replace('.' . $this->view_suffix, '', $result['templist'])
: 'lists_' . $this->nid;
/*--end*/
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH . $this->theme_style_path . DS . $viewfile . "_{$this->home_lang}." . $this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
}
}
/*--end*/
// /*模板文件*/
// $viewfile = $filename = !empty($result['templist'])
// ? str_replace('.'.$this->view_suffix, '',$result['templist'])
// : 'lists_'.$this->nid;
// /*--end*/
// /*每个栏目内置模板文件名*/
// $viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$filename."_{$result['id']}.".$this->view_suffix;
// if (file_exists($viewfilepath)) {
// $viewfile = $filename."_{$result['id']}";
// }
// /*--end*/
// /*多语言内置模板文件名*/
// if (!empty($this->home_lang)) {
// $viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$filename."_{$this->home_lang}.".$this->view_suffix;
// if (file_exists($viewfilepath)) {
// $viewfile = $filename."_{$this->home_lang}";
// }
// /*每个栏目内置模板文件名*/
// $viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$filename."_{$result['id']}_{$this->home_lang}.".$this->view_suffix;
// if (file_exists($viewfilepath)) {
// $viewfile = $filename."_{$result['id']}_{$this->home_lang}";
// }
// /*--end*/
// }
// /*--end*/
$view = ":{$viewfile}";
if (51 == $this->channel) { // 问答模型
$Ask = new \app\home\controller\Ask;
return $Ask->index();
}else{
return $this->fetch($view);
}
}
/**
* 模型对应逻辑
* @param intval $tid 栏目ID
* @return array
*/
private function logic($tid = '')
{
$result = array();
if (empty($tid)) {
return $result;
}
switch ($this->channel) {
case '6': // 单页模型
{
$arctype_info = model('Arctype')->getInfo($tid);
if ($arctype_info) {
// 读取当前栏目的内容,否则读取每一级第一个子栏目的内容,直到有内容或者最后一级栏目为止。
$archivesModel = new \app\home\model\Archives();
$result_new = $archivesModel->readContentFirst($tid);
// 阅读权限
if ($result_new['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result_new['is_part'] == 1) {
$result_new['typelink'] = htmlspecialchars_decode($result_new['typelink']);
if (!is_http_url($result_new['typelink'])) {
$typeurl = '//'.$this->request->host();
if (!preg_match('#^'.ROOT_DIR.'(.*)$#i', $result_new['typelink'])) {
$typeurl .= ROOT_DIR;
}
$typeurl .= '/'.trim($result_new['typelink'], '/');
$result_new['typelink'] = $typeurl;
}
$this->redirect($result_new['typelink']);
exit;
}
/*自定义字段的数据格式处理*/
$result_new = $this->fieldLogic->getChannelFieldList($result_new, $this->channel);
/*--end*/
$result = array_merge($arctype_info, $result_new);
$result['templist'] = !empty($arctype_info['templist']) ? $arctype_info['templist'] : 'lists_'. $arctype_info['nid'];
$result['dirpath'] = $arctype_info['dirpath'];
$result['typeid'] = $arctype_info['typeid'];
}
break;
}
default:
{
$result = model('Arctype')->getInfo($tid);
/*外部链接跳转*/
if ($result['is_part'] == 1) {
$result['typelink'] = htmlspecialchars_decode($result['typelink']);
if (!is_http_url($result['typelink'])) {
$result['typelink'] = '//'.$this->request->host().ROOT_DIR.'/'.trim($result['typelink'], '/');
}
$this->redirect($result['typelink']);
exit;
}
/*end*/
break;
}
}
if (!empty($result)) {
/*自定义字段的数据格式处理*/
$result = $this->fieldLogic->getTableFieldList($result, config('global.arctype_channel_id'));
/*--end*/
}
/*是否有子栏目,用于标记【全部】选中状态*/
$result['has_children'] = model('Arctype')->hasChildren($tid);
/*--end*/
// seo
$result['seo_title'] = set_typeseotitle($result['typename'], $result['seo_title']);
/*获取当前页面URL*/
$result['pageurl'] = $this->request->url(true);
/*--end*/
/*给没有type前缀的字段新增一个带前缀的字段并赋予相同的值*/
foreach ($result as $key => $val) {
if (!preg_match('/^type/i', $key)) {
$key_new = 'type' . $key;
!array_key_exists($key_new, $result) && $result[$key_new] = $val;
}
}
/*--end*/
return $result;
}
/**
* 留言提交
*/
public function gbook_submit()
{
$typeid = input('post.typeid/d');
if (IS_POST && !empty($typeid)) {
$gourl = input('post.gourl/s');
$post = input('post.');
unset($post['gourl']);
$token = '__token__';
foreach ($post as $key => $val) {
if (preg_match('/^__token__/i', $key)) {
$token = $key;
continue;
}
}
$ip = clientIP();
/*留言间隔限制*/
$channel_guestbook_interval = tpSetting('channel_guestbook.channel_guestbook_interval');
$channel_guestbook_interval = is_numeric($channel_guestbook_interval) ? intval($channel_guestbook_interval) : 60;
if (0 < $channel_guestbook_interval) {
$map = array(
'ip' => $ip,
'typeid' => $typeid,
'lang' => $this->home_lang,
'add_time' => array('gt', getTime() - $channel_guestbook_interval),
);
$count = M('guestbook')->where($map)->count('aid');
if ($count > 0) {
$this->error('同一个IP在'.$channel_guestbook_interval.'秒之内不能重复提交!');
}
}
/*end*/
//判断必填项
$ContentArr = []; // 添加站内信所需参数
foreach ($post as $key => $value) {
if (stripos($key, "attr_") !== false) {
//处理得到自定义属性id
$attr_id = substr($key, 5);
$attr_id = intval($attr_id);
$ga_data = Db::name('guestbook_attribute')->where([
'attr_id' => $attr_id,
'lang' => $this->home_lang,
])->find();
if ($ga_data['required'] == 1) {
if (empty($value)) {
$this->error($ga_data['attr_name'] . '不能为空!');
} else {
if ($ga_data['validate_type'] == 6) {
$pattern = "/^1\d{10}$/";
if (!preg_match($pattern, $value)) {
$this->error($ga_data['attr_name'] . '格式不正确!');
}
} elseif ($ga_data['validate_type'] == 7) {
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
if (preg_match($pattern, $value) == false) {
$this->error($ga_data['attr_name'] . '格式不正确!');
}
}
}
}
// 添加站内信所需参数
array_push($ContentArr, $value);
}
}
/* 处理判断验证码 */
$is_vertify = 1; // 默认开启验证码
$guestbook_captcha = config('captcha.guestbook');
if (!function_exists('imagettftext') || empty($guestbook_captcha['is_on'])) {
$is_vertify = 0; // 函数不存在,不符合开启的条件
}
if (1 == $is_vertify) {
if (empty($post['vertify'])) {
$this->error('图片验证码不能为空!');
}
$verify = new Verify();
if (!$verify->check($post['vertify'], $token)) {
$this->error('图片验证码不正确!');
}
}
/* END */
$channeltype_list = config('global.channeltype_list');
$this->channel = !empty($channeltype_list['guestbook']) ? $channeltype_list['guestbook'] : 8;
$newData = array(
'typeid' => $typeid,
'channel' => $this->channel,
'ip' => $ip,
'lang' => $this->home_lang,
'add_time' => getTime(),
'update_time' => getTime(),
);
$data = array_merge($post, $newData);
// 数据验证
$rule = [
'typeid' => 'require|token:' . $token,
];
$message = [
'typeid.require' => '表单缺少标签属性{$field.hidden}',
];
$validate = new \think\Validate($rule, $message);
if (!$validate->batch()->check($data)) {
$error = $validate->getError();
$error_msg = array_values($error);
$this->error($error_msg[0]);
} else {
$guestbookRow = [];
/*处理是否重复表单数据的提交*/
$formdata = $data;
foreach ($formdata as $key => $val) {
if (in_array($key, ['typeid', 'lang']) || preg_match('/^attr_(\d+)$/i', $key)) {
continue;
}
unset($formdata[$key]);
}
$md5data = md5(serialize($formdata));
$data['md5data'] = $md5data;
$guestbookRow = M('guestbook')->field('aid')->where(['md5data' => $md5data])->find();
/*--end*/
$dataStr = '';
if (empty($guestbookRow)) { // 非重复表单的才能写入数据库
$aid = M('guestbook')->insertGetId($data);
if ($aid > 0) {
$res = $this->saveGuestbookAttr($aid, $typeid);
if ($res){
$this->error($res);
}
}
/*插件 - 邮箱发送*/
$data = [
'gbook_submit',
$typeid,
$aid,
];
$dataStr = implode('|', $data);
/*--end*/
/*发送站内信给后台*/
SendNotifyMessage($ContentArr, 1, 1, 0);
/* END */
} else {
// 存在重复数据的表单,将在后台显示在最前面
Db::name('guestbook')->where('aid', $guestbookRow['aid'])->update([
'add_time' => getTime(),
'update_time' => getTime(),
]);
}
$this->success('操作成功!', $gourl, $dataStr, 5);
}
}
$this->error('表单缺少标签属性{$field.hidden}');
}
/**
* 给指定留言添加表单值到 guestbook_attr
* @param int $aid 留言id
* @param int $typeid 留言栏目id
*/
private function saveGuestbookAttr($aid, $typeid)
{
// post 提交的属性 以 attr_id _ 和值的 组合为键名
$post = input("post.");
$arr = explode(',', config('global.image_ext'));
/*上传图片或附件*/
foreach ($_FILES as $fileElementId => $file) {
try {
if (!empty($file['name']) && !is_array($file['name'])) {
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
if (in_array($ext,$arr)){
$uplaod_data = func_common($fileElementId, 'allimg');
}else{
$uplaod_data = func_common_doc($fileElementId, 'files');
}
if (0 == $uplaod_data['errcode']) {
$post[$fileElementId] = $uplaod_data['img_url'];
} else {
return $uplaod_data['errmsg'];
// $post[$fileElementId] = '';
}
}
} catch (\Exception $e) {}
}
/*end*/
$attrArr = [];
/*多语言*/
if (is_language()) {
foreach ($post as $key => $val) {
if (preg_match_all('/^attr_(\d+)$/i', $key, $matchs)) {
$attr_value = intval($matchs[1][0]);
$attrArr[$attr_value] = [
'attr_id' => $attr_value,
];
}
}
$attrArr = model('LanguageAttr')->getBindValue($attrArr, 'guestbook_attribute'); // 多语言
}
/*--end*/
foreach ($post as $k => $v) {
if (!strstr($k, 'attr_'))
continue;
$attr_id = str_replace('attr_', '', $k);
is_array($v) && $v = implode(PHP_EOL, $v);
/*多语言*/
if (!empty($attrArr)) {
$attr_id = $attrArr[$attr_id]['attr_id'];
}
/*--end*/
//$v = str_replace('_', '', $v); // 替换特殊字符
//$v = str_replace('@', '', $v); // 替换特殊字符
$v = trim($v);
$adddata = array(
'aid' => $aid,
'attr_id' => $attr_id,
'attr_value' => $v,
'lang' => $this->home_lang,
'add_time' => getTime(),
'update_time' => getTime(),
);
M('GuestbookAttr')->add($adddata);
}
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Db;
class Media extends Base
{
// 模型标识
public $nid = 'media';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$result = model('Media')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
/**
* 记录视频播放进程
*/
public function record_process()
{
\think\Session::pause(); // 暂停session防止session阻塞机制
$aid = input('aid/d', 0);
$file_id = input('file_id/d', 0);
$timeDisplay = input('timeDisplay/d', 0);
$users_id = session('users_id');
if (empty($users_id)){
return true;
}
if ( 0 == $timeDisplay ){
exit;
}
$where = ['users_id' => $users_id,
'aid' => $aid,
'file_id' => $file_id];
$count = Db::name('media_play_record')->where($where)->find();
$data = [
'users_id' => intval($users_id),
'aid' => intval($aid),
'file_id' => intval($file_id),
'play_time' => $timeDisplay,
'update_time' => getTime(),
];
if (!empty($count)) {
$timeDisplay = $timeDisplay + $count['play_time'];
$file_time = Db::name('media_file')->where('file_id',$file_id)->value('file_time');
$data['play_time'] = $timeDisplay > $file_time ? $file_time : $timeDisplay;
$data['play_time'] = intval($data['play_time']);
//更新
Db::name('media_play_record')->where($where)->update($data);
}else{
$data['add_time'] = getTime();
Db::name('media_play_record')->insert($data);
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Product extends Base
{
// 模型标识
public $nid = 'product';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$result = model('Product')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Recruit extends Base
{
// 模型标识
public $nid = 'recruit';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$result = model('Recruit')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Db;
class Search extends Base
{
private $searchword_db;
public function _initialize() {
parent::_initialize();
$this->searchword_db = Db::name('search_word');
}
/**
* 搜索主页
*/
public function index()
{
$result = [];
$result = $param = input('param.');
/*获取当前页面URL*/
$result['pageurl'] = request()->url(true);
/*--end*/
!isset($result['keywords']) && $result['keywords'] = '';
$eyou = array(
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
$viewfile = 'index_search';
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile.".".$this->view_suffix;
if (!file_exists($viewfilepath)) {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile."_{$this->home_lang}.".$this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
} else {
return $this->lists();
}
}
} else {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile.".".$this->view_suffix;
if (!file_exists($viewfilepath)) {
return $this->lists();
}
}
/*--end*/
return $this->fetch(":{$viewfile}");
}
/**
* 搜索列表
*/
public function lists()
{
$param = input('param.');
/*记录搜索词*/
$word = $this->request->param('keywords');
$page = $this->request->param('page');
if(!empty($word) && 2 > $page)
{
$word = addslashes($word);
$nowTime = getTime();
$row = $this->searchword_db->field('id')->where(['word'=>$word, 'lang'=>$this->home_lang])->find();
if(empty($row))
{
$this->searchword_db->insert([
'word' => $word,
'sort_order' => 100,
'lang' => $this->home_lang,
'add_time' => $nowTime,
'update_time' => $nowTime,
]);
}else{
$this->searchword_db->where(['id'=>$row['id']])->update([
'searchNum' => Db::raw('searchNum+1'),
'update_time' => $nowTime,
]);
}
}
/*--end*/
$result = $param;
!isset($result['keywords']) && $result['keywords'] = '';
$eyou = array(
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
/*模板文件*/
$viewfile = 'lists_search';
/*--end*/
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile."_{$this->home_lang}.".$this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
}
}
/*--end*/
return $this->fetch(":{$viewfile}");
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Single extends Base
{
// 模型标识
public $nid = 'single';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => array('eq', 0),
'is_hidden' => 0,
'status' => 1,
'lang' => $this->home_lang,
);
$res = M('arctype')->where($map)->order('sort_order asc')->limit(1)->find();
$typeurl = model('Arctype')->getTypeUrl($res);
header('Location: '.$typeurl);
exit;
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
}
return action('home/Lists/index', $tid);
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Special extends Base
{
// 模型标识
public $nid = 'special';
// 模型ID
public $channeltype = '';
public function _initialize() {
parent::_initialize();
$channeltype_list = config('global.channeltype_list');
$this->channeltype = $channeltype_list[$this->nid];
}
public function lists($tid)
{
$tid_tmp = $tid;
$seo_pseudo = config('ey_config.seo_pseudo');
if (empty($tid)) {
$map = array(
'channeltype' => $this->channeltype,
'parent_id' => 0,
'is_hidden' => 0,
'status' => 1,
);
} else {
if (3 == $seo_pseudo) {
$map = array('dirname'=>$tid);
} else {
if (!is_numeric($tid) || strval(intval($tid)) !== strval($tid)) {
abort(404,'页面不存在');
}
$map = array('id'=>$tid);
}
}
$map['lang'] = $this->home_lang; // 多语言
$row = M('arctype')->field('id,dirname')->where($map)->order('sort_order asc')->limit(1)->find();
$tid = !empty($row['id']) ? intval($row['id']) : 0;
$dirname = !empty($row['dirname']) ? $row['dirname'] : '';
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($tid, $dirname, 'lists');
/*--end*/
if (3 == $seo_pseudo) {
$tid = $dirname;
} else {
$tid = $tid_tmp;
}
return action('home/Lists/index', $tid);
}
public function view($aid)
{
$result = model('Special')->getInfo($aid);
if (empty($result)) {
abort(404,'页面不存在');
} elseif ($result['arcrank'] == -1) {
$this->success('待审核稿件,你没有权限阅读!');
exit;
}
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: '.$result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*301重定向到新的伪静态格式*/
$this->jumpRewriteFormat($aid, $arctypeInfo['dirname'], 'view');
/*--end*/
return action('home/View/index', $aid);
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
class Tags extends Base
{
public function _initialize() {
parent::_initialize();
}
/**
* 标签主页
*/
public function index()
{
/*获取当前页面URL*/
$result['pageurl'] = $this->request->url(true);
/*--end*/
$eyou = array(
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
/*模板文件*/
$viewfile = 'index_tags';
/*--end*/
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile."_{$this->home_lang}.".$this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
}
}
/*--end*/
return $this->fetch(":{$viewfile}");
}
/**
* 标签列表
*/
public function lists()
{
$param = I('param.');
$tagid = isset($param['tagid']) ? $param['tagid'] : '';
$tag = isset($param['tag']) ? trim($param['tag']) : '';
if (!empty($tag)) {
$tagindexInfo = M('tagindex')->where([
'tag' => $tag,
'lang' => $this->home_lang,
])->find();
} elseif (intval($tagid) > 0) {
$tagindexInfo = M('tagindex')->where([
'id' => $tagid,
'lang' => $this->home_lang,
])->find();
}
if (!empty($tagindexInfo)) {
$tagid = $tagindexInfo['id'];
$tag = $tagindexInfo['tag'];
//更新浏览量和记录数
$map = array(
'tid' => array('eq', $tagid),
'arcrank' => array('gt', -1),
'lang' => $this->home_lang,
);
$total = M('taglist')->where($map)
->count('tid');
M('tagindex')->where([
'id' => $tagid,
'lang' => $this->home_lang,
])->inc('count')
->inc('weekcc')
->inc('monthcc')
->update(array('total'=>$total));
$ntime = getTime();
$oneday = 24 * 3600;
//周统计
if(ceil( ($ntime - $tagindexInfo['weekup'])/$oneday ) > 7)
{
M('tagindex')->where([
'id' => $tagid,
'lang' => $this->home_lang,
])->update(array('weekcc'=>0, 'weekup'=>$ntime));
}
//月统计
if(ceil( ($ntime - $tagindexInfo['monthup'])/$oneday ) > 30)
{
M('tagindex')->where([
'id' => $tagid,
'lang' => $this->home_lang,
])->update(array('monthcc'=>0, 'monthup'=>$ntime));
}
} else {
abort(404);
}
$field_data = array(
'tag' => $tag,
'tagid' => $tagid,
'seo_title' => set_tagseotitle($tag, $tagindexInfo['seo_title']),
'seo_keywords' => !empty($tagindexInfo['seo_keywords']) ? $tagindexInfo['seo_keywords'] : $tagindexInfo['seo_keywords'],
'seo_description' => !empty($tagindexInfo['seo_description']) ? $tagindexInfo['seo_description'] : $tagindexInfo['seo_description'],
);
$eyou = array(
'field' => $field_data,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
/*模板文件*/
$viewfile = 'lists_tags';
/*--end*/
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH.$this->theme_style_path.DS.$viewfile."_{$this->home_lang}.".$this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
}
}
/*--end*/
return $this->fetch(":{$viewfile}");
}
}

View File

@@ -0,0 +1,688 @@
<?php
/**
* 易优CMS
* ============================================================================
* 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
* 网站地址: http://www.eyoucms.com
* ----------------------------------------------------------------------------
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* Author: 小虎哥 <1105415366@qq.com>
* Date: 2018-4-3
*/
namespace app\home\controller;
use think\Db;
class View extends Base
{
// 模型标识
public $nid = '';
// 模型ID
public $channel = '';
// 模型名称
public $modelName = '';
public function _initialize()
{
parent::_initialize();
}
/**
* 内容页
*/
public function index($aid = '')
{
$seo_pseudo = config('ey_config.seo_pseudo');
/*URL上参数的校验*/
if (3 == $seo_pseudo)
{
if (stristr($this->request->url(), '&c=View&a=index&')) {
abort(404, '页面不存在');
}
}
else if (1 == $seo_pseudo || (2 == $seo_pseudo && isMobile()))
{
$seo_dynamic_format = config('ey_config.seo_dynamic_format');
if (1 == $seo_pseudo && 2 == $seo_dynamic_format && stristr($this->request->url(), '&c=View&a=index&')) {
abort(404, '页面不存在');
}
}
/*--end*/
$map = [];
if (!is_numeric($aid) || strval(intval($aid)) !== strval($aid)) {
$map = array('a.htmlfilename' => $aid);
} else {
$map = array('a.aid' => intval($aid));
}
$map['a.is_del'] = 0; // 回收站功能
$field = 'a.aid, a.typeid, a.channel, a.users_price, a.users_free, b.nid, b.ctl_name, c.level_id, c.level_name, c.level_value';
$archivesInfo = Db::name('archives')->field($field)
->alias('a')
->join('__CHANNELTYPE__ b', 'a.channel = b.id', 'LEFT')
->join('__USERS_LEVEL__ c', 'a.arc_level_id = c.level_id', 'LEFT')
->where($map)
->find();
if (empty($archivesInfo) || !in_array($archivesInfo['channel'], config('global.allow_release_channel'))) {
abort(404, '页面不存在');
// $this->redirect('/public/static/errpage/404.html', 301);
}
$aid = $archivesInfo['aid'];
$this->nid = $archivesInfo['nid'];
$this->channel = $archivesInfo['channel'];
$this->modelName = $archivesInfo['ctl_name'];
$result = model($this->modelName)->getInfo($aid);
// 若是管理员则不受限制
// if (session('?admin_id')) {
// if ($result['arcrank'] == -1 && $result['users_id'] != session('users_id')) {
// $this->success('待审核稿件,你没有权限阅读!');
// }
// }
// 外部链接跳转
if ($result['is_jump'] == 1) {
header('Location: ' . $result['jumplinks']);
exit;
}
/*--end*/
$tid = $result['typeid'];
$arctypeInfo = model('Arctype')->getInfo($tid);
/*自定义字段的数据格式处理*/
$arctypeInfo = $this->fieldLogic->getTableFieldList($arctypeInfo, config('global.arctype_channel_id'));
/*--end*/
if (!empty($arctypeInfo)) {
/*URL上参数的校验*/
if (3 == $seo_pseudo) {
$dirname = input('param.dirname/s');
$dirname2 = '';
$seo_rewrite_format = config('ey_config.seo_rewrite_format');
if (1 == $seo_rewrite_format) {
$toptypeRow = model('Arctype')->getAllPid($tid);
$toptypeinfo = current($toptypeRow);
$dirname2 = $toptypeinfo['dirname'];
} else if (2 == $seo_rewrite_format) {
$dirname2 = $arctypeInfo['dirname'];
} else if (3 == $seo_rewrite_format) {
$dirname2 = $arctypeInfo['dirname'];
}
if ($dirname != $dirname2) {
abort(404, '页面不存在');
}
}
/*--end*/
// 是否有子栏目,用于标记【全部】选中状态
$arctypeInfo['has_children'] = model('Arctype')->hasChildren($tid);
// 文档模板文件,不指定文档模板,默认以栏目设置的为主
empty($result['tempview']) && $result['tempview'] = $arctypeInfo['tempview'];
/*给没有type前缀的字段新增一个带前缀的字段并赋予相同的值*/
foreach ($arctypeInfo as $key => $val) {
if (!preg_match('/^type/i', $key)) {
$key_new = 'type' . $key;
!array_key_exists($key_new, $arctypeInfo) && $arctypeInfo[$key_new] = $val;
}
}
/*--end*/
} else {
abort(404, '页面不存在');
}
$result = array_merge($arctypeInfo, $result);
// 文档链接
$result['arcurl'] = $result['pageurl'] = '';
if ($result['is_jump'] != 1) {
$result['arcurl'] = arcurl('home/'.$this->modelName.'/view', $result, true, true);
$result['pageurl'] = $this->request->url(true);
}
/*--end*/
// seo
$result['seo_title'] = set_arcseotitle($result['title'], $result['seo_title'], $result['typename'], $result['typeid']);
$result['seo_description'] = @msubstr(checkStrHtml($result['seo_description']), 0, config('global.arc_seo_description_length'), false);
/*支持子目录*/
$result['litpic'] = handle_subdir_pic($result['litpic']);
/*--end*/
$result = view_logic($aid, $this->channel, $result, true); // 模型对应逻辑
/*自定义字段的数据格式处理*/
$result = $this->fieldLogic->getChannelFieldList($result, $this->channel);
/*--end*/
$eyou = array(
'type' => $arctypeInfo,
'field' => $result,
);
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
/*模板文件*/
$viewfile = !empty($result['tempview'])
? str_replace('.' . $this->view_suffix, '', $result['tempview'])
: 'view_' . $this->nid;
/*--end*/
/*多语言内置模板文件名*/
if (!empty($this->home_lang)) {
$viewfilepath = TEMPLATE_PATH . $this->theme_style_path . DS . $viewfile . "_{$this->home_lang}." . $this->view_suffix;
if (file_exists($viewfilepath)) {
$viewfile .= "_{$this->home_lang}";
}
}
/*--end*/
$emptyhtml = '';
if ($this->eyou['field']['arcrank'] > 0) { // 若需要会员权限则执行
if (!session('?users_id')) {
$url = url('user/Users/login');
if (stristr($url, '.html')) {
$url = $url."?referurl={$result['arcurl']}";
} else {
$url = url('user/Users/login', ['referurl'=>$result['arcurl']]);
}
$this->redirect($url);
}
$msg = action('api/Ajax/get_arcrank', ['aid' => $aid, 'vars' => 1]);
if (true !== $msg) {
$this->error($msg);
}
} else if ($this->eyou['field']['arcrank'] == -1) {
/*待审核稿件,是否有权限查阅的处理,登录的管理员可查阅*/
$admin_id = input('param.admin_id/d');
if (!session('?admin_id') || empty($admin_id)) {
$emptyhtml = <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>{$this->eyou['field']['seo_title']}</title>
<meta name="description" content="{$this->eyou['field']['seo_description']}" />
<meta name="keywords" content="{$this->eyou['field']['seo_keywords']}" />
</head>
<body>
</body>
</html>
EOF;
}
/*end*/
}
if (!empty($emptyhtml)) {
/*尝试写入静态缓存*/
write_html_cache($emptyhtml, $result);
/*--end*/
return $this->display($emptyhtml);
} else {
return $this->fetch(":{$viewfile}");
}
}
/**
* 下载文件
*/
public function downfile()
{
$file_id = input('param.id/d', 0);
$uhash = input('param.uhash/s', '');
if (empty($file_id) || empty($uhash)) {
$this->error('下载地址出错!');
exit;
}
clearstatcache();
// 查询信息
$map = array(
'a.file_id' => $file_id,
'a.uhash' => $uhash,
);
$result = Db::name('download_file')
->alias('a')
->field('a.*,b.arc_level_id')
->join('__ARCHIVES__ b', 'a.aid = b.aid', 'LEFT')
->where($map)
->find();
$file_url_gbk = iconv("utf-8", "gb2312//IGNORE", $result['file_url']);
$file_url_gbk = preg_replace('#^(/[/\w]+)?(/public/upload/soft/|/uploads/soft/)#i', '$2', $file_url_gbk);
if (empty($result) || (!is_http_url($result['file_url']) && !file_exists('.' . $file_url_gbk))) {
$this->error('下载文件不存在!');
exit;
}
// 下载次数限制
$this->down_num_access($result['aid']);
// 判断会员信息
if (0 < intval($result['arc_level_id'])) {
$UsersData = session('users');
if (empty($UsersData['users_id'])) {
$this->error('请登录后下载!', null, ['is_login'=>0, 'url'=>url('user/Users/login')]);
exit;
} else {
/*判断会员是否可下载该文件--2019-06-21 陈风任添加*/
// 查询会员信息
$users = Db::name('users')
->alias('a')
->field('a.users_id,b.level_value,b.level_name')
->join('__USERS_LEVEL__ b', 'a.level = b.level_id', 'LEFT')
->where(['a.users_id' => $UsersData['users_id']])
->find();
// 查询下载所需等级值
$file_level = Db::name('archives')
->alias('a')
->field('b.level_value,b.level_name')
->join('__USERS_LEVEL__ b', 'a.arc_level_id = b.level_id', 'LEFT')
->where(['a.aid' => $result['aid']])
->find();
if ($users['level_value'] < $file_level['level_value']) {
$msg = '文件为【' . $file_level['level_name'] . '】可下载,您当前为【' . $users['level_name'] . '】,请先升级!';
$this->error($msg, null, ['url'=>url('user/Level/level_centre')]);
exit;
}
/*--end*/
}
}
// 外部下载链接
if (is_http_url($result['file_url']) || !empty($result['is_remote'])) {
if ($result['uhash'] != md5($result['file_url'])) {
$this->error('下载地址出错!');
}
// 记录下载次数
$this->download_log($result['file_id'], $result['aid']);
$result['file_url'] = htmlspecialchars_decode($result['file_url']);
if (IS_AJAX) {
$this->success('正在跳转中……', $result['file_url']);
} else {
$this->redirect($result['file_url']);
exit;
}
}
// 本站链接
else
{
if (md5_file('.' . $file_url_gbk) != $result['md5file']) {
$this->error('下载文件包已损坏!');
}
// 记录下载次数
$this->download_log($result['file_id'], $result['aid']);
$uhash_mch = mchStrCode($uhash);
$url = $this->root_dir . "/index.php?m=home&c=View&a=download_file&file_id={$file_id}&uhash={$uhash_mch}";
cookie($file_id.$uhash_mch, 1);
if (IS_AJAX) {
$this->success('开始下载中……', $url);
} else {
$url = $this->request->domain() . $url;
$this->redirect($url);
exit;
}
}
}
/**
* 本地附件下载
*/
public function download_file()
{
$file_id = input('param.file_id/d');
$uhash_mch = input('param.uhash/s', '');
$uhash = mchStrCode($uhash_mch, 'DECODE');
$map = array(
'file_id' => $file_id,
);
$result = Db::name('download_file')->field('aid,file_url,file_mime,uhash')->where($map)->find();
if (!empty($result['uhash']) && $uhash != $result['uhash']) {
$this->error('下载地址出错!');
}
$value = cookie($file_id.$uhash_mch);
if (empty($value)) {
$result = Db::name('archives')
->field("b.*, a.*")
->alias('a')
->join('__ARCTYPE__ b', 'b.id = a.typeid', 'LEFT')
->where(['a.aid'=>$result['aid']])
->find();
$arcurl = arcurl('home/Download/view', $result);
$this->error('下载地址已失效,请在下载详情页进行下载!', $arcurl);
} else {
cookie($file_id.$uhash_mch, null);
}
download_file($result['file_url'], $result['file_mime']);
exit;
}
/**
* 会员每天下载次数的限制
*/
private function down_num_access($aid)
{
/*是否安装启用下载次数限制插件*/
if (is_dir('./weapp/Downloads/')) {
$DownloadsRow = model('Weapp')->getWeappList('Downloads');
if (1 != $DownloadsRow['status']) {
return true;
}
} else {
return true;
}
/*end*/
$users = session('users');
if (empty($users['users_id'])) {
$this->error('请登录后下载!');
}
$level_info = Db::name('users_level')->field('level_name,down_count')->where(['level_id' => $users['level']])->find();
if (empty($level_info)) {
$this->error('当前会员等级不存在!');
}
$begin_mtime = strtotime(date('Y-m-d 00:00:00'));
$end_mtime = strtotime(date('Y-m-d 23:59:59'));
$downNum = Db::name('download_log')->where([
'users_id' => $users['users_id'],
'add_time' => ['between', [$begin_mtime, $end_mtime]],
'aid' => ['NEQ', $aid],
])->group('aid')->count('aid');
if (intval($level_info['down_count']) <= intval($downNum)) {
$msg = "{$level_info['level_name']}每天最多下载{$level_info['down_count']}个!";
$this->error($msg);
}
}
/**
* 记录下载次数(重复下载不做记录,游客可重复记录)
*/
private function download_log($file_id = 0, $aid = 0)
{
try {
$users_id = session('users_id');
$users_id = intval($users_id);
$counts = Db::name('download_log')->where([
'file_id' => $file_id,
'aid' => $aid,
'users_id' => $users_id,
])->count();
if (empty($users_id) || empty($counts)) {
$saveData = [
'users_id' => $users_id,
'aid' => $aid,
'file_id' => $file_id,
'ip' => clientIP(),
'add_time' => getTime(),
];
$r = Db::name('download_log')->insertGetId($saveData);
if ($r !== false) {
Db::name('download_file')->where(['file_id' => $file_id])->setInc('downcount');
Db::name('archives')->where(['aid' => $aid])->setInc('downcount');
}
}
} catch (\Exception $e) {}
}
/**
* 获取播放视频路径(仅限于早期第一套和第二套使用)
*/
public function pay_video_url()
{
$file_id = input('param.id/d', 0);
$uhash = input('param.uhash/s', '');
if (empty($file_id) || empty($uhash)) $this->error('视频播放链接出错!');
// 查询信息
$map = array(
'a.file_id' => $file_id,
'a.uhash' => $uhash
);
$result = Db::name('media_file')
->alias('a')
->field('a.*, b.arc_level_id, b.users_price, b.users_free')
->join('__ARCHIVES__ b', 'a.aid = b.aid', 'LEFT')
->where($map)
->find();
if (preg_match('#^(/[\w]+)?(/uploads/media/)#i', $result['file_url'])) {
$file_url = preg_replace('#^(/[\w]+)?(/uploads/media/)#i', '$2', $result['file_url']);
} else {
$file_url = preg_replace('#^(' . $this->root_dir . ')?(/)#i', '$2', $result['file_url']);
}
if (empty($result) || (!is_http_url($result['file_url']) && !file_exists('.' . $file_url))) {
$this->error('视频文件不存在!');
}
$UsersData = GetUsersLatestData();
$UsersID = !empty($UsersData['users_id']) ? intval($UsersData['users_id']) : 0;
$upVip = "window.location.href = '" . url('user/Level/level_centre') . "'";
$data['onclick'] = "if (document.getElementById('ey_login_id_1609665117')) {\$('#ey_login_id_1609665117').trigger('click');}else{window.location.href = '" . url('user/Users/login') . "';}";
$data['button'] = '点击登录!';
$data['users_id'] = $UsersID;
// 未登录则提示
if (empty($UsersID)) $this->error('请先登录!', url('user/Users/login'), $data);
if (empty($result['gratis'])) {
$arc_level_id = !empty($result['arc_level_id']) ? intval($result['arc_level_id']) : 0;
/*是否需要付费*/
if (0 < $result['users_price'] && empty($result['users_free'])) {
$Paid = 0; // 未付费
$where = [
'users_id' => $UsersID,
'product_id' => $result['aid'],
'order_status' => 1
];
// 存在数据则已付费
$Paid = Db::name('media_order')->where($where)->count();
// 未付费则执行
if (empty($Paid)) {
if (0 < $arc_level_id && $UsersData['level'] < $arc_level_id) {
$data['onclick'] = $upVip;
$data['button'] = '升级会员';
$level_name = Db::name('users_level')->where(['level_id'=>$arc_level_id])->value('level_name');
$this->error('未付费,需要【' . $level_name . '】付费才能播放', '', $data);
} else {
$data['onclick'] = 'MediaOrderBuy_1592878548();';
$data['button'] = '立即购买';
$this->error('未付费,视频需要付费才能播放', '', $data);
}
}
}
//会员
if (0 < $arc_level_id && $UsersData['level'] < $arc_level_id) {
$where = [
'level_id' => $arc_level_id,
'lang' => $this->home_lang
];
$arcLevel = Db::name('users_level')->where($where)->Field('level_value,level_name')->find();
$data['onclick'] = $upVip;
$data['button'] = '升级会员';
$this->error('未付费,请升级会员至【' . $arcLevel['level_name'] . '】观看视频', '', $data);
}
}
// 外部视频链接
if (is_http_url($result['file_url'])) {
// 记录播放次数
$this->video_log($result['file_id'], $result['aid']);
if (IS_AJAX) {
$this->success('准备播放中……', $result['file_url']);
} else {
$this->redirect($result['file_url']);
exit;
}
}
// 本站链接
else
{
if (md5_file('.' . $file_url) != $result['md5file']) {
$this->error('视频文件已损坏!');
}
// 记录播放次数
$this->video_log($result['file_id'], $result['aid']);
$url = $this->request->domain() . $this->root_dir . $file_url;
if (IS_AJAX) {
$this->success('准备播放中……', $url);
} else {
$this->redirect($url);
exit;
}
}
}
/**
* 记录播放次数(重复播放不做记录,游客可重复记录)
*/
private function video_log($file_id = 0, $aid = 0)
{
try {
$users_id = session('users_id');
$users_id = intval($users_id);
$counts = Db::name('media_log')->where([
'file_id' => $file_id,
'aid' => $aid,
'users_id' => $users_id,
])->count();
if (empty($users_id) || empty($counts)) {
$saveData = [
'users_id' => $users_id,
'aid' => $aid,
'file_id' => $file_id,
'ip' => clientIP(),
'add_time' => getTime(),
];
$r = Db::name('media_log')->insertGetId($saveData);
if ($r !== false) {
Db::name('media_file')->where(['file_id' => $file_id])->setInc('playcount');
Db::name('archives')->where(['aid' => $aid])->setInc('downcount');
}
}
} catch (\Exception $e) {}
}
/**
* 内容播放页【易而优视频模板专用】
*/
public function play($aid = '', $fid = '')
{
$aid = intval($aid);
$fid = intval($fid);
$res = Db::name('archives')
->alias('a')
->field('a.*,b.*,c.typename,c.dirname')
->join('media_content b', 'a.aid=b.aid')
->join('arctype c', 'a.typeid=c.id')
->where('a.aid', $aid)
->find();
if(!empty($res['courseware'])){
$res['courseware'] = get_default_pic($res['courseware'],true);
}
// 播放权限验证
$redata = $this->check_auth($aid, $fid, $res, 1);
if (!isset($redata['status']) || $redata['status'] != 2) {
$url = null;
if (!empty($redata['url'])) {
$url = $redata['url'];
}
$this->error($redata['msg'], $url);
}
Db::name('media_file')->where(['file_id' => $fid])->setInc('playcount');
$res['seo_title'] = set_arcseotitle($res['title'], $res['seo_title'], $res['typename'], $res['typeid']);
$res['seo_description'] = @msubstr(checkStrHtml($res['seo_description']), 0, config('global.arc_seo_description_length'), false);
$eyou['field'] = $res;
$eyou['field']['fid'] = $fid;
$this->eyou = array_merge($this->eyou, $eyou);
$this->assign('eyou', $this->eyou);
return $this->fetch(":view_media_play");
}
/**
* 播放权限验证【易而优视频模板专用】
*/
public function check_auth($aid = '', $fid = '', $res = [], $_ajax = 0)
{
if (IS_AJAX || $_ajax == 1){
$is_mobile = isMobile() ? 1 : 0;
if (empty($res)) {
$res = Db::name('archives')
->alias('a')
->join('media_content b', 'a.aid=b.aid')
->where('a.aid', $aid)
->field('a.title,b.courseware,a.arc_level_id,a.users_price,a.users_free')
->find();
}
if ((0 < $res['users_price'] && empty($res['users_free'])) || 0 < $res['arc_level_id']) {
$UsersData = GetUsersLatestData();
$UsersID = !empty($UsersData['users_id']) ? intval($UsersData['users_id']) : 0;
if (empty($UsersID)) return ['status'=>1,'msg'=>'请先登录','url'=>url('user/Users/login','', true, false, 1, 1),'is_mobile'=>$is_mobile];
$gratis = Db::name('media_file')->where(['file_id' => $fid])->value('gratis');
if ($gratis == 0) {
$arc_level_id = !empty($res['arc_level_id']) ? intval($res['arc_level_id']) : 0;
/*是否需要付费*/
if (0 < $res['users_price'] && empty($res['users_free'])) {
$Paid = 0; // 未付费
if (!empty($UsersID)) {
$where = [
'users_id' => $UsersID,
'product_id' => $aid,
'order_status' => 1
];
// 存在数据则已付费
$Paid = Db::name('media_order')->where($where)->count();
}
// 未付费则执行
if (empty($Paid)) {
if (0 < $arc_level_id && $UsersData['level'] < $arc_level_id) {
$where = [
'level_id' => $arc_level_id,
'lang' => $this->home_lang
];
$arcLevel = DB::name('users_level')->where($where)->Field('level_value,level_name')->find();
return ['status'=>0,'msg'=>'尊敬的用户,该视频需要【' . $arcLevel['level_name'] . '】付费后才可观看全部内容!','price'=>$res['users_price'],'is_mobile'=>$is_mobile];
} else {
return ['status'=>0,'msg'=>'尊敬的用户,该视频需要付费后才可观看全部内容!','price'=>$res['users_price'],'is_mobile'=>$is_mobile];
}
}
}
// 会员
if (0 < $arc_level_id && $UsersData['level'] < $arc_level_id) {
$where = [
'level_id' => $arc_level_id,
'lang' => $this->home_lang
];
$arcLevel = DB::name('users_level')->where($where)->Field('level_value,level_name')->find();
return ['status'=>0,'url'=>url('user/Level/level_centre','', true, false, 1, 1),'msg'=>'尊敬的用户,该视频需要【' . $arcLevel['level_name'] . '】才可观看!','is_mobile'=>$is_mobile];
}
}
}
return ['status'=>2,'msg'=>'success!','is_mobile'=>$is_mobile];
}
}
}