Now supports new preferredtitle field for custom feed channel titles. Supports new...
authordhawes <dhawes>
Thu, 27 Jan 2005 22:47:13 +0000 (22:47 +0000)
committerdhawes <dhawes>
Thu, 27 Jan 2005 22:47:13 +0000 (22:47 +0000)
blocks/rss_client/block_rss_client.php
blocks/rss_client/block_rss_client_action.php
blocks/rss_client/config_global.html
blocks/rss_client/config_instance.html

index ff8483c0008d4b00a99ad2efdec83916e12c9138..b3ef45b2d4a785f9d360878e50ba15bc5a666a0a 100644 (file)
@@ -152,16 +152,20 @@ class block_rss_client extends block_base {
             }
             
             if ($showtitle) {
-                $returnstring .= '<div class="rssclienttitle">'. $rss_record->title .'</div>';
+                $returnstring .= '<div class="rssclienttitle">'. $rss_record->title .'</div><br /><br />';
             }
             if ($shownumentries > 0 && $shownumentries < count($rss->items) ) {
                 $rss->items = array_slice($rss->items, 0, $shownumentries);
             }
 
-            $rss->channel['title'] = rss_unhtmlentities($rss->channel['title']);
+            if (empty($rss_record->preferredtitle)) {
+                $feedtitle = stripslashes_safe($rss_record->preferredtitle);
+            } else {
+                $feedtitle =  stripslashes_safe(rss_unhtmlentities($rss->channel['title']));
+            }            
             foreach ($rss->items as $item) {
-                $item['title'] = rss_unhtmlentities($item['title']);
-                $item['description'] = rss_unhtmlentities($item['description']);
+                $item['title'] = stripslashes_safe(rss_unhtmlentities($item['title']));
+                $item['description'] = stripslashes_safe(rss_unhtmlentities($item['description']));
                 if ($item['title'] == '') {
                     $item['title'] = substr(strip_tags($item['description']), 0, 20) . '...';
                 }
@@ -179,8 +183,13 @@ class block_rss_client extends block_base {
                 }
             }
 
-            if (!empty($rss->channel['link']) && !empty($rss->channel['title']) ) {
-                $feedtitle = '<a href="'. $rss->channel['link'] .'">'. $rss->channel['title'] .'</a>';
+            if (!empty($rss->channel['link'])) {
+                if (!empty($this->config) && isset($this->config->block_rss_client_show_channel_link) && $this->config->block_rss_client_show_channel_link) {
+                    $returnstring .=  '<div class="rssclientchannellink"><br /><a href="'. $rss->channel['link'] .'">'. get_string('block_rss_client_channel_link', 'block_rss_client') .'</a></div>';
+                } 
+                if (!empty($feedtitle) ) {
+                    $feedtitle = '<a href="'. $rss->channel['link'] .'">'. $feedtitle .'</a>';
+                }
             }
         }
 
index c0a80b0f4c85c64c165fe06793fbab9a9b963138..f8d54e85ef2c4c19341e989e9d7d68b236371a2c 100644 (file)
@@ -20,6 +20,7 @@
     optional_variable($rssid, 'none');
     optional_variable($courseid, 'none');
     optional_variable($url);
+    optional_variable($preferredtitle);
     optional_variable($item);
     
     $straddedit = get_string('block_rss_feeds_add_edit', 'block_rss_client');
