Dotclear

source: plugins/pages/_public.php @ 0:54703be25dd6

Revision 0:54703be25dd6, 6.7 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

2.3 branch (trunk) first checkin

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

Sites map