From: stronk7 Date: Sun, 9 May 2004 22:20:05 +0000 (+0000) Subject: Now glossaries can produce RSS feeds too !! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2dda0bbbc7199303c5b1c7e81efd6776298e53ec;p=moodle.git Now glossaries can produce RSS feeds too !! Some strings (RSS related) has been moved from forum.php to moodle.php to avoid suplicating them once per module. It seems to work fine, please test...:-) --- diff --git a/lang/en/forum.php b/lang/en/forum.php index d12f9826a0..3a7985223d 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -114,8 +114,6 @@ $string['reply'] = 'Reply'; $string['replyforum'] = 'Reply to forum'; $string['rsssubscriberssdiscussions'] = 'Display the RSS feed for \'$a\' discussions'; $string['rsssubscriberssposts'] = 'Display the RSS feed for \'$a\' posts'; -$string['rsstype'] = "RSS feed for this forum"; -$string['rssarticles'] = "Number of RSS recent articles"; $string['search'] = 'Search'; $string['searchforums'] = 'Search forums'; $string['searcholderposts'] = 'Search older posts...'; diff --git a/lang/en/glossary.php b/lang/en/glossary.php index 2913907970..da2b2809b7 100644 --- a/lang/en/glossary.php +++ b/lang/en/glossary.php @@ -49,6 +49,7 @@ $string['commentson'] = 'Comments on'; $string['commentupdated'] = 'The comment has been updated.'; $string['concept'] = 'Concept'; $string['concepts'] = 'Concepts'; +$string['configenablerssfeeds'] = 'This switch will enable the possibility of RSS feeds for all glosaries. You will still need to turn feeds on manually in the settings for each glossary.'; $string['currentglossary'] = 'Current glossary'; $string['dateview'] = 'Browse by date'; $string['defaultapproval'] = 'Default approval status'; @@ -135,6 +136,7 @@ $string['ratingsuse'] = 'Use ratings'; $string['ratingtime'] = 'Restrict ratings to entries with dates in this range:'; $string['rejectedentries'] = 'Rejected entries'; $string['rejectionrpt'] = 'Rejection Report'; +$string['rsssubscriberss'] = 'Display the RSS feed for \'$a\' concepts'; $string['searchindefinition'] = 'Search full text'; $string['secondaryglossary'] = 'Secondary glossary'; $string['sendinratings'] = 'Send in my latest ratings'; diff --git a/lang/en/help/glossary/rssarticles.html b/lang/en/help/glossary/rssarticles.html new file mode 100644 index 0000000000..d3f33f6c40 --- /dev/null +++ b/lang/en/help/glossary/rssarticles.html @@ -0,0 +1,8 @@ +

Number of RSS recent articles

+ +

This option allows you to select the number of articles + to include in the RSS Feed. + +

A number between 5 and 20 should be appropiate for + most glossaries. Increase it if the glossary is very used. + diff --git a/lang/en/help/glossary/rsstype.html b/lang/en/help/glossary/rsstype.html new file mode 100644 index 0000000000..0256a2f4f7 --- /dev/null +++ b/lang/en/help/glossary/rsstype.html @@ -0,0 +1,14 @@ +

RSS feed for this glossary

+ +

This option allows you to enable RSS feeds in this glossary. + +

You can select between two types of feeds: + +

