Attaching files to resources: FileAttach for MODx Revolution

Latest version 1.0.10-pl1 from 06.10.2017

[Russian]

May be installed with Package Manager from official MODx repository http://modx.com/extras/package/fileattach.

Allows to upload files to resources in site manager. File list is held in a table. For every file it could be set description, privacy mode (accessibility by direct link), download count, SHA1 checksum.

Custom order may be set by enabling order column in editor and dragging selected rows.

Supports MySQL and SQLSrv DB schemes.

Support download range, download continuation, paginated output.

Minimal version PHP v5.3.

Component development is here: https://github.com/13hakta/FileAttach

Screenshots

Editor in admin mode

File list in manager

Media source tree

File editor

File editor in admin mode

File list in frontend

Upload dialog window

Chunk FileAttachTpl

Allows to customize view of file item output.

Name Description
name File name. When private=false internal_name equal to name
internal_name  Internal name. File name in file system
hash  SHA1 checksum
description  Description
docid Resource ID, where file uploaded
ext File extension, lowercased
id File ID
path Path in media source
private Privacy flag
download Download count
size File size in bytes
rank Order in file list. May be used for custom sorting

Initial chunk content:

<p>[{+description:notempty=`<strong>[[+description]]</strong><br/>`]]
<a href="[[+url]]">[[+name]]</a> <span class="badge">[[+download]]</span>
[{+size:notempty=`<br/><small>Size: [[+size]] bytes</small>`]]
[{+hash:notempty=`<br/><small>SHA1: [[+hash]]</small>`]]</p>

Snippet FileAttach

Outputs file list.

Name Description Default value
&limit The number of files to limit per page. Show all items if not set 0
&totalVar Name of placeholder to output count of rows total
&offset Offset in output 0
&makeURL Generate URL for file download false
&outputSeparator A string to separate each row with.  
&privateUrl Force private url. Allows to count downloads even with open files false
&resource Show files for resource id 0
&showExt Extract file extension false
&showSize Retrieve file size false
&sortBy The field to sort by. name
&sortDir The direction to sort by. ASC
&toPlaceholder If set, will output the content to the placeholder specified in this property, rather than outputting the content directly. false
&tpl The chunk to use for each row of files. FileAttachTpl
&groups Limit file list displaying to user groups. Delemitter is comma.  

Class FileItem

Methods:

Name Description Arguments
getPath Get file path relatively to media source root  
getFullPath Get full file path  
getUrl Get file link  
generateName Generate new filename length (int) = 32
sanitizeName Filter unacceptable symbol combination in file name name (str)
rename Rename file name (str)
setPrivate Set privacy mode private (bool)
getSize Get file size  

System options

Name Description Default value
calchash  Calculate file hash at upload false
files_path Path relative to media source root   
mediasource Media source ID  1
private Make file private at upload false
put_docid Upload file in subfolder <ResourceID> / false
templates List of templates to activate module   
user_folders Upload file in subfolder <UserID> /  false

Access policies

Permissions list

Name Description
fileattach.doclist Manage files in resource
fileattach.totallist  Manage all files
fileattach.download  Permission to download files
fileattach.remove Permission to delete files in frontend
fileattach.list Listing files in frontend

To allow user file upload you should enable access:

  • Permission "create" in media source
  • Permission "file_upload" from AdminTemplate

In frontend by default allowed to remove own files corresponding to resource. For ability to remove not only owned files you should enable permission "fileattach.totallist".

During installation set of policies are created:

Title Description
File Attach Full access
File Attach Download Only download
File Attach Frontend Allows to use processors to manage files in frontend

Usage example

In simple case just call snippet:

[[FileAttach]]

To force download count it's needed to open files through private link:

[[FileAttach? &amp;privateUrl=`1`]]

Custom sorting:

[[FileAttach? &amp;sortBy=`rank`]]

Example for frontend file managing

Look in attach.

Прикрепленные файлы

faupm-1071.zip 2004
Size: 9240 bytes
SHA1: 2b58a4317c5f2f8608f520c36cd21f71b3ecd7f4


Метки: filemodxразработка

Просмотров: 1333
Автор: Admin
Опубликовано: 06.02.2015