| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | #====================================================== |
|---|
| 5 | | <#TAG_NAME_TAG#> |
|---|
| 6 | | ===================================== |
|---|
| 7 | | <#TAG_DEVELOPERS_TAG#> |
|---|
| 8 | | <#TAG_COPYRIGHT_TAG#> |
|---|
| 9 | | <#TAG_URL_TAG#> |
|---|
| 10 | | ===================================== |
|---|
| 11 | | Email: <#TAG_EMAIL_TAG#> |
|---|
| 12 | #====================================================== |
|---|
| 13 | | @ Version: <#TAG_VER_HUMAN_TAG#> |
|---|
| 14 | | @ Version Int: <#TAG_VER_INT_TAG#> |
|---|
| 15 | | @ Version Num: <#TAG_VER_NUM_TAG#> |
|---|
| 16 | | @ Build: <#TAG_VER_BUILD_TAG#> |
|---|
| 17 | #====================================================== |
|---|
| 18 | | | Admin Source: News |
|---|
| 19 | #====================================================== |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | class td_ad_news { |
|---|
| 23 | |
|---|
| 24 | private $output = ""; |
|---|
| 25 | |
|---|
| 26 | #======================================= |
|---|
| 27 | # @ Auto Run |
|---|
| 28 | #======================================= |
|---|
| 29 | |
|---|
| 30 | public function auto_run() |
|---|
| 31 | { |
|---|
| 32 | if ( ! $this->trellis->cache->data['settings']['news']['enable'] ) $this->trellis->skin->error('news_disabled'); |
|---|
| 33 | |
|---|
| 34 | $this->trellis->check_perm( 'manage', 'news' ); |
|---|
| 35 | |
|---|
| 36 | $this->trellis->load_functions('news'); |
|---|
| 37 | $this->trellis->load_lang('news'); |
|---|
| 38 | |
|---|
| 39 | $this->trellis->skin->set_active_link( 2 ); |
|---|
| 40 | |
|---|
| 41 | switch( $this->trellis->input['act'] ) |
|---|
| 42 | { |
|---|
| 43 | case 'list': |
|---|
| 44 | $this->list_news(); |
|---|
| 45 | break; |
|---|
| 46 | case 'view': |
|---|
| 47 | $this->view_news(); |
|---|
| 48 | break; |
|---|
| 49 | case 'add': |
|---|
| 50 | $this->add_news(); |
|---|
| 51 | break; |
|---|
| 52 | case 'edit': |
|---|
| 53 | $this->edit_news(); |
|---|
| 54 | break; |
|---|
| 55 | |
|---|
| 56 | case 'togglecomments': |
|---|
| 57 | $this->do_toggle_comments(); |
|---|
| 58 | break; |
|---|
| 59 | |
|---|
| 60 | case 'doadd': |
|---|
| 61 | $this->do_add(); |
|---|
| 62 | break; |
|---|
| 63 | case 'doedit': |
|---|
| 64 | $this->do_edit(); |
|---|
| 65 | break; |
|---|
| 66 | case 'dodel': |
|---|
| 67 | $this->do_delete(); |
|---|
| 68 | break; |
|---|
| 69 | |
|---|
| 70 | case 'doaddcomment': |
|---|
| 71 | $this->do_add_comment(); |
|---|
| 72 | break; |
|---|
| 73 | case 'doeditcomment': |
|---|
| 74 | $this->do_edit_comment(); |
|---|
| 75 | break; |
|---|
| 76 | case 'dodelcomment': |
|---|
| 77 | $this->do_delete_comment(); |
|---|
| 78 | break; |
|---|
| 79 | |
|---|
| 80 | case 'getcomment': |
|---|
| 81 | $this->ajax_get_comment(); |
|---|
| 82 | break; |
|---|
| 83 | |
|---|
| 84 | default: |
|---|
| 85 | $this->list_news(); |
|---|
| 86 | break; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | #======================================= |
|---|
| 91 | # @ List News |
|---|
| 92 | #======================================= |
|---|
| 93 | |
|---|
| 94 | private function list_news($error='', $alert='') |
|---|
| 95 | { |
|---|
| 96 | #============================= |
|---|
| 97 | # Sorting Options |
|---|
| 98 | #============================= |
|---|
| 99 | |
|---|
| 100 | $sort = $this->trellis->generate_sql_sort( array( |
|---|
| 101 | 'default_sort' => 'id', |
|---|
| 102 | 'default_order' => 'asc', |
|---|
| 103 | 'base_url' => $this->generate_url( array( 'sort' => '', 'order' => '' ) ), |
|---|
| 104 | 'options' => array( |
|---|
| 105 | 'id' => '{lang.id}', |
|---|
| 106 | 'title' => '{lang.title}', |
|---|
| 107 | ), |
|---|
| 108 | ) ); |
|---|
| 109 | |
|---|
| 110 | #============================= |
|---|
| 111 | # Grab News |
|---|
| 112 | #============================= |
|---|
| 113 | |
|---|
| 114 | $n_total = $this->trellis->func->news->get( array( 'select' => array( 'id' ) ) ); |
|---|
| 115 | |
|---|
| 116 | $news_rows = ''; |
|---|
| 117 | |
|---|
| 118 | if ( ! $news = $this->trellis->func->news->get( array( 'select' => array( 'id', 'title', 'content', 'excerpt' ), 'order' => array( $sort['sort'] => $sort['order'] ), 'limit' => array( $this->trellis->input['st'], 15 ) ) ) ) |
|---|
| 119 | { |
|---|
| 120 | $news_rows .= "<tr><td class='bluecell-light' colspan='5'><strong><a href='<! HD_URL !>/admin.php?section=manage&page=news&act=add'>{lang.no_news}</a></strong></td></tr>"; |
|---|
| 121 | } |
|---|
| 122 | else |
|---|
| 123 | { |
|---|
| 124 | foreach( $news as $nid => $n ) |
|---|
| 125 | { |
|---|
| 126 | if ( ! $n['excerpt'] ) $n['excerpt'] = '<i>{lang.no_excerpt}</i>'; |
|---|
| 127 | |
|---|
| 128 | $news_rows .= "<tr> |
|---|
| 129 | <td class='bluecellthin-light'><strong>{$n['id']}</strong></td> |
|---|
| 130 | <td class='bluecellthin-dark'><a href='<! HD_URL !>/admin.php?section=manage&page=news&act=view&id={$n['id']}'>{$n['title']}</a></td> |
|---|
| 131 | <td class='bluecellthin-light' style='font-weight: normal'><a href='<! HD_URL !>/admin.php?section=manage&page=news&act=view&id={$n['id']}'>{$n['excerpt']}</a></td> |
|---|
| 132 | <td class='bluecellthin-light' align='center'><a href='<! HD_URL !>/admin.php?section=manage&page=news&act=edit&id={$n['id']}'><img src='<! IMG_DIR !>/button_edit.gif' alt='{lang.edit}' /></a></td> |
|---|
| 133 | <td class='bluecellthin-light' align='center'><a href='<! HD_URL !>/admin.php?section=manage&page=news&act=dodel&id={$n['id']}' onclick='return confirmDelete({$n['id']})'><img src='<! IMG_DIR !>/button_delete.gif' alt='{lang.delete}' /></a></td> |
|---|
| 134 | </tr>"; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | #============================= |
|---|
| 139 | # Do Output |
|---|
| 140 | #============================= |
|---|
| 141 | |
|---|
| 142 | $page_links = $this->trellis->page_links( array( |
|---|
| 143 | 'total' => count( $n_total ), |
|---|
| 144 | 'per_page' => 15, |
|---|
| 145 | 'url' => $this->generate_url( array( 'st' => 0 ) ), |
|---|
| 146 | ) ); |
|---|
| 147 | |
|---|
| 148 | if ( $error ) |
|---|
| 149 | { |
|---|
| 150 | $this->output .= $this->trellis->skin->error_wrap( '{lang.error_'. $error .'}' ); |
|---|
| 151 | } |
|---|
| 152 | elseif ( $alert ) |
|---|
| 153 | { |
|---|
| 154 | $this->output .= $this->trellis->skin->alert_wrap( '{lang.alert_'. $alert .'}' ); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | $this->output .= "<script type='text/javascript'> |
|---|
| 158 | function confirmDelete(nid) { |
|---|
| 159 | dialogConfirm({ |
|---|
| 160 | title: '{lang.dialog_delete_news_title}', |
|---|
| 161 | message: '{lang.dialog_delete_news_msg}', |
|---|
| 162 | yesButton: '{lang.dialog_delete_news_button}', |
|---|
| 163 | yesAction: function() { goToUrl('<! HD_URL !>/admin.php?section=manage&page=news&act=dodel&id='+nid) }, |
|---|
| 164 | noButton: '{lang.cancel}', |
|---|
| 165 | width: 350 |
|---|
| 166 | }); return false; |
|---|
| 167 | } |
|---|
| 168 | </script> |
|---|
| 169 | <div id='ticketroll'> |
|---|
| 170 | ". $this->trellis->skin->start_group_table( '{lang.news_list}' ) ." |
|---|
| 171 | <tr> |
|---|
| 172 | <th class='bluecellthin-th' width='6%' align='left'>{$sort['link_id']}</th> |
|---|
| 173 | <th class='bluecellthin-th' width='28%' align='left'>{$sort['link_title']}</th> |
|---|
| 174 | <th class='bluecellthin-th' width='60%' align='left'>{lang.description}</th> |
|---|
| 175 | <th class='bluecellthin-th' width='3%' align='center'>{lang.edit}</th> |
|---|
| 176 | <th class='bluecellthin-th' width='3%' align='center'>{lang.delete}</th> |
|---|
| 177 | </tr> |
|---|
| 178 | ". $news_rows ." |
|---|
| 179 | <tr> |
|---|
| 180 | <td class='bluecellthin-th-pages' colspan='5'>". $page_links ."</td> |
|---|
| 181 | </tr> |
|---|
| 182 | ". $this->trellis->skin->end_group_table() ." |
|---|
| 183 | </div>"; |
|---|
| 184 | |
|---|
| 185 | $menu_items = array( |
|---|
| 186 | array( 'circle_plus', '{lang.menu_add}', '<! HD_URL !>/admin.php?section=manage&page=news&act=add' ), |
|---|
| 187 | array( 'mails_arrow', '{lang.menu_mass_email}', '<! HD_URL !>/admin.php?section=tools&page=email&act=mass' ), |
|---|
| 188 | array( 'compile', '{lang.menu_cache}', '<! HD_URL !>/admin.php?section=tools&page=cache&act=rebuild&id=news' ), |
|---|
| 189 | array( 'settings', '{lang.menu_settings}', '<! HD_URL !>/admin.php?section=tools&page=settings&act=edit&group=news' ), |
|---|
| 190 | ); |
|---|
| 191 | |
|---|
| 192 | $this->trellis->skin->add_sidebar_menu( '{lang.menu_news_options}', $menu_items ); |
|---|
| 193 | $this->trellis->skin->add_sidebar_help( '{lang.help_about_news_title}', '{lang.help_about_news_msg}' ); |
|---|
| 194 | |
|---|
| 195 | $this->trellis->skin->add_output( $this->output ); |
|---|
| 196 | |
|---|
| 197 | $this->trellis->skin->do_output(); |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | #======================================= |
|---|
| 201 | # @ View News |
|---|
| 202 | #======================================= |
|---|
| 203 | |
|---|
| 204 | private function view_news($params=array()) |
|---|
| 205 | { |
|---|
| 206 | #============================= |
|---|
| 207 | # Grab News |
|---|
| 208 | #============================= |
|---|
| 209 | |
|---|
| 210 | $n = $this->trellis->db->get_single( array( |
|---|
| 211 | 'select' => array( |
|---|
| 212 | 'n' => array( 'id', 'uid', 'title', 'excerpt', 'content', 'views', 'comments', 'html', 'date', 'allow_comments' ), |
|---|
| 213 | 'u' => array( array( 'name' => 'uname' ) ), |
|---|
| 214 | ), |
|---|
| 215 | 'from' => array( 'n' => 'news' ), |
|---|
| 216 | 'join' => array( array( 'from' => array( 'u' => 'users' ), 'where' => array( 'n' => 'uid', '=', 'u' => 'id' ) ) ), |
|---|
| 217 | 'where' => array( array( 'n' => 'id' ), '=', $this->trellis->input['id'] ), |
|---|
| 218 | 'limit' => array( 0, 1 ), |
|---|
| 219 | ) ); |
|---|
| 220 | |
|---|
| 221 | if ( ! $n ) $this->trellis->skin->error('no_news'); |
|---|
| 222 | |
|---|
| 223 | #============================= |
|---|
| 224 | # Grab Comments |
|---|
| 225 | #============================= |
|---|
| 226 | |
|---|
| 227 | # New get() db function |
|---|
| 228 | |
|---|
| 229 | $comments = $this->trellis->db->get( array( |
|---|
| 230 | 'select' => array( |
|---|
| 231 | 'c' => 'all', |
|---|
| 232 | 'u' => array( array( 'name' => 'uname' ) ), |
|---|
| 233 | ), |
|---|
| 234 | 'from' => array( 'c' => 'news_comments' ), |
|---|
| 235 | 'join' => array( array( 'from' => array( 'u' => 'users' ), 'where' => array( 'c' => 'uid', '=', 'u' => 'id' ) ) ), |
|---|
| 236 | 'where' => array( array( 'c' => 'nid' ), '=', $n['id'] ), |
|---|
| 237 | 'order' => array( 'date' => array( 'c' => 'asc' ) ), |
|---|
| 238 | ), 'id' ); |
|---|
| 239 | |
|---|
| 240 | #============================= |
|---|
| 241 | # Format |
|---|
| 242 | #============================= |
|---|
| 243 | |
|---|
| 244 | $n['date_human'] = $this->trellis->td_timestamp( array( 'time' => $n['date'], 'format' => 'long' ) ); |
|---|
| 245 | |
|---|
| 246 | if ( ! $n['excerpt'] ) $n['excerpt'] = '<i>{lang.no_excerpt}</i>'; |
|---|
| 247 | |
|---|
| 248 | ( $n['allow_comments'] ) ? $n['comments_status'] = '({lang.enabled})' : $n['comments_status'] = '({lang.disabled})'; |
|---|
| 249 | |
|---|
| 250 | $noutput_params = array( 'urls' => 1 ); |
|---|
| 251 | |
|---|
| 252 | ( $n['html'] ) ? $noutput_params['html'] = 1 : $noutput_params['nl2br'] = 1; |
|---|
| 253 | |
|---|
| 254 | $n['content'] = $this->trellis->prepare_output( $n['content'], $noutput_params ); |
|---|
| 255 | |
|---|
| 256 | #============================= |
|---|
| 257 | # Do Output |
|---|
| 258 | #============================= |
|---|
| 259 | |
|---|
| 260 | if ( $params['error'] ) |
|---|
| 261 | { |
|---|
| 262 | $this->output .= $this->trellis->skin->error_wrap( '{lang.error_'. $params['error'] .'}' ); |
|---|
| 263 | $this->trellis->skin->preserve_input = 1; |
|---|
| 264 | } |
|---|
| 265 | elseif ( $params['alert'] ) |
|---|
| 266 | { |
|---|
| 267 | $this->output .= $this->trellis->skin->alert_wrap( '{lang.alert_'. $params['alert'] .'}' ); |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | $this->output .= "<script type='text/javascript'> |
|---|
| 271 | //<![CDATA[ |
|---|
| 272 | function confirmDeleteNews(aid) { |
|---|
| 273 | dialogConfirm({ |
|---|
| 274 | title: '{lang.dialog_delete_news_title}', |
|---|
| 275 | message: '{lang.dialog_delete_news_msg}', |
|---|
| 276 | yesButton: '{lang.dialog_delete_news_button}', |
|---|
| 277 | yesAction: function() { goToUrl('<! HD_URL !>/admin.php?section=manage&page=news&act=dodel&id='+aid) }, |
|---|
| 278 | noButton: '{lang.cancel}', |
|---|
| 279 | width: 350 |
|---|
| 280 | }); return false; |
|---|
| 281 | } |
|---|
| 282 | function confirmDeleteComment(cid) { |
|---|
| 283 | dialogConfirm({ |
|---|
| 284 | title: '{lang.dialog_delete_comment_title}', |
|---|
| 285 | message: '{lang.dialog_delete_comment_msg}', |
|---|
| 286 | yesButton: '{lang.dialog_delete_comment_button}', |
|---|
| 287 | yesAction: function() { inlineCommentDelete(cid); }, |
|---|
| 288 | noButton: '{lang.cancel}' |
|---|
| 289 | }); return false; |
|---|
| 290 | } |
|---|
| 291 | //]]> |
|---|
| 292 | </script> |
|---|
| 293 | ". $this->trellis->skin->start_ticket_details( '{lang.news_num}'. $n['id'] .': '. $n['title'] ) ." |
|---|
| 294 | <input type='hidden' id='nid' name='nid' value='{$n['id']}' /> |
|---|
| 295 | <table width='100%' border='0' cellspacing='0' cellpadding='0'> |
|---|
| 296 | <tr> |
|---|
| 297 | <td class='cardcell-light' width='20%'>{lang.news_id}</td> |
|---|
| 298 | <td class='cardcell-dark' width='30%'>{$n['id']}</td> |
|---|
| 299 | <td class='cardcell-light' width='20%'>{lang.views}</td> |
|---|
| 300 | <td class='cardcell-dark' width='30%'>{$n['views']}</td> |
|---|
| 301 | </tr> |
|---|
| 302 | <tr> |
|---|
| 303 | <td class='cardcell-light'>{lang.date}</td> |
|---|
| 304 | <td class='cardcell-dark'>{$n['date_human']}</td> |
|---|
| 305 | <td class='cardcell-light'>{lang.comments}</td> |
|---|
| 306 | <td class='cardcell-dark'>{$n['comments']} {$n['comments_status']}". $this->trellis->skin->setting_alert( array( 'check' => $this->trellis->cache->data['settings']['news']['comments'], 'for' => 1, 'msg' => '{lang.warn_comments}' ) ) ."</td> |
|---|
| 307 | </tr> |
|---|
| 308 | <tr> |
|---|
| 309 | <td class='cardcell-light'>{lang.excerpt}</td> |
|---|
| 310 | <td class='cardcell-dark' colspan='3' style='line-height:1.4;padding: 6px 10px;'>{$n['excerpt']}</td> |
|---|
| 311 | </tr> |
|---|
| 312 | </table> |
|---|
| 313 | ". $this->trellis->skin->end_ticket_details() ." |
|---|
| 314 | <div id='ticketroll'> |
|---|
| 315 | ". $this->trellis->skin->group_title('{lang.news_content}') ." |
|---|
| 316 | <div class='rollstart'> |
|---|
| 317 | {$n['content']} |
|---|
| 318 | </div>"; |
|---|
| 319 | |
|---|
| 320 | if ( ! empty( $comments ) ) |
|---|
| 321 | { |
|---|
| 322 | foreach( $comments as $c ) |
|---|
| 323 | { |
|---|
| 324 | ( $c['staff'] ) ? $cclass = 'staff': $cclass = 'customer'; |
|---|
| 325 | |
|---|
| 326 | $c['date'] = $this->trellis->td_timestamp( array( 'time' => $c['date'], 'format' => 'long' ) ); |
|---|
| 327 | |
|---|
| 328 | $coutput_params = array( 'urls' => 1 ); |
|---|
| 329 | |
|---|
| 330 | ( $c['html'] ) ? $coutput_params['html'] = 1 : $coutput_params['nl2br'] = 1; |
|---|
| 331 | |
|---|
| 332 | $c['message'] = $this->trellis->prepare_output( $c['message'], $coutput_params ); |
|---|
| 333 | |
|---|
| 334 | /*if ( $c['signature'] ) $c['message'] .= '<br /><br />'. $this->trellis->prepare_output( $c['usignature'], array( 'html' => $c['sig_html'] ) );*/ |
|---|
| 335 | |
|---|
| 336 | $this->output .= "<div id='cc{$c['id']}'> |
|---|
| 337 | <div class='bar{$cclass}'>"; |
|---|
| 338 | |
|---|
| 339 | $comment_edit = 0; |
|---|
| 340 | $comment_delete = 0; |
|---|
| 341 | $comment_javascript_html = ''; |
|---|
| 342 | |
|---|
| 343 | if ( $c['html'] ) $comment_javascript_html = 'Html'; |
|---|
| 344 | |
|---|
| 345 | if ( $this->trellis->user['g_news_com_edit_all'] || ( $this->trellis->user['g_news_com_edit'] && $c['uid'] == $this->trellis->user['id'] ) ) $comment_edit = 1; |
|---|
| 346 | if ( $this->trellis->user['g_news_com_delete_all'] || ( $this->trellis->user['g_news_com_delete'] && $c['uid'] == $this->trellis->user['id'] ) ) $comment_delete = 1; |
|---|
| 347 | |
|---|
| 348 | if ( $comment_edit || $comment_delete ) $this->output .= "<div class='barright'>"; |
|---|
| 349 | |
|---|
| 350 | if ( $comment_edit ) $this->output .= "<span id='cedit_". $c['id'] ."' style='cursor:pointer' onclick='inlineCommentEdit{$comment_javascript_html}(". $c['id'] .")'><img src='<! IMG_DIR !>/icon_page_edit.png' alt='{lang.edit}' />{lang.edit}</span><span id='csave_". $c['id'] ."' style='display:none;cursor:pointer' onclick='inlineCommentSave{$comment_javascript_html}(". $c['id'] .")'><img src='<! IMG_DIR !>/icon_page_edit.png' alt='{lang.save_edit}' />{lang.save_edit}</span>"; |
|---|
| 351 | |
|---|
| 352 | if ( $comment_delete ) |
|---|
| 353 | { |
|---|
| 354 | if ( $comment_edit ) $this->output .= " "; |
|---|
| 355 | |
|---|
| 356 | $this->output .= "<span id='cdelete_". $c['id'] ."' style='cursor:pointer' onclick='return confirmDeleteComment(". $c['id'] .")'><img src='<! IMG_DIR !>/icon_page_delete.png' alt='{lang.delete}' />{lang.delete}</span>"; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | if ( $comment_edit || $comment_delete ) $this->output .= "</div>"; |
|---|
| 360 | |
|---|
| 361 | $this->output .= "<strong>{$c['uname']}</strong> -- {$c['date']}</div> |
|---|
| 362 | <div class='roll{$cclass}' id='c{$c['id']}'> |
|---|
| 363 | {$c['message']} |
|---|
| 364 | </div> |
|---|
| 365 | </div>"; |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | if ( $this->trellis->cache->data['settings']['news']['comments'] && $n['allow_comments'] && $this->trellis->user['g_news_comment'] ) |
|---|
| 370 | { |
|---|
| 371 | if ( $this->trellis->user['rte_enable'] && $this->trellis->cache->data['settings']['news']['rte'] ) |
|---|
| 372 | { |
|---|
| 373 | $this->output .= $this->trellis->skin->tinymce_js( 'message' ); |
|---|
| 374 | |
|---|
| 375 | $html = 1; |
|---|
| 376 | } |
|---|
| 377 | else |
|---|
| 378 | { |
|---|
| 379 | $html = 0; |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | if ( $params['comment_error'] ) |
|---|
| 383 | { |
|---|
| 384 | $this->output .= '<br />'. $this->trellis->skin->error_wrap( '{lang.error_'. $params['comment_error'] .'}' ); |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | #( $this->trellis->user['sig_auto'] ) ? $sig_checked = " checked='yes'" : $sig_checked = ''; |
|---|
| 388 | |
|---|
| 389 | $this->output .= "<form action='<! HD_URL !>/admin.php?section=manage&page=news&act=doaddcomment&id={$n['id']}' method='post'> |
|---|
| 390 | <input type='hidden' id='html' name='html' value='{$html}' /> |
|---|
| 391 | <div class='slatebox'>{lang.post_a_comment}</div> |
|---|
| 392 | <div class='rollpost'> |
|---|
| 393 | ". $this->trellis->skin->textarea( array( 'name' => 'message', 'cols' => 80, 'rows' => 8, 'width' => '98%', 'height' => '200px' ) ) ." |
|---|
| 394 | </div> |
|---|
| 395 | <div class='formtail'>". $this->trellis->skin->submit_button( 'add_comment', '{lang.button_add_comment}' ) ."</div> |
|---|
| 396 | </form>"; |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | $this->output .= "</div> |
|---|
| 400 | <script language='javascript' type='text/javascript'> |
|---|
| 401 | //<![CDATA[ |
|---|
| 402 | function inlineCommentEditHtml(cid) { |
|---|
| 403 | $.get('admin.php?section=manage&page=news&act=getcomment', |
|---|
| 404 | { id: cid }, |
|---|
| 405 | function(data) { |
|---|
| 406 | if (data != 0) { |
|---|
| 407 | tinyMCE.init({ |
|---|
| 408 | mode : 'exact', |
|---|
| 409 | theme : 'advanced', |
|---|
| 410 | elements : 'c'+cid, |
|---|
| 411 | plugins : 'inlinepopups,safari,spellchecker', |
|---|
| 412 | dialog_type : 'modal', |
|---|
| 413 | theme_advanced_toolbar_location : 'top', |
|---|
| 414 | theme_advanced_toolbar_align : 'left', |
|---|
| 415 | theme_advanced_path_location : 'bottom', |
|---|
| 416 | theme_advanced_disable : 'styleselect,formatselect', |
|---|
| 417 | theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,separator,forecolor,backcolor,separator,bullist,numlist,separator,outdent,indent,separator,link,unlink,image,separator,undo,redo,separator,spellchecker,separator,removeformat,cleanup,code', |
|---|
| 418 | theme_advanced_buttons2 : '', |
|---|
| 419 | theme_advanced_buttons3 : '', |
|---|
| 420 | theme_advanced_resize_horizontal : false, |
|---|
| 421 | theme_advanced_resizing : true, |
|---|
| 422 | setup: function(ed) { |
|---|
| 423 | ed.onInit.add( function(ed) { |
|---|
| 424 | ed.setContent(data); |
|---|
| 425 | }); |
|---|
| 426 | } |
|---|
| 427 | }); |
|---|
| 428 | |
|---|
| 429 | $('#cedit_'+cid).hide(); |
|---|
| 430 | $('#cdelete_'+cid).hide(); |
|---|
| 431 | $('#csave_'+cid).show(); |
|---|
| 432 | } |
|---|
| 433 | }); |
|---|
| 434 | } |
|---|
| 435 | function inlineCommentSaveHtml(cid) { |
|---|
| 436 | $.post('admin.php?section=manage&page=news&act=doeditcomment', |
|---|
| 437 | { id: cid, message: tinyMCE.get('c'+cid).getContent(), html: 1 }, |
|---|
| 438 | function(data) { |
|---|
| 439 | if (data != 0) { |
|---|
| 440 | tinyMCE.get('c'+cid).setContent(data); |
|---|
| 441 | tinyMCE.get('c'+cid).remove(); |
|---|
| 442 | |
|---|
| 443 | $('#csave_'+cid).hide(); |
|---|
| 444 | $('#cedit_'+cid).show(); |
|---|
| 445 | $('#cdelete_'+cid).show(); |
|---|
| 446 | } |
|---|
| 447 | }); |
|---|
| 448 | } |
|---|
| 449 | function inlineCommentEdit(cid) { |
|---|
| 450 | $.get('admin.php?section=manage&page=news&act=getcomment', |
|---|
| 451 | { id: cid }, |
|---|
| 452 | function(data) { |
|---|
| 453 | if (data != 0) { |
|---|
| 454 | $('#c'+cid).html(\"<textarea id='ce\"+cid+\"' name='ce\"+cid+\"' cols='80' rows='7' style='width:98%'>\"+data+\"</textarea>\"); |
|---|
| 455 | |
|---|
| 456 | $('#cedit_'+cid).hide(); |
|---|
| 457 | $('#cdelete_'+cid).hide(); |
|---|
| 458 | $('#csave_'+cid).show(); |
|---|
| 459 | } |
|---|
| 460 | }); |
|---|
| 461 | } |
|---|
| 462 | function inlineCommentSave(cid) { |
|---|
| 463 | $.post('admin.php?section=manage&page=news&act=doeditcomment', |
|---|
| 464 | { id: cid, message: $('#ce'+cid).val() }, |
|---|
| 465 | function(data) { |
|---|
| 466 | if (data != 0) { |
|---|
| 467 | $('#c'+cid).html(data); |
|---|
| 468 | |
|---|
| 469 | $('#csave_'+cid).hide(); |
|---|
| 470 | $('#cedit_'+cid).show(); |
|---|
| 471 | $('#cdelete_'+cid).show(); |
|---|
| 472 | } |
|---|
| 473 | }); |
|---|
| 474 | } |
|---|
| 475 | function inlineCommentDelete(cid) { |
|---|
| 476 | $.post('admin.php?section=manage&page=news&act=dodelcomment', |
|---|
| 477 | { id: cid }, |
|---|
| 478 | function(data) { |
|---|
| 479 | if (data != 0) { |
|---|
| 480 | $('#cc'+cid).hide('blind'); |
|---|
| 481 | } |
|---|
| 482 | }); |
|---|
| 483 | } |
|---|
| 484 | //]]> |
|---|
| 485 | </script>"; |
|---|
| 486 | |
|---|
| 487 | $menu_items = array( array( 'arrow_back', '{lang.menu_back}', '<! HD_URL !>/admin.php?section=manage&page=news' ) ); |
|---|
| 488 | |
|---|
| 489 | #if ( $this->trellis->check_perm( 'manage', 'news', 'add' ) ) $menu_items[] = array( 'circle_plus', '{lang.menu_add}', '<! HD_URL !>/admin.php?section=manage&page=news&act=add' ); |
|---|
| 490 | if ( $this->trellis->check_perm( 'manage', 'news', 'edit' ) ) $menu_items[] = array( 'edit', '{lang.menu_edit}', '<! HD_URL !>/admin.php?section=manage&page=news&act=edit&id='. $n['id'] ); |
|---|
| 491 | |
|---|
| 492 | # Repeated code below... clean up |
|---|
| 493 | |
|---|
| 494 | if ( $this->trellis->check_perm( 'manage', 'news', 'edit' ) ) |
|---|
| 495 | { |
|---|
| 496 | if ( $n['allow_comments'] ) |
|---|
| 497 | { |
|---|
| 498 | $menu_items[] = array( 'balloon', '{lang.menu_disable_comments}'. $this->trellis->skin->setting_alert( array( 'check' => $this->trellis->cache->data['settings']['news']['comments'], 'for' => 1, 'msg' => '{lang.warn_comments}' ) ), '<! HD_URL !>/admin.php?section=manage&page=news&act=togglecomments&id='. $n['id'] ); |
|---|
| 499 | } |
|---|
| 500 | else |
|---|
| 501 | { |
|---|
| 502 | $menu_items[] = array( 'balloon', '{lang.menu_enable_comments}'. $this->trellis->skin->setting_alert( array( 'check' => $this->trellis->cache->data['settings']['news']['comments'], 'for' => 1, 'msg' => '{lang.warn_comments}' ) ), '<! HD_URL !>/admin.php?section=manage&page=news&act=togglecomments&id='. $n['id'] ); |
|---|
| 503 | } |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | if ( $this->trellis->check_perm( 'manage', 'news', 'delete' ) ) $menu_items[] = array( 'circle_delete', '{lang.menu_delete}', '<! HD_URL !>/admin.php?section=manage&page=news&act=dodel&id='. $n['id'], 'return confirmDeleteNews('. $n['id'] .')' ); |
|---|
| 507 | if ( $this->trellis->check_perm( 'manage', 'settings' ) ) $menu_items[] = array( 'settings', '{lang.menu_settings}', '<! HD_URL !>/admin.php?section=tools&page=settings&act=edit&group=news' ); |
|---|
| 508 | |
|---|
| 509 | $this->trellis->skin->add_sidebar_menu( '{lang.menu_news_options}', $menu_items ); |
|---|
| 510 | $this->trellis->skin->add_sidebar_help( '{lang.random_title}', '{lang.random_text}' ); |
|---|
| 511 | |
|---|
| 512 | $this->trellis->skin->add_output( $this->output ); |
|---|
| 513 | |
|---|
| 514 | $this->trellis->skin->do_output(); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | #======================================= |
|---|
| 518 | # @ Add News Form |
|---|
| 519 | #======================================= |
|---|
| 520 | |
|---|
| 521 | private function add_news($error='') |
|---|
| 522 | { |
|---|
| 523 | #============================= |
|---|
| 524 | # Security Checks |
|---|
| 525 | #============================= |
|---|
| 526 | |
|---|
| 527 | $this->trellis->check_perm( 'manage', 'news', 'add' ); |
|---|
| 528 | |
|---|
| 529 | #============================= |
|---|
| 530 | # Do Output |
|---|
| 531 | #============================= |
|---|
| 532 | |
|---|
| 533 | if ( $error ) |
|---|
| 534 | { |
|---|
| 535 | $this->output .= $this->trellis->skin->error_wrap( '{lang.error_'. $error .'}' ); |
|---|
| 536 | $this->trellis->skin->preserve_input = 1; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | if ( $this->trellis->user['rte_enable'] && $this->trellis->cache->data['settings']['news']['rte'] ) |
|---|
| 540 | { |
|---|
| 541 | $this->output .= $this->trellis->skin->tinymce_js( 'content' ); |
|---|
| 542 | |
|---|
| 543 | $html = 1; |
|---|
| 544 | } |
|---|
| 545 | else |
|---|
| 546 | { |
|---|
| 547 | $html = 0; |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | $this->output .= "<div id='ticketroll'> |
|---|
| 551 | ". $this->trellis->skin->start_form( "<! HD_URL !>/admin.php?section=manage&page=news&act=doadd", 'add_news', 'post' ) ." |
|---|
| 552 | <input type='hidden' id='html' name='html' value='{$html}' /> |
|---|
| 553 | ". $this->trellis->skin->start_group_table( '{lang.adding_news}', 'a' ) ." |
|---|
| 554 | ". $this->trellis->skin->group_table_row( '{lang.title}', $this->trellis->skin->textfield( 'title' ), 'a', '20%', '80%' ) ." |
|---|
| 555 | ". $this->trellis->skin->group_table_row( '{lang.excerpt} '. $this->trellis->skin->help_tip('{lang.tip_excerpt}'), $this->trellis->skin->textarea( 'excerpt', '', '', 0, 60, 2 ), 'a' ) ." |
|---|
| 556 | <tr> |
|---|
| 557 | <td class='option1'>{lang.options}</td> |
|---|
| 558 | <td class='option1' style='font-weight: normal'> |
|---|
| 559 | ". $this->trellis->skin->checkbox( array( 'name' => 'allow_comments', 'title' => '{lang.allow_comments}', 'value' => 1, 'alert' => array( 'check' => $this->trellis->cache->data['settings']['news']['comments'], 'for' => 1, 'msg' => '{lang.warn_comments}' ) ) ) ." |
|---|
| 560 | ". $this->trellis->skin->checkbox( 'email_users', '{lang.email_users} '. $this->trellis->skin->help_tip('{lang.tip_email_users}') ) ." |
|---|
| 561 | </td> |
|---|
| 562 | </tr> |
|---|
| 563 | <tr> |
|---|
| 564 | <td colspan='2' class='option2'>". $this->trellis->skin->textarea( array( 'name' => 'content', 'cols' => 80, 'rows' => 10, 'width' => '98%', 'height' => '230px' ) ) ."</td> |
|---|
| 565 | </tr> |
|---|
| 566 | ". $this->trellis->skin->end_group_table( 'a' ) ." |
|---|
| 567 | ". $this->trellis->skin->end_form( $this->trellis->skin->submit_button( 'add', '{lang.button_add_news}' ) ) ." |
|---|
| 568 | </div>"; |
|---|
| 569 | |
|---|
| 570 | $validate_fields = array( |
|---|
| 571 | 'title' => array( array( 'type' => 'presence', 'params' => array( 'fail_msg' => '{lang.lv_no_title}' ) ) ), |
|---|
| 572 | ); |
|---|
| 573 | |
|---|
| 574 | $this->output .= $this->trellis->skin->live_validation_js( $validate_fields ); |
|---|
| 575 | $this->output .= $this->trellis->skin->focus_js('title'); |
|---|
| 576 | |
|---|
| 577 | $menu_items = array( |
|---|
| 578 | array( 'arrow_back', '{lang.menu_back}', '<! HD_URL !>/admin.php?section=manage&page=news' ), |
|---|
| 579 | array( 'mails_arrow', '{lang.menu_mass_email}', '<! HD_URL !>/admin.php?section=tools&page=email&act=mass' ), |
|---|
| 580 | array( 'settings', '{lang.menu_settings}', '<! HD_URL !>/admin.php?section=tools&page=settings&act=edit&group=news' ), |
|---|
| 581 | ); |
|---|
| 582 | |
|---|
| 583 | $this->trellis->skin->add_sidebar_menu( '{lang.menu_news_options}', $menu_items ); |
|---|
| 584 | $this->trellis->skin->add_sidebar_help( '{lang.random_title}', '{lang.random_text}' ); |
|---|
| 585 | |
|---|
| 586 | $this->trellis->skin->add_output( $this->output ); |
|---|
| 587 | |
|---|
| 588 | $this->trellis->skin->do_output(); |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | #======================================= |
|---|
| 592 | # @ Edit News Form |
|---|
| 593 | #======================================= |
|---|
| 594 | |
|---|
| 595 | private function edit_news($error='') |
|---|
| 596 | { |
|---|
| 597 | #============================= |
|---|
| 598 | # Security Checks |
|---|
| 599 | #============================= |
|---|
| 600 | |
|---|
| 601 | $this->trellis->check_perm( 'manage', 'news', 'edit' ); |
|---|
| 602 | |
|---|
| 603 | if ( ! $n = $this->trellis->func->news->get_single_by_id( 'all', $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_news'); |
|---|
| 604 | |
|---|
| 605 | #============================= |
|---|
| 606 | # Do Output |
|---|
| 607 | #============================= |
|---|
| 608 | |
|---|
| 609 | if ( $error ) |
|---|
| 610 | { |
|---|
| 611 | $this->output .= $this->trellis->skin->error_wrap( '{lang.error_'. $error .'}' ); |
|---|
| 612 | $this->trellis->skin->preserve_input = 1; |
|---|
| 613 | |
|---|
| 614 | $content = $this->trellis->input['content']; |
|---|
| 615 | } |
|---|
| 616 | else |
|---|
| 617 | { |
|---|
| 618 | $content = $n['content']; |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | if ( $this->trellis->user['rte_enable'] && $this->trellis->cache->data['settings']['news']['rte'] ) |
|---|
| 622 | { |
|---|
| 623 | $this->output .= $this->trellis->skin->tinymce_js( 'content' ); |
|---|
| 624 | |
|---|
| 625 | $html = 1; |
|---|
| 626 | } |
|---|
| 627 | else |
|---|
| 628 | { |
|---|
| 629 | $html = 0; |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | $this->output .= "<div id='ticketroll'> |
|---|
| 633 | ". $this->trellis->skin->start_form( "<! HD_URL !>/admin.php?section=manage&page=news&act=doedit&id={$n['id']}", 'edit_news', 'post' ) ." |
|---|
| 634 | <input type='hidden' id='html' name='html' value='{$html}' /> |
|---|
| 635 | ". $this->trellis->skin->start_group_table( '{lang.editing_news} '. $n['title'], 'a' ) ." |
|---|
| 636 | ". $this->trellis->skin->group_table_row( '{lang.title}', $this->trellis->skin->textfield( 'title', $n['title'] ), 'a', '20%', '80%' ) ." |
|---|
| 637 | ". $this->trellis->skin->group_table_row( '{lang.excerpt} '. $this->trellis->skin->help_tip('{lang.tip_excerpt}'), $this->trellis->skin->textarea( 'excerpt', $n['excerpt'], '', 0, 60, 2 ), 'a' ) ." |
|---|
| 638 | <tr> |
|---|
| 639 | <td class='option1'>{lang.options}</td> |
|---|
| 640 | <td class='option1' style='font-weight: normal'> |
|---|
| 641 | ". $this->trellis->skin->checkbox( array( 'name' => 'allow_comments', 'title' => '{lang.allow_comments}', 'value' => $n['allow_comments'], 'alert' => array( 'check' => $this->trellis->cache->data['settings']['news']['comments'], 'for' => 1, 'msg' => '{lang.warn_comments}' ) ) ) ." |
|---|
| 642 | </td> |
|---|
| 643 | </tr> |
|---|
| 644 | <tr> |
|---|
| 645 | <td colspan='2' class='option2'>". $this->trellis->skin->textarea( array( 'name' => 'content', 'value' => $n['content'], 'cols' => 80, 'rows' => 10, 'width' => '98%', 'height' => '230px' ) ) ."</td> |
|---|
| 646 | </tr> |
|---|
| 647 | ". $this->trellis->skin->end_group_table( 'a' ) ." |
|---|
| 648 | ". $this->trellis->skin->end_form( $this->trellis->skin->submit_button( 'edit', '{lang.button_edit_news}' ) ) ." |
|---|
| 649 | </div>"; |
|---|
| 650 | |
|---|
| 651 | $validate_fields = array( |
|---|
| 652 | 'title' => array( array( 'type' => 'presence', 'params' => array( 'fail_msg' => '{lang.lv_no_title}' ) ) ), |
|---|
| 653 | ); |
|---|
| 654 | |
|---|
| 655 | $this->output .= $this->trellis->skin->live_validation_js( $validate_fields ); |
|---|
| 656 | |
|---|
| 657 | $menu_items = array( |
|---|
| 658 | array( 'arrow_back', '{lang.menu_back}', '<! HD_URL !>/admin.php?section=manage&page=news' ), |
|---|
| 659 | array( 'circle_plus', '{lang.menu_add}', '<! HD_URL !>/admin.php?section=manage&page=news&act=add' ), |
|---|
| 660 | array( 'mails_arrow', '{lang.menu_mass_email}', '<! HD_URL !>/admin.php?section=tools&page=email&act=mass' ), |
|---|
| 661 | array( 'settings', '{lang.menu_settings}', '<! HD_URL !>/admin.php?section=tools&page=settings&act=edit&group=news' ), |
|---|
| 662 | ); |
|---|
| 663 | |
|---|
| 664 | $this->trellis->skin->add_sidebar_menu( '{lang.menu_news_options}', $menu_items ); |
|---|
| 665 | $this->trellis->skin->add_sidebar_help( '{lang.random_title}', '{lang.random_text}' ); |
|---|
| 666 | |
|---|
| 667 | $this->trellis->skin->add_output( $this->output ); |
|---|
| 668 | |
|---|
| 669 | $this->trellis->skin->do_output(); |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | #======================================= |
|---|
| 673 | # @ Do Add News |
|---|
| 674 | #======================================= |
|---|
| 675 | |
|---|
| 676 | private function do_add() |
|---|
| 677 | { |
|---|
| 678 | #============================= |
|---|
| 679 | # Security Checks |
|---|
| 680 | #============================= |
|---|
| 681 | |
|---|
| 682 | $this->trellis->check_perm( 'manage', 'news', 'add' ); |
|---|
| 683 | |
|---|
| 684 | if ( ! $this->trellis->input['title'] ) $this->add_news('no_title'); |
|---|
| 685 | if ( ! $this->trellis->input['content'] ) $this->add_news('no_content'); |
|---|
| 686 | |
|---|
| 687 | #============================= |
|---|
| 688 | # Add News |
|---|
| 689 | #============================= |
|---|
| 690 | |
|---|
| 691 | ( $this->trellis->input['html'] && $this->trellis->cache->data['settings']['news']['rte'] ) ? $html = 1 : $html = 0; |
|---|
| 692 | |
|---|
| 693 | $db_array = array( |
|---|
| 694 | 'uid' => $this->trellis->user['id'], |
|---|
| 695 | 'title' => $this->trellis->input['title'], |
|---|
| 696 | 'excerpt' => $this->trellis->input['excerpt'], |
|---|
| 697 | 'content' => $this->trellis->input['content'], |
|---|
| 698 | 'email' => $this->trellis->input['email_users'], |
|---|
| 699 | 'allow_comments' => $this->trellis->input['allow_comments'], |
|---|
| 700 | 'html' => $html, |
|---|
| 701 | 'date' => time(), |
|---|
| 702 | 'ipadd' => $this->trellis->input['ip_address'], |
|---|
| 703 | ); |
|---|
| 704 | |
|---|
| 705 | $news_id = $this->trellis->func->news->add( $db_array ); |
|---|
| 706 | |
|---|
| 707 | $this->trellis->log( 'admin', "News Added '". $this->trellis->input['title'] ."'", 1, $news_id ); |
|---|
| 708 | |
|---|
| 709 | #============================= |
|---|
| 710 | # Send Email |
|---|
| 711 | #============================= |
|---|
| 712 | |
|---|
| 713 | # TODO: to be completed |
|---|
| 714 | |
|---|
| 715 | #============================= |
|---|
| 716 | # Rebuild Cache |
|---|
| 717 | #============================= |
|---|
| 718 | |
|---|
| 719 | $this->trellis->load_functions('rebuild'); |
|---|
| 720 | |
|---|
| 721 | $this->trellis->func->rebuild->news_cache(); |
|---|
| 722 | |
|---|
| 723 | #============================= |
|---|
| 724 | # Do Output |
|---|
| 725 | #============================= |
|---|
| 726 | |
|---|
| 727 | $this->trellis->input['id'] = $news_id; |
|---|
| 728 | |
|---|
| 729 | $this->view_news( array( 'alert' => 'news_added' ) ); |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | #======================================= |
|---|
| 733 | # @ Do Edit News |
|---|
| 734 | #======================================= |
|---|
| 735 | |
|---|
| 736 | private function do_edit() |
|---|
| 737 | { |
|---|
| 738 | #============================= |
|---|
| 739 | # Security Checks |
|---|
| 740 | #============================= |
|---|
| 741 | |
|---|
| 742 | $this->trellis->check_perm( 'manage', 'news', 'edit' ); |
|---|
| 743 | |
|---|
| 744 | if ( ! $this->trellis->input['title'] ) $this->edit_news('no_title'); |
|---|
| 745 | if ( ! $this->trellis->input['content'] ) $this->edit_news('no_content'); |
|---|
| 746 | |
|---|
| 747 | #============================= |
|---|
| 748 | # Update News |
|---|
| 749 | #============================= |
|---|
| 750 | |
|---|
| 751 | ( $this->trellis->input['html'] && $this->trellis->cache->data['settings']['news']['rte'] ) ? $html = 1 : $html = 0; |
|---|
| 752 | |
|---|
| 753 | $db_array = array( |
|---|
| 754 | 'uid' => $this->trellis->user['id'], |
|---|
| 755 | 'title' => $this->trellis->input['title'], |
|---|
| 756 | 'excerpt' => $this->trellis->input['excerpt'], |
|---|
| 757 | 'content' => $this->trellis->input['content'], |
|---|
| 758 | 'allow_comments' => $this->trellis->input['allow_comments'], |
|---|
| 759 | 'html' => $html, |
|---|
| 760 | ); |
|---|
| 761 | |
|---|
| 762 | $this->trellis->func->news->edit( $db_array, $this->trellis->input['id'] ); |
|---|
| 763 | |
|---|
| 764 | $this->trellis->log( 'admin', "News Edited '". $this->trellis->input['title'] ."'", 1, $this->trellis->input['id'] ); |
|---|
| 765 | |
|---|
| 766 | #============================= |
|---|
| 767 | # Rebuild Cache |
|---|
| 768 | #============================= |
|---|
| 769 | |
|---|
| 770 | $this->trellis->load_functions('rebuild'); |
|---|
| 771 | |
|---|
| 772 | $this->trellis->func->rebuild->news_cache(); |
|---|
| 773 | |
|---|
| 774 | #============================= |
|---|
| 775 | # Do Output |
|---|
| 776 | #============================= |
|---|
| 777 | |
|---|
| 778 | $this->view_news( array( 'alert' => 'news_updated' ) ); |
|---|
| 779 | } |
|---|
| 780 | |
|---|
| 781 | #======================================= |
|---|
| 782 | # @ Do Delete News |
|---|
| 783 | #======================================= |
|---|
| 784 | |
|---|
| 785 | private function do_delete() |
|---|
| 786 | { |
|---|
| 787 | #============================= |
|---|
| 788 | # Security Checks |
|---|
| 789 | #============================= |
|---|
| 790 | |
|---|
| 791 | $this->trellis->check_perm( 'manage', 'news', 'delete' ); |
|---|
| 792 | |
|---|
| 793 | #============================= |
|---|
| 794 | # DELETE News |
|---|
| 795 | #============================= |
|---|
| 796 | |
|---|
| 797 | $this->trellis->func->news->delete( $this->trellis->input['id'] ); |
|---|
| 798 | |
|---|
| 799 | $this->trellis->log( 'admin', "News Deleted '". $this->trellis->cache->data['news'][ $this->trellis->input['id'] ]['title'] ."'", 2, $this->trellis->input['id'] ); |
|---|
| 800 | |
|---|
| 801 | #============================= |
|---|
| 802 | # Rebuild Cache |
|---|
| 803 | #============================= |
|---|
| 804 | |
|---|
| 805 | $this->trellis->load_functions('rebuild'); |
|---|
| 806 | |
|---|
| 807 | $this->trellis->func->rebuild->news_cache(); |
|---|
| 808 | |
|---|
| 809 | #============================= |
|---|
| 810 | # Do Output |
|---|
| 811 | #============================= |
|---|
| 812 | |
|---|
| 813 | $this->list_news( 'news_deleted' ); |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | #======================================= |
|---|
| 817 | # @ Do Toggle Comments |
|---|
| 818 | #======================================= |
|---|
| 819 | |
|---|
| 820 | private function do_toggle_comments() |
|---|
| 821 | { |
|---|
| 822 | #============================= |
|---|
| 823 | # Security Checks |
|---|
| 824 | #============================= |
|---|
| 825 | |
|---|
| 826 | $this->trellis->check_perm( 'manage', 'news', 'edit' ); |
|---|
| 827 | |
|---|
| 828 | if ( ! $n = $this->trellis->func->news->get_single_by_id( array( 'id', 'title', 'allow_comments' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_news'); |
|---|
| 829 | |
|---|
| 830 | #============================= |
|---|
| 831 | # Edit New |
|---|
| 832 | #============================= |
|---|
| 833 | |
|---|
| 834 | ( $n['allow_comments'] ) ? $allow_comments = 0 : $allow_comments = 1; |
|---|
| 835 | |
|---|
| 836 | $this->trellis->func->news->edit( array( 'allow_comments' => $allow_comments ), $n['id'] ); |
|---|
| 837 | |
|---|
| 838 | $this->trellis->log( 'admin', "News Item Comments State Modified '". $n['title'] ."'", 1, $n['id'] ); |
|---|
| 839 | |
|---|
| 840 | #============================= |
|---|
| 841 | # Do Output |
|---|
| 842 | #============================= |
|---|
| 843 | |
|---|
| 844 | $this->view_news( array( 'alert' => 'news_updated' ) ); |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | #======================================= |
|---|
| 848 | # @ Do Add Comment |
|---|
| 849 | #======================================= |
|---|
| 850 | |
|---|
| 851 | private function do_add_comment() |
|---|
| 852 | { |
|---|
| 853 | #============================= |
|---|
| 854 | # Security Checks |
|---|
| 855 | #============================= |
|---|
| 856 | |
|---|
| 857 | if ( $this->trellis->input['html'] ) |
|---|
| 858 | { |
|---|
| 859 | $this->trellis->input['message'] = $this->trellis->remove_extra_lbs( $this->trellis->input['message'] ); |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | if ( ! $this->trellis->input['message'] ) $this->view_news( array( 'comment_error' => 'no_message' ) ); |
|---|
| 863 | |
|---|
| 864 | if ( ! $n = $this->trellis->func->news->get_single_by_id( array( 'id', 'title', 'allow_comments' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_news'); |
|---|
| 865 | |
|---|
| 866 | if ( ! $this->trellis->cache->data['settings']['news']['comments'] || ! $n['allow_comments'] || ! $this->trellis->user['g_news_comment'] ) $this->trellis->skin->error('no_perm'); |
|---|
| 867 | |
|---|
| 868 | #============================= |
|---|
| 869 | # Add Comment |
|---|
| 870 | #============================= |
|---|
| 871 | |
|---|
| 872 | $db_array = array( |
|---|
| 873 | 'nid' => $n['id'], |
|---|
| 874 | 'uid' => $this->trellis->user['id'], |
|---|
| 875 | 'message' => $this->trellis->input['message'], |
|---|
| 876 | 'staff' => 1, |
|---|
| 877 | 'html' => $this->trellis->input['html'], |
|---|
| 878 | 'date' => time(), |
|---|
| 879 | 'ipadd' => $this->trellis->input['ip_address'], |
|---|
| 880 | ); |
|---|
| 881 | |
|---|
| 882 | $comment_id = $this->trellis->func->news->add_comment( $db_array, $n['id'] ); |
|---|
| 883 | |
|---|
| 884 | $this->trellis->log( 'admin', "News Item Comment Added '". $n['title'] ."'", 1, $n['id'] ); |
|---|
| 885 | |
|---|
| 886 | #============================= |
|---|
| 887 | # Do Output |
|---|
| 888 | #============================= |
|---|
| 889 | |
|---|
| 890 | $this->trellis->input['id'] = $n['id']; |
|---|
| 891 | |
|---|
| 892 | $this->view_news( array( 'comment' => $comment_id ) ); |
|---|
| 893 | } |
|---|
| 894 | |
|---|
| 895 | #======================================= |
|---|
| 896 | # @ Do Edit Comment |
|---|
| 897 | #======================================= |
|---|
| 898 | |
|---|
| 899 | private function do_edit_comment() |
|---|
| 900 | { |
|---|
| 901 | #============================= |
|---|
| 902 | # Security Checks |
|---|
| 903 | #============================= |
|---|
| 904 | |
|---|
| 905 | if ( $this->trellis->input['html'] ) |
|---|
| 906 | { |
|---|
| 907 | $this->trellis->input['message'] = $this->trellis->remove_extra_lbs( $this->trellis->input['message'] ); |
|---|
| 908 | } |
|---|
| 909 | |
|---|
| 910 | if ( ! $this->trellis->input['message'] ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 911 | |
|---|
| 912 | $c = $this->trellis->db->get_single( array( |
|---|
| 913 | 'select' => array( |
|---|
| 914 | 'c' => array( 'id', 'uid' ), |
|---|
| 915 | 'n' => array( 'title' ), |
|---|
| 916 | ), |
|---|
| 917 | 'from' => array( 'c' => 'news_comments' ), |
|---|
| 918 | 'join' => array( array( 'from' => array( 'n' => 'news' ), 'where' => array( 'c' => 'nid', '=', 'n' => 'id' ) ) ), |
|---|
| 919 | 'where' => array( array( 'c' => 'id' ), '=', $this->trellis->input['id'] ), |
|---|
| 920 | 'limit' => array( 0, 1 ), |
|---|
| 921 | ) ); |
|---|
| 922 | |
|---|
| 923 | if ( ! $c ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 924 | |
|---|
| 925 | # Double Check Permission Logic Below... |
|---|
| 926 | |
|---|
| 927 | if ( ! $this->trellis->user['g_news_com_edit_all'] && ! ( $this->trellis->user['g_news_com_edit'] && $c['uid'] == $this->trellis->user['id'] ) ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 928 | |
|---|
| 929 | #============================= |
|---|
| 930 | # Edit Reply |
|---|
| 931 | #============================= |
|---|
| 932 | |
|---|
| 933 | $db_array = array( |
|---|
| 934 | 'message' => $this->trellis->input['message'], |
|---|
| 935 | 'html' => $this->trellis->input['html'], |
|---|
| 936 | ); |
|---|
| 937 | |
|---|
| 938 | $this->trellis->func->news->edit_comment( $db_array, $c['id'] ); |
|---|
| 939 | |
|---|
| 940 | $this->trellis->log( 'admin', "News Item Comment Edited '". $c['title'] ."'", 1, $c['nid'] ); |
|---|
| 941 | |
|---|
| 942 | #============================= |
|---|
| 943 | # Do Output |
|---|
| 944 | #============================= |
|---|
| 945 | |
|---|
| 946 | $coutput_params = array( 'urls' => 1 ); |
|---|
| 947 | |
|---|
| 948 | ( $this->trellis->input['html'] ) ? $coutput_params['html'] = 1 : $coutput_params['nl2br'] = 1; |
|---|
| 949 | |
|---|
| 950 | $rmessage = $this->trellis->prepare_output( $this->trellis->input['message'], $coutput_params ); |
|---|
| 951 | |
|---|
| 952 | /*if ( $r['signature'] ) |
|---|
| 953 | { |
|---|
| 954 | $rmessage .= '<br /><br />'. $this->trellis->prepare_output( $r['usignature'], array( 'html' => $r['sig_html'] ) ); |
|---|
| 955 | }*/ |
|---|
| 956 | |
|---|
| 957 | $this->trellis->skin->ajax_output( $rmessage ); |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | #======================================= |
|---|
| 961 | # @ Do Delete Comment |
|---|
| 962 | #======================================= |
|---|
| 963 | |
|---|
| 964 | private function do_delete_comment() |
|---|
| 965 | { |
|---|
| 966 | #============================= |
|---|
| 967 | # Security Checks |
|---|
| 968 | #============================= |
|---|
| 969 | |
|---|
| 970 | $c = $this->trellis->db->get_single( array( |
|---|
| 971 | 'select' => array( |
|---|
| 972 | 'c' => array( 'id','nid', 'uid' ), |
|---|
| 973 | 'n' => array( 'title' ), |
|---|
| 974 | ), |
|---|
| 975 | 'from' => array( 'c' => 'news_comments' ), |
|---|
| 976 | 'join' => array( array( 'from' => array( 'n' => 'news' ), 'where' => array( 'c' => 'nid', '=', 'n' => 'id' ) ) ), |
|---|
| 977 | 'where' => array( array( 'c' => 'id' ), '=', $this->trellis->input['id'] ), |
|---|
| 978 | 'limit' => array( 0, 1 ), |
|---|
| 979 | ) ); |
|---|
| 980 | |
|---|
| 981 | if ( ! $c ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 982 | |
|---|
| 983 | if ( ! $this->trellis->user['g_news_com_delete_all'] && ! ( $this->trellis->user['g_news_com_delete'] && $c['uid'] == $this->trellis->user['id'] ) ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 984 | |
|---|
| 985 | #============================= |
|---|
| 986 | # DELETE Comment |
|---|
| 987 | #============================= |
|---|
| 988 | |
|---|
| 989 | $this->trellis->func->news->delete_comment( $c['id'], array( 'nid' => $c['nid'] ) ); |
|---|
| 990 | |
|---|
| 991 | $this->trellis->log( 'admin', "News Item Comment Deleted '". $c['title'] ."'", 2, $c['nid'] ); |
|---|
| 992 | |
|---|
| 993 | #============================= |
|---|
| 994 | # Do Output |
|---|
| 995 | #============================= |
|---|
| 996 | |
|---|
| 997 | $this->trellis->skin->ajax_output( '1' ); |
|---|
| 998 | } |
|---|
| 999 | |
|---|
| 1000 | #======================================= |
|---|
| 1001 | # @ AJAX Get Comment |
|---|
| 1002 | #======================================= |
|---|
| 1003 | |
|---|
| 1004 | private function ajax_get_comment() |
|---|
| 1005 | { |
|---|
| 1006 | $c = $this->trellis->func->news->get_single_comment_by_id( array( 'id', 'uid', 'message', 'html' ), $this->trellis->input['id'] ); |
|---|
| 1007 | |
|---|
| 1008 | if ( ! $c ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 1009 | |
|---|
| 1010 | if ( ! $this->trellis->user['g_news_com_edit_all'] && ! ( $this->trellis->user['g_news_com_edit'] && $c['uid'] == $this->trellis->user['id'] ) ) $this->trellis->skin->ajax_output( '0' ); |
|---|
| 1011 | |
|---|
| 1012 | $this->trellis->skin->ajax_output( $this->trellis->prepare_output( $c['message'], array( 'html' => $c['html'] ) ) ); |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | #======================================= |
|---|
| 1016 | # @ Generate URL |
|---|
| 1017 | #======================================= |
|---|
| 1018 | |
|---|
| 1019 | private function generate_url($params=array()) |
|---|
| 1020 | { |
|---|
| 1021 | $url = '<! HD_URL !>/admin.php?section=manage&page=news'; |
|---|
| 1022 | |
|---|
| 1023 | if ( ! isset( $params['sort'] ) ) $params['sort'] = $this->trellis->input['sort']; |
|---|
| 1024 | if ( ! isset( $params['order'] ) ) $params['order'] = $this->trellis->input['order']; |
|---|
| 1025 | if ( ! isset( $params['st'] ) ) $params['st'] = $this->trellis->input['st']; |
|---|
| 1026 | |
|---|
| 1027 | if ( $params['sort'] ) $url .= '&sort='. $params['sort']; |
|---|
| 1028 | |
|---|
| 1029 | if ( $params['order'] ) $url .= '&order='. $params['order']; |
|---|
| 1030 | |
|---|
| 1031 | if ( $params['st'] ) $url .= '&st='. $params['st']; |
|---|
| 1032 | |
|---|
| 1033 | return $url; |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | } |
|---|
| 1037 | |
|---|
| 1038 | ?> |
|---|