From 9611fc7bda651dc9cbb40dc5b5b92ddb0f4ed3ff Mon Sep 17 00:00:00 2001 From: mmx900 Date: Wed, 14 Jun 2023 19:13:48 +0900 Subject: [PATCH] Fix #2114 Allow specifying file formats to be indexed --- modules/file/file.admin.controller.php | 1 + modules/file/file.controller.php | 25 ++++++++++++++++++++++++- modules/file/lang/en.php | 2 ++ modules/file/lang/ko.php | 2 ++ modules/file/tpl/download_config.html | 7 +++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/file/file.admin.controller.php b/modules/file/file.admin.controller.php index dbcf8e011..5648eaa95 100644 --- a/modules/file/file.admin.controller.php +++ b/modules/file/file.admin.controller.php @@ -158,6 +158,7 @@ class FileAdminController extends File $config->allow_outlink = Context::get('allow_outlink') === 'N' ? 'N' : 'Y'; $config->allow_outlink_format = Context::get('allow_outlink_format'); $config->allow_outlink_site = Context::get('allow_outlink_site'); + $config->allow_indexing_format = Context::get('allow_indexing_format'); $config->allow_multimedia_direct_download = Context::get('allow_multimedia_direct_download') === 'Y' ? 'Y' : 'N'; $config->download_short_url = Context::get('download_short_url') === 'Y' ? 'Y' : 'N'; $config->inline_download_format = array_map('utf8_trim', Context::get('inline_download_format') ?: []); diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php index 3a8e636c3..c1bfa5626 100644 --- a/modules/file/file.controller.php +++ b/modules/file/file.controller.php @@ -400,7 +400,30 @@ 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); } - header('X-Robots-Tag: noindex'); + $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) + { + header('X-Robots-Tag: noindex'); + } + header('Location: ' . $url); Context::close(); exit(); diff --git a/modules/file/lang/en.php b/modules/file/lang/en.php index 6f097fe50..4a3722b72 100644 --- a/modules/file/lang/en.php +++ b/modules/file/lang/en.php @@ -12,6 +12,7 @@ $lang->status = 'Status'; $lang->is_valid = 'Valid'; $lang->is_stand_by = 'Stand by'; $lang->file_list = 'Attachment List'; +$lang->allow_indexing_format = 'Allowed formats to be indexed'; $lang->allow_outlink = 'Allow External Link to Download URL'; $lang->allow_outlink_site = 'Allowed Websites'; $lang->allow_outlink_format = 'Allowed Formats'; @@ -33,6 +34,7 @@ $lang->about_use_default_file_config = 'Follow the default settings from the Fil $lang->about_download_short_url = 'Using short URLs can fix broken filenames in Android and some other platforms.
Short URLs must be enabled, and rewrite rules must be updated to the latest version if you use nginx.'; $lang->about_inline_download_format = 'Selected types of files will be opened in the current window instead of a download dialog when a user clicks the download link.'; $lang->enable_download_group = 'Downloadable Groups'; +$lang->about_allow_indexing_format = 'These file formats will be allowed to be indexed by search engines like Google.
This can increase server load and traffic, and you should be careful not to expose files containing confidential information.
Please use a comma (,) to separate items: e.g. doc, zip, pdf'; $lang->about_allow_outlink = 'Allow other websites to link directly to your download URLs.
Rhymix does not control links to image files that can be embedded directly in a document.
in order to block external links to such images, you may need to modify your web server configuration.'; $lang->about_allow_outlink_format = 'These file formats will always be allowed.
Please use a comma (,) to separate items: e.g. doc, zip, pdf'; $lang->about_allow_outlink_site = 'These referers will always be allowed.
Please enter one full address per line: e.g. https://www.rhymix.org/'; diff --git a/modules/file/lang/ko.php b/modules/file/lang/ko.php index 91414b8ce..9031f7b7e 100644 --- a/modules/file/lang/ko.php +++ b/modules/file/lang/ko.php @@ -12,6 +12,7 @@ $lang->status = '상태'; $lang->is_valid = '유효'; $lang->is_stand_by = '대기'; $lang->file_list = '첨부 파일 목록'; +$lang->allow_indexing_format = '외부 색인 허용 확장자'; $lang->allow_outlink = '다운로드 링크 외부 접근 허용'; $lang->allow_outlink_site = '외부 접근 허용 사이트'; $lang->allow_outlink_format = '외부 접근 허용 확장자'; @@ -33,6 +34,7 @@ $lang->about_use_default_file_config = '파일 모듈의 기본 설정을 따릅 $lang->about_download_short_url = '안드로이드 등 일부 환경에서 첨부파일 다운로드시 파일명이 깨지는 문제를 해결할 수 있습니다.
짧은주소 사용이 활성화되어 있어야 하며, nginx 사용시 rewrite 규칙을 최신 버전으로 업데이트하여야 합니다.'; $lang->about_inline_download_format = '선택한 종류의 파일은 다운로드 링크를 클릭하더라도 다운로드 창을 열지 않고 현재 창에 표시합니다.'; $lang->enable_download_group = '다운로드 가능 그룹'; +$lang->about_allow_indexing_format = '구글 등 검색엔진에 의한 색인을 허용하는 파일 확장자입니다.
서버 부하와 트래픽이 증가할 수 있으며, 개인정보가 포함된 파일이 노출되지 않게 주의해야 합니다.
여러 개 입력시 쉼표(,)을 이용해서 구분해 주세요. 예) doc, zip, pdf'; $lang->about_allow_outlink = '다른 사이트에서 파일 다운로드 링크에 직접 접근하는 것을 허용합니다.
본문에 바로 삽입할 수 있는 이미지 파일은 라이믹스에서 접근을 통제할 수 없으며, 이를 차단하려면 웹서버 설정이 필요합니다.'; $lang->about_allow_outlink_format = '파일 외부 링크 설정에 상관없이 허용하는 파일 확장자입니다.
여러 개 입력시 쉼표(,)을 이용해서 구분해 주세요. 예) doc, zip, pdf'; $lang->about_allow_outlink_site = '파일 외부 링크 설정에 상관없이 허용하는 사이트 주소입니다.
여러 개 입력시 줄을 바꿔서 구분해 주세요. 예) https://www.rhymix.org/'; diff --git a/modules/file/tpl/download_config.html b/modules/file/tpl/download_config.html index 8f0e1edf0..bc09e2c61 100644 --- a/modules/file/tpl/download_config.html +++ b/modules/file/tpl/download_config.html @@ -57,6 +57,13 @@

{$lang->about_inline_download_format}

+
+ +
+ +

{$lang->about_allow_indexing_format}

+
+