| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: rsslib.php,v 1.11 2007/02/27 18:22:04 stronk7 Exp $ 2 //This file adds support to rss feeds generation 3 4 //This function is the main entry point to glossary 5 //rss feeds generation. Foreach site glossary with rss enabled 6 //build one XML rss structure. 7 function glossary_rss_feeds() { 8 9 global $CFG; 10 11 $status = true; 12 13 //Check CFG->enablerssfeeds 14 if (empty($CFG->enablerssfeeds)) { 15 debugging("DISABLED (admin variables)"); 16 //Check CFG->glossary_enablerssfeeds 17 } else if (empty($CFG->glossary_enablerssfeeds)) { 18 debugging("DISABLED (module configuration)"); 19 //It's working so we start... 20 } else { 21 //Iterate over all glossaries 22 if ($glossaries = get_records("glossary")) { 23 foreach ($glossaries as $glossary) { 24 if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) { 25 26 $filename = rss_file_name('glossary', $glossary); // RSS file 27 28 //First let's make sure there is work to do by checking existing files 29 if (file_exists($filename)) { 30 if ($lastmodified = filemtime($filename)) { 31 if (!glossary_rss_newstuff($glossary, $lastmodified)) { 32 continue; 33 } 34 } 35 } 36 37 //Ignore hidden forums 38 if (!instance_is_visible('glossary',$glossary)) { 39 if (file_exists($filename)) { 40 @unlink($filename); 41 } 42 continue; 43 } 44 45 mtrace("Updating RSS feed for ".format_string($glossary->name,true).", ID: $glossary->id"); 46 47 //Get the XML contents 48 $result = glossary_rss_feed($glossary); 49 //Save the XML contents to file 50 if (!empty($result)) { 51 $status = rss_save_file("glossary",$glossary,$result); 52 } 53 //Some debug... 54 if (debugging()) { 55 if (empty($result)) { 56 echo "ID: $glossary->id-> (empty) "; 57 } else { 58 if (!empty($status)) { 59 echo "ID: $glossary->id-> OK "; 60 } else { 61 echo "ID: $glossary->id-> FAIL "; 62 } 63 } 64 } 65 } 66 } 67 } 68 } 69 return $status; 70 } 71 72 function glossary_rss_newstuff($glossary, $time) { 73 // If there is new stuff in the glossary since $time then this returns 74 // true. Otherwise it returns false. 75 if ($glossary->rsstype == 1) { 76 $items = glossary_rss_feed_withauthor($glossary, $time); 77 } else { 78 $items = glossary_rss_feed_withoutauthor($glossary, $time); 79 } 80 return (!empty($items)); 81 } 82 83 //This function return the XML rss contents about the glossary record passed as parameter 84 //It returns false if something is wrong 85 function glossary_rss_feed($glossary) { 86 87 global $CFG; 88 89 $status = true; 90 91 //Check CFG->enablerssfeeds 92 if (empty($CFG->enablerssfeeds)) { 93 debugging("DISABLED (admin variables)"); 94 //Check CFG->glossary_enablerssfeeds 95 } else if (empty($CFG->glossary_enablerssfeeds)) { 96 debugging("DISABLED (module configuration)"); 97 //It's working so we start... 98 } else { 99 //Check the glossary has rss activated 100 if (!empty($glossary->rsstype) && !empty($glossary->rssarticles)) { 101 //Depending of the glossary->rsstype, we are going to execute, different sqls 102 if ($glossary->rsstype == 1) { //With author RSS 103 $items = glossary_rss_feed_withauthor($glossary); 104 } else { //Without author RSS 105 $items = glossary_rss_feed_withoutauthor($glossary); 106 107 } 108 //Now, if items, we begin building the structure 109 if (!empty($items)) { 110 //First all rss feeds common headers 111 $header = rss_standard_header(format_string($glossary->name,true), 112 $CFG->wwwroot."/mod/glossary/view.php?g=".$glossary->id, 113 format_string($glossary->intro,true)); 114 //Now all the rss items 115 if (!empty($header)) { 116 $articles = rss_add_items($items); 117 } 118 //Now all rss feeds common footers 119 if (!empty($header) && !empty($articles)) { 120 $footer = rss_standard_footer(); 121 } 122 //Now, if everything is ok, concatenate it 123 if (!empty($header) && !empty($articles) && !empty($footer)) { 124 $status = $header.$articles.$footer; 125 } else { 126 $status = false; 127 } 128 } else { 129 $status = false; 130 } 131 } 132 } 133 return $status; 134 } 135 136 //This function returns "items" record array to be used to build the rss feed 137 //for a Type=with author glossary 138 function glossary_rss_feed_withauthor($glossary, $newsince=0) { 139 140 global $CFG; 141 142 $items = array(); 143 144 if ($newsince) { 145 $newsince = " AND e.timecreated > '$newsince'"; 146 } else { 147 $newsince = ""; 148 } 149 150 if ($recs = get_records_sql ("SELECT e.id AS entryid, 151 e.concept AS entryconcept, 152 e.definition AS entrydefinition, 153 e.format AS entryformat, 154 e.timecreated AS entrytimecreated, 155 u.id AS userid, 156 u.firstname AS userfirstname, 157 u.lastname AS userlastname 158 FROM {$CFG->prefix}glossary_entries e, 159 {$CFG->prefix}user u 160 WHERE e.glossaryid = '$glossary->id' AND 161 u.id = e.userid AND 162 e.approved = 1 $newsince 163 ORDER BY e.timecreated desc")) { 164 165 //Are we just looking for new ones? If so, then return now. 166 if ($newsince) { 167 return true; 168 } 169 //Iterate over each entry to get glossary->rssarticles records 170 $articlesleft = $glossary->rssarticles; 171 $item = NULL; 172 $user = NULL; 173 174 $formatoptions = new object; 175 $formatoptions->trusttext = true; 176 177 foreach ($recs as $rec) { 178 unset($item); 179 unset($user); 180 $item->title = $rec->entryconcept; 181 $user->firstname = $rec->userfirstname; 182 $user->lastname = $rec->userlastname; 183 $item->author = fullname($user); 184 $item->pubdate = $rec->entrytimecreated; 185 $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid; 186 $item->description = format_text($rec->entrydefinition,$rec->entryformat,$formatoptions,$glossary->course); 187 $items[] = $item; 188 $articlesleft--; 189 if ($articlesleft < 1) { 190 break; 191 } 192 } 193 } 194 return $items; 195 } 196 197 //This function returns "items" record array to be used to build the rss feed 198 //for a Type=without author glossary 199 function glossary_rss_feed_withoutauthor($glossary, $newsince=0) { 200 201 global $CFG; 202 203 $items = array(); 204 205 if ($newsince) { 206 $newsince = " AND e.timecreated > '$newsince'"; 207 } else { 208 $newsince = ""; 209 } 210 211 if ($recs = get_records_sql ("SELECT e.id AS entryid, 212 e.concept AS entryconcept, 213 e.definition AS entrydefinition, 214 e.format AS entryformat, 215 e.timecreated AS entrytimecreated, 216 u.id AS userid, 217 u.firstname AS userfirstname, 218 u.lastname AS userlastname 219 FROM {$CFG->prefix}glossary_entries e, 220 {$CFG->prefix}user u 221 WHERE e.glossaryid = '$glossary->id' AND 222 u.id = e.userid AND 223 e.approved = 1 $newsince 224 ORDER BY e.timecreated desc")) { 225 226 //Are we just looking for new ones? If so, then return now. 227 if ($newsince) { 228 return true; 229 } 230 231 //Iterate over each entry to get glossary->rssarticles records 232 $articlesleft = $glossary->rssarticles; 233 $item = NULL; 234 $user = NULL; 235 236 $formatoptions = new object; 237 $formatoptions->trusttext = true; 238 239 foreach ($recs as $rec) { 240 unset($item); 241 unset($user); 242 $item->title = $rec->entryconcept; 243 $user->firstname = $rec->userfirstname; 244 $user->lastname = $rec->userlastname; 245 //$item->author = fullname($user); 246 $item->pubdate = $rec->entrytimecreated; 247 $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid; 248 $item->description = format_text($rec->entrydefinition,$rec->entryformat,$formatoptions,$glossary->course); 249 $items[] = $item; 250 $articlesleft--; 251 if ($articlesleft < 1) { 252 break; 253 } 254 } 255 } 256 return $items; 257 } 258 259 ?>
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 |