初始化官网代码

This commit is contained in:
wojiaoxiaomage
2025-12-30 10:26:47 +08:00
commit 00f55e8b83
232 changed files with 49856 additions and 0 deletions

View File

@@ -0,0 +1,349 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年3月13日
* 默认主页
*/
namespace app\admin\controller;
use core\basic\Controller;
use app\admin\model\IndexModel;
class IndexController extends Controller
{
private $model;
public function __construct()
{
$this->model = new IndexModel();
}
// 登录页面
public function index()
{
if (session('sid')) {
location(url('admin/Index/home'));
}
$this->assign('admin_check_code', $this->config('admin_check_code'));
$this->display('index.html');
}
// 主页面
public function home()
{
// 手动修改数据名称
if (get('action') == 'moddb') {
if ($this->modDB()) {
alert_back('修改成功!');
} else {
alert_back('修改失败!');
}
}
// 删除修改后老数据库(上一步无法直接修改删除)
if (issetSession('deldb')) {
@unlink(ROOT_PATH . session('deldb'));
unset($_SESSION['deldb']);
}
$dbsecurity = true;
// 如果是sqlite数据库并且路径为默认的则标记为不安全
if (get_db_type() == 'sqlite') {
if (strpos($this->config('database.dbname'), 'pbootcms') !== false) {
if (get_user_ip() != '127.0.0.1' && $this->modDB()) { // 非本地测试时尝试自动修改数据库名称
$dbsecurity = true;
} else {
$dbsecurity = false;
}
}
} elseif (file_exists(ROOT_PATH . '/data/pbootcms.db')) {
rename(ROOT_PATH . '/data/pbootcms.db', ROOT_PATH . '/data/' . get_uniqid() . '.db');
}
$this->assign('dbsecurity', $dbsecurity);
if (! session('pwsecurity')) {
location(url('/admin/Index/ucenter'));
}
$this->assign('server', get_server_info());
$this->assign('branch', $this->config('upgrade_branch') == '3.X.dev' ? '3.X.dev' : '3.X');
$this->assign('revise', $this->config('revise_version') ?: '0');
$this->assign('snuser', $this->config('sn_user') ?: '0');
$this->assign('site', get_http_url());
$this->assign('user_info', $this->model->getUserInfo(session('ucode')));
$this->assign('sum_msg', model('admin.content.Message')->getCount());
// 内容模型菜单
$model = model('admin.content.Model');
$models = $model->getModelMenu();
foreach ($models as $key => $value) {
$models[$key]->count = $model->getModelCount($value->mcode)->count;
}
$this->assign('model_msg', $models);
$this->display('system/home.html');
}
// 异步登录验证
public function login()
{
if (! $_POST) {
return;
}
// 在安装了gd库时才执行验证码验证
if (extension_loaded("gd") && $this->config('admin_check_code') && strtolower(post('checkcode', 'var')) != session('checkcode')) {
json(0, '验证码错误!');
}
// 就收数据
$username = post('username');
$password = post('password');
if (! preg_match('/^[\x{4e00}-\x{9fa5}\w\-\.@]+$/u', $username)) {
json(0, '用户名含有不允许的特殊字符!');
}
if (! $username) {
json(0, '用户名不能为空!');
}
if (! $password) {
json(0, '密码不能为空!');
}
if (! ! $time = $this->checkLoginBlack()) {
$this->log('登录锁定!');
json(0, '您登录失败次数太多已被锁定,请' . $time . '秒后再试!');
}
// 执行用户登录
$where = array(
'username' => $username,
'password' => encrypt_string($password)
);
// 判断数据库写入权限
if ((get_db_type() == 'sqlite') && ! is_writable(ROOT_PATH . $this->config('database.dbname'))) {
json(0, '数据库目录写入权限不足!');
}
if (! ! $login = $this->model->login($where)) {
session_regenerate_id(true);
session('sid', encrypt_string(session_id() . $login->id)); // 会话标识
session('M', M);
session('id', $login->id); // 用户id
session('ucode', $login->ucode); // 用户编码
session('username', $login->username); // 用户名
session('realname', $login->realname); // 真实名字
if ($where['password'] != '14e1b600b1fd579f47433b88e8d85291') {
session('pwsecurity', true);
}
session('acodes', $login->acodes); // 用户管理区域
if ($login->acodes) { // 当前显示区域
session('acode', $login->acodes[0]);
} else {
session('acode', '');
}
session('rcodes', $login->rcodes); // 用户角色代码表
session('levels', $login->levels); // 用户权限URL列表
session('menu_tree', $login->menus); // 菜单树
session('area_map', $login->area_map); // 区域代码名称映射表
session('area_tree', $login->area_tree); // 用户区域树
$this->log('登录成功!');
json(1, url('admin/Index/home'));
} else {
$this->setLoginBlack();
$this->log('登录失败!');
session('checkcode', mt_rand(10000, 99999)); // 登录失败,随机打乱原有验证码
json(0, '用户名或密码错误!');
}
}
// 退出登录
public function loginOut()
{
session_unset();
location(url('/admin/Index/index'));
}
// 用户中心,修改密码
public function ucenter()
{
if ($_POST) {
$username = post('username'); // 用户名
$realname = post('realname'); // 真实姓名
$cpassword = post('cpassword'); // 现在密码
$password = post('password'); // 新密码
$rpassword = post('rpassword'); // 确认密码
if (! $username) {
alert_back('用户名不能为空!');
}
if (! $cpassword) {
alert_back('当前密码不能为空!');
}
if (! preg_match('/^[\x{4e00}-\x{9fa5}\w\-\.@]+$/u', $username)) {
alert_back('用户名含有不允许的特殊字符!');
}
$data = array(
'username' => $username,
'realname' => $realname,
'update_user' => $username
);
// 如果有修改密码,则添加数据
if ($password) {
if ($password != $rpassword) {
alert_back('确认密码不正确!');
}
$data['password'] = encrypt_string($password);
if ($data['password'] != '14e1b600b1fd579f47433b88e8d85291') {
session('pwsecurity', true);
} else {
session('pwsecurity', false);
}
}
// 检查现有密码
if ($this->model->checkUserPwd(encrypt_string($cpassword))) {
if ($this->model->modUserInfo($data)) {
session('username', post('username'));
session('realname', post('realname'));
$this->log('用户资料成功!');
success('用户资料修改成功!', - 1);
}
} else {
$this->log('用户资料修改时当前密码错误!');
alert_location('当前密码错误!', - 1);
}
}
$this->display('system/ucenter.html');
}
// 切换显示的数据区域
public function area()
{
if ($_POST) {
$acode = post('acode');
if (in_array($acode, session('acodes'))) {
session('acode', $acode);
cookie('lg', $acode); // 同步切换前台语言
}
location(url('admin/Index/home'));
}
}
// 清理缓存
public function clearCache()
{
if (get('delall')) {
$rs = path_delete(RUN_PATH);
} else {
$rs = (path_delete(RUN_PATH . '/cache') && path_delete(RUN_PATH . '/complile') && path_delete(RUN_PATH . '/config') && path_delete(RUN_PATH . '/upgrade') && path_delete(RUN_PATH . '/image'));
}
if ($rs) {
if (extension_loaded('Zend OPcache')) {
opcache_reset(); // 在启用了OPcache加速器时同时清理
}
$this->log('清理缓存成功!');
alert_back('清理缓存成功!');
} else {
$this->log('清理缓存失败!');
alert_back('清理缓存失败!');
}
}
// 文件上传方法
public function upload()
{
$upload = upload('upload');
if (is_array($upload)) {
json(1, $upload);
} else {
json(0, $upload);
}
}
// 检查是否在黑名单
private function checkLoginBlack()
{
// 读取黑名单
$ip_black = RUN_PATH . '/data/' . md5('login_black') . '.php';
if (file_exists($ip_black)) {
$data = require $ip_black;
$user_ip = get_user_ip();
$lock_time = $this->config('lock_time') ?: 900;
$lock_count = $this->config('lock_count') ?: 5;
if (isset($data[$user_ip]) && $data[$user_ip]['count'] >= $lock_count && time() - $data[$user_ip]['time'] < $lock_time) {
return $lock_time - (time() - $data[$user_ip]['time']); // 返回剩余秒数
}
}
return false;
}
// 添加登录黑名单
private function setLoginBlack()
{
// 读取黑名单
$ip_black = RUN_PATH . '/data/' . md5('login_black') . '.php';
if (file_exists($ip_black)) {
$data = require $ip_black;
} else {
$data = array();
}
// 添加IP
$user_ip = get_user_ip();
$lock_time = $this->config('lock_time') ?: 900;
$lock_count = $this->config('lock_count') ?: 5;
if (isset($data[$user_ip]) && $data[$user_ip]['count'] < $lock_count && time() - $data[$user_ip]['time'] < $lock_time) {
$data[$user_ip] = array(
'time' => time(),
'count' => $data[get_user_ip()]['count'] + 1
);
} else {
$data[$user_ip] = array(
'time' => time(),
'count' => 1
);
}
// 写入黑名单
check_file($ip_black, true);
return file_put_contents($ip_black, "<?php\nreturn " . var_export($data, true) . ";");
}
// 修改数据库名称
private function modDB()
{
$file = CONF_PATH . '/database.php';
$sname = $this->config('database.dbname');
$dname = '/data/' . get_uniqid() . '.db';
$sconfig = file_get_contents($file);
$dconfig = str_replace($sname, $dname, $sconfig);
if (file_put_contents($file, $dconfig)) {
if (! copy(ROOT_PATH . $sname, ROOT_PATH . $dname)) {
file_put_contents($file, $sconfig); // 回滚配置
} else {
session('deldb', $sname);
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,535 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年12月15日
* 文章控制器
*/
namespace app\admin\controller\content;
use core\basic\Controller;
use app\admin\model\content\ContentModel;
class ContentController extends Controller
{
private $model;
private $blank;
public function __construct()
{
$this->model = new ContentModel();
}
// 文章列表
public function index()
{
if ((! ! $id = get('id', 'int')) && $result = $this->model->getContent($id)) {
$this->assign('more', true);
$this->assign('content', $result);
} else {
$this->assign('list', true);
if (! $mcode = get('mcode', 'var')) {
error('传递的模型编码参数有误,请核对后重试!');
}
if (isset($_GET['keyword'])) {
if (! ! $scode = get('scode', 'var')) {
$result = $this->model->findContent($mcode, $scode, get('keyword', 'vars'));
} else {
$result = $this->model->findContentAll($mcode, get('keyword', 'vars'));
}
} else {
$result = $this->model->getList($mcode);
}
$this->assign('contents', $result);
// 文章分类下拉列表
$sort_model = model('admin.content.ContentSort');
$sort_select = $sort_model->getListSelect($mcode);
$this->assign('search_select', $this->makeSortSelect($sort_select, get('scode')));
$this->assign('sort_select', $this->makeSortSelect($sort_select, session('addscode')));
$this->assign('subsort_select', $this->makeSortSelect($sort_select));
// 模型名称
$this->assign('model_name', model('admin.content.Model')->getName($mcode));
// 扩展字段
$this->assign('extfield', model('admin.content.ExtField')->getModelField($mcode));
$this->assign('baidu_zz_token', $this->config('baidu_zz_token'));
$this->assign('baidu_ks_token', $this->config('baidu_ks_token'));
// 前端地址连接符判断
$url_break_char = $this->config('url_break_char') ?: '_';
$this->assign('url_break_char', $url_break_char);
// 获取会员分组
$this->assign('groups', model('admin.member.MemberGroup')->getSelect());
}
$this->display('content/content.html');
}
// 文章增加
public function add()
{
if ($_POST) {
// 获取数据
$scode = post('scode');
$subscode = post('subscode');
$title = post('title');
$titlecolor = post('titlecolor');
$subtitle = post('subtitle');
$filename = post('filename');
$author = post('author');
$source = post('source');
$outlink = post('outlink');
$date = post('date');
$ico = post('ico');
$pics = post('pics');
$content = post('content');
$tags = str_replace('', ',', post('tags'));
$enclosure = post('enclosure');
$keywords = post('keywords');
$description = post('description');
$status = post('status', 'int');
$istop = post('istop', 'int', '', '', 0);
$isrecommend = post('isrecommend', 'int', '', '', 0);
$isheadline = post('isheadline', 'int', '', '', 0);
$gid = post('gid', 'int') ?: 0;
$gtype = post('gtype', 'int') ?: 4;
$gnote = post('gnote');
if (! $scode) {
alert_back('内容分类不能为空!');
}
if (! $title) {
alert_back('文章标题不能为空!');
}
if ($filename && ! preg_match('/^[a-zA-Z0-9\-]+$/', $filename)) {
alert_back('内容URL名称只允许字母、数字、横线组成!');
}
// 自动提起前一百个字符为描述
if (! $description && isset($_POST['content'])) {
$description = escape_string(clear_html_blank(substr_both(strip_tags($_POST['content']), 0, 150)));
}
// 缩放缩略图
if ($ico) {
resize_img(ROOT_PATH . $ico, '', $this->config('ico.max_width'), $this->config('ico.max_height'));
}
// 检查自定义URL名称
if ($filename) {
while ($this->model->checkFilename($filename)) {
$filename = $filename . '-' . mt_rand(1, 20);
}
}
// 记住新增栏目
session('addscode', $scode);
// 构建数据
$data = array(
'acode' => session('acode'),
'scode' => $scode,
'subscode' => $subscode,
'title' => $title,
'titlecolor' => $titlecolor,
'subtitle' => $subtitle,
'filename' => $filename,
'author' => $author,
'source' => $source,
'outlink' => $outlink,
'date' => $date,
'ico' => $ico,
'pics' => $pics,
'content' => $content,
'tags' => $tags,
'enclosure' => $enclosure,
'keywords' => $keywords,
'description' => clear_html_blank($description),
'sorting' => 255,
'status' => $status,
'istop' => $istop,
'isrecommend' => $isrecommend,
'isheadline' => $isheadline,
'gid' => $gid,
'gtype' => $gtype,
'gnote' => $gnote,
'visits' => 0,
'likes' => 0,
'oppose' => 0,
'create_user' => session('username'),
'update_user' => session('username')
);
// 执行添加
if (! ! $id = $this->model->addContent($data)) {
// 扩展内容添加
foreach ($_POST as $key => $value) {
if (preg_match('/^ext_[\w\-]+$/', $key)) {
if (! isset($data2['contentid'])) {
$data2['contentid'] = $id;
}
$temp = post($key);
if (is_array($temp)) {
$data2[$key] = implode(',', $temp);
} else {
$data2[$key] = str_replace("\r\n", '<br>', $temp);
}
}
}
if (isset($data2)) {
if (! $this->model->addContentExt($data2)) {
$this->model->delContent($id);
$this->log('新增文章失败!');
error('新增失败!', - 1);
}
}
$this->log('新增文章成功!');
if (! ! $backurl = get('backurl')) {
success('新增成功!', base64_decode($backurl));
} else {
success('新增成功!', url('/admin/Content/index/mcode/' . get('mcode')));
}
} else {
$this->log('新增文章失败!');
error('新增失败!', - 1);
}
}
}
// 生成分类选择
private function makeSortSelect($tree, $selectid = null)
{
$list_html = '';
foreach ($tree as $value) {
// 默认选择项
if ($selectid == $value->scode) {
$select = "selected='selected'";
} else {
$select = '';
}
$list_html .= "<option value='{$value->scode}' $select>{$this->blank}{$value->name}";
// 子菜单处理
if ($value->son) {
$this->blank .= '  ';
$list_html .= $this->makeSortSelect($value->son, $selectid);
}
}
// 循环完后回归位置
$this->blank = substr($this->blank, 0, - 6);
return $list_html;
}
// 文章删除
public function del()
{
// 执行批量删除
if ($_POST) {
if (! ! $list = post('list')) {
if ($this->model->delContentList($list)) {
$this->model->delContentExtList($list);
$this->log('批量删除文章成功!');
success('批量删除成功!', - 1);
} else {
$this->log('批量删除文章失败!');
error('批量删除失败!', - 1);
}
} else {
alert_back('请选择要删除的内容!');
}
}
if (! $id = get('id', 'int')) {
error('传递的参数值错误!', - 1);
}
if ($this->model->delContent($id)) {
$this->model->delContentExt($id);
$this->log('删除文章' . $id . '成功!');
success('删除成功!', - 1);
} else {
$this->log('删除文章' . $id . '失败!');
error('删除失败!', - 1);
}
}
// 文章修改
public function mod()
{
if (! ! $submit = post('submit')) {
switch ($submit) {
case 'sorting': // 修改列表排序
$listall = post('listall');
if ($listall) {
$sorting = post('sorting');
foreach ($listall as $key => $value) {
if ($sorting[$key] === '' || ! is_numeric($sorting[$key]))
$sorting[$key] = 255;
$this->model->modContent($value, "sorting=" . $sorting[$key]);
}
$this->log('修改内容排序成功!');
success('修改成功!', - 1);
} else {
alert_back('排序失败,无任何内容!');
}
break;
case 'copy':
$list = post('list');
$scode = post('scode');
if (! $list) {
alert_back('请选择要复制的内容!');
}
if (! $scode) {
alert_back('请选择目标栏目!');
}
if ($this->model->copyContent($list, $scode)) {
$this->log('复制内容成功!');
success('复制内容成功!', - 1);
} else {
alert_back('复制内容失败!');
}
break;
case 'move':
$list = post('list');
$scode = post('scode');
if (! $list) {
alert_back('请选择要移动的内容!');
}
if (! $scode) {
alert_back('请选择目标栏目!');
}
if ($this->model->modContent($list, "scode='" . $scode . "'")) {
$this->log('移动内容成功!');
success('移动内容成功!', - 1);
} else {
alert_back('移动内容失败!');
}
break;
case 'baiduzz':
$list = post('list');
$urls = post('urls');
if (! $list) {
alert_back('请选择要推送的内容!');
}
// 依次推送
$domain = get_http_url();
if (! $token = $this->config('baidu_zz_token')) {
alert_back('请先到系统配置中填写百度普通收录推送token值');
}
$api = "http://data.zz.baidu.com/urls?site=$domain&token=$token";
foreach ($list as $key => $value) {
$url = $domain . $urls[$value];
$this->log('百度普通收录推送:' . $url);
$post_urls[] = $url;
}
$result = post_baidu($api, $post_urls);
if (isset($result->error)) {
alert_back('百度普通收录推送发生错误:' . $result->message);
} elseif (isset($result->success)) {
alert_back('成功推送' . $result->success . '条,今天剩余可推送' . $result->remain . '条数!');
} else {
alert_back('发生未知错误!');
}
case 'baiduks':
$list = post('list');
$urls = post('urls');
if (! $list) {
alert_back('请选择要推送的内容!');
}
// 依次推送
$domain = get_http_url();
if (! $token = $this->config('baidu_ks_token')) {
alert_back('请先到系统配置中填写百度快速收录推送token值');
}
$api = "http://data.zz.baidu.com/urls?site=$domain&token=$token&type=daily";
foreach ($list as $key => $value) {
$url = $domain . $urls[$value];
$this->log('百度快速收录推送:' . $url);
$post_urls[] = $url;
}
$result = post_baidu($api, $post_urls);
if (isset($result->error)) {
alert_back('百度快速收录推送发生错误:' . $result->message);
} elseif (isset($result->success_daily)) {
alert_back('成功推送' . $result->success_daily . '条,今天剩余可推送' . $result->remain_daily . '条数!');
} else {
alert_back('发生未知错误!');
}
}
}
if (! $id = get('id', 'int')) {
error('传递的参数值错误!', - 1);
}
// 单独修改状态
if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
if ($this->model->modContent($id, "$field='$value',update_user='" . session('username') . "'")) {
location(- 1);
} else {
alert_back('修改失败!');
}
}
// 修改操作
if ($_POST) {
// 获取数据
$scode = post('scode');
$subscode = post('subscode');
$title = post('title');
$titlecolor = post('titlecolor');
$subtitle = post('subtitle');
$filename = post('filename');
$author = post('author');
$source = post('source');
$outlink = post('outlink');
$date = post('date');
$ico = post('ico');
$pics = post('pics');
$content = post('content');
$tags = str_replace('', ',', post('tags'));
$enclosure = post('enclosure');
$keywords = post('keywords');
$description = post('description');
$status = post('status', 'int');
$istop = post('istop', 'int', '', '', 0);
$isrecommend = post('isrecommend', 'int', '', '', 0);
$isheadline = post('isheadline', 'int', '', '', 0);
$gid = post('gid', 'int') ?: 0;
$gtype = post('gtype', 'int') ?: 4;
$gnote = post('gnote');
if (! $scode) {
alert_back('内容分类不能为空!');
}
if (! $title) {
alert_back('文章标题不能为空!');
}
if ($filename && ! preg_match('/^[a-zA-Z0-9\-]+$/', $filename)) {
alert_back('内容URL名称只允许字母、数字、横线组成!');
}
// 自动提起前一百个字符为描述
if (! $description && isset($_POST['content'])) {
$description = escape_string(clear_html_blank(substr_both(strip_tags($_POST['content']), 0, 150)));
}
// 缩放缩略图
if ($ico) {
resize_img(ROOT_PATH . $ico, '', $this->config('ico.max_width'), $this->config('ico.max_height'));
}
if ($filename) {
while ($this->model->checkFilename($filename, "id<>$id")) {
$filename = $filename . '-' . mt_rand(1, 20);
}
}
// 构建数据
$data = array(
'scode' => $scode,
'subscode' => $subscode,
'title' => $title,
'titlecolor' => $titlecolor,
'subtitle' => $subtitle,
'filename' => $filename,
'author' => $author,
'source' => $source,
'outlink' => $outlink,
'date' => $date,
'ico' => $ico,
'pics' => $pics,
'content' => $content,
'tags' => $tags,
'enclosure' => $enclosure,
'keywords' => $keywords,
'description' => clear_html_blank($description),
'status' => $status,
'istop' => $istop,
'isrecommend' => $isrecommend,
'isheadline' => $isheadline,
'gid' => $gid,
'gtype' => $gtype,
'gnote' => $gnote,
'update_user' => session('username')
);
// 执行添加
if ($this->model->modContent($id, $data)) {
// 扩展内容修改
foreach ($_POST as $key => $value) {
if (preg_match('/^ext_[\w\-]+$/', $key)) {
$temp = post($key);
if (is_array($temp)) {
$data2[$key] = implode(',', $temp);
} else {
$data2[$key] = str_replace("\r\n", '<br>', $temp);
}
}
}
if (isset($data2)) {
if ($this->model->findContentExt($id)) {
$this->model->modContentExt($id, $data2);
} else {
$data2['contentid'] = $id;
$this->model->addContentExt($data2);
}
}
$this->log('修改文章' . $id . '成功!');
if (! ! $backurl = get('backurl')) {
success('修改成功!', base64_decode($backurl));
} else {
success('修改成功!', url('/admin/Content/index/mcode/2'));
}
} else {
location(- 1);
}
} else {
// 调取修改内容
$this->assign('mod', true);
if (! $result = $this->model->getContent($id)) {
error('编辑的内容已经不存在!', - 1);
}
$this->assign('content', $result);
if (! $mcode = get('mcode', 'var')) {
error('传递的模型编码参数有误,请核对后重试!');
}
// 文章分类
$sort_model = model('admin.content.ContentSort');
$sort_select = $sort_model->getListSelect($mcode);
$this->assign('sort_select', $this->makeSortSelect($sort_select, $result->scode));
$this->assign('subsort_select', $this->makeSortSelect($sort_select, $result->subscode));
// 模型名称
$this->assign('model_name', model('admin.content.Model')->getName($mcode));
// 扩展字段
$this->assign('extfield', model('admin.content.ExtField')->getModelField($mcode));
// 获取会员分组
$this->assign('groups', model('admin.member.MemberGroup')->getSelect());
$this->display('content/content.html');
}
}
}

View File

@@ -0,0 +1,543 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年12月26日
* 内容栏目控制器
*/
namespace app\admin\controller\content;
use core\basic\Controller;
use app\admin\model\content\ContentSortModel;
class ContentSortController extends Controller
{
private $count;
private $blank;
private $outData = array();
private $model;
public function __construct()
{
$this->model = new ContentSortModel();
}
// 内容栏目列表
public function index()
{
$this->assign('list', true);
$tree = $this->model->getList();
$sorts = $this->makeSortList($tree);
$this->assign('sorts', $sorts);
// 内容模型
$models = model('admin.content.Model');
$this->assign('allmodels', $models->getSelectAll());
$this->assign('models', $models->getSelect());
// 内容栏目下拉表
$sort_tree = $this->model->getSelect();
$sort_select = $this->makeSortSelect($sort_tree);
$this->assign('sort_select', $sort_select);
// 模板文件
$htmldir = $this->config('tpl_html_dir') ? '/' . $this->config('tpl_html_dir') : '';
$this->assign('tpls', file_list(ROOT_PATH . current($this->config('tpl_dir')) . '/' . $this->model->getTheme() . $htmldir));
// 前端地址连接符判断
$url_break_char = $this->config('url_break_char') ?: '_';
$this->assign('url_break_char', $url_break_char);
// 获取会员分组
$this->assign('groups', model('admin.member.MemberGroup')->getSelect());
$this->display('content/contentsort.html');
}
// 生成无限级内容栏目列表
private function makeSortList($tree)
{
// 循环生成
foreach ($tree as $value) {
$this->count ++;
$this->outData[$this->count] = new \stdClass();
$this->outData[$this->count]->id = $value->id;
$this->outData[$this->count]->blank = $this->blank;
$this->outData[$this->count]->name = $value->name;
$this->outData[$this->count]->subname = $value->subname;
$this->outData[$this->count]->scode = $value->scode;
$this->outData[$this->count]->pcode = $value->pcode;
$this->outData[$this->count]->mcode = $value->mcode;
$this->outData[$this->count]->listtpl = $value->listtpl;
$this->outData[$this->count]->contenttpl = $value->contenttpl;
$this->outData[$this->count]->ico = $value->ico;
$this->outData[$this->count]->pic = $value->pic;
$this->outData[$this->count]->keywords = $value->keywords;
$this->outData[$this->count]->description = $value->description;
$this->outData[$this->count]->outlink = $value->outlink;
$this->outData[$this->count]->sorting = $value->sorting;
$this->outData[$this->count]->status = $value->status;
$this->outData[$this->count]->filename = $value->filename;
$this->outData[$this->count]->type = $value->type;
$this->outData[$this->count]->urlname = $value->urlname;
$this->outData[$this->count]->create_user = $value->create_user;
$this->outData[$this->count]->update_user = $value->update_user;
$this->outData[$this->count]->create_time = $value->create_time;
$this->outData[$this->count]->update_time = $value->update_time;
if ($value->son) {
$this->outData[$this->count]->son = true;
} else {
$this->outData[$this->count]->son = false;
}
// 子菜单处理
if ($value->son) {
$this->blank .= '  ';
$this->makeSortList($value->son);
}
}
// 循环完后回归缩进位置
$this->blank = substr($this->blank, 6);
return $this->outData;
}
// 内容栏目增加
public function add()
{
if ($_POST) {
if (! ! $multiplename = post('multiplename')) {
$multiplename = str_replace('', ',', $multiplename);
$pcode = post('pcode', 'var');
$type = post('type');
$mcode = post('mcode');
$listtpl = basename(post('listtpl'));
$contenttpl = basename(post('contenttpl'));
$status = post('status');
if (! $pcode) { // 父编码默认为0
$pcode = 0;
}
if (! $mcode) {
alert_back('栏目模型必须选择!');
}
if (! $type) {
alert_back('栏目类型不能为空!');
}
$names = explode(',', $multiplename);
$lastcode = $this->model->getLastCode();
$scode = get_auto_code($lastcode);
foreach ($names as $key => $value) {
$data[] = array(
'acode' => session('acode'),
'pcode' => $pcode,
'scode' => $scode,
'name' => $value,
'mcode' => $mcode,
'listtpl' => $listtpl,
'contenttpl' => $contenttpl,
'status' => $status,
'gid' => 0,
'gtype' => 4,
'subname' => '',
'filename' => '',
'outlink' => '',
'ico' => '',
'pic' => '',
'title' => '',
'keywords' => '',
'description' => '',
'sorting' => 255,
'create_user' => session('username'),
'update_user' => session('username')
);
$scode = get_auto_code($scode);
}
} else {
// 获取数据
$scode = get_auto_code($this->model->getLastCode()); // 自动编码;
$pcode = post('pcode', 'var');
$name = post('name');
$type = post('type');
$mcode = post('mcode');
$listtpl = basename(post('listtpl'));
$contenttpl = basename(post('contenttpl'));
$status = post('status');
$subname = post('subname');
$filename = post('filename');
$outlink = post('outlink');
$ico = post('ico');
$pic = post('pic');
$title = post('title');
$keywords = post('keywords');
$description = post('description');
$gid = post('gid', 'int') ?: 0;
$gtype = post('gtype', 'int') ?: 4;
$gnote = post('gnote');
if (! $scode) {
alert_back('编码不能为空!');
}
if (! $pcode) { // 父编码默认为0
$pcode = 0;
}
if (! $name) {
alert_back('栏目名不能为空!');
}
if (! $mcode) {
alert_back('栏目模型必须选择!');
}
if (! $type) {
alert_back('栏目类型不能为空!');
}
if ($filename && ! preg_match('/^[a-zA-Z0-9\-]+$/', $filename)) {
alert_back('URL名称只允许字母、数字、横线组成!');
}
if ($filename && $this->model->checkUrlname($filename)) {
alert_back('URL名称与模型URL名称冲突请换一个名称');
}
// 缩放缩略图
if ($ico) {
resize_img(ROOT_PATH . $ico, '', $this->config('ico.max_width'), $this->config('ico.max_height'));
}
// 检查编码
if ($this->model->checkSort("scode='$scode'")) {
alert_back('该内容栏目编号已经存在,不能再使用!');
}
// 检查自定义URL名称
if ($filename) {
while ($this->model->checkFilename($filename)) {
$filename = $filename . '_' . mt_rand(1, 20);
}
}
// 构建数据
$data = array(
'acode' => session('acode'),
'pcode' => $pcode,
'scode' => $scode,
'name' => $name,
'mcode' => $mcode,
'listtpl' => $listtpl,
'contenttpl' => $contenttpl,
'status' => $status,
'gid' => $gid,
'gtype' => $gtype,
'gnote' => $gnote,
'subname' => $subname,
'filename' => $filename,
'outlink' => $outlink,
'ico' => $ico,
'pic' => $pic,
'title' => $title,
'keywords' => $keywords,
'description' => $description,
'sorting' => 255,
'create_user' => session('username'),
'update_user' => session('username')
);
}
// 执行添加
if ($this->model->addSort($data)) {
if ($type == 1 && ! $outlink) { // 在填写了外链时不生成单页
if ($multiplename) {
foreach ($data as $key => $value) {
$this->addSingle($value['scode'], $value['name']);
}
} else {
$this->addSingle($scode, $name);
}
}
$this->log('新增数据内容栏目' . $scode . '成功!');
success('新增成功!', url('/admin/ContentSort/index'));
} else {
$this->log('新增数据内容栏目' . $scode . '失败!');
error('新增失败!', - 1);
}
}
}
// 生成内容栏目下拉选择
private function makeSortSelect($tree, $selectid = null)
{
$list_html = '';
foreach ($tree as $value) {
// 默认选择项
if ($selectid == $value->scode) {
$select = "selected='selected'";
} else {
$select = '';
}
if (get('scode') != $value->scode) { // 不显示本身,避免出现自身为自己的父节点
$list_html .= "<option value='{$value->scode}' $select>{$this->blank}{$value->name}</option>";
}
// 子菜单处理
if ($value->son) {
$this->blank .= '  ';
$list_html .= $this->makeSortSelect($value->son, $selectid);
}
}
// 循环完后回归位置
$this->blank = substr($this->blank, 0, - 6);
return $list_html;
}
// 内容栏目删除
public function del()
{
// 执行批量删除
if ($_POST) {
if (! ! $list = post('list')) {
if ($this->model->delSortList($list)) {
$this->log('批量删除栏目成功!');
success('批量删除成功!', - 1);
} else {
$this->log('批量删除栏目失败!');
error('批量删除失败!', - 1);
}
} else {
alert_back('请选择要删除的栏目!');
}
}
if (! $scode = get('scode', 'var')) {
error('传递的参数值错误!', - 1);
}
if ($this->model->delSort($scode)) {
$this->log('删除数据内容栏目' . $scode . '成功!');
success('删除成功!', - 1);
} else {
$this->log('删除数据内容栏目' . $scode . '失败!');
error('删除失败!', - 1);
}
}
// 内容栏目修改
public function mod()
{
if (! ! $submit = post('submit')) {
switch ($submit) {
case 'sorting': // 修改列表排序
$listall = post('listall');
if ($listall) {
$sorting = post('sorting');
foreach ($listall as $key => $value) {
if ($sorting[$key] === '' || ! is_numeric($sorting[$key]))
$sorting[$key] = 255;
$this->model->modSortSorting($value, "sorting=" . $sorting[$key]);
}
$this->log('批量修改栏目排序成功!');
success('修改成功!', - 1);
} else {
alert_back('排序失败,无任何内容!');
}
break;
}
}
if (! $scode = get('scode', 'var')) {
error('传递的参数值错误!', - 1);
}
// 单独修改状态
if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
if ($this->model->modSort($scode, "$field='$value',update_user='" . session('username') . "'")) {
$this->log('修改数据内容栏目' . $scode . '状态' . $value . '成功!');
location(- 1);
} else {
$this->log('修改数据内容栏目' . $scode . '状态' . $value . '失败!');
alert_back('修改失败!');
}
}
// 修改操作
if ($_POST) {
// 获取数据
$pcode = post('pcode', 'var');
$name = post('name');
$mcode = post('mcode');
$type = post('type');
$listtpl = basename(post('listtpl'));
$contenttpl = basename(post('contenttpl'));
$status = post('status');
$subname = post('subname');
$filename = post('filename');
$outlink = post('outlink');
$ico = post('ico');
$pic = post('pic');
$title = post('title');
$keywords = post('keywords');
$description = post('description');
$modsub = post('modsub', 'int');
$gid = post('gid', 'int') ?: 0;
$gtype = post('gtype', 'int') ?: 4;
$gnote = post('gnote');
if (! $pcode) { // 父编码默认为0
$pcode = 0;
}
if (! $name) {
alert_back('栏目名不能为空!');
}
if (! $mcode) {
alert_back('栏目模型必须选择!');
}
if (! $type) {
alert_back('栏目类型不能为空!');
}
if ($filename && ! preg_match('/^[a-zA-Z0-9\-]+$/', $filename)) {
alert_back('URL名称只允许字母、数字、横线组成!');
}
if ($filename && $this->model->checkUrlname($filename)) {
alert_back('URL名称与模型URL名称冲突请换一个名称');
}
// 缩放缩略图
if ($ico) {
resize_img(ROOT_PATH . $ico, '', $this->config('ico.max_width'), $this->config('ico.max_height'));
}
if ($filename) {
while ($this->model->checkFilename($filename, "scode<>'$scode'")) {
$filename = $filename . '-' . mt_rand(1, 20);
}
}
// 构建数据
$data = array(
'pcode' => $pcode,
'name' => $name,
'mcode' => $mcode,
'listtpl' => $listtpl,
'contenttpl' => $contenttpl,
'status' => $status,
'gid' => $gid,
'gtype' => $gtype,
'gnote' => $gnote,
'subname' => $subname,
'filename' => $filename,
'outlink' => $outlink,
'ico' => $ico,
'pic' => $pic,
'title' => $title,
'keywords' => $keywords,
'description' => $description,
'update_user' => session('username')
);
// 执行添加
if ($this->model->modSort($scode, $data, $modsub)) {
// 如果修改为单页并且跳转,则删除单页内容,否则判断是否存在内容,不存在则添加
if ($type == 1 && $outlink) {
$this->model->delContent($scode);
} elseif ($type == 1 && ! $this->model->findContent($scode)) {
$this->addSingle($scode, $name);
}
$this->log('修改数据内容栏目' . $scode . '成功!');
success('修改成功!', url('/admin/ContentSort/index'));
} else {
location(- 1);
}
} else { // 调取修改内容
$this->assign('mod', true);
$sort = $this->model->getSort($scode);
if (! $sort) {
error('编辑的内容已经不存在!', - 1);
}
$this->assign('sort', $sort);
// 父编码下拉选择
$sort_tree = $this->model->getSelect();
$sort_select = $this->makeSortSelect($sort_tree, $sort->pcode);
$this->assign('sort_select', $sort_select);
// 模板文件
$htmldir = $this->config('tpl_html_dir') ? '/' . $this->config('tpl_html_dir') : '';
$this->assign('tpls', file_list(ROOT_PATH . current($this->config('tpl_dir')) . '/' . $this->model->getTheme() . $htmldir));
// 内容模型
$models = model('admin.content.Model');
$this->assign('models', $models->getSelect());
// 获取会员分组
$this->assign('groups', model('admin.member.MemberGroup')->getSelect());
$this->display('content/contentsort.html');
}
}
// 添加栏目时执行单页内容增加
public function addSingle($scode, $title)
{
// 构建数据
$data = array(
'acode' => session('acode'),
'scode' => $scode,
'subscode' => '',
'title' => $title,
'titlecolor' => '#333333',
'subtitle' => '',
'filename' => '',
'author' => session('username'),
'source' => '本站',
'outlink' => '',
'date' => date('Y-m-d H:i:s'),
'ico' => '',
'pics' => '',
'content' => '',
'tags' => '',
'enclosure' => '',
'keywords' => '',
'description' => '',
'sorting' => 255,
'status' => 1,
'istop' => 0,
'isrecommend' => 0,
'isheadline' => 0,
'gid' => 0,
'gtype' => 4,
'gnote' => '',
'visits' => 0,
'likes' => 0,
'oppose' => 0,
'create_user' => session('username'),
'update_user' => session('username')
);
// 执行添加
if ($this->model->addSingle($data)) {
return true;
} else {
return false;
}
}
}

View File

@@ -0,0 +1,231 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年3月1日
* 扩展字段控制器
*/
namespace app\admin\controller\content;
use core\basic\Controller;
use app\admin\model\content\ExtFieldModel;
class ExtFieldController extends Controller
{
private $model;
public function __construct()
{
$this->model = new ExtFieldModel();
}
// 扩展字段列表
public function index()
{
if ((! ! $id = get('id', 'int')) && $result = $this->model->getExtField($id)) {
$this->assign('more', true);
$this->assign('extfield', $result);
} else {
$this->assign('list', true);
if (! ! ($field = get('field', 'var')) && ! ! ($keyword = get('keyword', 'vars'))) {
$result = $this->model->findExtField($field, $keyword);
} else {
$result = $this->model->getList();
}
// 内容模型
$models = model('admin.content.Model');
$this->assign('models', $models->getSelect());
$this->assign('extfields', $result);
}
$this->display('content/extfield.html');
}
// 扩展字段增加
public function add()
{
if ($_POST) {
// 获取数据
$mcode = post('mcode');
$name = post('name', 'var');
$type = post('type', 'int');
if (! ! $value = post('value')) {
$value = str_replace("\r\n", ",", $value); // 替换回车
$value = str_replace("", ",", $value); // 替换中文逗号分割符
}
$description = post('description');
$sorting = post('sorting', 'int');
if (! $mcode) {
alert_back('内容模型不能为空!');
}
if (! $name) {
alert_back('字段名称不能为空!');
} else {
$name = "ext_" . $name;
}
if (! $type) {
alert_back('字段类型不能为空!');
}
if (! $description) {
alert_back('字段描述不能为空!');
}
// 构建数据
$data = array(
'mcode' => $mcode,
'name' => $name,
'type' => $type,
'value' => $value,
'description' => $description,
'sorting' => $sorting
);
// 字段类型及长度
switch ($type) {
case '2': // 多行
$mysql = 'varchar(1000)';
$sqlite = 'TEXT(1000)';
break;
case '7': // 时间日期
$mysql = 'datetime';
$sqlite = 'TEXT';
break;
case '8': // 编辑器
$mysql = 'TEXT';
$sqlite = 'TEXT(10000)';
break;
default:
$mysql = 'varchar(200)';
$sqlite = 'TEXT(200)';
}
// 字段不存在时创建
if (! $this->model->isExistField($name)) {
if (get_db_type() == 'sqlite') {
$result = $this->model->amd("ALTER TABLE ay_content_ext ADD COLUMN $name $sqlite NULL");
} else {
$result = $this->model->amd("ALTER TABLE ay_content_ext ADD $name $mysql NULL COMMENT '$description'");
}
} elseif ($this->model->checkExtField($name)) { // 字段存在且已使用则 报错
alert_back('字段已经存在,不能重复添加!');
}
// 执行扩展字段记录添加
if ($this->model->addExtField($data)) {
$this->log('新增扩展字段成功!');
if (! ! $backurl = get('backurl')) {
success('新增成功!', base64_decode($backurl));
} else {
success('新增成功!', url('/admin/ExtField/index'));
}
} else {
$this->log('新增扩展字段失败!');
error('新增失败!', - 1);
}
}
}
// 扩展字段删除
public function del()
{
if (! $id = get('id', 'int')) {
error('传递的参数值错误!', - 1);
}
$name = $this->model->getExtFieldName($id);
if ($this->model->delExtField($id)) {
// mysql数据库执行字段删除sqlite暂时不支持
if (! ! $name) {
if (get_db_type() == 'mysql') {
$result = $this->model->amd("ALTER TABLE ay_content_ext DROP COLUMN $name");
}
}
$this->log('删除扩展字段' . $id . '成功!');
success('删除成功!', - 1);
} else {
$this->log('删除扩展字段' . $id . '失败!');
error('删除失败!', - 1);
}
}
// 扩展字段修改
public function mod()
{
if (! $id = get('id', 'int')) {
error('传递的参数值错误!', - 1);
}
// 单独修改状态
if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
if ($this->model->modExtField($id, "$field='$value',update_user='" . session('username') . "'")) {
location(- 1);
} else {
alert_back('修改失败!');
}
}
// 修改操作
if ($_POST) {
// 获取数据
$mcode = post('mcode');
$type = post('type');
if (! ! $value = post('value')) {
$value = str_replace("\r\n", ",", $value); // 替换回车
$value = str_replace("", ",", $value); // 替换中文逗号分割符
}
$description = post('description');
$sorting = post('sorting', 'int');
if (! $mcode) {
alert_back('内容模型不能为空!');
}
if (! $description) {
alert_back('字段描述不能为空!');
}
// 构建数据
$data = array(
'mcode' => $mcode,
'type' => $type,
'value' => $value,
'description' => $description,
'sorting' => $sorting
);
// 执行修改
if ($this->model->modExtField($id, $data)) {
$this->log('修改扩展字段' . $id . '成功!');
if (! ! $backurl = get('backurl')) {
success('修改成功!', base64_decode($backurl));
} else {
success('修改成功!', url('/admin/ExtField/index'));
}
} else {
location(- 1);
}
} else {
// 调取修改内容
$this->assign('mod', true);
if (! $result = $this->model->getExtField($id)) {
error('编辑的内容已经不存在!', - 1);
}
// 内容模型
$models = model('admin.content.Model');
$this->assign('models', $models->getSelect());
$this->assign('extfield', $result);
$this->display('content/extfield.html');
}
}
}

View File

@@ -0,0 +1,259 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年12月15日
* 单页内容控制器
*/
namespace app\admin\controller\content;
use core\basic\Controller;
use app\admin\model\content\SingleModel;
class SingleController extends Controller
{
private $model;
private $blank;
public function __construct()
{
$this->model = new SingleModel();
}
// 单页内容列表
public function index()
{
if ((! ! $id = get('id', 'int')) && $result = $this->model->getSingle($id)) {
$this->assign('more', true);
$this->assign('content', $result);
} else {
$this->assign('list', true);
if (! $mcode = get('mcode', 'var')) {
error('传递的模型编码参数有误,请核对后重试!');
}
if (! ! ($field = get('field', 'var')) && ! ! ($keyword = get('keyword', 'vars'))) {
$result = $this->model->findSingle($mcode, $field, $keyword);
} else {
$result = $this->model->getList($mcode);
}
$this->assign('baidu_zz_token', $this->config('baidu_zz_token'));
$this->assign('baidu_ks_token', $this->config('baidu_ks_token'));
// 模型名称
$this->assign('model_name', model('admin.content.Model')->getName($mcode));
// 前端地址连接符判断
$url_break_char = $this->config('url_break_char') ?: '_';
$this->assign('url_break_char', $url_break_char);
$this->assign('contents', $result);
}
$this->display('content/single.html');
}
// 单页内容删除
public function del()
{
if (! $id = get('id', 'int')) {
error('传递的参数值错误!', - 1);
}
if ($this->model->delSingle($id)) {
$this->log('删除单页内容' . $id . '成功!');
success('删除成功!', - 1);
} else {
$this->log('删除单页内容' . $id . '失败!');
error('删除失败!', - 1);
}
}
// 单页内容修改
public function mod()
{
// 前端地址连接符判断
if (get('baiduzz') || get('baiduxzh')) {
$url_break_char = $this->config('url_break_char') ?: '_';
$url_rule_sort_suffix = $this->config('url_rule_sort_suffix') ? true : false;
}
// 站长普通推送
if (! ! $id = get('baiduzz')) {
$domain = get_http_url();
if (! $token = $this->config('baidu_zz_token')) {
alert_back('请先到系统配置中填写百度普通收录推送token值');
}
$api = "http://data.zz.baidu.com/urls?site=$domain&token=$token";
$data = $this->model->getSingle($id);
$data->urlname = $data->urlname ?: 'about';
if ($data->outlink) {
alert_back('链接类型不允许推送!');
}
if ($data->filename) {
$urls[] = $domain . homeurl('/home/Index/' . $data->filename, $url_rule_sort_suffix);
} else {
$urls[] = $domain . homeurl('/home/Index/' . $data->urlname . $url_break_char . $data->scode, $url_rule_sort_suffix);
}
$result = post_baidu($api, $urls);
if (isset($result->error)) {
$this->log('百度普通收录推送失败:' . $urls[0]);
alert_back('推送发生错误:' . $result->message);
} elseif (isset($result->success)) {
$this->log('百度普通收录推送成功:' . $urls[0]);
alert_back('成功推送' . $result->success . '条,今天剩余可推送' . $result->remain . '条数!');
} else {
alert_back('发生未知错误!');
}
}
// 站长快速推送
if (! ! $id = get('baiduks')) {
$domain = get_http_url();
if (! $token = $this->config('baidu_ks_token')) {
alert_back('请先到系统配置中填写百度快速收录推送token值');
}
$api = "http://data.zz.baidu.com/urls?site=$domain&token=$token&type=daily";
$data = $this->model->getSingle($id);
$data->urlname = $data->urlname ?: 'about';
if ($data->outlink) {
alert_back('链接类型不允许推送!');
}
if ($data->filename) {
$urls[] = $domain . homeurl('/home/Index/' . $data->filename, $url_rule_sort_suffix);
} else {
$urls[] = $domain . homeurl('/home/Index/' . $data->urlname . $url_break_char . $data->scode, $url_rule_sort_suffix);
}
$result = post_baidu($api, $urls);
if (isset($result->error)) {
$this->log('百度快速收录推送失败:' . $urls[0]);
alert_back('推送发生错误:' . $result->message);
} elseif (isset($result->success_daily)) {
$this->log('百度快速收录推送成功:' . $urls[0]);
alert_back('成功推送' . $result->success_daily . '条,今天剩余可推送' . $result->remain_daily . '条数!');
} else {
alert_back('发生未知错误!');
}
}
if (! $id = get('id', 'int')) {
error('传递的参数值错误!', - 1);
}
// 单独修改状态
if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
if ($this->model->modSingle($id, "$field='$value',update_user='" . session('username') . "'")) {
location(- 1);
} else {
alert_back('修改失败!');
}
}
// 修改操作
if ($_POST) {
// 获取数据
$title = post('title');
$author = post('author');
$source = post('source');
$ico = post('ico');
$pics = post('pics');
$content = post('content');
$tags = str_replace('', ',', post('tags'));
$titlecolor = post('titlecolor');
$subtitle = post('subtitle');
$outlink = post('outlink');
$date = post('date');
$enclosure = post('enclosure');
$keywords = post('keywords');
$description = post('description');
$status = post('status', 'int');
if (! $title) {
alert_back('单页内容标题不能为空!');
}
// 自动提起前一百个字符为描述
if (! $description && isset($_POST['content'])) {
$description = escape_string(clear_html_blank(substr_both(strip_tags($_POST['content']), 0, 150)));
}
// 缩放缩略图
if ($ico) {
resize_img(ROOT_PATH . $ico, '', $this->config('ico.max_width'), $this->config('ico.max_height'));
}
// 构建数据
$data = array(
'title' => $title,
'content' => $content,
'tags' => $tags,
'author' => $author,
'source' => $source,
'ico' => $ico,
'pics' => $pics,
'titlecolor' => $titlecolor,
'subtitle' => $subtitle,
'outlink' => $outlink,
'date' => $date,
'enclosure' => $enclosure,
'keywords' => $keywords,
'description' => clear_html_blank($description),
'status' => $status,
'update_user' => session('username')
);
// 执行添加
if ($this->model->modSingle($id, $data)) {
// 扩展内容修改
foreach ($_POST as $key => $value) {
if (preg_match('/^ext_[\w\-]+$/', $key)) {
$temp = post($key);
if (is_array($temp)) {
$data2[$key] = implode(',', $temp);
} else {
$data2[$key] = str_replace("\r\n", '<br>', $temp);
}
}
}
if (isset($data2)) {
if ($this->model->findContentExt($id)) {
$this->model->modContentExt($id, $data2);
} else {
$data2['contentid'] = $id;
$this->model->addContentExt($data2);
}
}
$this->log('修改单页内容' . $id . '成功!');
if (! ! $backurl = get('backurl')) {
success('修改成功!', base64_decode($backurl));
} else {
success('修改成功!', url('/admin/Single/index/mcode/1'));
}
} else {
location(- 1);
}
} else {
// 调取修改内容
$this->assign('mod', true);
if (! $result = $this->model->getSingle($id)) {
error('编辑的内容已经不存在!', - 1);
}
$this->assign('content', $result);
// 扩展字段
if (! $mcode = get('mcode', 'var')) {
error('传递的模型编码参数有误,请核对后重试!');
}
$this->assign('extfield', model('admin.content.ExtField')->getModelField($mcode));
$this->display('content/single.html');
}
}
}

