root/devel/mod/file/lib/function_rss_getitems.php

Revision 1539, 3.0 kB (checked in by renato, 1 year ago)

Setting prop svn:eol-style in LOTS of files.

  • Property svn:eol-style set to native
Line 
1 <?php
2 global $CFG;
3 /*
4  *    Function to get RSS item blocks for a filestore
5  *   
6  *    $parameter[0] is the numeric id of the user to retrieve
7  *    $parameter[1] is the number of entries to retrieve
8  *    $parameter[2] is a tag to search for, if any
9  *
10  */
11
12     $run_result = "";
13
14     global $page_owner;
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             $numrows = (int) $parameter[1];
25             if (!$numrows) {
26                 $numrows = 10;
27             }
28             
29             $tag = trim($parameter[2]);
30             if (empty($tag)) {
31                 $files = get_records_sql('SELECT * FROM '.$CFG->prefix.'files where files_owner = ? and access = ? order by time_uploaded desc limit ?',array($parameter[0],'PUBLIC',$numrows));
32             } else {
33                 $files = get_records_sql('SELECT f.* FROM '.$CFG->prefix.'tags t
34                                           JOIN '.$CFG->prefix.'files f ON f.ident = t.ref
35                                           WHERE f.files_owner = ? AND f.access = ?
36                                           AND t.tagtype = ? AND t.tag = ?
37                                           ORDER BY f.time_uploaded DESC LIMIT 10',array($parameter[0],'PUBLIC','file',$tag));
38             }
39             
40             if (is_array($files) && sizeof($files) > 0) {
41                 require_once($CFG->dirroot . 'lib/filelib.php');
42                 foreach($files as $file) {
43                     $title = stripslashes($file->title);
44                     $link = url . $username . "/files/" . $file->folder . "/" . $file->ident . "/" . (urlencode(stripslashes($file->originalname)));
45                     $description = stripslashes($file->description);
46                     $pubdate = gmdate("D, d M Y H:i:s T", $file->time_uploaded);
47                     // $trackmaxtime = max($trackmaxtime, $file->time_uploaded);
48                     $length = (int) $file->size;
49                     $mimetype = mimeinfo('type',$file->location);
50                     $keywordtags = "";
51                     if ($keywords = get_records_select('tags',"tagtype = ? AND ref = ?",array('file',$file->ident))) {
52                         foreach($keywords as $keyword) {
53                             $keywordtags .= "\n\t\t<dc:subject><![CDATA[". (stripslashes($keyword->tag)) . "]]></dc:subject>";
54                         }
55                     }
56                     $run_result .= <<< END
57
58         <item>
59             <title><![CDATA[$title]]></title>
60             <link>$link</link>
61             <enclosure url="$link" length="$length" type="$mimetype" />
62             <pubDate>$pubdate</pubDate>$keywordtags
63             <description><![CDATA[$description]]></description>
64         </item>
65 END;
66                 }
67             } else {
68                 //$run_result .= "no items";
69             }
70             
71         } // if ($username)
72         
73     }
74
75 ?>
Note: See TracBrowser for help on using the browser.