1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Private mode, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2008-2009 Osku and contributors |
---|
7 | ## Licensed under the GPL version 2.0 license. |
---|
8 | # A copy of this license is available in LICENSE file or at |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')) { return; } |
---|
14 | |
---|
15 | $core->tpl->addValue('PrivatePageTitle',array('tplPrivate','PrivatePageTitle')); |
---|
16 | $core->tpl->addValue('PrivateMsg',array('tplPrivate','PrivateMsg')); |
---|
17 | $core->tpl->addValue('PrivateReqPage',array('tplPrivate','PrivateReqPage')); |
---|
18 | $core->tpl->addBlock('IfPrivateMsgError',array('tplPrivate','IfPrivateMsgError')); |
---|
19 | $core->tpl->addValue('PrivatePassRemember',array('tplPrivate','PrivatePassRemember')); |
---|
20 | $core->tpl->addValue('PrivateMsgError',array('tplPrivate','PrivateMsgError')); |
---|
21 | |
---|
22 | if ($core->blog->settings->private_flag) |
---|
23 | { |
---|
24 | $core->addBehavior('publicBeforeDocument',array('urlPrivate','privacy')); |
---|
25 | } |
---|
26 | |
---|
27 | class urlPrivate extends dcUrlHandlers |
---|
28 | { |
---|
29 | public static function privateFeed($args) |
---|
30 | { |
---|
31 | self::feed($args); |
---|
32 | } |
---|
33 | |
---|
34 | public static function publicFeed($args) |
---|
35 | { |
---|
36 | global $core,$_ctx; |
---|
37 | |
---|
38 | $type = null; |
---|
39 | $params = array(); |
---|
40 | |
---|
41 | $mime = 'application/xml'; |
---|
42 | |
---|
43 | if (preg_match('#^rss2/xslt$#',$args,$m)) |
---|
44 | { |
---|
45 | # RSS XSLT stylesheet |
---|
46 | self::serveDocument('rss2.xsl','text/xml'); |
---|
47 | //exit; |
---|
48 | } |
---|
49 | elseif (preg_match('#^(atom|rss2)/comments/([0-9]+)$#',$args,$m)) |
---|
50 | { |
---|
51 | # Post comments feed |
---|
52 | $type = $m[1]; |
---|
53 | } |
---|
54 | elseif (preg_match('#^(?:category/(.+)/)?(atom|rss2)(/comments)?$#',$args,$m)) |
---|
55 | { |
---|
56 | # All posts or comments feed |
---|
57 | $type = $m[2]; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | $tpl = $type == '' ? 'atom' : $type; |
---|
62 | $tpl .= '-pv.xml'; |
---|
63 | |
---|
64 | if ($type == 'atom') { |
---|
65 | $mime = 'application/atom+xml'; |
---|
66 | } |
---|
67 | |
---|
68 | header('X-Robots-Tag: '.context::robotsPolicy($core->blog->settings->robots_policy,'')); |
---|
69 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
70 | self::serveDocument($tpl,$mime); |
---|
71 | |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | public static function callbackbidon($args) |
---|
76 | { |
---|
77 | return; |
---|
78 | } |
---|
79 | |
---|
80 | public static function privacy($args) |
---|
81 | { |
---|
82 | global $core,$_ctx; |
---|
83 | |
---|
84 | $urlp = new urlHandler(); |
---|
85 | $urlp->mode = $core->url->mode; |
---|
86 | $urlp->registerDefault(array('urlPrivate','callbackbidon')); |
---|
87 | |
---|
88 | //$path = str_replace(http::getHost(),'',$core->blog->url); |
---|
89 | //if ($core->blog->settings->url_scan == 'query_string') |
---|
90 | //{ |
---|
91 | // $path = str_replace(basename($core->blog->url),'',$path); |
---|
92 | //} |
---|
93 | if (!isset($session)) |
---|
94 | { |
---|
95 | $session = new sessionDB( |
---|
96 | $core->con, |
---|
97 | $core->prefix.'session', |
---|
98 | 'dc_privateblog_sess_'.$core->blog->id, |
---|
99 | '/' |
---|
100 | ); |
---|
101 | $session->start(); |
---|
102 | } |
---|
103 | |
---|
104 | foreach ($core->url->getTypes() as $k=>$v) |
---|
105 | { |
---|
106 | $urlp->register($k,$v['url'],$v['representation'],array('urlPrivate','callbackbidon')); |
---|
107 | } |
---|
108 | |
---|
109 | $urlp->getDocument(); |
---|
110 | $type = $urlp->type; |
---|
111 | unset($urlp); |
---|
112 | |
---|
113 | if ($type == 'feed' || $type == 'pubfeed' || $type == 'spamfeed' || $type == 'hamfeed' || $type == 'trackback') |
---|
114 | { |
---|
115 | return; |
---|
116 | } |
---|
117 | |
---|
118 | else |
---|
119 | { |
---|
120 | // Add cookie test (automatic login) |
---|
121 | $cookiepass="dc_privateblog_cookie_".$core->blog->id; |
---|
122 | if (!empty($_COOKIE[$cookiepass])) { |
---|
123 | $cookiepassvalue=(($_COOKIE[$cookiepass]) == |
---|
124 | $core->blog->settings->blog_private_pwd); |
---|
125 | } else { |
---|
126 | $cookiepassvalue=false; |
---|
127 | } |
---|
128 | if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "") |
---|
129 | { |
---|
130 | if ($cookiepassvalue != false) { |
---|
131 | $_SESSION['sess_blog_private'] = $_COOKIE[$cookiepass]; |
---|
132 | return; |
---|
133 | |
---|
134 | } |
---|
135 | if (!empty($_POST['private_pass'])) |
---|
136 | { |
---|
137 | if (md5($_POST['private_pass']) == $core->blog->settings->blog_private_pwd) |
---|
138 | { |
---|
139 | $_SESSION['sess_blog_private'] = md5($_POST['private_pass']); |
---|
140 | if (!empty($_POST['pass_remember'])) |
---|
141 | { |
---|
142 | setcookie($cookiepass,md5($_POST['private_pass']),time()+31536000,'/'); |
---|
143 | } |
---|
144 | return; |
---|
145 | } |
---|
146 | $_ctx->blogpass_error = __('Wrong password'); |
---|
147 | } |
---|
148 | $session->destroy(); |
---|
149 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
150 | self::serveDocument('private.html','text/html',false); |
---|
151 | exit; |
---|
152 | } |
---|
153 | elseif ($_SESSION['sess_blog_private'] != $core->blog->settings->blog_private_pwd) |
---|
154 | { |
---|
155 | $session->destroy(); |
---|
156 | $_ctx->blogpass_error = __('Wrong password'); |
---|
157 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
158 | self::serveDocument('private.html','text/html',false); |
---|
159 | exit; |
---|
160 | } |
---|
161 | elseif (isset($_POST['blogout'])) |
---|
162 | { |
---|
163 | $session->destroy(); |
---|
164 | setcookie($cookiepass,'ciao',time()-86400,'/'); |
---|
165 | $_ctx->blogpass_error = __('Disconnected'); |
---|
166 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
167 | self::serveDocument('private.html','text/html',false); |
---|
168 | exit; |
---|
169 | } |
---|
170 | return; |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | class tplPrivate |
---|
176 | { |
---|
177 | public static function PrivatePageTitle($attr) |
---|
178 | { |
---|
179 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
180 | return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_title').'; ?>'; |
---|
181 | } |
---|
182 | |
---|
183 | public static function PrivateMsg($attr) |
---|
184 | { |
---|
185 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
186 | return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_msg').'; ?>'; |
---|
187 | } |
---|
188 | |
---|
189 | public static function PrivateReqPage($attr) |
---|
190 | { |
---|
191 | return '<?php echo(isset($_SERVER[\'REQUEST_URI\']) ? html::escapeHTML($_SERVER[\'REQUEST_URI\']) : $core->blog->url); ?>'; |
---|
192 | } |
---|
193 | |
---|
194 | public static function IfPrivateMsgError($attr,$content) |
---|
195 | { |
---|
196 | return |
---|
197 | '<?php if ($_ctx->blogpass_error !== null) : ?>'. |
---|
198 | $content. |
---|
199 | '<?php endif; ?>'; |
---|
200 | } |
---|
201 | |
---|
202 | public static function PrivateMsgError($attr) |
---|
203 | { |
---|
204 | return '<?php if ($_ctx->blogpass_error !== null) { echo $_ctx->blogpass_error; } ?>'; |
---|
205 | } |
---|
206 | |
---|
207 | public static function PrivatePassRemember($attr) |
---|
208 | { |
---|
209 | global $core; |
---|
210 | if ($core->blog->settings->private_conauto) |
---|
211 | { |
---|
212 | $res = '<p><label class="classic">'. |
---|
213 | form::checkbox(array('pass_remember'),1,'','',2).' '. |
---|
214 | __('Enable automatic connection').'</label></p>'; |
---|
215 | return $res; |
---|
216 | } |
---|
217 | else |
---|
218 | { |
---|
219 | return; |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | public static function privateWidgets(&$w) |
---|
224 | { |
---|
225 | global $core; |
---|
226 | if ($w->homeonly && $core->url->type != 'default') { |
---|
227 | return; |
---|
228 | } |
---|
229 | |
---|
230 | if ($core->blog->settings->private_flag) |
---|
231 | { |
---|
232 | $res = '<div class="blogout">'. |
---|
233 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
234 | ($w->text ? $w->text : ''). |
---|
235 | '<form action="'.$core->blog->url.'" method="post">'. |
---|
236 | '<p class="buttons">'. |
---|
237 | '<input type="hidden" name="blogout" id="blogout" value="" />'. |
---|
238 | '<input type="submit" value="'.html::escapeHTML($w->label).'" class="logout" /></p>'. |
---|
239 | '</form></div>'; |
---|
240 | return $res; |
---|
241 | } |
---|
242 | else |
---|
243 | { |
---|
244 | return; |
---|
245 | } |
---|
246 | } |
---|
247 | } |
---|
248 | ?> |
---|