<?php
/*
Plugin Name: 模板设置
Version: 2+2
Plugin URL: https://github.com/Baiqiang/em_tpl_options
Description: 为支持的模板设置参数。
ForEmlog: 5.2.0+
Author: 奇遇
Author URL: http://www.qiyuuu.com
*/
!defined('EMLOG_ROOT') && exit('access deined!');
/**
* 模板设置类
*/
class TplOptions {
//插件标识
const ID = 'tpl_options';
const NAME = '模板设置';
const VERSION = '2+2';
//数据表前缀
private $_prefix = 'tpl_options_';
//数据表
private $_tables = array(
'data',
);
//运行上传的文件类型
private $_imageTypes = array(
'gif',
'jpg',
'jpeg',
'png'
);
//实例
private static $_instance;
//是否初始化
private $_inited = false;
//模板参数
private $_templateOptions;
//从模板读取经过处理的原始设置项
private $_options;
//支持的参数类型
private $_types;
//数据为数组的类型
private $_arrayTypes = array();
//数据库连接实例
private $_db;
//插件模板目录
private $_view;
//插件前端资源路径
private $_assets;
//当前模板
private $_currentTemplate;
//页面
private $_pages;
/**
* 单例入口
* @return TplOptions
*/
public static function getInstance() {
if (self::$_instance === null) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* 私有构造函数,保证单例
*/
private function __construct() {
}
/**
* 初始化函数
* @return void
*/
public function init() {
if ($this->_inited === true) {
return;
}
$this->_inited = true;
//初始化各个数据表名
$tables = array();
foreach ($this->_tables as $name => $table) {
$tables[$table] = $this->getTableName($table);
}
$this->_tables = $tables;
//初始化模板设置类型
$this->_types = array(
'radio' => array(
'name' => '单选按钮',
'allowMulti' => false,
),
'checkbox' => array(
'name' => '复选按钮',
'allowMulti' => true,
),
'text' => array(
'name' => '文本',
'allowMulti' => true,
'allowRich' => true,
),
'image' => array(
'name' => '图片',
'allowMulti' => false,
),
'page' => array(
'name' => '页面',
'allowMulti' => true,
),
'sort' => array(
'name' => '分类',
'allowMulti' => true,
'allowDepend' => true,
),
'tag' => array(
'name' => '标签',
'allowMulti' => true,
),
);
$this->_arrayTypes = array(
'checkbox',
'tag',
);
//设置模板目录
$this->_view = dirname(__FILE__) . '/views/';
$this->_assets = BLOG_URL . 'content/plugins/' . self::ID . '/assets/';
//注册各个钩子
$scriptBaseName = strtolower(substr(basename($_SERVER['SCRIPT_NAME']), 0, -4));
addAction('adm_main_top', array(
$this,
'hookAdminMainTopIcon'
));
addAction('data_prebakup', array(
$this,
'hookDataPreBackup'
));
if ($scriptBaseName == 'template') {
addAction('adm_main_top', array(
$this,
'hookAdminMainTopData'
));
addAction('adm_head', array(
$this,
'hookAdminHead'
));
}
}
/**
* 侧栏小图标
* @return void
*/
public function hookAdminMainTopIcon() {
echo sprintf('<script>$("a[href=\\"template.php\\"]").css("background", "url(%s/setting.png) no-repeat 20px 1px");</script>', $this->_assets);
}
/**
* 输出数据
* @return void
*/
public function hookAdminMainTopData() {
$templates = $this->getTemplates();
$data = array(
'templates' => $templates,
'prefix' => str_replace('_', '-', $this->_prefix),
'baseUrl' => $this->url(),
'uploadUrl' => $this->url(array(
"do" => "upload"
)),
);
echo sprintf('<script>var tplOptions = %s;</script>', json_encode($data));
}
/**
* 备份数据表
* @return void
*/
public function hookDataPreBackup() {
global $tables;
$prefixLen = strlen(DB_PREFIX);
foreach ($this->getTable() as $table) {
$tables[] = substr($table, $prefixLen);
}
}
/**
* 头部,如css文件
* @return void
*/
public function hookAdminHead() {
echo sprintf('<link rel="stylesheet" href="%s">', $this->_assets . 'main.css?ver=' . urlencode(self::VERSION));
echo '<script charset="utf-8" src="./editor/kindeditor.js"></script>';
echo '<script charset="utf-8" src="./editor/lang/zh_CN.js"></script>';
echo sprintf('<script src="%s"></script>', $this->_assets . 'main.js?ver=' . urlencode(self::VERSION));
}
/**
* 获取数据表
* @param mixed $table 表名缩写,可选,若不设置则返回所有表,否则返回对应表
* @return mixed 返回数组或字符串
*/
public function getTable($table = null) {
return $table === null ? $this->_tables : (isset($this->_tables[$table]) ? $this->_tables[$table] : '');
}
/**
* 获取数据表名
* @param string $table 表名缩写
* @return string 表全名
*/
private function getTableName($table) {
return DB_PREFIX . $this->_prefix . $table;
}
/**
* 获取模板参数数据,默认获取当前模板
* @param mixed $template 模板名称,可选
* @return array 模板参数
*/
public function getTemplateOptions($template = null) {
if ($template === null) {
$template = Option::get('nonce_templet');
}
if (isset($this->_templateOptions[$template])) {
return $this->_templateOptions[$template];
}
$_data = $this->queryAll('data', array(
'template' => $template,
));
$templateOptions = array();
$options = $this->getTemplateDefinedOptions($template);
if ($options === false) {
$options = array();
}
foreach ($_data as $row) {
extract($row);
$data = unserialize($data);
$templateOptions[$name] = $data;
}
$unsorted = isset($option['unsorted']) ? $option['unsorted'] : true;
$sorts = $this->getSorts($unsorted);
$pages = $this->getPages();
foreach ($options as $name => $option) {
if (!is_array($option) || !isset($option['name']) || !isset($option['type']) || !isset($this->_types[$option['type']])) {
unset($options[$name]);
continue;
}
if (!isset($templateOptions[$name])) {
$templateOptions[$name] = $this->getOptionDefaultValue($option, $template);
}
$depend = isset($option['depend']) ? $option['depend'] : '';
switch ($depend) {
case 'sort':
if (!is_array($templateOptions[$name])) {
$templateOptions[$name] = array();
}
foreach ($sorts as $sort) {
if (!isset($templateOptions[$name][$sort['sid']])) {
$templateOptions[$name][$sort['sid']] = $this->getOptionDefaultValue($option, $template);
}
}
break;
}
switch ($option['type']) {
case 'sort':
case 'page':
$varName = $option['type'] . 's';
$var = $$varName;
if (!$this->isMulti($option) && !isset($var[$templateOptions[$name]])) {
$templateOptions[$name] = $this->getOptionDefaultValue($option, $template);
}
break;
default:
break;
}
if ($option['type'] == 'image') {
$templateOptions[$name] = $this->buildImageUrl($templateOptions[$name]);
}
}
return $this->_templateOptions[$template] = $templateOptions;
}
/**
* 设置模板参数数据
* @param string $template 模板名称
* @param array $options 模板参数
* @return boolean
*/
public function setTemplateOptions($template, $options) {
if ($options === array()) {
return true;
}
$data = array();
foreach ($options as $name => $option) {
$data[] = array(
'template' => $template,
'name' => $name,
'depend' => $option['depend'],
'data' => serialize($option['data']),
);
}
return $this->insert('data', $data, true);
}
/**
* 获取所有分类
* @param boolean $unsorted 是否获取未分类
* @return array
*/
private function getSorts($unsorted = false) {
$sorts = Cache::getInstance()->readCache('sort');
if ($unsorted) {
array_unshift($sorts, array(
'sid' => - 1,
'sortname' => '未分类',
'lognum' => 0,
'children' => array(),
));
}
return $sorts;
}
/**
* 获取所有页面
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码-Emlog for SAE 适合新浪sae使用的个人博客系统 移植版.zip
共386个文件
php:173个
gif:113个
png:32个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 147 浏览量
2022-11-21
08:22:15
上传
评论
收藏 886KB ZIP 举报
温馨提示
PHP实例开发源码—Emlog for SAE 适合新浪sae使用的个人博客系统 移植版.zip PHP实例开发源码—Emlog for SAE 适合新浪sae使用的个人博客系统 移植版.zip PHP实例开发源码—Emlog for SAE 适合新浪sae使用的个人博客系统 移植版.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码-Emlog for SAE 适合新浪sae使用的个人博客系统 移植版.zip (386个子文件)
config 361B
default.css 21KB
main.css 21KB
css-main.css 18KB
uquwu.css 17KB
main.css 11KB
main.css 5KB
style.css 3KB
style.css 3KB
css-uploadify.css 2KB
css-login.css 1KB
prettify.css 1KB
css-att.css 934B
imgareaselect.css 828B
top_bottom.css 497B
static.gif 11KB
logo.gif 7KB
sprite.gif 7KB
loading.gif 3KB
custom_top.gif 2KB
sidebar_bg_a.gif 2KB
add_bg.gif 2KB
tar.gif 2KB
13.gif 2KB
19.gif 2KB
30.gif 1KB
28.gif 1KB
25.gif 1KB
16.gif 1KB
rss.gif 1KB
8.gif 1KB
29.gif 1KB
21.gif 1KB
goto1.gif 1KB
18.gif 1KB
20.gif 1KB
6.gif 1KB
7.gif 1KB
32.gif 1KB
10.gif 1KB
top_mid.gif 1KB
yeka.gif 1KB
4.gif 1KB
nav-new.gif 1KB
34.gif 1KB
fnone.gif 1KB
23.gif 1KB
flash.gif 1KB
11.gif 1KB
15.gif 1KB
media.gif 1KB
22.gif 998B
rm.gif 989B
goto.gif 964B
store.gif 961B
31.gif 956B
14.gif 948B
3.gif 932B
33.gif 895B
2.gif 892B
1.gif 887B
att.gif 875B
5.gif 856B
9.gif 838B
26.gif 838B
36.gif 830B
12.gif 818B
24.gif 814B
17.gif 796B
loading.gif 722B
27.gif 692B
35.gif 645B
align_left.gif 639B
align_right.gif 636B
0.gif 636B
align_top.gif 625B
plugin.gif 607B
bg_cal_today.gif 599B
m.gif 582B
login_button.gif 560B
hot.gif 477B
sidebar_bg_a.gif 469B
sidebar_bg_t.gif 381B
sidebar_bg_t.gif 381B
plugin_active.gif 375B
addblog.gif 357B
icon_tips.gif 355B
onsel.gif 314B
em_button.gif 265B
icon_error.gif 265B
top_mid.gif 263B
weibe_button.gif 247B
weibe_button.gif 247B
t.gif 239B
sidebar_bg_b.gif 225B
sidebar_bg_b.gif 225B
icon_add.gif 224B
border-anim-v.gif 219B
border-anim-h.gif 219B
post-nav-previous.gif 212B
共 386 条
- 1
- 2
- 3
- 4
资源评论
毕业_设计
- 粉丝: 1924
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功