예제 #1
0
 public function testGetException()
 {
     $this->setExpectedException('MW_Media_Exception');
     MW_Media_Factory::get(null);
 }
예제 #2
0
 public function uploadItem(stdClass $params)
 {
     $this->_checkParams($params, array('site', 'domain'));
     $this->_setLocale($params->site);
     if (($fileinfo = reset($_FILES)) === false) {
         throw new Controller_ExtJS_Exception('No file was uploaded');
     }
     $config = $this->_getContext()->getConfig();
     /** controller/extjs/media/default/options
      * Options used for processing the uploaded media files
      *
      * When uploading a file, a preview image for that file is generated if
      * possible (especially for images). You can configure certain options
      * for the generated images, namely the quality of those images with
      *
      *  array(
      *  	'image' => array(
      *  		'jpeg' => array(
      *  			'quality' => 75
      *  		),
      *  		'png' => array(
      *  			'quality' => 9
      *  		),
      *  	)
      *  )
      *
      * @param array Multi-dimendional list of configuration options
      * @since 2014.03
      * @category Developer
      * @category User
      */
     $options = $config->get('controller/extjs/media/default/options', array());
     /** controller/extjs/media/default/enablecheck
      * Enables checking uploaded files if they are valid and not part of an attack
      *
      * This configuration option is for unit testing only! Please don't disable
      * the checks for uploaded files in production environments as this
      * would give attackers the possibility to infiltrate your installation!
      *
      * @param boolean True to enable, false to disable
      * @since 2014.03
      * @category Developer
      */
     if ($config->get('controller/extjs/media/default/enablecheck', true)) {
         $this->_checkFileUpload($fileinfo['tmp_name'], $fileinfo['error']);
     }
     $filename = md5($fileinfo['name'] . microtime(true));
     $mediaFile = MW_Media_Factory::get($fileinfo['tmp_name'], $options);
     $item = $this->_getManager()->createItem();
     $item->setDomain($params->domain);
     $item->setLabel(basename($fileinfo['name']));
     $item->setMimeType($mediaFile->getMimetype());
     if ($mediaFile instanceof MW_Media_Image_Interface) {
         $item->setPreview($this->_createImage($mediaFile, 'preview', $params->domain, $fileinfo['tmp_name'], $filename));
         $item->setUrl($this->_createImage($mediaFile, 'files', $params->domain, $fileinfo['tmp_name'], $filename));
     } else {
         $item->setPreview($this->_getMimeIcon($mediaFile->getMimetype()));
         $item->setUrl($this->_copyFile($mediaFile, $params->domain, $filename));
     }
     if (unlink($fileinfo['tmp_name']) === false) {
         $msg = sprintf('Deleting file "%1$s" failed', $fileinfo['tmp_name']);
         $this->_getContext()->getLogger()->log($msg, MW_Logger_Abstract::WARN);
     }
     return (object) $item->toArray();
 }