root/devel/mod/profile/lib/function_rss_publish.php

Revision 1301, 2.8 kB (checked in by dramirez, 1 year ago)

Moved from units to mod:

  • profile
  • users
  • template

Updated .htaccess rules

  • Property svn:eol-style set to native
Line 
1 <?php
2 global $CFG;
3 require_once($CFG->dirroot.'lib/uploadlib.php');
4 /*
5  *    Function to publish weblog posts and files as RSS, either a static file or return output
6  *   
7  *    $parameter[0] is the numeric id of the user to publish
8  *   
9  *    $parameter[1] is true to return a string of RSS, or false to publish static file.
10  *        (Defaults to publishing file)
11  *
12  */
13
14     $run_result = false;
15     
16     if (isset($parameter) && is_array($parameter)) {
17         
18         $userid = (int) $parameter[0];
19         if ($userid > 0) {
20             $username = user_info('username', $userid);
21         }
22         if ($username) {
23             
24             // make output dirs if they don't already exist
25             $publish_folder = substr($username,0,1);
26             
27             $publish_folder = "rss/" . $publish_folder . "/" . $username;
28             
29             make_upload_directory($publish_folder,false);
30             
31             $rssfile = $CFG->dataroot.$publish_folder.'/profile.xml';
32             
33             //generate rss
34             $sitename = sitename;
35             $rssactivity = __gettext("Activity");
36             
37             $info = get_record('users','ident',$userid);
38             $name = stripslashes(user_name($info->ident));
39             //$username = $info->username;
40             $mainurl = url . $username . "/";
41             $rssurl = $mainurl . "rss/";
42             $url = url;
43             $rssdescription = sprintf(__gettext("Activity for %s, hosted on %s."),$name,$sitename);
44             $output = <<< END
45 <?xml-stylesheet type="text/xsl" href="{$rssurl}rssstyles.xsl"?>
46 <rss version='2.0'   xmlns:dc='http://purl.org/dc/elements/1.1/'>
47     <channel xml:base='$mainurl'>
48         <title><![CDATA[$name : $rssactivity]]></title>
49         <description><![CDATA[$rssdescription]]></description>
50         <generator>Elgg</generator>
51         <link>$mainurl</link>
52 END;
53
54             $tag= '';
55             if (!empty($_REQUEST['tag'])) {
56                 $tag = trim($_REQUEST['tag']);
57             }
58             
59             // WEBLOGS
60             $output .= run("weblogs:rss:getitems", array($userid, 10, $tag));
61             
62             // FILES
63             $output .= run("files:rss:getitems", array($userid, 10, $tag));
64             
65             $output .= <<< END
66
67     </channel>
68 </rss>
69 END;
70             
71             if ($parameter[1] === true) {
72                 
73                 $run_result = $output;
74                 
75             } else {
76                 
77                 // write to file
78                 if ($handle = fopen($rssfile, "wb")) {
79                     $writeresult = fwrite($handle, $output);
80                     $closeresult = fclose($handle);
81                     if ($writeresult && $closeresult) {
82                         $run_result = true;
83                     }
84                 }
85                 
86             }
87             
88         } // if ($username)
89         
90     }
91
92 ?>
Note: See TracBrowser for help on using the browser.