Dotclear

source: plugins/private/index.php @ 1768

Revision 1768, 5.1 KB checked in by Osku, 14 years ago (diff)

Private mode 1.1RC1 :

  • should fixe some tickets bugs (closes #140, #296)
Line 
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// Setting default parameters if missing configuration
14if (is_null($core->blog->settings->private_flag)) {
15     try {
16               $core->blog->settings->setNameSpace('private');
17
18               // Private mode is not active by default
19               $core->blog->settings->put('private_flag',false,'boolean');
20               $core->blog->settings->put('private_conauto',false,'boolean');
21               $core->blog->triggerBlog();
22               http::redirect(http::getSelfURI());
23          }
24     catch (Exception $e) {
25          $core->error->add($e->getMessage());
26     }
27}
28
29// Getting current parameters
30$private_flag = (boolean)$core->blog->settings->private_flag;
31$private_conauto = (boolean)$core->blog->settings->private_conauto;
32$blog_private_title = $core->blog->settings->blog_private_title;
33$blog_private_msg = $core->blog->settings->blog_private_msg;
34
35if ($blog_private_title === null) {
36     $blog_private_title = __('Private blog');
37}
38
39if ($blog_private_msg === null) {
40     $blog_private_msg = __('<p class="message">You need the password to view this blog.</p>');
41}
42
43if (!empty($_POST['saveconfig']))
44{
45     try
46     {
47          $private_flag = (empty($_POST['private_flag']))?false:true;
48          $private_conauto = (empty($_POST['private_conauto']))?false:true;
49          $blog_private_title = $_POST['blog_private_title'];
50          $blog_private_msg = $_POST['blog_private_msg'];
51          $blog_private_pwd = md5($_POST['blog_private_pwd']);
52
53          if (empty($_POST['blog_private_title'])) {
54               throw new Exception(__('No page title.'));
55          }
56
57          if (empty($_POST['blog_private_msg'])) {
58               throw new Exception(__('No private message.'));
59          }
60
61          $core->blog->settings->setNamespace('private');
62          $core->blog->settings->put('private_flag',$private_flag,'boolean','Protect your blog with a password');
63          $core->blog->settings->put('private_conauto',$private_conauto,'boolean','Allow automatic connection');
64          $core->blog->settings->put('blog_private_title',$blog_private_title,'string','Private page title');
65          $core->blog->settings->put('blog_private_msg',$blog_private_msg,'string','Private message');
66
67          if (!empty($_POST['blog_private_pwd'])) {
68               if ($_POST['blog_private_pwd'] != $_POST['blog_private_pwd_c']) {
69                    throw new Exception(__("Passwords don't match"));
70               }
71               $core->blog->settings->put('blog_private_pwd',$blog_private_pwd,'string','Private blog password');
72          }
73
74          $core->blog->triggerBlog();
75          http::redirect($p_url.'&config=1');
76     }
77
78     catch (Exception $e)
79     {
80          $core->error->add($e->getMessage());
81     }
82}
83if ($core->blog->settings->blog_private_pwd === null)
84{
85     $err = __('No password set.');
86}
87?>
88<html>
89<head>
90     <title><?php echo __('Private mode'); ?></title>
91</head>
92<body>
93<?php 
94
95if (isset($_GET['config'])) {
96     echo '<p class="message">'.__('Configuration successfully updated.').'</p>';
97}
98
99if (!empty($err)) echo '<p class="error">'.$err.'</p>'; 
100
101echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Private mode').'</h2>';
102
103echo '<div id="private_options">'.
104     '<form method="post" action="'.$p_url.'">'.
105          '<fieldset>'.
106               '<legend>'. __('Plugin activation').'</legend>'.
107                    '<div class="two-cols">'.
108                    '<div class="col">'.
109                    '<p class="field">'.
110                         form::checkbox('private_flag', 1, $private_flag).
111                         '<label class=" classic" for="private_flag">'.__('Enable Private mode').'</label>'.
112                    '</p>'.
113                    '<p><label class="required" title="'.__('Required field').'">'.
114                         __('New password:').
115                         form::password('blog_private_pwd',30,255).
116                    '</label></p>'.
117                    '<p><label class="required" title="'.__('Required field').'">'.
118                         __('Confirm password:').
119                         form::password('blog_private_pwd_c',30,255).
120                    '</label></p>'.
121                    '</div>'.
122                    '<div class="col">'.
123                    '<p>'.
124                         form::checkbox('private_conauto', 1, $private_conauto).
125                         '<label class=" classic" for="private_conauto">'. __('Propose automatic connection to visitors').'</label>'.
126                    '</p>'.
127                    '<p class="form-note">'.
128                    __('With this option, the password could be stored in a cookie.').
129                    __('But it still remains a choice for the visitor.').
130                    '</p>'.
131                    '<p>'.sprintf(__('Don\'t forget to add a <a href="%s">widget</a> allowing disconnection from the blog.'),'plugin.php?p=widgets').'</p>'.
132                    '</div>'.
133                    '</div>'.
134          '</fieldset>'.
135          '<fieldset>'.
136               '<legend>'.__('Presentation options').'</legend>'.
137                    '<p class="col"><label class="required" title="'.__('Required field').'">'.
138                         __('Private page title:').
139                         form::field('blog_private_title',20,255,html::escapeHTML($blog_private_title),'maximal').
140                    '.</label></p>'.
141                    '<p class="area"><label class="required" title="'.__('Required field').'">'.
142                         __('Private message:').
143                         form::textarea('blog_private_msg',30,4,html::escapeHTML($blog_private_msg)).
144                    '</label></p>'.
145          '</fieldset>'.
146
147          '<p>'.form::hidden(array('p'),'private').
148          $core->formNonce().
149          '<input type="submit" name="saveconfig" value="'.__('Save configuration').'" /></p>'.
150     '</form>'.
151'</div>';
152?>
153</body>
154</html>
Note: See TracBrowser for help on using the repository browser.

Sites map