@@ -53,7 +54,7 @@
 
     if ($act == 'none') {
         rss_display_feeds();
-        rss_get_form($act, $url, $rssid);
+        rss_get_form($act, $url, $rssid, $preferredtitle);
 
     } else if ($act == 'updfeed') {
         require_variable($url);
         if ($rss === false) {
             $dataobject->description = '';
             $dataobject->title = '';
+            $dataobject->preferredtitle = '';
         } else {
             $dataobject->description = addslashes(rss_unhtmlentities($rss->channel['description']));
             $dataobject->title = addslashes(rss_unhtmlentities($rss->channel['title']));
+            $dataobject->preferredtitle = addslashes($preferredtitle);
         }
         $dataobject->url = addslashes($url);
 
@@ -82,8 +85,8 @@
 
         rss_display_feeds($rssid);
         print '<strong>'. get_string('block_rss_feed_updated', 'block_rss_client') .'</strong>';                
-        rss_get_form($act, $url, $rssid);
-            
+        rss_get_form($act, $dataobject->url, $rssid, $dataobject->preferredtitle);
+
     } else if ($act == 'addfeed' ) {
 
         require_variable($url);            
@@ -91,6 +94,7 @@
         $dataobject->description = '';
         $dataobject->title = '';
         $dataobject->url = addslashes($url);
+        $dataobject->preferredtitle = addslashes($preferredtitle);
 
         $rssid = insert_record('block_rss_client', $dataobject);
         if (!$rssid){
             print '<strong>'. get_string('block_rss_feed_added', 'block_rss_client') .'</strong>';
         }
         rss_display_feeds();
-        rss_get_form($act, $url, $rssid);
-            
+        rss_get_form($act, $dataobject->url, $dataobject->id, $dataobject->preferredtitle);
+
     } else if ( $act == 'rss_edit') {
         
         $rss_record = get_record('block_rss_client', 'id', $rssid);
         $fname = stripslashes_safe($rss_record->title);
         $url = stripslashes_safe($rss_record->url);
-        rss_get_form($act, $url, $rssid);
-        
+        $preferredtitle = stripslashes_safe($rss_record->preferredtitle);
+        rss_get_form($act, $url, $rssid, $preferredtitle);
+
     } else if ($act == 'delfeed') {
         
         $file = $CFG->dataroot .'/cache/rsscache/'. $rssid .'.xml';
 
         rss_display_feeds();
         print '<strong>'. get_string('block_rss_feed_deleted', 'block_rss_client') .'</strong>';
-        rss_get_form($act, $url, $rssid);
+        rss_get_form($act, $url, $rssid, $preferredtitle);
 
     } else if ($act == 'view') {
         //              echo $sql; //debug
             $rsserror = ob_get_contents();
             ob_end_clean();
             
-            $rss->channel['title'] - rss_unhtmlentities($rss->channel['title']);
+            if (empty($rss_record->preferredtitle)) {
+                $feedtitle = stripslashes_safe($rss_record->preferredtitle);
+            } else {
+               $feedtitle =  stripslashes_safe(rss_unhtmlentities($rss->channel['title']));
+            }
             print '<table align="center" width="50%" cellspacing="1">'."\n";
-            print '<tr><td colspan="2"><strong>'. $rss->channel['title'] .'</strong></td></tr>'."\n";
+            print '<tr><td colspan="2"><strong>'. $feedtitle .'</strong></td></tr>'."\n";
             for($y=0; $y < count($rss->items); $y++) {
-                $rss->items[$y]['title'] = rss_unhtmlentities($rss->items[$y]['title']);
-                $rss->items[$y]['description'] = rss_unhtmlentities($rss->items[$y]['description']);
+                $rss->items[$y]['title'] = stripslashes_safe(rss_unhtmlentities($rss->items[$y]['title']));
+                $rss->items[$y]['description'] = stripslashes_safe(rss_unhtmlentities($rss->items[$y]['description']));
                 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=_new><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";
                     print '<img src="'. $CFG->pixpath .'/blog/blog.gif" alt="'. get_string('blog_blog_this', 'blog').'" title="'. get_string('blog_blog_this', 'blog') .'" border="0" align="middle" />'."\n";
                     print '<a href="'. $CFG->wwwroot .'/blog/blogthis.php?blogid='. $blogid .'&act=use&item='. $y .'&rssid='. $rssid .'"><small><strong>'. get_string('blog_blog_this', 'blog') .'</strong></small></a>'."\n";
         }
     } else {
         rss_display_feeds();
-        rss_get_form($act, $url, $rssid);
+        rss_get_form($act, $url, $rssid, $preferredtitle);
     }
 
     print_footer();
