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 callbackbidon($args) |
---|
35 | { |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | public static function privacy($args) |
---|
40 | { |
---|
41 | global $core,$_ctx; |
---|
42 | |
---|
43 | $urlp = new urlHandler(); |
---|
44 | $urlp->mode = $core->url->mode; |
---|
45 | $urlp->registerDefault(array('urlPrivate','callbackbidon')); |
---|
46 | |
---|
47 | //$path = str_replace(http::getHost(),'',$core->blog->url); |
---|
48 | //if ($core->blog->settings->url_scan == 'query_string') |
---|
49 | //{ |
---|
50 | // $path = str_replace(basename($core->blog->url),'',$path); |
---|
51 | //} |
---|
52 | if (!isset($session)) |
---|
53 | { |
---|
54 | $session = new sessionDB( |
---|
55 | $core->con, |
---|
56 | $core->prefix.'session', |
---|
57 | 'dc_privateblog_sess_'.$core->blog->id, |
---|
58 | '/' |
---|
59 | ); |
---|
60 | $session->start(); |
---|
61 | } |
---|
62 | |
---|
63 | foreach ($core->url->getTypes() as $k=>$v) |
---|
64 | { |
---|
65 | $urlp->register($k,$v['url'],$v['representation'],array('urlPrivate','callbackbidon')); |
---|
66 | } |
---|
67 | |
---|
68 | $urlp->getDocument(); |
---|
69 | $type = $urlp->type; |
---|
70 | unset($urlp); |
---|
71 | |
---|
72 | if ($type == 'feed' || $type == 'spamfeed' || $type == 'hamfeed' || $type == 'trackback') |
---|
73 | { |
---|
74 | return; |
---|
75 | } |
---|
76 | |
---|
77 | else |
---|
78 | { |
---|
79 | // Add cookie test (automatic login) |
---|
80 | $cookiepass="dc_privateblog_cookie_".$core->blog->id; |
---|
81 | if (!empty($_COOKIE[$cookiepass])) { |
---|
82 | $cookiepassvalue=(($_COOKIE[$cookiepass]) == |
---|
83 | $core->blog->settings->blog_private_pwd); |
---|
84 | } else { |
---|
85 | $cookiepassvalue=false; |
---|
86 | } |
---|
87 | if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "") |
---|
88 | { |
---|
89 | if ($cookiepassvalue != false) { |
---|
90 | $_SESSION['sess_blog_private'] = $_COOKIE[$cookiepass]; |
---|
91 | return; |
---|
92 | |
---|
93 | } |
---|
94 | if (!empty($_POST['private_pass'])) |
---|
95 | { |
---|
96 | if (md5($_POST['private_pass']) == $core->blog->settings->blog_private_pwd) |
---|
97 | { |
---|
98 | $_SESSION['sess_blog_private'] = md5($_POST['private_pass']); |
---|
99 | if (!empty($_POST['pass_remember'])) |
---|
100 | { |
---|
101 | setcookie($cookiepass,md5($_POST['private_pass']),time()+31536000,'/'); |
---|
102 | } |
---|
103 | return; |
---|
104 | } |
---|
105 | $_ctx->blogpass_error = __('Wrong password'); |
---|
106 | } |
---|
107 | $session->destroy(); |
---|
108 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
109 | self::serveDocument('private.html','text/html',false); |
---|
110 | exit; |
---|
111 | } |
---|
112 | elseif ($_SESSION['sess_blog_private'] != $core->blog->settings->blog_private_pwd) |
---|
113 | { |
---|
114 | $session->destroy(); |
---|
115 | $_ctx->blogpass_error = __('Wrong password'); |
---|
116 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
117 | self::serveDocument('private.html','text/html',false); |
---|
118 | exit; |
---|
119 | } |
---|
120 | elseif (isset($_POST['blogout'])) |
---|
121 | { |
---|
122 | $session->destroy(); |
---|
123 | setcookie($cookiepass,'ciao',time()-86400,'/'); |
---|
124 | $_ctx->blogpass_error = __('Disconnected'); |
---|
125 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
126 | self::serveDocument('private.html','text/html',false); |
---|
127 | exit; |
---|
128 | } |
---|
129 | return; |
---|
130 | } |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | class tplPrivate |
---|
135 | { |
---|
136 | public static function PrivatePageTitle($attr) |
---|
137 | { |
---|
138 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
139 | return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_title').'; ?>'; |
---|
140 | } |
---|
141 | |
---|
142 | public static function PrivateMsg($attr) |
---|
143 | { |
---|
144 | return '<?php echo $core->blog->settings->blog_private_msg; ?>'; |
---|
145 | } |
---|
146 | |
---|
147 | public static function PrivateReqPage($attr) |
---|
148 | { |
---|
149 | return '<?php echo(isset($_SERVER[\'REQUEST_URI\']) ? html::escapeHTML($_SERVER[\'REQUEST_URI\']) : $core->blog->url); ?>'; |
---|
150 | } |
---|
151 | |
---|
152 | public static function IfPrivateMsgError($attr,$content) |
---|
153 | { |
---|
154 | return |
---|
155 | '<?php if ($_ctx->blogpass_error !== null) : ?>'. |
---|
156 | $content. |
---|
157 | '<?php endif; ?>'; |
---|
158 | } |
---|
159 | |
---|
160 | public static function PrivateMsgError($attr) |
---|
161 | { |
---|
162 | return '<?php if ($_ctx->blogpass_error !== null) { echo $_ctx->blogpass_error; } ?>'; |
---|
163 | } |
---|
164 | |
---|
165 | public static function PrivatePassRemember($attr) |
---|
166 | { |
---|
167 | global $core; |
---|
168 | if ($core->blog->settings->private_conauto) |
---|
169 | { |
---|
170 | $res = '<p><label class="classic">'. |
---|
171 | form::checkbox(array('pass_remember'),1,'','',2).' '. |
---|
172 | __('Enable automatic connection').'</label></p>'; |
---|
173 | return $res; |
---|
174 | } |
---|
175 | else |
---|
176 | { |
---|
177 | return; |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | public static function privateWidgets(&$w) |
---|
182 | { |
---|
183 | global $core; |
---|
184 | if ($w->homeonly && $core->url->type != 'default') { |
---|
185 | return; |
---|
186 | } |
---|
187 | |
---|
188 | if ($core->blog->settings->private_flag) |
---|
189 | { |
---|
190 | $res = '<div class="blogout">'. |
---|
191 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
192 | ($w->text ? $w->text : ''). |
---|
193 | '<form action="'.$core->blog->url.'" method="post">'. |
---|
194 | '<p class="buttons">'. |
---|
195 | '<input type="hidden" name="blogout" id="blogout" value="">'. |
---|
196 | '<input type="submit" value="'.html::escapeHTML($w->label).'" class="logout"></p>'. |
---|
197 | '</form></div>'; |
---|
198 | return $res; |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | return; |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | ?> |
---|