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 | $core->addBehavior('publicBeforeDocument',array('urlPrivate','privacy')); |
---|
25 | |
---|
26 | |
---|
27 | class urlPrivate extends dcUrlHandlers |
---|
28 | { |
---|
29 | public static function privacy($args) |
---|
30 | { |
---|
31 | global $core,$_ctx; |
---|
32 | |
---|
33 | if ($core->blog->settings->private_flag) |
---|
34 | { |
---|
35 | $session_private = session_id(); |
---|
36 | if (empty($session_private)) |
---|
37 | { |
---|
38 | session_start(); |
---|
39 | } |
---|
40 | if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "") |
---|
41 | { |
---|
42 | if (!empty($_POST['private_pass'])) |
---|
43 | { |
---|
44 | if (md5($_POST['private_pass']) == $core->blog->settings->blog_private_pwd) |
---|
45 | { |
---|
46 | $_SESSION['sess_blog_private'] = md5($_POST['private_pass']); |
---|
47 | return; |
---|
48 | } |
---|
49 | $_ctx->blogpass_error = __('Wrong password'); |
---|
50 | } |
---|
51 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
52 | self::serveDocument('private.html'); |
---|
53 | exit; |
---|
54 | } |
---|
55 | elseif (isset($_POST['blogout'])){ |
---|
56 | session_unset(); |
---|
57 | session_destroy(); |
---|
58 | $_ctx->blogpass_error = __('Disconnected'); |
---|
59 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
60 | self::serveDocument('private.html'); |
---|
61 | exit; |
---|
62 | } |
---|
63 | return; |
---|
64 | } |
---|
65 | return; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | class tplPrivate |
---|
70 | { |
---|
71 | public static function PrivatePageTitle($attr) |
---|
72 | { |
---|
73 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
74 | return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_title').'; ?>'; |
---|
75 | } |
---|
76 | |
---|
77 | public static function PrivateMsg($attr) |
---|
78 | { |
---|
79 | return '<?php echo $core->blog->settings->blog_private_msg; ?>'; |
---|
80 | } |
---|
81 | |
---|
82 | public static function PrivateReqPage($attr) |
---|
83 | { |
---|
84 | $url = isset($_SERVER['REQUEST_URI']) ? html::escapeHTML($_SERVER['REQUEST_URI']) : $core->blog->url; |
---|
85 | return '<?php echo $url; ?>'; |
---|
86 | } |
---|
87 | |
---|
88 | public static function IfPrivateMsgError($attr,$content) |
---|
89 | { |
---|
90 | return |
---|
91 | '<?php if ($_ctx->blogpass_error !== null) : ?>'. |
---|
92 | $content. |
---|
93 | '<?php endif; ?>'; |
---|
94 | } |
---|
95 | |
---|
96 | public static function PrivateMsgError($attr) |
---|
97 | { |
---|
98 | return '<?php if ($_ctx->blogpass_error !== null) { echo $_ctx->blogpass_error; } ?>'; |
---|
99 | } |
---|
100 | |
---|
101 | public static function privateWidgets(&$w) |
---|
102 | { |
---|
103 | global $core; |
---|
104 | if ($w->homeonly && $core->url->type != 'default') { |
---|
105 | return; |
---|
106 | } |
---|
107 | $res = '<div class="blogout">'. |
---|
108 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
109 | '<form action="'.$core->blog->url.'logout" method="post">'. |
---|
110 | '<p class="buttons">'. |
---|
111 | '<input type="hidden" name="blogout" id="blogout" value="">'. |
---|
112 | '<input type="submit" value="'.__('Disconnect').'" class="logout"></p>'. |
---|
113 | '</form></div>'; |
---|
114 | return $res; |
---|
115 | } |
---|
116 | } |
---|
117 | ?> |
---|