Changeset 306 for hot_topics

Show
Ignore:
Timestamp:
05/11/08 20:00:08 (7 months ago)
Author:
rho
Message:

Improved hottopics plugin

  • Code cleanup
  • Added INSTALL.txt
  • Added template

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hot_topics/trunk/lib.php

    r201 r306  
    1515*/ 
    1616 
     17/* 
     18 * @changelog 2008-05-11        Install text, code cleanup and tweak 
     19 *            Rolando Espinoza La fuente 
     20 */ 
     21 
    1722    function hottopics_pagesetup() { 
    18          
     23        // register template 
     24        templates_add_context('hottopics:link', 'mod/hottopics/templates/hottopics_link.html');          
    1925    } 
    2026     
     
    3844                $days=7; 
    3945                } else { 
    40                 $days=$vars[1]; 
     46                $days=(int)$vars[1]; 
    4147                } 
    4248                 
     
    4854                $limit=5; 
    4955                } else { 
    50                 $limit=$vars[2]; 
     56                $limit=(int)$vars[2]; 
    5157                } 
    5258                 
     
    5662                $count=2; 
    5763                } else { 
    58                 $count=$vars[3]; 
     64                $count=(int)$vars[3]; 
    5965                } 
    6066                 
     
    6470 
    6571 
    66  
    67 $query_weblogs =  "SELECT {$CFG->prefix}weblog_comments.post_id, {$CFG->prefix}weblog_posts.ident, {$CFG->prefix}weblog_posts.title, {$CFG->prefix}weblog_posts.posted, count(*) FROM `{$CFG->prefix}weblog_comments`, `{$CFG->prefix}weblog_posts` WHERE {$CFG->prefix}weblog_posts.ident = {$CFG->prefix}weblog_comments.post_id AND ({$CFG->prefix}weblog_posts.access= 'PUBLIC' OR {$CFG->prefix}weblog_posts.access='LOGGED_IN') AND DATE_SUB( CURDATE( ) , INTERVAL ".$days." DAY ) <= FROM_UNIXTIME({$CFG->prefix}weblog_comments.posted) GROUP BY {$CFG->prefix}weblog_comments.post_id HAVING count(*)>".$count." ORDER BY count(*) DESC, {$CFG->prefix}weblog_posts.title LIMIT ".$limit; 
     72        $query_weblogs = " 
     73            SELECT wc.post_id, wp.owner, wp.title, wp.posted, 
     74            count(*) as rank 
     75            FROM {$CFG->prefix}weblog_comments wc, {$CFG->prefix}weblog_posts wp 
     76            WHERE wp.ident = wc.post_id 
     77            AND wp.access in ('PUBLIC', 'LOGGED_IN') 
     78            AND DATE_SUB( CURDATE() , INTERVAL {$days} DAY ) <= FROM_UNIXTIME(wc.posted) 
     79            GROUP BY wc.post_id HAVING rank > {$count} 
     80            ORDER BY rank DESC, wp.title 
     81            LIMIT {$limit}"; 
    6882 
    6983 
    7084//GET THE RESULTS FROM DB 
    7185 
    72 $posts = get_records_sql($query_weblogs); 
     86        $posts = get_records_sql($query_weblogs); 
     87        $html = ''; 
    7388 
    74 if ($posts) { 
     89        if ($posts) { 
     90            $params = array('context' => 'hottopics:link'); 
    7591 
    76 $html .="<span>"; 
     92            foreach($posts as $key => $info) { 
     93             
     94                $username = user_info('username', $info->owner); 
     95                $postid=$info->post_id; 
     96                $posttitle = htmlspecialchars($info->title, ENT_COMPAT, 'utf-8'); 
    7797 
    78         foreach($posts as $key => $info) { 
    79                  
    80          
    81             $usrid = $info->ident; 
    82                         $postid=$info->post_id; 
    83                         $posttitle = $info->title; 
    84          
    85                          
    86         // GET THE POST OWNERS USERNAME (CAN THIS BE DONE ANOTHER WAY?) 
    87                          
    88                          $query_blogger = "SELECT * FROM {$CFG->prefix}users WHERE ident = ".$usrid; 
    89                           
    90 $blogger = get_records_sql($query_blogger); 
     98                // Maybe there is some post without title... ¿? 
     99                if (empty($posttitle)) { 
     100                    $posttitle = __gettext("Weblog post"); 
     101                } 
     102             
     103                $params['title'] = $posttitle; 
     104                $params['permalink'] = $CFG->wwwroot . $username . '/weblog/' . $postid . '.html'; 
     105                $params['comments'] = $info->rank; 
     106                $params['date'] = strftime('%Y-%m-%d', $info->posted); 
    91107 
    92 foreach ($blogger as $key1 => $value) { 
     108                $html .= templates_draw($params); 
    93109 
    94          
    95         $username=$value->username; 
    96          
    97         // OUTPUT LINK FOR EACH MATCHING POST - NOTE HTML CAN BE CHANGED TO SUITE NEEDS - E.G. REPLACE <P> WITH <LI> ETC 
    98          
    99         $html .= "<P><A HREF='".$username."/weblog/".$postid.".html'>".$posttitle."</A></P>"; 
    100 
    101  
    102  
    103  
    104 
    105  $html .="</span>"; 
    106   
    107  } 
     110            } 
     111        } 
    108112 
    109113// RETURN RESULTANT HTML TO THE PAGE 
     
    113117    } 
    114118 
    115 ?>