+ diff --git a/lang/en/moodle.php b/lang/en/moodle.php index d2f8bbf302..b148227b45 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -142,6 +142,7 @@ $string['configcountry'] = 'If you set a country here, then this country will be $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.'; $string['configdeleteunconfirmed'] = 'If you are using email authentication, this is the period within which a response will be accepted from users. After this period, old unconfirmed accounts are deleted.'; $string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site. To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.'; +$string['configenablerssfeedsdisabled'] = ' It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.'; $string['configerrorlevel'] = 'Choose the amount of PHP warnings that you want to be displayed. Normal is usually the best choice.'; $string['configfilteruploadedfiles'] = 'Enabling this setting will cause Moodle to process all uploaded HTML and text files with the filters before displaying them.'; $string['configforcelogin'] = 'Normally, the front page of the site and the course listings (but not courses) can be read by people without logging in to the site. If you want to force people to log in before they do ANYTHING on the site, then you should enable this setting.'; @@ -756,6 +757,8 @@ $string['restoreto'] = 'Restore to'; $string['returningtosite'] = 'Returning to this web site?'; $string['revert'] = 'Revert'; $string['role'] = 'Role'; +$string['rsstype'] = "RSS feed for this activity"; +$string['rssarticles'] = "Number of RSS recent articles"; $string['savechanges'] = 'Save changes'; $string['saveto'] = 'Save to'; $string['scale'] = 'Scale'; diff --git a/mod/forum/config.html b/mod/forum/config.html index 7b44f470d1..783cabe9cd 100644 --- a/mod/forum/config.html +++ b/mod/forum/config.html @@ -67,7 +67,7 @@ enablerssfeeds == 0) { - print_string("configenablerssfeedsdisabled","forum"); + print_string("configenablerssfeedsdisabled"); } ?> diff --git a/mod/forum/mod.html b/mod/forum/mod.html index 18d4df98b7..e7e7d7d9e2 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -119,19 +119,19 @@ //Only show rss parameters if rss is activated at site and forum levels if ($CFG->enablerssfeeds && $CFG->forum_enablerssfeeds) { echo ""; - echo "

".get_string("rsstype", "forum")."

"; + echo "

".get_string("rsstype")."

"; echo ""; unset($choices); $choices[0] = get_string("none"); $choices[1] = get_string("discussions", "forum"); $choices[2] = get_string("posts", "forum"); choose_from_menu ($choices, "rsstype", $form->rsstype, ""); - helpbutton("rsstype", get_string("rsstype", "forum"), "forum"); + helpbutton("rsstype", get_string("rsstype"), "forum"); echo ""; echo ""; echo ""; - echo "

".get_string("rssarticles", "forum")."

"; + echo "

".get_string("rssarticles")."

"; echo ""; unset($choices); $choices[0] = "0"; @@ -148,7 +148,7 @@ $choices[40] = "40"; $choices[50] = "50"; choose_from_menu ($choices, "rssarticles", $form->rssarticles, ""); - helpbutton("rssarticles", get_string("rssarticles", "forum"), "forum"); + helpbutton("rssarticles", get_string("rssarticles"), "forum"); echo ""; echo ""; } diff --git a/mod/glossary/config.html b/mod/glossary/config.html index 949b58e1ac..73f949e01a 100644 --- a/mod/glossary/config.html +++ b/mod/glossary/config.html @@ -264,6 +264,30 @@ + +

