[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 | |
---|
[3042] | 14 | $core->addBehavior('coreBlogBeforeGetPosts',array('publicPages','coreBlogBeforeGetPosts')); |
---|
| 15 | |
---|
[0] | 16 | # Localized string we find in template |
---|
| 17 | __('Published on'); |
---|
| 18 | __('This page\'s comments feed'); |
---|
| 19 | |
---|
| 20 | require dirname(__FILE__).'/_widgets.php'; |
---|
| 21 | |
---|
[3042] | 22 | class publicPages |
---|
| 23 | { |
---|
| 24 | public static function coreBlogBeforeGetPosts($params) |
---|
| 25 | { |
---|
[3043] | 26 | global $core; |
---|
[3042] | 27 | |
---|
| 28 | if ($core->url->type == 'search') { |
---|
| 29 | // Add page post type for searching |
---|
| 30 | if (isset($params['post_type'])) { |
---|
| 31 | if (!is_array($params['post_type'])) { |
---|
| 32 | // Convert it in array |
---|
| 33 | $params['post_type'] = array($params['post_type']); |
---|
| 34 | } |
---|
| 35 | if (!in_array('page', $params['post_type'])) { |
---|
| 36 | // Add page post type |
---|
| 37 | $params['post_type'][] = 'page'; |
---|
| 38 | } |
---|
| 39 | } else { |
---|
| 40 | // Dont miss default post type (aka post) |
---|
| 41 | $params['post_type'] = array('post','page'); |
---|
| 42 | } |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
[0] | 47 | class urlPages extends dcUrlHandlers |
---|
| 48 | { |
---|
| 49 | public static function pages($args) |
---|
| 50 | { |
---|
| 51 | if ($args == '') { |
---|
| 52 | # No page was specified. |
---|
| 53 | self::p404(); |
---|
| 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
| 57 | $_ctx =& $GLOBALS['_ctx']; |
---|
| 58 | $core =& $GLOBALS['core']; |
---|
[2566] | 59 | |
---|
[0] | 60 | $core->blog->withoutPassword(false); |
---|
[2566] | 61 | |
---|
[306] | 62 | $params = new ArrayObject(array( |
---|
| 63 | 'post_type' => 'page', |
---|
| 64 | 'post_url' => $args)); |
---|
[2566] | 65 | |
---|
[306] | 66 | $core->callBehavior('publicPagesBeforeGetPosts',$params,$args); |
---|
[2566] | 67 | |
---|
[0] | 68 | $_ctx->posts = $core->blog->getPosts($params); |
---|
[2566] | 69 | |
---|
[0] | 70 | $_ctx->comment_preview = new ArrayObject(); |
---|
| 71 | $_ctx->comment_preview['content'] = ''; |
---|
| 72 | $_ctx->comment_preview['rawcontent'] = ''; |
---|
| 73 | $_ctx->comment_preview['name'] = ''; |
---|
| 74 | $_ctx->comment_preview['mail'] = ''; |
---|
| 75 | $_ctx->comment_preview['site'] = ''; |
---|
| 76 | $_ctx->comment_preview['preview'] = false; |
---|
| 77 | $_ctx->comment_preview['remember'] = false; |
---|
[2566] | 78 | |
---|
[0] | 79 | $core->blog->withoutPassword(true); |
---|
[2566] | 80 | |
---|
| 81 | |
---|
[0] | 82 | if ($_ctx->posts->isEmpty()) |
---|
| 83 | { |
---|
| 84 | # The specified page does not exist. |
---|
| 85 | self::p404(); |
---|
| 86 | } |
---|
| 87 | else |
---|
| 88 | { |
---|
| 89 | $post_id = $_ctx->posts->post_id; |
---|
| 90 | $post_password = $_ctx->posts->post_password; |
---|
[2566] | 91 | |
---|
[0] | 92 | # Password protected entry |
---|
| 93 | if ($post_password != '' && !$_ctx->preview) |
---|
| 94 | { |
---|
| 95 | # Get passwords cookie |
---|
| 96 | if (isset($_COOKIE['dc_passwd'])) { |
---|
[2634] | 97 | $pwd_cookie = json_decode($_COOKIE['dc_passwd']); |
---|
| 98 | if ($pwd_cookie === NULL) { |
---|
| 99 | $pwd_cookie = array(); |
---|
| 100 | } else { |
---|
| 101 | $pwd_cookie = (array) $pwd_cookie; |
---|
| 102 | } |
---|
[0] | 103 | } else { |
---|
| 104 | $pwd_cookie = array(); |
---|
| 105 | } |
---|
[2566] | 106 | |
---|
[0] | 107 | # Check for match |
---|
[2771] | 108 | # Note: We must prefix post_id key with '#'' in pwd_cookie array in order to avoid integer conversion |
---|
| 109 | # because MyArray["12345"] is treated as MyArray[12345] |
---|
[0] | 110 | if ((!empty($_POST['password']) && $_POST['password'] == $post_password) |
---|
[2771] | 111 | || (isset($pwd_cookie['#'.$post_id]) && $pwd_cookie['#'.$post_id] == $post_password)) |
---|
[0] | 112 | { |
---|
[2771] | 113 | $pwd_cookie['#'.$post_id] = $post_password; |
---|
[2634] | 114 | setcookie('dc_passwd',json_encode($pwd_cookie),0,'/'); |
---|
[0] | 115 | } |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | self::serveDocument('password-form.html','text/html',false); |
---|
| 119 | return; |
---|
| 120 | } |
---|
| 121 | } |
---|
[2566] | 122 | |
---|
[0] | 123 | $post_comment = |
---|
| 124 | isset($_POST['c_name']) && isset($_POST['c_mail']) && |
---|
| 125 | isset($_POST['c_site']) && isset($_POST['c_content']) && |
---|
| 126 | $_ctx->posts->commentsActive(); |
---|
[2566] | 127 | |
---|
[0] | 128 | # Posting a comment |
---|
| 129 | if ($post_comment) |
---|
| 130 | { |
---|
| 131 | # Spam trap |
---|
| 132 | if (!empty($_POST['f_mail'])) { |
---|
| 133 | http::head(412,'Precondition Failed'); |
---|
| 134 | header('Content-Type: text/plain'); |
---|
| 135 | echo "So Long, and Thanks For All the Fish"; |
---|
| 136 | # Exits immediately the application to preserve the server. |
---|
| 137 | exit; |
---|
| 138 | } |
---|
[2566] | 139 | |
---|
[0] | 140 | $name = $_POST['c_name']; |
---|
| 141 | $mail = $_POST['c_mail']; |
---|
| 142 | $site = $_POST['c_site']; |
---|
| 143 | $content = $_POST['c_content']; |
---|
| 144 | $preview = !empty($_POST['preview']); |
---|
[2566] | 145 | |
---|
[0] | 146 | if ($content != '') |
---|
| 147 | { |
---|
[2586] | 148 | # --BEHAVIOR-- publicBeforeCommentTransform |
---|
| 149 | $buffer = $core->callBehavior('publicBeforeCommentTransform',$content); |
---|
| 150 | if ($buffer != '') { |
---|
| 151 | $content = $buffer; |
---|
[0] | 152 | } else { |
---|
[2586] | 153 | if ($core->blog->settings->system->wiki_comments) { |
---|
| 154 | $core->initWikiComment(); |
---|
| 155 | } else { |
---|
| 156 | $core->initWikiSimpleComment(); |
---|
| 157 | } |
---|
| 158 | $content = $core->wikiTransform($content); |
---|
[0] | 159 | } |
---|
| 160 | $content = $core->HTMLfilter($content); |
---|
| 161 | } |
---|
[2566] | 162 | |
---|
[0] | 163 | $_ctx->comment_preview['content'] = $content; |
---|
| 164 | $_ctx->comment_preview['rawcontent'] = $_POST['c_content']; |
---|
| 165 | $_ctx->comment_preview['name'] = $name; |
---|
| 166 | $_ctx->comment_preview['mail'] = $mail; |
---|
| 167 | $_ctx->comment_preview['site'] = $site; |
---|
[2566] | 168 | |
---|
[0] | 169 | if ($preview) |
---|
| 170 | { |
---|
| 171 | # --BEHAVIOR-- publicBeforeCommentPreview |
---|
| 172 | $core->callBehavior('publicBeforeCommentPreview',$_ctx->comment_preview); |
---|
[2566] | 173 | |
---|
[0] | 174 | $_ctx->comment_preview['preview'] = true; |
---|
| 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | # Post the comment |
---|
| 179 | $cur = $core->con->openCursor($core->prefix.'comment'); |
---|
| 180 | $cur->comment_author = $name; |
---|
| 181 | $cur->comment_site = html::clean($site); |
---|
| 182 | $cur->comment_email = html::clean($mail); |
---|
| 183 | $cur->comment_content = $content; |
---|
| 184 | $cur->post_id = $_ctx->posts->post_id; |
---|
| 185 | $cur->comment_status = $core->blog->settings->system->comments_pub ? 1 : -1; |
---|
| 186 | $cur->comment_ip = http::realIP(); |
---|
[2566] | 187 | |
---|
[0] | 188 | $redir = $_ctx->posts->getURL(); |
---|
[727] | 189 | $redir .= $core->blog->settings->system->url_scan == 'query_string' ? '&' : '?'; |
---|
[2566] | 190 | |
---|
[0] | 191 | try |
---|
| 192 | { |
---|
| 193 | if (!text::isEmail($cur->comment_email)) { |
---|
| 194 | throw new Exception(__('You must provide a valid email address.')); |
---|
| 195 | } |
---|
[2566] | 196 | |
---|
[0] | 197 | # --BEHAVIOR-- publicBeforeCommentCreate |
---|
| 198 | $core->callBehavior('publicBeforeCommentCreate',$cur); |
---|
[2566] | 199 | if ($cur->post_id) { |
---|
[0] | 200 | $comment_id = $core->blog->addComment($cur); |
---|
[2566] | 201 | |
---|
[0] | 202 | # --BEHAVIOR-- publicAfterCommentCreate |
---|
| 203 | $core->callBehavior('publicAfterCommentCreate',$cur,$comment_id); |
---|
| 204 | } |
---|
[2566] | 205 | |
---|
[0] | 206 | if ($cur->comment_status == 1) { |
---|
| 207 | $redir_arg = 'pub=1'; |
---|
| 208 | } else { |
---|
| 209 | $redir_arg = 'pub=0'; |
---|
| 210 | } |
---|
[2566] | 211 | |
---|
[0] | 212 | header('Location: '.$redir.$redir_arg); |
---|
| 213 | } |
---|
| 214 | catch (Exception $e) |
---|
| 215 | { |
---|
| 216 | $_ctx->form_error = $e->getMessage(); |
---|
| 217 | $_ctx->form_error; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | } |
---|
[2566] | 221 | |
---|
[0] | 222 | # The entry |
---|
[1674] | 223 | if ($_ctx->posts->trackbacksActive()) { |
---|
| 224 | header('X-Pingback: '.$core->blog->url.$core->url->getURLFor("xmlrpc",$core->blog->id)); |
---|
| 225 | } |
---|
[2603] | 226 | |
---|
| 227 | $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme,'tplset'); |
---|
| 228 | if (!empty($tplset) && is_dir(dirname(__FILE__).'/default-templates/'.$tplset)) { |
---|
| 229 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.$tplset); |
---|
| 230 | } else { |
---|
[2607] | 231 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET); |
---|
[2603] | 232 | } |
---|
[0] | 233 | self::serveDocument('page.html'); |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | } |
---|
[2566] | 237 | |
---|
[0] | 238 | public static function pagespreview($args) |
---|
| 239 | { |
---|
| 240 | $core = $GLOBALS['core']; |
---|
| 241 | $_ctx = $GLOBALS['_ctx']; |
---|
[2566] | 242 | |
---|
[0] | 243 | if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) { |
---|
| 244 | # The specified Preview URL is malformed. |
---|
| 245 | self::p404(); |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
| 249 | $user_id = $m[1]; |
---|
| 250 | $user_key = $m[2]; |
---|
| 251 | $post_url = $m[3]; |
---|
| 252 | if (!$core->auth->checkUser($user_id,null,$user_key)) { |
---|
| 253 | # The user has no access to the entry. |
---|
| 254 | self::p404(); |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | $_ctx->preview = true; |
---|
[2920] | 259 | if (defined ("DC_ADMIN_URL")) { |
---|
| 260 | $_ctx->xframeoption=DC_ADMIN_URL; |
---|
| 261 | } |
---|
| 262 | |
---|
[0] | 263 | self::pages($post_url); |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | class tplPages |
---|
| 270 | { |
---|
| 271 | # Widget function |
---|
| 272 | public static function pagesWidget($w) |
---|
| 273 | { |
---|
| 274 | global $core, $_ctx; |
---|
[2566] | 275 | |
---|
[2778] | 276 | if ($w->offline) |
---|
| 277 | return; |
---|
| 278 | |
---|
[945] | 279 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
| 280 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
[0] | 281 | return; |
---|
| 282 | } |
---|
[2566] | 283 | |
---|
[0] | 284 | $params['post_type'] = 'page'; |
---|
| 285 | $params['limit'] = abs((integer) $w->limit); |
---|
| 286 | $params['no_content'] = true; |
---|
[911] | 287 | $params['post_selected'] = false; |
---|
[2566] | 288 | |
---|
[0] | 289 | $sort = $w->sortby; |
---|
| 290 | if (!in_array($sort,array('post_title','post_position','post_dt'))) { |
---|
| 291 | $sort = 'post_title'; |
---|
| 292 | } |
---|
[2566] | 293 | |
---|
[0] | 294 | $order = $w->orderby; |
---|
| 295 | if ($order != 'asc') { |
---|
| 296 | $order = 'desc'; |
---|
| 297 | } |
---|
| 298 | $params['order'] = $sort.' '.$order; |
---|
[2566] | 299 | |
---|
[0] | 300 | $rs = $core->blog->getPosts($params); |
---|
[2566] | 301 | |
---|
[0] | 302 | if ($rs->isEmpty()) { |
---|
| 303 | return; |
---|
| 304 | } |
---|
[2566] | 305 | |
---|
[2667] | 306 | $res = ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').'<ul>'; |
---|
[2566] | 307 | |
---|
[0] | 308 | while ($rs->fetch()) { |
---|
| 309 | $class = ''; |
---|
| 310 | if (($core->url->type == 'pages' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id)) { |
---|
| 311 | $class = ' class="page-current"'; |
---|
| 312 | } |
---|
| 313 | $res .= '<li'.$class.'><a href="'.$rs->getURL().'">'. |
---|
| 314 | html::escapeHTML($rs->post_title).'</a></li>'; |
---|
| 315 | } |
---|
[2566] | 316 | |
---|
[2667] | 317 | $res .= '</ul>'; |
---|
[2566] | 318 | |
---|
[2667] | 319 | return $w->renderDiv($w->content_only,'pages '.$w->class,'',$res); |
---|
[0] | 320 | } |
---|
| 321 | } |
---|