22 |
22 |
23 // Insert our News namespace |
23 // Insert our News namespace |
24 $plugins->attachHook('acl_rule_init', 'NewsBoy_namespace_setup($this);'); |
24 $plugins->attachHook('acl_rule_init', 'NewsBoy_namespace_setup($this);'); |
25 |
25 |
26 // Hook into page rendering |
26 // Hook into page rendering |
27 $plugins->attachHook('page_not_found', 'NewsBoy_namespace_handler();'); |
27 $plugins->attachHook('page_not_found', 'NewsBoy_namespace_handler($this);'); |
28 $plugins->attachHook('send_page_footers', 'NewsBoy_PortalLink();'); |
28 $plugins->attachHook('send_page_footers', 'NewsBoy_PortalLink();'); |
29 |
29 |
30 // String to determine page type string |
30 // String to determine page type string |
31 $plugins->attachHook('page_type_string_set', 'NewsBoy_set_page_string();'); |
31 $plugins->attachHook('page_type_string_set', 'NewsBoy_set_page_string();'); |
32 |
32 |
68 $session->acl_extend_scope('php_in_pages', 'NewsBoy', $paths); |
68 $session->acl_extend_scope('php_in_pages', 'NewsBoy', $paths); |
69 $session->acl_extend_scope('edit_acl', 'NewsBoy', $paths); |
69 $session->acl_extend_scope('edit_acl', 'NewsBoy', $paths); |
70 |
70 |
71 } |
71 } |
72 |
72 |
73 function NewsBoy_namespace_handler() |
73 function NewsBoy_namespace_handler($page) |
74 { |
74 { |
75 global $db, $session, $paths, $template, $plugins; // Common objects |
75 global $db, $session, $paths, $template, $plugins; // Common objects |
76 |
76 |
77 if ( defined('ENANO_FEEDBURNER_INCLUDED') ) |
77 if ( defined('ENANO_FEEDBURNER_INCLUDED') ) |
78 { |
78 { |
80 } |
80 } |
81 |
81 |
82 if ( $paths->namespace != 'NewsBoy' ) |
82 if ( $paths->namespace != 'NewsBoy' ) |
83 return; |
83 return; |
84 |
84 |
85 $chk = $paths->page; |
85 if ( $paths->cpage['urlname_nons'] == 'Portal' || preg_match('/^Archive(\/|$)/', $page->page_id) || preg_match('/^Article\//', $page->page_id) ) |
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 { |
86 { |
91 |
87 |
92 // Add admin opener Javascript function |
88 // Add admin opener Javascript function |
93 $template->add_header('<!-- NewsBoy: admin panel nav function --> |
89 $template->add_header('<!-- NewsBoy: admin panel nav function --> |
94 <enano:no-opt> |
90 <enano:no-opt> |
120 ( ( empty($x) ) ? |
116 ( ( empty($x) ) ? |
121 'Welcome to ' . getConfig('site_name') : |
117 'Welcome to ' . getConfig('site_name') : |
122 $x ) : |
118 $x ) : |
123 'News Archive'; |
119 'News Archive'; |
124 |
120 |
125 if ( !$session->get_permissions('read') ) |
121 if ( !$page->perms->get_permissions('read') ) |
126 { |
122 { |
127 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>'); |
123 $page->err_access_denied(); |
|
124 return false; |
128 } |
125 } |
129 |
126 |
130 $paths->cpage['comments_on'] = 0; |
127 $paths->cpage['comments_on'] = 0; |
131 |
128 |
132 $template->header(); |
129 if ( $page->page_id == 'Portal' ) |
133 ( $paths->cpage['urlname_nons'] == 'Portal' ) ? NewsBoy_portal() : NewsBoy_archive(); |
130 { |
134 $template->footer(); |
131 $template->header(); |
|
132 NewsBoy_portal(); |
|
133 $template->footer(); |
|
134 } |
|
135 else if ( preg_match('/^Archive(\/|$)/', $page->page_id) ) |
|
136 { |
|
137 $template->header(); |
|
138 NewsBoy_archive(); |
|
139 $template->footer(); |
|
140 } |
|
141 else if ( preg_match('/^Article\//', $page->page_id) ) |
|
142 { |
|
143 if ( !preg_match('#^Article/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.+?)$#', $page->page_id, $id_match) ) |
|
144 { |
|
145 return; |
|
146 } |
|
147 // look around for this page |
|
148 // int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] ) |
|
149 $timestamp_min = mktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1])); |
|
150 $timestamp_max = $timestamp_min + 86400; |
|
151 // mysql and postgresql friendly |
|
152 $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : ''; |
|
153 $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';"); |
|
154 if ( !$q ) |
|
155 $db->_die(); |
|
156 if ( $db->numrows() < 1 ) |
|
157 return; |
|
158 // found a page |
|
159 $row = $db->fetchrow(); |
|
160 if ( sanitize_page_id($row['name']) === $id_match[4] ) |
|
161 { |
|
162 // we have a definitive match, send the page through |
|
163 $article = new PageProcessor($row['urlname'], 'NewsBoy'); |
|
164 $article->send_headers = $page->send_headers; |
|
165 $article->password = $page->password; |
|
166 $article->send(true); |
|
167 } |
|
168 else |
|
169 { |
|
170 // can't find it. |
|
171 return; |
|
172 } |
|
173 return; |
|
174 } |
135 } |
175 } |
136 } |
176 } |
137 |
177 |
138 function NewsBoy_set_page_string() |
178 function NewsBoy_set_page_string() |
139 { |
179 { |
375 $num_comments = $row['num_comments']; |
415 $num_comments = $row['num_comments']; |
376 $comment_s = ( $num_comments == 1 ) ? '' : 's'; |
416 $comment_s = ( $num_comments == 1 ) ? '' : 's'; |
377 $comment_link = '<a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '#do:comments" style="color: inherit;">add a comment</a>'; |
417 $comment_link = '<a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '#do:comments" style="color: inherit;">add a comment</a>'; |
378 $parser->assign_vars(array( |
418 $parser->assign_vars(array( |
379 'TITLE' => $title, |
419 'TITLE' => $title, |
380 'LINK' => makeUrlNS('NewsBoy', $row['urlname']), |
420 'LINK' => nb_make_article_url($row['urlname'], $row['name']), |
381 'CONTENT' => $content, |
421 'CONTENT' => $content, |
382 'USER_LINK' => $user_link, |
422 'USER_LINK' => $user_link, |
383 'DATE' => $date, |
423 'DATE' => $date, |
384 'NUM_COMMENTS' => $num_comments, |
424 'NUM_COMMENTS' => $num_comments, |
385 'COMMENT_S' => $comment_s, |
425 'COMMENT_S' => $comment_s, |
428 |
468 |
429 class NewsBoyFormatter |
469 class NewsBoyFormatter |
430 { |
470 { |
431 function article_link($name, $row) |
471 function article_link($name, $row) |
432 { |
472 { |
433 $article_link = '<a href="' . makeUrlNS('NewsBoy', $row['urlname']) . '">' . $row['name'] . '</a>'; |
473 $article_link = '<a href="' . nb_make_article_url($row['urlname'], $row['name']) . '">' . $row['name'] . '</a>'; |
434 return $article_link; |
474 return $article_link; |
435 } |
475 } |
436 function format_date($date, $row) |
476 function format_date($date, $row) |
437 { |
477 { |
438 $date = date('Y-m-j g:m', intval ( $date )); |
478 $date = date('Y-m-j g:m', intval ( $date )); |
1084 $text = substr($text, 0, $i); |
1124 $text = substr($text, 0, $i); |
1085 } |
1125 } |
1086 return $text; |
1126 return $text; |
1087 } |
1127 } |
1088 |
1128 |
|
1129 /** |
|
1130 * Generates a link to the given Newsboy article given the article name and timestamp |
|
1131 * @param int Article timestamp |
|
1132 * @param string Article title |
|
1133 * @return string |
|
1134 */ |
|
1135 |
|
1136 function nb_make_article_url($timestamp, $title = false) |
|
1137 { |
|
1138 if ( !$title ) |
|
1139 return makeUrlNS('NewsBoy', $timestamp); |
|
1140 $day = date('d', $timestamp); |
|
1141 $year = date('Y', $timestamp); |
|
1142 $month = date('m', $timestamp); |
|
1143 return makeUrlNS('NewsBoy', "Article/$year/$month/$day/" . sanitize_page_id($title)); |
|
1144 } |
|
1145 |
1089 ?> |
1146 ?> |