Issues (2128)

main/blog/download.php (1 issue)

Labels
Severity
1
<?php
2
/* For licensing terms, see /license.txt */
3
/**
4
 * This file is responsible for  passing requested documents to the browser.
5
 * Html files are parsed to fix a few problems with URLs,
6
 * but this code will hopefully be replaced soon by an Apache URL
7
 * rewrite mechanism.
8
 */
9
session_cache_limiter('public');
10
11
require_once __DIR__.'/../inc/global.inc.php';
12
$this_section = SECTION_COURSES;
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 (!isset($_course)) {
30
    api_not_allowed(true);
31
}
32
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'.$doc_url;
33
34
//if the rewrite rule asks for a directory, we redirect to the course view
35
if (is_dir($full_file_name)) {
36
    //remove last slash if present
37
    while ('/' == $doc_url[$dul = strlen($doc_url) - 1]) {
38
        $doc_url = substr($doc_url, 0, $dul);
39
    }
40
    //create the path
41
    $document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
42
    //redirect
43
    header('Location: '.$document_explorer);
44
    exit;
45
}
46
47
$tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
48
$course_id = api_get_course_int_id();
49
50
// launch event
51
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

51
Event::/** @scrutinizer ignore-call */ 
52
       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...
52
53
$sql = 'SELECT filename FROM '.$tbl_blogs_attachment.'
54
        WHERE 
55
            c_id = '.$course_id.' AND 
56
            path LIKE BINARY "'.Database::escape_string($doc_url).'"';
57
$result = Database::query($sql);
58
if (Database::num_rows($result) > 0) {
59
    $row = Database::fetch_array($result);
60
    if (Security::check_abs_path(
61
        $full_file_name,
62
        api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'
63
    )
64
    ) {
65
        $result = DocumentManager::file_send_for_download(
66
            $full_file_name,
67
            true,
68
            $row['filename']
69
        );
70
71
        if ($result === false) {
72
            api_not_allowed(true);
73
        }
74
    }
75
}
76
exit;
77