Dotclear

source: plugins/private/_public.php @ 2378

Revision 2378, 6.2 KB checked in by Osku, 13 years ago (diff)

private : version 1.3 - ready for Dotaddict

  • PHP 5.3 compliant
  • For Dotclear 2.2 & 2.16
  • Title and message are now optionnal
  • New icon menu
  • minor improvements
  • Add a LICENSE file
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-2010 Osku and contributors
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13
14if (!defined('DC_RC_PATH')) { return; }
15
16$core->tpl->addValue('PrivatePageTitle',array('tplPrivate','PrivatePageTitle'));
17$core->tpl->addValue('PrivateMsg',array('tplPrivate','PrivateMsg'));
18$core->tpl->addValue('PrivateReqPage',array('tplPrivate','PrivateReqPage'));
19$core->tpl->addBlock('IfPrivateMsgError',array('tplPrivate','IfPrivateMsgError'));
20$core->tpl->addValue('PrivatePassRemember',array('tplPrivate','PrivatePassRemember'));
21$core->tpl->addValue('PrivateMsgError',array('tplPrivate','PrivateMsgError'));
22
23$s = privateSettings($core);
24         
25if ($s->private_flag)
26{
27     $core->addBehavior('publicBeforeDocument',array('urlPrivate','privateHandler'));
28}
29
30class urlPrivate extends dcUrlHandlers
31{
32     public static function privateFeed($args)
33     {
34          self::feed($args);
35     }
36     
37     public static function publicFeed($args)
38     {
39          global $core,$_ctx;
40         
41          $type = null;
42          $params = array();
43          $mime = 'application/xml';
44         
45          if (preg_match('#^rss2/xslt$#',$args,$m))
46          {
47               # RSS XSLT stylesheet
48               self::serveDocument('rss2.xsl','text/xml');
49          }
50          elseif (preg_match('#^(atom|rss2)/comments/([0-9]+)$#',$args,$m))
51          {
52               # Post comments feed
53               $type = $m[1];
54          }
55          elseif (preg_match('#^(?:category/(.+)/)?(atom|rss2)(/comments)?$#',$args,$m))
56          {
57               # All posts or comments feed
58               $type = $m[2];
59          }
60         
61          $tpl =  $type == '' ? 'atom' : $type;
62          $tpl .= '-pv.xml';
63         
64          if ($type == 'atom') {
65               $mime = 'application/atom+xml';
66          }
67         
68          header('X-Robots-Tag: '.context::robotsPolicy($core->blog->settings->robots_policy,''));
69          $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
70          self::serveDocument($tpl,$mime);
71         
72          return;
73     }
74
75     public static function callbackfoo($args)
76     {
77          return;
78     }
79
80     public static function privateHandler($args)
81     {
82          global $core,$_ctx;
83
84          $urlp = new urlHandler();
85          $urlp->mode = $core->url->mode;
86          $urlp->registerDefault(array('urlPrivate','callbackfoo'));
87          $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
88          $s = privateSettings($core);
89          $password = $s->blog_private_pwd;
90
91          if (!isset($session))
92          {
93               $session = new sessionDB(
94                    $core->con,
95                    $core->prefix.'session',
96                    'dc_privateblog_sess_'.$core->blog->id,
97                    '/'
98               );
99               $session->start();
100          }
101
102          foreach ($core->url->getTypes() as $k=>$v)
103          {
104               $urlp->register($k,$v['url'],$v['representation'],array('urlPrivate','callbackfoo'));
105          }
106
107          $urlp->getDocument();
108          $type = $urlp->type;
109          unset($urlp);
110
111          if ($type == 'feed' || $type == 'pubfeed' || $type == 'spamfeed' || $type == 'hamfeed' || $type == 'trackback') 
112          {
113               return;
114          }
115          else
116          {
117               // Add cookie test (automatic login)
118               $cookiepass = "dc_privateblog_cookie_".$core->blog->id;
119               
120               if (!empty($_COOKIE[$cookiepass])) 
121               {
122                    $cookiepassvalue = (($_COOKIE[$cookiepass]) == $password);
123               } 
124               else 
125               {
126                    $cookiepassvalue = false;
127               }
128               
129               if (!isset($_SESSION['sess_blog_private']) || $_SESSION['sess_blog_private'] == "")
130               {
131                    if ($cookiepassvalue != false) 
132                    {
133                         $_SESSION['sess_blog_private'] = $_COOKIE[$cookiepass];
134                         return;
135                    }
136                    if (!empty($_POST['private_pass'])) 
137                    {
138                         if (md5($_POST['private_pass']) == $password)
139                         {
140                              $_SESSION['sess_blog_private'] = md5($_POST['private_pass']);
141                             
142                              if (!empty($_POST['pass_remember'])) 
143                              {
144                                   setcookie($cookiepass,md5($_POST['private_pass']),time() + 31536000,'/');
145                              }
146                              return;
147                         }
148                         $_ctx->blogpass_error = __('Wrong password');
149                    }
150                    $session->destroy();
151                    self::serveDocument('private.html','text/html',false);
152                    exit;
153               }
154               elseif ($_SESSION['sess_blog_private'] != $password)
155               {
156                    $session->destroy();
157                    $_ctx->blogpass_error = __('Wrong password');
158                    self::serveDocument('private.html','text/html',false);
159                    exit;
160               }
161               elseif (isset($_POST['blogout']))
162               {
163                    $session->destroy();
164                    setcookie($cookiepass,'ciao',time() - 86400,'/');
165                    $_ctx->blogpass_error = __('Disconnected');
166                    self::serveDocument('private.html','text/html',false);
167                    exit;
168               }
169               return;
170          }
171     }
172}
173
174class tplPrivate
175{
176     public static function PrivatePageTitle($attr)
177     {
178          global $core;
179          $s = privateSettings($core);
180          $f = $core->tpl->getFilters($attr);
181          return '<?php echo '.sprintf($f,'$s->private_page_title').'; ?>';
182     }
183
184     public static function PrivateMsg($attr)
185     {
186          global $core;
187          $s = privateSettings($core);
188          $f = $core->tpl->getFilters($attr);
189          return '<?php echo '.sprintf($f,'$s->private_page_message').'; ?>';
190     }
191
192     public static function PrivateReqPage($attr)
193     {
194          return 
195          '<?php echo(isset($_SERVER[\'REQUEST_URI\'])
196          ? html::escapeHTML($_SERVER[\'REQUEST_URI\'])
197          : $core->blog->url); ?>' ;
198     }
199
200     public static function IfPrivateMsgError($attr,$content)
201     {
202          return
203          '<?php if ($_ctx->blogpass_error !== null) : ?>'.
204          $content.
205          '<?php endif; ?>';
206     }
207
208     public static function PrivateMsgError($attr)
209     {
210          return 
211          '<?php if ($_ctx->blogpass_error !== null)
212          { echo $_ctx->blogpass_error; } ?>';
213     }
214
215     public static function PrivatePassRemember($attr)
216     {
217          global $core;
218          $s = privateSettings($core);
219          if ($s->private_conauto_flag)
220          {
221               $res = '<p><label class="classic">'.
222                    form::checkbox(array('pass_remember'),1).' '.
223                    __('Enable automatic connection').'</label></p>';
224               return $res;
225          }
226          else
227          {
228               return;
229          }
230     }
231}
232
233class widgetsPrivage
234{
235     public static function widgetLogout($w) 
236     {
237          global $core;
238          $s = privateSettings($core);
239
240          if ($w->homeonly && $core->url->type != 'default') {
241               return;
242          }
243
244          if ($s->private_flag)
245          {
246               $res = '<div class="blogout">'.
247                    ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
248                    ($w->text ? $w->text : '').
249                    '<form action="'.$core->blog->url.'" method="post">'.
250                    '<p class="buttons">'.
251                    '<input type="hidden" name="blogout" id="blogout" value="" />'.
252                    '<input type="submit" value="'.html::escapeHTML($w->label).'" class="logout" /></p>'.
253                    '</form></div>';
254               return $res;
255          }
256          else
257          {
258               return;
259          }
260     }
261}
262?>
Note: See TracBrowser for help on using the repository browser.

Sites map