-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
129 lines (111 loc) · 1.99 KB
/
common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
// 站点信息
function site($data = null)
{
$site = array();
if (empty($data))
{
$data = db()->select('site', '`name`, `value`')->where('state = 1')->all();
}
foreach ($data as $item)
{
$value = $item['value'];
if ($value)
{
$site[$item['name']] = $value;
}
}
return $site;
}
// 预览网站主题
function theme($site)
{
$theme = $_GET['theme'];
$skin = $_GET['skin'];
if ($theme && $skin)
{
$expire = time() + 1 * 3600;
$skin = $skin == 'default' ? '' : $skin;
setcookie('theme', $theme, $expire);
setcookie('skin', $skin, $expire);
$site['theme'] = $theme;
$site['skin'] = $skin;
}
elseif (isset($_COOKIE['theme']) && isset($_COOKIE['skin']))
{
$site['theme'] = $_COOKIE['theme'];
$site['skin'] = $_COOKIE['skin'];
}
return $site;
}
/**
* SEO优化设置
*
* @param string $title 标题
* @param string $subtitle 副标题
* @param string $keywords 关键词
* @param string $description 描述
* @param string $divider 分割线
* @return array
*/
function seo($title = '', $subtitle = '', $keywords = '', $description = '', $divider = ' — ')
{
$data = array();
if ($title)
{
if ($subtitle)
{
$data['title'] = $title . $divider . $subtitle;
}
else
{
$data['title'] = $title;
}
}
if ($keywords)
{
$data['keywords'] = $keywords;
}
if ($description)
{
$data['description'] = $description;
}
return $data;
}
/**
* css活动状态
*
* @param string|array $source 本身
* @param string|array $target 目标
* @param boolean $isclass 是否添加class=""
*/
function active($source, $target, $isclass = false)
{
$value = '';
if (is_array($source) && in_array($target, $source))
{
$value = 'active';
}
elseif ($source == $target)
{
$value = 'active';
}
if ($value)
{
if ($isclass == true)
{
echo 'class="' . $value . '"';
}
else
{
echo $value;
}
}
}
// 获取表单令牌
function token()
{
$timestamp = microtime(true);
session('_token', $timestamp);
return md5($timestamp);
}