Internal: Format code, remove unused code, add psalm check dirs

pull/3513/head
Julio Montoya 5 years ago
parent f7776322c6
commit dee64d394c
  1. 8
      psalm.xml
  2. 79
      public/main/announcements/download.php
  3. 5
      public/main/attendance/index.php
  4. 76
      public/main/blog/download.php
  5. 1
      src/CoreBundle/Entity/AbstractResource.php

@ -9,10 +9,18 @@
<projectFiles>
<directory name="src"/>
<!-- <directory name="public/main/admin" />-->
<directory name="public/main/announcements"/>
<directory name="public/main/attendance"/>
<!-- <directory name="public/main/badge"/>-->
<directory name="public/main/blog"/>
<!-- <directory name="public/main/calendar"/>-->
<directory name="public/main/group"/>
<directory name="public/main/link" />
<!-- <directory name="public/main/session" /> -->
<!-- <directory name="public/main/exercise"/> -->
<file name="public/main/inc/lib/attendance.lib.php"/>
<ignoreFiles>
<directory name="vendor/*"/>
<directory name="src/CoreBundle/Menu"/>

@ -1,79 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file is responsible for passing requested documents to the browser.
* Html files are parsed to fix a few problems with URLs,
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*/
session_cache_limiter('nocache');
require_once __DIR__.'/../inc/global.inc.php';
// IMPORTANT to avoid caching of documents
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Cache-Control: public');
header('Pragma: no-cache');
//protection
api_protect_course_script(true);
$doc_url = $_GET['file'];
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
if (strpos($doc_url, '../') || strpos($doc_url, '/..')) {
$doc_url = '';
}
if (!isset($_course)) {
api_not_allowed(true);
}
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/announcements/'.$doc_url;
//if the rewrite rule asks for a directory, we redirect to the document explorer
if (is_dir($full_file_name)) {
//remove last slash if present
//$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
//mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
while ('/' == $doc_url[$dul = strlen($doc_url) - 1]) {
$doc_url = substr($doc_url, 0, $dul);
}
//create the path
$document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
//redirect
header('Location: '.$document_explorer);
exit;
}
$table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
// launch event
Event::event_download($doc_url);
$course_id = api_get_course_int_id();
$doc_url = Database::escape_string($doc_url);
$sql = "SELECT filename FROM $table
WHERE c_id = $course_id AND path LIKE BINARY '$doc_url'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
$title = str_replace(' ', '_', $row['filename']);
if (Security::check_abs_path(
$full_file_name,
api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/announcements/'
)
) {
$result = DocumentManager::file_send_for_download($full_file_name, true, $title);
if (false === $result) {
api_not_allowed(true);
}
}
}
exit;

@ -200,7 +200,7 @@ if ($attendanceEntity) {
$interbreadcrumb[] = ['url' => '#', 'name' => $attendanceEntity->getName()];
}
if ('calendar_list' == $action || 'calendar_edit' == $action) {
if ('calendar_list' === $action || 'calendar_edit' === $action) {
$interbreadcrumb[] = [
'url' => 'index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendanceId,
'name' => $attendanceEntity->getName(),
@ -211,7 +211,6 @@ if ('calendar_list' == $action || 'calendar_edit' == $action) {
$allowToEdit = api_is_allowed_to_edit(null, true);
$currentUrl = api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq();
$content = '';
switch ($action) {
case 'attendance_list':
if ($allowToEdit) {
@ -685,7 +684,7 @@ switch ($action) {
if (!$is_locked_attendance || api_is_platform_admin()) {
$content .= '<div class="actions">';
if ('calendar_add' == $action) {
if ('calendar_add' === $action) {
$content .= '<a href="index.php?'.api_get_cidreq().'&action=calendar_list&attendance_id='.$attendanceId.'">'.
Display::return_icon('back.png', get_lang('Attendance calendar'), '', ICON_SIZE_MEDIUM).'</a>';
} else {

@ -1,76 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file is responsible for passing requested documents to the browser.
* Html files are parsed to fix a few problems with URLs,
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*/
session_cache_limiter('public');
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_COURSES;
// IMPORTANT to avoid caching of documents
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Cache-Control: public');
header('Pragma: no-cache');
//protection
api_protect_course_script(true);
$doc_url = $_GET['file'];
//change the '&' that got rewritten to '///' by mod_rewrite back to '&'
$doc_url = str_replace('///', '&', $doc_url);
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
if (!isset($_course)) {
api_not_allowed(true);
}
$full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'.$doc_url;
//if the rewrite rule asks for a directory, we redirect to the course view
if (is_dir($full_file_name)) {
//remove last slash if present
while ('/' == $doc_url[$dul = strlen($doc_url) - 1]) {
$doc_url = substr($doc_url, 0, $dul);
}
//create the path
$document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
//redirect
header('Location: '.$document_explorer);
exit;
}
$tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT);
$course_id = api_get_course_int_id();
// launch event
Event::event_download($doc_url);
$sql = 'SELECT filename FROM '.$tbl_blogs_attachment.'
WHERE
c_id = '.$course_id.' AND
path LIKE BINARY "'.Database::escape_string($doc_url).'"';
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
if (Security::check_abs_path(
$full_file_name,
api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/blog/'
)
) {
$result = DocumentManager::file_send_for_download(
$full_file_name,
true,
$row['filename']
);
if (false === $result) {
api_not_allowed(true);
}
}
}
exit;

@ -254,7 +254,6 @@ abstract class AbstractResource
$this->resourceLinkListFromEntity = $resourceLinkList;
}
public function hasParentResourceNode(): bool
{
return null !== $this->parentResourceNode;

Loading…
Cancel
Save