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