Beispiel #1
0
 function convert(&$Medium, $mimeType)
 {
     if (Medium::name(null, $mimeType) === 'Image') {
         $randomFrame = rand(1, $Medium->objects['ffmpeg_movie']->getFrameCount() - 1);
         $resource = $Medium->objects['ffmpeg_movie']->getFrame($randomFrame)->toGDImage();
         if (!is_resource($resource)) {
             return false;
         }
         $Image = Medium::factory(array('gd' => $resource), 'image/gd');
         return $Image->convert($mimeType);
     }
     return false;
 }
Beispiel #2
0
 function convert(&$Medium, $mimeType)
 {
     if (!isset($this->_formatMap[$mimeType])) {
         return false;
     }
     $Medium->mimeType = $mimeType;
     if ($Medium->name === 'Document') {
         // application/pdf -> image
         $this->store($Medium, $Medium->files['temporary']);
         /* Unset files to prevent too early deletion by $Medium */
         $temporary = $Medium->files['temporary'];
         unset($Medium->files);
         return Medium::factory(array('temporary' => $temporary), $mimeType);
     }
     return true;
 }
 function convert($Medium, $mimeType)
 {
     if (!isset($this->_formatMap[$mimeType])) {
         return false;
     }
     try {
         $Medium->objects['Imagick']->setFormat($this->_formatMap[$mimeType]);
     } catch (Exception $E) {
         return false;
     }
     $Medium->mimeType = $mimeType;
     if ($Medium->name === 'Document') {
         // application/pdf -> image
         return Medium::factory($Medium->objects['Imagick'], $mimeType);
     }
     return true;
 }
Beispiel #4
0
 /**
  * "makes" a file
  *
  * @param string $file Absolute path to a file
  * @access protected
  * @return boolean
  */
 function _make($file)
 {
     $File = new File($file);
     $name = Medium::name($file);
     $subdir = array_pop(explode(DS, dirname($this->source)));
     if ($name === 'Icon' || strpos($file, 'ico' . DS) !== false) {
         return true;
     }
     if ($this->version) {
         $configString = 'Media.filter.' . strtolower($name) . '.' . $this->version;
         $filter = array(Configure::read($configString));
     } else {
         $configString = 'Media.filter.' . strtolower($name);
         $filter = Configure::read($configString);
     }
     foreach ($filter as $version => $instructions) {
         $directory = Folder::slashTerm(rtrim($this->destination . $version . DS . $subdir, '.'));
         $Folder = new Folder($directory, $this->_createDirectories);
         if (!$Folder->pwd()) {
             $this->err($directory . ' could not be created or is not writable.');
             $this->err('Please check your permissions.');
             return false;
         }
         $Medium = Medium::make($File->pwd(), $instructions);
         if (!$Medium) {
             $this->err('Failed to make version ' . $version . ' of medium.');
             return false;
         }
         $Medium->store($Folder->pwd() . $File->name, $this->overwrite);
     }
     return true;
 }
