source: trunk/Upload/sources/knowledgebase.php @ 74

Revision 74, 24.3 KB checked in by someotherguy, 3 years ago (diff)

Begin re-coding user-side.

  • Property svn:executable set to *
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|    | Sources :: Knowledge Base
19#======================================================
20*/
21
22class td_source_knowledgebase {
23
24        #=======================================
25        # @ Auto Run
26        #=======================================
27
28        public function auto_run()
29        {
30                #=============================
31                # Security Checks
32                #=============================
33
34                if ( ! $this->trellis->cache->data['settings']['kb']['enable'] ) $this->trellis->skin->error('kb_disabled');
35
36                if ( ! $this->trellis->user['g_kb_access'] || $this->trellis->user['ban_kb'] )
37                {
38                        $this->trellis->log( 'security', "Blocked Access Knowledge Base" );
39
40                        $this->trellis->skin->error('banned_kb');
41                }
42
43                #=============================
44                # Initialize
45                #=============================
46
47                $this->trellis->load_lang('knowledgebase');
48
49                switch( $this->trellis->input['act'] )
50        {
51                case 'view':
52                                $this->view_article();
53                break;
54                case 'cat':
55                                $this->show_category();
56                break;
57                case 'search':
58                                $this->do_search();
59                break;
60
61                case 'editcomment':
62                                $this->edit_comment();
63                break;
64
65                case 'doaddcomment':
66                                $this->do_add_comment();
67                break;
68                case 'doeditcomment':
69                                $this->do_edit_comment();
70                break;
71                case 'dodeletecomment':
72                                $this->do_delete_comment();
73                break;
74                case 'dorate':
75                                $this->do_rate();
76                break;
77
78                default:
79                        $this->show_categories();
80                break;
81                }
82        }
83
84        #=======================================
85        # @ Show Categories
86        #=======================================
87
88        private function show_categories()
89        {
90                #=============================
91                # Grab Categories
92                #=============================
93
94                $this->trellis->load_functions('categories');
95
96                $categories = $this->trellis->func->categories->get( array( 'select' => array( 'id', 'name', 'description', 'articles' ), 'where' => array( 'parent_id', '=', 0 ), 'order' => array( 'position' => 'asc' ) ) );
97
98                #=============================
99                # Do Output
100                #=============================
101
102                $this->trellis->skin->set_var( 'categories', $categories );
103
104                $this->nav = array(
105                                                   '<a href="'. $this->trellis->config['hd_url'] .'/index.php?page=kb">'. $this->trellis->lang['knowledge_base'] .'</a>',
106                                                   );
107
108                $this->trellis->skin->set_var( 'sub_tpl', 'knowledge_base.tpl' );
109
110                $this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] ) );
111        }
112
113        #=======================================
114        # @ Show Category
115        #=======================================
116
117        private function show_category()
118        {
119                #=============================
120                # Grab Category
121                #=============================
122
123                $this->trellis->load_functions('categories');
124
125                if ( ! $c = $this->trellis->func->categories->get_single_by_id( array( 'id', 'name', 'description', 'articles' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_category');
126
127                $this->trellis->skin->set_var( 'c', $c );
128
129                #=============================
130                # Grab Sub-Categories
131                #=============================
132
133                $categories = $this->trellis->func->categories->get( array( 'select' => array( 'id', 'name', 'description', 'articles' ), 'where' => array( 'parent_id', '=', $this->trellis->input['id'] ), 'order' => array( 'position' => 'asc' ) ) );
134
135                $this->trellis->skin->set_var( 'categories', $categories );
136
137                #=============================
138                # Grab Articles
139                #=============================
140
141                $this->trellis->load_functions('articles');
142
143                $articles = $this->trellis->func->articles->get( array( 'select' => array( 'id', 'title', 'description', 'rating', 'views', 'comments' ), 'where' => array( 'cid', '=', $c['id'] ), 'order' => array( 'title' => 'asc' ) ) );
144
145                $this->trellis->skin->set_var( 'articles', $articles );
146
147                #=============================
148                # Do Output
149                #=============================
150
151                $this->nav = array(
152                                                   '<a href="'. $this->trellis->config['hd_url'] .'/index.php?page=kb">'. $this->trellis->lang['knowledge_base'] .'</a>',
153                                                   '<a href="'. $this->trellis->config['hd_url'] .'/index.php?page=kb&amp;act=cat&amp;id='. $this->trellis->input['id'] .'">'. $c['name'] .'</a>',
154                                                   );
155
156                $this->trellis->skin->set_var( 'sub_tpl', 'kb_category.tpl' );
157
158                $this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $c['name'] ) );
159        }
160
161        #=======================================
162        # @ Show Article
163        #=======================================
164
165        private function view_article($alert="", $error="")
166        {
167                #=============================
168                # Grab Article
169                #=============================
170
171                $this->trellis->load_functions('articles');
172
173                if ( ! $a = $this->trellis->func->articles->get_single_by_id( array( 'id', 'cid', 'title', 'description', 'content', 'rating_average', 'votes', 'views', 'comments', 'html', 'date', 'modified', 'allow_comments', 'allow_rating' ), $this->trellis->input['id'] ) )
174                {
175                        $this->trellis->log( 'error', "Article Not Found ID: ". $this->trellis->input['id'] );
176
177                        $this->trellis->skin->error('no_article');
178                }
179
180                #=============================
181                # Fix Up Information
182                #=============================
183
184                $a['date_human'] = $this->trellis->td_timestamp( array( 'time' => $a['date'], 'format' => 'short' ) );
185
186                $aoutput_params = array( 'linkify' => 1 );
187
188                if ( $a['html'] )
189                {
190                        $aoutput_params['html'] = 1;
191                }
192                else
193                {
194                        $aoutput_params['paragraphs'] = 1;
195                        $aoutput_params['nl2br'] = 1;
196                }
197
198                $a['content'] = $this->trellis->prepare_output( $a['content'], $aoutput_params );
199
200                #=============================
201                # Can We Rate?
202                #=============================
203
204                if ( $this->trellis->cache->data['settings']['kb']['rating'] && $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_rating'] && $a['allow_rating'] )
205                {
206                        if ( $this->trellis->user['id'] && $this->trellis->user['g_kb_rate'] ) # TODO: allow guests to rate
207                        {
208                                if ( $this->trellis->func->articles->get_single_rating( array( 'id' ), array( array( 'aid', '=', $a['id'] ), array( 'uid', '=', $this->trellis->user['id'], 'and' ) ) ) )
209                                {
210                                        $rate = $this->rate_stars( $a['rating_average'], 0, $a['id'] );
211                                }
212                                else
213                                {
214                                        $rate = $this->rate_stars( $a['rating_average'], 1, $a['id'] );
215                                }
216                        }
217                        else
218                        {
219                                $rate = $this->rate_stars( $a['rating_average'], 0, $a['id'] );
220                        }
221
222                        $this->trellis->skin->set_var( 'rate', $rate );
223                }
224
225                #=============================
226                # Grab Comments?
227                #=============================
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' => 'article_comments' ),
235                                                                                                                 'join'     => array( array( 'from' => array( 'u' => 'users' ), 'where' => array( 'c' => 'uid', '=', 'u' => 'id' ) ) ),
236                                                                                                                 'where'        => array( array( 'c' => 'aid' ), '=', $a['id'] ),
237                                                                                                                 'order'    => array( 'date' => array( 'c' => 'asc' ) ),
238                                                  ), 'id' );
239
240                if ( $comments )
241                {
242                    foreach ( $comments as $c )
243                    {
244                                #=============================
245                                # Fix Up Information
246                                #=============================
247
248                                $comments[ $c['id'] ]['time_ago'] = $this->trellis->td_timestamp( array( 'time' => $comments[ $c['id'] ]['date'], 'format' => 'relative' ) );
249
250                                $comments[ $c['id'] ]['date_human'] = $this->trellis->td_timestamp( array( 'time' => $comments[ $c['id'] ]['date'], 'format' => 'short' ) );
251
252                        $coutput_params = array( 'linkify' => 1 );
253
254                            if ( $c['html'] )
255                                {
256                                        $coutput_params['html'] = 1;
257                                }
258                                else
259                                {
260                                        $coutput_params['paragraphs'] = 1;
261                                        $coutput_params['nl2br'] = 1;
262                                }
263
264                                // Permissions for Templates
265                                if ( $c['uid'] == $this->trellis->user['id'] )
266                                {
267                                        if ( $this->trellis->user['g_kb_com_edit'] ) $comments[ $c['id'] ]['can_edit'] = 1;
268                                        if ( $this->trellis->user['g_kb_com_delete'] ) $comments[ $c['id'] ]['can_delete'] = 1;
269                                }
270
271                        $comments[ $c['id'] ]['message'] = $this->trellis->prepare_output( $c['message'], $coutput_params );
272                    }
273
274                        $this->trellis->skin->set_var( 'comments', $comments );
275                }
276
277                #=============================
278                # Stats
279                #=============================
280
281                $this->trellis->func->articles->increase_count( $a['id'], 1, 'views' );
282
283                #=============================
284                # Do Output
285                #=============================
286
287                if ( $error ) $this->trellis->skin->set_var( 'error', $this->trellis->lang[ 'err_'. $error ] );
288                if ( $alert ) $this->trellis->skin->set_var( 'alert', $this->trellis->lang[ 'alert_'. $alert ] );
289
290                // Permissions for Templates
291                if ( $this->trellis->cache->data['settings']['kb']['comments'] && $this->trellis->user['g_kb_comment'] && $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_comments'] && $a['allow_comments'] ) $a['can_comment'] = 1;
292
293                $this->trellis->skin->set_var( 'a', $a );
294
295                $this->nav = array(
296                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb'>{$this->trellis->lang['knowledge_base']}</a>",
297                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb&amp;act=cat&amp;id={$a['cid']}'>{$this->trellis->cache->data['categories'][ $a['cid'] ]['name']}</a>",
298                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb&amp;act=view&amp;id={$a['id']}'>{$a['title']}</a>",
299                                                   );
300
301                if ( $type == 'print' )
302                {
303                        $this->trellis->skin->set_var( 'sub_tpl', 'kb_print_article.tpl' );
304
305                        $this->trellis->skin->do_print( array( 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $a['name'] ) );
306                }
307                else
308                {
309                        $this->trellis->skin->set_var( 'sub_tpl', 'kb_article.tpl' );
310
311                        $this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $a['name'] ) );
312                }
313        }
314
315        #=======================================
316        # @ Submit Comment
317        #=======================================
318
319        private function do_add_comment()
320        {
321                #=============================
322                # Security Checks
323                #=============================
324
325                $this->trellis->load_functions('articles');
326
327                if ( ! $this->trellis->input['message'] ) $this->view_article( null, 'no_message' );
328
329                if ( ! $a = $this->trellis->func->articles->get_single_by_id( array( 'id', 'cid', 'title', 'allow_comments' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_article');
330
331                if ( ! $this->trellis->cache->data['settings']['kb']['comments'] || ! $this->trellis->user['g_kb_comment'] || ! $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_comments'] || ! $a['allow_comments'] ) $this->trellis->skin->error('no_perm');
332
333                #=============================
334                # Add Comment
335                #=============================
336
337                $db_array = array(
338                                                  'aid'                 => $a['id'],
339                                                  'uid'                 => $this->trellis->user['id'],
340                                                  'message'             => $this->trellis->input['message'],
341                                                  'date'                => time(),
342                                                  'ipadd'               => $this->trellis->input['ip_address'],
343                                                 );
344
345                $comment_id = $this->trellis->func->articles->add_comment( $db_array, $a['id'] );
346
347                #=============================
348                # Redirect
349                #=============================
350
351                $this->trellis->skin->redirect( '?page=kb&act=view&id='. $a['id'] .'#com'. $comment_id, 'submit_comment_success' );
352        }
353
354        #=======================================
355        # @ Do Search
356        #=======================================
357
358        function do_search()
359        {
360                #=============================
361                # Search!
362                #=============================
363
364                # TODO: improve / finish search!
365
366                $this->trellis->check_token('search');
367
368                $searchstring = $this->trellis->input['keywords'];
369
370                #$sql = "SELECT *, MATCH(name, description, article) AGAINST ('$searchstring') AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring') ORDER BY score DESC";
371
372                $sql = "SELECT *, ( 1.6 * ( MATCH(keywords) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + 0.9 * ( MATCH(name) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + ( 0.6 * ( MATCH(article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) ) ) AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
373                #$sql = "SELECT *, ( 1.6 * ( MATCH(name) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + ( 0.9 * ( MATCH(article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) ) ) AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
374                #$sql = "SELECT *, ( 0.9 * ( MATCH(name) AGAINST ('$searchstring' IN BOOLEAN MODE) ) + ( 1.6 * ( MATCH(article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) ) ) AS score FROM ". DB_PRE ."articles WHERE MATCH(name, description, article) AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
375
376                #$sql = "SELECT *, ( (1.3 * (MATCH(name) AGAINST ('+{$searchtitle}' IN BOOLEAN MODE))) + (0.6 * (MATCH(article) AGAINST ('+$searchstring' IN BOOLEAN MODE))) ) AS score FROM ". DB_PRE ."articles WHERE ( MATCH(name,article) AGAINST ('$searchstring' IN BOOLEAN MODE) ) HAVING score > 0 ORDER BY score DESC";
377
378                $this->trellis->db->query( $sql );
379
380                $art = ""; // Initialize for Security
381
382                while( $m = $this->trellis->db->fetch_row() )
383                {
384                        if ( $m['score'] > $max_score )
385                        {
386                                $max_score = $m['score'];
387                        }
388
389                        $art[] = $m;
390                }
391
392                $articles = array(); // Initialize for Security
393                $row_count = 0; // Initialize for Security
394
395                if ( is_array( $art ) )
396                {
397                        while ( list( , $a ) = each( $art ) )
398                    {
399                                #=============================
400                                # Fix Up Information
401                                #=============================
402
403                                $row_count ++;
404
405                                ( $row_count & 1 ) ? $a['class'] = 1 : $a['class'] = 2;
406
407                                $a['date'] = $this->trellis->a5_date( $a['date'] );
408
409                                $a['score'] = @ round( ( $a['score'] / $max_score ) * 100 ) ."%";
410
411                        $articles[] = $a;
412                    }
413
414                    $this->trellis->skin->set_var( 'results', $articles );
415            }
416
417            #=============================
418                # Do Output
419                #=============================
420
421                $this->nav = array(
422                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?act=kb'>{$this->trellis->lang['knowledge_base']}</a>",
423                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?act=kb&amp;code=search'>{$this->trellis->lang['search_results']}</a>",
424                                                   );
425
426                $this->trellis->skin->set_var( 'sub_tpl', 'kb_search_results.tpl' );
427
428                $this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $this->trellis->lang['search_results'] ) );
429        }
430
431        #=======================================
432        # @ Do Rate
433        #=======================================
434
435        private function do_rate()
436        {
437                #=============================
438                # Security Checks
439                #=============================
440
441                $this->trellis->load_functions('articles');
442
443                if ( ! $a = $this->trellis->func->articles->get_single_by_id( array( 'id', 'cid', 'title', 'rating_total', 'votes', 'allow_rating' ), $this->trellis->input['id'] ) ) $this->trellis->skin->error('no_article');
444
445                if ( ! $this->trellis->user['id'] )
446                {
447                        $this->trellis->log( 'security', "Article Rating Blocked From Guest &#039;". $a['name'] ."&#039;", 1, $a['id'] );
448
449                        $this->trellis->skin->error( 'must_be_user', 1 );
450                }
451
452                $allowed_ratings = array( 1, 2, 3, 4, 5 );
453
454                if ( ! in_array( $this->trellis->input['amount'], $allowed_ratings ) )
455                {
456                        $this->trellis->log( 'security', "Invalid Article Rating Amount &#039;". $a['name'] ."&#039;", 1, $a['id'] );
457
458                        $this->trellis->skin->error('invalid_rate_value');
459                }
460
461                if ( ! $this->trellis->cache->data['settings']['kb']['rating'] || ! $this->trellis->user['g_kb_rate'] || ! $this->trellis->cache->data['categories'][ $a['cid'] ]['allow_rating'] || ! $a['allow_rating'] ) $this->trellis->skin->error('no_perm');  # TD LOG no perm
462
463                if ( $this->trellis->func->articles->get_single_rating( array( 'id' ), array( array( 'aid', '=', $a['id'] ), array( 'uid', '=', $this->trellis->user['id'], 'and' ) ) ) )
464                {
465                        $this->trellis->log( 'security', "Already Rated Article By User &#039;". $a['name'] ."&#039;", 1, $a['id'] );
466
467                        #$this->trellis->skin->error('already_rated');
468                }
469
470                #=============================
471                # Add Rating
472                #=============================
473
474                $this->trellis->func->articles->add_rating( $this->trellis->input['amount'], $a['id'], array( 'rating_total' => $a['rating_total'], 'votes' => $a['votes'] ) );
475
476                $this->trellis->log( 'user', "Article Rating Value ". $this->trellis->input['amount'] ." Added &#039;". $a['name'] ."&#039;", 1, $a['id'] );
477
478            #=============================
479                # Do Output
480                #=============================
481
482                $this->view_article( 'rating_added' );
483        }
484
485        #=======================================
486        # @ Edit Comment
487        # Show edit comment form.
488        #=======================================
489
490        function edit_comment($error="")
491        {
492                #=============================
493                # Security Checks
494                #=============================
495
496                $this->trellis->input['id'] = intval( $this->trellis->input['id'] );
497
498                $this->trellis->db->construct( array(
499                                                                                                 'select'       => 'all',
500                                                                                                 'from'         => 'article_comments',
501                                                                                                 'where'        => array( 'id', '=', $this->trellis->input['id'] ),
502                                                                                                 'limit'        => array( 0, 1 ),
503                                                                                  )     );
504
505                $this->trellis->db->execute();
506
507                if ( ! $this->trellis->db->get_num_rows() )
508                {
509                        $this->trellis->log( 'error', "Comment Not Found ID: ". $this->trellis->input['id'] );
510
511                        $this->trellis->skin->error('no_comment');
512                }
513
514                $c = $this->trellis->db->fetch_row();
515
516                if ( ! $this->trellis->user['g_kb_com_edit'] || $c['uid'] != $this->trellis->user['id'] )
517                {
518                        $this->trellis->log( 'security', "Blocked Editing of Comment" );
519
520                        $this->trellis->skin->error('no_perm_com_edit');
521                }
522
523                $this->trellis->skin->set_var( 'comment', $c );
524
525                #=============================
526                # Do Output
527                #=============================
528
529                if ( $error )
530                {
531                        $this->trellis->skin->set_var( 'error', $this->trellis->lang[ 'err_'. $error ] );
532                }
533
534                $this->nav = array(
535                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb'>{$this->trellis->lang['knowledge_base']}</a>",
536                                                   "<a href='{$this->trellis->config['hd_url']}/index.php?page=kb&amp;act=edit&amp;id={$c['id']}'>{$this->trellis->lang['edit_comment']}</a>",
537                                                   );
538
539                $this->trellis->skin->set_var( 'sub_tpl', 'kb_edit_comment.tpl' );
540
541                $this->trellis->skin->do_output( array( 'nav' => $this->nav, 'title' => $this->trellis->lang['knowledge_base'] .' :: '. $this->trellis->lang['edit_comment'] ) );
542        }
543
544        #=======================================
545        # @ Do Edit Comment
546        # Edit comment. :P
547        #=======================================
548
549        function do_edit_comment()
550        {
551                #=============================
552                # Security Checks
553                #=============================
554
555                $this->trellis->load_functions('articles');
556
557                $this->trellis->input['id'] = intval( $this->trellis->input['id'] );
558
559                $this->trellis->db->construct( array(
560                                                                                                 'select'       => 'all',
561                                                                                                 'from'         => 'article_comments',
562                                                                                                 'where'        => array( 'id', '=', $this->trellis->input['id'] ),
563                                                                                                 'limit'        => array( 0, 1 ),
564                                                                                  )     );
565
566                $this->trellis->db->execute();
567
568                if ( ! $this->trellis->db->get_num_rows() )
569                {
570                        $this->trellis->log( 'error', "Comment Not Found ID: ". $this->trellis->input['id'] );
571
572                        $this->trellis->skin->error('no_comment');
573                }
574
575                $c = $this->trellis->db->fetch_row();
576
577                if ( ! $this->trellis->user['g_kb_com_edit'] || $c['uid'] != $this->trellis->user['id'] )
578                {
579                        $this->trellis->log( 'security', "Blocked Editing of Comment" );
580
581                        $this->trellis->skin->error('no_perm_com_edit');
582                }
583
584                #=============================
585                # Update Comment
586                #=============================
587
588                $this->trellis->func->articles->edit_comment( array( 'message' => $this->trellis->input['message'] ), $c['id'] );
589
590                $this->trellis->log( 'user', "Article Comment Edited ID #". $c['id'], 1, $c['id'] );
591
592                #=============================
593                # Do Output
594                #=============================
595
596                $this->trellis->skin->redirect( '?page=kb&act=view&id='. $c['aid'] .'#com'. $c['id'], 'edit_comment_success' );
597        }
598
599        #=======================================
600        # @ Do Delete Comment
601        # Delete comment. :(
602        #=======================================
603
604        function do_delete_comment()
605        {
606                #=============================
607                # Security Checks
608                #=============================
609
610                $this->trellis->load_functions('articles');
611
612                $this->trellis->input['id'] = intval( $this->trellis->input['id'] );
613
614                $this->trellis->db->construct( array(
615                                                                                                 'select'       => 'all',
616                                                                                                 'from'         => 'article_comments',
617                                                                                                 'where'        => array( 'id', '=', $this->trellis->input['id'] ),
618                                                                                                 'limit'        => array( 0, 1 ),
619                                                                                  )     );
620
621                $this->trellis->db->execute();
622
623                if ( ! $this->trellis->db->get_num_rows() )
624                {
625                        $this->trellis->log( 'error', "Comment Not Found ID: ". $this->trellis->input['id'] );
626
627                        $this->trellis->skin->error('no_comment');
628                }
629
630                $c = $this->trellis->db->fetch_row();
631
632                if ( ! $this->trellis->user['g_kb_com_delete'] || $c['uid'] != $this->trellis->user['id'] )
633                {
634                        $this->trellis->log( 'security', "Blocked Deleting of Comment" );
635
636                        $this->trellis->skin->error('no_perm_com_delete');
637                }
638
639                #=============================
640                # Delete Comment
641                #=============================
642
643                $this->trellis->func->articles->delete_comment( $c['id'], array( 'aid' => $c['aid'] ) );
644
645                $this->trellis->log( 'user', "Article Comment Deleted ID #". $c['id'], 2, $c['id'] );
646
647                #=============================
648                # Do Output
649                #=============================
650
651                $this->trellis->skin->redirect( '?page=kb&act=view&id='. $c['aid'], 'delete_comment_success' );
652        }
653
654        #=======================================
655        # @ rate_stars()
656        #=======================================
657
658        function rate_stars($rating, $rate=0, $fid=0)
659        {
660                # TODO: move to templates
661
662                $half = 0; // Initialize for Security
663
664                if ( strstr( $rating, '.' ) )
665                {
666                        $half = 1;
667                }
668
669                $real_rating = $rating;
670
671                for ( $x = 1; $x < $rating + 1; $x++ )
672            {
673                if ( $half && $x == $rating )
674                {
675                        if ( $rate )
676                        {
677                                $a5_html .= "<a href='". $this->trellis->config['hd_url'] ."/index.php?page=kb&amp;act=dorate&amp;amount=". $x ."&amp;id={$fid}' title='". $x ." ". $this->trellis->lang['stars'] ."'><img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_half.gif' alt='". $this->trellis->lang['half_star'] ."' name='rate". $x ."' style='vertical-align:top' onmouseover='amirate(". $x .")' onmouseout='unamirate(". $real_rating .")' /></a>";
678                        }
679                        else
680                        {
681                                $a5_html .= "<img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_half.gif' alt='". $this->trellis->lang['half_star'] ."' name='rate". $x ."' style='vertical-align:top' />";
682                        }
683                }
684                else
685                {
686                        if ( $rate )
687                        {
688                                $a5_html .= "<a href='". $this->trellis->config['hd_url'] ."/index.php?page=kb&amp;act=dorate&amp;amount=". $x ."&amp;id={$fid}' title='". $x ." ". $this->trellis->lang['stars'] ."'><img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_on.gif' alt='". $this->trellis->lang['lang.full_star'] ."' name='rate". $x ."' style='vertical-align:top' onmouseover='amirate(". $x .")' onmouseout='unamirate(". $real_rating .")' /></a>";
689                        }
690                        else
691                        {
692                                $a5_html .= "<img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_on.gif' alt='". $this->trellis->lang['full_star'] ."' name='rate". $x ."' style='vertical-align:top' />";
693                        }
694                }
695            }
696
697            for ( $x = $x; $x <= 5; $x++ )
698            {
699                if ( $rate )
700                {
701                        $a5_html .= "<a href='". $this->trellis->config['hd_url'] ."/index.php?page=kb&amp;act=dorate&amp;amount=". $x ."&amp;id={$fid}' title='". $x ." ". $this->trellis->lang['stars'] ."'><img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_off.gif' alt='". $this->trellis->lang['no_star'] ."' name='rate". $x ."' style='vertical-align:top' onmouseover='amirate(". $x .")' onmouseout='unamirate(". $real_rating .")' /></a>";
702                }
703                else
704                {
705                        $a5_html .= "<img src='images/". $this->trellis->skin->data['img_dir'] ."/rate_off.gif' alt='". $this->trellis->lang['no_star'] ."' name='rate". $x ."' style='vertical-align:top' />";
706                }
707            }
708
709                return $a5_html;
710        }
711
712}
713
714?>
Note: See TracBrowser for help on using the repository browser.