Dotclear

source: plugins/splitPost/_public.php @ 1423

Revision 1423, 6.1 KB checked in by Tomtom33, 14 years ago (diff)

splitPost 0.2 :

  • Adds params for TPL tag
  • Adds wysiywg support
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of splitPost, a plugin for Dotclear.
4#
5# Copyright (c) 2009 Tomtom
6# http://blog.zenstyle.fr/
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 ------------------------------------
12
13if (!defined('DC_RC_PATH')) { return; }
14
15$core->tpl->addValue('PostPagination',array('splitPostTpl','PostPagination'));
16
17$core->url->register('post','post','^post/(.+)$',array('splitPostUrl','post'));
18
19$core->addBehavior('coreBlogGetPosts',array('splitPostBehaviors','coreBlogGetPosts'));
20
21class splitPostUrl extends dcUrlHandlers
22{
23     public static function post($args)
24     {
25          if ($args == '') {
26               self::p404();
27          }
28         
29          $_ctx = $GLOBALS['_ctx'];
30          $core = $GLOBALS['core'];
31         
32          $core->blog->withoutPassword(false);
33         
34          $args = preg_split('#/page/#',$args);
35         
36          $params = new ArrayObject();
37          $params['post_url'] = $args[0];
38         
39          $_ctx->posts = $core->blog->getPosts($params);
40         
41          # Post pages
42          $_ctx->post_page_count = count(preg_split($core->post_page_pattern,$_ctx->posts->post_content_xhtml));
43          $_ctx->post_page_current = isset($args[1]) ? (int) $args[1] : null;
44         
45          if (
46               $_ctx->post_page_current === 0 ||
47               $_ctx->post_page_current > $_ctx->post_page_count
48          ) {
49               self::p404();
50               exit;
51          }
52         
53          $_ctx->comment_preview = new ArrayObject();
54          $_ctx->comment_preview['content'] = '';
55          $_ctx->comment_preview['rawcontent'] = '';
56          $_ctx->comment_preview['name'] = '';
57          $_ctx->comment_preview['mail'] = '';
58          $_ctx->comment_preview['site'] = '';
59          $_ctx->comment_preview['preview'] = false;
60          $_ctx->comment_preview['remember'] = false;
61         
62          $core->blog->withoutPassword(true);
63         
64         
65          if ($_ctx->posts->isEmpty())
66          { 
67               # No entry
68               self::p404();
69               exit;
70          }
71         
72          $post_id = $_ctx->posts->post_id;
73          $post_password = $_ctx->posts->post_password;
74         
75          # Password protected entry
76          if ($post_password != '')
77          {
78               # Get passwords cookie
79               if (isset($_COOKIE['dc_passwd'])) {
80                    $pwd_cookie = unserialize($_COOKIE['dc_passwd']);
81               } else {
82                    $pwd_cookie = array();
83               }
84               
85               # Check for match
86               if ((!empty($_POST['password']) && $_POST['password'] == $post_password)
87               || (isset($pwd_cookie[$post_id]) && $pwd_cookie[$post_id] == $post_password))
88               {
89                    $pwd_cookie[$post_id] = $post_password;
90                    setcookie('dc_passwd',serialize($pwd_cookie),0,'/');
91               }
92               else
93               {
94                    self::serveDocument('password-form.html','text/html',false);
95                    exit;
96               }
97          }
98         
99          $post_comment =
100               isset($_POST['c_name']) && isset($_POST['c_mail']) &&
101               isset($_POST['c_site']) && isset($_POST['c_content']) &&
102               $_ctx->posts->commentsActive();
103         
104          # Posting a comment
105          if ($post_comment)
106          {
107               # Spam trap
108               if (!empty($_POST['f_mail'])) {
109                    http::head(412,'Precondition Failed');
110                    header('Content-Type: text/plain');
111                    echo "So Long, and Thanks For All the Fish";
112                    exit;
113               }
114               
115               $name = $_POST['c_name'];
116               $mail = $_POST['c_mail'];
117               $site = $_POST['c_site'];
118               $content = $_POST['c_content'];
119               $preview = !empty($_POST['preview']);
120               
121               if ($content != '')
122               {
123                    if ($core->blog->settings->wiki_comments) {
124                         $core->initWikiComment();
125                    } else {
126                         $core->initWikiSimpleComment();
127                    }
128                    $content = $core->wikiTransform($content);
129                    $content = $core->HTMLfilter($content);
130               }
131               
132               $_ctx->comment_preview['content'] = $content;
133               $_ctx->comment_preview['rawcontent'] = $_POST['c_content'];
134               $_ctx->comment_preview['name'] = $name;
135               $_ctx->comment_preview['mail'] = $mail;
136               $_ctx->comment_preview['site'] = $site;
137               
138               if ($preview)
139               {
140                    # --BEHAVIOR-- publicBeforeCommentPreview
141                    $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview);
142                   
143                    $_ctx->comment_preview['preview'] = true;
144               }
145               else
146               {
147                    # Post the comment
148                    $cur = $core->con->openCursor($core->prefix.'comment');
149                    $cur->comment_author = $name;
150                    $cur->comment_site = html::clean($site);
151                    $cur->comment_email = html::clean($mail);
152                    $cur->comment_content = $content;
153                    $cur->post_id = $_ctx->posts->post_id;
154                    $cur->comment_status = $core->blog->settings->comments_pub ? 1 : -1;
155                    $cur->comment_ip = http::realIP();
156                   
157                    $redir = $_ctx->posts->getURL();
158                    $redir .= strpos($redir,'?') !== false ? '&' : '?';
159                   
160                    try
161                    {
162                         if (!text::isEmail($cur->comment_email)) {
163                              throw new Exception(__('You must provide a valid email address.'));
164                         }
165
166                         # --BEHAVIOR-- publicBeforeCommentCreate
167                         $core->callBehavior('publicBeforeCommentCreate',$cur);
168                         if ($cur->post_id) {                         
169                              $comment_id = $core->blog->addComment($cur);
170                         
171                              # --BEHAVIOR-- publicAfterCommentCreate
172                              $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id);
173                         }
174                         
175                         if ($cur->comment_status == 1) {
176                              $redir_arg = 'pub=1';
177                         } else {
178                              $redir_arg = 'pub=0';
179                         }
180                         
181                         header('Location: '.$redir.$redir_arg);
182                         exit;
183                    }
184                    catch (Exception $e)
185                    {
186                         $_ctx->form_error = $e->getMessage();
187                         $_ctx->form_error;
188                    }
189               }
190          }
191         
192          # The entry
193          self::serveDocument('post.html');
194     }
195}
196
197class splitPostTpl
198{
199     public static function PostPagination($attr)
200     {
201          $f = $GLOBALS['core']->tpl->getFilters($attr);
202         
203          $max = isset($attr['max']) ? (int) $attr['max'] : 20;
204         
205          $p = "\$params = array();\n";
206          if (isset($attr['current'])) {
207               $p .= "\$params['current'] = '".$attr['current']."';\n";
208          }
209          if (isset($attr['prev'])) {
210               $p .= "\$params['prev'] = '".$attr['prev']."';\n";
211          }
212          if (isset($attr['next'])) {
213               $p .= "\$params['next'] = '".$attr['next']."';\n";
214          }
215         
216         
217          $res = "<?php\n";
218          $res .= $p;
219          $res .= "\$pager = new splitPostPager(\$_ctx->post_page_current,\$_ctx->post_page_count,".$max.");\n";
220          $res .= "\$pager->init(\$params);\n";
221          $res .= "echo \$pager->getLinks();\n";
222          $res .= "?>\n";
223         
224          return $res;
225     }
226}
227
228?>
Note: See TracBrowser for help on using the repository browser.

Sites map