[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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 ----------------------------------------- |
---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
---|
| 13 | |
---|
| 14 | # Localized string we find in template |
---|
| 15 | __('Published on'); |
---|
| 16 | __('This page\'s comments feed'); |
---|
| 17 | |
---|
| 18 | require dirname(__FILE__).'/_widgets.php'; |
---|
| 19 | |
---|
| 20 | class 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']; |
---|
[2566] | 32 | |
---|
[0] | 33 | $core->blog->withoutPassword(false); |
---|
[2566] | 34 | |
---|
[306] | 35 | $params = new ArrayObject(array( |
---|
| 36 | 'post_type' => 'page', |
---|
| 37 | 'post_url' => $args)); |
---|
[2566] | 38 | |
---|
[306] | 39 | $core->callBehavior('publicPagesBeforeGetPosts',$params,$args); |
---|
[2566] | 40 | |
---|
[0] | 41 | $_ctx->posts = $core->blog->getPosts($params); |
---|
[2566] | 42 | |
---|
[0] | 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; |
---|
[2566] | 51 | |
---|
[0] | 52 | $core->blog->withoutPassword(true); |
---|
[2566] | 53 | |
---|
| 54 | |
---|
[0] | 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; |
---|
[2566] | 64 | |
---|
[0] | 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 | } |
---|
[2566] | 74 | |
---|
[0] | 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 | } |
---|
[2566] | 88 | |
---|
[0] | 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(); |
---|
[2566] | 93 | |
---|
[0] | 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 | } |
---|
[2566] | 105 | |
---|
[0] | 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']); |
---|
[2566] | 111 | |
---|
[0] | 112 | if ($content != '') |
---|
| 113 | { |
---|
[2586] | 114 | # --BEHAVIOR-- publicBeforeCommentTransform |
---|
| 115 | $buffer = $core->callBehavior('publicBeforeCommentTransform',$content); |
---|
| 116 | if ($buffer != '') { |
---|
| 117 | $content = $buffer; |
---|
[0] | 118 | } else { |
---|
[2586] | 119 | if ($core->blog->settings->system->wiki_comments) { |
---|
| 120 | $core->initWikiComment(); |
---|
| 121 | } else { |
---|
| 122 | $core->initWikiSimpleComment(); |
---|
| 123 | } |
---|
| 124 | $content = $core->wikiTransform($content); |
---|
[0] | 125 | } |
---|
| 126 | $content = $core->HTMLfilter($content); |
---|
| 127 | } |
---|
[2566] | 128 | |
---|
[0] | 129 | $_ctx->comment_preview['content'] = $content; |
---|
| 130 | $_ctx->comment_preview['rawcontent'] = $_POST['c_content']; |
---|
| 131 | $_ctx->comment_preview['name'] = $name; |
---|
| 132 | $_ctx->comment_preview['mail'] = $mail; |
---|
| 133 | $_ctx->comment_preview['site'] = $site; |
---|
[2566] | 134 | |
---|
[0] | 135 | if ($preview) |
---|
| 136 | { |
---|
| 137 | # --BEHAVIOR-- publicBeforeCommentPreview |
---|
| 138 | $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview); |
---|
[2566] | 139 | |
---|
[0] | 140 | $_ctx->comment_preview['preview'] = true; |
---|
| 141 | } |
---|
| 142 | else |
---|
| 143 | { |
---|
| 144 | # Post the comment |
---|
| 145 | $cur = $core->con->openCursor($core->prefix.'comment'); |
---|
| 146 | $cur->comment_author = $name; |
---|
| 147 | $cur->comment_site = html::clean($site); |
---|
| 148 | $cur->comment_email = html::clean($mail); |
---|
| 149 | $cur->comment_content = $content; |
---|
| 150 | $cur->post_id = $_ctx->posts->post_id; |
---|
| 151 | $cur->comment_status = $core->blog->settings->system->comments_pub ? 1 : -1; |
---|
| 152 | $cur->comment_ip = http::realIP(); |
---|
[2566] | 153 | |
---|
[0] | 154 | $redir = $_ctx->posts->getURL(); |
---|
[727] | 155 | $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?'; |
---|
[2566] | 156 | |
---|
[0] | 157 | try |
---|
| 158 | { |
---|
| 159 | if (!text::isEmail($cur->comment_email)) { |
---|
| 160 | throw new Exception(__('You must provide a valid email address.')); |
---|
| 161 | } |
---|
[2566] | 162 | |
---|
[0] | 163 | # --BEHAVIOR-- publicBeforeCommentCreate |
---|
| 164 | $core->callBehavior('publicBeforeCommentCreate',$cur); |
---|
[2566] | 165 | if ($cur->post_id) { |
---|
[0] | 166 | $comment_id = $core->blog->addComment($cur); |
---|
[2566] | 167 | |
---|
[0] | 168 | # --BEHAVIOR-- publicAfterCommentCreate |
---|
| 169 | $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id); |
---|
| 170 | } |
---|
[2566] | 171 | |
---|
[0] | 172 | if ($cur->comment_status == 1) { |
---|
| 173 | $redir_arg = 'pub=1'; |
---|
| 174 | } else { |
---|
| 175 | $redir_arg = 'pub=0'; |
---|
| 176 | } |
---|
[2566] | 177 | |
---|
[0] | 178 | header('Location: '.$redir.$redir_arg); |
---|
| 179 | } |
---|
| 180 | catch (Exception $e) |
---|
| 181 | { |
---|
| 182 | $_ctx->form_error = $e->getMessage(); |
---|
| 183 | $_ctx->form_error; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | } |
---|
[2566] | 187 | |
---|
[0] | 188 | # The entry |
---|
[1674] | 189 | if ($_ctx->posts->trackbacksActive()) { |
---|
| 190 | header('X-Pingback: '.$core->blog->url.$core->url->getURLFor("xmlrpc",$core->blog->id)); |
---|
| 191 | } |
---|
[2603] | 192 | |
---|
| 193 | $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme,'tplset'); |
---|
| 194 | if (!empty($tplset) && is_dir(dirname(__FILE__).'/default-templates/'.$tplset)) { |
---|
| 195 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.$tplset); |
---|
| 196 | } else { |
---|
[2607] | 197 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET); |
---|
[2603] | 198 | } |
---|
[0] | 199 | self::serveDocument('page.html'); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
[2566] | 203 | |
---|
[0] | 204 | public static function pagespreview($args) |
---|
| 205 | { |
---|
| 206 | $core = $GLOBALS['core']; |
---|
| 207 | $_ctx = $GLOBALS['_ctx']; |
---|
[2566] | 208 | |
---|
[0] | 209 | if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) { |
---|
| 210 | # The specified Preview URL is malformed. |
---|
| 211 | self::p404(); |
---|
| 212 | } |
---|
| 213 | else |
---|
| 214 | { |
---|
| 215 | $user_id = $m[1]; |
---|
| 216 | $user_key = $m[2]; |
---|
| 217 | $post_url = $m[3]; |
---|
| 218 | if (!$core->auth->checkUser($user_id,null,$user_key)) { |
---|
| 219 | # The user has no access to the entry. |
---|
| 220 | self::p404(); |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | $_ctx->preview = true; |
---|
| 225 | self::pages($post_url); |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | class tplPages |
---|
| 232 | { |
---|
| 233 | # Widget function |
---|
| 234 | public static function pagesWidget($w) |
---|
| 235 | { |
---|
| 236 | global $core, $_ctx; |
---|
[2566] | 237 | |
---|
[945] | 238 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 239 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 240 | return; |
---|
| 241 | } |
---|
[2566] | 242 | |
---|
[0] | 243 | $params['post_type'] = 'page'; |
---|
| 244 | $params['limit'] = abs((integer) $w->limit); |
---|
| 245 | $params['no_content'] = true; |
---|
[911] | 246 | $params['post_selected'] = false; |
---|
[2566] | 247 | |
---|
[0] | 248 | $sort = $w->sortby; |
---|
| 249 | if (!in_array($sort,array('post_title','post_position','post_dt'))) { |
---|
| 250 | $sort = 'post_title'; |
---|
| 251 | } |
---|
[2566] | 252 | |
---|
[0] | 253 | $order = $w->orderby; |
---|
| 254 | if ($order != 'asc') { |
---|
| 255 | $order = 'desc'; |
---|
| 256 | } |
---|
| 257 | $params['order'] = $sort.' '.$order; |
---|
[2566] | 258 | |
---|
[0] | 259 | $rs = $core->blog->getPosts($params); |
---|
[2566] | 260 | |
---|
[0] | 261 | if ($rs->isEmpty()) { |
---|
| 262 | return; |
---|
| 263 | } |
---|
[2566] | 264 | |
---|
[0] | 265 | $res = |
---|
[1063] | 266 | ($w->content_only ? '' : '<div class="pages'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). |
---|
[0] | 267 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
| 268 | '<ul>'; |
---|
[2566] | 269 | |
---|
[0] | 270 | while ($rs->fetch()) { |
---|
| 271 | $class = ''; |
---|
| 272 | if (($core->url->type == 'pages' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id)) { |
---|
| 273 | $class = ' class="page-current"'; |
---|
| 274 | } |
---|
| 275 | $res .= '<li'.$class.'><a href="'.$rs->getURL().'">'. |
---|
| 276 | html::escapeHTML($rs->post_title).'</a></li>'; |
---|
| 277 | } |
---|
[2566] | 278 | |
---|
[1063] | 279 | $res .= '</ul>'.($w->content_only ? '' : '</div>'); |
---|
[2566] | 280 | |
---|
[0] | 281 | return $res; |
---|
| 282 | } |
---|
| 283 | } |
---|