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

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
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'];
32
33               $core->blog->withoutPassword(false);
34
35               $params = new ArrayObject(array(
36                    'post_type' => 'page',
37                    'post_url' => $args));
38
39               $core->callBehavior('publicPagesBeforeGetPosts',$params,$args);
40
41               $_ctx->posts = $core->blog->getPosts($params);
42
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;
51
52               $core->blog->withoutPassword(true);
53
54
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;
64
65                    # Password protected entry
66                    if ($post_password != '' && !$_ctx->preview)
67                    {
68                         # Get passwords cookie
69                         if (isset($_COOKIE['dc_passwd'])) {
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                              }
76                         } else {
77                              $pwd_cookie = array();
78                         }
79
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;
85                              setcookie('dc_passwd',json_encode($pwd_cookie),0,'/');
86                         }
87                         else
88                         {
89                              self::serveDocument('password-form.html','text/html',false);
90                              return;
91                         }
92                    }
93
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();
98
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                         }
110
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']);
116
117                         if ($content != '')
118                         {
119                              # --BEHAVIOR-- publicBeforeCommentTransform
120                              $buffer = $core->callBehavior('publicBeforeCommentTransform',$content);
121                              if ($buffer != '') {
122                                   $content = $buffer;
123                              } else {
124                                   if ($core->blog->settings->system->wiki_comments) {
125                                        $core->initWikiComment();
126                                   } else {
127                                        $core->initWikiSimpleComment();
128                                   }
129                                   $content = $core->wikiTransform($content);
130                              }
131                              $content = $core->HTMLfilter($content);
132                         }
133
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;
139
140                         if ($preview)
141                         {
142                              # --BEHAVIOR-- publicBeforeCommentPreview
143                              $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview);
144
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();
158
159                              $redir = $_ctx->posts->getURL();
160                              $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?';
161
162                              try
163                              {
164                                   if (!text::isEmail($cur->comment_email)) {
165                                        throw new Exception(__('You must provide a valid email address.'));
166                                   }
167
168                                   # --BEHAVIOR-- publicBeforeCommentCreate
169                                   $core->callBehavior('publicBeforeCommentCreate',$cur);
170                                   if ($cur->post_id) {
171                                        $comment_id = $core->blog->addComment($cur);
172
173                                        # --BEHAVIOR-- publicAfterCommentCreate
174                                        $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id);
175                                   }
176
177                                   if ($cur->comment_status == 1) {
178                                        $redir_arg = 'pub=1';
179                                   } else {
180                                        $redir_arg = 'pub=0';
181                                   }
182
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                    }
192
193                    # The entry
194                    if ($_ctx->posts->trackbacksActive()) {
195                         header('X-Pingback: '.$core->blog->url.$core->url->getURLFor("xmlrpc",$core->blog->id));
196                    }
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 {
202                         $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET);
203                    }
204                    self::serveDocument('page.html');
205               }
206          }
207     }
208
209     public static function pagespreview($args)
210     {
211          $core = $GLOBALS['core'];
212          $_ctx = $GLOBALS['_ctx'];
213
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;
242
243          if (($w->homeonly == 1 && $core->url->type != 'default') ||
244               ($w->homeonly == 2 && $core->url->type == 'default')) {
245               return;
246          }
247
248          $params['post_type'] = 'page';
249          $params['limit'] = abs((integer) $w->limit);
250          $params['no_content'] = true;
251          $params['post_selected'] = false;
252
253          $sort = $w->sortby;
254          if (!in_array($sort,array('post_title','post_position','post_dt'))) {
255               $sort = 'post_title';
256          }
257
258          $order = $w->orderby;
259          if ($order != 'asc') {
260               $order = 'desc';
261          }
262          $params['order'] = $sort.' '.$order;
263
264          $rs = $core->blog->getPosts($params);
265
266          if ($rs->isEmpty()) {
267               return;
268          }
269
270          $res = ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').'<ul>';
271
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          }
280
281          $res .= '</ul>';
282
283          return $w->renderDiv($w->content_only,'pages '.$w->class,'',$res);
284     }
285}
Note: See TracBrowser for help on using the repository browser.

Sites map