Beispiel #5
0
 /**
  * Triggered by `beforeValidate`, `beforeSave` or upon user request
  *
  * Prepares runtime for being used by `perform()`
  *
  * @param Model $Model
  * @param string $file Optionally provide a valid transfer resource to be used as source
  * @return mixed true if transfer is ready to be performed, false on error, null if no data was found
  */
 function prepare(&$Model, $file = null)
 {
     if (isset($Model->data[$Model->alias]['file'])) {
         $file = $Model->data[$Model->alias]['file'];
     }
     if (empty($file)) {
         return null;
     }
     if ($this->runtime[$Model->alias]['hasPerformed']) {
         $this->reset($Model);
     }
     if ($this->runtime[$Model->alias]['isReady']) {
         return true;
     }
     /* Extraction must happen after reset */
     extract($this->settings[$Model->alias], EXTR_SKIP);
     extract($this->runtime[$Model->alias], EXTR_SKIP);
     if (TransferValidation::blank($file)) {
         /* Set explicitly null enabling allowEmpty in rules act upon emptiness */
         return $Model->data[$Model->alias]['file'] = null;
     }
     if ($source = $this->_source($Model, $file)) {
         $this->runtime[$Model->alias]['source'] = $source;
     } else {
         return false;
     }
     /* Temporary is optional and can fail */
     if ($source['type'] !== 'file-local') {
         $temporary = $this->runtime[$Model->alias]['temporary'] = $this->_temporary($Model, $file);
     }
     $this->_addMarker($Model, 'DS', DS);
     $this->_addMarker($Model, 'uuid', String::uuid());
     $this->_addMarker($Model, 'unixTimestamp', time());
     $this->_addMarker($Model, 'year', date('Y'));
     $this->_addMarker($Model, 'month', date('m'));
     $this->_addMarker($Model, 'day', date('d'));
     $filename = $this->_addMarker($Model, 'Source.filename', $source['filename'], true);
     $extension = $this->_addMarker($Model, 'Source.extension', $source['extension'], true);
     $this->_addMarker($Model, 'Source.basename', empty($extension) ? $filename : $filename . '.' . $extension);
     $this->_addMarker($Model, 'Source.mimeType', $source['mimeType'], true);
     $this->_addMarker($Model, 'Source.type', $source['type']);
     $this->_addMarker($Model, 'Medium.name', strtolower(Medium::name($source['file'], $source['mimeType'])));
     $this->_addMarker($Model, 'Medium.short', Medium::short($source['file'], $source['mimeType']));
     /* Needed for tableless Models */
     if (isset($Model->data[$Model->alias])) {
         $this->_addMarker($Model, $Model->alias . '.', $Model->data[$Model->alias], true);
         $this->_addMarker($Model, 'Model.', $Model->data[$Model->alias], true);
     }
     $this->_addMarker($Model, 'Model.name', $Model->name);
     $this->_addMarker($Model, 'Model.alias', $Model->alias);
     if (!($destinationFile = $this->_replaceMarker($Model, $destinationFile))) {
         return false;
     }
     if ($destination = $this->_destination($Model, $baseDirectory . $destinationFile)) {
         $this->runtime[$Model->alias]['destination'] = $destination;
     } else {
         return false;
     }
     if ($source == $destination || $temporary == $destination) {
         return false;
     }
     $Folder = new Folder($destination['dirname'], $createDirectory);
     if (!$Folder->pwd()) {
         $message = "TransferBehavior::prepare - Directory `{$destination['dirname']}` could ";
         $message .= "not be created or is not writable. Please check the permissions.";
         trigger_error($message, E_USER_WARNING);
         return false;
     }
     return $this->runtime[$Model->alias]['isReady'] = true;
 }
<?php

// we now in presentation layer
// we will include business layer to load business logic
include 'model/movie.php';
include 'model/medium.php';
// init Movie Model from Business Logic
$movie = new Movie();
$medium = new Medium();
// insert new Movie if post data exists
if (isset($_POST["name"]) && $_POST["email"]) {
    $movie->createMovie($_POST["name"], $_POST["year"], $_POST["language"], $_POST["medium"], $_POST["email"]);
}
// now load all Mediums
$data = $medium->getAllMediums();
// now we can clearly output the requested data
?>


 <form method="post" >
   <h1>Neuen Film erstellen:</h1>
   <table id="newmovie">
   		<tr>
   			<td>
   				Name:
   			</td>
   			<td>
   				<input type="text" name="name" placeholder="Mein Film Titel" />
   			</td>
   		</tr>
   		<tr>
 /**
  * Initializes directory structure
  *
  * @access public
  * @return void
  */
 function init()
 {
     $message = 'Do you want to create missing media directories now?';
     if ($this->in($message, 'y,n', 'n') == 'n') {
         return false;
     }
     $dirs = array(MEDIA => array(), MEDIA_STATIC => Medium::short(), MEDIA_TRANSFER => Medium::short(), MEDIA_FILTER => array());
     foreach ($dirs as $dir => $subDirs) {
         if (is_dir($dir)) {
             $result = 'SKIP';
         } else {
             new Folder($dir, true);
             if (is_dir($dir)) {
                 $result = 'OK';
             } else {
                 $result = 'FAIL';
             }
         }
         $this->out(sprintf('%-50s [%-4s]', $this->shortPath($dir), $result));
         foreach ($subDirs as $subDir) {
             if (is_dir($dir . $subDir)) {
                 $result = 'SKIP';
             } else {
                 new Folder($dir . $subDir, true);
                 if (is_dir($dir . $subDir)) {
                     $result = 'OK';
                 } else {
                     $result = 'FAIL';
                 }
             }
             $this->out(sprintf('%-50s [%-4s]', $this->shortPath($dir . $subDir), $result));
         }
     }
     $this->out();
     $this->protect();
     $this->out('Remember to set the correct permissions on transfer and filter directory.');
 }
