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