forked from ccjuse/Mirages-For-Typecho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
head.php
191 lines (181 loc) · 7.27 KB
/
head.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php
$this->ddb = $this->db;
@$if_https = $_SERVER['HTTPS']; //这样就不会有错误提示
if ($if_https) { //如果是使用 https 访问的话就添加 https
define('IS_HTTPS', true);
} else {
define('IS_HTTPS', false);
}
if (IS_HTTPS) {
$highlightJSPath = "//cdn.bootcss.com/highlight.js/9.2.0/";
} else {
$highlightJSPath = "http://apps.bdimg.com/libs/highlight.js/9.1.0/";
}
//Add-on highlight language
$addOnHighlightLang = array();
$highlightLanguages = array(
"swift" => "languages/swift.min.js",
);
$rawContentText = $this->text;
$rawContentText = strtolower($rawContentText);
foreach ($highlightLanguages as $lang=>$url) {
$lang = '```'.strtolower($lang);
if(strpos($rawContentText,$lang) >= 0){
$addOnHighlightLang[] = $url;
}
}
$addOnHighlightLangHtml = "";
foreach ($addOnHighlightLang as $url) {
$addOnHighlightLangHtml .='<script src="'.$highlightJSPath . $url.'" type="text/javascript"></script>'."\n";
}
?>
<meta charset="<?php $this->options->charset(); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title><?php $this->archiveTitle(array(
'category' => _t('分类 %s 下的文章'),
'search' => _t('包含关键字 %s 的文章'),
'tag' => _t('标签 %s 下的文章'),
'author' => _t('%s 发布的文章')
), '', ' - '); ?><?php $this->options->title(); ?></title>
<?php $this->options->bowserInsight()?>
<?php $this->options->customMeta()?>
<script type="text/javascript">
var BASE_SCRIPT_URL = "<?= STATIC_PATH ?>";
var width=window.screen.availWidth;
var height=window.screen.availHeight;
var injectStyle = function(css) {
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.href = css;
document.head.appendChild(link);
};
var getImageAddon = function(width, height){
var addon = "?";
var ratio = window.devicePixelRatio || 1;
width = width || 0;
height = height || 0;
if(width == 0 && height == 0){
return "";
}
var format = "";
<?php if(!empty($this->options->otherOptions) && in_array('enableWebP', $this->options->otherOptions) && shouldEnableWebP()):?>
format = "/format/webp";
<?php endif?>
if(width >= height){
addon += "imageView2/2/w/"+ parseInt(width * ratio) + "/q/75" + format;
}else{
addon += "imageView2/2/h/"+ parseInt(height * ratio) + "/q/75" + format;
}
return addon;
};
var IS_MOBILE = false,
IS_PHONE = false,
IS_TABLET = false,
IS_HTTPS = false;
<?php if(isMobile()):?>
IS_MOBILE = true;
<?php endif?>
<?php if(isPhone()):?>
IS_PHONE = true;
<?php endif?>
<?php if(isTablet()):?>
IS_TABLET = true;
<?php endif?>
<?php if(IS_HTTPS):?>
IS_HTTPS = true;
<?php endif?>
var bg = "<?php
if($this->is("index")){
$this->banner = $this->options->defaultBg;
} else {
$this->banner = loadArchiveBanner($this);
}
echo $this->banner;
?>";
var getBgHeight = function(windowHeight){
windowHeight = windowHeight || 560;
if (windowHeight > window.screen.availHeight) {
windowHeight = window.screen.availHeight;
}
<?php if(isset($this->fields->bannerHeight)):?>
var bgHeightP = "<?=$this->fields->bannerHeight?>";
<?php else:?>
var bgHeightP = "<?=$this->options->defaultBgHeight?>";
<?php endif?>
bgHeightP = bgHeightP.trim();
bgHeightP = parseFloat(bgHeightP);
bgHeightP = windowHeight * bgHeightP / 100;
return bgHeightP;
};
<?php if((!empty($this->options->otherOptions) && in_array('useQiniuImageResize', $this->options->otherOptions))):?>
var addon = getImageAddon(width, height);
bg = bg.trim();
bg += addon;
<?php endif?>
</script>
<?php if(isMobile()):?>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Merriweather:300italic,300&subset=latin,latin-ext">
<?php else:?>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Merriweather:300italic,300&subset=latin,latin-ext">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:100,300,400,600&subset=latin,latin-ext">
<?php endif?>
<!-- 使用url函数转换相关路径 -->
<link rel="stylesheet" href="//cdn.bootcss.com/normalize/3.0.3/normalize.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" href="<?= STATIC_PATH ?>css/base.css">
<?php if(IS_HTTPS): ?>
<link rel="stylesheet" href="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.css">
<?php else:?>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/nprogress/0.1.2/nprogress.css">
<?php endif?>
<?php if(THEME_CLASS == "theme-dark"):?>
<link rel="stylesheet" href="<?=$highlightJSPath?>/styles/tomorrow-night-eighties.min.css">
<?php else:?>
<link rel="stylesheet" href="<?=$highlightJSPath?>/styles/tomorrow.min.css">
<?php endif?>
<?php if($this->options->disableAutoNightTheme <= 0 && !hasValue($this->options->disqusShortName) && THEME_CLASS != "theme-dark"):?>
<script>
var hour = new Date().getHours();
var USE_MIRAGES_DARK = false;
if (hour <= 5 || hour >= 22) {
USE_MIRAGES_DARK = true;
injectStyle("<?=$highlightJSPath?>/styles/tomorrow-night-eighties.min.css");
}
</script>
<?php endif?>
<link rel="stylesheet" href="<?= STATIC_PATH ?>css/theme.css">
<?php if (strlen($this->options->shortcutIcon) > 5): ?>
<link rel="shortcut icon" href="<?php $this->options->shortcutIcon(); ?>">
<?php else:?>
<link rel="shortcut icon" href="<?php $this->options->siteUrl(); ?>favicon.ico">
<?php endif?>
<script src="<?=$highlightJSPath?>/highlight.min.js" type="text/javascript"></script>
<?php if(IS_HTTPS): ?>
<script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js" type="text/javascript"></script>
<script src="//cdn.bootcss.com/nprogress/0.2.0/nprogress.min.js" type="text/javascript"></script>
<?php else:?>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
<script src="http://apps.bdimg.com/libs/nprogress/0.1.2/nprogress.js" type="text/javascript"></script>
<?php endif?>
<?=$addOnHighlightLangHtml; ?>
<?php if((!empty($this->options->otherOptions) && in_array('showJax', $this->options->otherOptions))):?>
<script src="//cdn.bootcss.com/mathjax/2.5.3/MathJax.js" type="text/javascript"></script>
<script src="<?= STATIC_PATH ?>js/TeX-AMS-MML_HTMLorMML.js" type="text/javascript"></script>
<?php endif?>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
<!--[if lt IE 9]>
<script src="//cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>
<script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- 通过自有函数输出HTML头部信息 -->
<?php $this->header("generator=&");echo "\n"; ?>
<?php if(!$this->user->hasLogin()):?>
<script>
<?php $this->options->tongJi();echo "\n"; ?>
</script>
<?php endif?>