Integration on client-side is possible through JavaScript function cs.file_upload()
cs.file_upload(button, success, error, progress, multi, drop_element)
$('<button></button>')
that may be clickedfiles
with array of absolute urls of all uploaded fileserror, jqXHR, file
with error text, jqXHR object and file object being uploadedpercent, size, uploaded_size, name, total_percent, total_size, total_uploaded, current_file, total_files
current progress in percents, total file size, size of uploaded part, file name, total percents, size and uploaded size (useful when multiple files being uploaded) and currently uploading file number and total number of files to be uploaded.true
- selection of several files will be possiblebutton
assumedExample (TinyMCE plugin):
var uploader_callback; var uploader = cs.file_upload ? cs.file_upload( null, function (files) { tinymce.uploader_dialog.close(); if (files.length) { uploader_callback(files[0]); } uploader_callback = undefined; }, function (error) { tinymce.uploader_dialog.close(); alert(error); }, function (file) { if (!tinymce.uploader_dialog) { var progress = document.createElement('progress', 'cs-progress'); tinymce.uploader_dialog = cs.ui.modal(progress); tinymce.uploader_dialog.progress = progress; tinymce.uploader_dialog.style.zIndex = 100000; tinymce.uploader_dialog.open(); } tinymce.uploader_dialog.progress.value = file.percent || 1; } ) : false;
cs.file_upload
call will return object with 2 methods:
button
or drop_element
elementsOn server side any module should confirm files uploading by adding tag to uploaded file (and should delete tag, when file is not used any more).
Confirmation is realized with 2 triggers, that third-party components may run. Also, any uploaded file may have several triggers
[ 'url' => $url, //Required 'tag' => $tag //Required ]
Example (Blogs module):
preg_match_all('/"(http[s]?:\/\/.*)"/Uims', $data['content'], $old_files); preg_match_all('/"(http[s]?:\/\/.*)"/Uims', $content, $new_files); $old_files = isset($old_files[1]) ? $old_files[1] : []; $new_files = isset($new_files[1]) ? $new_files[1] : []; if ($old_files || $new_files) { foreach (array_diff($old_files, $new_files) as $file) { \cs\Event::instance()->fire( 'System/upload_files/del_tag', [ 'tag' => "Blogs/posts/$id/$L->clang", 'url' => $file ] ); } unset($file); foreach (array_diff($new_files, $old_files) as $file) { \cs\Event::instance()->fire( 'System/upload_files/add_tag', [ 'tag' => "Blogs/posts/$id/$L->clang", 'url' => $file ] ); } unset($file); } unset($old_files, $new_files);
This code compares previous version of post and current for links, removes old files, and adds new ones.
Links that doesn't corresponds to any existed files will be ignored automatically.
[ 'url' => url, //Optional 'tag' => tag //Optional ]
Example (Blogs module):
\cs\Event::instance()->fire( 'System/upload_files/del_tag', [ 'tag' => "Blogs/posts/$id%" ] );
This code deletes all links, associated with post on any language.