summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael Klier <chi@chimeric.de>2007-09-09 02:38:43 +0200
committerMichael Klier <chi@chimeric.de>2007-09-09 02:38:43 +0200
commit11d9dfa5f39e8005a998d25bca1885847c2cb561 (patch)
treeb6670944b6c5a493295047a50a01e7a85e90e044 /inc
parente681fae7a45f2fb572a45421666afc3d0f86672c (diff)
downloadrpg-11d9dfa5f39e8005a998d25bca1885847c2cb561.tar.gz
rpg-11d9dfa5f39e8005a998d25bca1885847c2cb561.tar.bz2
New event MEDIA_UPLOAD_FINISH
This adds a new event MEDIA_UPLOAD_FINISH which is triggered when a media file is uploaded via the mediamanager. (The event is preventable) Event data: data[0] temporary file name (read from $_FILES) data[1] file name of the file being uploaded data[2] future directory id of the file being uploaded data[3] the mime type of the file being uploaded darcs-hash:20070909003843-23886-182d42a34f254fd8e63486210c458c34dd953b5d.gz
Diffstat (limited to 'inc')
-rw-r--r--inc/media.php73
1 files changed, 60 insertions, 13 deletions
diff --git a/inc/media.php b/inc/media.php
index 8a35840bd..491dbd8da 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -179,7 +179,19 @@ function media_delete($id,$auth){
/**
* Handles media file uploads
*
+ * This generates an action event and delegates to _media_upload_action().
+ * Action plugins are allowed to pre/postprocess the uploaded file.
+ * (The triggered event is preventable.)
+ *
+ * Event data:
+ * $data[0] fn_tmp: the temporary file name (read from $_FILES)
+ * $data[1] fn: the file name of the uploaded file
+ * $data[2] id: the future directory id of the uploaded file
+ * $data[3] imime: the mimetype of the uploaded file
+ *
+ * @triggers MEDIA_UPLOAD_FINISH
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Michael Klier <chi@chimeric.de>
* @return mixed false on error, id of the new file on success
*/
function media_upload($ns,$auth){
@@ -235,19 +247,15 @@ function media_upload($ns,$auth){
return false;
}
- // prepare directory
- io_createNamespace($id, 'media');
- if(move_uploaded_file($file['tmp_name'], $fn)) {
- // Set the correct permission here.
- // Always chmod media because they may be saved with different permissions than expected from the php umask.
- // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
- chmod($fn, $conf['fmode']);
- msg($lang['uploadsucc'],1);
- media_notify($id,$fn,$imime);
- return $id;
- }else{
- msg($lang['uploadfail'],-1);
- }
+ // prepare event data
+ $data[0] = $file['tmp_name'];
+ $data[1] = $fn;
+ $data[2] = $id;
+ $data[3] = $imime;
+
+ // trigger event
+ return trigger_event('MEDIA_UPLOAD_FINISH', $data, '_media_upload_action', true);
+
}else{
msg($lang['uploadwrong'],-1);
}
@@ -255,6 +263,45 @@ function media_upload($ns,$auth){
}
/**
+ * Callback adapter for media_upload_finish()
+ * @author Michael Klier <chi@chimeric.de>
+ */
+function _media_upload_action($data) {
+ // fixme do further sanity tests of given data?
+ if(is_array($data) && count($data)===4) {
+ return media_upload_finish($data[0], $data[1], $data[2], $data[3]);
+ } else {
+ return false; //callback error
+ }
+}
+
+/**
+ * Saves an uploaded media file
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @author Michael Klier <chi@chimeric.de>
+ */
+function media_upload_finish($fn_tmp, $fn, $id, $imime) {
+ global $conf;
+ global $lang;
+
+ // prepare directory
+ io_createNamespace($id, 'media');
+
+ if(move_uploaded_file($fn_tmp, $fn)) {
+ // Set the correct permission here.
+ // Always chmod media because they may be saved with different permissions than expected from the php umask.
+ // (Should normally chmod to $conf['fperm'] only if $conf['fperm'] is set.)
+ chmod($fn, $conf['fmode']);
+ msg($lang['uploadsucc'],1);
+ media_notify($id,$fn,$imime);
+ return $id;
+ }else{
+ msg($lang['uploadfail'],-1);
+ }
+}
+
+/**
* This function checks if the uploaded content is really what the
* mimetype says it is. We also do spam checking for text types here.
*