-?>
+
+/**
+ * @param string $act .
+ * @param string $url .
+ * @param int $rssid .
+ * @param bool $printnow True if the generated form should be printed out, false if the string should be returned from this function quietly
+ */
+function rss_get_form($act, $url, $rssid, $preferredtitle, $printnow=true) {
+    global $USER, $CFG, $_SERVER, $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('block_rss_update_feed', 'block_rss_client');
+    $straddfeed = get_string('block_rss_add_feed', 'block_rss_client');
+    
+    $returnstring = '<table align="center"><tbody><tr><td>'."\n";
+    
+    $returnstring .= '<form action="'. $_SERVER['PHP_SELF'] .'" method="POST" name="block_rss">'."\n";
+    if ($act == 'rss_edit') {
+        $returnstring .= $strupdatefeed; 
+    } else { 
+        $returnstring .= $straddfeed; 
+    }
+    $returnstring .= '<br /><input type="text" size="60" maxlength="256" name="url" value="';
+    if ($act == 'rss_edit') { 
+        $returnstring .= $url; 
+    }
+    $returnstring .= '" />'."\n";
+    $returnstring .= '<br />'. get_string('block_rss_custom_title_label', 'block_rss_client');
+    $returnstring .= '<br /><input type="text" size="60" maxlength="64" name="preferredtitle" value="';
+    if ($act == 'rss_edit') { 
+        $returnstring .= $preferredtitle; 
+    }
+    $returnstring .= '" />'."\n";
+
+    $returnstring .= '<input type="hidden" name="act" value="';
+    if ($act == 'rss_edit') {
+        $returnstring .= 'updfeed';
+    } else {
+        $returnstring .= 'addfeed';
+    }
+    $returnstring .= '" />'."\n";
+    if ($act == 'rss_edit') { 
+        $returnstring .= '<input type="hidden" name="rssid" value="'. $rssid .'" />'. "\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='+document.block_rss.elements['url'].value,'validate','width=640,height=480,scrollbars=yes,status=yes,resizable=yes');return true;\">". get_string('validate_feed', 'block_rss_client')."</a>";
+    if ($act == 'rss_edit') {
+        $returnstring .= $stredit;
+    } else {
+        $returnstring .= $stradd;
+    }
+    $returnstring .= '" />&nbsp;'. $validatestring .'</form>'."\n";
+    $returnstring .= '</td></tr></tbody></table>'."\n";
+
+    if ($printnow){
+        print $returnstring;
+    }
+    return $returnstring;
+}
+?>
\ No newline at end of file
index 262897acde33f5d12414d873f0781088d5c04689..f82294a58135e9db0d4ea3d99ade68db0e07dbf1 100644 (file)
@@ -51,6 +51,8 @@
         <?php print_string('block_rss_submitters', 'block_rss_client') ?>
     </td>
 </tr>
+
+
 <tr>
     <td colspan="3" align="center">
     <input type="submit" value="<?php print_string('savechanges') ?>"></td>
index 738e3e1d400aff0367a8b0086226784d2af55061..324672ade260ff966164e2442e8e7019f6adcf54 100644 (file)
@@ -1,7 +1,7 @@
 <table cellpadding="9" cellspacing="0">
 <tr valign="top">
     <td align="right">
-        <?php print_string('block_rss_display_description', 'block_rss_client') ?>
+        <?php print_string('block_rss_display_description_label', 'block_rss_client') ?>
     </td>
     <td>
             <?php 
@@ -20,7 +20,7 @@
 </tr>
 <tr valign="top">
     <td align="right">
-        <?php print_string('block_rss_shownumentries', 'block_rss_client') ?>
+        <?php print_string('block_rss_shownumentries_label', 'block_rss_client') ?>
     </td>
     <td>
         <input name="shownumentries" type="text" size="5" value="<?php
@@ -37,8 +37,8 @@
     </td>
 </tr>
 <tr valign="top">
-    <td>
-        <?php print_string('block_rss_choose_feed', 'block_rss_client') ?>
+    <td align="right">
+        <?php print_string('block_rss_choose_feed_label', 'block_rss_client') ?>
     </td>
     <td>
         <?php 
     <td><input type="text" name="title" size="30" value="<?php echo $title; ?>" />
     </td>
 </tr>
+<tr valign="top">
+    <td align="right"><p><?php print_string('block_rss_client_show_channel_link_label', 'block_rss_client'); ?></td>
+    <td>
+        <?php if (isset($CFG->block_rss_client_show_channel_link)) {
+                        $selected = $CFG->block_rss_client_show_channel_link;
+                } else {
+                       $selected = '0';
+                       $CFG->block_rss_client_show_channel_link = 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>
     <td colspan="2" align="center">
         <input type="submit" value="<?php print_string('savechanges') ?>">