CMS  Version 3.9
VideoManager Class Reference

Public Member Functions

 VideoManager ()
 
 hasFFMPEG ()
 
 open ($file)
 
 getFrameWidth ()
 
 getFrameHeight ()
 
 getFrameRate ()
 
 getFrame ($idx)
 
 saveFrame ($offset, $out)
 
 makeMultipleTwo ($value)
 
 thumbnailLink ($video_id, $size)
 Returns the URI that can be used to access the specified thumbnail of a video at the given size. More...
 
 imageLink ($video_id)
 
 renderThumbnail ($video_id, $size=0, $width=0, $height=0)
 Renders the Image specified by the image_id at the specified size. More...
 

Static Public Member Functions

static setDefaults ()
 
static onInitialize ()
 
static getVideoFolder ()
 
static getVideoURI ($video)
 
static formatVideoURI ($video)
 
static upgradeComponent ($version)
 
static displayVideoGallery ($identifier, &$continue)
 Event handler to display an image gallery from the specified identifier. More...
 
static deleteUser ($user)
 Respond to fired event DeleteUser. More...
 
static deleteGallery ($gallery)
 When deleting a video gallery, we must also delete all videos linked to the gallery and any downloads of those videos. More...
 
static videoGalleryTabs ($key)
 
static enumerateItems ($items)
 Enumerate the Image Gallery objects. More...
 
static registerTaxonomyClasses ($classes)
 

Public Attributes

 $movieFile = null
 

Detailed Description

Definition at line 41 of file video_manager.inc.

Member Function Documentation

◆ deleteGallery()

static VideoManager::deleteGallery (   $gallery)
static

When deleting a video gallery, we must also delete all videos linked to the gallery and any downloads of those videos.

Parameters
obj$galleryclass VideoGallery

Definition at line 497 of file video_manager.inc.

498  {
499  $tx = new DataTransaction();
500 
501  try
502  {
503  $videos = $gallery->Videos();
504 
505  if(count($videos))
506  {
507  $download = new VideoDownload();
508  foreach($videos as $video)
509  {
510  $download->joinTransaction($tx);
511  $video->joinTransaction($tx);
512  $download->delete("WHERE video_id={$video->video_id}");
513  $video->delete();
514  }
515  }
516  $tx->commit();
517  }
518  catch(Exception $e)
519  {
520  $tx->rollback();
521  throw $e;
522  }
523  }
$video
Definition: video_form.inc:42
$videos
Definition: videos.inc:40

◆ deleteUser()

static VideoManager::deleteUser (   $user)
static

Respond to fired event DeleteUser.

Delete any records in this component that have dependencies on user object.

Parameters
obj$user- class SiteUser or custom user class

Definition at line 449 of file video_manager.inc.

450  {
451  $pk = $user->getPrimaryKey();
452  $user_id = $user->$pk;
453 
454  trace("Component video is deleting objects dependent on user_id {$user_id}", 3);
455 
456  $tx = new DataTransaction();
457 
458  try
459  {
460  $galleries = Query::create(VideoGallery, "WHERE owner_id=:owner_id")
461  ->bind(":owner_id", $user_id)
462  ->execute();
463 
464  if(count($galleries))
465  {
466  foreach($galleries as $gallery)
467  {
468  $gallery->joinTransaction($tx);
470  }
471  }
472 
473  $video = new Video();
474  $video->joinTransaction($tx);
475  $video->delete("WHERE user_id={$user_id}");
476 
477  $download = new VideoDownload();
478  $download->joinTransaction($tx);
479  $download->delete("WHERE user_id={$user_id}");
480  $tx->commit();
481  }
482  catch(Exception $e)
483  {
484  $tx->rollback();
485  throw $e;
486  }
487 
488  return $user;
489  }
$user_id
Definition: video.inc:42
static deleteGallery($gallery)
When deleting a video gallery, we must also delete all videos linked to the gallery and any downloads...
global $user
$galleries

◆ displayVideoGallery()