Beispiel #8
0
 /**
  * Reset medium.
  *
  * @return $this
  */
 public function reset()
 {
     parent::reset();
     $this->attributes['controls'] = true;
     return $this;
 }
Beispiel #9
0
 /**
  * Resolves partial path
  *
  * Examples:
  * 	css/cake.generic         >>> MEDIA_STATIC/css/cake.generic.css
  *  transfer/img/image.jpg   >>> MEDIA_TRANSFER/img/image.jpg
  * 	s/img/image.jpg          >>> MEDIA_FILTER/s/static/img/image.jpg
  *
  * @param string|array $path Either a string or an array with dirname and basename keys
  * @return string|boolean False on error or if path couldn't be resolbed otherwise
  * 							an absolute path to the file
  */
 function file($path)
 {
     $path = array();
     foreach (func_get_args() as $arg) {
         if (is_array($arg)) {
             if (isset($arg['dirname'])) {
                 $path[] = rtrim($arg['dirname'], '/\\');
             }
             if (isset($arg['basename'])) {
                 $path[] = $arg['basename'];
             }
         } else {
             $path[] = rtrim($arg, '/\\');
         }
     }
     $path = implode(DS, $path);
     $path = str_replace(array('/', '\\'), DS, $path);
     if (isset($this->__cached[$path])) {
         return $this->__cached[$path];
     }
     if (Folder::isAbsolute($path)) {
         return file_exists($path) ? $path : false;
     }
     $parts = explode(DS, $path);
     if (in_array($parts[0], $this->_versions)) {
         array_unshift($parts, basename(key($this->_map['filter'])));
     }
     if (!in_array($parts[0], array_keys($this->_directories))) {
         array_unshift($parts, basename(key($this->_map['static'])));
     }
     if (in_array($parts[1], $this->_versions) && !in_array($parts[2], array_keys($this->_directories))) {
         array_splice($parts, 2, 0, basename(key($this->_map['static'])));
     }
     $path = implode(DS, $parts);
     if (isset($this->__cached[$path])) {
         return $this->__cached[$path];
     }
     $file = $this->_directories[array_shift($parts)] . implode(DS, $parts);
     if (file_exists($file)) {
         return $this->__cached[$path] = $file;
     }
     $short = current(array_intersect(Medium::short(), $parts));
     if (!$short) {
         $message = "MediumHelper::file - ";
         $message .= "You've provided a partial path without a medium directory (e.g. img) ";
         $message .= "which is required to resolve the path.";
         trigger_error($message, E_USER_NOTICE);
         return false;
     }
     $extension = null;
     extract(pathinfo($file), EXTR_OVERWRITE);
     if (!isset($filename)) {
         /* PHP < 5.2.0 */
         $filename = substr($basename, 0, isset($extension) ? -(strlen($extension) + 1) : 0);
     }
     for ($i = 0; $i < 2; $i++) {
         $file = $i ? $dirname . DS . $filename : $dirname . DS . $basename;
         foreach ($this->_extensions[$short] as $extension) {
             $try = $file . '.' . $extension;
             if (file_exists($try)) {
                 return $this->__cached[$path] = $try;
             }
         }
     }
     return false;
 }
