Changeset 667

Show
Ignore:
Timestamp:
10/23/06 16:03:53 (2 years ago)
Author:
sven
Message:

feeds page shows viewed user's feeds instead of viewing user.
feeds system relies less on assumptions about $page_owner, more on explicit parameters.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/_rss/index.php

    r659 r667  
    33    require_once(dirname(dirname(__FILE__))."/includes.php"); 
    44     
     5//    global $page_owner; 
     6     
    57    run("weblogs:init"); 
    68    run("profile:init"); 
    7     run("rss:init"); 
     9     
     10    $username = trim(optional_param('profile_name','')); 
     11    $user_id = user_info_username("ident", $username); 
     12    if (!$user_id) { 
     13        $user_id = $page_owner; 
     14    } else { 
     15        $page_owner = $user_id; 
     16        $profile_id = $user_id; 
     17    } 
     18     
     19    run("rss:init"); // down here cos it sends $page_owner to rss function_actions.php 
    820     
    921    define('context','resources'); 
    10     global $page_owner; 
    11     templates_page_setup();     
    12     $title = run("profile:display:name") ." :: " . __gettext("Feeds"); 
     22    templates_page_setup(); 
    1323     
    14     run("rss:update:all",$page_owner); 
    15     $body = run("rss:view",$page_owner); 
     24    $title = run("profile:display:name", $user_id) ." :: " . __gettext("Feeds"); 
     25     
     26    run("rss:update:all", $user_id); 
     27    $body = run("rss:view", $user_id); 
    1628     
    1729    $body = templates_draw(array( 
  • devel/_rss/subscriptions.php

    r659 r667  
    33    require_once(dirname(dirname(__FILE__))."/includes.php"); 
    44     
    5     global $page_owner; 
    6  
     5//    global $page_owner; 
     6     
    77    run("weblogs:init"); 
    88    run("profile:init"); 
    9     run("rss:init"); 
     9     
     10    $username = trim(optional_param('profile_name','')); 
     11    $user_id = user_info_username("ident", $username); 
     12    if (!$user_id) { 
     13        $user_id = $page_owner; 
     14    } else { 
     15        $page_owner = $user_id; 
     16        $profile_id = $user_id; 
     17    } 
     18     
     19    run("rss:init"); // down here cos it sends $page_owner to rss function_actions.php 
    1020     
    1121    define('context','resources'); 
    12  
    13     templates_page_setup();     
    14  
    15     $title = run("profile:display:name") ." :: " . __gettext("Feeds"); 
     22    templates_page_setup(); 
    1623     
    17     $body = run("rss:subscriptions"); 
     24    $title = run("profile:display:name", $user_id) ." :: " . __gettext("Feeds"); 
     25     
     26    $body = run("rss:subscriptions", $user_id); 
    1827     
    1928    $body = templates_draw(array( 
  • devel/lib/userlib.php

    r659 r667  
    4747                $id_to_name_table[$user_id] = (array) get_record('users','ident',$user_id); 
    4848            } 
    49             return $id_to_name_table[$user_id][$fieldname]; 
     49            if (isset($id_to_name_table[$user_id][$fieldname])) { 
     50                return $id_to_name_table[$user_id][$fieldname]; 
     51            } 
    5052        } 
    5153         
     
    6971                $name_to_id_table[$username] = (array) get_record('users','username',$username); 
    7072            } 
    71             return $name_to_id_table[$username][$fieldname]; 
     73            if (isset($name_to_id_table[$username][$fieldname])){ 
     74                return $name_to_id_table[$username][$fieldname]; 
     75            } 
    7276        } 
    7377         
     
    105109            // Unset the flag first 
    106110            user_flag_unset($flag_name, $user_id); 
    107      
     111             
    108112            // Then add data 
    109113            $flag = new StdClass; 
  • devel/mod/newsclient/lib.php

    r659 r667  
    88 
    99    $page_owner = $profile_id; 
     10    $rss_username = user_info('username', $page_owner); 
    1011 
    1112    if (isloggedin() && user_info("user_type",$_SESSION['userid']) != "external") { 
     
    1718                                   'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/feeds/\" >" .__gettext("Your Resources").'</a></li>'); 
    1819        } 
    19  
    20         $rss_username = user_info('username', $page_owner); 
    2120    } 
    2221 
     
    2423     
    2524        if ($page_owner != -1) { 
     25            $PAGE->menu_sub[] = array( 'name' => 'newsfeed:subscription', 
     26                                       'html' => a_href( $CFG->wwwroot.$rss_username."/feeds/",  
     27                                                          __gettext("Feeds"))); 
    2628            if (run("permissions:check", "rss") && logged_on && $page_owner == $_SESSION['userid']) { 
    27                 $PAGE->menu_sub[] = array( 'name' => 'newsfeed:subscription', 
    28                                            'html' => a_href( $CFG->wwwroot.$_SESSION['username']."/feeds/",  
    29                                                               __gettext("Feeds"))); 
    3029                $PAGE->menu_sub[] = array( 'name' => 'newsfeed:subscription:publish:blog', 
    3130                                           'html' => a_href( $CFG->wwwroot."_rss/blog.php?page_owner=" . $_SESSION['userid'],  
     
    7675} 
    7776 
    78         function newsclient_init() { 
     77function newsclient_init() { 
     78     
     79    global $CFG; 
     80     
     81    $CFG->widgets->display['feed'] = "newsclient_widget_display"; 
     82    $CFG->widgets->edit['feed'] = "newsclient_widget_edit"; 
     83    $CFG->widgets->list[] = array( 
     84                                        'name' => __gettext("Feed widget"), 
     85                                        'description' => __gettext("Displays the latest entries from an external feed of your choice."), 
     86                                        'id' => "feed" 
     87                                ); 
     88     
     89
     90 
     91function newsclient_widget_display($widget) { 
     92     
     93    global $CFG; 
     94     
     95    $feed_id = adash_get_data("feed_id",$widget->ident); 
     96    $feed_posts = adash_get_data("feed_posts",$widget->ident); 
     97    if (empty($feed_posts)) { 
     98        $feed_posts = 1; 
     99    } 
     100     
     101    if (!empty($feed_id)) { 
     102         
     103        if ($posts = get_records_sql("SELECT fp.*,f.name,f.siteurl,f.tagline FROM ".$CFG->prefix."feed_posts fp 
     104                      JOIN ".$CFG->prefix."feeds f ON f.ident = fp.feed 
     105                      WHERE f.ident = $feed_id ORDER BY fp.added DESC, fp.ident ASC limit $feed_posts")) { 
     106                           
     107            foreach($posts as $post) { 
     108                $body .= "<h2><a href=\"" .$post->url . "\">". $post->title . "</a></h2>" . $post->body; 
     109            } 
     110        } else { 
    79111             
    80             global $CFG; 
    81              
    82             $CFG->widgets->display['feed'] = "newsclient_widget_display"; 
    83             $CFG->widgets->edit['feed'] = "newsclient_widget_edit"; 
    84             $CFG->widgets->list[] = array( 
    85                                                 'name' => __gettext("Feed widget"), 
    86                                                 'description' => __gettext("Displays the latest entries from an external feed of your choice."), 
    87                                                 'id' => "feed" 
    88                                         ); 
     112            $body .= "<p>" . __gettext("This feed is currently empty.") . "</p>"; 
    89113             
    90114        } 
     115         
     116       
     117    } else { 
     118         
     119        $body .= "<p>" . __gettext("This feed widget is undefined.") . "</p>"; 
     120         
     121    } 
     122     
     123    return $body; 
     124     
     125} 
    91126 
    92         function newsclient_widget_display($widget) { 
    93              
    94             global $CFG; 
    95              
    96             $feed_id = adash_get_data("feed_id",$widget->ident); 
    97             $feed_posts = adash_get_data("feed_posts",$widget->ident); 
    98             if (empty($feed_posts)) { 
    99                 $feed_posts = 1; 
     127function newsclient_widget_edit($widget) { 
     128     
     129    global $CFG, $page_owner; 
     130     
     131    $feed_id = adash_get_data("feed_id",$widget->ident); 
     132    $feed_posts = adash_get_data("feed_posts",$widget->ident); 
     133    if (empty($feed_posts)) { 
     134        $feed_posts = 1; 
     135    } 
     136 
     137    $body = "<h2>" . __gettext("Feeds dashboard widget") . "</h2>"; 
     138    $body .= "<p>" . __gettext("This widget displays the last couple of entries from an external feed you have subscribed to. To begin, select the feed from your subscriptions below:") . "</p>"; 
     139                 
     140    $feed_subscriptions = get_records_sql('SELECT fs.ident AS subid, fs.autopost, fs.autopost_tag, f.* FROM '.$CFG->prefix.'feed_subscriptions fs 
     141                                      JOIN '.$CFG->prefix.'feeds f ON f.ident = fs.feed_id 
     142                                      WHERE fs.user_id = ? ORDER BY f.name ASC',array($page_owner)); 
     143     
     144    if (is_array($feed_subscriptions) && !empty($feed_subscriptions)) { 
     145         
     146        $body .= "<p><select name=\"dashboard_data[feed_id]\">\n"; 
     147        foreach ($feed_subscriptions as $subscription) { 
     148            if ($subscription->ident == $feed_id) { 
     149                $selected = "selected=\"selected\""; 
     150            } else { 
     151                $selected = ""; 
    100152            } 
    101              
    102             if (!empty($feed_id)) { 
    103                  
    104                 if ($posts = get_records_sql("SELECT fp.*,f.name,f.siteurl,f.tagline FROM ".$CFG->prefix."feed_posts fp 
    105                               JOIN ".$CFG->prefix."feeds f ON f.ident = fp.feed 
    106                               WHERE f.ident = $feed_id ORDER BY fp.added DESC, fp.ident ASC limit $feed_posts")) { 
    107                                    
    108                     foreach($posts as $post) { 
    109                         $body .= "<h2><a href=\"" .$post->url . "\">". $post->title . "</a></h2>" . $post->body; 
    110                     } 
    111                 } else { 
    112                      
    113                     $body .= "<p>" . __gettext("This feed is currently empty.") . "</p>"; 
    114                      
    115                 } 
    116                  
    117                
    118             } else { 
    119                  
    120                 $body .= "<p>" . __gettext("This feed widget is undefined.") . "</p>"; 
    121                  
    122             } 
    123              
    124             return $body; 
    125              
     153            $body .= "<option value=\"" . $subscription->ident . "\" $selected>" . $subscription->name . "</option>\n"; 
    126154        } 
    127  
    128         function newsclient_widget_edit($widget) { 
    129              
    130             global $CFG, $page_owner; 
    131              
    132             $feed_id = adash_get_data("feed_id",$widget->ident); 
    133             $feed_posts = adash_get_data("feed_posts",$widget->ident); 
    134             if (empty($feed_posts)) { 
    135                 $feed_posts = 1; 
    136             } 
    137  
    138             $body = "<h2>" . __gettext("Feeds dashboard widget") . "</h2>"; 
    139             $body .= "<p>" . __gettext("This widget displays the last couple of entries from an external feed you have subscribed to. To begin, select the feed from your subscriptions below:") . "</p>"; 
    140                          
    141             $feed_subscriptions = get_records_sql('SELECT fs.ident AS subid, fs.autopost, fs.autopost_tag, f.* FROM '.$CFG->prefix.'feed_subscriptions fs 
    142                                               JOIN '.$CFG->prefix.'feeds f ON f.ident = fs.feed_id 
    143                                               WHERE fs.user_id = ? ORDER BY f.name ASC',array($page_owner)); 
    144              
    145             if (is_array($feed_subscriptions) && !empty($feed_subscriptions)) { 
    146                  
    147                 $body .= "<p><select name=\"dashboard_data[feed_id]\">\n"; 
    148                 foreach ($feed_subscriptions as $subscription) { 
    149                     if ($subscription->ident == $feed_id) { 
    150                         $selected = "selected=\"selected\""; 
    151                     } else { 
    152                         $selected = ""; 
    153                     } 
    154                     $body .= "<option value=\"" . $subscription->ident . "\" $selected>" . $subscription->name . "</option>\n"; 
    155                 } 
    156                 $body .= "</select></p>\n"; 
    157                  
    158                 $body .= "<p>" . __gettext("Then enter the number of feed entries you'd like to display:") . "</p>"; 
    159              
    160                 $body .= "<p><input type=\"text\" name=\"dashboard_data[feed_posts]\" value=\"" . $feed_posts . "\" /></p>"; 
    161                  
    162             } else { 
    163                  
    164                 $body .= "<p>" . sprintf(__gettext("You can't select a feed for this widget because you don't have any feed subscriptions. Click on <a href=\"%s\">Your</a> Resources to subscribe to a feed."),$CFG->wwwroot . $_SESSION['username'] . "/feeds/") . "</p>"; 
    165                  
    166             } 
    167              
    168             return $body; 
    169              
    170         } 
     155        $body .= "</select></p>\n"; 
     156         
     157        $body .= "<p>" . __gettext("Then enter the number of feed entries you'd like to display:") . "</p>"; 
     158     
     159        $body .= "<p><input type=\"text\" name=\"dashboard_data[feed_posts]\" value=\"" . $feed_posts . "\" /></p>"; 
     160         
     161    } else { 
     162         
     163        $body .= "<p>" . sprintf(__gettext("You can't select a feed for this widget because you don't have any feed subscriptions. Click on <a href=\"%s\">Your</a> Resources to subscribe to a feed."),$CFG->wwwroot . $_SESSION['username'] . "/feeds/") . "</p>"; 
     164         
     165    } 
     166     
     167    return $body; 
     168     
     169
    171170 
    172171 
  • devel/search/personaltags.php

    r659 r667  
    1111        define("context","profile"); 
    1212         
    13         templates_page_setup();         
    14         global $page_owner; 
     13//         global $page_owner; 
    1514         
    1615        $username = trim(optional_param('profile_name','')); 
     
    1817        if (!$user_id) { 
    1918            $user_id = $page_owner; 
     19        } else { 
     20            $page_owner = $user_id; 
     21            $profile_id = $user_id; 
    2022        } 
     23         
     24        templates_page_setup(); 
    2125         
    2226        $title = run("profile:display:name", $user_id) . " :: " . __gettext("Tags"); 
  • devel/units/magpie/function_actions.php

    r659 r667  
    2828         
    2929        // Unsubscribe from an existing feed 
    30         case "unsubscribe":                         
     30        case "unsubscribe": 
    3131            $feed = optional_param('feed'); 
    3232            if (!empty($feed) && run("rss:subscribed",$feed)) { 
  • devel/units/magpie/function_get_subscriptions.php

    r269 r667  
    44     
    55    global $rss_subscriptions; 
     6     
    67    $parameter = (int) $parameter; 
    78     
    8     if (!isset($rss_subscriptions)) { 
    9         $rss_subscriptions = array(); 
    10         if ($subscriptions_var = get_records('feed_subscriptions','user_id',$USER->ident)) { 
     9    if ($parameter && !isset($rss_subscriptions[$parameter])) { 
     10        $rss_subscriptions[$parameter] = array(); 
     11        if ($subscriptions_var = get_records('feed_subscriptions', 'user_id', $parameter)) { 
    1112            foreach($subscriptions_var as $subscription) { 
    12                 $rss_subscriptions[] = $subscription->feed_id; 
     13                $rss_subscriptions[$parameter][] = $subscription->feed_id; 
    1314            } 
    1415        } 
  • devel/units/magpie/function_is_subscribed.php

    r269 r667  
    11<?php 
    2  
     2    // parameter is a feed id 
     3    // checks if $page_owner is subscribed to it 
     4     
    35    $run_result = false; 
    4  
     6     
    57    if (logged_on && isset($parameter)) { 
    6  
     8         
    79        global $page_owner; 
    810        $parameter = (int) $parameter; 
    911         
    10         if ($page_owner == $_SESSION['userid']) { 
     12        global $rss_subscriptions; 
     13        run("rss:subscriptions:get", $page_owner); 
     14        $run_result = in_array($parameter, $rss_subscriptions[$page_owner]); 
    1115         
    12             global $rss_subscriptions; 
    13              
    14         run("rss:subscriptions:get"); 
    15          
    16         $run_result = in_array($parameter, $rss_subscriptions); 
    17  
    18         } else if (run("permissions:check", "profile")) { 
    19              
    20             $num = count_records('feed_subscriptions','user_id',$page_owner,'ident',$parameter); 
    21             if (!empty($num)) { 
    22                 $run_result = true; 
    23             } 
    24              
    25         } 
    26  
    2716    } 
    28          
     17     
    2918?> 
  • devel/units/magpie/function_subscriptions.php

    r659 r667  
    44 
    55if (logged_on) { 
    6          
    7     global $rss_subscriptions; 
    8     run("rss:subscriptions:get"); 
    9     run("rss:update:all",$page_owner); 
    10     if ($USER->ident == $page_owner) { 
     6     
     7    $displayuser = (int) $parameter; 
     8     
     9    //global $rss_subscriptions; 
     10    //run("rss:subscriptions:get"); 
     11     
     12    run("rss:update:all",$displayuser); 
     13    if ($USER->ident == $displayuser) { 
    1114        $body .= "<p>". __gettext("Feeds are information streams from other sites. You will often see a link to an 'RSS' feed while browsing; enter the link address into the 'add feed' box at the bottom of the page to read that information from within your learning landscape.") . "</p>"; 
    12         // $body .= "<p>". __gettext("Click a box below to automatically import content from a feed into your blog. You can also add default keywords for content from that feed. (You should only do this if you have the legal right to use this resource.)") . "</p>"; 
    1315    } 
    1416    if ($feed_subscriptions = get_records_sql('SELECT fs.ident AS subid, fs.autopost, fs.autopost_tag, f.* FROM '.$CFG->prefix.'feed_subscriptions fs 
    1517                                              JOIN '.$CFG->prefix.'feeds f ON f.ident = fs.feed_id 
    16                                               WHERE fs.user_id = ? ORDER BY f.name ASC',array($page_owner))) { 
     18                                              WHERE fs.user_id = ? ORDER BY f.name ASC',array($displayuser))) { 
    1719        if (run("permissions:check", "profile")) { 
    1820            $body .= "<form action=\"\" method=\"post\" >"; 
     
    3032            $name = "<a href=\"".$feed->siteurl."\">" . stripslashes($feed->name) . "</a>"; 
    3133            $column2 = "<a href=\"".url."_rss/individual.php?feed=".$feed->ident."\">". __gettext("View content") . "</a>"; 
     34            // this allows unsubscribing the *displayed* user from the feed (if you're admin), as opposed 
     35            // to the popular feeds page, which allows you to unsubscribe yourself from a feed. 
     36            // I think. 
     37            // maybe. 
     38            // Love, Sven 
    3239            if (run("permissions:check", "profile")) { 
    3340                $column2 .= " | <a href=\"".url."_rss/subscriptions.php?action=unsubscribe&amp;feed=".$feed->ident 
     
    5966         
    6067    } else { 
    61         if ($_SESSION['userid'] == $page_owner) { 
     68        if ($_SESSION['userid'] == $displayuser) { 
    6269            $body .= "<p>" . __gettext("You are not subscribed to any feeds.") . "</p>"; 
    6370        } else { 
  • devel/units/magpie/function_subscriptions_publish_to_blog.php

    r659 r667  
    66    if (logged_on) { 
    77         
    8     global $rss_subscriptions; 
    9     run("rss:subscriptions:get"); 
     8//     global $rss_subscriptions; 
     9//     run("rss:subscriptions:get"); 
    1010    if ($USER->ident == $page_owner) { 
    1111        $body .= "<p>". __gettext("Click a box below to automatically import content from a feed into your blog. You can also add default keywords for content from that feed. (You should only do this if you have the legal right to use this resource - in other words, you must have permission from the content owner.)") . "</p>"; 
  • devel/units/magpie/function_view.php

    r659 r667  
    3030    $run_result .= <<< END 
    3131         
    32                 <a href="{$CFG->wwwroot}{$profile_name}/newsclient/all/skip={$display_feed_offset}">&lt;&lt; $back</a> 
    33                  
     32        <a href="{$CFG->wwwroot}{$profile_name}/newsclient/all/skip={$display_feed_offset}">&lt;&lt; $back</a> 
     33         
    3434END; 
    3535} 
     
    4141    $next = __gettext("Next"); 
    4242    $run_result .= <<< END 
    43                  
    44                 <a href="{$CFG->wwwroot}{$profile_name}/newsclient/all/skip={$display_feed_offset}">$next &gt;&gt;</a> 
    45                  
     43         
     44        <a href="{$CFG->wwwroot}{$profile_name}/newsclient/all/skip={$display_feed_offset}">$next &gt;&gt;</a> 
     45         
    4646END; 
    4747}