Dotclear

source: plugins/specificsTemplates/_public.php @ 985

Revision 985, 6.3 KB checked in by thi3rry, 14 years ago (diff)

Adding licence heading (GPL V2)

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

Sites map