Beispiel #10
0
 /**
  * Construct.
  * @param array  $attributes
  * @param Medium $medium
  */
 public function __construct(array $attributes, Medium $medium)
 {
     $this->attributes = $attributes;
     $this->source = $medium->reset()->thumbnail('auto')->display('thumbnail');
     $this->source->linked = true;
 }
 /**
  * Retrieve (cached) metadata of a file
  *
  * @param Model $Model
  * @param string $file Path to a file relative to `baseDirectory` or an absolute path to a file
  * @param integer $level level of amount of info to add, `0` disable, `1` for basic, `2` for detailed info
  * @return mixed Array with results or false if file is not readable
  */
 function metadata(&$Model, $file, $level = 1)
 {
     if ($level < 1) {
         return array();
     }
     extract($this->settings[$Model->alias]);
     list($file, ) = $this->_file($Model, $file);
     $File = new File($file);
     if (!$File->readable()) {
         return false;
     }
     $checksum = $File->md5(true);
     if (isset($this->__cached[$Model->alias][$checksum])) {
         $data = $this->__cached[$Model->alias][$checksum];
     }
     if ($level > 0 && !isset($data[1])) {
         $data[1] = array('size' => $File->size(), 'mime_type' => MimeType::guessType($File->pwd()), 'checksum' => $checksum);
     }
     if ($level > 1 && !isset($data[2])) {
         $Medium = Medium::factory($File->pwd());
         if ($Medium->name === 'Audio') {
             $data[2] = array('artist' => $Medium->artist(), 'album' => $Medium->album(), 'title' => $Medium->title(), 'track' => $Medium->track(), 'year' => $Medium->year(), 'length' => $Medium->duration(), 'quality' => $Medium->quality(), 'sampling_rate' => $Medium->samplingRate(), 'bit_rate' => $Medium->bitRate());
         } elseif ($Medium->name === 'Image') {
             $data[2] = array('width' => $Medium->width(), 'height' => $Medium->height(), 'ratio' => $Medium->ratio(), 'quality' => $Medium->quality(), 'megapixel' => $Medium->megapixel());
         } elseif ($Medium->name === 'Text') {
             $data[2] = array('characters' => $Medium->characters(), 'syllables' => $Medium->syllables(), 'sentences' => $Medium->sentences(), 'words' => $Medium->words(), 'flesch_score' => $Medium->fleschScore(), 'lexical_density' => $Medium->lexicalDensity());
         } elseif ($Medium->name === 'Video') {
             $data[2] = array('title' => $Medium->title(), 'year' => $Medium->year(), 'length' => $Medium->duration(), 'width' => $Medium->width(), 'height' => $Medium->height(), 'ratio' => $Medium->ratio(), 'quality' => $Medium->quality(), 'bit_rate' => $Medium->bitRate());
         } else {
             $data[2] = array();
         }
     }
     for ($i = $level, $result = array(); $i > 0; $i--) {
         $result = array_merge($result, $data[$i]);
     }
     $this->__cached[$Model->alias][$checksum] = $data;
     return Set::filter($result);
 }
 function convert($Medium, $mimeType)
 {
     if (Medium::name(null, $mimeType) === 'Image') {
         $coverArt = $this->__coverArt($Medium);
         if (!$coverArt) {
             return false;
         }
         $resource = @imagecreatefromstring($coverArt);
         if (!is_resource($resource)) {
             return false;
         }
         $Image = Medium::factory(array('gd' => $resource), 'image/gd');
         return $Image->convert($mimeType);
     }
     return false;
 }
 public function getParsedTag($match, $maxwidth = 0, $maxheight = 0)
 {
     global $DIR_MEDIA, $member;
     list($code, $tag, $path, $width, $height, $alt) = $match;
     if (!preg_match("#^.+?/.+\$#", $path) && self::$authorid) {
         $path = self::$authorid . '/' . $path;
     }
     if (FALSE === ($medium = new Medium($DIR_MEDIA, $path, MediaUtils::$prefix))) {
         return $this->t('NP_Thumbnail: 指定したメディアファイルを読み込めませんでした。', array($path));
     }
     if (!array_key_exists($medium->mime, MediaUtils::$image_mime)) {
         return $this->t(_NP_THUMBNAIL_12, array($path));
     }
     if ($tag == 'Thumbnail') {
         $maxwidth = (int) $width;
         $maxheight = (int) $height;
     }
     if ($maxwidth == 0 && $maxheight == 0) {
         $maxwidth = (int) $this->getOption('maxwidth');
         $maxheight = (int) $this->getOption('maxheight');
     }
     if ($maxwidth < 0 || $maxwidth > 1000 || $maxheight < 0 || $maxheight > 1000) {
         return $this->t(_NP_THUMBNAIL_10, array($path));
     }
     if (FALSE === $medium->setResampledSize($maxwidth, $maxheight)) {
         return $this->t('NP_Thumbnail: サムネイルのサイズが不正です。', array($path));
     }
     if (!$alt) {
         $alt =& $path;
     }
     return $this->generateTag($this->getBlogOption(MediaUtils::$blogid, 'thumb_template'), $medium, $alt);
 }
 function testMake()
 {
     $instructions = array('convert' => 'image/png', 'zoomCrop' => array(10, 10));
     $Medium = Medium::make($this->TestData->getFile('image-jpg.jpg'), $instructions);
     $this->assertIsA($Medium, 'Medium');
 }
