Hello! Today I would like to talk about creating file archives on the site.
Unfortunately, I did not find universal means for this, there is a well-known snippet for FileDownload v2.6, but it was last updated in 2007. And I heard that the guys from one of the sites about MODx are writing the archive now and at the end they promise to publish it in universal access. However, if the task is not particularly difficult (for example, a banal list of files with descriptions for downloads in the technical support section), then the FileDownload snippet is fine.
For starters, those who have not tried:
File Download 2.6
- link to snippet on modxcms.comDescription
Supports: MODx Evo 1.xx and below
Authors: Kyle Jaebker, Adam Strzelecki
Snippet FileDownload displays a list of files from the specified directory for users to download. It can be used in conjunction with FileDownload Plugin to ensure the generation of secure links (not pointing directly to the downloaded file), as well as to be able to count the number of downloads.
Snippet supports the template system and has a sufficient number of parameters for modification for various needs.Main features of the snippet:
• Counting the number of downloads.
• Ability to display descriptions of files from the chunk.
• Fully customizable appearance with chunks.
• Visitors can view subdirectories.
• Ability to display the file type.
• Ability to display the creation date and file size.
• Ability to delimit access to files by groups.Installation:
• Upload the filedownload folder to the snippets directory (there should be 3 files in the folder: filedownload.class.inc.php, data.db.class.inc.php and filecount.txt).
• Create a new snippet - FileDownload.
• Copy the contents of the file FileDownload2.6.php in a new snippet.
• Create chunks that you will use.
• To display a list of files, call the snippet.Call example:
A simple call, specifying the file directory:
[! FileDownload? & getFolder = `assets / snippets / filedownload`!]
A simple call indicating the directory with files and permission to use subdirectories:
[! FileDownload? & getFolder = `assets / snippets / filedownload` & browseDirectories =` 1`!]List of options "to start":& getFolderDefault:
comma separated list of directoriesDescription:
The getFolder parameter is used to determine the directories that the snippet will scan. If several directories are specified, the & browseDirectories parameter will not work. The “/” symbol is not necessary to add directories.Note:
If used with the FileDownload Plugin plugin, the directory is specified in the TV parameter FileDownloadFolder, and not in the parameters when calling the snippetExample:
assets / snippets / filedownload& browseDirectoriesDefault:
[1 | 0]Description:
This parameter allows users to browse subdirectories in the directory that you specify in & getFolder. If you use this parameter, the following sections in the template are used: parent & folder.& getFileDefault:
When filling in the parameter, the snippet will display only the specified file. In this case, the getFolder parameter is still needed and the file specified in getFile should be located in the specified directory. Thus, the parameter allows you to download and read downloads of only one specific file in a directory.Example:
This option allows you to add a description to the files. The parameter specifies the name of the chunk with the descriptions. The syntax for a chunk entry should be: directory / filename | description for the file ||Example:
Chunk name: fileDescription
assets / snippets / filedownload / test.pdf | This is a test pdf. It shows report stuff. ||
assets / snippets / filedownload / options.gif | these are the options available to you. ||
All these parameters are enough to start using the snippet. You can see the remaining parameters in the help file from the archive (in English), here
or in the archive with the FileDownload Module, about which below.
So, if you are familiar with the snippet or have tried it now, you probably noticed that editing descriptions of files is completely inconvenient, especially for people who are not dedicated (for example, secretaries). After all, it looks like a chunk like this:
Well, for simple needs, you can change this business by adding a simple module, which I called FileDownload Module.
- This is an addition that was written for more convenient adding and editing descriptions of files.Installation:
• Create a new module with the name, for example, the File Archive Description Editor.
• Copy the contents of the FileDownload Module v0.9b.php file to the module code window. Remember to remove the <? Php tags at the beginning and?> At the end of the code.
• Configure the module by changing the parameters you need in the code itself.Options:
$ downloadFolder = 'directory name, separated by comma'; - list of directories to be scanned by the module. Specify all the directories that you use when calling or various calls snippet.
$ chunkname = 'chunk name'; - the name of the chunk in which the descriptions are stored or will be stored.
$ chunkid = 'id chunk'; - id of the chunk in which the descriptions are stored or will be stored. Id chunk you can see in the Manage Items -> Chunks. In brackets, next to the name of the chunk, Id will be specified.What it looks like:
We have a new item in the module manager:
And when you click on it, from the module panel, we will see such a simple interface:
Everything, now the customer who likes to do everything by himself or through the secretary will not round his eyes when you tell him about the system for changing the descriptions of the files.
So, files to download:Module and documentationModule, documentation and snippet itself (all in one)
By the way, there is a bonus in the “all in one” archive - icons of various file extensions, which, why, were not in the original archive.
I hope the article, the translation of the snippet documentation and the module will be useful to someone)