Changeset 252

Show
Ignore:
Timestamp:
02/15/06 22:57:55 (3 years ago)
Author:
ben
Message:

Code to allow for RSS imports into weblogs

Files:

Legend:

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

    r112 r252  
    1111        define('context','resources'); 
    1212         
    13         $title = run("profile:display:name") ." :: " . gettext("External feeds"); 
     13        $title = run("profile:display:name") ." :: " . gettext("Feeds"); 
    1414         
    1515        $body = run("rss:subscriptions",$feed); 
  • devel/units/magpie/function_actions.php

    r167 r252  
    22 
    33 
    4         if (logged_on && isset($_REQUEST['action'])) { 
     4        if (logged_on && isset($_REQUEST['action']) && run("permissions:check", "profile")) { 
    55                 
    66                global $page_owner; 
     7                 
     8                if ($page_owner != $_SESSION['userid']) { 
     9                        $page_username = db_query("select username from users where ident = $page_owner"); 
     10                        $page_username = $page_username->username; 
     11                } else { 
     12                        $page_username = $_SESSION['username']; 
     13                } 
    714                 
    815                switch($_REQUEST['action']) { 
     
    5764                                                                                                                } 
    5865                                                                                                                break; 
     66                                case "rss:subscriptions:update":                if (isset($_REQUEST['keywords'])) { 
     67                                                                                                                        db_query("update feed_subscriptions set autopost = 'no' where user_id = '$page_owner'"); 
     68                                                                                                                        if (is_array($_REQUEST['keywords']) && sizeof($_REQUEST['keywords']) > 0) { 
     69                                                                                                                                foreach($_REQUEST['keywords'] as $key => $keyword_set) { 
     70                                                                                                                                        $keyword_set = trim($keyword_set); 
     71                                                                                                                                        if (strlen($keyword_set) > 128) { 
     72                                                                                                                                                $keyword_set = substr($keyword_set, 0, 128); 
     73                                                                                                                                        } 
     74                                                                                                                                        $key = (int) $key; 
     75                                                                                                                                        db_query("update feed_subscriptions set autopost_tag = \"".addslashes($keyword_set)."\" where ident = $key and user_id = $page_owner"); 
     76                                                                                                                                } 
     77                                                                                                                        } 
     78                                                                                                                        if (isset($_REQUEST['feedautopost']) && is_array($_REQUEST['feedautopost']) && sizeof($_REQUEST['feedautopost']) > 0) { 
     79                                                                                                                                foreach($_REQUEST['feedautopost'] as $autopost) { 
     80                                                                                                                                        $autopost = (int) $autopost; 
     81                                                                                                                                        $feedurl = db_query("select feeds.url from feed_subscriptions left join feeds on feeds.ident = feed_subscriptions.feed_id where feed_subscriptions.ident = $autopost"); 
     82                                                                                                                                        if (is_array($feedurl) && sizeof($feedurl) > 0) { 
     83                                                                                                                                                $feedurl = $feedurl[0]->url; 
     84                                                                                                                                                if (substr_count($feedurl,url) > 0 && substr_count($feedurl,"/".$page_username."/") > 0) { 
     85                                                                                                                                                        $messages[] = gettext("Feed not imported to blog: You cannot import a feed from this account."); 
     86                                                                                                                                                        echo $feedurl; 
     87                                                                                                                                                } else { 
     88                                                                                                                                                        db_query("update feed_subscriptions set autopost = 'yes' where ident = $autopost and user_id = $page_owner"); 
     89                                                                                                                                                } 
     90                                                                                                                                        } 
     91                                                                                                                                } 
     92                                                                                                                        } 
     93                                                                                                                        $messages[] = "Your changes were saved."; 
     94                                                                                                                } 
    5995                         
    6096                } 
  • devel/units/magpie/function_subscriptions.php

    r167 r252  
    1111                if ($_SESSION['userid'] == $page_owner) { 
    1212                        $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>"; 
     13                        $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>"; 
    1314                } 
    1415                 
    15                 $feed_subscriptions = db_query("select feeds.* from feed_subscriptions join feeds on feeds.ident = feed_subscriptions.feed_id where feed_subscriptions.user_id = ". $page_owner . " order by feeds.name asc"); 
     16                $feed_subscriptions = db_query("select feed_subscriptions.ident as subid, feed_subscriptions.autopost, feed_subscriptions.autopost_tag, feeds.* from feed_subscriptions join feeds on feeds.ident = feed_subscriptions.feed_id where feed_subscriptions.user_id = ". $page_owner . " order by feeds.name asc"); 
    1617                if (sizeof($feed_subscriptions) > 0) { 
     18                         
     19                        if (run("permissions:check", "profile")) { 
     20                                $body .= "<form action=\"\" method=\"post\" >"; 
     21                        } 
    1722                         
    1823                        $body .= run("templates:draw", array( 
     
    2429                                                                                                                ); 
    2530                         
    26                 foreach($feed_subscriptions as $feed) { 
    27                          
    28                                 $name = "<a href=\"".$feed->siteurl."\">" . stripslashes($feed->name) . "</a>"; 
    29                                 $column2 = "<a href=\"".url."_rss/individual.php?feed=".$feed->ident."\">". gettext("View content") . "</a>"; 
    30                                 if (run("permissions:check", "profile")) { 
    31                                         $column2 .= " | <a href=\"".url."_rss/subscriptions.php?action=unsubscribe&amp;feed=".$feed->ident."&amp;profile_id=$page_owner\" onClick=\"return confirm('".gettext("Are you sure you want to unsubscribe from this feed?")."')\">" . gettext("Unsubscribe") . "</a>"; 
    32                                 } 
    33                                  
    34                                 $body .= run("templates:draw", array( 
     31                                foreach($feed_subscriptions as $feed) { 
     32                                         
     33                                                if (run("permissions:check", "profile")) { 
     34                                                        $name = "<input type=\"checkbox\" name=\"feedautopost[]\" value=\"" . $feed->subid . "\" "; 
     35                                                        if ($feed->autopost == "yes") { 
     36                                                                $name .= " checked=\"checked\""; 
     37                                                                 
     38                                                        } 
     39                                                        $name .= " />"; 
     40                                                } 
     41                                                $name .= "<a href=\"".$feed->siteurl."\">" . stripslashes($feed->name) . "</a>"; 
     42                                                if (run("permissions:check", "profile")) { 
     43                                                        $name .= "<br />"; 
     44                                                        $name .= gettext("Keywords: ") . "<input type=\"text\" name=\"keywords[" . $feed->subid . "]\" value=\"" . htmlentities(stripslashes($feed->autopost_tag)) . "\" />"; 
     45                                                } 
     46                                                 
     47                                                $column2 = "<a href=\"".url."_rss/individual.php?feed=".$feed->ident."\">". gettext("View content") . "</a>"; 
     48                                                if (run("permissions:check", "profile")) { 
     49                                                        $column2 .= " | <a href=\"".url."_rss/subscriptions.php?action=unsubscribe&amp;feed=".$feed->ident."&amp;profile_id=$page_owner\" onClick=\"return confirm('".gettext("Are you sure you want to unsubscribe from this feed?")."')\">" . gettext("Unsubscribe") . "</a>"; 
     50                                                } 
     51                                                 
     52                                                $body .= run("templates:draw", array( 
     53                                                                                                                                        'context' => 'adminTable', 
     54                                                                                                                                        'name' => date("F j, Y, g:i a",$feed->last_updated), 
     55                                                                                                                                        'column1' => $name, 
     56                                                                                                                                        'column2' => $column2 
     57                                                                                                                                ) 
     58                                                                                                                                ); 
     59                                                                                                                                 
     60                                        } 
     61                                         
     62                                        if (run("permissions:check", "profile")) { 
     63                                                 
     64                                                $body .= run("templates:draw", array( 
    3565                                                                                                                        'context' => 'adminTable', 
    36                                                                                                                         'name' => date("F j, Y, g:i a",$feed->last_updated)
    37                                                                                                                         'column1' => $name
    38                                                                                                                         'column2' => $column2 
     66                                                                                                                        'name' => "<input type=\"hidden\" name=\"action\" value=\"rss:subscriptions:update\" />"
     67                                                                                                                        'column1' => "<input type=\"submit\" value=\"" . gettext("Update") . "\" />"
     68                                                                                                                        'column2' => "" 
    3969                                                                                                                ) 
    4070                                                                                                                ); 
    41                                                                                                                  
     71                                                 
     72                                                $body .= "</form>"; 
     73                                        } 
     74                                         
     75                        } else { 
     76                                if ($_SESSION['userid'] == $page_owner) { 
     77                                        $body .= "<p>" . gettext("You are not subscribed to any feeds.") . "</p>"; 
     78                                } else { 
     79                                        $body .= "<p>" . gettext("No feeds were found.") . "</p>"; 
     80                                } 
    4281                        } 
    4382                         
    44                 } else { 
    45                         if ($_SESSION['userid'] == $page_owner) { 
    46                                 $body .= "<p>" . gettext("You are not subscribed to any feeds.") . "</p>"; 
    47                         } else { 
    48                                 $body .= "<p>" . gettext("No feeds were found.") . "</p>"; 
     83                        if (run("permissions:check", "profile")) { 
     84                                $body .= "<p>". gettext("To subscribe to a new feed, enter its address below:") . "</p>"; 
     85                                $body .= "<form action=\"\" method=\"post\">"; 
     86                                $body .= run("templates:draw", array( 
     87                                                                                                                                        'context' => 'adminTable', 
     88                                                                                                                                        'name' => "&nbsp;", 
     89                                                                                                                                        'column1' => "<input type=\"text\" name=\"url\" value=\"http://\" style=\"width: 100%\" />", 
     90                                                                                                                                        'column2' => "<input type=\"submit\" value=\"".gettext("Subscribe") . "\" />" 
     91                                                                                                                                ) 
     92                                                                                                                                ); 
     93                                $body .= "<input type=\"hidden\" name=\"action\" value=\"subscribe-new\" /></form>"; 
    4994                        } 
    50                 } 
    51                  
    52                 if (run("permissions:check", "profile")) { 
    53                         $body .= "<p>". gettext("To subscribe to a new feed, enter its address below:") . "</p>"; 
    54                         $body .= "<form action=\"\" method=\"post\">"; 
    55                         $body .= run("templates:draw", array( 
    56                                                                                                                                 'context' => 'adminTable', 
    57                                                                                                                                 'name' => "&nbsp;", 
    58                                                                                                                                 'column1' => "<input type=\"text\" name=\"url\" value=\"http://\" style=\"width: 100%\" />", 
    59                                                                                                                                 'column2' => "<input type=\"submit\" value=\"".gettext("Subscribe") . "\" />" 
    60                                                                                                                         ) 
    61                                                                                                                         ); 
    62                         $body .= "<input type=\"hidden\" name=\"action\" value=\"subscribe-new\" /></form>"; 
    63                 } 
    64                 $run_result .= $body; 
     95                        $run_result .= $body; 
    6596                 
    6697        } 
  • devel/units/magpie/function_update.php

    r106 r252  
    1212                                                 
    1313                if (sizeof($feed) > 0 && $subscribers > 0) { 
    14  
     14                         
     15                        $update_time = 1; 
     16/* 
    1517                        if ($subscribers > 10) { 
    1618                                $update_time = 3600; 
     
    2224                                $update_time = 14400; 
    2325                        } 
    24                          
     26*/ 
    2527                        $feed = $feed[0]; 
    26                         if ($feed->last_updated < (time() - $update_time)) { 
     28                //      if ($feed->last_updated < (time() - $update_time)) { 
     29                        if (1 == 1) { 
     30                                 
    2731                                db_query("update feeds set last_updated = " . time() . " where ident = $parameter"); 
    2832                                if ($rss = run("rss:get", $feed->url)) { 
     
    8286                                                        } else { 
    8387                                                                db_query("insert into feed_posts set title = '".addslashes($title)."', body = '".addslashes($description)."', posted = '".addslashes($posted)."', url = '".addslashes($url)."', feed = $parameter, added = $added"); 
     88                                                                $weblogs = db_query("select user_id, autopost_tag from feed_subscriptions where feed_id = $parameter and autopost = 'yes'"); 
     89                                                                if (is_array($weblogs) && sizeof($weblogs) > 0) { 
     90                                                                        $body = "<p><a href=\"$url\">$url</a></p>" . addslashes($description); 
     91                                                                        foreach($weblogs as $weblog) { 
     92                                                                                db_query("insert into weblog_posts set title = '".addslashes($title)."', body = '$body', access = 'PUBLIC', owner = " . $weblog->user_id . ", weblog = " . $weblog->user_id . ", posted = $added"); 
     93                                                                                $id = db_id(); 
     94                                                                                $tags = trim($weblog->autopost_tag); 
     95                                                                                if ($tags != "") { 
     96                                                                                        $tags = explode(",",$tags); 
     97                                                                                        foreach($tags as $tag) { 
     98                                                                                                $tag = trim($tag); 
     99                                                                                                if ($tag != "") { 
     100                                                                                                        $tag = addslashes($tag); 
     101                                                                                                        db_query("insert into tags set tag = '$tag', tagtype = 'weblog', ref = $id, access = 'PUBLIC', owner = " . $weblog->user_id); 
     102                                                                                                } 
     103                                                                                        } 
     104                                                                                } 
     105                                                                        } 
     106                                                                } 
    84107                                                        } 
    85108                                                } 
  • devel/units/magpie/function_update_all_cron.php

    r59 r252  
    77                 
    88        // Get all subscriptions 
    9                 $subscriptions = db_query("select ident, url, last_updated from feeds where last_updated < (UNIX_TIMESTAMP() - 3600)"); 
     9                $subscriptions = db_query("select ident, url, last_updated from feeds where last_updated <= (UNIX_TIMESTAMP() - 0)"); 
    1010                if (sizeof($subscriptions > 0)) { 
    1111                        foreach($subscriptions as $subscription) { 
  • devel/units/magpie/menu_sub.php

    r112 r252  
    1111                                        $run_result .= run("templates:draw", array( 
    1212                                                                'context' => 'submenuitem', 
    13                                                                 'name' => gettext("External feeds"), 
     13                                                                'name' => gettext("Feeds"), 
    1414                                                                'location' =>  url . $rss_username . "/feeds/" 
    1515                                                        )