glossary_enablerssfeeds: + + enablerssfeeds == 0) { + print_string("no"); + } else { + unset($options); + $options[0] = get_string("no"); + $options[1] = get_string("yes"); + + choose_from_menu ($options, "glossary_enablerssfeeds", $CFG->glossary_enablerssfeeds, "", "", ""); + } + ?> + + + enablerssfeeds == 0) { + print_string("configenablerssfeedsdisabled"); + } + ?> + + "> diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php index 7e1c629b9a..00eaeabb06 100644 --- a/mod/glossary/db/mysql.php +++ b/mod/glossary/db/mysql.php @@ -249,6 +249,12 @@ function glossary_upgrade($oldversion) { set_config("textfilters", $CFG->textfilters); } } + + if ($oldversion < 2004050900) { + table_column("glossary","","rsstype","tinyint","2", "unsigned", "0", "", "entbypage"); + table_column("glossary","","rssarticles","tinyint","2", "unsigned", "0", "", "rsstype"); + set_config("glossary_enablerssfeeds",0); + } return true; } diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql index cf11269917..260d4e66e4 100644 --- a/mod/glossary/db/mysql.sql +++ b/mod/glossary/db/mysql.sql @@ -25,10 +25,12 @@ CREATE TABLE prefix_glossary ( defaultapproval tinyint(2) unsigned NOT NULL default '1', globalglossary tinyint(2) unsigned NOT NULL default '0', entbypage tinyint(3) unsigned NOT NULL default '10', - assessed int(10) unsigned NOT NULL default '0', - assesstimestart int(10) unsigned NOT NULL default '0', - assesstimefinish int(10) unsigned NOT NULL default '0', - scale int(10) NOT NULL default '0', + rsstype tinyint(2) unsigned NOT NULL default '0', + rssarticles tinyint(2) unsigned NOT NULL default '0', + assessed int(10) unsigned NOT NULL default '0', + assesstimestart int(10) unsigned NOT NULL default '0', + assesstimefinish int(10) unsigned NOT NULL default '0', + scale int(10) NOT NULL default '0', timecreated int(10) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', PRIMARY KEY (id) diff --git a/mod/glossary/db/oci8po.sql b/mod/glossary/db/oci8po.sql index d18e06be51..092dadd9b3 100755 --- a/mod/glossary/db/oci8po.sql +++ b/mod/glossary/db/oci8po.sql @@ -21,6 +21,8 @@ CREATE TABLE prefix_glossary ( showspecial number(2) default '1' not null, showall number(2) default '1' not null, showalphabet number(2) default '1' not null, + rsstype number(2) default '0' NOT NULL, + rssarticles number(2) default '0' NOT NULL, timecreated number(10) default '0' not null, timemodified number(10) default '0' not null ); diff --git a/mod/glossary/db/postgres7.php b/mod/glossary/db/postgres7.php index 15b2adaccc..76974f0ac5 100644 --- a/mod/glossary/db/postgres7.php +++ b/mod/glossary/db/postgres7.php @@ -13,6 +13,12 @@ function glossary_upgrade($oldversion) { } } + if ($oldversion < 2004050900) { + table_column("glossary","","rsstype","integer","2", "unsigned", "0", "", "entbypage"); + table_column("glossary","","rssarticles","integer","2", "unsigned", "0", "", "rsstype"); + set_config("glossary_enablerssfeeds",0); + } + return true; } diff --git a/mod/glossary/db/postgres7.sql b/mod/glossary/db/postgres7.sql index 824d5d06cf..a6e6f9788e 100644 --- a/mod/glossary/db/postgres7.sql +++ b/mod/glossary/db/postgres7.sql @@ -25,10 +25,12 @@ CREATE TABLE prefix_glossary ( defaultapproval int2 NOT NULL default '1', globalglossary int2 NOT NULL default '0', entbypage int NOT NULL default '10', - assessed int4 NOT NULL default '0', - assesstimestart int4 NOT NULL default '0', - assesstimefinish int4 NOT NULL default '0', - scale int4 NOT NULL default '0', + rsstype integer NOT NULL default '0', + rssarticles integer NOT NULL default '0', + assessed int4 NOT NULL default '0', + assesstimestart int4 NOT NULL default '0', + assesstimefinish int4 NOT NULL default '0', + scale int4 NOT NULL default '0', timecreated int4 NOT NULL default '0', timemodified int4 NOT NULL default '0', PRIMARY KEY (id) diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html index 6cf3cafd1f..c55aa71398 100644 --- a/mod/glossary/mod.html +++ b/mod/glossary/mod.html @@ -46,6 +46,12 @@ if (!isset($form->showalphabet)) { if (!isset($form->showspecial)) { $form->showspecial = 1; } + if (!isset($form->rsstype)) { + $form->rsstype = 0; + } + if (!isset($form->rssarticles)) { + $form->rssarticles = 0; + } ?>

