Dotclear

source: plugins/pages/_public.php @ 1063:6636d160f15c

Revision 1063:6636d160f15c, 7.0 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Widget may now be displayed without inclusive div, fixes #1242

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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 = unserialize($_COOKIE['dc_passwd']);
71                         } else {
72                              $pwd_cookie = array();
73                         }
74                         
75                         # Check for match
76                         if ((!empty($_POST['password']) && $_POST['password'] == $post_password)
77                         || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password))
78                         {
79                              $pwd_cookie[$post_id] = $post_password;
80                              setcookie('dc_passwd',serialize($pwd_cookie),0,'/');
81                         }
82                         else
83                         {
84                              self::serveDocument('password-form.html','text/html',false);
85                              return;
86                         }
87                    }
88                   
89                    $post_comment =
90                         isset($_POST['c_name']) && isset($_POST['c_mail']) &&
91                         isset($_POST['c_site']) && isset($_POST['c_content']) &&
92                         $_ctx->posts->commentsActive();
93                   
94                    # Posting a comment
95                    if ($post_comment)
96                    {
97                         # Spam trap
98                         if (!empty($_POST['f_mail'])) {
99                              http::head(412,'Precondition Failed');
100                              header('Content-Type: text/plain');
101                              echo "So Long, and Thanks For All the Fish";
102                              # Exits immediately the application to preserve the server.
103                              exit;
104                         }
105                         
106                         $name = $_POST['c_name'];
107                         $mail = $_POST['c_mail'];
108                         $site = $_POST['c_site'];
109                         $content = $_POST['c_content'];
110                         $preview = !empty($_POST['preview']);
111                         
112                         if ($content != '')
113                         {
114                              if ($core->blog->settings->system->wiki_comments) {
115                                   $core->initWikiComment();
116                              } else {
117                                   $core->initWikiSimpleComment();
118                              }
119                              $content = $core->wikiTransform($content);
120                              $content = $core->HTMLfilter($content);
121                         }
122                         
123                         $_ctx->comment_preview['content'] = $content;
124                         $_ctx->comment_preview['rawcontent'] = $_POST['c_content'];
125                         $_ctx->comment_preview['name'] = $name;
126                         $_ctx->comment_preview['mail'] = $mail;
127                         $_ctx->comment_preview['site'] = $site;
128                         
129                         if ($preview)
130                         {
131                              # --BEHAVIOR-- publicBeforeCommentPreview
132                              $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview);
133                             
134                              $_ctx->comment_preview['preview'] = true;
135                         }
136                         else
137                         {
138                              # Post the comment
139                              $cur = $core->con->openCursor($core->prefix.'comment');
140                              $cur->comment_author = $name;
141                              $cur->comment_site = html::clean($site);
142                              $cur->comment_email = html::clean($mail);
143                              $cur->comment_content = $content;
144                              $cur->post_id = $_ctx->posts->post_id;
145                              $cur->comment_status = $core->blog->settings->system->comments_pub ? 1 : -1;
146                              $cur->comment_ip = http::realIP();
147                             
148                              $redir = $_ctx->posts->getURL();
149                              $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?';
150                             
151                              try
152                              {
153                                   if (!text::isEmail($cur->comment_email)) {
154                                        throw new Exception(__('You must provide a valid email address.'));
155                                   }
156                                   
157                                   # --BEHAVIOR-- publicBeforeCommentCreate
158                                   $core->callBehavior('publicBeforeCommentCreate',$cur);
159                                   if ($cur->post_id) {                         
160                                        $comment_id = $core->blog->addComment($cur);
161                                   
162                                        # --BEHAVIOR-- publicAfterCommentCreate
163                                        $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id);
164                                   }
165                                   
166                                   if ($cur->comment_status == 1) {
167                                        $redir_arg = 'pub=1';
168                                   } else {
169                                        $redir_arg = 'pub=0';
170                                   }
171                                   
172                                   header('Location: '.$redir.$redir_arg);
173                              }
174                              catch (Exception $e)
175                              {
176                                   $_ctx->form_error = $e->getMessage();
177                                   $_ctx->form_error;
178                              }
179                         }
180                    }
181                   
182                    # The entry
183                    $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
184                    self::serveDocument('page.html');
185               }
186          }
187     }
188     
189     public static function pagespreview($args)
190     {
191          $core = $GLOBALS['core'];
192          $_ctx = $GLOBALS['_ctx'];
193         
194          if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) {
195               # The specified Preview URL is malformed.
196               self::p404();
197          }
198          else
199          {
200               $user_id = $m[1];
201               $user_key = $m[2];
202               $post_url = $m[3];
203               if (!$core->auth->checkUser($user_id,null,$user_key)) {
204                    # The user has no access to the entry.
205                    self::p404();
206               }
207               else
208               {
209                    $_ctx->preview = true;
210                    self::pages($post_url);
211               }
212          }
213     }
214}
215
216class tplPages
217{
218     # Widget function
219     public static function pagesWidget($w)
220     {
221          global $core, $_ctx;
222         
223          if (($w->homeonly == 1 && $core->url->type != 'default') ||
224               ($w->homeonly == 2 && $core->url->type == 'default')) {
225               return;
226          }
227         
228          $params['post_type'] = 'page';
229          $params['limit'] = abs((integer) $w->limit);
230          $params['no_content'] = true;
231          $params['post_selected'] = false;
232         
233          $sort = $w->sortby;
234          if (!in_array($sort,array('post_title','post_position','post_dt'))) {
235               $sort = 'post_title';
236          }
237         
238          $order = $w->orderby;
239          if ($order != 'asc') {
240               $order = 'desc';
241          }
242          $params['order'] = $sort.' '.$order;
243         
244          $rs = $core->blog->getPosts($params);
245         
246          if ($rs->isEmpty()) {
247               return;
248          }
249         
250          $res =
251          ($w->content_only ? '' : '<div class="pages'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
252          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
253          '<ul>';
254         
255          while ($rs->fetch()) {
256               $class = '';
257               if (($core->url->type == 'pages' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id)) {
258                    $class = ' class="page-current"';
259               }
260               $res .= '<li'.$class.'><a href="'.$rs->getURL().'">'.
261               html::escapeHTML($rs->post_title).'</a></li>';
262          }
263         
264          $res .= '</ul>'.($w->content_only ? '' : '</div>');
265         
266          return $res;
267     }
268}
269?>
Note: See TracBrowser for help on using the repository browser.

Sites map