]> git.mjollnir.org Git - moodle.git/commitdiff
block_rss_client: MDL-13932 Clean up a lot of the crap.
authortjhunt <tjhunt>
Wed, 29 Jul 2009 11:18:55 +0000 (11:18 +0000)
committertjhunt <tjhunt>
Wed, 29 Jul 2009 11:18:55 +0000 (11:18 +0000)
This was all in order to do MDL-19889!

* The old tabbed interface is gone.
* The manage feeds UI has been completely rewritten to be a few
separate sane scripts like managefeeds.php, editfeed.php and viewfeed.php
* This is used from both Admin -> plugins -> blocks ... and as a link from the block edit_form.php
* new edit_form.php for the block replacing config_istance.php.
* A lot of stuff to do with UI specific to this block has been removed from rsslib.php

14 files changed:
blocks/rss_client/block_rss_client.php
blocks/rss_client/block_rss_client_action.php [deleted file]
blocks/rss_client/block_rss_client_error.php [deleted file]
blocks/rss_client/config_instance.html [deleted file]
blocks/rss_client/config_instance_tabs.php [deleted file]
blocks/rss_client/db/access.php
blocks/rss_client/edit_form.php [new file with mode: 0644]
blocks/rss_client/editfeed.php [new file with mode: 0644]
blocks/rss_client/managefeeds.php [new file with mode: 0644]
blocks/rss_client/settings.php
blocks/rss_client/viewfeed.php [new file with mode: 0644]
lang/en_utf8/block_rss_client.php
lang/en_utf8/error.php
lib/rsslib.php

index 3dfc24b5e3653ab27fd2ed5f1197f3053e4d914b..36c454b53d74fbdf119ffaf166b679dc0d806185 100644 (file)
@@ -19,7 +19,7 @@
 
     function init() {
         $this->title = get_string('feedstitle', 'block_rss_client');
-        $this->version = 2007101511;
+        $this->version = 2009072900;
         $this->cron = 300; /// Set min time between cron executions to 300 secs (5 mins)
     }
 
             $shownumentries = 5; //default to 5 entries is not specified in admin section or instance
         }
 