@@ -322,6 +328,44 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) { +enablerssfeeds && $CFG->glossary_enablerssfeeds) { + echo ""; + echo "

".get_string("rsstype")."

"; + echo ""; + unset($choices); + $choices[0] = get_string("none"); + $choices[1] = get_string("withauthor", "glossary"); + $choices[2] = get_string("withoutauthor", "glossary"); + choose_from_menu ($choices, "rsstype", $form->rsstype, ""); + helpbutton("rsstype", get_string("rsstype"), "glossary"); + echo ""; + echo ""; + + echo ""; + echo "

".get_string("rssarticles")."

"; + echo ""; + unset($choices); + $choices[0] = "0"; + $choices[1] = "1"; + $choices[2] = "2"; + $choices[3] = "3"; + $choices[4] = "4"; + $choices[5] = "5"; + $choices[10] = "10"; + $choices[15] = "15"; + $choices[20] = "20"; + $choices[25] = "25"; + $choices[30] = "30"; + $choices[40] = "40"; + $choices[50] = "50"; + choose_from_menu ($choices, "rssarticles", $form->rssarticles, ""); + helpbutton("rssarticles", get_string("rssarticles"), "glossary"); + echo ""; + echo ""; + } +?>

:

diff --git a/mod/glossary/rsslib.php b/mod/glossary/rsslib.php new file mode 100644 index 0000000000..08bc03295d --- /dev/null +++ b/mod/glossary/rsslib.php @@ -0,0 +1,209 @@ +enablerssfeeds + if (empty($CFG->enablerssfeeds)) { + //Some debug... + if ($CFG->debug > 7) { + echo "DISABLED (admin variables)"; + } + //Check CFG->glossary_enablerssfeeds + } else if (empty($CFG->glossary_enablerssfeeds)) { + //Some debug... + if ($CFG->debug > 7) { + echo "DISABLED (module configuration)"; + } + //It's working so we start... + } else { + //Iterate over all glossaries + if ($glossaries = get_records("glossary")) { + foreach ($glossaries as $glossary) { + if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) { + //Some debug... + if ($CFG->debug > 7) { + echo "ID: $glossary->id->"; + } + //Get the XML contents + $result = glossary_rss_feed($glossary); + //Save the XML contents to file + if (!empty($result)) { + $status = rss_save_file("glossary",$glossary,$result); + } + //Some debug... + if ($CFG->debug > 7) { + if (empty($result)) { + echo "(empty) "; + } else { + if (!empty($status)) { + echo "OK "; + } else { + echo "FAIL "; + } + } + } + } + } + } + } + return $status; + } + + //This function return the XML rss contents about the glossary record passed as parameter + //It returns false if something is wrong + function glossary_rss_feed($glossary) { + + global $CFG; + + $status = true; + + //Check CFG->enablerssfeeds + if (empty($CFG->enablerssfeeds)) { + //Some debug... + if ($CFG->debug > 7) { + echo "DISABLED (admin variables)"; + } + //Check CFG->glossary_enablerssfeeds + } else if (empty($CFG->glossary_enablerssfeeds)) { + //Some debug... + if ($CFG->debug > 7) { + echo "DISABLED (module configuration)"; + } + //It's working so we start... + } else { + //Check the glossary has rss activated + if (!empty($glossary->rsstype) && !empty($glossary->rssarticles)) { + //Depending of the glossary->rsstype, we are going to execute, different sqls + if ($glossary->rsstype == 1) { //With author RSS + $items = glossary_rss_feed_withauthor($glossary); + } else { //Without author RSS + $items = glossary_rss_feed_withoutauthor($glossary); + + } + //Now, if items, we begin building the structure + if (!empty($items)) { + //First all rss feeds common headers + $header = rss_standard_header($glossary->name, + $CFG->wwwroot."/mod/glossary/view.php?f=".$glossary->id, + $glossary->intro); + //Now all the rss items + if (!empty($header)) { + $articles = rss_add_items($items); + } + //Now all rss feeds common footers + if (!empty($header) && !empty($articles)) { + $footer = rss_standard_footer(); + } + //Now, if everything is ok, concatenate it + if (!empty($header) && !empty($articles) && !empty($footer)) { + $status = $header.$articles.$footer; + } else { + $status = false; + } + } else { + $status = false; + } + } + } + return $status; + } + + //This function returns "items" record array to be used to build the rss feed + //for a Type=with author glossary + function glossary_rss_feed_withauthor($glossary) { + + global $CFG; + + $items = array(); + + if ($recs = get_records_sql ("SELECT e.id entryid, + e.concept entryconcept, + e.definition entrydefinition, + e.format entryformat, + e.timecreated entrytimecreated, + u.id userid, + u.firstname userfirstname, + u.lastname userlastname + FROM {$CFG->prefix}glossary_entries e, + {$CFG->prefix}user u + WHERE e.glossaryid = '$glossary->id' AND + u.id = e.userid + ORDER BY e.timecreated desc")) { + //Iterate over each entry to get glossary->rssarticles records + $articlesleft = $glossary->rssarticles; + $item = NULL; + $user = NULL; + foreach ($recs as $rec) { + unset($item); + unset($user); + $item->title = $rec->entryconcept; + $user->firstname = $rec->userfirstname; + $user->lastname = $rec->userlastname; + $item->author = fullname($user); + $item->pubdate = $rec->entrytimecreated; + $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid; + $item->description = format_text($rec->entrydefinition,$rec->entryformat,NULL,$glossary->course); + $items[] = $item; + $articlesleft--; + if ($articlesleft < 1) { + break; + } + } + } + return $items; + } + + //This function returns "items" record array to be used to build the rss feed + //for a Type=without author glossary + function glossary_rss_feed_withoutauthor($glossary) { + + global $CFG; + + $items = array(); + + if ($recs = get_records_sql ("SELECT e.id entryid, + e.concept entryconcept, + e.definition entrydefinition, + e.format entryformat, + e.timecreated entrytimecreated, + u.id userid, + u.firstname userfirstname, + u.lastname userlastname + FROM {$CFG->prefix}glossary_entries e, + {$CFG->prefix}user u + WHERE e.glossaryid = '$glossary->id' AND + u.id = e.userid + ORDER BY e.timecreated desc")) { + //Iterate over each entry to get glossary->rssarticles records + $articlesleft = $glossary->rssarticles; + $item = NULL; + $user = NULL; + foreach ($recs as $rec) { + unset($item); + unset($user); + $item->title = $rec->entryconcept; + $user->firstname = $rec->userfirstname; + $user->lastname = $rec->userlastname; + //$item->author = fullname($user); + $item->pubdate = $rec->entrytimecreated; + $item->link = $CFG->wwwroot."/mod/glossary/showentry.php?courseid=".$glossary->course."&eid=".$rec->entryid; + $item->description = format_text($rec->entrydefinition,$rec->entryformat,NULL,$glossary->course); + $items[] = $item; + $articlesleft--; + if ($articlesleft < 1) { + break; + } + } + } + return $items; + } + +?> diff --git a/mod/glossary/version.php b/mod/glossary/version.php index c9106e176f..9d48af27e1 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -5,8 +5,8 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2004022200; // The current module version (Date: YYYYMMDDXX) -$module->requires = 2004013101; // Requires this Moodle version +$module->version = 2004050900; // The current module version (Date: YYYYMMDDXX) +$module->requires = 2004050300; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) $release = "0.5 development"; // User-friendly version number diff --git a/mod/glossary/view.php b/mod/glossary/view.php index dbf27f0c45..eb660f087b 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -2,6 +2,8 @@ /// This page prints a particular instance of glossary require_once("../../config.php"); require_once("lib.php"); + require_once("$CFG->dirroot/rss/rsslib.php"); + global $CFG, $THEME, $USER; $debug = 0; $CFG->startpagetime = microtime(); @@ -217,6 +219,14 @@ "$navigation id>$strglossaries -> $glossary->name", "", "", true, update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm)); + + //If rss are activated at site and glossary level and this glossary has rss defined, show link + if ($CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype and $glossary->rssarticles) { + echo '
'; + $tooltiptext = get_string("rsssubscriberss","glossary",$glossary->name); + rss_print_link($course->id, $USER->id, "glossary", $glossary->id, $tooltiptext); + echo '
'; + } echo '

' . stripslashes_safe($glossary->name); if ( $isuserframe and $mode != 'search') {