source: trunk/Upload/admin/manage/ad_news.php @ 73

Revision 73, 38.7 KB checked in by someotherguy, 3 years ago (diff)

Updated class naming conventions. Fixed broken my account functions.

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