/** * @brief Creates mapping between encoded filenames and real filenames * @global type $group_sql * @param type $downloadDir * @param type $include_invisible */ function create_map_to_real_filename($downloadDir, $include_invisible) { global $group_sql; $prefix = strlen(preg_replace('|[^/]*$|', '', $downloadDir)) - 1; $encoded_filenames = $decoded_filenames = $filename = array(); $hidden_dirs = array(); $sql = Database::get()->queryArray("SELECT path, filename, visible, format, extra_path, public FROM document\n WHERE {$group_sql} AND\n path LIKE '{$downloadDir}%'"); foreach ($sql as $files) { if ($cpath = common_doc_path($files->extra_path, true)) { if ($GLOBALS['common_doc_visible'] and ($include_invisible or $files->visible == 1)) { $GLOBALS['common_docs'][$files->path] = $cpath; } } $GLOBALS['path_visibility'][$files->path] = ($include_invisible or resource_access($files->visible, $files->public)); array_push($encoded_filenames, $files->path); array_push($filename, $files->filename); if (!$include_invisible and $files->format == '.dir' and !resource_access($files->visible, $files->public)) { $parentdir = preg_replace('|/[^/]+$|', '', $files->path); // Don't need to check lower-level hidden dir if parent is there if (array_search($parentdir, $hidden_dirs) === false) { array_push($hidden_dirs, $files->path); } } } if (!$include_invisible) { if (count($hidden_dirs)) { $hidden_regexp = '#^(' . implode('|', $hidden_dirs) . ')#'; } else { $hidden_regexp = false; } } $decoded_filenames = $encoded_filenames; foreach ($encoded_filenames as $position => $name) { if (!$include_invisible and $hidden_regexp and preg_match($hidden_regexp, $name)) { $GLOBALS['path_visibility'][$name] = false; } $last_name_component = substr(strrchr($name, "/"), 1); foreach ($decoded_filenames as &$newname) { $newname = str_replace($last_name_component, $filename[$position], $newname); } unset($newname); } foreach ($decoded_filenames as &$s) { $s = substr($s, $prefix); } // create global array with mappings $GLOBALS['map_filenames'] = array_combine($encoded_filenames, $decoded_filenames); }
$link_title_extra .= ' ' . icon('edit', $langEdit, $edit_url); } if ($copyid = $entry['copyrighted'] and $copyicon = $copyright_icons[$copyid]) { $link_title_extra .= " " . icon($copyicon, $copyright_titles[$copyid], $copyright_links[$copyid], null, 'png', 'target="_blank"'); } $dload_msg = $langSave; $dObj = $entry['object']; $dObj->setAccessURL($file_url); $dObj->setPlayURL(file_playurl($cmdDirName, $entry['filename'])); if ($is_in_tinymce && !$compatiblePlugin) { // use Access/DL URL for non-modable tinymce plugins $dObj->setPlayURL($dObj->getAccessURL()); } $link_href = MultimediaHelper::chooseMediaAhref($dObj); } if (!$entry['extra_path'] or common_doc_path($entry['extra_path'])) { // Normal or common document $download_url = $base_url . "download={$cmdDirName}"; } else { // External document $download_url = $entry['extra_path']; } $tool_content .= "<tr {$style}><td class='text-center'>{$img_href}</td>\n <td>{$link_href} {$link_title_extra}"; // comments if (!empty($entry['comment'])) { $tool_content .= "<br><span class='comment'>" . nl2br(htmlspecialchars($entry['comment'])) . "</span>"; } $tool_content .= "</td>"; $date = nice_format($entry['date'], true, true); $date_with_time = nice_format($entry['date'], true); if ($is_dir) {
require_once 'include/lib/forcedownload.php'; if (defined('GROUP_DOCUMENTS')) { if (!$uid) { error($langNoRead); } if (!($is_editor or $is_member)) { error($langNoRead); } } $file_info = public_path_to_disk_path($path_components); if (!$is_editor and !resource_access($file_info->visible, $file_info->public)) { error($langNoRead); } if ($file_info->extra_path) { // $disk_path is set if common file link $disk_path = common_doc_path($file_info->extra_path, true); if (!$disk_path) { // external file URL header("Location: {$file_info->extra_path}"); exit; } elseif (!$common_doc_visible) { forbidden(preg_replace('/^.*file\\.php/', '', $uri)); } } else { // Normal file $disk_path = $basedir . $file_info->path; } if (file_exists($disk_path)) { if (!$is_in_playmode) { $valid = $uid || course_status($course_id) == COURSE_OPEN ? true : token_validate($file_info->path, $_GET['token'], 30); if (!$valid) {