Beispiel #15
0
 /**
  * (Interactively) maps source files to destinations
  *
  * @param string $path Path to search for source files
  * @access protected
  * @return array
  */
 function _map($path)
 {
     $include = '.*[\\/\\].*\\.[a-z0-9]{2,3}$';
     $directories = array('.htaccess', '.DS_Store', 'media', '.git', '.svn', 'simpletest', 'empty');
     $extensions = array('db', 'htm', 'html', 'txt', 'php', 'ctp');
     $exclude = '.*[/\\\\](' . implode('|', $directories) . ').*$';
     $exclude .= '|.*[/\\\\].*\\.(' . implode('|', $extensions) . ')$';
     if (!empty($this->_exclude)) {
         $exclude = '|.*[/\\\\](' . implode('|', $this->_exclude) . ').*$';
     }
     $Folder = new Folder($path);
     $files = $Folder->findRecursive($include);
     foreach ($files as $file) {
         if (preg_match('#' . $exclude . '#', $file)) {
             continue;
         }
         $search[] = '/' . preg_quote($Folder->pwd(), '/') . '/';
         $search[] = '/(' . implode('|', Medium::short()) . ')' . preg_quote(DS, '/') . '/';
         $fragment = preg_replace($search, null, $file);
         $mapped = array($file => MEDIA_STATIC . Medium::short($file) . DS . $fragment);
         while (in_array(current($mapped), $this->_map) && $mapped) {
             $mapped = $this->_handleCollision($mapped);
         }
         while (file_exists(current($mapped)) && $mapped) {
             $this->out($this->shortPath(current($mapped)) . ' already exists.');
             $answer = $this->in('Would you like to [r]ename or [s]kip?', 'r,s', 's');
             if ($answer == 's') {
                 $mapped = array();
             } else {
                 $mapped = array(key($mapped) => $this->_rename(current($mapped)));
             }
         }
         if ($mapped) {
             $this->_map[key($mapped)] = current($mapped);
         }
     }
 }
Beispiel #16
0
 /**
  * Automatically processes a file and returns a Medium instance
  *
  * Possible values for $instructions:
  * 	array('name of method', 'name of other method')
  *  array('name of method' => array('arg1', 'arg2'))
  *
  * @param string $file Absolute path to a file
  * @param array $instructions See description above
  * @return object
  */
 static function make($file, $instructions = array())
 {
     $Medium = Medium::factory($file);
     foreach ($instructions as $key => $value) {
         if (is_int($key)) {
             $method = $value;
             $args = null;
         } else {
             $method = $key;
             if (is_array($value)) {
                 $args = $value;
             } else {
                 $args = array($value);
             }
         }
         if (!method_exists($Medium, $method)) {
             $message = "Medium::make - Invalid instruction ";
             $message .= "`" . get_class($Medium) . "::{$method}()`.";
             trigger_error($message, E_USER_WARNING);
             return false;
         }
         $result = call_user_func_array(array($Medium, $method), $args);
         if ($result === false) {
             $message = "Medium::make - Instruction ";
             $message .= "`" . get_class($Medium) . "::{$method}()` failed.";
             trigger_error($message, E_USER_WARNING);
             return false;
         } elseif (is_a($result, 'Medium')) {
             $Medium = $result;
         }
     }
     return $Medium;
 }