static VideoManager::displayVideoGallery (   $identifier,
$continue 
)
static

Event handler to display an image gallery from the specified identifier.

Parameters
string$identifierthe identifier to match
boolean$continuereturns whether to continue processing this event

Definition at line 409 of file video_manager.inc.

410  {
411  try
412  {
413  $gallery = Query::create(VideoGallery, "WHERE identifier=:i")
414  ->bind(":i", $identifier)
415  ->executeSingle();
416 
417  $page = ComponentPage::findByIdentifier("video_gallery", "WHERE enabled=1");
418  $_GET["gallery_id"] = $gallery->video_gallery_id;
419 
420  $pageView = new ComponentPageView($page);
421 
422  $page_role = $page->role;
423 
424  if (!checkRole($page->role))
425  {
427  redirect("/login");
428  }
429 
430  echo $pageView->drawView();
431 
432  $continue = false;
433  }
434  catch(DataNotFoundException $e)
435  {
436 
437  }
438 
439  return $identifier;
440  }
$page
Definition: help.inc:39
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
Definition: login.inc:493
$identifier
Definition: rss.inc:37

◆ enumerateItems()

static VideoManager::enumerateItems (   $items)
static

Enumerate the Image Gallery objects.

Parameters
$itemscollection that the ImageGallery items are returned in

Definition at line 542 of file video_manager.inc.

543  {
544  $galleries = Query::create(VideoGallery, "ORDER BY gallery_name")->execute();
545 
546  $items["Video Galleries"] = $galleries;
547  return $items;
548  }

◆ formatVideoURI()

static VideoManager::formatVideoURI (   $video)
static

Definition at line 158 of file video_manager.inc.

159  {
161  }
static getVideoURI($video)

◆ getFrame()

VideoManager::getFrame (   $idx)

Definition at line 274 of file video_manager.inc.

275  {
276  return $this->ffmpeg->getFrame($idx);
277  }

◆ getFrameHeight()

VideoManager::getFrameHeight ( )

Definition at line 254 of file video_manager.inc.

255  {
256  foreach($this->movieInfo->streams as $stream)
257  {
258  if ($stream->codec_type == "video") return $stream->height;
259  }
260 
261  throw new FakoliException("Failed to locate video stream in file");
262  }
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53

◆ getFrameRate()

VideoManager::getFrameRate ( )

Definition at line 264 of file video_manager.inc.

265  {
266  foreach($this->movieInfo->streams as $stream)
267  {
268  if ($stream->codec_type == "video") return $stream->r_frame_rate;
269  }
270 
271  throw new FakoliException("Failed to locate video stream in file");
272  }

◆ getFrameWidth()

VideoManager::getFrameWidth ( )

Definition at line 244 of file video_manager.inc.

245  {
246  foreach($this->movieInfo->streams as $stream)
247  {
248  if ($stream->codec_type == "video") return $stream->width;
249  }
250 
251  throw new FakoliException("Failed to locate video stream in file");
252  }

◆ getVideoFolder()

static VideoManager::getVideoFolder ( )
static

Definition at line 102 of file video_manager.inc.

103  {
104  global $config;
105 
106  $location = Settings::getValue("video", "video_upload_location");
107  $folder = Settings::getValue("video", "video_folder");
108 
109  if ($location == "Other")
110  {
111  $dir = sanitizePath(Settings::getValue("video", "video_upload_other_location") . DIRECTORY_SEPARATOR . $folder);
112  trace($dir, 3);
113  if (!file_exists($dir))
114  {
115  //throw new FakoliException("Video Folder does not exist");
116  }
117  }
118  else if ($location == "Web Folder")
119  {
120  $dir = $config['homedir']. DIRECTORY_SEPARATOR . $folder;
121  if (!file_exists($dir))
122  {
123  throw new FakoliException("Video Folder does not exist");
124  }
125  }
126  else
127  {
128  $dir = $config['uploadbase']. DIRECTORY_SEPARATOR . $folder;
129  if (!file_exists($dir))
130  {
131  if (!mkdir($dir))
132  {
133  throw new FakoliException("Could not create video upload folder");
134  }
135  }
136  }
137 
138  return $dir;
139  }
$folder
Definition: templates.inc:41
$dir
Definition: delete.inc:44
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $config
Definition: import.inc:4

