From 17e14546ddcb68ca35327fa548d65ac31d1bbbfb Mon Sep 17 00:00:00 2001 From: mmx900 Date: Fri, 30 Jun 2023 21:10:01 +0900 Subject: [PATCH] Apply allow_indexing_format to procFileDownload() --- modules/file/file.controller.php | 27 ++++++--------------------- modules/file/file.model.php | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 128b248da..d1b080757 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -400,26 +400,7 @@ class FileController extends File $url = getNotEncodedUrl('', 'module', 'file', 'act', 'procFileOutput', 'file_srl', $file_srl, 'file_key', $file_key, 'force_download', Context::get('force_download') === 'Y' ? 'Y' : null); } - $allow_indexing = false; - // Handles extension to allow indexing - if($file_module_config->allow_indexing_format) - { - $allow_indexing_format_array = array(); - $allow_indexing_format_array = explode(',', $file_module_config->allow_indexing_format); - if(!is_array($allow_indexing_format_array)) $allow_indexing_format_array[0] = $file_module_config->allow_indexing_format; - - foreach($allow_indexing_format_array as $val) - { - $val = trim($val); - if(preg_match("/\.{$val}$/i", $filename)) - { - $allow_indexing = true; - break; - } - } - } - - if(!$allow_indexing) + if (!FileModel::isIndexable($filename, $file_module_config)) { header('X-Robots-Tag: noindex'); } @@ -572,7 +553,11 @@ class FileController extends File header('Content-Length: ' . $range_length); header('Accept-Ranges: bytes'); header('Etag: "' . $etag . '"'); - header('X-Robots-Tag: noindex'); + + if (!FileModel::isIndexable($filename, $file_config)) + { + header('X-Robots-Tag: noindex' . false); + } // Print the file contents for($offset = 0; $offset < $range_length; $offset += 4096) diff --git a/modules/file/file.model.php b/modules/file/file.model.php index 124be2996..ed454a8cc 100644 --- a/modules/file/file.model.php +++ b/modules/file/file.model.php @@ -181,6 +181,33 @@ class FileModel extends File return true; } + /** + * Check if the file is indexable + * @param object $filename + * @param object $file_module_config + * @return bool + */ + public static function isIndexable($filename, $file_module_config) + { + if($file_module_config->allow_indexing_format) + { + $allow_indexing_format_array = array(); + $allow_indexing_format_array = explode(',', $file_module_config->allow_indexing_format); + if(!is_array($allow_indexing_format_array)) $allow_indexing_format_array[0] = $file_module_config->allow_indexing_format; + + foreach($allow_indexing_format_array as $val) + { + $val = trim($val); + if(preg_match("/\.{$val}$/i", $filename)) + { + return true; + } + } + } + + return false; + } + /** * Check if the file is deletable *