diff options
Diffstat (limited to 'modules/gallery/models/item.php')
| -rw-r--r-- | modules/gallery/models/item.php | 69 | 
1 files changed, 54 insertions, 15 deletions
| diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 931da382..8f127532 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -663,31 +663,70 @@ class Item_Model_Core extends ORM_MPTT {    }    /** -   * Return a flowplayer <script> tag for movies +   * Return a view for movies.  By default this is a Flowplayer v3 <script> tag, but  +   * movie_img events can override this and provide their own player/view.  If no player/view +   * is found and the movie is unsupported by Flowplayer v3, this returns a simple download link.     * @param array $extra_attrs     * @return string     */    public function movie_img($extra_attrs) { -    $v = new View("movieplayer.html");      $max_size = module::get_var("gallery", "resize_size", 640);      $width = $this->width;      $height = $this->height; -    if ($width > $max_size || $height > $max_size) { -      if ($width > $height) { -        $height = (int)($height * $max_size / $width); -        $width = $max_size; +    if ($width == 0 || $height == 0) { +      // Not set correctly, likely because ffmpeg isn't available.  Making the window 0x0 causes the +      // video to be effectively unviewable.  So, let's guess: set width to max_size and guess a  +      // height (using 4:3 aspect ratio).  Once the video metadata is loaded, js in  +      // movieplayer.html.php will correct these values. +      $width = $max_size; +      $height = ceil($width * 3/4); +    }  +    $attrs = array_merge(array("id" => "g-item-id-{$this->id}"), $extra_attrs, +                         array("class" => "g-movie")); + +    // Run movie_img events, which can either: +    //  - generate a view, which is used in place of the standard Flowplayer v3 player +    //    (use view variable) +    //  - alter the arguments sent to the standard player +    //    (use fp_params and fp_config variables) +    $movie_img = new stdClass(); +    $movie_img->max_size = $max_size; +    $movie_img->width = $width; +    $movie_img->height = $height; +    $movie_img->attrs = $attrs; +    $movie_img->url = $this->file_url(true); +    $movie_img->fp_params = array(); // additional Flowplayer params values (will be json encoded) +    $movie_img->fp_config = array(); // additional Flowplayer config values (will be json encoded) +    $movie_img->view = array(); +    module::event("movie_img", $movie_img, $this); + +    if (count($movie_img->view) > 0) { +      // View generated - use it +      $view = implode("\n", $movie_img->view); +    } else { +      // View NOT generated - see if filetype supported by Flowplayer v3 +      // Note that the extension list below is hard-coded and doesn't use the legal_file helper +      // since anything else will not work in Flowplayer v3. +      if (in_array(strtolower(pathinfo($this->name, PATHINFO_EXTENSION)), +                   array("flv", "mp4", "m4v", "mov", "f4v"))) { +        // Filetype supported by Flowplayer v3 - use it (default) +        $view = new View("movieplayer.html"); +        $view->max_size = $movie_img->max_size; +        $view->width = $movie_img->width; +        $view->height = $movie_img->height; +        $view->attrs = $movie_img->attrs; +        $view->url = $movie_img->url; +        $view->fp_params = $movie_img->fp_params; +        $view->fp_config = $movie_img->fp_config;        } else { -        $width = (int)($width * $max_size / $height); -        $height = $max_size; +        // Filetype NOT supported by Flowplayer v3 - display download link +        $attrs = array_merge($attrs, array("style" => "width: {$max_size}px;", +                                           "download" => $this->name, // forces download (HTML5 only) +                                           "class" => "g-movie g-movie-download-link")); +        $view = html::anchor($this->file_url(true), t("Click here to download item."), $attrs);        }      } - -    $v->attrs = array_merge($extra_attrs, array("style" => "width:{$width}px;height:{$height}px", -                                                "class" => "g-movie")); -    if (empty($v->attrs["id"])) { -       $v->attrs["id"] = "g-item-id-{$this->id}"; -    } -    return $v; +    return $view;    }    /** | 
