-
Notifications
You must be signed in to change notification settings - Fork 0
/
_public.php
executable file
·99 lines (92 loc) · 4.06 KB
/
_public.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
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of YASH3, a plugin for DotClear2.
# Copyright (c) 2016 Gnieark https://blog-du-grouik.tinad.fr
#
# Forked and modified from Yash Copyright (c) 2008 Pep and contributors
# licensed under GNU/GPL license
#
# This plugin is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This plugin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this plugin; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
if (!defined('DC_RC_PATH')) { return; }
$core->addBehavior('publicHeadContent', array('dcYASH','publicHeadContent'));
$core->addBehavior('publicFooterContent', array('dcYASH','publicFooterContent'));
$core->url->register('yash3','yash3','^yash3(?:/(.+))?$',array('dcYASH','getVarFile'));
class dcYASH
{
public static function getVarFile($args)
{
/*
* send the css or js file
* Don't take care about all path vars
*/
global $core;
list($osef,$ext) = explode(".",$args);
switch($ext){
case "css":
$ext = "css";
header("Content-type: text/css");
break;
case "js":
header('Content-Type: application/javascript');
$ext = "js";
break;
default:
throw new Exception ("Page not found",404);
break;
}
$fileToSend = path::real(DC_VAR)."/yash3/".
$core->blog->id."/".
$core->blog->settings->yash3->yash3_concat_version.".".
$ext;
if(file_exists($fileToSend)){
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (365*3600*24)));
echo file_get_contents($fileToSend);
}else{
throw new Exception ("Page not found",404);
}
}
public static function publicFooterContent()
{
global $core;
$core->blog->settings->addNamespace('yash3');
if ($core->blog->settings->yash3->yash3_active){
$cssURL = $core->blog->url.$core->url->getBase('yash3')."/".
$core->blog->settings->yash3->yash3_concat_version.
".css";
echo "<noscript id=\"deferred-yash-style\">\n".
" <link rel=\"stylesheet\" type=\"text/css\" href=\"".$cssURL."\"/>\n".
"</noscript>\n".
"<script>\n".
"var loadYashDeferredStyles = function() {\n".
" var addStylesNode = document.getElementById('deferred-yash-style');\n".
" var replacement = document.createElement('div');\n".
" replacement.innerHTML = addStylesNode.textContent;\n".
" document.body.appendChild(replacement)\n".
" addStylesNode.parentElement.removeChild(addStylesNode);\n".
"};\n".
"var raf = requestAnimationFrame || mozRequestAnimationFrame ||\n".
" webkitRequestAnimationFrame || msRequestAnimationFrame;\n".
"if (raf) raf(function() { window.setTimeout(loadYashDeferredStyles, 0); });\n".
"else window.addEventListener('load', loadYashDeferredStyles);\n".
"</script>";
$jsURL = $core->blog->url.$core->url->getBase('yash3')."/".
$core->blog->settings->yash3->yash3_concat_version.
".js";
echo '<script async src="'.$jsURL.'"></script>';
}
}
}