| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once($CFG->dirroot.'/lib/rsslib.php'); 4 require_once($CFG->dirroot .'/blog/lib.php'); 5 6 7 // This function returns the icon (from theme) with the link to rss/file.php 8 // needs some hacking to rss/file.php 9 function blog_rss_print_link($filtertype, $filterselect, $tagid=0, $tooltiptext='') { 10 11 global $CFG, $USER; 12 13 if (empty($USER->id)) { 14 $userid = 1; 15 } else { 16 $userid = $USER->id; 17 } 18 19 switch ($filtertype) { 20 case 'site': 21 $path = SITEID.'/'.$userid.'/blog/site/'.SITEID; 22 break; 23 case 'course': 24 $path = $filterselect.'/'.$userid.'/blog/course/'.$filterselect; 25 break; 26 case 'group': 27 $path = SITEID.'/'.$userid.'/blog/group/'.$filterselect; 28 break; 29 case 'user': 30 $path = SITEID.'/'.$userid.'/blog/user/'.$filterselect; 31 break; 32 } 33 34 if ($tagid) { 35 $path .= '/'.$tagid; 36 } 37 38 $path .= '/rss.xml'; 39 $rsspix = $CFG->pixpath .'/i/rss.gif'; 40 41 require_once($CFG->libdir.'/filelib.php'); 42 $path = get_file_url($path, null, 'rssfile'); 43 print '<div align="right"><a href="'. $path .'"><img src="'. $rsspix .'" title="'. strip_tags($tooltiptext) .'" alt="'.get_string('rss').'" /></a></div>'; 44 45 } 46 47 48 // Generate any blog RSS feed via one function (called by ../rss/file.php) 49 function blog_generate_rss_feed($type, $id, $tagid=0) { 50 global $CFG, $SITE; 51 52 if (empty($CFG->enablerssfeeds)) { 53 debugging('Sorry, RSS feeds are disabled on this site'); 54 return ''; 55 } 56 57 $filename = blog_rss_file_name($type, $id, $tagid); 58 59 if (file_exists($filename)) { 60 if (filemtime($filename) + 3600 > time()) { 61 return $filename; /// It's already done so we return cached version 62 } 63 } 64 65 /// Get all the posts from the database 66 67 $blogposts = blog_fetch_entries('', 20, '', $type, $id, $tagid); 68 69 /// Now generate an array of RSS items 70 if ($blogposts) { 71 $items = array(); 72 foreach ($blogposts as $blogpost) { 73 $item = NULL; 74 $item->author = fullname(get_record('user','id',$blogpost->userid)); 75 $item->title = $blogpost->subject; 76 $item->pubdate = $blogpost->lastmodified; 77 $item->link = $CFG->wwwroot.'/blog/index.php?postid='.$blogpost->id; 78 $item->description = format_text($blogpost->summary, $blogpost->format); 79 $items[] = $item; 80 } 81 $articles = rss_add_items($items); /// Change structure to XML 82 } else { 83 $articles = ''; 84 } 85 86 /// Get header and footer information 87 88 switch ($type) { 89 case 'user': 90 $info = fullname(get_record('user', 'id', $id, '','','','','firstname,lastname')); 91 break; 92 case 'course': 93 $info = get_field('course', 'fullname', 'id', $id); 94 break; 95 case 'site': 96 $info = $SITE->fullname; 97 break; 98 case 'group': 99 $group = groups_get_group($id, false); 100 $info = $group->name; //TODO: get_field('groups', 'name', 'id', $id) 101 break; 102 default: 103 $info = ''; 104 break; 105 } 106 107 if ($tagid) { 108 $info .= ': '.get_field('tags', 'text', 'id', $tagid); 109 } 110 111 $header = rss_standard_header(get_string($type.'blog','blog', $info), 112 $CFG->wwwroot.'/blog/index.php', 113 get_string('intro','blog')); 114 115 $footer = rss_standard_footer(); 116 117 118 /// Save the XML contents to file. 119 120 $rssdata = $header.$articles.$footer; 121 122 if (blog_rss_save_file($type,$id,$tagid,$rssdata)) { 123 return $filename; 124 } else { 125 return false; // Couldn't find it or make it 126 } 127 } 128 129 130 function blog_rss_file_name($type, $id, $tagid=0) { 131 global $CFG; 132 133 if ($tagid) { 134 return "$CFG->dataroot/rss/blog/$type/$id/$tagid.xml"; 135 } else { 136 return "$CFG->dataroot/rss/blog/$type/$id.xml"; 137 } 138 } 139 140 //This function saves to file the rss feed specified in the parameters 141 function blog_rss_save_file($type, $id, $tagid=0, $contents='') { 142 global $CFG; 143 144 if (! $basedir = make_upload_directory("rss/blog/$type/$id")) { 145 return false; 146 } 147 148 $file = blog_rss_file_name($type, $id, $tagid); 149 $rss_file = fopen($file, 'w'); 150 if ($rss_file) { 151 $status = fwrite ($rss_file, $contents); 152 fclose($rss_file); 153 } else { 154 $status = false; 155 } 156 157 return $status; 158 } 159 160 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |