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

Revision 1539, 3.3 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 // Turn file ID into a proper link
4
5 if (isset($parameter)) {
6     run("files:metadata:init");
7     $fileid = (int) $parameter;
8     if ($file = get_record('files','ident',$fileid)) {
9         
10         require_once($CFG->dirroot . 'lib/filelib.php');
11         $filelocation = file_cache($file);
12         if (run("users:access_level_check",$file->access) || $file->owner == $_SESSION['userid']) {
13             if (!in_array(run("files:mimetype:inline",$filelocation), $data['mimetype:inline'])) {
14                 require_once($CFG->dirroot.'lib/filelib.php');
15                 $mimeinfo = mimeinfo('type',$file->location);
16                 $filepath = $CFG->wwwroot . user_info('username', $file->owner) . "/files/" . $file->folder . "/" . $file->ident . "/" . urlencode($file->originalname);
17                 switch($mimeinfo) {
18                     
19                     case "audio/mpeg":
20                     case "audio/mp3":
21                         $filetitle = urlencode(stripslashes($file->title));
22                         $run_result .= "
23         <embed src=\"" . $CFG->wwwroot . "mod/file/mp3player/xspf_player_slim.swf?song_url=$filepath&amp;song_title=$filetitle\"
24         type=\"application/x-shockwave-flash\"
25         height=\"15\" width=\"400\" />";
26                         break;
27                         
28                    case "application/x-shockwave-flash":
29                         $run_result .= "<embed src=\"$filepath\" type=\"application/x-shockwave-flash\" />";
30                         break;
31                    default:
32                         $extension = strtolower(substr($file->originalname,strpos($file->originalname,".")+1));
33                         $type=(array_key_exists($extension,get_mimetype_array()))?" $extension":"";
34                         $run_result .= '<a class="mediafile'.$type.'" href="' . $filepath . '">';
35                         $run_result .= stripslashes((!empty($file->title))?$file->title:$file->originalname);
36                         $run_result .= "</a> ";
37                         break;
38                   
39                 }
40             } else {
41                 list($width, $height, $type, $attr) = getimagesize($filelocation);
42                 if ($width > 400 || $height > 400) {
43                     $run_result .= "<a href=\"";
44                     $run_result .= $CFG->wwwroot . user_info('username', $file->owner) . "/files/" . $file->folder . "/" . $file->ident . "/" . $file->originalname;
45                     $run_result .= "\" >";
46                     $run_result .= '<img src="' . $CFG->wwwroot . '_icon/file/' . $file->ident . '" alt="' . htmlspecialchars(stripslashes($file->title), ENT_COMPAT, 'utf-8') . '" />';
47                     $run_result .= "</a>";
48                 } else {
49                     $run_result .= "<img src=\"";
50                     $run_result .= url . user_info('username', $file->owner) . "/files/" . $file->folder . "/" . $file->ident . "/" . $file->originalname;
51                     $run_result .= "\" $attr alt=\"".htmlspecialchars(stripslashes($file->title), ENT_COMPAT, 'utf-8')."\" />";
52                 }
53             }
54         } else {
55             $run_result .= "<b>[" . __gettext("You do not have permission to access this file") . "]</b>";
56         }
57     } else {
58         $run_result .= "<b>[" . __gettext("File does not exist") . "]</b>";
59     }
60 }
61
62 ?>
Note: See TracBrowser for help on using the browser.