1 | <?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ |
---|
2 | /***************************************************************\ |
---|
3 | * This is 'Private', a plugin for Dotclear 2 * |
---|
4 | * * |
---|
5 | * Copyright (c) 2008 * |
---|
6 | * Osku and contributors. * |
---|
7 | * * |
---|
8 | * This is an open source software, distributed under the GNU * |
---|
9 | * General Public License (version 2) terms and conditions. * |
---|
10 | * * |
---|
11 | * You should have received a copy of the GNU General Public * |
---|
12 | * License along with 'Private blog' (see LICENSE); * |
---|
13 | * if not, write to the Free Software Foundation, Inc., * |
---|
14 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
15 | \***************************************************************/ |
---|
16 | if (!defined('DC_RC_PATH')) { return; } |
---|
17 | |
---|
18 | $core->tpl->addValue('PrivatePageTitle',array('tplPrivate','PrivatePageTitle')); |
---|
19 | $core->tpl->addValue('PrivateMsg',array('tplPrivate','PrivateMsg')); |
---|
20 | $core->tpl->addValue('PrivateReqPage',array('tplPrivate','PrivateReqPage')); |
---|
21 | $core->tpl->addBlock('IfPrivateMsgError',array('tplPrivate','IfPrivateMsgError')); |
---|
22 | $core->tpl->addValue('PrivatePassRemember',array('tplPrivate','PrivatePassRemember')); |
---|
23 | $core->tpl->addValue('PrivateMsgError',array('tplPrivate','PrivateMsgError')); |
---|
24 | |
---|
25 | if ($core->blog->settings->private_flag) |
---|
26 | { |
---|
27 | $core->addBehavior('publicBeforeDocument',array('urlPrivate','privacy')); |
---|
28 | } |
---|
29 | |
---|
30 | class urlPrivate extends dcUrlHandlers |
---|
31 | { |
---|
32 | public static function privateFeed($args) |
---|
33 | { |
---|
34 | self::feed($args); |
---|
35 | } |
---|
36 | |
---|
37 | public static function callbackbidon($args) |
---|
38 | { |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | public static function privacy($args) |
---|
43 | { |
---|
44 | global $core,$_ctx; |
---|
45 | |
---|
46 | $urlp = new urlHandler(); |
---|
47 | $urlp->mode = $core->url->mode; |
---|
48 | $urlp->registerDefault(array('urlPrivate','callbackbidon')); |
---|
49 | |
---|
50 | $path = str_replace(http::getHost(),'',$core->blog->url); |
---|
51 | if ($core->blog->settings->url_scan == 'query_string') |
---|
52 | { |
---|
53 | $path = str_replace(basename($core->blog->url),'',$path); |
---|
54 | } |
---|
55 | if (!isset($session)) |
---|
56 | { |
---|
57 | $session = new sessionDB( |
---|
58 | $core->con, |
---|
59 | $core->prefix.'session', |
---|
60 | 'dc_privateblog', |
---|
61 | $path |
---|
62 | ); |
---|
63 | $session->start(); |
---|
64 | } |
---|
65 | |
---|
66 | foreach ($core->url->getTypes() as $k=>$v) |
---|
67 | { |
---|
68 | $urlp->register($k,$v['url'],$v['representation'],array('urlPrivate','callbackbidon')); |
---|
69 | } |
---|
70 | |
---|
71 | $urlp->getDocument(); |
---|
72 | $type = $urlp->type; |
---|
73 | unset($urlp); |
---|
74 | |
---|
75 | if ($type == 'feed' || $type == 'spamfeed' || $type == 'hamfeed' || $type == 'trackback') |
---|
76 | { |
---|
77 | return; |
---|
78 | } |
---|
79 | |
---|
80 | else |
---|
81 | { |
---|
82 | // Add cookie test |
---|
83 | $cookiepass="dc_blog_private_".$core->blog->id; |
---|
84 | if (!empty($_COOKIE[$cookiepass])) { |
---|
85 | $cookiepassvalue=(($_COOKIE[$cookiepass]) == |
---|
86 | $core->blog->settings->blog_private_pwd); |
---|
87 | } else { |
---|
88 | $cookiepassvalue=false; |
---|
89 | } |
---|
90 | if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "") |
---|
91 | { |
---|
92 | if ($cookiepassvalue != false) { |
---|
93 | $_SESSION['sess_blog_private'] = $_COOKIE[$cookiepass]; |
---|
94 | setcookie($cookiepass,$_COOKIE[$cookiepass],time()+31536000,'/'); |
---|
95 | return; |
---|
96 | |
---|
97 | } |
---|
98 | if (!empty($_POST['private_pass'])) |
---|
99 | { |
---|
100 | if (md5($_POST['private_pass']) == $core->blog->settings->blog_private_pwd) |
---|
101 | { |
---|
102 | $_SESSION['sess_blog_private'] = md5($_POST['private_pass']); |
---|
103 | if (!empty($_POST['pass_remember'])) |
---|
104 | { |
---|
105 | setcookie($cookiepass,md5($_POST['private_pass']),time()+31536000,'/'); |
---|
106 | } |
---|
107 | return; |
---|
108 | } |
---|
109 | $_ctx->blogpass_error = __('Wrong password'); |
---|
110 | } |
---|
111 | $session->destroy(); |
---|
112 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
113 | self::serveDocument('private.html','text/html',false); |
---|
114 | exit; |
---|
115 | } |
---|
116 | elseif ($_SESSION['sess_blog_private'] != $core->blog->settings->blog_private_pwd) |
---|
117 | { |
---|
118 | $session->destroy(); |
---|
119 | $_ctx->blogpass_error = __('Wrong password'); |
---|
120 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
121 | self::serveDocument('private.html','text/html',false); |
---|
122 | exit; |
---|
123 | } |
---|
124 | elseif (isset($_POST['blogout'])) |
---|
125 | { |
---|
126 | $session->destroy(); |
---|
127 | $_ctx->blogpass_error = __('Disconnected'); |
---|
128 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
129 | self::serveDocument('private.html','text/html',false); |
---|
130 | exit; |
---|
131 | } |
---|
132 | return; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | class tplPrivate |
---|
138 | { |
---|
139 | public static function PrivatePageTitle($attr) |
---|
140 | { |
---|
141 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
142 | return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_title').'; ?>'; |
---|
143 | } |
---|
144 | |
---|
145 | public static function PrivateMsg($attr) |
---|
146 | { |
---|
147 | return '<?php echo $core->blog->settings->blog_private_msg; ?>'; |
---|
148 | } |
---|
149 | |
---|
150 | public static function PrivateReqPage($attr) |
---|
151 | { |
---|
152 | return '<?php echo(isset($_SERVER[\'REQUEST_URI\']) ? html::escapeHTML($_SERVER[\'REQUEST_URI\']) : $core->blog->url); ?>'; |
---|
153 | } |
---|
154 | |
---|
155 | public static function IfPrivateMsgError($attr,$content) |
---|
156 | { |
---|
157 | return |
---|
158 | '<?php if ($_ctx->blogpass_error !== null) : ?>'. |
---|
159 | $content. |
---|
160 | '<?php endif; ?>'; |
---|
161 | } |
---|
162 | |
---|
163 | public static function PrivateMsgError($attr) |
---|
164 | { |
---|
165 | return '<?php if ($_ctx->blogpass_error !== null) { echo $_ctx->blogpass_error; } ?>'; |
---|
166 | } |
---|
167 | |
---|
168 | public static function PrivatePassRemember($attr) |
---|
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 | |
---|
176 | public static function privateWidgets(&$w) |
---|
177 | { |
---|
178 | global $core; |
---|
179 | if ($w->homeonly && $core->url->type != 'default') { |
---|
180 | return; |
---|
181 | } |
---|
182 | |
---|
183 | if ($core->blog->settings->private_flag) |
---|
184 | { |
---|
185 | $res = '<div class="blogout">'. |
---|
186 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
187 | '<form action="'.$core->blog->url.'" method="post">'. |
---|
188 | '<p class="buttons">'. |
---|
189 | '<input type="hidden" name="blogout" id="blogout" value="">'. |
---|
190 | '<input type="submit" value="'.__('Disconnect').'" class="logout"></p>'. |
---|
191 | '</form></div>'; |
---|
192 | return $res; |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | return; |
---|
197 | } |
---|
198 | } |
---|
199 | } |
---|
200 | ?> |
---|