更新目录结构
This commit is contained in:
20
app/model/system/Attach.php
Normal file
20
app/model/system/Attach.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\system;
|
||||
|
||||
/**
|
||||
* 附件模型
|
||||
*/
|
||||
class Attach extends \think\Model {
|
||||
|
||||
protected function getUrlAttr($value, $data){
|
||||
return $value ? $value : $data['path'];
|
||||
}
|
||||
|
||||
}
|
||||
54
app/model/system/Channel.php
Normal file
54
app/model/system/Channel.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\system;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Channel extends \think\Model {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected function setStatusAttr($value){
|
||||
return ($value !== '') ? $value : 1;
|
||||
}
|
||||
|
||||
protected function getStatusTextAttr($value, $data){
|
||||
$status = [0 => '禁用', 1 => '启用'];
|
||||
return isset($status[$data['status']]) ? $status[$data['status']] : '禁用';
|
||||
}
|
||||
|
||||
public static function getChannelList($type, $pid = '', $tree = false){
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 1];
|
||||
if ($pid !== '') {
|
||||
$map[] = ['pid', '=', $pid];
|
||||
}
|
||||
if($type !== ''){
|
||||
$map[] = ['type', '=', $type];
|
||||
}
|
||||
$list = self::where($map)->order('sort asc, id desc')->select()->each(function($item){
|
||||
if(strpos($item['url'], "?")){
|
||||
$url = parse_url($item['url']);
|
||||
$param = [];
|
||||
parse_str($url['query'], $param);
|
||||
$item['url'] = url($url['path'], $param);
|
||||
}else{
|
||||
$item['url'] = url($item['url']);
|
||||
}
|
||||
return $item;
|
||||
})->toArray();
|
||||
if ($tree) {
|
||||
$list = (new \sent\tree\Tree())->listToTree($list);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
85
app/model/system/Config.php
Normal file
85
app/model/system/Config.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\system;
|
||||
|
||||
use think\facade\Cache;
|
||||
use think\Model;
|
||||
|
||||
class Config extends Model {
|
||||
|
||||
public function getValuesAttr($value, $data) {
|
||||
return self::parse($data['type'], $data['value']);
|
||||
}
|
||||
|
||||
public static function getConfigList($request) {
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = self::where($map)->field('type,name,value')->select();
|
||||
|
||||
$config = array();
|
||||
if ($data) {
|
||||
foreach ($data->toArray() as $value) {
|
||||
$config[$value['name']] = self::parse($value['type'], $value['value']);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function getConfig($request) {
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = self::where($map)->select()->append(['values']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getConfigTree($request) {
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = self::where($map)->select();
|
||||
|
||||
$group = Cache::get('config')['config_group_list'];
|
||||
$config = [];
|
||||
foreach ($data->toArray() as $value) {
|
||||
if (isset($group[$value['group']])) {
|
||||
$config[$group[$value['group']]][] = $value;
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置类型解析配置
|
||||
* @param integer $type 配置类型
|
||||
* @param string $value 配置值
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
private static function parse($type, $value) {
|
||||
$data = [];
|
||||
switch ($type) {
|
||||
case 'textarea': //解析数组
|
||||
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
|
||||
if (strpos($value, ':')) {
|
||||
foreach ($array as $val) {
|
||||
$list = explode(':', $val);
|
||||
if (isset($list[2])) {
|
||||
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1], 'other' => $list[2]];
|
||||
} else {
|
||||
$data[] = ['key' => is_numeric($list[0]) ? (int) $list[0] : $list[0], 'value' => $list[1], 'label' => $list[1]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($array as $key => $val) {
|
||||
$data[] = ['key' => $key, 'value' => $val, 'label' => $val];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return $value;
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
43
app/model/system/Dictionary.php
Normal file
43
app/model/system/Dictionary.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\system;
|
||||
|
||||
use think\Model;
|
||||
use think\facade\Db;
|
||||
|
||||
class Dictionary extends Model {
|
||||
|
||||
protected $type = [
|
||||
'pid' => 'integer',
|
||||
'code' => 'integer'
|
||||
];
|
||||
|
||||
public function getTitleAttr($value, $data){
|
||||
return $data['name'];
|
||||
}
|
||||
|
||||
public function getDictionList($request){
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
$order = "id asc";
|
||||
|
||||
if (isset($param['title']) && $param['title'] != '') {
|
||||
$map[] = ['title', 'LIKE', '%'.$param['title'].'%'];
|
||||
}
|
||||
if (isset($param['status']) && $param['status'] != '') {
|
||||
$map[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (isset($param['type']) && $param['type'] != '') {
|
||||
$map[] = ['model', '=', $param['type']];
|
||||
}
|
||||
|
||||
return self::where($map)->field('id, name, pid, code, model')->order($order)->select();
|
||||
}
|
||||
|
||||
}
|
||||
36
app/model/system/Rewrite.php
Normal file
36
app/model/system/Rewrite.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\system;
|
||||
|
||||
/**
|
||||
* 伪静态
|
||||
*/
|
||||
class Rewrite extends \think\Model {
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
public static $keyList = array(
|
||||
array('name' => 'id', 'title' => '标识', 'type' => 'hidden'),
|
||||
array('name' => 'rule', 'title' => '规则名称', 'type' => 'text', 'is_must'=> true, 'option' => '', 'help' => '规则名称,方便记忆'),
|
||||
array('name' => 'url', 'title' => '规则地址', 'type' => 'text', 'is_must'=> true, 'option' => '', 'help' => '规则地址'),
|
||||
);
|
||||
|
||||
/**
|
||||
* 数据修改
|
||||
* @return [bool] [是否成功]
|
||||
*/
|
||||
public function change() {
|
||||
$data = \think\Request::instance()->post();
|
||||
if (isset($data['id']) && $data['id']) {
|
||||
return $this->validate(true)->save($data, array('id' => $data['id']));
|
||||
} else {
|
||||
return $this->validate(true)->save($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
132
app/model/system/SeoRule.php
Normal file
132
app/model/system/SeoRule.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\system;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class SeoRule extends \think\Model {
|
||||
|
||||
public static $keyList = [
|
||||
['name' => 'id', 'title' => '标识', 'type' => 'hidden'],
|
||||
['name' => 'title', 'title' => '规则名称', 'type' => 'text', 'is_must'=>true, 'option' => '', 'help' => '规则名称,方便记忆'],
|
||||
['name' => 'app', 'title' => '模块名', 'type' => 'select', 'option' => [['key'=>'*', 'label' => '-所有模块-'], ['key'=>'front', 'label' => '前台模块'], ['key'=>'user', 'label' => '用户中心']], 'help' => '不选表示所有模块'],
|
||||
['name' => 'controller', 'title' => '控制器', 'type' => 'text', 'option' => '', 'help' => '不填表示所有控制器'],
|
||||
['name' => 'action', 'title' => '方法', 'type' => 'text', 'option' => '', 'help' => '不填表示所有方法'],
|
||||
['name' => 'seo_title', 'title' => 'SEO标题', 'type' => 'text', 'is_must'=>true, 'option' => '', 'help' => '不填表示使用默认'],
|
||||
['name' => 'seo_keywords', 'title' => 'SEO关键字', 'type' => 'text', 'is_must'=>true, 'option' => '', 'help' => '不填表示使用默认'],
|
||||
['name' => 'seo_description', 'title' => 'SEO描述', 'type' => 'text', 'is_must'=>true, 'option' => '', 'help' => '不填表示使用默认'],
|
||||
['name' => 'status', 'title' => '状态', 'type' => 'select', 'option' => [['key'=>'0', 'label' => '禁用'], ['key'=>'1', 'label' => '启用']], 'help' => ''],
|
||||
['name' => 'sort', 'title' => '排序', 'type' => 'text', 'option' => '', 'help' => ''],
|
||||
];
|
||||
|
||||
protected function setAppAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function setControllerAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function setActionAttr($value) {
|
||||
return (isset($value) && $value) ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getAppAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getControllerAttr($value) {
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getActionAttr($value) {
|
||||
return (isset($value) && $value) ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getRuleNameAttr($value, $data) {
|
||||
return $data['app'] . '/' . $data['controller'] . '/' . $data['action'];
|
||||
}
|
||||
|
||||
public static function getMetaOfCurrentPage($request, $seo) {
|
||||
foreach ($seo as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$seo_to_str[$key] = implode(',', $value);
|
||||
} else {
|
||||
$seo_to_str[$key] = $value;
|
||||
}
|
||||
}
|
||||
if (false !== strrpos($request->controller(), ".")) {
|
||||
list($module, $controller) = explode(".", $request->controller());
|
||||
}else{
|
||||
$module = "front";
|
||||
$controller = $request->controller();
|
||||
}
|
||||
|
||||
$result = self::getMeta($module, $controller , $request->action(), $seo_to_str);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function getMeta($module, $controller, $action, $seo) {
|
||||
//获取相关的规则
|
||||
$rules = self::getRelatedRules($module, $controller, $action);
|
||||
|
||||
//按照排序计算最终结果
|
||||
$title = '';
|
||||
$keywords = '';
|
||||
$description = '';
|
||||
|
||||
$need_seo = 1;
|
||||
foreach ($rules as $e) {
|
||||
//如果存在完全匹配的seo配置,则不用程序设置的seo资料
|
||||
if ($e['app'] && $e['controller'] && $e['action']) {
|
||||
$need_seo = 0;
|
||||
}
|
||||
if (!$title && $e['seo_title']) {
|
||||
$title = $e['seo_title'];
|
||||
}
|
||||
if (!$keywords && $e['seo_keywords']) {
|
||||
$keywords = $e['seo_keywords'];
|
||||
}
|
||||
if (!$description && $e['seo_description']) {
|
||||
$description = $e['seo_description'];
|
||||
}
|
||||
}
|
||||
if ($need_seo) {
|
||||
//默认让全站的seo规则优先级小于$this->setTitle等方式设置的规则。
|
||||
if ($seo['title']) {
|
||||
$title = $seo['title'];
|
||||
}
|
||||
if ($seo['keywords']) {
|
||||
$keywords = $seo['keywords'];
|
||||
}
|
||||
if ($seo['description']) {
|
||||
$description = $seo['description'];
|
||||
}
|
||||
}
|
||||
//生成结果
|
||||
$result = array('title' => $title, 'keywords' => $keywords, 'description' => $description);
|
||||
|
||||
//返回结果
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function getRelatedRules($module, $controller, $action) {
|
||||
//查询与当前页面相关的SEO规则
|
||||
$rules = self::where('app', 'like', ['*', $module], 'or')
|
||||
->where('controller', 'like', ['*', $controller], 'or')
|
||||
->where('action', 'like', ['*', $action], 'or')
|
||||
->where('status', 1)
|
||||
->order('sort asc')
|
||||
->select();
|
||||
|
||||
//返回规则列表
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user