heimrichhannot/contao-filename-sanitizer-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

heimrichhannot/contao-filename-sanitizer-bundle

Composer 安装命令:

composer require heimrichhannot/contao-filename-sanitizer-bundle

包简介

This bundle offers functionality for sanitizing filenames, i.e. replacing unwanted characters like whitespaces, non-ascii characters, ... (e.g. while uploading them to the CMS).

README 文档

README

This bundle offers functionality for sanitizing filenames, i.e. replacing unwanted characters like whitespaces, non-ascii characters, ... (e.g. while uploading them to the CMS).

Features

  • sanitize filenames while uploading files using the Contao file manager
  • sanitize filenames while saving a given file using the Contao file manager
  • configurable sanitizing rules:
    • valid alphabets (the characters which are valid in the end -> "whitelist")
    • trimming
    • replacing of repeating (consecutive) hyphens or underscores
  • service is also available for various other use cases besides file upload
  • define a set of 1:1 character replacements (useful for German umlauts, i.e. ä => ae)
  • use the SanitizeCommand in order to sanitize the filenames of files/folders already in the system and automatically create htaccess rewrite rules in order to keep deep links working

Default sanitizing rules after installation of this bundle

configuration

Configuration in Contao's global settings

Installation

Install via composer: composer require heimrichhannot/contao-filename-sanitizer-bundle and update your database.

Configuration

You can configure the sanitizing rules in the global Contao settings under "file names".

Important notes

When is the sanitizing done exactly?

There are different situations where the filename sanitizing (which affects files and folders) takes place:

  1. A new file is uploaded by using Contao's file manager (files uploaded by FTP are of course not covered)
  2. An already existing file is saved by using Contao's file manager.
  3. An already existing folder is saved by using Contao's file manager. Files inside the folder are NOT sanitized automatically!
  4. By using the command huh_filename_sanitizer:sanitize. See below for more details.

What about already existing files and folders and the links to these?

IMPORTANT: The sanitizing rules are applied when saving a file or folder already existing.

The file or folder is linked in the system by binary UUID

This is the case if you have used fileTree widgets (file pickers) in news or content elements for example. Same applies if you have used inserttags like {{file::some-hash-uuid}}.

In this case the links will be working even after the sanitizing has been done because the link is done by an immutable binary UUID stored in the database.

The file or folder is linked in the system by a hardcoded path

Files and folders already present in the system

Caution: Files not linked by UUIDs are DEAD after filename sanitizing has been used.

You'll have to create htaccess rules to redirect the old paths to the new ones in this case.

The file or folder if linked from outside of the system

In this case it's of course always a hardcoded path. You'll have to create htaccess rules to redirect the old paths to the new ones in this case.

Commands

Sanitize Command

This command is designed for sanitizing existing files as a batch processing. Please use it with caution!

Features:

  • process files or folders (one or more by passing a pipe ("|") separated list of IDs or paths)
  • run as dry-run to see what would have been done if the command is executed
  • generate a set of htaccess rules to redirect the old paths to the new ones (pass in a domain)

Usage:

vendor/bin/contao-console huh_filename_sanitizer:sanitize [options]

Options:

    --dry-run[=DRY-RUN]      See what the command would do [default: false]
    --ids[=IDS]              Pass in one or a comma separated list of IDs (tl_files.id); example: 1,2,3
    --paths[=PATHS]          Pass in one or a *pipe* separated list of paths (relative to the Contao root directory); example: files|files/some-folder|files/Hello, John
-R, --recursive[=RECURSIVE]  Also process files/folders inside folders [default: false]
    --domain[=DOMAIN]        The domain for the htaccess rewrite rules

Events

Name Arguments
AfterFilenameSanitizationEvent string $file
AfterFolderSanitizationEvent string $folder
AfterStringSanitizationEvent string $string
BeforeFilenameSanitizationEvent \Contao\File file
BeforeFolderSanitizationEvent \Contao\Folder $folder
BeforeStringSanitizationEvent string $string

heimrichhannot/contao-filename-sanitizer-bundle 适用场景与选型建议

heimrichhannot/contao-filename-sanitizer-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.96k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 heimrichhannot/contao-filename-sanitizer-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 heimrichhannot/contao-filename-sanitizer-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 heimrichhannot/contao-filename-sanitizer-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2019-01-11