-        if (!empty($this->config)) {
-            if (!empty($this->config->rssid)) {
-                if (is_array($this->config->rssid)) {
-                    $rssidarray = $this->config->rssid;
-                } else {     // Make an array of the single value
-                    $rssidarray = array($this->config->rssid);
-                }
-            }
-            if (!empty($this->config->display_description)) {
-                $display_description = intval($this->config->display_description);
-            }
-            if (!empty($this->config->shownumentries)) {
-                $shownumentries = intval($this->config->shownumentries);
-            }
+        if (empty($this->config)) {
+            $this->content->text = get_string('feedsconfigurenewinstance2', 'block_rss_client');
+            return $this->content;
         }
 
-        if (has_any_capability(array('block/rss_client:createsharedfeeds', 'block/rss_client:createprivatefeeds'), $this->context)) {
-
-            $page = $this->page;
-            //if ($page->user_allowed_editing()) { // for SUBMITTERS_ALL_ACCOUNT_HOLDERS we're going to run into trouble later if we show it and then they don't have write access to the page.
-            if (isset($this->config)) {
-                // This instance is configured - show Add/Edit feeds link.
-                $script = $page->url->out(
-                                    array('instanceid' => $this->instance->id,
-                                          'sesskey' => sesskey(),
-                                          'blockaction' => 'config',
-                                          'currentaction' => 'managefeeds',
-                                          'id' => $this->courseid,
-                                          'section' => 'rss'
-                                          ));
-                $output .= '<div class="info"><a title="'. get_string('feedsaddedit', 'block_rss_client') .'" href="'. $script .'">'. get_string('feedsaddedit', 'block_rss_client') .'</a></div>';
-            } else {
-                // This instance has not been configured yet - show configure link?
-                if (has_capability('block/rss_client:manageanyfeeds', $this->context)) {
-                    $script = $page->url->out(
-                                    array('instanceid' => $this->instance->id,
-                                          'sesskey' => sesskey(),
-                                          'blockaction' => 'config',
-                                          'currentaction' => 'configblock',
-                                          'id' => $this->page->course->id,
-                                          'section' => 'rss'
-                                          ));
-                    $output .= '<div class="info"><a title="'. get_string('feedsconfigurenewinstance', 'block_rss_client') .'" href="'. $script.'">'. get_string('feedsconfigurenewinstance', 'block_rss_client') .'</a></div>';
-                }
+        if (!empty($this->config->rssid)) {
+            if (is_array($this->config->rssid)) {
+                $rssidarray = $this->config->rssid;
+            } else {     // Make an array of the single value
+                $rssidarray = array($this->config->rssid);
             }
-            //}
+        }
+        if (!empty($this->config->display_description)) {
+            $display_description = intval($this->config->display_description);
+        }
+        if (!empty($this->config->shownumentries)) {
+            $shownumentries = intval($this->config->shownumentries);
         }
 
         // Daryl Hawes note: if count of rssidarray is greater than 1 
         $now = time();
         require_once($CFG->libdir .'/rsslib.php');
         require_once(MAGPIE_DIR .'rss_fetch.inc');
-        if (!defined('MAGPIE_OUTPUT_ENCODING')) {
-            define('MAGPIE_OUTPUT_ENCODING', 'utf-8');  // see bug 3107
-        }
 
         $rss_record = $DB->get_record('block_rss_client', array('id'=>$rssid));
         if (isset($rss_record) && isset($rss_record->id)) {
             ob_end_clean();
 
             if ($rss === false) {
-                if (debugging() && !empty($rsserror)) {
-                    // There was a failure in loading the rss feed, print link to full error text
-                    return '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_error.php?error='. urlencode($rsserror) .'">Error loading a feed.</a><br />'; //Daryl Hawes note: localize this line
-                }
+                debugging($rsserror);
             }
 
             // first we must verify that the rss feed is loaded
         require_once($CFG->libdir .'/rsslib.php');
         require_once(MAGPIE_DIR .'rss_fetch.inc');
 
-        if (!defined('MAGPIE_OUTPUT_ENCODING')) {
-            define('MAGPIE_OUTPUT_ENCODING', 'utf-8');  // see bug 3107
-        }
-
     /// Fetch all site feeds.
         $rs = $DB->get_recordset('block_rss_client');
         $counter = 0;
diff --git a/blocks/rss_client/block_rss_client_action.php b/blocks/rss_client/block_rss_client_action.php
deleted file mode 100644 (file)
index 2f05664..0000000
+++ /dev/null
@@ -1,289 +0,0 @@
-<?php //$Id$
-
-/*******************************************************************
-* This file contains no classes. It will display a list of existing feeds
-* defined for the site and allow add/edit/delete of site feeds.
-*
-* @author Daryl Hawes
-* @version  $Id$
-* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
-* @package base
-******************************************************************/
-
-require_once('../../config.php');
-require_once($CFG->libdir .'/rsslib.php');
-require_once(MAGPIE_DIR .'rss_fetch.inc');
-
-require_login();
-
-
-if (isset($_SERVER['HTTP_REFERER'])) {
-    $referrer = $_SERVER['HTTP_REFERER'];
-} else {
-    $referrer = $CFG->wwwroot.'/';
-}
-
-
-// Ensure that the logged in user is not using the guest account
-if (isguest()) {
-    print_error('noguestpost', 'forum', $referrer);
-}
-
-
-$url = optional_param('url','',PARAM_URL);
-
-if (!empty($url)) {
-    // attempting to replace feed and rss url types with http
-    // it appears that the rss feed validator will validate these url types but magpie will not load them    $url = str_replace ("feed://", "http://", "$url");
-    // Shifting this forward since PARAM_URL rejects these feed types as invalid entries!
-    $url = str_replace ("feed://", "http://", "$url");
-    $url = str_replace ("FEED://", "http://", "$url");
-    $url = str_replace ("rss://", "http://", "$url");
-    $url = str_replace ("RSS://", "http://", "$url");
-}
-
-$act            = optional_param('act', NULL, PARAM_ALPHA);
-$rssid          = optional_param('rssid', NULL, PARAM_INT);
-$id             = optional_param('id', SITEID, PARAM_INT);
-//$url            = clean_param($url, PARAM_URL);
-$preferredtitle = optional_param('preferredtitle', '', PARAM_TEXT);
-$shared         = optional_param('shared', 0, PARAM_INT);
-
-
-if (!defined('MAGPIE_OUTPUT_ENCODING')) {
-    define('MAGPIE_OUTPUT_ENCODING', 'utf-8');  // see bug 3107
-}
-
-
-if (!empty($id)) {
-    // we get the complete $course object here because print_header assumes this is
-    // a complete object (needed for proper course theme settings)
-    if ($course = $DB->get_record('course', array('id'=>$id))) {
-        $context = get_context_instance(CONTEXT_COURSE, $id);
-    }
-} else {
-    $context = get_context_instance(CONTEXT_SYSTEM);
-}
-
-
-$straddedit = get_string('feedsaddedit', 'block_rss_client');
-$link = $CFG->wwwroot.'/course/view.php?id='.$id;
-if (empty($course)) {
-    $link = '';
-}
-$navlinks = array();
-$navlinks = array(array('name' => get_string('administration'), 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc'));
-$navlinks[] = array('name' => get_string('managemodules'), 'link' => null, 'type' => 'misc');
-$navlinks[] = array('name' => get_string('blocks'), 'link' => null, 'type' => 'misc');
-$navlinks[] = array('name' => get_string('feedstitle', 'block_rss_client'), 'link' => "$CFG->wwwroot/$CFG->admin/settings.php?section=blocksettingrss_client", 'type' => 'misc');
-$navlinks[] = array('name' => get_string('addnew', 'block_rss_client'), 'link' => null,  'type' => 'misc');
-$navigation = build_navigation($navlinks);
-print_header($straddedit, $straddedit, $navigation);
-
-
-if ( !isset($act) ) {
-    rss_display_feeds($id, $USER->id, '', $context);
-    rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context);
-    print_footer();
-    die();
-}
-
-if ( isset($rssid) ) {
-    $rss_record = $DB->get_record('block_rss_client', array('id'=>$rssid));
-}
-
-
-if (isset($rss_record)) {
-    $managefeeds = ($rss_record->userid == $USER->id && has_capability('block/rss_client:manageownfeeds', $context))
-                || ($rss_record->userid != $USER->id && has_capability('block/rss_client:manageanyfeeds', $context));
-}
-
-
-if ($act == 'updfeed') {
-
-    if (!$managefeeds) {
-        print_error('cannotmakemodification', 'rss_client', $referrer);
-    }
-
-
-    if (empty($url)) {
-        print_error('urlnotdefinerss');
-    }
-
-    // By capturing the output from fetch_rss this way
-    // error messages do not display and clutter up the moodle interface
-    // however, we do lose out on seeing helpful messages like "cache hit", etc.
-    $message = '';
-    ob_start();
-    $rss = fetch_rss($url);
-    if (debugging()) {
-        $message .= ob_get_contents();
-    }
-    ob_end_clean();
-
-    $canaddsharedfeeds = has_capability('block/rss_client:createsharedfeeds', $context);
-
-    $dataobject->id = $rssid;
-    if ($rss === false) {
-        $dataobject->description = '';
-        $dataobject->title = '';
-        $dataobject->preferredtitle = '';
-        $dataobject->shared = 0;
-    } else {
-        $dataobject->description = $rss->channel['description'];
-        $dataobject->title = $rss->channel['title'];
-        $dataobject->preferredtitle = $preferredtitle;
-        if ($shared == 1 && $canaddsharedfeeds) {
-            $dataobject->shared = 1;
-        } else {
-            $dataobject->shared = 0;
-        }
-    }
-    $dataobject->url = $url;
-
-    $DB->update_record('block_rss_client', $dataobject);
-
-    $message .= '<br />'. get_string('feedupdated', 'block_rss_client');
-    redirect($referrer, $message);
-
-} else if ($act == 'addfeed' ) {
-
-    $canaddprivfeeds = has_capability('block/rss_client:createprivatefeeds', $context);
-    $canaddsharedfeeds = has_capability('block/rss_client:createsharedfeeds', $context);
-
-    if (!$canaddprivfeeds && !$canaddsharedfeeds) {
-        print_error('cannotaddrss', 'error');
-    }
-
-    if (empty($url)) {
-        print_error('urlnotdefinerss', 'error');
-
-    }
-    $dataobject->userid = $USER->id;
-    $dataobject->description = '';
-    $dataobject->title = '';
-    $dataobject->url = $url;
-    $dataobject->preferredtitle = $preferredtitle;
-
-    if ($shared == 1 && $canaddsharedfeeds) {
-        $dataobject->shared = 1;
-    } else {
-        $dataobject->shared = 0;
-    }
-
-    $rssid = $DB->insert_record('block_rss_client', $dataobject);
-
-    // By capturing the output from fetch_rss this way
-    // error messages do not display and clutter up the moodle interface
-    // however, we do lose out on seeing helpful messages like "cache hit", etc.
-    $message = '';
-    ob_start();
-    $rss = fetch_rss($url);
-    if (debugging()) {
-        $message .= ob_get_contents();
-    }
-    ob_end_clean();
-
-    if ($rss === false) {
-        $message .= '<br /><br />There was an error loading this rss feed. You may want to verify the url you have specified before using it.'; //Daryl Hawes note: localize this line
-    } else {
-
-        $dataobject->id = $rssid;
-        if (!empty($rss->channel['description'])) {
-            $dataobject->description = $rss->channel['description'];
-        }
-        if (!empty($rss->channel['title'])) {
-            $dataobject->title = $rss->channel['title'];
-        }
-        $DB->update_record('block_rss_client', $dataobject);
-        $message .= '<br />'. get_string('feedadded', 'block_rss_client');
-    }
-    redirect($referrer, $message);
-/*
-        rss_display_feeds($id, $USER->id, '', $context);
-        rss_print_form($act, $dataobject->url, $dataobject->id, $dataobject->preferredtitle, $shared, $id, $context);
-*/
-} else if ( isset($rss_record) && $act == 'rssedit' ) {
-
-    $preferredtitle = $rss_record->preferredtitle;
-    if (empty($preferredtitle)) {
-        $preferredtitle = $rss_record->title;
-    }
-    $url = $rss_record->url;
-    $shared = $rss_record->shared;
-    rss_display_feeds($id, $USER->id, $rssid, $context);
-    rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context);
-
-} else if ($act == 'delfeed') {
-
-    if (!$managefeeds) {
-        print_error('cannotmakemodification', 'rss_client', $referrer);
-    }
-
-    $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml';
-    if (file_exists($file)) {
-        unlink($file);
-    }
-
-    // echo "DEBUG: act = delfeed"; //debug
-    $DB->delete_records('block_rss_client', array('id'=>$rssid));
-
-    redirect($referrer, get_string('feeddeleted', 'block_rss_client') );
-
-} else if ( isset($rss_record) && $act == 'view' ) {
-    //              echo $sql; //debug
-    //              print_object($res); //debug
-    if (!$rss_record->id) {
-        print '<strong>'. get_string('couldnotfindfeed', 'block_rss_client') .': '. $rssid .'</strong>';
-    } else {
-        // By capturing the output from fetch_rss this way
-        // error messages do not display and clutter up the moodle interface
-        // however, we do lose out on seeing helpful messages like "cache hit", etc.
-        ob_start();
-        $rss = fetch_rss($rss_record->url);
-        ob_end_clean();
-
-        if (empty($rss_record->preferredtitle)) {
-            $feedtitle = $rss_record->preferredtitle;
-        } else {
-            $feedtitle =  $rss->channel['title'];
-        }
-        print '<table align="center" width="50%" cellspacing="1">'."\n";
-        print '<tr><td colspan="2"><strong>'. $feedtitle .'</strong></td></tr>'."\n";
-        for($y=0; $y < count($rss->items); $y++) {
-            if ($rss->items[$y]['link'] == '') {
-                $rss->items[$y]['link'] = $rss->items[$y]['guid'];
-            }
-
-            if ($rss->items[$y]['title'] == '') {
-                $rss->items[$y]['title'] = '&gt;&gt;';
-            }
-
-            print '<tr><td valign="middle">'."\n";
-            print '<a href="'. $rss->items[$y]['link'] .'" target="_blank"><strong>'. $rss->items[$y]['title'];
-            print '</strong></a>'."\n";
-            print '</td>'."\n";
-            if (file_exists($CFG->dirroot .'/blog/lib.php')) {
-                //Blog module is installed - provide "blog this" link
-                print '<td align="right">'."\n";
-
-                /// MDL-9291, blog this feature needs further discussion/implementation
-                /// temporarily disabling for now.
-
-                // print '<img src="'. $OUTPUT->old_icon_url('blog/blog') . '" alt="'. get_string('blogthis', 'blog').'" title="'. get_string('blogthis', 'blog') .'" border="0" align="middle" />'."\n";
-                //print '<a href="'. $CFG->wwwroot .'/blog/blogthis.php?userid='. $USER->id .'&act=use&item='. $y .'&rssid='. $rssid .'"><small><strong>'. get_string('blogthis', 'blog') .'</strong></small></a>'."\n";
-            } else {
-                print '<td>&nbsp;';
-            }
-            print '</td></tr>'."\n";
-            print '<tr><td colspan=2><small>';
-            print $rss->items[$y]['description'] .'</small></td></tr>'."\n";
-        }
-        print '</table>'."\n";
-    }
-} else {
-    rss_display_feeds($id, $USER->id, '', $context);
-    rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context);
-}
-print_footer();
-?>
diff --git a/blocks/rss_client/block_rss_client_error.php b/blocks/rss_client/block_rss_client_error.php
deleted file mode 100644 (file)
index 14ab2aa..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php //$Id$
-// Print an error page condition
-require_once('../../config.php');
-
-$error = required_param('error', PARAM_CLEAN);
-
-print_header(get_string('error'),
-              get_string('error'),
-              get_string('error') );
-
-print clean_text(urldecode($error));
-
-print_footer();
-?>
diff --git a/blocks/rss_client/config_instance.html b/blocks/rss_client/config_instance.html
deleted file mode 100644 (file)
index 9de7b3b..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-<?php // $Id$ //
-require_once($CFG->libdir .'/rsslib.php');
-
-$id = optional_param('id', SITEID, PARAM_INT);
-
-//create a page object for url_get_full()
-$page = $this->page;
-
-
-/// Print tabs at top
-$currentaction = optional_param('currentaction', '', PARAM_ALPHA);
-if (empty($currentaction) || $currentaction == 'configblock') {
-    $currentaction = 'configblock';
-} else {
-    $currentaction = 'managefeeds';
-}
-
-include('config_instance_tabs.php');
-
-if ($currentaction == 'configblock') {
-print_box_start();
-?>
-<table cellpadding="9" cellspacing="0" class="blockconfigtable">
-<tr valign="top">
-    <td class="label">
-        <?php print_string('displaydescriptionlabel', 'block_rss_client') ?>
-    </td>
-    <td class="value">
-            <?php
-                if(! isset($CFG->block_rss_client_display_description) ) {
-                    $CFG->block_rss_client_display_description = '0';
-                }
-                $selected = $CFG->block_rss_client_display_description;
-                if (isset($this->config) && isset($this->config->display_description)) {
-                    $selected = $this->config->display_description;
-                }
-                $options[0] = get_string('no');
-                $options[1] = get_string('yes');
-                choose_from_menu ($options, 'display_description', $selected);
-            ?>
-    </td>
-</tr>
-
-<tr valign="top">
-    <td class="label">
-        <?php print_string('shownumentrieslabel', 'block_rss_client') ?>
-    </td>
-    <td class="value">
-        <input name="shownumentries" type="text" size="5" value="<?php
-            if(! isset($CFG->block_rss_client_num_entries) ) {
-                $CFG->block_rss_client_num_entries = '5';
-            }
-            $numentries = $CFG->block_rss_client_num_entries;
-            if (isset($this->config) && isset($this->config->shownumentries)) {
-                $numentries = intval($this->config->shownumentries);
-            }
-
-            p($numentries);
-        ?>" />
-    </td>
-</tr>
-
-<tr valign="top">
-    <td class="label">
-        <?php print_string('choosefeedlabel', 'block_rss_client') ?>
-    </td>
-    <td class="value">
-        <?php
-            $selectedarray = array();
-            if (isset($this->config) && isset($this->config->rssid)) {
-                if (is_array($this->config->rssid)) {
-                    // rssid is an array of rssids
-                    $selectedarray = $this->config->rssid;
-                } else {
-                    // rssid is a single rssid
-                    $selectedarray = array($this->config->rssid);
-                }
-            }
-            global $USER;
-
-            if ($rssfeeds = $DB->get_records_select('block_rss_client', 'userid = ? OR shared = 1', array($USER->id))) {
-                foreach($rssfeeds as $rssfeed) {
-                    if (!empty($rssfeed->preferredtitle)) {
-                        $feedtitle = $rssfeed->preferredtitle;
-                    } else {
-                        $feedtitle = $rssfeed->title;
-                    }
-                    $checked = '';
-                    if (in_array($rssfeed->id, $selectedarray)) {
-                        $checked = 'checked="checked"';
-                    }
-                    $checkbox =  '<input type="checkbox" name="rssid[]" id="rssid" value="'. $rssfeed->id .'" '. $checked .' />';
-                    print $checkbox . $feedtitle .'<br />'."\n";
-                }
-            } else {
-                print_string('nofeeds', 'block_rss_client');
-
-                if (has_capability('block/rss_client:createprivatefeeds', $this->context)
-                        || has_capability('block/rss_client:createsharedfeeds', $this->context)) {
-
-                    $addrsspage = $page->url->out(array('instanceid' => $this->instance->id,
-                                                            'sesskey' => sesskey(),
-                                                            'blockaction' => 'config',
-                                                            'currentaction' => 'managefeeds',
-                                                            'id' => $id));
-                    print '&nbsp;<a href="'.$addrsspage.'">'. get_string('editnewsfeeds', 'block_rss_client') .'</a><br />';
-                }
-            }
-        ?>
-    </td>
-</tr>
-
-<tr valign="top">
-    <td class="label"><?php print_string('uploadlabel'); ?></td>
-    <?php
-        $title = '';
-        if (!empty($this->config) && !empty($this->config->title)) {
-            $title = $this->config->title;
-        }
-    ?>
-    <td class="value"><input type="text" name="title" size="30" value="<?php echo $title; ?>" />
-    </td>
-</tr>
-
-<tr valign="top">
-    <td class="label"><?php print_string('clientshowchannellinklabel', 'block_rss_client'); ?></td>
-    <td class="value">
-        <?php 
-                if (isset($this->config) && isset($this->config->block_rss_client_show_channel_link)) {
-                        $selected = $this->config->block_rss_client_show_channel_link;
-                } else {
-                       $selected = '0';
-                }
-                $options = array ( '0'  => get_string('no'),
-                                   '1' => get_string('yes') );
-
-                choose_from_menu ($options, 'block_rss_client_show_channel_link', $selected);
-        ?>
-    </td>
-</tr>
-
-<tr valign="top">
-    <td class="label"><?php print_string('clientshowimagelabel', 'block_rss_client'); ?></td>
-    <td class="value">
-        <?php 
-                if (isset($this->config) && isset($this->config->block_rss_client_show_channel_image)) {
-                        $selected = $this->config->block_rss_client_show_channel_image;
-                } else {
-                       $selected = '0';
-                }
-                $options = array ( '0'  => get_string('no'),
-                                   '1' => get_string('yes') );
-
-                choose_from_menu ($options, 'block_rss_client_show_channel_image', $selected);
-        ?>
-    </td>
-</tr>
-
-<tr>
-    <td colspan="2" class="submit">
-        <input type="submit" value="<?php print_string('savechanges') ?>" />
-    </td>
-</tr>
-</table>
-<?php
-    print_box_end();
-    print "<!-- code came from " . __FILE__ . " at line " . __LINE__ . ". -->\n";
-} else {
-  global $act, $url, $rssid, $preferredtitle, $shared;
-  print '</div></form></div>';   // Closes off page form
-
-  print_box_start();
-  rss_display_feeds($id, $USER->id, '', $context);
-  rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $this->context);
-  print_box_end();
-}
-?>
diff --git a/blocks/rss_client/config_instance_tabs.php b/blocks/rss_client/config_instance_tabs.php
deleted file mode 100644 (file)
index a7ac1d4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php  // $Id$
-/// This file to be included so we can assume config.php has already been included.
-/// We also assume that $inactive, $activetab and $currentaction have been set
-
-global $USER;
-$tabs = $row = array();
-
-if (has_capability('moodle/site:manageblocks', $this->context)) {
-    $script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'configblock', 'id' => $id, 'section' => 'rss'));
-    $row[] = new tabobject('configblock', $script,
-                get_string('configblock', 'block_rss_client'));
-}
-
-$script = $page->url->out(array('instanceid' => $this->instance->id, 'sesskey' => sesskey(), 'blockaction' => 'config', 'currentaction' => 'managefeeds', 'id' => $id, 'section' => 'rss'));
-$row[] = new tabobject('managefeeds', $script,
-            get_string('managefeeds', 'block_rss_client'));
-
-$tabs[] = $row;
-
-/// Print out the tabs and continue!
-print "\n".'<div class="tabs">'."\n";
-print_tabs($tabs, $currentaction);
-print '</div>' . print_location_comment(__FILE__, __LINE__, true);
-?>
index 9f77fdf38f45bd87223cf7ba6bcb875d2c81c982..ab3905fa1362231d25c1b8328f236fdb218fb94f 100644 (file)
 
 $block_rss_client_capabilities = array(
 
-    'block/rss_client:createprivatefeeds' => array(
-
-        'captype' => 'write',
-        'contextlevel' => CONTEXT_BLOCK,
-        'legacy' => array(
-            'teacher' => CAP_ALLOW,
-            'editingteacher' => CAP_ALLOW,
-            'admin' => CAP_ALLOW
-        )
-    ),
-
-    'block/rss_client:createsharedfeeds' => array(
-
-        'riskbitmask' => RISK_SPAM,
-
-        'captype' => 'write',
-        'contextlevel' => CONTEXT_BLOCK,
-        'legacy' => array(
-            'editingteacher' => CAP_ALLOW,
-            'admin' => CAP_ALLOW
-        )
-    ),
-
     'block/rss_client:manageownfeeds' => array(
 
         'captype' => 'write',
diff --git a/blocks/rss_client/edit_form.php b/blocks/rss_client/edit_form.php
new file mode 100644 (file)
index 0000000..2a605eb
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/ 
+// 
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Form for editing RSS client block instances.
+ *
+ * @package   moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Form for editing RSS client block instances.
+ *
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class block_rss_client_edit_form extends block_edit_form {
+    protected function specific_definition($mform) {
+        global $CFG, $DB, $USER;
+
+        // Fields for editing HTML block title and contents.
+        $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
+
+        $mform->addElement('selectyesno', 'config_display_description', get_string('displaydescriptionlabel', 'block_rss_client'));
+        $mform->setDefault('config_display_description', 0);
+
+        $mform->addElement('text', 'config_shownumentries', get_string('shownumentrieslabel', 'block_rss_client'), array('size' => 5));
+        $mform->setType('config_text', PARAM_INTEGER);
+        if (!empty($CFG->block_rss_client_num_entries)) {
+            $mform->setDefault('config_text', $CFG->block_rss_client_num_entries);
+        } else {
+            $mform->setDefault('config_text', 5);
+        }
+
+        $rssfeeds = $DB->get_records_sql_menu('
+                SELECT id, CASE WHEN preferredtitle = ? THEN title ELSE preferredtitle END AS acutaltitle
+                FROM {block_rss_client}
+                WHERE userid = ? OR shared = 1
+                ORDER BY acutaltitle',
+                array($DB->sql_empty(), $USER->id));
+        if ($rssfeeds) {
+            $select = $mform->addElement('select', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'), $rssfeeds);
+            $select->setMultiple(true);
+
+        } else {
+            $mform->addElement('static', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'),
+                    get_string('nofeeds', 'block_rss_client'));
+        }
+
+        if (has_any_capability(array('block/rss_client:manageanyfeeds', 'block/rss_client:manageownfeeds'), $this->block->context)) {
+            $mform->addElement('static', 'nofeedmessage', '',
+                    '<a href="' . $CFG->wwwroot . '/blocks/rss_client/managefeeds.php?courseid=' . $this->page->course->id . '">' .
+                    get_string('feedsaddedit', 'block_rss_client') . '</a>');
+        }
+
+        $mform->addElement('selectyesno', 'config_title', get_string('uploadlabel'));
+        $mform->setType('config_title', PARAM_NOTAGS);
+
+        $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_link', get_string('clientshowchannellinklabel', 'block_rss_client'));
+        $mform->setDefault('config_block_rss_client_show_channel_link', 0);
+
+        $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_image', get_string('clientshowimagelabel', 'block_rss_client'));
+        $mform->setDefault('config_block_rss_client_show_channel_image', 0);
+    }
+}
\ No newline at end of file
diff --git a/blocks/rss_client/editfeed.php b/blocks/rss_client/editfeed.php
new file mode 100644 (file)
index 0000000..9341974
--- /dev/null
@@ -0,0 +1,197 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/ 
+// 
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to let a user edit the properties of a particular RSS feed.
+ *
+ * @package   moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+require_once(dirname(__FILE__) . '/../../config.php');
+require_once($CFG->libdir . '/formslib.php');
+require_once($CFG->libdir .'/rsslib.php');
+require_once(MAGPIE_DIR .'rss_fetch.inc');
+
+class feed_edit_form extends moodleform {
+    protected $isadding;
+    protected $caneditshared;
+    protected $title = '';
+    protected $description = '';
+
+    function __construct($actionurl, $isadding, $caneditshared) {
+        $this->isadding = $isadding;
+        $this->caneditshared = $caneditshared;
+        parent::moodleform($actionurl);
+    }
+
+    function definition() {
+        $mform =& $this->_form;
+
+        // Then show the fields about where this block appears.
+        $mform->addElement('header', 'header', get_string('feed', 'block_rss_client'));
+
+        $mform->addElement('text', 'url', get_string('feedurl', 'block_rss_client'), array('size' => 60));
+        $mform->setType('url', PARAM_URL);
+        $mform->addRule('url', null, 'required');
+
+        $validatejs = "window.open('http://feedvalidator.org/check.cgi?url='+" .
+                "getElementById('id_url').value, 'validate', " .
+                "'width=640,height=480,scrollbars=yes,status=yes,resizable=yes'); return true;";
+        $validatelink = '<a href="#" onclick="' . $validatejs . '">' . get_string('validatefeed', 'block_rss_client') . '</a>';
+        $mform->addElement('static', 'validatelink', '', $validatelink);
+
+        $mform->addElement('text', 'preferredtitle', get_string('customtitlelabel', 'block_rss_client'), array('size' => 60));
+        $mform->setType('preferredtitle', PARAM_NOTAGS);
+
+        if ($this->caneditshared) {
+            $mform->addElement('selectyesno', 'shared', get_string('sharedfeed', 'block_rss_client'));
+            $mform->setDefault('shared', 0);
+        }
+
+        $submitlabal = null; // Default
+        if ($this->isadding) {
+            $submitlabal = get_string('addnewfeed', 'block_rss_client');
+        }
+        $this->add_action_buttons(true, $submitlabal);
+    }
+
+    function validation($data, $files) {
+        $errors = parent::validation($data, $files);
+
+        ob_start();
+        $rss = fetch_rss($data['url']);
+        $rsserrors = ob_get_clean();
+
+        if (!$rss) {
+            $errors['url'] = get_string('errorloadingfeed', 'block_rss_client', $rsserrors);
+        } else {
+            $this->title = $rss->channel['title'];
+            $this->description = $rss->channel['description'];
+        }
+
+        return $errors;
+    }
+
+    function get_data() {
+        $data = parent::get_data();
+        if ($data) {
+            $data->title = $this->title;
+            $data->description = $this->description;
+        }
+        return $data;
+    }
+}
+
+$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
+$courseid = optional_param('courseid', 0, PARAM_INTEGER);
+$rssid = optional_param('rssid', 0, PARAM_INTEGER); // 0 mean create new.
+
+if ($courseid = SITEID) {
+    $courseid = 0;
+}
+if ($courseid) {
+    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+    $PAGE->set_course($course);
+    $context = $PAGE->context;
+} else {
+    $context = get_context_instance(CONTEXT_SYSTEM);
+    $PAGE->set_context($context);
+}
+
+$managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
+if (!$managesharedfeeds) {
+    require_capability('block/rss_client:manageownfeeds', $context);
+}
+
+$urlparams = array('rssid' => $rssid);
+$manageparams = array();
+if ($courseid) {
+    $urlparams['courseid'] = $courseid;
+    $manageparams[] = 'courseid=$courseid';
+}
+if ($returnurl) {
+    $urlparams['returnurl'] = $returnurl;
+    $manageparams = 'returnurl=' . $returnurl;
+}
+if ($manageparams) {
+    $manageparams = '?' . implode('&', $manageparams);
+} else {
+    $manageparams = '';
+}
+$PAGE->set_url('blocks/rss_client/editfeed.php', $urlparams);
+$PAGE->set_generaltype('form');
+
+if ($rssid) {
+    $isadding = false;
+    $rssrecord = $DB->get_record('block_rss_client', array('id' => $rssid), '*', MUST_EXIST);
+} else {
+    $isadding = true;
+    $rssrecord = new stdClass;
+}
+
+$mform = new feed_edit_form($PAGE->url, $isadding, $managesharedfeeds);
+$mform->set_data($rssrecord);
+
+if ($mform->is_cancelled()) {
+    redirect($CFG->wwwroot . '/blocks/rss_client/managefeeds.php' . $manageparams);
+
+} else if ($data = $mform->get_data()) {
+    $data->userid = $USER->id;
+    if (!$managesharedfeeds) {
+        $data->shared = 0;
+    }
+
+    if ($isadding) {
+        $DB->insert_record('block_rss_client', $data);
+    } else {
+        $data->id = $rssid;
+        $DB->update_record('block_rss_client', $data);
+    }
+
+    redirect($CFG->wwwroot . '/blocks/rss_client/managefeeds.php' . $manageparams);
+
+} else {
+    if ($isadding) {
+        $strtitle = get_string('addnewfeed', 'block_rss_client');
+    } else {
+        $strtitle = get_string('editafeed', 'block_rss_client');
+    }
+
+    $PAGE->set_title($strtitle);
+    $PAGE->set_heading($strtitle);
+
+    $navlinks = array(
+        array('name' => get_string('administration'), 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc'),
+        array('name' => get_string('managemodules'), 'link' => null, 'type' => 'misc'),
+        array('name' => get_string('blocks'), 'link' => null, 'type' => 'misc'),
+        array('name' => get_string('feedstitle', 'block_rss_client'), 'link' => "$CFG->wwwroot/$CFG->admin/settings.php?section=blocksettingrss_client", 'type' => 'misc'),
+        array('name' => get_string('managefeeds', 'block_rss_client'), 'link' => $CFG->wwwroot . '/blocks/rss_client/managefeeds.php' . $manageparams, 'type' => 'misc'),
+        array('name' => $strtitle, 'link' => null,  'type' => 'misc'),
+    );
+    $navigation = build_navigation($navlinks);
+
+    echo $OUTPUT->header($navigation);
+    echo $OUTPUT->heading($strtitle, 2);
+
+    $mform->display();
+
+    echo $OUTPUT->footer();
+}
+
diff --git a/blocks/rss_client/managefeeds.php b/blocks/rss_client/managefeeds.php
new file mode 100644 (file)
index 0000000..9cad064
--- /dev/null
@@ -0,0 +1,162 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/ 
+// 
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to let a user manage their RSS feeds.
+ *
+ * @package   moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../config.php');
+require_once($CFG->libdir . '/tablelib.php');
+
+require_login();
+
+$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
+$courseid = optional_param('courseid', 0, PARAM_INTEGER);
+$deleterssid = optional_param('deleterssid', 0, PARAM_INTEGER);
+
+if ($courseid == SITEID) {
+    $courseid = 0;
+}
+if ($courseid) {
+    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+    $PAGE->set_course($course);
+    $context = $PAGE->context;
+} else {
+    $context = get_context_instance(CONTEXT_SYSTEM);
+    $PAGE->set_context($context);
+}
+
+$managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
+if (!$managesharedfeeds) {
+    require_capability('block/rss_client:manageownfeeds', $context);
+}
+
+$urlparams = array();
+$extraparams = '';
+if ($courseid) {
+    $urlparams['courseid'] = $courseid;
+    $extraparams = '&courseid=' . $courseid;
+}
+if ($returnurl) {
+    $urlparams['returnurl'] = $returnurl;
+    $extraparams = '&returnurl=' . $returnurl;
+}
+$PAGE->set_url('blocks/rss_client/managefeeds.php', $urlparams);
+
+// Process any actions
+if ($deleterssid && confirm_sesskey()) {
+    $DB->delete_records('block_rss_client', array('id'=>$rssid));
+
+    $file = $CFG->dataroot . '/cache/rsscache/' . $rssid .'.xml';
+    if (file_exists($file)) {
+        unlink($file);
+    }
+
+    redirect($PAGE->url, get_string('feeddeleted', 'block_rss_client'));
+}
+
+// Display the list of feeds.
+if ($managesharedfeeds) {
+    $select = '(userid = ' . $USER->id . ' OR shared = 1)';
+} else {
+    $select = 'userid = ' . $USER->id;
+}
+$feeds = $DB->get_records_select('block_rss_client', $select, null, $DB->sql_order_by_text('title'));
+
+$strmanage = get_string('managefeeds', 'block_rss_client');
+
+$PAGE->set_generaltype('form');
+$PAGE->set_title($strmanage);
+$PAGE->set_heading($strmanage);
+
+$navlinks = array(
+    array('name' => get_string('administration'), 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc'),
+    array('name' => get_string('managemodules'), 'link' => null, 'type' => 'misc'),
+    array('name' => get_string('blocks'), 'link' => null, 'type' => 'misc'),
+    array('name' => get_string('feedstitle', 'block_rss_client'), 'link' => "$CFG->wwwroot/$CFG->admin/settings.php?section=blocksettingrss_client", 'type' => 'misc'),
+    array('name' => get_string('managefeeds', 'block_rss_client'), 'link' => null, 'type' => 'misc'),
+);
+$navigation = build_navigation($navlinks);
+
+echo $OUTPUT->header($navigation);
+
+$table = new flexible_table('rss-display-feeds');
+
+$table->define_columns(array('feed', 'actions'));
+$table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
+
+$table->set_attribute('cellspacing', '0');
+$table->set_attribute('id', 'rssfeeds');
+$table->set_attribute('class', 'generaltable generalbox');
+$table->column_class('feed', 'feed');
+$table->column_class('actions', 'actions');
+
+$table->setup();
+
+foreach($feeds as $feed) {
+    if (!empty($feed->preferredtitle)) {
+        $feedtitle = $feed->preferredtitle;
+    } else {
+        $feedtitle =  $feed->title;
+    }
+
+    $viewlink = new html_link();
+    $viewlink->url = $CFG->wwwroot .'/blocks/rss_client/viewfeed.php?rssid=' . $feed->id . $extraparams;
+    $viewlink->text = $feedtitle;
+
+    $feedinfo = '<div class="title">' . $OUTPUT->link($viewlink) . '</div>' .
+        '<div class="url">' . $OUTPUT->link($feed->url, $feed->url) .'</div>' .
+        '<div class="description">' . $feed->description . '</div>';
+
+    $editaction = new action_icon();
+    $editaction->link->url = $CFG->wwwroot .'/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams;
+    $editaction->link->title = get_string('edit');
+    $editaction->image->src = $OUTPUT->old_icon_url('t/edit');
+    $editaction->image->alt = get_string('edit');
+
+    $deleteaction = new action_icon();
+    $deleteaction->link->url = $CFG->wwwroot .'/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id .
+            '&sesskey=' . sesskey() . $extraparams;
+    $deleteaction->link->title = get_string('delete');
+    $deleteaction->image->src = $OUTPUT->old_icon_url('t/delete');
+    $deleteaction->image->alt = get_string('delete');
+    $deleteaction->link->add_action('click', 'confirm_dialog', array(get_string('deletefeedconfirm', 'block_rss_client')));
+
+    $feedicons = $OUTPUT->action_icon($editaction) . ' ' . $OUTPUT->action_icon($deleteaction);
+
+    $table->add_data(array($feedinfo, $feedicons));
+}
+
+$table->print_html();
+
+$button = new html_form();
+$button->method = 'get';
+$button->url = $CFG->wwwroot . '/blocks/rss_client/editfeed.php?' . substr($extraparams, 1);
+$button->showbutton = true;
+$button->button->text = get_string('addnewfeed', 'block_rss_client');
+echo '<div class="actionbuttons">' . $OUTPUT->button($button) . '</div>';
+
+
+if ($returnurl) {
+    echo '<div class="backlink">' . $OUTPUT->link(get_string('back'), $returnurl) . '</div>';
+}
+
+echo $OUTPUT->footer();
index f18c8c232ff883f953172496f8fb271e7c4a29e3..313f0b611782b0ace6fb12936ca36736aeba199f 100644 (file)
@@ -14,8 +14,5 @@ $options = array (SUBMITTERS_ALL_ACCOUNT_HOLDERS => get_string('everybody'),
 $settings->add(new admin_setting_configselect('block_rss_client_submitters', get_string('submitters2', 'block_rss_client'),
                    get_string('submitters', 'block_rss_client'), SUBMITTERS_ADMIN_ONLY, $options));
 
-$link ='<a href="'.$CFG->wwwroot.'/blocks/rss_client/block_rss_client_action.php">'.get_string('feedsaddedit', 'block_rss_client').'</a>';
+$link ='<a href="'.$CFG->wwwroot.'/blocks/rss_client/managefeeds.php">'.get_string('feedsaddedit', 'block_rss_client').'</a>';
 $settings->add(new admin_setting_heading('block_rss_addheading', '', $link));
-
-
-?>
diff --git a/blocks/rss_client/viewfeed.php b/blocks/rss_client/viewfeed.php
new file mode 100644 (file)
index 0000000..a0085e6
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/ 
+// 
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Script to let a user edit the properties of a particular RSS feed.
+ *
+ * @package   moodlecore
+ * @copyright 2009 Tim Hunt
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../config.php');
+require_once($CFG->libdir .'/rsslib.php');
+require_once(MAGPIE_DIR .'rss_fetch.inc');
+
+require_login();
+if (isguest()) {
+    echo_error('guestsarenotallowed');
+}
+
+$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
+$courseid = optional_param('courseid', 0, PARAM_INTEGER);
+$rssid = required_param('rssid', PARAM_INTEGER);
+
+if ($courseid = SITEID) {
+    $courseid = 0;
+}
+if ($courseid) {
+    $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+    $PAGE->set_course($course);
+    $context = $PAGE->context;
+} else {
+    $context = get_context_instance(CONTEXT_SYSTEM);
+    $PAGE->set_context($context);
+}
+
+$urlparams = array('rssid' => $rssid);
+$manageparams = array();
+if ($courseid) {
+    $urlparams['courseid'] = $courseid;
+    $manageparams[] = 'courseid=$courseid';
+}
+if ($returnurl) {
+    $urlparams['returnurl'] = $returnurl;
+    $manageparams = 'returnurl=' . $returnurl;
+}
+if ($manageparams) {
+    $manageparams = '?' . implode('&', $manageparams);
+} else {
+    $manageparams = '';
+}
+$PAGE->set_url('blocks/rss_client/viewfeed.php', $urlparams);
+$PAGE->set_generaltype('popup');
+
+$rssrecord = $DB->get_record('block_rss_client', array('id' => $rssid), '*', MUST_EXIST);
+
+ob_start();
+$rss = fetch_rss($rssrecord->url);
+$rsserrors = ob_get_clean();
+
+if (!$rss) {
+    debugging($rsserrors);
+    print_error('errorfetchingrssfeed');
+}
+
+$strviewfeed = get_string('viewfeed', 'block_rss_client');
+
+$PAGE->set_title($strviewfeed);
+$PAGE->set_heading($strviewfeed);
+
+$navlinks = array(
+    array('name' => get_string('administration'), 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc'),
+    array('name' => get_string('managemodules'), 'link' => null, 'type' => 'misc'),
+    array('name' => get_string('blocks'), 'link' => null, 'type' => 'misc'),
+    array('name' => get_string('feedstitle', 'block_rss_client'), 'link' => "$CFG->wwwroot/$CFG->admin/settings.php?section=blocksettingrss_client", 'type' => 'misc'),
+    array('name' => get_string('managefeeds', 'block_rss_client'), 'link' => $CFG->wwwroot . '/blocks/rss_client/managefeeds.php' . $manageparams, 'type' => 'misc'),
+    array('name' => $strviewfeed, 'link' => null,  'type' => 'misc'),
+);
+$navigation = build_navigation($navlinks);
+
+echo $OUTPUT->header($navigation);
+
+
+if (!empty($rssrecord->preferredtitle)) {
+    $feedtitle = $rssrecord->preferredtitle;
+} else {
+    $feedtitle =  $rss->channel['title'];
+}
+echo '<table align="center" width="50%" cellspacing="1">'."\n";
+echo '<tr><td colspan="2"><strong>'. $feedtitle .'</strong></td></tr>'."\n";
+foreach ($rss->items as $item) {
+    if ($item['link'] == '') {
+        $item['link'] = $item['guid'];
+    }
+
+    if ($item['title'] == '') {
+        $item['title'] = '&gt;&gt;';
+    }
+
+    echo '<tr><td valign="middle">'."\n";
+    echo '<a href="'. $item['link'] .'" target="_blank"><strong>'. $item['title'];
+    echo '</strong></a>'."\n";
+    echo '</td>'."\n";
+    echo '</tr>'."\n";
+    echo '<tr><td colspan="2"><small>';
+    echo $item['description'] .'</small></td></tr>'."\n";
+}
+echo '</table>'."\n";
+
+echo $OUTPUT->footer();
index 280fd944cc4a785b4ff92bcbc23a92f13d857824..2836fc10aef732a6783c18c6c82bd62d1feeef8e 100644 (file)
@@ -5,6 +5,7 @@
 $string['addfeed'] = 'Add a news feed URL:';
 $string['addheadlineblock'] = 'Add RSS headline block';
 $string['addnew'] = 'Add New';
+$string['addnewfeed'] = 'Add a new feed';
 $string['blockname'] = 'RSS Client';
 $string['cannotmakemodification'] = 'You are not allowed to make modifications to this RSS feed at this time.';
 $string['choosefeedlabel'] = 'Choose the feeds which you would like to make available in this block:';
@@ -17,17 +18,21 @@ $string['couldnotfindfeed'] = 'Could not find feed with id';
 $string['customtitlelabel'] = 'Custom title (leave blank to use title supplied by feed):';
 $string['deletefeedconfirm'] = 'Are you sure you want to delete this feed?';
 $string['displaydescriptionlabel'] = 'Display each link\'s description?';
+$string['editafeed'] = 'Edit a feed';
 $string['editfeeds'] = 'Edit, subscribe or unsubsribe from RSS/Atom news feeds';
 $string['editnewsfeeds'] = 'Edit news feeds';
 $string['editrssblock'] = 'Edit RSS Headline Block';
+$string['errorloadingfeed'] = 'Error loading this RSS feed ($a)';
 $string['feed'] = 'Feed';
 $string['feedadded'] = 'News feed added';
 $string['feeddeleted'] = 'News feed deleted';
 $string['feeds'] = 'News Feeds';
 $string['feedsaddedit'] = 'Add/Edit Feeds';
 $string['feedsconfigurenewinstance'] = 'Click here to configure this block to display RSS feeds.';
+$string['feedsconfigurenewinstance2'] = 'Click the edit icon above to configure this block to display RSS feeds.';
 $string['feedstitle'] = 'Remote RSS Feeds';
 $string['feedupdated'] = 'News feed updated';
+$string['feedurl'] = 'Feed URL';
 $string['findmorefeeds'] = 'Find more rss feeds';
 $string['managefeeds'] = 'Manage all my feeds';
 $string['numentries'] = 'Entries per feed';
@@ -48,5 +53,6 @@ $string['timeout2'] = 'Timeout';
 $string['timeoutdesc'] = 'Time in minutes for an RSS feed to live in cache.';
 $string['updatefeed'] = 'Update a news feed URL:';
 $string['validatefeed'] = 'Validate feed';
+$string['viewfeed'] = 'View feed';
 
 ?>
index f025424d72cb132cb0ffdd6b42634206afb430b2..b2d842d6006e10257129e127ff168d5a483c4499 100644 (file)
@@ -193,6 +193,7 @@ $string['errorcopyingfiles'] = 'Error copying files';
 $string['errorcreatingdirectory'] = 'Error creating directory \"$a\"';
 $string['errorcreatingfile'] = 'Error creating file \"$a\"';
 $string['errorcreatingrole'] = 'Error creating role';
+$string['errorfetchingrssfeed'] = 'Error fetching RSS feed.';
 $string['erroronline'] = 'Error on line $a';
 $string['errorreadingfile'] = 'Error reading file \"$a\"';
 $string['errorsavingrequest'] = 'An error occurred when trying to save your request.';
index 852c87101dcab1eb4851029f639d760b68c4f4cf..8263ff5340e8e6dadca1c14ec8d4a8ce7644413b 100644 (file)
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+if (!defined('MAGPIE_OUTPUT_ENCODING')) {
+    define('MAGPIE_OUTPUT_ENCODING', 'utf-8');  // see bug 3107
+}
+
 /**
  * This function returns the icon (from theme) with the link to rss/file.php
  *
@@ -404,188 +408,6 @@ define('SUBMITTERS_ALL_ACCOUNT_HOLDERS', 0);
 define('SUBMITTERS_ADMIN_ONLY', 1);
 define('SUBMITTERS_ADMIN_AND_TEACHER', 2);
 
-/**
- * @param int $courseid The id of the course the user is currently viewing
- * @param int $userid We need this to know which feeds the user is allowed to manage
- * @param int $rssid If present the rss entry matching this id alone will be displayed
- *            as long as the user is allowed to manage this feed
- * @param object $context we need the context object to check what the user is allowed to do.
- */
-function rss_display_feeds($courseid, $userid, $rssid='', $context) {
-    global $USER, $CFG, $DB, $OUTPUT;
-    global $blogid; //hackish, but if there is a blogid it would be good to preserve it
-
-    require_once($CFG->libdir.'/tablelib.php');
-
-    $select = '';
-    $managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
-    $manageownfeeds = has_capability('block/rss_client:manageownfeeds', $context);
-
-    if ($rssid != '') {
-        $select = 'id = '.$rssid.' AND ';
-    }
-    if ($managesharedfeeds) {
-        $select .= '(userid = '.$userid.' OR shared = 1)';
-    } else if ($manageownfeeds) {
-        $select .= 'userid = '.$userid;
-    }
-
-    $table = new flexible_table('rss-display-feeds');
-
-    $table->define_columns(array('feed', 'actions'));
-    $table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
-
-    $table->set_attribute('cellspacing', '0');
-    $table->set_attribute('id', 'rssfeeds');
-    $table->set_attribute('class', 'generaltable generalbox');
-    $table->column_class('feed', 'feed');
-    $table->column_class('actions', 'actions');
-
-    $table->setup();
-
-    $feeds = $DB->get_records_select('block_rss_client', $select, null, $DB->sql_order_by_text('title'));
-
-    if(!empty($feeds)) {
-        foreach($feeds as $feed) {
-
-            if (!empty($feed->preferredtitle)) {
-                $feedtitle = $feed->preferredtitle;
-            } else {
-                $feedtitle =  $feed->title;
-            }
-
-            if ( ($feed->userid == $USER->id && $manageownfeeds)
-                    || ($feed->shared && $managesharedfeeds) ) {
-
-                $feedicons = '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $courseid .'&amp;act=rssedit&amp;rssid='. $feed->id .'&amp;shared='.$feed->shared.'&amp;blogid='. $blogid .'">'.
-                             '<img src="'. $OUTPUT->old_icon_url('t/edit') . '" alt="'. get_string('edit').'" title="'. get_string('edit') .'" /></a>&nbsp;'.
-
-                             '<a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $courseid .'&amp;act=delfeed&amp;rssid='. $feed->id.'&amp;shared='.$feed->shared.'blogid='. $blogid .'"
-                onclick="return confirm(\''. get_string('deletefeedconfirm', 'block_rss_client') .'\');">'.
-                             '<img src="'. $OUTPUT->old_icon_url('t/delete') . '" alt="'. get_string('delete').'" title="'. get_string('delete') .'" /></a>';
-            }
-            else {
-                $feedicons = '';
-            }
-
-            $feedinfo = '
-    <div class="title">
-        <a href="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php?id='. $courseid .'&amp;act=view&amp;rssid='.$feed->id .'&amp;blogid='. $blogid .'">
-        '. $feedtitle .'</a>
-    </div>
-    <div class="url">
-        <a href="'. $feed->url .'">'. $feed->url .'</a>
-    </div>
-    <div class="description">'.$feed->description.'</div>';
-
-            $table->add_data(array($feedinfo, $feedicons));
-        }
-    }
-
-    $table->print_html();
-}
-
-
-/**
- * Wrapper function for rss_get_form
- */
-function rss_print_form($act='none', $url='', $rssid='', $preferredtitle='', $shared=0, $courseid='', $context) {
-    print rss_get_form($act, $url, $rssid, $preferredtitle, $shared, $courseid, $context);
-}
-
-
-/**
- * Prints or returns a form for managing rss feed entries.
- *
- * @global object
- * @global object
- * @global int
- * @global string
- * @param string $act The current action. If "rssedit" then and "update" button is used, otherwise "add" is used.
- * @param string $url The url of the feed that is being updated or NULL
- * @param int $rssid The dataabse id of the feed that is being updated or NULL
- * @param string $preferredtitle The preferred title to display for this feed
- * @param int $shared Whether this feed is to be shared or not
- * @param int $courseid The id of the course that is currently being viewed if applicable
- * @param object $context The context that we will use to check for permissions
- * @return string Either the form is printed directly and nothing is returned or the form is returned as a string
- */
-function rss_get_form($act='none', $url='', $rssid='', $preferredtitle='', $shared=0, $courseid='', $context) {
-    global $USER, $CFG, $blockid, $blockaction;
-    global $blogid; //hackish, but if there is a blogid it would be good to preserve it
-
-    $stredit = get_string('edit');
-    $stradd = get_string('add');
-    $strupdatefeed = get_string('updatefeed', 'block_rss_client');
-    $straddfeed = get_string('addfeed', 'block_rss_client');
-
-    $returnstring = '';
-
-    $returnstring .= '<form action="'. $CFG->wwwroot .'/blocks/rss_client/block_rss_client_action.php" method="post" id="block_rss">'."\n";
-    print_location_comment(__FILE__,__LINE__);
-    $returnstring .= '<div id="rss_table">'."\n";
-    if ($act == 'rssedit') {
-        $returnstring .= $strupdatefeed;
-    } else {
-        $returnstring .= $straddfeed;
-    }
-
-    $returnstring .= "\n".'<br /><input type="text" size="60" maxlength="256" name="url" value="';
-    if ($act == 'rssedit') {
-        $returnstring .= $url;
-    }
-
-    $returnstring .= '" />'."\n";
-    $returnstring .= '<br />'. get_string('customtitlelabel', 'block_rss_client');
-    $returnstring .= '<br /><input type="text" size="60" maxlength="128" name="preferredtitle" value="';
-
-    if ($act == 'rssedit') {
-        $returnstring .= $preferredtitle;
-    }
-
-    $returnstring .= '" />'."\n";
-
-    if (has_capability('block/rss_client:createsharedfeeds', $context)) {
-        $returnstring .= '<br /><input type="checkbox" name="shared" value="1" ';
-        if ($shared) {
-            $returnstring .= 'checked="checked" ';
-        }
-        $returnstring .= '/> ';
-        $returnstring .= get_string('sharedfeed', 'block_rss_client');
-        $returnstring .= '<br />'."\n";
-    }
-
-    $returnstring .= '<input type="hidden" name="act" value="';
-
-    if ($act == 'rssedit') {
-        $returnstring .= 'updfeed';
-    } else {
-        $returnstring .= 'addfeed';
-    }
-
-    $returnstring .= '" />'."\n";
-    if ($act == 'rssedit') {
-        $returnstring .= '<input type="hidden" name="rssid" value="'. $rssid .'" />'. "\n";
-    }
-
-    $returnstring .= '<input type="hidden" name="id" value="'. $courseid .'" />'."\n";
-    $returnstring .= '<input type="hidden" name="blogid" value="'. $blogid .'" />'."\n";
-    $returnstring .= '<input type="hidden" name="user" value="'. $USER->id .'" />'."\n";
-    $returnstring .= '<br /><input type="submit" value="';
-    $validatestring = "<a href=\"#\" onclick=\"window.open('http://feedvalidator.org/check.cgi?url='+getElementById('block_rss').elements['url'].value,'validate','width=640,height=480,scrollbars=yes,status=yes,resizable=yes');return true;\">". get_string('validatefeed', 'block_rss_client')."</a>";
-
-    if ($act == 'rssedit') {
-        $returnstring .= $stredit;
-    } else {
-        $returnstring .= $stradd;
-    }
-
-    $returnstring .= '" />&nbsp;'. $validatestring ."\n";
-    // $returnstring .= '</div></form>'."\n"; // Avoiding nested forms... Ugly temporary hack #8922
-    return $returnstring . print_location_comment(__FILE__, __LINE__, true);
-}
-
-
 /**
  * Adds RSS Media Enclosures for "podcasting" by examining links to media files,
  * and attachments which are media files. Please note that the RSS that is