◆ getVideoURI()

static VideoManager::getVideoURI (   $video)
static

Definition at line 141 of file video_manager.inc.

142  {
143 
144  $location = Settings::getValue("video", "video_upload_location");
145 
146  if ($location == "Web Folder")
147  {
148  $folder = Settings::getValue("video", "video_folder");
149  $gallery = $video->VideoGallery();
150  return "/".$folder."/gallery_".$video->video_gallery_id."/".$video->video_file;
151  }
152  else
153  {
154  return "/action/video/stream?video_id=".$video->video_id;
155  }
156  }

◆ hasFFMPEG()

VideoManager::hasFFMPEG ( )

Definition at line 202 of file video_manager.inc.

203  {
204  $path = Settings::getValue("video", "ffmpeg_path");
205 
206  if (!$path)
207  {
208  trace("FFMPEG: path not set", 3);
209  return false;
210  }
211 
212  $ffmpeg = $this->getExecutablePath("ffmpeg");
213  if (!file_exists($ffmpeg))
214  {
215  trace("FFMPEG: no executable at $ffmpeg", 3);
216  return false;
217  }
218 
219  $ffprobe = $this->getExecutablePath("ffprobe");
220  if (!file_exists($ffprobe))
221  {
222  trace("FFMPEG: no executable at $ffprobe", 3);
223  return false;
224  }
225 
226  trace("FFMPEG: executables detected in correct location", 3);
227 
228  return true;
229  }
if(! $page) $path
Definition: page.inc:57

◆ imageLink()

VideoManager::imageLink (   $video_id)

Definition at line 304 of file video_manager.inc.

305  {
306  return "/action/video/show?image_id=$video_id";
307  }

◆ makeMultipleTwo()

VideoManager::makeMultipleTwo (   $value)

Definition at line 288 of file video_manager.inc.

289  {
290  return intval($value) >> 1 << 1;
291  }

◆ onInitialize()

static VideoManager::onInitialize ( )
static

Definition at line 65 of file video_manager.inc.

66  {
67  global $isAction;
68  global $isResource;
69 
70  global $html_editor_extra_buttons;
71  global $script;
72  global $styles;
73 
74  $html_editor_extra_buttons[] =
75  array("name" => "video_picker",
76  "image" => "/fakoli/images/video_button.png",
77  "tooltip" => "Insert Video",
78  "handler" => "videoPicker");
79 
80  $useHTML5 = Settings::getValue("video", "use_HTML5_video");
81  $useFlash = Settings::getValue("video", "use_flash_video");
82  $flowPlayerScript = Settings::getValue("video", "flowplayer_script");
83 
84  if ($isAction || $isResource) return;
85 
86  if ($useHTML5)
87  {
88  $styles = "<link href='//vjs.zencdn.net/4.12/video-js.css' rel='stylesheet'>" . $styles;
89  $script = "<script src='//vjs.zencdn.net/4.12/video.js'></script>" . $script;
90  }
91 
92  if ($useFlash && $flowPlayerScript)
93  {
94  $script .= "<script type='text/javascript' src='$flowPlayerScript'></script>\n";
95  }
96 
97  $flowPlayer = Settings::getValue("video", "flowplayer_player");
98 
99  $script .= "<script type='text/javascript'>\nvar flowplayerPath = '$flowPlayer';\n</script>\n";
100  }
$isResource
Definition: core.inc:1585
if($config["default_content_type"]) $isAction
Definition: core.inc:1584
$styles
$useHTML5
Definition: video_form.inc:58

◆ open()

VideoManager::open (   $file)

Definition at line 231 of file video_manager.inc.

