author | Dan |
Tue, 05 May 2009 00:18:09 -0400 | |
changeset 17 | f6edf51a9479 |
parent 16 | 3d96dbb770b5 |
child 18 | 8205e4ca237e |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/* |
|
3 |
Plugin Name: Newsboy |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
4 |
Plugin URI: http://enanocms.org/plugin/newsboy |
0 | 5 |
Description: Newsboy adds a news management system to Enano. It can integrate with the Feed Me plugin to provide an additional RSS feed. |
6 |
Author: Dan Fuhry |
|
7 |
Version: 0.1 |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
8 |
Author URI: http://enanocms.org/ |
0 | 9 |
*/ |
10 |
||
11 |
/* |
|
12 |
* Newsboy |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
13 |
* Version 1.1.2 |
0 | 14 |
* Copyright (C) 2007 Dan Fuhry |
15 |
* |
|
16 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
17 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
20 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
21 |
*/ |
|
22 |
||
23 |
// Insert our News namespace |
|
24 |
$plugins->attachHook('acl_rule_init', 'NewsBoy_namespace_setup($this);'); |
|
25 |
||
26 |
// Hook into page rendering |
|
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
27 |
$plugins->attachHook('page_not_found', 'NewsBoy_namespace_handler($this);'); |
0 | 28 |
$plugins->attachHook('send_page_footers', 'NewsBoy_PortalLink();'); |
29 |
||
30 |
// String to determine page type string |
|
31 |
$plugins->attachHook('page_type_string_set', 'NewsBoy_set_page_string();'); |
|
32 |
||
33 |
// Attach to the Feed Me plugin, if it's loaded (if not, the feed handler simply won't get called) |
|
34 |
$plugins->attachHook('feed_me_request', 'NewsBoy_feed_handler($mode);'); |
|
35 |
||
36 |
function NewsBoy_namespace_setup(&$paths) |
|
37 |
{ |
|
38 |
$paths->create_namespace('NewsBoy', 'News:'); |
|
39 |
$paths->addAdminNode('Newsboy portal', 'Configuration', 'NewsboyConfiguration'); |
|
40 |
$paths->addAdminNode('Newsboy portal', 'Manage news items', 'NewsboyItemManager'); |
|
41 |
||
42 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
43 |
||
44 |
$session->acl_extend_scope('read', 'NewsBoy', $paths); |
|
45 |
$session->acl_extend_scope('post_comments', 'NewsBoy', $paths); |
|
46 |
$session->acl_extend_scope('edit_comments', 'NewsBoy', $paths); |
|
47 |
$session->acl_extend_scope('edit_page', 'NewsBoy', $paths); |
|
48 |
$session->acl_extend_scope('view_source', 'NewsBoy', $paths); |
|
49 |
$session->acl_extend_scope('mod_comments', 'NewsBoy', $paths); |
|
50 |
$session->acl_extend_scope('history_view', 'NewsBoy', $paths); |
|
51 |
$session->acl_extend_scope('history_rollback', 'NewsBoy', $paths); |
|
52 |
$session->acl_extend_scope('history_rollback_extra', 'NewsBoy', $paths); |
|
53 |
$session->acl_extend_scope('protect', 'NewsBoy', $paths); |
|
54 |
$session->acl_extend_scope('rename', 'NewsBoy', $paths); |
|
55 |
$session->acl_extend_scope('clear_logs', 'NewsBoy', $paths); |
|
56 |
$session->acl_extend_scope('vote_delete', 'NewsBoy', $paths); |
|
57 |
$session->acl_extend_scope('vote_reset', 'NewsBoy', $paths); |
|
58 |
$session->acl_extend_scope('delete_page', 'NewsBoy', $paths); |
|
59 |
$session->acl_extend_scope('set_wiki_mode', 'NewsBoy', $paths); |
|
60 |
$session->acl_extend_scope('password_set', 'NewsBoy', $paths); |
|
61 |
$session->acl_extend_scope('password_reset', 'NewsBoy', $paths); |
|
62 |
$session->acl_extend_scope('mod_misc', 'NewsBoy', $paths); |
|
63 |
$session->acl_extend_scope('edit_cat', 'NewsBoy', $paths); |
|
64 |
$session->acl_extend_scope('even_when_protected', 'NewsBoy', $paths); |
|
65 |
$session->acl_extend_scope('upload_files', 'NewsBoy', $paths); |
|
66 |
$session->acl_extend_scope('upload_new_version', 'NewsBoy', $paths); |
|
67 |
$session->acl_extend_scope('create_page', 'NewsBoy', $paths); |
|
15 | 68 |
$session->acl_extend_scope('html_in_pages', 'NewsBoy', $paths); |
0 | 69 |
$session->acl_extend_scope('php_in_pages', 'NewsBoy', $paths); |
70 |
$session->acl_extend_scope('edit_acl', 'NewsBoy', $paths); |
|
71 |
||
72 |
} |
|
73 |
||
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
74 |
function NewsBoy_namespace_handler(&$page) |
0 | 75 |
{ |
76 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
77 |
||
78 |
if ( defined('ENANO_FEEDBURNER_INCLUDED') ) |
|
79 |
{ |
|
80 |
$template->add_header('<link rel="alternate" title="'.getConfig('site_name').' News feed" href="'.makeUrlNS('Special', 'RSS/news', null, true).'" type="application/rss+xml" />'); |
|
81 |
} |
|
82 |
||
83 |
if ( $paths->namespace != 'NewsBoy' ) |
|
84 |
return; |
|
85 |
||
17 | 86 |
if ( $paths->cpage['urlname_nons'] == 'Portal' || preg_match('/^Archive(\/|$)/', $page->page_id) ) |
0 | 87 |
{ |
88 |
||
89 |
// Add admin opener Javascript function |
|
90 |
$template->add_header('<!-- NewsBoy: admin panel nav function --> |
|
4
bf5589120afb
Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents:
3
diff
changeset
|
91 |
<enano:no-opt> |
0 | 92 |
<script type="text/javascript"> |
93 |
function newsboy_open_admin() |
|
94 |
{ |
|
95 |
if ( auth_level < USER_LEVEL_ADMIN ) |
|
96 |
{ |
|
97 |
ajaxPromptAdminAuth(function(k) { |
|
98 |
ENANO_SID = k; |
|
99 |
auth_level = USER_LEVEL_ADMIN; |
|
100 |
var loc = String(window.location + \'\'); |
|
101 |
window.location = append_sid(loc); |
|
102 |
var loc = makeUrlNS(\'Special\', \'Administration\', \'module=\' + namespace_list[\'Admin\'] + \'NewsboyItemManager\'); |
|
103 |
if ( (ENANO_SID + \' \').length > 1 ) |
|
104 |
window.location = loc; |
|
105 |
}, 9); |
|
106 |
return false; |
|
107 |
} |
|
108 |
var loc = makeUrlNS(\'Special\', \'Administration\', \'module=\' + namespace_list[\'Admin\'] + \'NewsboyItemManager\'); |
|
109 |
window.location = loc; |
|
110 |
} |
|
4
bf5589120afb
Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents:
3
diff
changeset
|
111 |
</script> |
bf5589120afb
Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents:
3
diff
changeset
|
112 |
</enano:no-opt>'); |
0 | 113 |
|
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
114 |
if ( !$page->perms->get_permissions('read') ) |
0 | 115 |
{ |
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
116 |
$page->err_access_denied(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
117 |
return false; |
0 | 118 |
} |
119 |
||
120 |
$paths->cpage['comments_on'] = 0; |
|
121 |
||
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
122 |
if ( $page->page_id == 'Portal' ) |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
123 |
{ |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
124 |
$template->header(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
125 |
NewsBoy_portal(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
126 |
$template->footer(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
127 |
} |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
128 |
else if ( preg_match('/^Archive(\/|$)/', $page->page_id) ) |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
129 |
{ |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
130 |
$template->header(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
131 |
NewsBoy_archive(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
132 |
$template->footer(); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
133 |
} |
0 | 134 |
} |
135 |
} |
|
136 |
||
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
137 |
// This is a 1.1.6-and-later thing. |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
138 |
|
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
139 |
if ( class_exists('Namespace_Default') ) |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
140 |
{ |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
141 |
class Namespace_NewsBoy extends Namespace_Default |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
142 |
{ |
13 | 143 |
public $perms, $password, $send_headers; |
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
144 |
|
17 | 145 |
function __construct($page_id, $namespace, $revision = 0) |
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
146 |
{ |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
147 |
global $db, $session, $paths, $template, $plugins; // Common objects |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
148 |
|
17 | 149 |
if ( preg_match('#^Article/#', $page_id) ) |
150 |
{ |
|
151 |
$timestamp = NewsBoy_resolve_article_url($page_id); |
|
152 |
if ( $timestamp ) |
|
153 |
{ |
|
154 |
$page_id = strval($timestamp); |
|
155 |
$template->set_page($page_id, $namespace); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
parent::__construct($page_id, $namespace, $revision); |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
160 |
$this->perms = $session->fetch_page_acl($this->page_id, $this->namespace); |
17 | 161 |
$this->build_cdata(); |
162 |
} |
|
163 |
||
164 |
function build_cdata() |
|
165 |
{ |
|
166 |
if ( $this->page_id == 'Portal' || $this->page_id == 'Article' ) |
|
167 |
{ |
|
168 |
$config_title = getConfig('nb_portal_title'); |
|
169 |
$this->cdata = array( |
|
170 |
'urlname' => $this->page_id, |
|
171 |
'namespace' => $this->namespace, |
|
172 |
'name' => $this->page_id == 'Portal' ? ( !empty($config_title) ? $config_title : "Welcome to " . getConfig('site_name') ) : 'News archive', |
|
173 |
'special' => 1, |
|
174 |
'comments_on' => 0, |
|
175 |
'protected' => 0, |
|
176 |
'wiki_mode' => 0, |
|
177 |
'visible' => 1, |
|
178 |
'delvotes' => 0, |
|
179 |
'delvote_ips' => '' |
|
180 |
); |
|
181 |
$this->cdata = Namespace_Default::bake_cdata($this->cdata); |
|
182 |
$this->title =& $this->cdata['name']; |
|
183 |
} |
|
184 |
else |
|
185 |
{ |
|
186 |
parent::build_cdata(); |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
function set_conds() |
|
191 |
{ |
|
192 |
parent::set_conds(); |
|
193 |
if ( $this->page_id == 'Portal' || $this->page_id == 'Archive' ) |
|
194 |
{ |
|
195 |
$this->conds['edit'] = false; |
|
196 |
$this->conds['password'] = false; |
|
197 |
$this->conds['clearlogs'] = false; |
|
198 |
} |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
199 |
} |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
200 |
|
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
201 |
function send() |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
202 |
{ |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
203 |
ob_start(); |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
204 |
NewsBoy_namespace_handler($this); |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
205 |
if ( ob_get_contents() == '' ) |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
206 |
{ |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
207 |
parent::send(); |
15 | 208 |
} |
209 |
// transfer OB to parent |
|
210 |
$c = ob_get_contents(); |
|
211 |
ob_end_clean(); |
|
212 |
echo $c; |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
213 |
} |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
214 |
} |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
215 |
} |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
216 |
|
17 | 217 |
function NewsBoy_resolve_article_url($url) |
218 |
{ |
|
219 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
220 |
||
221 |
if ( !preg_match('#^Article/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+?)$#', $url, $id_match) ) |
|
222 |
{ |
|
223 |
return false; |
|
224 |
} |
|
225 |
// look around for this page |
|
226 |
// int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] ) |
|
227 |
$timestamp_min = gmmktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1])); |
|
228 |
$timestamp_max = $timestamp_min + 86400; |
|
229 |
// mysql and postgresql friendly |
|
230 |
$integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : ''; |
|
231 |
$q = $db->sql_query('SELECT urlname, name FROM ' . table_prefix . "pages WHERE CAST(urlname AS $integer_prepend integer) >= $timestamp_min AND CAST(urlname AS $integer_prepend integer) <= $timestamp_max AND namespace = 'NewsBoy';"); |
|
232 |
if ( !$q ) |
|
233 |
$db->_die(); |
|
234 |
if ( $db->numrows() < 1 ) |
|
235 |
return false; |
|
236 |
// found a page |
|
237 |
$found_match = false; |
|
238 |
while ( $row = $db->fetchrow($q) ) |
|
239 |
{ |
|
240 |
if ( sanitize_page_id($row['name']) === $id_match[4] ) |
|
241 |
{ |
|
242 |
$found_match = true; |
|
243 |
// we have a definitive match, send the page through |
|
244 |
return $row['urlname']; |
|
245 |
} |
|
246 |
} |
|
247 |
if ( !$found_match ) |
|
248 |
{ |
|
249 |
// can't find it. |
|
250 |
return false; |
|
251 |
} |
|
252 |
return false; |
|
253 |
} |
|
254 |
||
0 | 255 |
function NewsBoy_set_page_string() |
256 |
{ |
|
257 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
258 |
if ( $paths->namespace == 'NewsBoy' ) |
|
259 |
{ |
|
260 |
if ( $paths->cpage['urlname_nons'] == 'Portal' ) |
|
261 |
{ |
|
262 |
$template->namespace_string = 'portal'; |
|
263 |
||
264 |
// block editing |
|
265 |
$perm_arr = Array('edit_page' => AUTH_DENY, 'view_source' => AUTH_DENY); |
|
266 |
$session->acl_merge_with_current($perm_arr, false, 2); |
|
267 |
} |
|
268 |
else |
|
269 |
{ |
|
270 |
$template->namespace_string = 'news item'; |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
||
275 |
function NewsBoy_format_title($title) |
|
276 |
{ |
|
277 |
$title = strtolower($title); |
|
278 |
$title = preg_replace('/\W/', '-', $title); |
|
279 |
$title = preg_replace('/([-]+)/', '-', $title); |
|
280 |
$title = trim($title, '-'); |
|
281 |
return $title; |
|
282 |
} |
|
283 |
||
284 |
function NewsBoy_feed_handler($mode) |
|
285 |
{ |
|
286 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
287 |
||
288 |
if ( $mode != 'news' ) |
|
289 |
return; |
|
290 |
||
291 |
$limit = ( $x = $paths->getParam(1) ) ? $x : 20; |
|
292 |
$limit = intval($limit); |
|
293 |
if ( $limit > 50 ) |
|
294 |
$limit = 50; |
|
295 |
||
296 |
$title = getConfig('site_name') . ': Site news'; |
|
297 |
||
298 |
$x = getConfig('nb_portal_title'); |
|
299 |
$desc = ( empty($x) ) ? 'Welcome to ' . getConfig('site_name') : $x; |
|
300 |
||
301 |
$link = makeUrlComplete('NewsBoy', 'Portal'); |
|
302 |
$generator = 'Enano CMS ' . enano_version() . ' - NewsBoy plugin'; |
|
303 |
$email = getConfig('contact_email'); |
|
304 |
||
305 |
$rss = new RSS($title, $desc, $link, $generator, $email); |
|
306 |
||
307 |
$sql = 'SELECT p.*, l.time_id, l.author, u.user_level,COUNT(c.comment_id) AS num_comments,t.page_text FROM '.table_prefix.'pages AS p |
|
308 |
LEFT JOIN '.table_prefix.'comments AS c |
|
309 |
ON ( c.page_id=p.urlname AND c.namespace=p.namespace ) |
|
310 |
LEFT JOIN '.table_prefix.'logs AS l |
|
311 |
ON ( l.page_id=p.urlname AND l.namespace=p.namespace ) |
|
312 |
LEFT JOIN '.table_prefix.'users AS u |
|
313 |
ON ( u.username=l.author ) |
|
314 |
LEFT JOIN '.table_prefix.'page_text AS t |
|
315 |
ON ( t.page_id=p.urlname AND t.namespace=p.namespace ) |
|
316 |
WHERE p.namespace=\'NewsBoy\' |
|
317 |
AND l.action=\'create\' |
|
318 |
AND p.urlname REGEXP \'^([0-9]+)$\' |
|
319 |
AND p.visible=1 |
|
320 |
GROUP BY p.urlname |
|
321 |
ORDER BY urlname DESC |
|
322 |
LIMIT '.$limit.';'; |
|
323 |
||
324 |
$q = $db->sql_unbuffered_query($sql); |
|
325 |
||
326 |
if ( !$q ) |
|
327 |
$db->_die(); |
|
328 |
||
329 |
$formatter = new NewsBoyFormatter(); |
|
330 |
||
331 |
if ( $row = $db->fetchrow() ) |
|
332 |
{ |
|
333 |
do { |
|
334 |
||
335 |
$title = $row['name']; |
|
336 |
$link = makeUrlComplete('NewsBoy', $row['urlname']); |
|
337 |
$desc = RenderMan::render($row['page_text']); |
|
338 |
$time = intval($row['urlname']); |
|
339 |
||
340 |
$rss->add_item($title, $link, $desc, $time); |
|
341 |
||
342 |
} while ( $row = $db->fetchrow() ); |
|
343 |
} |
|
344 |
else |
|
345 |
{ |
|
346 |
$rss->add_item('Error', $link, 'No news items yet.', time()); |
|
347 |
} |
|
348 |
||
349 |
echo $rss->render(); |
|
350 |
||
351 |
} |
|
352 |
||
353 |
function NewsBoy_portal() |
|
354 |
{ |
|
355 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
356 |
||
5
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
357 |
if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-post.tpl" ) ) |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
358 |
{ |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
359 |
$parser = $template->makeParser("newsboy-post.tpl"); |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
360 |
} |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
361 |
else |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
362 |
{ |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
363 |
$news_template = <<<TPLCODE |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
364 |
<div class="tblholder news"> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
365 |
<table border="0" cellspacing="1" cellpadding="4" style="width: 100%;"> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
366 |
<tr> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
367 |
<th><a href="{LINK}" style="color: inherit;">{TITLE}</a></th> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
368 |
</tr> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
369 |
<tr> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
370 |
<td class="row3"> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
371 |
{CONTENT} |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
372 |
</td> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
373 |
</tr> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
374 |
<tr> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
375 |
<th class="subhead" style="font-weight: normal; font-size: 67%;"> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
376 |
Posted by {USER_LINK} on {DATE}<br /> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
377 |
[ {NUM_COMMENTS} comment{COMMENT_S} | {COMMENT_LINK} ] |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
378 |
</th> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
379 |
</tr> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
380 |
</table> |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
381 |
</div> |
0 | 382 |
TPLCODE; |
383 |
||
5
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
384 |
$parser = $template->makeParserText($news_template); |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
385 |
} |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
386 |
|
0 | 387 |
/* |
388 |
$p = RenderMan::strToPageID(getConfig('main_page')); |
|
389 |
if ( $p[1] != 'NewsBoy' ) |
|
390 |
{ |
|
391 |
echo RenderMan::getPage($p[0], $p[1]); |
|
392 |
} |
|
393 |
else |
|
394 |
{ */ |
|
395 |
/* |
|
396 |
$s = $paths->nslist['NewsBoy'] . 'Announce'; |
|
397 |
if ( isPage($s) ) |
|
398 |
{ |
|
399 |
$p = RenderMan::getPage('Announce', 'NewsBoy'); |
|
400 |
echo $p; |
|
401 |
} |
|
402 |
/* } */ |
|
403 |
||
6 | 404 |
$announce_page_default = $paths->nslist['NewsBoy'] . 'Announce'; |
405 |
$s = $announce_page_default; |
|
0 | 406 |
$announce_page = getConfig('nb_announce_page'); |
407 |
if ( !empty($announce_page) && isPage($announce_page) ) |
|
408 |
{ |
|
409 |
$s = $announce_page; |
|
410 |
} |
|
411 |
else if ( !isPage($s) ) |
|
412 |
{ |
|
413 |
$s = false; |
|
414 |
} |
|
415 |
if ( $s ) |
|
416 |
{ |
|
417 |
$stuff = RenderMan::strToPageID($s); |
|
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
418 |
// Hackish fix to prevent the categorization button and other stuff from being displayed |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
419 |
$paths->pages[$s]['special'] = 1; |
1
540d077b7612
Fix stupid announcement link bug; replace getPage call with PageProcessor
Dan
parents:
0
diff
changeset
|
420 |
$page = new PageProcessor($stuff[0], $stuff[1]); |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
421 |
$content = $page->fetch_text(); |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
422 |
$content = '?>' . RenderMan::render($content); |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
423 |
eval($content); |
0 | 424 |
} |
6 | 425 |
else |
426 |
{ |
|
427 |
$stuff = RenderMan::strToPageID($announce_page_default); |
|
428 |
} |
|
0 | 429 |
|
5
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
430 |
if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-pre.tpl" ) ) |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
431 |
{ |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
432 |
$parser_pre = $template->makeParser("newsboy-portal-pre.tpl"); |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
433 |
echo $parser_pre->run(); |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
434 |
} |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
435 |
else |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
436 |
{ |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
437 |
echo '<h2>Latest news</h2>'; |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
438 |
} |
0 | 439 |
|
440 |
$q = $db->sql_unbuffered_query('SELECT p.*, COUNT(c.comment_id) AS num_comments, t.page_text, l.time_id, l.author, u.user_level FROM '.table_prefix.'pages AS p |
|
441 |
LEFT JOIN '.table_prefix.'comments AS c |
|
442 |
ON ( c.page_id=p.urlname AND c.namespace=p.namespace ) |
|
443 |
LEFT JOIN '.table_prefix.'page_text AS t |
|
444 |
ON ( t.page_id=p.urlname AND t.namespace=p.namespace ) |
|
445 |
LEFT JOIN '.table_prefix.'logs AS l |
|
446 |
ON ( l.page_id=p.urlname AND l.namespace=p.namespace ) |
|
447 |
LEFT JOIN '.table_prefix.'users AS u |
|
448 |
ON ( u.username=l.author OR u.user_id=1 ) |
|
449 |
WHERE p.namespace=\'NewsBoy\' |
|
450 |
AND l.action=\'create\' |
|
451 |
AND p.urlname!=\'Announce\' |
|
452 |
AND p.visible=1 |
|
453 |
GROUP BY p.urlname |
|
454 |
ORDER BY urlname DESC;'); |
|
455 |
if ( !$q ) |
|
456 |
$db->_die(); |
|
457 |
||
16
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
458 |
$num_articles = intval(getConfig('nb_portal_num_articles', 5)); |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
459 |
|
0 | 460 |
if ( $row = $db->fetchrow() ) |
461 |
{ |
|
462 |
$i = 0; |
|
463 |
do |
|
464 |
{ |
|
16
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
465 |
if ( $i < $num_articles ) |
0 | 466 |
{ |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
467 |
$content = $row['page_text']; |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
468 |
|
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
469 |
$trimmed = false; |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
470 |
if ( $pos = strpos($content, '<!--BREAK-->' ) ) |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
471 |
{ |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
472 |
$content = substr($content, 0, $pos); |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
473 |
$trimmed = true; |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
474 |
} |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
475 |
|
0 | 476 |
$title = htmlspecialchars($row['name']); |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
477 |
$content = RenderMan::render($content); |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
478 |
|
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
479 |
if ( strlen($content) > 400 && !$trimmed ) |
0 | 480 |
{ |
481 |
$content = nb_trim_paragraph($content, 400, $trimmed); |
|
482 |
} |
|
483 |
if ( $trimmed ) |
|
484 |
{ |
|
14 | 485 |
$link = ' <a href="' . nb_make_article_url($row['urlname'], $row['name']) . '">Read more...</a>'; |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
486 |
$content = preg_replace('/(.+?)<\/(p|ul|table|div|pre)>([\s]*?)$/Usi', '\\1' . $link . '</\\2>\\3', $content, 1); |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
487 |
if ( !strstr($content, $link) ) |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
488 |
{ |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
489 |
$content .= $link; |
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
490 |
} |
0 | 491 |
} |
492 |
$user_link = nb_make_username_link($row['author'], $row['user_level']); |
|
493 |
$date = date('F d, Y h:i:s a', $row['urlname']); |
|
494 |
$num_comments = $row['num_comments']; |
|
495 |
$comment_s = ( $num_comments == 1 ) ? '' : 's'; |
|
496 |
$comment_link = '<a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '#do:comments" style="color: inherit;">add a comment</a>'; |
|
497 |
$parser->assign_vars(array( |
|
498 |
'TITLE' => $title, |
|
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
499 |
'LINK' => nb_make_article_url($row['urlname'], $row['name']), |
0 | 500 |
'CONTENT' => $content, |
501 |
'USER_LINK' => $user_link, |
|
502 |
'DATE' => $date, |
|
503 |
'NUM_COMMENTS' => $num_comments, |
|
504 |
'COMMENT_S' => $comment_s, |
|
505 |
'COMMENT_LINK' => $comment_link |
|
506 |
)); |
|
507 |
echo $parser->run(); |
|
508 |
} |
|
509 |
else |
|
510 |
{ |
|
511 |
echo '<p><a href="'.makeUrlNS('NewsBoy', 'Archive').'">Older news...</a></p>'; |
|
512 |
break; |
|
513 |
} |
|
514 |
$i++; |
|
515 |
} while ( $row = $db->fetchrow() ); |
|
516 |
} |
|
517 |
else |
|
518 |
{ |
|
519 |
echo '<p>No news items yet.</p>'; |
|
520 |
} |
|
9 | 521 |
$db->free_result(); |
5
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
522 |
if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-post.tpl" ) ) |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
523 |
{ |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
524 |
$parser_post = $template->makeParser("newsboy-portal-post.tpl"); |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
525 |
echo $parser_post->run(); |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
526 |
} |
fed61fc8895b
Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents:
4
diff
changeset
|
527 |
|
0 | 528 |
if ( $session->user_level >= USER_LEVEL_ADMIN ) |
529 |
{ |
|
530 |
echo '<div class="tblholder" style="margin: 10px auto 0 auto; display: table;"> |
|
531 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
532 |
<tr> |
|
533 |
<th>Administrative tools:</th> |
|
3
8ae9acb2e919
Re-implement announcement link fix, blame it on my bad Hg repo management
Dan
parents:
2
diff
changeset
|
534 |
<td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS($stuff[1], $stuff[0], '', true) . '#do:edit">Edit announcement »</a></td> |
0 | 535 |
<td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'NewsboyItemManager', true) . '" onclick="newsboy_open_admin(); return false;">Portal Administration</a></td> |
536 |
</tr> |
|
537 |
</table> |
|
538 |
</div><br />'; |
|
539 |
} |
|
540 |
} |
|
541 |
||
542 |
/** |
|
543 |
* Formats row data in the archive. |
|
544 |
* @package Enano |
|
545 |
* @subpackage Newsboy |
|
546 |
* @license GNU General Public License |
|
547 |
*/ |
|
548 |
||
549 |
class NewsBoyFormatter |
|
550 |
{ |
|
551 |
function article_link($name, $row) |
|
552 |
{ |
|
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
553 |
$article_link = '<a href="' . nb_make_article_url($row['urlname'], $row['name']) . '">' . $row['name'] . '</a>'; |
0 | 554 |
return $article_link; |
555 |
} |
|
556 |
function format_date($date, $row) |
|
557 |
{ |
|
558 |
$date = date('Y-m-j g:m', intval ( $date )); |
|
559 |
return $date; |
|
560 |
} |
|
561 |
function format_username($x, $row) |
|
562 |
{ |
|
563 |
$ul = intval($row['user_level']); |
|
564 |
$author = nb_make_username_link($row['author'], $ul); |
|
565 |
return $author; |
|
566 |
} |
|
567 |
function format_commentlink($x, $row) |
|
568 |
{ |
|
569 |
$comments = '<a href="' . makeUrlNS('NewsBoy', $row['urlname']) . '#do:comments">' . $row['num_comments'] . '</a>'; |
|
570 |
return $comments; |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
function NewsBoy_archive() |
|
575 |
{ |
|
576 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
577 |
||
578 |
$lower_limit = ( isset($_GET['start']) ) ? intval($_GET['start']) : ( ( $xx = $paths->getParam(0) ) ? intval($xx) : 0 ); |
|
579 |
$entries_per_page = 50; |
|
580 |
||
581 |
$row_count = $entries_per_page + 1; |
|
582 |
||
583 |
// Determine number of total news entries |
|
584 |
$q = $db->sql_query('SELECT urlname FROM '.table_prefix.'pages WHERE namespace=\'NewsBoy\' AND urlname REGEXP \'^([0-9]+)$\' AND visible=1;'); |
|
585 |
if ( !$q ) |
|
586 |
$db->_die(); |
|
587 |
$r = $db->fetchrow(); |
|
588 |
$num_total = intval($db->numrows()); |
|
589 |
$db->free_result(); |
|
590 |
||
591 |
if ( $lower_limit >= $num_total ) |
|
592 |
$lower_limit = 0; |
|
593 |
||
594 |
$sql = 'SELECT p.*, l.time_id, l.author, u.user_level,COUNT(c.comment_id) AS num_comments FROM '.table_prefix.'pages AS p |
|
595 |
LEFT JOIN '.table_prefix.'comments AS c |
|
596 |
ON ( c.page_id=p.urlname AND c.namespace=p.namespace ) |
|
597 |
LEFT JOIN '.table_prefix.'logs AS l |
|
598 |
ON ( l.page_id=p.urlname AND l.namespace=p.namespace ) |
|
599 |
LEFT JOIN '.table_prefix.'users AS u |
|
600 |
ON ( u.username=l.author ) |
|
601 |
WHERE p.namespace=\'NewsBoy\' |
|
602 |
AND l.action=\'create\' |
|
603 |
AND p.urlname REGEXP \'^([0-9]+)$\' |
|
604 |
AND p.visible=1 |
|
605 |
GROUP BY p.urlname |
|
606 |
ORDER BY urlname DESC;'; |
|
607 |
||
608 |
$q = $db->sql_unbuffered_query($sql); |
|
609 |
||
610 |
if ( !$q ) |
|
611 |
$db->_die(); |
|
612 |
||
613 |
$formatter = new NewsBoyFormatter(); |
|
614 |
||
615 |
$callers = Array( |
|
616 |
'name' => Array($formatter, 'article_link'), |
|
617 |
'urlname' => Array($formatter, 'format_date'), |
|
618 |
'author' => Array($formatter, 'format_username'), |
|
619 |
'num_comments' => Array($formatter, 'format_commentlink') |
|
620 |
); |
|
621 |
||
622 |
$head = '<div class="tblholder"> |
|
623 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
624 |
<tr> |
|
625 |
<th>Article</th><th>Date</th><th>Author</th><th>Comments</th> |
|
626 |
</tr>'; |
|
627 |
$foot = "</table></div>"; |
|
628 |
||
629 |
$content = paginate($q, "\n".'<tr><td class="{_css_class}">{name}</td><td class="{_css_class}">{urlname}</td><td class="{_css_class}">{author}</td><td class="{_css_class}">{num_comments}</td></tr>', |
|
630 |
$num_total, makeUrlNS('NewsBoy', 'Archive/%s'), $lower_limit, 20, $callers, $head, $foot); |
|
631 |
echo $content; |
|
632 |
||
633 |
$code = $plugins->setHook('send_page_footers'); |
|
634 |
foreach ( $code as $cmd ) |
|
635 |
{ |
|
636 |
eval($cmd); |
|
637 |
} |
|
638 |
||
639 |
} |
|
640 |
||
641 |
function nb_make_username_link($username, $user_level) |
|
642 |
{ |
|
643 |
$color = '#0000AA'; |
|
644 |
$user_level = intval($user_level); |
|
645 |
if ( $user_level < USER_LEVEL_MEMBER ) return $username; |
|
646 |
if ( $user_level >= USER_LEVEL_MOD ) $color = '#00AA00'; |
|
647 |
if ( $user_level >= USER_LEVEL_ADMIN ) $color = '#AA0000'; |
|
648 |
$link = '<a style="color: ' . $color . '" href="' . makeUrlNS('User', str_replace(' ', '_', $username) ) . '">' . $username . '</a>'; |
|
649 |
return $link; |
|
650 |
} |
|
651 |
||
652 |
function NewsBoy_PortalLink() |
|
653 |
{ |
|
654 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
655 |
if ( $paths->namespace == 'NewsBoy' ) |
|
656 |
echo '<div class="tblholder"><table border="0" style="width: 100%;" cellspacing="1" cellpadding="4"><tr><th><a style="color: inherit;" href="' . makeUrlNS('NewsBoy', 'Portal') . '">« Return to News Portal</a></th></tr></table></div><br />'; |
|
657 |
} |
|
658 |
||
659 |
// Administration panel |
|
660 |
function page_Admin_NewsboyItemManager() |
|
661 |
{ |
|
662 |
global $db, $session, $paths, $template, $plugins; if($session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN) { redirect(makeUrlNS('Special', 'Administration', 'noheaders', true), '', '', 0); die('Hacking attempt'); } |
|
663 |
||
664 |
$done = false; |
|
665 |
||
666 |
if ( isset( $_GET['act'] ) ) |
|
667 |
{ |
|
668 |
switch ( $_GET['act'] ) |
|
669 |
{ |
|
670 |
case 'edit': |
|
671 |
||
672 |
// Error list |
|
673 |
$errors = Array(); |
|
674 |
||
675 |
if ( isset ( $_POST['submitting'] ) ) |
|
676 |
{ |
|
677 |
// Generate timestamp |
|
678 |
$year = intval($_POST['pub_year']); |
|
679 |
$month = intval($_POST['pub_month']); |
|
680 |
$day = intval($_POST['pub_day']); |
|
681 |
$hour = intval($_POST['pub_hour']); |
|
682 |
$minute = intval($_POST['pub_minute']); |
|
683 |
$second = intval($_POST['pub_second']); |
|
684 |
||
685 |
// Validation |
|
686 |
if ( $year < 1500 || $year > 10000 ) |
|
687 |
$errors[] = 'Invalid year.'; |
|
688 |
||
689 |
if ( $month < 1 || $month > 12 ) |
|
690 |
$errors[] = 'Invalid month.'; |
|
691 |
||
692 |
if ( $day < 1 || $day > 31 ) |
|
693 |
$errors[] = 'Invalid day.'; |
|
694 |
||
695 |
if ( $hour < 0 || $hour > 23 ) |
|
696 |
$errors[] = 'Invalid hour.'; |
|
697 |
||
698 |
if ( $minute < 0 || $minute > 60 ) |
|
699 |
$errors[] = 'Invalid minute.'; |
|
700 |
||
701 |
if ( $second < 0 || $second > 60 ) |
|
702 |
$errors[] = 'Invalid second.'; |
|
703 |
||
704 |
$name = $_POST['article_name']; |
|
705 |
$name = $db->escape($name); |
|
706 |
||
707 |
$author = $_POST['author']; |
|
708 |
$author = $db->escape($author); |
|
709 |
||
710 |
if ( count($errors) < 1 ) |
|
711 |
{ |
|
712 |
$time = mktime($hour, $minute, $second, $month, $day, $year); |
|
713 |
} |
|
714 |
||
715 |
if ( isset($paths->pages[ $paths->nslist['NewsBoy'] . $time ]) && $paths->pages[ $paths->nslist['NewsBoy'] . $time ] != $paths->pages[ $paths->nslist['NewsBoy'] . $_POST['page_id'] ] ) |
|
716 |
$errors[] = 'You cannot have two news articles with the same publish time.'; |
|
717 |
||
718 |
if ( count($errors) < 1 ) |
|
719 |
{ |
|
720 |
$publ = ( isset($_POST['published']) ) ? '1' : '0'; |
|
721 |
$sql = 'UPDATE '.table_prefix.'pages SET name=\'' . $name . '\',visible='.$publ.',urlname=\''.$time.'\' WHERE urlname=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';'; |
|
722 |
$q = $db->sql_query($sql); |
|
723 |
||
724 |
if ( !$q ) |
|
725 |
$db->_die(); |
|
726 |
||
727 |
// Update author |
|
728 |
$q = $db->sql_query('UPDATE '.table_prefix.'logs SET author=\'' . $author . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\' AND action=\'create\';'); |
|
729 |
||
730 |
if ( !$q ) |
|
731 |
$db->_die(); |
|
732 |
||
733 |
// Update other tables with urlname info |
|
734 |
$q = $db->sql_query('UPDATE '.table_prefix.'logs SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';'); |
|
735 |
if ( !$q ) |
|
736 |
$db->_die(); |
|
737 |
||
738 |
$q = $db->sql_query('UPDATE '.table_prefix.'comments SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';'); |
|
739 |
if ( !$q ) |
|
740 |
$db->_die(); |
|
741 |
||
742 |
$q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';'); |
|
743 |
if ( !$q ) |
|
744 |
$db->_die(); |
|
745 |
||
746 |
$q = $db->sql_query('UPDATE '.table_prefix.'categories SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';'); |
|
747 |
if ( !$q ) |
|
748 |
$db->_die(); |
|
749 |
||
750 |
echo '<div class="info-box">Your changes have been saved.</div>'; |
|
751 |
||
752 |
break; |
|
753 |
} |
|
754 |
} |
|
755 |
||
756 |
if ( count($errors) > 0 ) |
|
757 |
echo '<div class="warning-box">Errors encountered while saving data:<ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>'; |
|
758 |
||
759 |
// Obtain page information |
|
760 |
if ( !isset($paths->pages[ $paths->nslist['NewsBoy'] . $_GET['id'] ]) ) |
|
761 |
{ |
|
762 |
echo 'Invalid ID'; |
|
763 |
return false; |
|
764 |
} |
|
765 |
$page_info =& $paths->pages[ $paths->nslist['NewsBoy'] . $_GET['id'] ]; |
|
766 |
$time = intval($page_info['urlname_nons']); |
|
767 |
||
768 |
// Get author |
|
769 |
$q = $db->sql_query('SELECT author FROM '.table_prefix.'logs WHERE page_id=\'' . $db->escape($page_info['urlname_nons']) . '\' AND namespace=\'NewsBoy\' AND action=\'create\' ORDER BY time_id DESC LIMIT 1;'); |
|
770 |
||
771 |
if ( !$q ) |
|
772 |
$db->_die(); |
|
773 |
||
774 |
$row = $db->fetchrow(); |
|
775 |
$author = ( isset($row['author']) ) ? $row['author'] : ''; |
|
776 |
if ( empty($author) ) |
|
777 |
$author = 'Anonymous'; |
|
778 |
||
779 |
// Set date & time |
|
780 |
$month = date('n', $time); |
|
781 |
$year = date('Y', $time); |
|
782 |
$day = date('j', $time); |
|
783 |
$hour = date('G', $time); |
|
784 |
$minute = date('m', $time); |
|
785 |
$second = date('s', $time); |
|
786 |
||
787 |
echo '<form id="nb_edit_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&' : '') .'module='.$paths->cpage['module'] . '&act=edit').'" method="post" onsubmit="if ( !submitAuthorized ) return false;">'; |
|
788 |
echo '<div class="tblholder"> |
|
789 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
790 |
<tr> |
|
791 |
<th colspan="2">Editing news article</th> |
|
792 |
</tr> |
|
793 |
<tr> |
|
794 |
<td class="row1">Article name:</td><td class="row2"><input name="article_name" value="' . htmlspecialchars($page_info['name']) . '" /></td> |
|
795 |
</tr> |
|
796 |
<tr> |
|
797 |
<td class="row1">Published date:</td> |
|
798 |
<td class="row2"> |
|
799 |
<input name="pub_year" type="text" size="5" value="'.$year.'" />-<select name="pub_month">'; |
|
800 |
for ( $i = 1; $i <= 12; $i++ ) |
|
801 |
{ |
|
802 |
$m = "[$i] "; |
|
803 |
switch ( $i ) |
|
804 |
{ |
|
805 |
case 1: $m .= 'January'; break; |
|
806 |
case 2: $m .= 'February'; break; |
|
807 |
case 3: $m .= 'March'; break; |
|
808 |
case 4: $m .= 'April'; break; |
|
809 |
case 5: $m .= 'May'; break; |
|
810 |
case 6: $m .= 'June'; break; |
|
811 |
case 7: $m .= 'July'; break; |
|
812 |
case 8: $m .= 'August'; break; |
|
813 |
case 9: $m .= 'September'; break; |
|
814 |
case 10: $m .= 'October'; break; |
|
815 |
case 11: $m .= 'November'; break; |
|
816 |
case 12: $m .= 'December'; break; |
|
817 |
default: $m .= 'Fuhrober'; break; |
|
818 |
} |
|
819 |
if ( $month == $i ) |
|
820 |
echo ' <option selected="selected" value="' . $i . '">'.$m.'</option>'; |
|
821 |
else |
|
822 |
echo ' <option value="' . $i . '">'.$m.'</option>'; |
|
823 |
} |
|
824 |
echo ' </select> |
|
825 |
<input name="pub_day" type="text" size="3" value="' . $day . '" />, time: |
|
826 |
<input name="pub_hour" type="text" size="3" value="' . $hour . '" /> : <input name="pub_minute" type="text" size="3" value="' . $minute . '" /> : <input name="pub_second" type="text" size="3" value="' . $second . '" /><br /> |
|
827 |
<small>Note: Hours are in 24-hour format.</small> |
|
828 |
</td> |
|
829 |
</tr> |
|
830 |
<!-- Inline developer blog, episode 1: |
|
831 |
Right about the time I got here, I started sneezing like crazy. Must have caught it Friday night. Great... now |
|
832 |
my life is officially stuck on pause for the next 3 days. I\'d swear here but (a) Mommy taught me better, and |
|
833 |
(b) I wouldn\'t want to offend you hackers. (j/k) |
|
834 |
||
835 |
Oh crap. And no, I don\'t give towels with my showers. |
|
836 |
||
837 |
-Dan |
|
838 |
--> |
|
839 |
<tr> |
|
840 |
<td class="row1">Publish article:</td><td class="row2"><label><input name="published" type="checkbox" ' . ( $page_info['visible'] == 1 ? 'checked="checked"' : '' ) . ' /> Article is published (shown to the public)</label></td> |
|
841 |
</tr> |
|
842 |
<tr> |
|
843 |
<td class="row1">Article author:</td><td class="row2">' . $template->username_field('author', $author) . '</td></tr> |
|
844 |
</tr> |
|
845 |
<tr> |
|
846 |
<td class="row3" style="text-align: center;" colspan="2"> |
|
847 |
<a href="#" onclick="var frm = document.getElementById(\'nb_edit_form\'); frm.submit(); return false;">Save changes</a> <a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Return to main menu</a> |
|
848 |
</td> |
|
849 |
</tr> |
|
850 |
</table> |
|
851 |
</div> |
|
852 |
<input type="hidden" name="submitting" value="yes" /> |
|
853 |
<input type="hidden" name="page_id" value="' . $_GET['id'] . '" />'; |
|
854 |
echo '</form>'; |
|
855 |
$done = true; |
|
856 |
break; |
|
857 |
case 'del': |
|
858 |
if ( isset( $_POST['confirmed'] ) ) |
|
859 |
{ |
|
860 |
$page_id = $_POST['page_id']; |
|
861 |
$namespace = 'NewsBoy'; |
|
862 |
||
863 |
$e = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'delete\', \''.$page_id.'\', \''.$namespace.'\', \''.$session->username.'\')'); |
|
864 |
if(!$e) $db->_die('The page log entry could not be inserted.'); |
|
865 |
$e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
|
866 |
if(!$e) $db->_die('The page categorization entries could not be deleted.'); |
|
867 |
$e = $db->sql_query('DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
|
868 |
if(!$e) $db->_die('The page comments could not be deleted.'); |
|
869 |
$e = $db->sql_query('DELETE FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
|
870 |
if(!$e) $db->_die('The page text entry could not be deleted.'); |
|
871 |
$e = $db->sql_query('DELETE FROM '.table_prefix.'pages WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\''); |
|
872 |
if(!$e) $db->_die('The page entry could not be deleted.'); |
|
873 |
||
874 |
$result = 'This page has been deleted. Note that there is still a log of edits and actions in the database, and anyone with admin rights can raise this page from the dead unless the log is cleared. If the deleted file is an image, there may still be cached thumbnails of it in the cache/ directory, which is inaccessible to users.'; |
|
875 |
||
876 |
echo $result . '<br /> |
|
877 |
<br /> |
|
15 | 878 |
<a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\'); return false;">Return to Newsboy</a>'; |
0 | 879 |
} |
880 |
else |
|
881 |
{ |
|
882 |
echo '<form id="nb_delete_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&' : '') .'module='.$paths->cpage['module'] . '&act=del').'" method="post">'; |
|
883 |
echo '<div class="tblholder"> |
|
884 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
885 |
<tr> |
|
886 |
<th>Confirm deletion</th> |
|
887 |
</tr> |
|
888 |
<tr> |
|
889 |
<td class="row1" style="text-align: center;"> |
|
890 |
<p>Are you sure you want to delete this news article?</p> |
|
891 |
</td> |
|
892 |
</tr> |
|
893 |
<tr> |
|
894 |
<td class="row3" style="text-align: center;"> |
|
895 |
<a href="#" onclick="var frm = document.getElementById(\'nb_delete_form\'); frm.submit(); return false;">Delete</a> <a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Cancel</a> |
|
896 |
</td> |
|
897 |
</tr> |
|
898 |
</table> |
|
899 |
</div> |
|
900 |
<input type="hidden" name="confirmed" value="yes" /> |
|
901 |
<input type="hidden" name="page_id" value="' . intval ( $_GET['id'] ) . '" />'; |
|
902 |
echo '</form>'; |
|
903 |
} |
|
904 |
$done = true; |
|
905 |
break; |
|
906 |
case 'create': |
|
907 |
||
908 |
// Error list |
|
909 |
$errors = Array(); |
|
910 |
||
911 |
if ( isset ( $_POST['submitting'] ) ) |
|
912 |
{ |
|
913 |
// Generate timestamp |
|
914 |
$year = intval($_POST['pub_year']); |
|
915 |
$month = intval($_POST['pub_month']); |
|
916 |
$day = intval($_POST['pub_day']); |
|
917 |
$hour = intval($_POST['pub_hour']); |
|
918 |
$minute = intval($_POST['pub_minute']); |
|
919 |
$second = intval($_POST['pub_second']); |
|
920 |
||
921 |
// Validation |
|
922 |
if ( $year < 1500 || $year > 10000 ) |
|
923 |
$errors[] = 'Invalid year.'; |
|
924 |
||
925 |
if ( $month < 1 || $month > 12 ) |
|
926 |
$errors[] = 'Invalid month.'; |
|
927 |
||
928 |
if ( $day < 1 || $day > 31 ) |
|
929 |
$errors[] = 'Invalid day.'; |
|
930 |
||
931 |
if ( $hour < 0 || $hour > 23 ) |
|
932 |
$errors[] = 'Invalid hour.'; |
|
933 |
||
934 |
if ( $minute < 0 || $minute > 60 ) |
|
935 |
$errors[] = 'Invalid minute.'; |
|
936 |
||
937 |
if ( $second < 0 || $second > 60 ) |
|
938 |
$errors[] = 'Invalid second.'; |
|
939 |
||
940 |
$name = $_POST['article_name']; |
|
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
941 |
// This is db-escaped by PageUtils |
0 | 942 |
|
943 |
$author = $_POST['author']; |
|
944 |
$author = $db->escape($author); |
|
945 |
||
946 |
if ( count($errors) < 1 ) |
|
947 |
{ |
|
948 |
$time = mktime($hour, $minute, $second, $month, $day, $year); |
|
949 |
} |
|
950 |
||
951 |
if ( isset($paths->pages[ $paths->nslist['NewsBoy'] . $time ]) && $paths->pages[ $paths->nslist['NewsBoy'] . $time ] != $paths->pages[ $paths->nslist['NewsBoy'] . $_POST['page_id'] ] ) |
|
952 |
$errors[] = 'You cannot have two news articles with the same publish time.'; |
|
953 |
||
954 |
if ( count($errors) < 1 ) |
|
955 |
{ |
|
956 |
$publ = ( isset($_POST['published']) ) ? 1 : 0; |
|
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
957 |
|
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
958 |
$page = new PageProcessor((string)$time, 'NewsBoy'); |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
959 |
$page->create_page($name, $publ); |
0 | 960 |
|
15 | 961 |
if ( $page->update_page($_POST['content'], 'Initial revision', false, 'wikitext') ) |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
962 |
{ |
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
963 |
echo '<div class="info-box">Your changes have been saved.</div>'; |
15 | 964 |
break; |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
965 |
} |
0 | 966 |
else |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
967 |
{ |
10
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
968 |
while ( $err = $page->pop_error() ) |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
969 |
{ |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
970 |
$errors[] = $err; |
0d52ee49c11c
Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents:
9
diff
changeset
|
971 |
} |
15 | 972 |
$done = false; |
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
973 |
} |
0 | 974 |
} |
975 |
} |
|
976 |
||
977 |
if ( count($errors) > 0 ) |
|
978 |
echo '<div class="warning-box">Errors encountered while preparing data:<ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>'; |
|
979 |
||
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
980 |
$time = time(); |
0 | 981 |
|
982 |
// Get author |
|
983 |
$author = $session->username; |
|
984 |
||
985 |
if ( empty($author) ) |
|
986 |
$author = 'Anonymous'; |
|
987 |
||
988 |
// Set date & time |
|
989 |
$month = date('n', $time); |
|
990 |
$year = date('Y', $time); |
|
991 |
$day = date('j', $time); |
|
992 |
$hour = date('G', $time); |
|
993 |
$minute = date('m', $time); |
|
994 |
$second = date('s', $time); |
|
995 |
||
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
996 |
echo '<form id="nb_create_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&' : '') .'module='.$paths->cpage['module'] . '&act=create').'" method="post" onsubmit="if ( !submitAuthorized ) return false;">'; |
0 | 997 |
echo '<div class="tblholder"> |
998 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
999 |
<tr> |
|
1000 |
<th colspan="2">Creating news article</th> |
|
1001 |
</tr> |
|
1002 |
<tr> |
|
1003 |
<td class="row1">Article name:</td><td class="row2"><input name="article_name" value="" /></td> |
|
1004 |
</tr> |
|
1005 |
<tr> |
|
1006 |
<td class="row1">Published datestamp:</td> |
|
1007 |
<td class="row2"> |
|
1008 |
<input name="pub_year" type="text" size="5" value="'.$year.'" />-<select name="pub_month">'; |
|
1009 |
for ( $i = 1; $i <= 12; $i++ ) |
|
1010 |
{ |
|
1011 |
$m = "[$i] "; |
|
1012 |
switch ( $i ) |
|
1013 |
{ |
|
1014 |
case 1: $m .= 'January'; break; |
|
1015 |
case 2: $m .= 'February'; break; |
|
1016 |
case 3: $m .= 'March'; break; |
|
1017 |
case 4: $m .= 'April'; break; |
|
1018 |
case 5: $m .= 'May'; break; |
|
1019 |
case 6: $m .= 'June'; break; |
|
1020 |
case 7: $m .= 'July'; break; |
|
1021 |
case 8: $m .= 'August'; break; |
|
1022 |
case 9: $m .= 'September'; break; |
|
1023 |
case 10: $m .= 'October'; break; |
|
1024 |
case 11: $m .= 'November'; break; |
|
1025 |
case 12: $m .= 'December'; break; |
|
1026 |
default: $m .= 'Fuhrober'; break; |
|
1027 |
} |
|
1028 |
if ( $month == $i ) |
|
1029 |
echo ' <option selected="selected" value="' . $i . '">'.$m.'</option>'; |
|
1030 |
else |
|
1031 |
echo ' <option value="' . $i . '">'.$m.'</option>'; |
|
1032 |
} |
|
1033 |
echo ' </select> |
|
1034 |
<input name="pub_day" type="text" size="3" value="' . $day . '" />, time: |
|
1035 |
<input name="pub_hour" type="text" size="3" value="' . $hour . '" /> : <input name="pub_minute" type="text" size="3" value="' . $minute . '" /> : <input name="pub_second" type="text" size="3" value="' . $second . '" /><br /> |
|
1036 |
<small>Note: Hours are in 24-hour format.</small> |
|
1037 |
</td> |
|
1038 |
</tr> |
|
1039 |
<tr> |
|
1040 |
<td class="row1">Publish article:</td><td class="row2"><label><input name="published" type="checkbox" /> Article is published (shown to the public)</label></td> |
|
1041 |
</tr> |
|
1042 |
<tr> |
|
1043 |
<td class="row1">Article author:</td><td class="row2">' . $template->username_field('author', $author) . '</td></tr> |
|
1044 |
</tr> |
|
1045 |
<tr> |
|
1046 |
<td class="row1">Initial content:<br /><small>You can always edit this later.</small></td><td class="row2"><textarea name="content" rows="15" cols="60" style="width: 100%;"></textarea></td> |
|
1047 |
</tr> |
|
1048 |
<tr> |
|
1049 |
<td class="row3" style="text-align: center;" colspan="2"> |
|
1050 |
<a href="#" onclick="var frm = document.getElementById(\'nb_create_form\'); frm.submit(); return false;">Create article</a> <a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Return to main menu</a> |
|
1051 |
</td> |
|
1052 |
</tr> |
|
1053 |
</table> |
|
1054 |
</div> |
|
1055 |
<input type="hidden" name="submitting" value="yes" />'; |
|
1056 |
echo '</form>'; |
|
1057 |
||
1058 |
$done = true; |
|
1059 |
break; |
|
1060 |
} |
|
1061 |
} |
|
1062 |
||
1063 |
if ( !$done ) |
|
1064 |
{ |
|
1065 |
||
1066 |
// Start output |
|
1067 |
echo '<div class="tblholder"> |
|
1068 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
1069 |
<tr> |
|
1070 |
<th>Name</th> |
|
1071 |
<th>Date published</th> |
|
1072 |
<th colspan="3">Actions</th> |
|
1073 |
</tr>'; |
|
1074 |
||
1075 |
$row_class = 'row2'; |
|
1076 |
||
1077 |
// List existing news entries |
|
1078 |
$q = $db->sql_query('SELECT name,urlname FROM '.table_prefix.'pages WHERE namespace="NewsBoy" AND urlname!="Announce" ORDER BY name ASC;'); |
|
1079 |
||
1080 |
if ( !$q ) |
|
1081 |
$db->_die(); |
|
1082 |
||
1083 |
if ( $row = $db->fetchrow($q) ) |
|
1084 |
{ |
|
1085 |
do { |
|
1086 |
$row_class = ( $row_class == 'row1' ) ? 'row2' : 'row1'; |
|
1087 |
$ts = intval($row['urlname']); |
|
1088 |
$date = date('F d, Y h:i a', $ts); |
|
1089 |
$edit_url = makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=edit&id={$row['urlname']}", true); |
|
1090 |
$dele_url = makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=del&id={$row['urlname']}", true); |
|
1091 |
$page_url = makeUrlNS('NewsBoy', $row['urlname']); |
|
1092 |
echo "<tr> |
|
1093 |
<td class='$row_class' style='width: 50%;'> |
|
1094 |
{$row['name']} |
|
1095 |
</td> |
|
1096 |
<td class='$row_class' style='width: 40%;'> |
|
1097 |
$date |
|
1098 |
</td> |
|
1099 |
<td class='$row_class'> |
|
1100 |
<a href='$edit_url'>Settings</a> |
|
1101 |
</td> |
|
1102 |
<td class='$row_class'> |
|
1103 |
<a href='$page_url' onclick='window.open(this.href); return false;'>Page</a> |
|
1104 |
</td> |
|
1105 |
<td class='$row_class'> |
|
1106 |
<a href='$dele_url'>Delete</a> |
|
1107 |
</td> |
|
1108 |
</tr>"; |
|
1109 |
} while ( $row = $db->fetchrow($q) ); |
|
1110 |
} |
|
1111 |
else |
|
1112 |
{ |
|
1113 |
echo '<tr><td class="row3" colspan="5" style="text-align: center;">No news items yet.</td></tr>'; |
|
1114 |
} |
|
1115 |
echo '<tr><th class="subhead" colspan="5"><a href="' . makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=create", true) . '" style="color: inherit;">Create new entry</a></th></tr> |
|
1116 |
</table></div>'; |
|
1117 |
$db->free_result(); |
|
1118 |
||
1119 |
} |
|
1120 |
||
1121 |
} |
|
1122 |
||
1123 |
function page_Admin_NewsboyConfiguration() |
|
1124 |
{ |
|
1125 |
global $db, $session, $paths, $template, $plugins; if($session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN) { redirect(makeUrlNS('Special', 'Administration', 'noheaders', true), '', '', 0); die('Hacking attempt'); } |
|
1126 |
if ( isset($_POST['submit']) ) |
|
1127 |
{ |
|
1128 |
setConfig('nb_portal_title', $_POST['portal_name']); |
|
1129 |
if ( isPage($_POST['announce_page']) ) |
|
1130 |
setConfig('nb_announce_page', $_POST['announce_page']); |
|
1131 |
else |
|
1132 |
setConfig('nb_announce_page', ''); |
|
16
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1133 |
|
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1134 |
$num_articles = intval($_POST['num_articles']); |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1135 |
if ( $num_articles > 0 ) |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1136 |
setConfig('nb_portal_num_articles', $num_articles); |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1137 |
|
0 | 1138 |
// Submit |
1139 |
echo '<div class="info-box">Your changes have been saved.</div>'; |
|
1140 |
} |
|
1141 |
echo '<form name="main" action="'.htmlspecialchars(makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module'])).'" method="post">'; |
|
1142 |
echo '<div class="tblholder"> |
|
1143 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
1144 |
<tr> |
|
1145 |
<th colspan="2"> |
|
1146 |
Newsboy portal: General configuration |
|
1147 |
</th> |
|
1148 |
</tr> |
|
1149 |
<tr> |
|
1150 |
<td class="row2"> |
|
1151 |
Portal title:<br /> |
|
1152 |
<small>This is the text that will be shown as the page title on the<br /> |
|
1153 |
portal. If you don\'t enter anything here, a default will be used.</small> |
|
1154 |
</td> |
|
1155 |
<td class="row1"><input type="text" size="30" name="portal_name" value="' . htmlspecialchars(getConfig('nb_portal_title')) . '"></td> |
|
1156 |
</tr> |
|
1157 |
<tr> |
|
1158 |
<td class="row2"> |
|
1159 |
Page to embed as announcement:<br /> |
|
1160 |
<small>The page you enter here will always be shown at the top of the<br /> |
|
1161 |
portal. The default is "' . $paths->nslist['NewsBoy'] . 'Announce".</small> |
|
1162 |
</td> |
|
1163 |
<td class="row1"> |
|
1164 |
' . $template->pagename_field('announce_page', htmlspecialchars(getConfig('nb_announce_page'))) . ' |
|
1165 |
</td> |
|
1166 |
</tr> |
|
1167 |
<tr> |
|
16
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1168 |
<td class="row2"> |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1169 |
Number of articles to show on portal: |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1170 |
</td> |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1171 |
<td class="row1"> |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1172 |
<input type="text" name="num_articles" value="' . getConfig('nb_portal_num_articles', '5') . '" size="7" /> |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1173 |
</td> |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1174 |
</tr> |
3d96dbb770b5
Added ability to change number of articles shown on portal.
Dan
parents:
15
diff
changeset
|
1175 |
<tr> |
0 | 1176 |
<th class="subhead" colspan="2"> |
1177 |
<input type="submit" name="submit" value="Save changes" /> |
|
1178 |
</th> |
|
1179 |
</tr> |
|
1180 |
</table> |
|
1181 |
</div>'; |
|
1182 |
echo '</form>'; |
|
1183 |
} |
|
1184 |
||
1185 |
/** |
|
1186 |
* Trims a wad of text to the specified length. |
|
1187 |
* @todo make HTML friendly (don't break tags) |
|
1188 |
* @param string The text to trim |
|
1189 |
* @param int The maximum length to trim the text to. |
|
1190 |
* @param bool Reference. Set to true if the text was trimmed, otherwise set to false. |
|
1191 |
*/ |
|
1192 |
||
2
66b299fdb9ca
Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents:
1
diff
changeset
|
1193 |
function nb_trim_paragraph($text, $len = 500, &$trimmed) |
0 | 1194 |
{ |
1195 |
$trimmed = false; |
|
1196 |
if ( strlen($text) <= $len ) |
|
1197 |
return $text; |
|
1198 |
$trimmed = true; |
|
1199 |
$text = substr($text, 0, $len); |
|
1200 |
for ( $i = $len; $i > 0; $i-- ) |
|
1201 |
{ |
|
1202 |
$chr = $text{$i-1}; |
|
1203 |
if ( preg_match('/[\s]/', $chr) ) |
|
1204 |
{ |
|
1205 |
$text = substr($text, 0, $i - 1); |
|
1206 |
$text .= '...'; |
|
1207 |
return $text; |
|
1208 |
} |
|
1209 |
$text = substr($text, 0, $i); |
|
1210 |
} |
|
1211 |
return $text; |
|
1212 |
} |
|
1213 |
||
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1214 |
/** |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1215 |
* Generates a link to the given Newsboy article given the article name and timestamp |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1216 |
* @param int Article timestamp |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1217 |
* @param string Article title |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1218 |
* @return string |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1219 |
*/ |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1220 |
|
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1221 |
function nb_make_article_url($timestamp, $title = false) |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1222 |
{ |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1223 |
if ( !$title ) |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1224 |
return makeUrlNS('NewsBoy', $timestamp); |
9 | 1225 |
$day = gmdate('d', $timestamp); |
1226 |
$year = gmdate('Y', $timestamp); |
|
1227 |
$month = gmdate('m', $timestamp); |
|
7
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1228 |
return makeUrlNS('NewsBoy', "Article/$year/$month/$day/" . sanitize_page_id($title)); |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1229 |
} |
c3710cbed6d0
Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents:
6
diff
changeset
|
1230 |
|
0 | 1231 |
?> |