Dotclear

source: plugins/pages/_public.php @ 1107:3943962d69b8

Revision 1107:3943962d69b8, 3.5 KB checked in by JcDenis, 12 years ago (diff)

merge with default branch in 2.5-RC

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14# Localized string we find in template
15__('Published on');
16__('This page\'s comments feed');
17
18require dirname(__FILE__).'/_widgets.php';
19
20class 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'];
32               
33               $core->blog->withoutPassword(false);
34               
35               $params = new ArrayObject(array(
36                    'post_type' => 'page',
37                    'post_url' => $args));
38               
39               $core->callBehavior('publicPagesBeforeGetPosts',$params,$args);
40               
41               $_ctx->posts = $core->blog->getPosts($params);
42               
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;
51               
52               $core->blog->withoutPassword(true);
53               
54               
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                    # The entry
64                    $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
65                    self::serveDocument('page.html');
66               }
67          }
68     }
69     
70     public static function pagespreview($args)
71     {
72          $core = $GLOBALS['core'];
73          $_ctx = $GLOBALS['_ctx'];
74         
75          if (!preg_match('#^(.+?)/([0-9a-z]{40})/(.+?)$#',$args,$m)) {
76               # The specified Preview URL is malformed.
77               self::p404();
78          }
79          else
80          {
81               $user_id = $m[1];
82               $user_key = $m[2];
83               $post_url = $m[3];
84               if (!$core->auth->checkUser($user_id,null,$user_key)) {
85                    # The user has no access to the entry.
86                    self::p404();
87               }
88               else
89               {
90                    $_ctx->preview = true;
91                    self::pages($post_url);
92               }
93          }
94     }
95}
96
97class tplPages
98{
99     # Widget function
100     public static function pagesWidget($w)
101     {
102          global $core, $_ctx;
103         
104          if (($w->homeonly == 1 && $core->url->type != 'default') ||
105               ($w->homeonly == 2 && $core->url->type == 'default')) {
106               return;
107          }
108         
109          $params['post_type'] = 'page';
110          $params['limit'] = abs((integer) $w->limit);
111          $params['no_content'] = true;
112          $params['post_selected'] = false;
113         
114          $sort = $w->sortby;
115          if (!in_array($sort,array('post_title','post_position','post_dt'))) {
116               $sort = 'post_title';
117          }
118         
119          $order = $w->orderby;
120          if ($order != 'asc') {
121               $order = 'desc';
122          }
123          $params['order'] = $sort.' '.$order;
124         
125          $rs = $core->blog->getPosts($params);
126         
127          if ($rs->isEmpty()) {
128               return;
129          }
130         
131          $res =
132          ($w->content_only ? '' : '<div class="pages'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
133          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
134          '<ul>';
135         
136          while ($rs->fetch()) {
137               $class = '';
138               if (($core->url->type == 'pages' && $_ctx->posts instanceof record && $_ctx->posts->post_id == $rs->post_id)) {
139                    $class = ' class="page-current"';
140               }
141               $res .= '<li'.$class.'><a href="'.$rs->getURL().'">'.
142               html::escapeHTML($rs->post_title).'</a></li>';
143          }
144         
145          $res .= '</ul>'.($w->content_only ? '' : '</div>');
146         
147          return $res;
148     }
149}
150?>
Note: See TracBrowser for help on using the repository browser.

Sites map