232  {
233  trace("Opening video '$file'", 3);
234 
235  if (!file_exists($file))
236  {
237  throw new FakoliException("File not found");
238  }
239 
240  $this->movieFile = $file;
241  $this->movieInfo = json_decode($this->execute("ffprobe", "-v quiet -print_format json -show_format -show_streams {$this->movieFile}"));
242  }
$file
Definition: delete.inc:47

◆ registerTaxonomyClasses()

static VideoManager::registerTaxonomyClasses (   $classes)
static

Definition at line 550 of file video_manager.inc.

551  {
552  $classes[] = Video;
553  return $classes;
554  }

◆ renderThumbnail()

VideoManager::renderThumbnail (   $video_id,
  $size = 0,
  $width = 0,
  $height = 0 
)

Renders the Image specified by the image_id at the specified size.

Note that the size is the length of the major axis, and aspect ratio is maintained. The generated image is cached after rendering to speed subsequent accesses. The image file is output with the correct HTTP headers to ensure correct interpretation by the browser.

Parameters
$image_idthe ID of the image to render
$sizethe size of the major axis, in pixels
$widththe specific width of the rendered thumbnail (if $size is 0)
$heightthe specific height of the rendered thumbnail (if $size and $width are 0)

Definition at line 321 of file video_manager.inc.

322  {
323  global $config;
324 
325  $video = new Video($video_id);
326 
327  //AJG - default to natural size if not specified
328  if (!$size && !$width && !$height)
329  {
330  $width = $video->width;
331  $height = $video->height;
332  }
333 
334  $suffix = $size ? "$size" : ($width ? "{$width}w" : ($height ? "{$height}h" : ""));
335 
336  $dir = $video->VideoGallery()->getGalleryDirectory();
337 
338  $imageFile = $dir . DIRECTORY_SEPARATOR . $video->image_file;
339  $cacheFile = $dir . DIRECTORY_SEPARATOR . $video->video_id . "_" . $suffix .".png";
340  trace("renderThumbnail:: imageFile {$imageFile} and cacheDir {$cacheDir} and cacheFile {$cacheFile}", 3);
341 
342  if (!file_exists($cacheFile) || (filemtime($cacheFile) < filemtime($imageFile)))
343  {
344  $src = imagecreatefrompng($imageFile);
345 
346  // If the thumbnail hasn't been generated yet, or is out-of-date, create it.
347  $fullWidth = imagesx($src);
348  $fullHeight = imagesy($src);
349 
350  if ($size)
351  {
352  if ($fullWidth > $fullHeight)
353  {
354  $newWidth = $size;
355  $newHeight = intval(($fullHeight * $size) / $fullWidth);
356 
357  }
358  else
359  {
360  $newWidth = intval(($fullWidth * $size) / $fullHeight);
361  $newHeight = $size;
362  }
363  }
364  else if ($width)
365  {
366  $newWidth = $width;
367  $newHeight = intval(($fullHeight * $width) / $fullWidth);
368  }
369  else if ($height)
370  {
371  $newHeight = $height;
372  $newWidth = intval(($fullWidth * $height) / $fullHeight);
373  }
374  else
375  {
376  $newWidth = $fullWidth;
377  $newHeight = $fullHeight;
378  }
379 
380  trace("Rendering $cacheFile @ $newWidth x $newHeight", 3);
381 
382  $dst = imagecreatetruecolor($newWidth, $newHeight);
383  imagecopyresampled($dst, $src, 0, 0, 0, 0, $newWidth, $newHeight, $fullWidth, $fullHeight);
384 
385  if (file_exists($cacheFile))
386  {
387  // If a previous copy of the file already exists, remove it
388  trace("renderThumbnail:: unlinking cachefile", 3);
389  unlink($cacheFile);
390  }
391 
392  imagepng($dst, $cacheFile);
393 
394  imagedestroy($dst);
395  imagedestroy($src);
396  }
397 
398  Fakoli::sendFile($cacheFile);
399 
400  trace("renderThumbnail:: exiting", 3);
401  }
$src
Definition: page.inc:37
$size
Definition: download.inc:47
static sendFile($resource)
Sends the contents of the specified file to the client.
Definition: core.inc:780
$height
Definition: cover.inc:38
$width
Definition: cover.inc:37
$video_id
Definition: video_form.inc:40

