Dotclear

source: plugins/private/index.php @ 694

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

Private mode plugin 0.5 : new way of manage session, fixe [9] and [14]

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 (is_null($core->blog->settings->blog_private_pwd))
46{
47     $err = __('No password set.');
48}
49
50if (!empty($_POST['saveconfig']))
51{
52     try
53     {
54          $private_flag = (empty($_POST['private_flag']))?false:true;
55          $blog_private_title = $_POST['blog_private_title'];
56          $blog_private_msg = $_POST['blog_private_msg'];
57          $blog_private_pwd = md5($_POST['blog_private_pwd']);
58
59          if (empty($_POST['blog_private_title'])) {
60               throw new Exception(__('No page title.'));
61          }
62
63          if (empty($_POST['blog_private_msg'])) {
64               throw new Exception(__('No private message.'));
65          }
66
67          $core->blog->settings->setNamespace('private');
68          $core->blog->settings->put('private_flag',$private_flag,'boolean');
69          $core->blog->settings->put('blog_private_title',$blog_private_title,'string','Private page title');
70          $core->blog->settings->put('blog_private_msg',$blog_private_msg,'string','Private message');
71
72          if (!empty($_POST['blog_private_pwd'])) {
73               if ($_POST['blog_private_pwd'] != $_POST['blog_private_pwd_c']) {
74                    throw new Exception(__("Passwords don't match"));
75               }
76               $core->blog->settings->put('blog_private_pwd',$blog_private_pwd,'string','Private blog password');
77          }
78
79          $core->blog->triggerBlog();
80
81          $msg = __('Configuration successfully updated.');
82     }
83
84     catch (Exception $e)
85     {
86          $core->error->add($e->getMessage());
87     }
88}
89?>
90<html>
91<head>
92     <title><?php echo __('Private mode'); ?></title>
93</head>
94<body>
95<h2 style="padding:8px 0 8px 34px;background:url(index.php?pf=private/icon_32.png) no-repeat;">
96<?php echo html::escapeHTML($core->blog->name); ?> &rsaquo; <?php echo __('Private mode'); ?></h2>
97
98<?php if (!empty($msg)) echo '<p class="message">'.$msg.'</p>'; ?>
99
100<?php if (!empty($err)) echo '<p class="error">'.$err.'</p>'; ?>
101
102<div id="offline_options">
103     <form method="post" action="plugin.php">
104          <fieldset>
105               <legend><?php echo __('Plugin activation'); ?></legend>
106                    <p class="field">
107                         <?php echo form::checkbox('private_flag', 1, $private_flag); ?>
108                         <label class=" classic" for="private_flag"> <?php echo __('Enable Private mode');?></label>
109                    </p>
110                    <p><label class="required" title="__('Required field')">
111                         <?php echo __('New password:'); ?>
112                         <?php echo form::password('blog_private_pwd',20,255); ?>
113                    </label></p>
114                    <p><label class="required" title="__('Required field')">
115                         <?php echo __('Confirm password:'); ?>
116                         <?php echo form::password('blog_private_pwd_c',20,255); ?>
117                    </label></p>
118          </fieldset>
119          <fieldset>
120               <legend><?php echo __('Presentation options'); ?></legend>
121                    <p><label class="required" title="__('Required field')">
122                         <?php echo __('Private page title:');?>
123                         <?php echo form::field('blog_private_title',30,256,html::escapeHTML($blog_private_title)); ?>
124                    </label></p>
125                    <p class="area"><label class="required" title="__('Required field')">
126                         <?php echo __('Private message:');?>
127                         <?php echo form::textarea('blog_private_msg',30,2,html::escapeHTML($blog_private_msg)); ?>
128                    </label></p>
129          </fieldset>
130
131          <p><input type="hidden" name="p" value="private" />
132          <?php echo $core->formNonce(); ?>
133          <input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
134     </form>
135</div>
136</body>
137</html>
Note: See TracBrowser for help on using the repository browser.

Sites map