View File

@@ -0,0 +1,226 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年01月03日
* 应用配置控制器
*/
namespace app\admin\controller\system;
use core\basic\Controller;
use app\admin\model\system\ConfigModel;
use core\basic\Config;
class ConfigController extends Controller
{
private $model;
public function __construct()
{
$this->model = new ConfigModel();
}
// 应用配置列表
public function index()
{
if (! ! $action = get('action')) {
switch ($action) {
case 'sendemail':
$rs = sendmail($this->config(), get('to'), '【PbootCMS】测试邮件', '欢迎您使用PbootCMS网站开发管理系统');
if ($rs === true) {
alert_back('测试邮件发送成功!');
} else {
error('发送失败:' . $rs);
}
break;
}
}
// 修改参数配置
if ($_POST) {
unset($_POST['upload']); // 去除上传组件
foreach ($_POST as $key => $value) {
if (! preg_match('/^[\w\-]+$/', $key)) {
continue;
}
$config = array(
'debug',
'sn',
'sn_user',
'pagenum',
'tpl_html_cache',
'tpl_html_cache_time',
'session_in_sitepath'
);
if (in_array($key, $config)) {
if ($key == 'tpl_html_cache_time' && ! $value) {
$value = 900;
} else {
$value = post($key);
}
$this->modConfig($key, $value);
} else {
$this->modDbConfig($key);
}
}
$this->log('修改参数配置成功!');
path_delete(RUN_PATH . '/config'); // 清理缓存的配置文件
switch (post('submit')) {
case 'email':
success('修改成功!', url('/admin/Config/index' . get_tab('t2'), false));
break;
case 'baidu':
success('修改成功!', url('/admin/Config/index' . get_tab('t3'), false));
break;
case 'api':
success('修改成功!', url('/admin/Config/index' . get_tab('t4'), false));
break;
case 'watermark':
success('修改成功!', url('/admin/Config/index' . get_tab('t5'), false));
break;
case 'security':
success('修改成功!', url('/admin/Config/index' . get_tab('t6'), false));
break;
case 'urlrule':
success('修改成功!', url('/admin/Config/index' . get_tab('t7'), false));
break;
case 'pagetitle':
success('修改成功!', url('/admin/Config/index' . get_tab('t8'), false));
break;
case 'member':
success('修改成功!', url('/admin/Config/index' . get_tab('t9'), false));
break;
case 'upgrade':
success('修改成功!', url('/admin/Upgrade/index' . get_tab('t2'), false));
break;
default:
success('修改成功!', url('/admin/Config/index', false));
}
}
$configs = $this->model->getList();
$configs['debug']['value'] = $this->config('debug');
$configs['sn']['value'] = $this->config('sn');
$configs['sn_user']['value'] = $this->config('sn_user');
$configs['session_in_sitepath']['value'] = $this->config('session_in_sitepath');
$configs['pagenum']['value'] = $this->config('pagenum');
$configs['url_type']['value'] = $this->config('url_type');
$configs['tpl_html_cache']['value'] = $this->config('tpl_html_cache');
$configs['tpl_html_cache_time']['value'] = $this->config('tpl_html_cache_time');
$this->assign('configs', $configs);
$this->assign('groups', model('admin.member.MemberGroup')->getSelect());
$this->display('system/config.html');
}
// 修改配置文件
private function modConfig($key, $value)
{
$value = str_replace(' ', '', $value); // 去除空格
$value = str_replace('', ',', $value); // 转换可能输入的中文逗号
if (! preg_match('/^[\w\s\,\-]+$/', $value)) {
return;
}
$config = file_get_contents(CONF_PATH . '/config.php');
if (preg_match("'$key'", $config)) {
if (preg_match('/^[0-9]+$/', $value)) {
$config = preg_replace('/(\'' . $key . '\'([\s]+)?=>([\s]+)?)[\w\'\"\s,]+,/', '${1}' . $value . ',', $config);
} else {
$config = preg_replace('/(\'' . $key . '\'([\s]+)?=>([\s]+)?)[\w\'\"\s,]+,/', '${1}\'' . $value . '\',', $config);
}
} else {
$config = preg_replace('/(return array\()/', "$1\r\n\r\n\t'$key' => '$value',", $config); // 自动新增配置
}
return file_put_contents(CONF_PATH . '/config.php', $config);
}
// 修改数据库配置
private function modDbConfig($key)
{
$value = post($key);
// 如果开启伪静态时自动拷贝文件
if ($key == 'url_rule_type' && $value == 2) {
$soft = get_server_soft();
if ($soft == 'iis') {
if (! file_exists(ROOT_PATH . '/web.config')) {
copy(ROOT_PATH . '/rewrite/web.config', ROOT_PATH . '/web.config');
}
} elseif ($soft == 'apache') {
if (! file_exists(ROOT_PATH . '/web.config')) {
copy(ROOT_PATH . '/rewrite/.htaccess', ROOT_PATH . '/.htaccess');
}
}
}
// 模板目录修改
if (($key == 'tpl_html_dir') && $value) {
// 不允许特殊字符
if (! preg_match('/^\w+$/', $value)) {
return;
}
$value = basename($value);
$htmldir = $this->config('tpl_html_dir');
$tpl_path = ROOT_PATH . current($this->config('tpl_dir')) . '/' . model('admin.content.ContentSort')->getTheme();
if (! $htmldir || ! file_exists($tpl_path . '/' . $htmldir)) {
if (! check_dir($tpl_path . '/' . $value, true)) {
return;
} // 原来没有目录时只创建目录,创建失败时直接不修改
} else {
if ($value != $htmldir) {
if (file_exists($tpl_path . '/' . $value)) {
if (dir_copy($tpl_path . '/' . $htmldir, $tpl_path . '/' . $value)) {
path_delete($tpl_path . '/' . $htmldir, true); // 删除原来的
} else {
return; // 修改失败
}
} else {
if (! rename($tpl_path . '/' . $htmldir, $tpl_path . '/' . $value)) {
return; // 修改失败
}
}
}
}
}
if ($key == 'home_upload_ext') {
// 不允许特殊扩展
if (preg_match('/(php|jsp|asp|exe|sh|cmd|vb|vbs)/i', $value)) {
return;
}
}
// 数据分割处理
$hander = array(
'content_keyword_replace',
'ip_deny',
'ip_allow'
);
if (in_array($key, $hander) && $value) {
$value = str_replace("\r\n", ",", $value); // 替换回车
$value = str_replace("", ",", $value); // 替换中文逗号分割符
}
if ($this->model->checkConfig("name='$key'")) {
$this->model->modValue($key, $value);
} elseif ($key != 'submit' && $key != 'formcheck') {
// 自动新增配置项
$data = array(
'name' => $key,
'value' => $value,
'type' => 2,
'sorting' => 255,
'description' => ''
);
return $this->model->addConfig($data);
}
}
}

