Dotclear

source: plugins/specificsTemplates/_public.php @ 3028

Revision 3028, 6.3 KB checked in by thi3rry, 12 years ago (diff)

suppression adresse mail

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of specificsTemplates, a plugin for Dotclear.
4#
5# Copyright (c) 2009 Thierry Poinot
6#
7# Licensed under the GPL version 2.0 license.
8# A copy of this license is available in LICENSE file or at
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10# -- END LICENSE BLOCK ------------------------------------
11if (!defined('DC_RC_PATH')) { return; } 
12l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/main');
13
14//*/
15
16// réécriture du gestionnaire d'url de catégories et de pages de Dotclear pour aller chercher le fichier category-##.html comme sous spip
17// via http://aiguebrun.adjaya.info/post/20080707/Template-personnalise-par-categorie (mot de passe : pep)
18// via http://forum.dotclear.net/viewtopic.php?id=34414
19
20
21class specificsTemplatesURLHandlers extends dcUrlHandlers // /inc/public/lib.urlhandlers.php
22{
23     public static function category($args) // /inc/public/lib.urlhandlers.php
24     {
25          $_ctx =& $GLOBALS['_ctx'];
26          $core =& $GLOBALS['core'];
27         
28          $n = self::getPageNumber($args);
29         
30          if ($args == '' && !$n) {
31               self::p404();
32          }
33         
34          $params['cat_url'] = $args;
35          $params['post_type'] = 'post';
36         
37          $_ctx->categories = $core->blog->getCategories($params);
38         
39          if ($_ctx->categories->isEmpty()) {
40               self::p404();
41          } else {
42               if ($n) {
43                    $GLOBALS['_page_number'] = $n;
44               }
45
46               $tpl = 'category-'.$_ctx->categories->cat_url.'.html'; //category-##.html où ## est l'url de la catégorie
47               if (!$core->tpl->getFilePath($tpl)) {
48                    $tpl = 'category-'.$_ctx->categories->cat_id.'.html'; //category-##.html où ## est l'id de la catégorie
49                    if (!$core->tpl->getFilePath($tpl)) {
50                         $tpl = 'category.html';
51                    }
52               }
53               self::serveDocument($tpl);
54               exit;
55          }
56     }
57     public static function pages($args) // /plugins/pages/_public.php
58     {
59          if ($args == '') {
60               self::p404();
61          }
62         
63          $_ctx =& $GLOBALS['_ctx'];
64          $core =& $GLOBALS['core'];
65         
66          $core->blog->withoutPassword(false);
67         
68          $params = new ArrayObject();
69          $params['post_type'] = 'page';
70          $params['post_url'] = $args;
71         
72          $_ctx->posts = $core->blog->getPosts($params);
73         
74          $_ctx->comment_preview = new ArrayObject();
75          $_ctx->comment_preview['content'] = '';
76          $_ctx->comment_preview['rawcontent'] = '';
77          $_ctx->comment_preview['name'] = '';
78          $_ctx->comment_preview['mail'] = '';
79          $_ctx->comment_preview['site'] = '';
80          $_ctx->comment_preview['preview'] = false;
81          $_ctx->comment_preview['remember'] = false;
82         
83          $core->blog->withoutPassword(true);
84         
85         
86          if ($_ctx->posts->isEmpty())
87          {
88               # No entry
89               self::p404();
90          }
91         
92          $post_id = $_ctx->posts->post_id;
93          $post_url = $_ctx->posts->post_url;
94          $post_password = $_ctx->posts->post_password;
95         
96          # Password protected entry
97          if ($post_password != '')
98          {
99               # Get passwords cookie
100               if (isset($_COOKIE['dc_passwd'])) {
101                    $pwd_cookie = unserialize($_COOKIE['dc_passwd']);
102               } else {
103                    $pwd_cookie = array();
104               }
105               
106               # Check for match
107               if ((!empty($_POST['password']) && $_POST['password'] == $post_password)
108               || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password))
109               {
110                    $pwd_cookie[$post_id] = $post_password;
111                    setcookie('dc_passwd',serialize($pwd_cookie),0,'/');
112               }
113               else
114               {
115                    self::serveDocument('password-form.html','text/html',false);
116                    exit;
117               }
118          }
119         
120          $post_comment =
121               isset($_POST['c_name']) && isset($_POST['c_mail']) &&
122               isset($_POST['c_site']) && isset($_POST['c_content']) &&
123               $_ctx->posts->commentsActive();
124         
125          # Posting a comment
126          if ($post_comment)
127          {
128               # Spam trap
129               if (!empty($_POST['f_mail'])) {
130                    http::head(412,'Precondition Failed');
131                    header('Content-Type: text/plain');
132                    echo "So Long, and Thanks For All the Fish";
133                    exit;
134               }
135               
136               $name = $_POST['c_name'];
137               $mail = $_POST['c_mail'];
138               $site = $_POST['c_site'];
139               $content = $_POST['c_content'];
140               $preview = !empty($_POST['preview']);
141               
142               if ($content != '')
143               {
144                    if ($core->blog->settings->wiki_comments) {
145                         $core->initWikiComment();
146                    } else {
147                         $core->initWikiSimpleComment();
148                    }
149                    $content = $core->wikiTransform($content);
150                    $content = $core->HTMLfilter($content);
151               }
152               
153               $_ctx->comment_preview['content'] = $content;
154               $_ctx->comment_preview['rawcontent'] = $_POST['c_content'];
155               $_ctx->comment_preview['name'] = $name;
156               $_ctx->comment_preview['mail'] = $mail;
157               $_ctx->comment_preview['site'] = $site;
158               
159               if ($preview)
160               {
161                    $_ctx->comment_preview['preview'] = true;
162               }
163               else
164               {
165                    # Post the comment
166                    $cur = $core->con->openCursor($core->prefix.'comment');
167                    $cur->comment_author = $name;
168                    $cur->comment_site = html::clean($site);
169                    $cur->comment_email = html::clean($mail);
170                    $cur->comment_content = $content;
171                    $cur->post_id = $_ctx->posts->post_id;
172                    $cur->comment_status = $core->blog->settings->comments_pub ? 1 : -1;
173                    $cur->comment_ip = http::realIP();
174                   
175                    $redir = $_ctx->posts->getURL();
176                    $redir .= strpos($redir,'?') !== false ? '&' : '?';
177                   
178                    try
179                    {
180                         if (!text::isEmail($cur->comment_email)) {
181                              throw new Exception(__('You must provide a valid email address.'));
182                         }
183
184                         # --BEHAVIOR-- publicBeforeCommentCreate
185                         $core->callBehavior('publicBeforeCommentCreate',$cur);
186                         if ($cur->post_id) {                         
187                              $comment_id = $core->blog->addComment($cur);
188                         
189                              # --BEHAVIOR-- publicAfterCommentCreate
190                              $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id);
191                         }
192                         
193                         if ($cur->comment_status == 1) {
194                              $redir_arg = 'pub=1';
195                         } else {
196                              $redir_arg = 'pub=0';
197                         }
198                         
199                         header('Location: '.$redir.$redir_arg);
200                         exit;
201                    }
202                    catch (Exception $e)
203                    {
204                         $_ctx->form_error = $e->getMessage();
205                         $_ctx->form_error;
206                    }
207               }
208          }
209         
210          # The entry
211          $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
212         
213          $tpl = 'page-'.$post_url.'.html'; //page-##.html où ## est l'url de la page
214          if (!$core->tpl->getFilePath($tpl)) {
215               $tpl = 'page-'.$post_id.'.html'; //page-##.html où ## est l'id de la page
216               if (!$core->tpl->getFilePath($tpl)) {
217                    $tpl = 'page.html';
218               }
219          }
220         
221          self::serveDocument($tpl);
222          exit;
223     }
224}
225?>
Note: See TracBrowser for help on using the repository browser.

Sites map