This commit is contained in:
Gitea
2022-01-24 10:43:35 +08:00
commit 15dfc6576b
786 changed files with 219240 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年06月27日
* 评论控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\ParserModel;
use core\basic\Url;
class CommentController extends Controller
{
protected $parser;
protected $model;
protected $htmldir;
public function __construct()
{
$this->model = new ParserModel();
$this->parser = new ParserController();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 评论新增
public function add()
{
if ($_POST) {
if ($this->config('comment_status') === '0') {
error('系统已经关闭评论功能,请到后台开启再试!');
}
if (time() - session('lastsub') < 10) {
alert_back('您提交太频繁了,请稍后再试!');
}
if (! session('pboot_uid') && ! $this->config('comment_anonymous')) {
if (! ! $backurl = $_SERVER['HTTP_REFERER']) {
alert_location("请先注册登录后再评论!", Url::home('member/login', null, "backurl=" . urlencode($backurl)));
} else {
alert_location("请先注册登录后再评论!", Url::home('member/login'));
}
}
// 验证码验证
$checkcode = strtolower(post('checkcode', 'var'));
if ($this->config('comment_check_code') !== '0') {
if (! $checkcode) {
alert_back('验证码不能为空!');
}
if ($checkcode != session('checkcode')) {
alert_back('验证码错误!');
}
}
// 接收数据
$status = $this->config('comment_verify') === '0' ? 1 : 0;
if (! $contentid = request('contentid', 'int')) {
alert_back('文章ID未能正常获取请使用POST或URL参数传递');
}
$comment = post('comment');
$data = array(
'pid' => request('pid', 'int') ?: 0,
'contentid' => $contentid,
'comment' => $comment,
'uid' => session('pboot_uid'),
'puid' => request('puid', 'int'),
'likes' => 0,
'oppose' => 0,
'status' => $status,
'user_ip' => ip2long(get_user_ip()),
'user_os' => get_user_os(),
'user_bs' => get_user_bs(),
'create_time' => get_datetime(),
'update_user' => '',
'update_time' => ''
);
if ($this->model->addComment($data)) {
session('lastsub', time()); // 记录最后提交时间
$this->log('文章' . $contentid . '评论提交成功!');
if ($this->config('comment_send_mail') && $this->config('message_send_to')) {
$mail_subject = "【PbootCMS】您有新的文章评论信息请注意查收";
$mail_body = '评论内容:' . $comment . '<br>';
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}
if ($status) {
alert_location('评论提交成功!', '-1', 1);
} else {
alert_location('评论提交成功,请等待管理员审核!', '-1', 1);
}
} else {
$this->log('文章评论提交失败!');
alert_back('提交失败!');
}
} else {
alert_back('提交失败请使用POST方式提交');
}
}
// 我的评论
public function my()
{
// 未登录时跳转到用户登录
if (! session('pboot_uid')) {
location(Url::home('member/login'));
}
$content = parent::parser($this->htmldir . 'member/mycomment.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', '我的评论-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '我的评论', Url::home('comment/my')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 3, '我的评论', Url::home('comment/my')); // 解析分类标签
$content = $this->parser->parserMyCommentLabel($content); // 我的评论
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content;
exit();
}
// 评论删除
public function del()
{
// 未登录时跳转到用户登录
if (! session('pboot_uid')) {
location(Url::home('member/login'));
}
// 执行删除
if (! ! $id = get('id', 'int')) {
if ($this->model->delComment($id)) {
alert_back('删除成功!', 1);
} else {
alert_back('删除失败!');
}
} else {
alert_back('传递参数有误!');
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年3月8日
*
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\DoModel;
class DoController extends Controller
{
private $model;
public function __construct()
{
$this->model = new DoModel();
}
// 多语言切换
public function area()
{
$lg = request('lg', 'var');
if ($lg) {
$lgs = $this->config('lgs');
if (isset($lgs[$lg])) {
cookie('lg', $lg);
}
location(SITE_INDEX_DIR . '/');
}
}
// 文章访问量累计
public function visits()
{
if (! ! $id = get('id', 'int')) {
$this->model->addVisits($id);
echo 'var ok;'; // 避免前端浏览器报js错
} else {
echo 'var error;'; // 避免前端浏览器报js错
}
}
// 点赞
public function likes()
{
if (($id = get('id', 'int')) && ! cookie('likes_' . $id)) {
$this->model->addLikes($id);
cookie('likes_' . $id, true, 31536000, null, null, null, null);
}
location('-1');
}
// 获取是否点赞
public function isLikes()
{
if (($id = get('id', 'int')) && cookie('likes_' . $id)) {
return json(1, 'yes');
} else {
return json(0, 'no');
}
}
// 反对
public function oppose()
{
if (($id = get('id', 'int')) && ! cookie('oppose_' . $id)) {
$this->model->addOppose($id);
cookie('oppose_' . $id, true, 31536000, null, null, null, null);
}
location('-1');
}
// 获取是否反对
public function isOppose()
{
if (($id = get('id', 'int')) && cookie('oppose_' . $id)) {
return json(1, 'yes');
} else {
return json(0, 'no');
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 个人扩展标签可编写到本类中,升级不会覆盖
*/
namespace app\home\controller;
use core\basic\Controller;
class ExtLabelController
{
protected $content;
/* 必备启动函数 */
public function run($content)
{
// 接收数据
$this->content = $content;
// 执行个人自定义标签函数
$this->test();
// 返回数据
return $this->content;
}
// 测试扩展单个标签
private function test()
{
$this->content = str_replace('{pboot:userip}', get_user_ip(), $this->content);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 表单控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\ParserModel;
class FormController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new ParserModel();
}
// 表单提交
public function index()
{
// 在非兼容模式接受地址第二参数值
if (defined('RVAR')) {
$_GET['fcode'] = RVAR;
}
if ($_POST) {
if ($this->config('form_status') === '0') {
error('系统已经关闭表单功能,请到后台开启再试!');
}
if (time() - session('lastsub') < 10) {
alert_back('您提交太频繁了,请稍后再试!');
}
if (! $fcode = get('fcode', 'var')) {
alert_back('传递的表单编码有误!');
}
if ($fcode == 1) {
alert_back('表单提交地址有误,留言提交请使用留言专用地址!');
}
// 验证码验证
$checkcode = strtolower(post('checkcode', 'var'));
if ($this->config('form_check_code') !== '0') {
if (! $checkcode) {
alert_back('验证码不能为空!');
}
if ($checkcode != session('checkcode')) {
alert_back('验证码错误!');
}
}
// 读取字段
if (! $form = $this->model->getFormField($fcode)) {
alert_back('接收表单不存在任何字段,请核对后重试!');
}
// 接收数据
$mail_body = '';
foreach ($form as $value) {
$field_data = post($value->name);
if (is_array($field_data)) { // 如果是多选等情况时转换
$field_data = implode(',', $field_data);
}
$field_data = preg_replace_r('/pboot:if/i', '', $field_data);
if ($value->required && ! $field_data) {
alert_back($value->description . '不能为空!');
} else {
$data[$value->name] = $field_data;
$mail_body .= $value->description . '' . $field_data . '<br>';
}
}
// 设置创建时间
if ($data) {
$data['create_time'] = get_datetime();
}
// 写入数据
if ($this->model->addForm($value->table_name, $data)) {
session('lastsub', time()); // 记录最后提交时间
$this->log('提交表单数据成功!');
if ($this->config('form_send_mail') && $this->config('message_send_to')) {
$mail_subject = "【PbootCMS】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}
alert_location('提交成功!', '-1', 1);
} else {
$this->log('提交表单数据失败!');
alert_back('提交失败!');
}
} else {
alert_back('提交失败请使用POST方式提交');
}
}
}

View File

@@ -0,0 +1,320 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年2月14日
* 首页控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\ParserModel;
use core\basic\Config;
use core\basic\Url;
class IndexController extends Controller
{
protected $parser;
protected $model;
protected $htmldir;
public function __construct()
{
$this->parser = new ParserController();
$this->model = new ParserModel();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 空拦截器, 实现文章路由转发
public function _empty()
{
// 地址类型
$url_rule_type = $this->config('url_rule_type') ?: 3;
if (P) { // 采用pathinfo模式及p参数伪静态模式
if ($url_rule_type == 2 && stripos(URL, $_SERVER['SCRIPT_NAME']) !== false) { // 禁止伪静态时带index.php访问
_404('您访问的内容不存在,请核对后重试!');
}
$path = P;
} elseif ($url_rule_type == 3 && isset($_SERVER["QUERY_STRING"]) && $qs = $_SERVER["QUERY_STRING"]) { // 采用简短传参模式
parse_str($qs, $output);
unset($output['page']); // 去除分页
if ($output && ! current($output)) { // 第一个路径参数不能有值,否则非标准路径参数
$path = key($output); // 第一个参数为路径信息注意PHP数组会自动将key点符号转换下划线
} elseif (get('tag')) { // 对于兼容模式tag需要自动跳转tag独立页面
$tag = new TagController();
$tag->index();
} elseif (get('keyword')) { // 兼容模式搜索处理
$search = new SearchController();
$search->index();
}
}
// 地址去后缀,并且强制模式
$url_rule_suffix = substr($this->config('url_rule_suffix'), 1);
$suffix = false;
$slash = false;
if (preg_match('/(.*)(_|\.)' . $url_rule_suffix . '$/', $path, $matchs)) {
$path = $matchs[1];
$suffix = true;
} elseif (preg_match('/^[\w\-\/]+\/$/', $path)) {
$slash = true;
$path = trim($path, '/');
}
$path_arr = $path ? explode('/', $path) : array();
// 开始路由
if (isset($path_arr) && count($path_arr) > 0) {
switch ($path_arr[0]) {
case 'search':
case 'keyword':
$search = new SearchController();
$search->index();
break;
case 'message':
$msg = new MessageController();
$msg->index();
break;
case 'form':
$_GET['fcode'] = $path_arr[1];
$form = new FormController();
$form->index();
break;
case 'sitemap':
case 'Sitemap':
$sitemap = new SitemapController();
$sitemap->index();
break;
case 'tag':
$tag = new TagController();
$tag->index();
break;
case 'member':
$member = new MemberController();
$member->{$path_arr[1]}();
break;
case 'comment':
$comment = new CommentController();
$comment->{$path_arr[1]}();
break;
default:
if (get($path_arr[0])) {
$this->getIndex();
} else {
// 假设详情页地址,详情页匹配前段为栏目路径
$temp = $path_arr;
$contenturl = array_pop($temp);
$sorturl = implode('/', $temp);
$url_break_char = $this->config('url_break_char') ?: '_';
// 开始进行匹配
if (! ! $sort = $this->model->getSort($path)) {
// 栏目名称
$iscontent = false;
} elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $path, $matchs) && ! ! $sort = $this->model->getSort($matchs[1])) {
// 栏目名称_分页
$iscontent = false;
define('CMS_PAGE_CUSTOM', true);
$_GET['page'] = $matchs[2]; // 分页
} elseif (! ! $sorturl && ! ! $sort = $this->model->getSort($sorturl)) {
// 栏目名称/内容名称或ID要在第2个判断【栏目名称_分页】后
$data = $this->model->getContent($contenturl);
$iscontent = true;
} elseif (preg_match('/^list' . $url_break_char . '[0-9]+|about' . $url_break_char . '[0-9]+$/', $sorturl)) {
// 模型默认名称_栏目ID/内容名称或ID
$data = $this->model->getContent($contenturl);
$iscontent = true;
} else {
preg_match('/^([a-zA-Z0-9\-\/]+)(' . $url_break_char . '([0-9]+))?' . $url_break_char . '([0-9]+)$/i', $path, $matchs);
if ($matchs[2] && $model = $this->model->checkModelUrlname($matchs[1])) {
// 模型名称_栏目ID_分页
define('CMS_PAGE_CUSTOM', false);
$sort = $this->model->getSort($matchs[3]);
$_GET['page'] = $matchs[4]; // 分页
} elseif (! ! $model = $this->model->checkModelUrlname($matchs[1])) {
// 模型名称_栏目ID
$sort = $this->model->getSort($matchs[4]);
} elseif (preg_match('/^([a-zA-Z0-9\-\/]+)' . $url_break_char . '([0-9]+)$/i', $sorturl, $matchs)) {
// 模型名称_栏目ID/内容名称或ID
if (! ! $model = $this->model->checkModelUrlname($matchs[1])) {
$data = $this->model->getContent($contenturl);
$iscontent = true;
}
}
}
if ($iscontent) {
define('CMS_PAGE', false); // 使用普通分页处理模型
if (! ! $data && $suffix) {
if ($data->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $data->acode); // 调用内容语言与当前语言不一致时,自动切换语言
}
$this->getContent($data);
} else {
_404('您访问的内容不存在,请核对后重试!');
}
} else {
define('CMS_PAGE', true); // 使用cms分页处理模型
if (! ! $sort && ! $suffix) {
if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
cookie('lg', $sort->acode); // 调用栏目语言与当前语言不一致时,自动切换语言
}
if ($sort->type == 1) {
$this->getAbout($sort);
} else {
$this->getList($sort);
}
} else {
_404('您访问的页面不存在,请核对后重试!');
}
}
}
}
} else {
$this->getIndex();
}
}
// 首页
private function getIndex()
{
$content = parent::parser($this->htmldir . 'index.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', $this->config('index_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, - 1, '首页', SITE_INDEX_DIR . '/'); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, 0, '', SITE_INDEX_DIR . '/'); // 解析分类标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
$this->cache($content, true);
}
// 列表
private function getList($sort)
{
if ($sort->listtpl) {
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
$content = parent::parser($this->htmldir . $sort->listtpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = $sort->title ? "{sort:title}" : "{sort:name}"; // 页面标题
$content = str_replace('{pboot:pagetitle}', $this->config('list_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
$content = str_replace('{pboot:pagekeywords}', '{sort:keywords}', $content);
$content = str_replace('{pboot:pagedescription}', '{sort:description}', $content);
$content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
$content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
$content = $this->parser->parserListLabel($content, $sort->scode); // CMS分类列表标签解析
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
} else {
error('请到后台设置分类栏目列表页模板!');
}
$this->cache($content, true);
}
// 详情页
private function getContent($data)
{
// 读取模板
if (! ! $sort = $this->model->getSort($data->scode)) {
if ($sort->contenttpl) {
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote); // 检查栏目权限
$this->checkPageLevel($data->gcode, $data->gtype, $data->gnote); // 检查内容权限
$content = parent::parser($this->htmldir . $sort->contenttpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', $this->config('content_title') ?: '{content:title}-{sort:name}-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content);
$content = str_replace('{pboot:pagedescription}', '{content:description}', $content);
$content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
$content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
$content = $this->parser->parserCurrentContentLabel($content, $sort, $data); // CMS内容标签解析
$content = $this->parser->parserCommentLabel($content); // 文章评论
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
} else {
error('请到后台设置分类栏目内容页模板!');
}
} else {
_404('您访问内容的分类已经不存在,请核对后再试!');
}
$this->cache($content, true);
}
// 单页
private function getAbout($sort)
{
// 读取数据
if (! $data = $this->model->getAbout($sort->scode)) {
_404('您访问的内容不存在,请核对后重试!');
}
if ($sort->contenttpl) {
$this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
$content = parent::parser($this->htmldir . $sort->contenttpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = $sort->title ? "{sort:title}" : "{content:title}"; // 页面标题
$content = str_replace('{pboot:pagetitle}', $this->config('about_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
$content = str_replace('{pboot:pagekeywords}', '{content:keywords}', $content);
$content = str_replace('{pboot:pagedescription}', '{content:description}', $content);
$content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
$content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
$content = $this->parser->parserCurrentContentLabel($content, $sort, $data); // CMS内容标签解析
$content = $this->parser->parserCommentLabel($content); // 文章评论
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
} else {
error('请到后台设置分类栏目内容页模板!');
}
$this->cache($content, true);
}
// 检查页面权限
private function checkPageLevel($gcode, $gtype, $gnote)
{
if ($gcode) {
$deny = false;
$gtype = $gtype ?: 4;
switch ($gtype) {
case 1:
if ($gcode <= session('pboot_gcode')) {
$deny = true;
}
break;
case 2:
if ($gcode < session('pboot_gcode')) {
$deny = true;
}
break;
case 3:
if ($gcode != session('pboot_gcode')) {
$deny = true;
}
break;
case 4:
if ($gcode > session('pboot_gcode')) {
$deny = true;
}
break;
case 5:
if ($gcode >= session('pboot_gcode')) {
$deny = true;
}
break;
}
if ($deny) {
$gnote = $gnote ?: '您的权限不足,无法浏览本页面!';
if (session('pboot_uid')) { // 已经登录
error($gnote);
} else {
if ($this->config('login_no_wait')) {
location(Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
} else {
error($gnote, Url::home('member/login', null, "backurl=" . urlencode(get_current_url())));
}
}
}
}
}
}

View File

@@ -0,0 +1,509 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年06月26日
* 会员前台控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\MemberModel;
use core\basic\Url;
class MemberController extends Controller
{
protected $parser;
protected $model;
protected $htmldir;
public function __construct()
{
$this->model = new MemberModel();
$this->parser = new ParserController();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 会员登录页面
public function login()
{
// 已经登录时跳转到用户中心
if (session('pboot_uid')) {
location(Url::home('member/ucenter'));
}
// 执行登录验证
if ($_POST) {
if ($this->config('login_status') === '0') {
error('系统已经关闭登录功能,请到后台开启再试!');
}
// 验证码验证
$checkcode = strtolower(post('checkcode', 'var'));
if ($this->config('login_check_code') !== '0') {
if (! $checkcode) {
alert_back('验证码不能为空!');
}
if ($checkcode != session('checkcode')) {
alert_back('验证码错误!');
}
}
$username = post('username');
$password = post('password');
if (! $username) {
alert_back('用户账号不能为空!');
}
// 检查用户名
if (! $this->model->checkUsername("username='$username' or useremail='$username' or usermobile='$username'")) {
alert_back('用户账号不存在!');
}
// 检查密码
if (! $password) {
alert_back('用户密码不能为空!');
} else {
$password = md5(md5($password));
}
// 登录验证
if (! ! $login = $this->model->login("(username='$username' or useremail='$username' or usermobile='$username') AND password='$password'")) {
if (! $login->status) {
alert_back('您的账号待审核,请联系管理员!');
}
session('pboot_uid', $login->id);
session('pboot_ucode', $login->ucode);
session('pboot_username', $login->username);
session('pboot_useremail', $login->seremail);
session('pboot_usermobile', $login->usermobile);
session('pboot_gid', $login->gid);
session('pboot_gcode', $login->gcode);
session('pboot_gname', $login->gname);
if (! ! $backurl = get('backurl')) {
alert_location('登录成功!', $backurl, 1);
} else {
alert_location('登录成功!', Url::home('member/ucenter'), 1);
}
} else {
alert_back('账号密码错误,请核对后重试!', 0);
}
} else {
$content = parent::parser($this->htmldir . 'member/login.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', $this->config('login_title') ?: '会员登录-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '会员登录', Url::home('member/login')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 2, '会员登录', Url::home('member/login')); // 解析分类标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content;
exit();
}
}
// 会员注册页面
public function register()
{
// 已经登录时跳转到用户中心
if (session('pboot_uid')) {
location(Url::home('member/ucenter'));
}
// 执行注册
if ($_POST) {
if ($this->config('register_status') === '0') {
error('系统已经关闭注册功能,请到后台开启再试!');
}
if (time() - session('lastreg') < 10) {
alert_back('您注册太频繁了,请稍后再试!');
}
// 验证码验证
$checkcode = strtolower(post('checkcode', 'var'));
if ($this->config('register_check_code') !== '0') {
if (! $checkcode) {
alert_back('验证码不能为空!');
}
if ($checkcode != session('checkcode')) {
alert_back('验证码错误!');
}
}
$ucode = get_auto_code($this->model->getLastUcode(), 1);
$username = post('username'); // 接受用户名、邮箱、手机三种方式
$nickname = post('nickname');
$password = post('password');
$rpassword = post('rpassword');
$useremail = '';
$usermobile = '';
// 注册类型判断
if ($this->config('register_type') == 2) { // 邮箱注册
$useremail = $username;
if (! $useremail) {
alert_back('账号不能为空,请输入注册的邮箱账号!');
}
if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
alert_back('账号格式不正确,请输入正确的邮箱账号!');
}
if ($this->model->checkUsername("useremail='$useremail' OR username='$useremail'")) {
alert_back('您输入的邮箱已被注册!');
}
} elseif ($this->config('register_type') == 3) { // 手机注册
$usermobile = $username;
if (! $usermobile) {
alert_back('账号不能为空,请输入注册的手机号码!');
}
if (! preg_match('/^1[0-9]{10}$/', $usermobile)) {
alert_back('账号格式不正确,请输入正确的手机号码!');
}
if ($this->model->checkUsername("usermobile='$usermobile' OR username='$usermobile'")) {
alert_back('您输入的手机号码已被注册!');
}
} else { // 账号注册
if (! $username) {
alert_back('用户名不能为空!');
}
if (! preg_match('/^[\w\@\.]+$/', $username)) {
alert_back('用户账号含有不允许的特殊字符!');
}
// 检查用户名
if ($this->model->checkUsername("username='$username' OR useremail='$username' OR usermobile='$username'")) {
alert_back('您输入的账号已被注册!');
}
}
if ($password != $rpassword) {
alert_back('确认密码不正确!');
}
if (! $password) {
alert_back('密码不能为空!');
} else {
$password = md5(md5($password));
}
// 默认值设置
$status = $this->config('register_verify') ? 0 : 1; // 默认不需要审核
$score = $this->config('register_score') ?: 0;
$group = $this->model->getFirstGroup();
$gid = $this->model->getGroupID($this->config('register_gcode')) ?: $group->id;
// 构建数据
$data = array(
'ucode' => $ucode,
'username' => $username,
'useremail' => $useremail,
'usermobile' => $usermobile,
'nickname' => $nickname,
'password' => $password,
'headpic' => '',
'status' => $status,
'gid' => $gid,
'wxid' => '',
'qqid' => '',
'wbid' => '',
'activation' => 1,
'score' => $score,
'register_time' => get_datetime(),
'login_count' => 0,
'last_login_ip' => 0,
'last_login_time' => 0
);
// 读取字段
if (! ! $field = $this->model->getField()) {
foreach ($field as $value) {
$field_data = post($value->name);
if (is_array($field_data)) { // 如果是多选等情况时转换
$field_data = implode(',', $field_data);
}
$field_data = preg_replace_r('pboot:if', '', $field_data);
if ($value->required && ! $field_data) {
alert_back($value->description . '不能为空!');
} else {
$data[$value->name] = $field_data;
}
}
}
// 执行注册
if ($this->model->register($data)) {
session('lastreg', time()); // 记录最后提交时间
if ($status) {
alert_location('注册成功!', Url::home('member/login'), 1);
} else {
alert_location('注册成功,请等待管理员审核!', Url::home('member/login'), 1);
}
} else {
error('会员注册失败!', - 1);
}
} else {
$content = parent::parser($this->htmldir . 'member/register.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', $this->config('register_title') ?: '会员注册-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '会员注册', Url::home('member/register')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 3, '会员注册', Url::home('member/register')); // 解析分类标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content;
exit();
}
}
// 用户中心
public function ucenter()
{
// 未登录时跳转到用户登录
if (! session('pboot_uid')) {
location(Url::home('member/login'));
}
$content = parent::parser($this->htmldir . 'member/ucenter.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', $this->config('ucenter_title') ?: '个人中心-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '个人中心', Url::home('member/ucenter')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 4, '个人中心', Url::home('member/ucenter')); // 解析分类标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content;
exit();
}
// 用户修改
public function umodify()
{
// 未登录时跳转到用户登录
if (! session('pboot_uid')) {
location(Url::home('member/login'));
}
// 执行资料修改
if ($_POST && session('pboot_uid')) {
$nickname = post('nickname');
$useremail = post('useremail');
$usermobile = post('usermobile');
$password = post('password');
$rpassword = post('rpassword');
$headpic = str_replace(SITE_DIR, '', post('headpic'));
if ($useremail) { // 邮箱校验
if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $useremail)) {
alert_back('邮箱格式不正确,请输入正确的邮箱账号!');
}
if ($this->model->checkUsername("(useremail='$useremail' OR username='$useremail') AND id<>'" . session('pboot_uid') . "'")) {
alert_back('您输入的邮箱已被注册!');
}
}
if ($usermobile) { // 手机检验
if (! preg_match('/^1[0-9]{10}$/', $usermobile)) {
alert_back('手机格式不正确,请输入正确的手机号码!');
}
if ($this->model->checkUsername("(usermobile='$usermobile' OR username='$usermobile') AND id<>'" . session('pboot_uid') . "'")) {
alert_back('您输入的手机号码已被注册!');
}
}
// 构建数据
$data = array(
'nickname' => $nickname,
'useremail' => $useremail,
'usermobile' => $usermobile,
'headpic' => $headpic
);
// 密码修改
if ($password) {
if ($password != $rpassword) {
alert_back('确认密码不正确!');
} else {
$data['password'] = md5(md5($password));
}
}
// 读取字段
if (! ! $field = $this->model->getField()) {
foreach ($field as $value) {
$field_data = post($value->name);
if (is_array($field_data)) { // 如果是多选等情况时转换
$field_data = implode(',', $field_data);
}
$field_data = preg_replace_r('pboot:if', '', $field_data);
if ($value->required && ! $field_data) {
alert_back($value->description . '不能为空!');
} else {
$data[$value->name] = $field_data;
}
}
}
// 不允许修改的字段
unset($data['id']);
unset($data['ucode']);
unset($data['username']);
unset($data['status']);
unset($data['gid']);
unset($data['wxid']);
unset($data['qqid']);
unset($data['wbid']);
unset($data['score']);
unset($data['register_time']);
unset($data['login_count']);
unset($data['last_login_ip']);
unset($data['last_login_time']);
// 执行修改
if ($this->model->modUser($data)) {
alert_location('修改成功!', Url::home('member/umodify'), 1);
} else {
error('资料修改失败!', - 1);
}
} else {
$content = parent::parser($this->htmldir . 'member/umodify.html'); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = str_replace('{pboot:pagetitle}', $this->config('umodify_title') ?: '资料修改-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '资料修改', Url::home('member/umodify')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 5, '资料修改', Url::home('member/umodify')); // 解析分类标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content;
exit();
}
}
// 退出登录
public function logout()
{
session('pboot_uid', '');
session('pboot_ucode', '');
session('pboot_username', '');
session('pboot_useremail', '');
session('pboot_usermobile', '');
session('pboot_gid', '');
session('pboot_gcode', '');
session('pboot_gname', '');
location(Url::home('member/login'));
}
// 文件上传方法(Ajax)
public function upload()
{
// 必须登录
if (! session('pboot_uid')) {
json(0, '请先登录!');
}
$ext = $this->config('home_upload_ext') ?: "jpg,jpeg,png,gif,xls,xlsx,doc,docx,ppt,pptx,rar,zip,pdf,txt";
$upload = upload('upload', $ext);
if (is_array($upload)) {
json(1, $upload);
} else {
json(0, $upload);
}
}
// 发送邮件
public function sendEmail()
{
if ($this->config('register_check_code') != 2) {
json(0, '发送失败,后台配置非邮箱验证码模式!');
}
if (time() - session('lastsend') < 10) {
json(0, '您提交太频繁了,请稍后再试!');
}
if (! session('sendemail')) {
json(0, '非法提交发送邮件!');
}
// 发送邮箱参数
if (! ! $to = post('to')) {
if (! preg_match('/^[\w]+@[\w]+\.[a-zA-Z]+$/', $to)) {
json(0, '邮箱格式不正确,请输入正确的邮箱账号!');
}
} else {
json(0, '发送失败缺少发送对象参数to');
}
// 检查邮箱注册
if ($this->model->checkUsername("useremail='$to' OR username='$to'")) {
alert_back('您输入的邮箱已被注册!');
}
$rs = false;
if ($to) {
session('lastsend', time()); // 记录最后提交时间
$mail_subject = "【PbootCMS】您有新的验证码信息请注意查收";
$code = create_code(4);
session('checkcode', strtolower($code));
$mail_body = "您的验证码为:" . $code;
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
$rs = sendmail($this->config(), $to, $mail_subject, $mail_body);
}
if ($rs === true) {
json(1, '发送成功!');
} else {
json(0, '发送失败,' . $rs);
}
}
// 检查用户是否注册
public function isRegister()
{
// 接受用户名、邮箱、手机三种方式
$info = '';
if (! $username = post('username')) {
$err = '账号不能为空!';
}
// 注册类型判断
if ($this->config('register_type') == 2) { // 邮箱注册
if (! preg_match('/^[\w]+@[\w\.]+\.[a-zA-Z]+$/', $username)) {
$err = '账号格式不正确,请输入正确的邮箱账号!';
}
if ($this->model->checkUsername("useremail='$username' OR username='$username'")) {
$err = '您输入的邮箱已被注册!';
} else {
$suc = '您输入的邮箱可以使用!';
}
} elseif ($this->config('register_type') == 3) { // 手机注册
if (! preg_match('/^1[0-9]{10}$/', $username)) {
$err = '账号格式不正确,请输入正确的手机号码!';
}
if ($this->model->checkUsername("usermobile='$username' OR username='$username'")) {
$err = '您输入的手机号码已被注册!';
} else {
$suc = '您输入的手机号码可以使用!';
}
} else { // 账号注册
if (! preg_match('/^[\w\@\.]+$/', $username)) {
$err = '用户账号含有不允许的特殊字符!';
}
// 检查用户名
if ($this->model->checkUsername("username='$username' OR useremail='$username' OR usermobile='$username'")) {
$err = '您输入的账号已被注册!';
} else {
$suc = '您输入的账号可以使用!';
}
}
if ($err) {
json(1, $err);
} else {
json(0, $suc);
}
}
public function _empty()
{
_404('您访问的地址不存在,请核对再试!');
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 留言控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\ParserModel;
use core\basic\Url;
class MessageController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new ParserModel();
}
// 留言新增
public function index()
{
if ($_POST) {
if ($this->config('message_status') === '0') {
error('系统已经关闭留言功能,请到后台开启再试!');
}
if (time() - session('lastsub') < 10) {
alert_back('您提交太频繁了,请稍后再试!');
}
// 需登录
if ($this->config('message_rqlogin') && ! session('pboot_uid')) {
if (! ! $backurl = $_SERVER['HTTP_REFERER']) {
alert_location("请先注册登录后再留言!", Url::home('member/login', null, "backurl=" . urlencode($backurl)));
} else {
alert_location("请先注册登录后再留言!", Url::home('member/login'));
}
}
// 验证码验证
$checkcode = strtolower(post('checkcode', 'var'));
if ($this->config('message_check_code') !== '0') {
if (! $checkcode) {
alert_back('验证码不能为空!');
}
if ($checkcode != session('checkcode')) {
alert_back('验证码错误!');
}
}
// 读取字段
if (! $form = $this->model->getFormField(1)) {
alert_back('留言表单不存在任何字段,请核对后重试!');
}
// 接收数据
$mail_body = '';
foreach ($form as $value) {
$field_data = post($value->name);
if (is_array($field_data)) { // 如果是多选等情况时转换
$field_data = implode(',', $field_data);
}
$field_data = preg_replace_r('/pboot:if/i', '', $field_data);
if ($value->required && ! $field_data) {
alert_back($value->description . '不能为空!');
} else {
$data[$value->name] = $field_data;
$mail_body .= $value->description . '' . $field_data . '<br>';
}
}
$status = $this->config('message_verify') === '0' ? 1 : 0;
// 设置额外数据
if ($data) {
$data['acode'] = get_lg();
$data['user_ip'] = ip2long(get_user_ip());
$data['user_os'] = get_user_os();
$data['user_bs'] = get_user_bs();
$data['recontent'] = '';
$data['status'] = $status;
$data['create_user'] = 'guest';
$data['update_user'] = 'guest';
$data['uid'] = session('pboot_uid');
}
if ($this->model->addMessage($data)) {
session('lastsub', time()); // 记录最后提交时间
$this->log('留言提交成功!');
if ($this->config('message_send_mail') && $this->config('message_send_to')) {
$mail_subject = "【PbootCMS】您有新的" . $value->form_name . "信息,请注意查收!";
$mail_body .= '<br>来自网站 ' . get_http_url() . ' ' . date('Y-m-d H:i:s') . '';
sendmail($this->config(), $this->config('message_send_to'), $mail_subject, $mail_body);
}
alert_location('提交成功!', '-1', 1);
} else {
$this->log('留言提交失败!');
alert_back('提交失败!');
}
} else {
alert_back('提交失败请使用POST方式提交');
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,46 @@
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 搜索控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use core\basic\Url;
class SearchController extends Controller
{
protected $parser;
protected $htmldir;
public function __construct()
{
$this->parser = new ParserController();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 内容搜索
public function index()
{
$searchtpl = request('searchtpl');
if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
$searchtpl = 'search.html';
}
$content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$pagetitle = get('keyword', 'var') ? get('keyword', 'var') . '-' : '';
$content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . '搜索结果-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = $this->parser->parserPositionLabel($content, 0, '搜索', Url::home('search')); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 1, '搜索结果', Url::home('search')); // 解析分类标签
$content = $this->parser->parserSearchLabel($content); // 搜索结果标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
echo $content; // 搜索页面不缓存
exit();
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年7月15日
* 生成sitemap文件
*/
namespace app\home\controller;
use core\basic\Controller;
use app\home\model\SitemapModel;
use core\basic\Url;
class SitemapController extends Controller
{
protected $model;
public function __construct()
{
$this->model = new SitemapModel();
}
public function index()
{
header("Content-type:text/xml;charset=utf-8");
$str = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$str .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">' . "\n";
$str .= $this->makeNode('', date('Y-m-d'), '1.00'); // 根目录
$url_break_char = $this->config('url_break_char') ?: '_';
$sorts = $this->model->getSorts();
foreach ($sorts as $value) {
if ($value->outlink) {
continue;
} elseif ($value->type == 1) {
$value->urlname = $value->urlname ?: 'list';
if ($value->filename) {
$link = Url::home($value->filename);
} else {
$link = Url::home($value->urlname . $url_break_char . $value->scode);
}
$str .= $this->makeNode($link, date('Y-m-d'), '0.80');
} else {
$value->urlname = $value->urlname ?: 'list';
if ($value->filename) {
$link = Url::home($value->filename);
} else {
$link = Url::home($value->urlname . $url_break_char . $value->scode);
}
$str .= $this->makeNode($link, date('Y-m-d'), '0.80');
$contents = $this->model->getSortContent($value->scode);
foreach ($contents as $value2) {
if ($value2->outlink) { // 外链
continue;
} else {
$value2->urlname = $value2->urlname ?: 'list';
if ($value2->filename && $value2->sortfilename) {
$link = Url::home($value2->sortfilename . '/' . $value2->filename, true);
} elseif ($value2->sortfilename) {
$link = Url::home($value2->sortfilename . '/' . $value2->id, true);
} elseif ($value2->contentfilename) {
$link = Url::home($value2->urlname . $url_break_char . $value2->scode . '/' . $value2->filename, true);
} else {
$link = Url::home($value2->urlname . $url_break_char . $value2->scode . '/' . $value2->id, true);
}
}
$str .= $this->makeNode($link, date('Y-m-d'), '0.60');
}
}
}
echo $str . "\n</urlset>";
}
// 生成结点信息
private function makeNode($link, $date, $priority = 0.60)
{
$node = '
<url>
<mobile:mobile type="pc,mobile"/>
<loc>' . get_http_url() . $link . '</loc>
<priority>' . $priority . '</priority>
<lastmod>' . $date . '</lastmod>
<changefreq>Always</changefreq>
</url>';
return $node;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* @copyright (C)2020-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2020年3月8日
* 标签控制器
*/
namespace app\home\controller;
use core\basic\Controller;
use core\basic\Url;
class TagController extends Controller
{
protected $parser;
protected $htmldir;
public function __construct()
{
$this->parser = new ParserController();
$this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
}
// 内容搜索
public function index()
{
// 在非兼容模式接受地址第二参数值
if (defined('RVAR')) {
$_GET['tag'] = RVAR;
}
if (! get('tag')) {
_404('您访问的页面不存在,请核对后重试!');
}
$tagstpl = request('tagstpl');
if (! preg_match('/^[\w]+\.html$/', $tagstpl)) {
$tagstpl = 'tags.html';
}
$content = parent::parser($this->htmldir . $tagstpl); // 框架标签解析
$content = $this->parser->parserBefore($content); // CMS公共标签前置解析
$content = $this->parser->parserPositionLabel($content, 0, '相关内容', Url::home('tag/' . get('tag'))); // CMS当前位置标签解析
$content = $this->parser->parserSpecialPageSortLabel($content, - 2, '相关内容', Url::home('tag/' . get('tag'))); // 解析分类标签
$content = $this->parser->parserAfter($content); // CMS公共标签后置解析
$this->cache($content, true);
}
}