Dotclear

source: plugins/pages/_public.php @ 2667:ef63c4e390be

Revision 2667:ef63c4e390be, 7.6 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Add widget class on every widget, fixes #1901

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14# Localized string we find in template
15__('Published on');
16__('This page\'s comments feed');
17
18require dirname(__FILE__).'/_widgets.php';
19
20class urlPages extends dcUrlHandlers
21{
22     public static function pages($args)
23     {
24          if ($args == '') {
25               # No page was specified.
26               self::p404();
27          }
28          else
29          {
30               $_ctx =& $GLOBALS['_ctx'];
31               $core =& $GLOBALS['core'];
[2566]32
[0]33               $core->blog->withoutPassword(false);
[2566]34
[306]35               $params = new ArrayObject(array(
36                    'post_type' => 'page',
37                    'post_url' => $args));
[2566]38
[306]39               $core->callBehavior('publicPagesBeforeGetPosts',$params,$args);
[2566]40
[0]41               $_ctx->posts = $core->blog->getPosts($params);
[2566]42
[0]43               $_ctx->comment_preview = new ArrayObject();
44               $_ctx->comment_preview['content'] = '';
45               $_ctx->comment_preview['rawcontent'] = '';
46               $_ctx->comment_preview['name'] = '';
47               $_ctx->comment_preview['mail'] = '';
48               $_ctx->comment_preview['site'] = '';
49               $_ctx->comment_preview['preview'] = false;
50               $_ctx->comment_preview['remember'] = false;
[2566]51
[0]52               $core->blog->withoutPassword(true);
[2566]53
54
[0]55               if ($_ctx->posts->isEmpty())
56               {
57                    # The specified page does not exist.
58                    self::p404();
59               }
60               else
61               {
62                    $post_id = $_ctx->posts->post_id;
63                    $post_password = $_ctx->posts->post_password;
[2566]64
[0]65                    # Password protected entry
66                    if ($post_password != '' && !$_ctx->preview)
67                    {
68                         # Get passwords cookie
69                         if (isset($_COOKIE['dc_passwd'])) {
[2634]70                              $pwd_cookie = json_decode($_COOKIE['dc_passwd']);
71                              if ($pwd_cookie === NULL) {
72                                   $pwd_cookie = array();
73                              } else {
74                                   $pwd_cookie = (array) $pwd_cookie;
75                              }
[0]76                         } else {
77                              $pwd_cookie = array();
78                         }
[2566]79
[0]80                         # Check for match
81                         if ((!empty($_POST['password']) && $_POST['password'] == $post_password)
82                         || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password))
83                         {
84                              $pwd_cookie[$post_id] = $post_password;
[2634]85                              setcookie('dc_passwd',json_encode($pwd_cookie),0,'/');
[0]86                         }
87                         else
88                         {
89                              self::serveDocument('password-form.html','text/html',false);
90                              return;
91                         }
92                    }
[2566]93
[0]94                    $post_comment =
95                         isset($_POST['c_name']) && isset($_POST['c_mail']) &&
96                         isset($_POST['c_site']) && isset($_POST['c_content']) &&
97                         $_ctx->posts->commentsActive();
[2566]98
[0]99                    # Posting a comment
100                    if ($post_comment)
101                    {
102                         # Spam trap
103                         if (!empty($_POST['f_mail'])) {
104                              http::head(412,'Precondition Failed');
105                              header('Content-Type: text/plain');
106                              echo "So Long, and Thanks For All the Fish";
107                              # Exits immediately the application to preserve the server.
108                              exit;
109                         }
[2566]110
[0]111                         $name = $_POST['c_name'];
112                         $mail = $_POST['c_mail'];
113                         $site = $_POST['c_site'];
114                         $content = $_POST['c_content'];
115                         $preview = !empty($_POST['preview']);
[2566]116
[0]117                         if ($content != '')
118                         {
[2586]119                              # --BEHAVIOR-- publicBeforeCommentTransform
120                              $buffer = $core->callBehavior('publicBeforeCommentTransform',$content);
121                              if ($buffer != '') {
122                                   $content = $buffer;
[0]123                              } else {
[2586]124                                   if ($core->blog->settings->system->wiki_comments) {
125                                        $core->initWikiComment();
126                                   } else {
127                                        $core->initWikiSimpleComment();
128                                   }
129                                   $content = $core->wikiTransform($content);
[0]130                              }
131                              $content = $core->HTMLfilter($content);
132                         }
[2566]133
[0]134                         $_ctx->comment_preview['content'] = $content;
135                         $_ctx->comment_preview['rawcontent'] = $_POST['c_content'];
136                         $_ctx->comment_preview['name'] = $name;
137                         $_ctx->comment_preview['mail'] = $mail;
138                         $_ctx->comment_preview['site'] = $site;
[2566]139
[0]140                         if ($preview)
141                         {
142                              # --BEHAVIOR-- publicBeforeCommentPreview
143                              $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview);
[2566]144
[0]145                              $_ctx->comment_preview['preview'] = true;
146                         }
147                         else
148                         {
149                              # Post the comment
150                              $cur = $core->con->openCursor($core->prefix.'comment');
151                              $cur->comment_author = $name;
152                              $cur->comment_site = html::clean($site);
153                              $cur->comment_email = html::clean($mail);
154                              $cur->comment_content = $content;
155                              $cur->post_id = $_ctx->posts->post_id;
156                              $cur->comment_status = $core->blog->settings->system->comments_pub ? 1 : -1;
157                              $cur->comment_ip = http::realIP();
[2566]158
[0]159                              $redir = $_ctx->posts->getURL();
[727]160                              $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?';
[2566]161
[0]162                              try
163                              {
164                                   if (!text::isEmail($cur->comment_email)) {
165                                        throw new Exception(__('You must provide a valid email address.'));
166                                   }
[2566]167
[0]168                                   # --BEHAVIOR-- publicBeforeCommentCreate
169                                   $core->callBehavior('publicBeforeCommentCreate',$cur);
[2566]170                                   if ($cur->post_id) {
[0]171                                        $comment_id = $core->blog->addComment($cur);
[2566]172
[0]173                                        # --BEHAVIOR-- publicAfterCommentCreate
174                                        $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id);
175                                   }
[2566]176
[0]177                                   if ($cur->comment_status == 1) {
178                                        $redir_arg = 'pub=1';
179                                   } else {
180                                        $redir_arg = 'pub=0';
181                                   }
[2566]182
[0]183                                   header('Location: '.$redir.$redir_arg);
184                              }
185                              catch (Exception $e)
186                              {
187                                   $_ctx->form_error = $e->getMessage();
188                                   $_ctx->form_error;
189                              }
190                         }
191                    }
[2566]192
[0]193                    # The entry
[1674]194                    if ($_ctx->posts->trackbacksActive()) {
195                         header('X-Pingback: '.$core->blog->url.$core->url->getURLFor("xmlrpc",$core->blog->id));
196                    }
[2603]197
198                    $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme,'tplset');
199                    if (!empty($tplset) && is_dir(dirname(__FILE__).'/default-templates/'.$tplset)) {
200                         $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.$tplset);
201                    } else {
[2607]202                         $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET);
[2603]203                    }
[0]204                    self::serveDocument('page.html');
205               }
206          }
207     }
[2566]208
[0]209     public static function pagespreview($args)
210     {
211          $core = $GLOBALS['core'];
212          $_ctx = $GLOBALS['_ctx'];
[2566]213
[0]214          if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) {
215               # The specified Preview URL is malformed.
216               self::p404();
217          }
218          else
219          {
220               $user_id = $m[1];
221               $user_key = $m[2];
222               $post_url = $m[3];
223               if (!$core->auth->checkUser($user_id,null,$user_key)) {
224                    # The user has no access to the entry.
225                    self::p404();
226               }
227               else
228               {
229                    $_ctx->preview = true;
230                    self::pages($post_url);
231               }
232          }
233     }
234}
235
236class tplPages
237{
238     # Widget function
239     public static function pagesWidget($w)
240     {
241          global $core, $_ctx;
[2566]242
[945]243          if (($w->homeonly == 1 && $core->url->type != 'default') ||
244               ($w->homeonly == 2 && $core->url->type == 'default')) {
[0]245               return;
246          }
[2566]247
[0]248          $params['post_type'] = 'page';
249          $params['limit'] = abs((integer) $w->limit);
250          $params['no_content'] = true;
[911]251          $params['post_selected'] = false;
[2566]252
[0]253          $sort = $w->sortby;
254          if (!in_array($sort,array('post_title','post_position','post_dt'))) {
255               $sort = 'post_title';
256          }
[2566]257
[0]258          $order = $w->orderby;
259          if ($order != 'asc') {
260               $order = 'desc';
261          }
262          $params['order'] = $sort.' '.$order;
[2566]263
[0]264          $rs = $core->blog->getPosts($params);
[2566]265
[0]266          if ($rs->isEmpty()) {
267               return;
268          }
[2566]269
[2667]270          $res = ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').'<ul>';
[2566]271
[0]272          while ($rs->fetch()) {
273               $class = '';
274               if (($core->url->type == 'pages' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id)) {
275                    $class = ' class="page-current"';
276               }
277               $res .= '<li'.$class.'><a href="'.$rs->getURL().'">'.
278               html::escapeHTML($rs->post_title).'</a></li>';
279          }
[2566]280
[2667]281          $res .= '</ul>';
[2566]282
[2667]283          return $w->renderDiv($w->content_only,'pages '.$w->class,'',$res);
[0]284     }
285}
Note: See TracBrowser for help on using the repository browser.

Sites map