Dotclear

source: plugins/private/_public.php @ 694

Revision 694, 5.1 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\***************************************************************/
16if (!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
23$core->tpl->addValue('PrivateMsgError',array('tplPrivate','PrivateMsgError'));
24
25if ($core->blog->settings->private_flag)
26{
27     $core->addBehavior('publicBeforeDocument',array('urlPrivate','privacy'));
28}
29
30class urlPrivate extends dcUrlHandlers
31{
32     public static function privateFeed($args)
33     {
34          self::feed($args);
35     }
36
37     public static function callbackbidon($args)
38     {
39          return;
40     }
41
42     public static function privacy($args)
43     {
44          global $core,$_ctx;
45
46          $urlp = new urlHandler();
47          $urlp->mode = $core->url->mode;
48          $urlp->registerDefault(array('urlPrivate','callbackbidon'));
49
50          $path = str_replace(http::getHost(),'',$core->blog->url);
51          if ($core->blog->settings->url_scan == 'query_string')
52          {
53               $path = str_replace(basename($core->blog->url),'',$path);
54          }
55          if (!isset($session))
56          {
57               $session = new sessionDB(
58                       $core->con,
59                       $core->prefix.'session',
60                       'dc_privateblog',
61                       $path
62               );
63               $session->start();
64          }
65
66          foreach ($core->url->getTypes() as $k=>$v)
67          {
68               $urlp->register($k,$v['url'],$v['representation'],array('urlPrivate','callbackbidon'));
69          }
70
71          $urlp->getDocument();
72          $type = $urlp->type;
73          unset($urlp);
74
75          if ($type == 'feed' || $type == 'spamfeed' || $type == 'hamfeed' || $type == 'trackback') 
76          {
77               return;
78          }
79
80          else
81          {
82               if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "")
83               {
84                    if (!empty($_POST['private_pass'])) 
85                    {
86                         if (md5($_POST['private_pass']) == $core->blog->settings->blog_private_pwd)
87                              {
88                                   $_SESSION['sess_blog_private'] = md5($_POST['private_pass']);
89                                   return;
90                              }
91                         $_ctx->blogpass_error = __('Wrong password');
92                    }
93                    $session->destroy();
94                    $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
95                    self::serveDocument('private.html','text/html',false);
96                    exit;
97               }
98               elseif ($_SESSION['sess_blog_private'] != $core->blog->settings->blog_private_pwd)
99               {
100                    $session->destroy();
101                    $_ctx->blogpass_error = __('Wrong password');
102                    $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
103                    self::serveDocument('private.html','text/html',false);
104                    exit;
105               }
106               elseif (isset($_POST['blogout']))
107               {
108                    $session->destroy();
109                    $_ctx->blogpass_error = __('Disconnected');
110                    $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
111                    self::serveDocument('private.html','text/html',false);
112                    exit;
113               }
114               return;
115          }
116     }
117}
118
119class tplPrivate
120{
121     public static function PrivatePageTitle($attr)
122     {
123          $f = $GLOBALS['core']->tpl->getFilters($attr);
124          return '<?php echo '.sprintf($f,'$core->blog->settings->blog_private_title').'; ?>';
125     }
126
127     public static function PrivateMsg($attr)
128     {
129          return '<?php echo $core->blog->settings->blog_private_msg; ?>';
130     }
131
132     public static function PrivateReqPage($attr)
133     {
134          return '<?php echo(isset($_SERVER[\'REQUEST_URI\']) ? html::escapeHTML($_SERVER[\'REQUEST_URI\']) : $core->blog->url); ?>';
135     }
136
137     public static function IfPrivateMsgError($attr,$content)
138     {
139          return
140          '<?php if ($_ctx->blogpass_error !== null) : ?>'.
141          $content.
142          '<?php endif; ?>';
143     }
144
145     public static function PrivateMsgError($attr)
146     {
147          return '<?php if ($_ctx->blogpass_error !== null) { echo $_ctx->blogpass_error; } ?>';
148     }
149
150     public static function privateWidgets(&$w) 
151     {
152          global $core;
153          if ($w->homeonly && $core->url->type != 'default') {
154               return;
155          }
156
157          if ($core->blog->settings->private_flag)
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          else
169          {
170               return;       
171          }
172     }
173}
174?>
Note: See TracBrowser for help on using the repository browser.

Sites map