◆ saveFrame()

VideoManager::saveFrame (   $offset,
  $out 
)

Definition at line 279 of file video_manager.inc.

280  {
281  if (!$this->movieFile) throw new FakoliException("Movie File not loaded");
282  $width = $this->getFrameWidth();
283  $height = $this->getFrameHeight();
284 
285  $this->execute("ffmpeg", "-ss {$offset} -i {$this->movieFile} -t 1 -s {$width}x{$height} -f image2 {$out}");
286  }

◆ setDefaults()

static VideoManager::setDefaults ( )
static

Definition at line 50 of file video_manager.inc.

51  {
52  Settings::setDefaultValue("video", "video_folder", "videos", String, "Directory inside the web folder that is used to store the video files", "Video Uploads");
53  Settings::setDefaultValue("video", "video_upload_location", "Web Folder", String,
54  "Indicate whether videos should be stored under the Web Folder or in the document upload area.".
55  "If you do not have mod_xsendfile installed, then Web Folder is strongly recommended",
56  "Video Uploads", "Web Folder\nDocument Upload Folder\nOther");
57  Settings::setDefaultValue("video","video_upload_other_location", "", String, "Full path to alternate video location", "Video Uploads");
58  Settings::setDefaultValue("video", "use_HTML5_video", false, Boolean, "Check to enable support for HTML5 video", "Video Player", null, 1);
59  Settings::setDefaultValue("video", "use_flash_video", true, Boolean, "Check to enable support for old-style FLV (requires Flowplayer Flash)", "Video Player", null, 2);
60  Settings::setDefaultValue("video", "flowplayer_script", "", String, "URI for the Flowplayer script", "Video Player", null, 3);
61  Settings::setDefaultValue("video", "flowplayer_player", "", String, "URI for the Flowplayer SWF file", "Video Player", null, 4);
62  Settings::setDefaultValue("video", "ffmpeg_path", "", String, "Directory containing the ffmpeg binary executables", "Video Transcoder");
63  }
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174

◆ thumbnailLink()

VideoManager::thumbnailLink (   $video_id,
  $size 
)

Returns the URI that can be used to access the specified thumbnail of a video at the given size.

Parameters
$video_idthe ID of the video
$sizethe size of the major axis in pixels
Returns
string URI that can be used in an tag to view this image.

Definition at line 299 of file video_manager.inc.

300  {
301  return "/action/video/thumbnail?video_id=$video_id&size=$size";
302  }

◆ upgradeComponent()

static VideoManager::upgradeComponent (   $version)
static

Definition at line 163 of file video_manager.inc.

164  {
165  $mgr = new VideoUpgradeManager();
166  $mgr->upgrade($version);
167  }

◆ videoGalleryTabs()

static VideoManager::videoGalleryTabs (   $key)
static

Definition at line 525 of file video_manager.inc.

526  {
527  $tabs = array(
528  "Gallery" => "/admin/video_gallery_form",
529  "Permissions" => "/admin/video_gallery_permissions",
530  "Videos" => "/admin/videos",
531  "Statistics" => "/admin/video_gallery_stats",
532  );
533 
534  $qs = ($key) ? "video_gallery_id=$key" : "";
535  return new TabBar("tabs", $tabs, $qs);
536  }
$tabs

◆ VideoManager()

VideoManager::VideoManager ( )

Definition at line 45 of file video_manager.inc.

46  {
47  trace("Creating VideoManager", 3);
48  }

Member Data Documentation

◆ $movieFile

VideoManager::$movieFile = null

Definition at line 43 of file video_manager.inc.


The documentation for this class was generated from the following file: