c6df5387adeede37398bad26f5819571826cffcf
[atutor.git] / mods / wordpress / module_news.php
1 <?php
2 /*
3 * Rename the function to match the name of the module. Names of all news functions must be unique
4 * across all modules installed on a system. Return a variable called $news
5 */
6 require('wp_connect.php');
7                 // Number of links to be displayed on "detail view" box
8 function wordpress_news() {
9         global $db_wp, $_config;
10 if($_GET['p'] != "all"){
11         $link_limit = "LIMIT 3";
12 }
13
14         $news = array();
15
16         $sql = "SELECT ID, post_title, guid, post_content, post_modified FROM ".WP_DB_PREFIX."posts WHERE post_status = 'publish' ORDER BY post_modified DESC ".$link_limit;
17         
18 $result = mysql_query($sql, $db_wp);
19
20         if($result){
21                 //$news_count = 0;
22                 //$page_ids = array();
23                 $post_title = array();
24                 while($row = mysql_fetch_assoc($result)){
25                 if(strlen($row['post_content']) > 100){
26                         $row['post_content'] = substr($row['post_content'],0,100)."...";
27                 }
28                                 if(!in_array($row['post_title'], $post_title)){
29                                 $post_title[] = $row['post_title'];
30                                 $news[] = array('time'=> $row['post_modified'], 
31                                         'alt'=>_AT('wordpress_update'),
32                                         'thumb'=>'mods/wordpress/wordpress_icon_sm.png', 
33                                         'link'=>'<a href="'.AT_BASE_HREF.url_rewrite('mods/wordpress/index_mystart.php?p='.$row['ID']).'"'.
34                                         (strlen($row['post_title']) > SUBLINK_TEXT_LEN ? ' title="'.$row['post_title'].'"' : '') .'>'. 
35                                         validate_length($row['post_title'], SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a> <br />'.$row['post_content']);
36                                 }
37                 }
38         }
39
40         return $news;
41
42 }
43 ?>