Issues (2128)

main/announcements/download.php (1 issue)

Labels
Severity
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
/**
5
 * This file is responsible for  passing requested documents to the browser.
6
 * Html files are parsed to fix a few problems with URLs,
7
 * but this code will hopefully be replaced soon by an Apache URL
8
 * rewrite mechanism.
9
 */
10
session_cache_limiter('nocache');
11
12
require_once __DIR__.'/../inc/global.inc.php';
13
14
// IMPORTANT to avoid caching of documents
15
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
16
header('Cache-Control: public');
17
header('Pragma: no-cache');
18
19
//protection
20
api_protect_course_script(true);
21
22
$doc_url = $_GET['file'];
23
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
24
$doc_url = str_replace('///', '&', $doc_url);
25
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
26
$doc_url = str_replace(' ', '+', $doc_url);
27
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
28
29
if (strpos($doc_url, '../') || strpos($doc_url, '/..')) {
30
    $doc_url = '';
31
}
32
33
if (!isset($_course)) {
34
    api_not_allowed(true);
35
}
36
37
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/announcements/'.$doc_url;
38
39
//if the rewrite rule asks for a directory, we redirect to the document explorer
40
if (is_dir($full_file_name)) {
41
    //remove last slash if present
42
    //$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
43
    //mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
44
    while ('/' == $doc_url[$dul = strlen($doc_url) - 1]) {
45
        $doc_url = substr($doc_url, 0, $dul);
46
    }
47
    //create the path
48
    $document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
49
    //redirect
50
    header('Location: '.$document_explorer);
51
    exit;
52
}
53
54
$table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
55
56
// launch event
57
Event::event_download($doc_url);
0 ignored issues
show
The method event_download() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
Event::/** @scrutinizer ignore-call */ 
58
       event_download($doc_url);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
$course_id = api_get_course_int_id();
59
$doc_url = Database::escape_string($doc_url);
60
61
$sql = "SELECT filename FROM $table
62
  	  	WHERE c_id = $course_id AND path LIKE BINARY '$doc_url'";
63
64
$result = Database::query($sql);
65
if (Database::num_rows($result) > 0) {
66
    $row = Database::fetch_array($result);
67
    $title = str_replace(' ', '_', $row['filename']);
68
    if (Security::check_abs_path(
69
        $full_file_name,
70
        api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/announcements/'
71
    )
72
    ) {
73
        $result = DocumentManager::file_send_for_download($full_file_name, true, $title);
74
        if (false === $result) {
75
            api_not_allowed(true);
76
        }
77
    }
78
}
79
exit;
80