Dotclear

source: plugins/private/index.php @ 570

Revision 570, 4.9 KB checked in by Osku, 15 years ago (diff)

New plugin - Private Mode : protect your blog with a password

Line 
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
17// Setting default parameters if missing configuration
18if (is_null($core->blog->settings->private_flag)) {
19     try {
20               $core->blog->settings->setNameSpace('private');
21
22               // Maintenance  is not active by default
23               $core->blog->settings->put('private_flag',false,'boolean');
24               $core->blog->triggerBlog();
25               http::redirect(http::getSelfURI());
26          }
27     catch (Exception $e) {
28          $core->error->add($e->getMessage());
29     }
30}
31
32// Getting current parameters
33$private_flag       = (boolean)$core->blog->settings->private_flag;
34$blog_private_title = $core->blog->settings->blog_private_title;
35$blog_private_msg   = $core->blog->settings->blog_private_msg;
36
37if ($blog_private_title === null) {
38     $blog_private_title = __('Private blog');
39}
40
41if ($blog_private_msg === null) {
42     $blog_private_msg = __('<p class="message">You need the password to view this blog.</p>');
43}
44
45if (!empty($_POST['saveconfig']))
46{
47     try
48     {
49          $private_flag = (empty($_POST['private_flag']))?false:true;
50          $blog_private_title = $_POST['blog_private_title'];
51          $blog_private_msg = $_POST['blog_private_msg'];
52          $blog_private_pwd = md5($_POST['blog_private_pwd']);
53
54          if (empty($_POST['blog_private_title'])) {
55               throw new Exception(__('No page title.'));
56          }
57
58          if (empty($_POST['blog_private_msg'])) {
59               throw new Exception(__('No private message.'));
60          }
61
62          $core->blog->settings->setNamespace('private');
63          $core->blog->settings->put('private_flag',$private_flag,'boolean');
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
76          $msg = __('Configuration successfully updated.');
77     }
78
79     catch (Exception $e)
80     {
81          $core->error->add($e->getMessage());
82     }
83
84     if (is_null($core->blog->settings->blog_private_pwd)) {
85          $err = __('No password set.');
86     }
87}
88?>
89<html>
90<head>
91     <title><?php echo __('Private mode'); ?></title>
92</head>
93<body>
94<h2 style="padding:8px 0 8px 34px;background:url(index.php?pf=private/icon_32.png) no-repeat;">
95<?php echo html::escapeHTML($core->blog->name); ?> &rsaquo; <?php echo __('Private mode'); ?></h2>
96
97<?php if (!empty($msg)) echo '<p class="message">'.$msg.'</p>'; ?>
98
99<?php if (!empty($err)) echo '<p class="error">'.$err.'</p>'; ?>
100
101<div id="offline_options">
102     <form method="post" action="plugin.php">
103          <fieldset>
104               <legend><?php echo __('Plugin activation'); ?></legend>
105                    <p class="field">
106                         <?php echo form::checkbox('private_flag', 1, $private_flag); ?>
107                         <label class=" classic" for="private_flag"> <?php echo __('Enable Private mode');?></label>
108                    </p>
109                    <p><label class="required" title="__('Required field')">
110                         <?php echo __('New password:'); ?>
111                         <?php echo form::password('blog_private_pwd',20,255); ?>
112                    </label></p>
113                    <p><label class="required" title="__('Required field')">
114                         <?php echo __('Confirm password:'); ?>
115                         <?php echo form::password('blog_private_pwd_c',20,255); ?>
116                    </label></p>
117          </fieldset>
118          <fieldset>
119               <legend><?php echo __('Presentation options'); ?></legend>
120                    <p><label class="required" title="__('Required field')">
121                         <?php echo __('Private page title:');?>
122                         <?php echo form::field('blog_private_title',30,256,html::escapeHTML($blog_private_title)); ?>
123                    </label></p>
124                    <p class="area"><label class="required" title="__('Required field')">
125                         <?php echo __('Private message:');?>
126                         <?php echo form::textarea('blog_private_msg',30,2,html::escapeHTML($blog_private_msg)); ?>
127                    </label></p>
128          </fieldset>
129
130          <p><input type="hidden" name="p" value="private" />
131          <?php echo $core->formNonce(); ?>
132          <input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
133     </form>
134</div>
135</body>
136</html>
Note: See TracBrowser for help on using the repository browser.

Sites map