function upload($method)
 {
     $zoom =& zmgFactory::getEvents()->fire('ongetcore');
     zmgimport('org.zoomfactory.lib.helpers.zmgFileHelper');
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     if ($method == "jupload") {
         echo "JUpload!!!";
     } else {
         $file = zmgGetParam($_FILES, 'Filedata');
         $filename = $zoom->checkDuplicate(zmgFileHelper::makeSafe(urldecode($file['name'])));
         $ext = zmgFileHelper::getExt($filename);
         $mime = zmgMimeHelper::getMime($file['tmp_name'], $file['type'], $ext);
         if (zmgFileHelper::tooBig($file['tmp_name'])) {
             header('HTTP/1.0 415 Unsupported Media Type');
             die('Error. File too big!');
         }
         if (!zmgMimeHelper::acceptableFormat($mime, true)) {
             header('HTTP/1.0 415 Unsupported Media Type');
             die('Error. Unsupported Media Type!');
         }
         //try to move the file to a proper location:
         $dest = ZMG_ABS_PATH . DS . "etc" . DS . "cache" . DS . $filename;
         if (zmgFileHelper::exists($dest)) {
             header('HTTP/1.0 409 Conflict');
             die('Error. File already exists');
         }
         if (!zmgFileHelper::upload($file['tmp_name'], $dest)) {
             header('HTTP/1.0 400 Bad Request');
             die('Error. Unable to upload file');
         }
         // store the filename into the session (the data is sent to the backend
         // after the file has been uploaded).
         $session =& zmgFactory::getSession();
         $session->update('uploadtool.fancyfiles', $filename, ZMG_DATATYPE_ARRAY);
         $session->store();
     }
 }
 function processMedium(&$medium, &$gallery)
 {
     $mime = $medium->getMimeType();
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     $ok = true;
     if (zmgMimeHelper::isImage($mime, true)) {
         zmgimport('org.zoomfactory.var.plugins.toolbox.tools.imageTool');
         $ok = zmgImageTool::process($medium, $gallery);
         if (!$ok) {
             zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Could not create thumbnail of image file'));
             //TODO: cleanup
         }
     } else {
         if (zmgMimeHelper::isDocument($mime, true) && zmgMimeHelper::isIndexable($mime, true)) {
             zmgimport('org.zoomfactory.var.plugins.toolbox.tools.documentTool');
             $ok = zmgDocumentTool::process($medium, $gallery);
             if (!$ok) {
                 zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Could not index document'));
                 //TODO: cleanup
             }
         } else {
             if (zmgMimeHelper::isVideo($mime, true) && zmgMimeHelper::isThumbnailable($mime, true)) {
                 zmgimport('org.zoomfactory.var.plugins.toolbox.tools.videoTool');
                 $ok = zmgVideoTool::process($medium, $gallery);
                 if (!$ok) {
                     zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Could not create thumbnail of video file'));
                     //TODO: cleanup
                 }
             } else {
                 if (zmgMimeHelper::isAudio($mime, true)) {
                     zmgimport('org.zoomfactory.var.plugins.toolbox.tools.audioTool');
                     $ok = zmgAudioTool::process($medium, $gallery);
                     if (!$ok) {
                         zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Audio file not supported'));
                         //TODO: cleanup
                     }
                 } else {
                     zmgToolboxPlugin::registerError(T_('Upload medium'), T_('Unsupported medium type.'));
                 }
             }
         }
     }
     return $ok;
 }
 /**
  * Check if a file is indexable by the zOOm toolbox.
  * 
  * @return boolean
  * @param string $tag
  * @param int $isMime
  */
 function isIndexable($tag, $isMime = false)
 {
     if ($isMime) {
         $tag = zmgMimeHelper::convertMimeToExtension($tag);
     }
     return in_array($tag, zmgMimeHelper::_indexableList());
 }
 function toJSON()
 {
     $json =& zmgFactory::getJSON();
     $out = "'metadata': {\n          'mid': " . $this->_mid;
     if ($this->_raw === null || empty($this->_raw)) {
         return $out . ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
     }
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     if (zmgMimeHelper::isImage($this->_ext)) {
         //TODO
         //print_r($this->_raw);
         if (empty($this->_raw['title'])) {
             $out .= ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
         } else {
             $out .= ",\n                  'title' : " . $json->encode($this->_raw['title']);
             if (is_array($this->_raw['IFD'])) {
                 $out .= ",";
                 foreach ($this->_raw['IFD'] as $name => $exif_val) {
                     $out .= $this->interpretJpegMeta($name, $exif_val);
                 }
                 $out = substr($out, 0, -1);
             }
             $out .= "}";
         }
     } else {
         if (zmgMimeHelper::isAudio($this->_ext)) {
             list($artist, $title, $album, $year, $length, $data) = $this->interpretId3($this->_raw);
             $out .= ",\n              'title' : " . $json->encode($title) . "," . $json->encode(T_('Artist')) . ": " . $json->encode($artist) . "," . $json->encode(T_('Song')) . ": " . $json->encode($title) . "," . $json->encode(T_('Album')) . ": " . $json->encode($album) . "," . $json->encode(T_('Year')) . ": " . $json->encode($year) . "," . $json->encode(T_('Length')) . ": " . $json->encode($length) . "," . $json->encode(T_('Data')) . ": " . $json->encode($data) . "}";
         } else {
             if (zmgMimeHelper::isVideo($this->_ext)) {
                 //TODO
                 $out .= ",'title': " . $json->encode(T_('No Metadata available.')) . "}";
             }
         }
     }
     return $out;
 }
 /**
  * Autodetect a file's MIME-type
  *
  * This function may be called staticly.
  *
  * @param  string $file        Path to the file to get the type of
  * @param  string $custom_mime An optional custom 'default' value, mostly used for the filetype sent by the users' browser
  * @param  bool   $params      Append MIME parameters if true
  * @return string $file's      MIME-type on success, false boolean otherwise
  * @since 1.0.0beta1
  * @static
  */
 function autoDetect($file, $custom_mime = null, $custom_ext = null, $params = false)
 {
     zmgimport('org.zoomfactory.lib.mime.zmgMimeHelper');
     $type = false;
     if (function_exists('finfo_open')) {
         // We have fileinfo
         $finfo = finfo_open(FILEINFO_MIME);
         $type = finfo_file($finfo, $file);
         finfo_close($finfo);
     } elseif (function_exists('mime_content_type')) {
         $type = mime_content_type($file);
         if (empty($type) && !empty($custom_ext)) {
             $type = zmgMimeHelper::convertExtensionToMime($custom_ext);
         }
     } elseif (!empty($custom_mime)) {
         $type = $custom_mime;
     } else {
         $type = zmgMime::_fileAutoDetect($file);
     }
     // _fileAutoDetect() may have returned an error.
     if ($type === false) {
         return $type;
     }
     if ($type == "application/octet-stream" || $type == "application/unknown") {
         if (!empty($custom_mime)) {
             $type = $custom_mime;
         } elseif (!empty($custom_ext)) {
             $type = zmgMimeHelper::convertExtensionToMime($custom_ext);
         }
     }
     if (!zmgMimeHelper::convertMimeToExtension($type)) {
         $type = zmgMimeHelper::convertExtensionToMime($custom_mime);
     }
     // flv (Flash Video format) files need exceptional handling (for now I'll provide a fictional mimetype)
     if ($custom_ext == "flv") {
         $type = "video/x-flv";
     }
     // Don't return an empty string
     if (!$type || !strlen($type)) {
         return zmgError::throwError("Sorry, couldn't determine file type.");
     }
     // Strip parameters if present & requested
     if (zmgMime::hasParameters($type) && !$params) {
         $type = zmgMime::stripParameters($type);
     }
     return $type;
 }