View File

@@ -0,0 +1,248 @@
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2017年5月9日
* 数据库管理,只支持MySQL
*/
namespace app\admin\controller\system;
use core\basic\Controller;
use app\admin\model\system\DatabaseModel;
class DatabaseController extends Controller
{
private $model;
private $dbauth;
function __construct()
{
$this->model = new DatabaseModel();
$this->dbauth = $this->config('database');
}
// 数据库管理
public function index()
{
switch ($this->dbauth['type']) {
case 'mysqli':
case 'pdo_mysql':
$this->assign('db', 'mysql');
$this->assign('tables', $this->model->getList());
break;
case 'sqlite':
case 'pdo_sqlite':
$this->assign('db', 'sqlite');
break;
default:
error('当前配置的数据库类型不支持在线管理!');
}
$this->display('system/database.html');
}
// 数据库修改
public function mod()
{
if (! $_POST) {
alert_back('非法访问!', - 1);
}
$submit = post('submit', 'letter', true);
switch ($submit) {
case 'yh':
$tables = self::getTableList();
if (! $tables)
alert_back('请选择数据表!');
if ($this->model->optimize(implode(',', $tables))) {
// $this->log('优化数据库表成功!');
success('优化成功!', - 1);
} else {
// $this->log('优化数据库表失败!');
error('优化失败!', - 1);
}
break;
case 'xf':
$tables = self::getTableList();
if (! $tables)
alert_back('请选择数据表!');
if ($this->model->repair(implode(',', $tables))) {
// $this->log('修复数据库表成功!');
success('修复成功!', - 1);
} else {
// $this->log('修复数据库表失败!');
error('修复失败!', - 1);
}
break;
case 'bf':
$tables = self::getTableList();
if (! $tables)
alert_back('请选择数据表!');
if ($this->backupTable($tables)) {
$this->log('备份数据库表成功!');
success('备份表成功!', - 1);
} else {
$this->log('备份数据库表失败!');
error('备份失败!', - 1);
}
break;
case 'bfdb':
if ($this->backupDB()) {
$this->log('备份数据库成功!');
success('备份数据库成功!', - 1);
} else {
$this->log('备份数据库失败!');
error('备份失败!', - 1);
}
break;
case 'bfsqlite':
if (copy(DOC_PATH . $this->dbauth['dbname'], DOC_PATH . STATIC_DIR . '/backup/sql/' . get_uniqid() . '_' . date('YmdHis') . '.db')) {
$this->log('备份数据库成功!');
success('备份数据库成功!', - 1);
} else {
$this->log('备份数据库失败!');
error('备份失败!', - 1);
}
break;
}
}
// 备份数据表
public function backupTable($tables)
{
$backdir = date('YmdHis');
foreach ($tables as $table) {
$sql = '';
$sql .= $this->header(); // 备份文件头部说明
$sql .= $this->tableSql($table); // 表结构信息
$fields = $this->model->getFields($table); // 表字段
$field_num = $this->model->getFieldNum($table); // 字段数量
$all_data = $this->model->getAll($table); // 读取全部数据
$sql .= $this->dataSql($table, $fields, $field_num, $all_data); // 生成语句
$filename = $backdir . "/" . get_uniqid() . "_" . $backdir . "_" . $table . '.sql'; // 写入文件
$result = $this->writeFile($filename, $sql);
}
return $result;
}
// 备份整个数据库
public function backupDB()
{
$sql = '';
$sql .= $this->header(); // 备份文件头部说明
$sql .= $this->dbSql(); // 数据库创建语句
$tables = $this->model->getTables(); // 获取所有表
foreach ($tables as $table) { // 表结构及数据
$sql .= $this->tableSql($table); // 表结构信息
$fields = $this->model->getFields($table); // 表字段
$field_num = $this->model->getFieldNum($table); // 字段数量
$all_data = $this->model->getAll($table); // 读取全部数据
if ($all_data) {
$sql .= $this->dataSql($table, $fields, $field_num, $all_data); // 生成数据语句
}
$sql .= '-- --------------------------------------------------------' . PHP_EOL . PHP_EOL;
}
// 写入文件
$filename = get_uniqid() . '_' . date('YmdHis') . '_' . $this->dbauth['dbname'] . '.sql';
return $this->writeFile($filename, $sql);
}
// 插入数据库备份基础信息
private function header()
{
$sql = '-- Online Database Management SQL Dump' . PHP_EOL;
$sql .= '-- 数据库名: ' . $this->dbauth['dbname'] . PHP_EOL;
$sql .= '-- 生成日期: ' . date('Y-m-d H:i:s') . PHP_EOL;
$sql .= '-- PHP 版本: ' . phpversion() . PHP_EOL . PHP_EOL;
$sql .= 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' . PHP_EOL;
$sql .= 'SET time_zone = "+08:00";' . PHP_EOL;
$sql .= 'SET NAMES utf8;' . PHP_EOL . PHP_EOL;
$sql .= '-- --------------------------------------------------------' . PHP_EOL . PHP_EOL;
return $sql;
}
// 数据库创建语句
private function dbSql()
{
$sql = '';
$sql .= "--" . PHP_EOL;
$sql .= "-- 数据库名 `" . $this->dbauth['dbname'] . '`' . PHP_EOL;
$sql .= "--" . PHP_EOL . PHP_EOL;
// 如果数据库不存在则创建
$sql .= "CREATE DATABASE IF NOT EXISTS `" . $this->dbauth['dbname'] . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;' . PHP_EOL;
// 选择数据库
$sql .= "USE `" . $this->dbauth['dbname'] . "`;" . PHP_EOL . PHP_EOL;
$sql .= '-- --------------------------------------------------------' . PHP_EOL . PHP_EOL;
return $sql;
}
// 表结构语句
private function tableSql($table)
{
$sql = '';
$sql .= "--" . PHP_EOL;
$sql .= "-- 表的结构 `" . $table . '`' . PHP_EOL;
$sql .= "--" . PHP_EOL . PHP_EOL;
$sql .= $this->model->tableStru($table); // 表创建语句
return $sql;
}
// 数据语句
private function dataSql($table, $fields, $fieldNnum, $data)
{
if (! $data)
return;
$sql = '';
$sql .= "--" . PHP_EOL;
$sql .= "-- 转存表中的数据 `" . $table . "`" . PHP_EOL;
$sql .= "--" . PHP_EOL;
$sql .= PHP_EOL;
// 循环每个字段下面的内容
$sql .= "INSERT INTO `" . $table . "` (" . implode(',', $fields) . ") VALUES" . PHP_EOL;
$brackets = "(";
foreach ($data as $value) {
$sql .= $brackets;
$comma = "";
for ($i = 0; $i < $fieldNnum; $i ++) {
$sql .= ($comma . "'" . decode_string($value[$i]) . "'");
$comma = ",";
}
$sql .= ")";
$brackets = "," . PHP_EOL . "(";
}
$sql .= ';' . PHP_EOL . PHP_EOL;
return $sql;
}
// 写入文件
private function writeFile($filename, $content)
{
$sqlfile = DOC_PATH . STATIC_DIR . '/backup/sql/' . $filename;
check_file($sqlfile, true);
if (file_put_contents($sqlfile, $content)) {
return true;
}
}
// 获取并检查表名称
private function getTableList()
{
$list = post('list');
foreach ($list as $key => $value) {
if (! preg_match('/^[\w]+$/', $value)) {
unset($list[$key]);
}
}
return $list;
}
}