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('PrivateMsgError',array('tplPrivate','PrivateMsgError')); |
---|
23 | |
---|
24 | if ($core->blog->settings->private_flag) |
---|
25 | { |
---|
26 | //$core->addBehavior('publicPrepend',array('urlPrivate','initSession')); |
---|
27 | $core->addBehavior('publicBeforeDocument',array('urlPrivate','privacy')); |
---|
28 | } |
---|
29 | |
---|
30 | class urlPrivate extends dcUrlHandlers |
---|
31 | { |
---|
32 | public static function initSession($args) |
---|
33 | { |
---|
34 | $session_private = session_id(); |
---|
35 | if (empty($session_private)) |
---|
36 | { |
---|
37 | session_start(); |
---|
38 | } |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | public static function privateFeed($args) |
---|
43 | { |
---|
44 | self::feed($args); |
---|
45 | } |
---|
46 | |
---|
47 | public static function callbackbidon($args) |
---|
48 | { |
---|
49 | return; |
---|
50 | } |
---|
51 | |
---|
52 | public static function privacy($args) |
---|
53 | { |
---|
54 | global $core,$_ctx; |
---|
55 | |
---|
56 | $urlp = new urlHandler(); |
---|
57 | $urlp->mode = $core->url->mode; |
---|
58 | $urlp->registerDefault(array('urlPrivate','callbackbidon')); |
---|
59 | |
---|
60 | foreach ($core->url->getTypes() as $k=>$v) |
---|
61 | { |
---|
62 | $urlp->register($k,$v['url'],$v['representation'],array('urlPrivate','callbackbidon')); |
---|
63 | } |
---|
64 | |
---|
65 | $urlp->getDocument(); |
---|
66 | $type = $urlp->type; |
---|
67 | unset($urlp); |
---|
68 | |
---|
69 | if ($type == 'feed' || $type == 'spamfeed' || $type == 'hamfeed' || $type == 'trackback') |
---|
70 | { |
---|
71 | return; |
---|
72 | } |
---|
73 | |
---|
74 | else |
---|
75 | { |
---|
76 | $session_private = session_id(); |
---|
77 | if (empty($session_private)) |
---|
78 | { |
---|
79 | session_start(); |
---|
80 | } |
---|
81 | if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "") |
---|
82 | { |
---|
83 | if (!empty($_POST['private_pass'])) |
---|
84 | { |
---|
85 | if (md5($_POST['private_pass']) == $core->blog->settings->blog_private_pwd) |
---|
86 | { |
---|
87 | $_SESSION['sess_blog_private'] = md5($_POST['private_pass']); |
---|
88 | return; |
---|
89 | } |
---|
90 | $_ctx->blogpass_error = __('Wrong password'); |
---|
91 | } |
---|
92 | session_unset(); |
---|
93 | session_destroy(); |
---|
94 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
95 | self::serveDocument('private.html'); |
---|
96 | exit; |
---|
97 | } |
---|
98 | elseif ($_SESSION['sess_blog_private'] != $core->blog->settings->blog_private_pwd) |
---|
99 | { |
---|
100 | session_unset(); |
---|
101 | session_destroy(); |
---|
102 | $_ctx->blogpass_error = __('Wrong password'); |
---|
103 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
104 | self::serveDocument('private.html'); |
---|
105 | exit; |
---|
106 | } |
---|
107 | elseif (isset($_POST['blogout'])) |
---|
108 | { |
---|
109 | session_unset(); |
---|
110 | session_destroy(); |
---|
111 | $_ctx->blogpass_error = __('Disconnected'); |
---|
112 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
113 | self::serveDocument('private.html'); |
---|
114 | exit; |
---|
115 | } |
---|
116 | return; |
---|
117 | } |
---|
118 | return; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | class tplPrivate |
---|
123 | { |
---|
124 | public static function PrivatePageTitle($attr) |
---|
125 | { |
---|
126 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
127 | return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_title').'; ?>'; |
---|
128 | } |
---|
129 | |
---|
130 | public static function PrivateMsg($attr) |
---|
131 | { |
---|
132 | return '<?php echo $core->blog->settings->blog_private_msg; ?>'; |
---|
133 | } |
---|
134 | |
---|
135 | public static function PrivateReqPage($attr) |
---|
136 | { |
---|
137 | return '<?php echo(isset($_SERVER[\'REQUEST_URI\']) ? html::escapeHTML($_SERVER[\'REQUEST_URI\']) : $core->blog->url); ?>'; |
---|
138 | } |
---|
139 | |
---|
140 | public static function IfPrivateMsgError($attr,$content) |
---|
141 | { |
---|
142 | return |
---|
143 | '<?php if ($_ctx->blogpass_error !== null) : ?>'. |
---|
144 | $content. |
---|
145 | '<?php endif; ?>'; |
---|
146 | } |
---|
147 | |
---|
148 | public static function PrivateMsgError($attr) |
---|
149 | { |
---|
150 | return '<?php if ($_ctx->blogpass_error !== null) { echo $_ctx->blogpass_error; } ?>'; |
---|
151 | } |
---|
152 | |
---|
153 | public static function privateWidgets(&$w) |
---|
154 | { |
---|
155 | global $core; |
---|
156 | if ($w->homeonly && $core->url->type != 'default') { |
---|
157 | return; |
---|
158 | } |
---|
159 | $res = '<div class="blogout">'. |
---|
160 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
161 | '<form action="'.$core->blog->url.'" method="post">'. |
---|
162 | '<p class="buttons">'. |
---|
163 | '<input type="hidden" name="blogout" id="blogout" value="">'. |
---|
164 | '<input type="submit" value="'.__('Disconnect').'" class="logout"></p>'. |
---|
165 | '</form></div>'; |
---|
166 | return $res; |
---|
167 | } |
---|
168 | } |
---|
169 | ?> |
---|