CMS  Version 3.9
video_form.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("video", "taxonomy");
35 Fakoli::usingFeature("auto_form", "tab_bar");
36 
37 $menu_item = "Videos";
38 
39 $video_gallery_id = checkNumeric($_GET["video_gallery_id"]);
40 $video_id = checkNumeric($_GET["video_id"]);
41 
42 $video = new Video();
43 
44 if (!$video_gallery_id && !$video_id) redirect("/admin/video_galleries");
45 
46 if ($video_id)
47 {
48  $video->load($video_id);
49  $title = "Edit Details for {$video->title}";
50  $video_gallery_id = $video->video_gallery_id;
51 }
52 else
53 {
54  $video->user_id = $user->user_id;
55  $video->video_gallery_id = $video_gallery_id;
56 }
57 
58 $useHTML5 = Settings::getValue("video", "use_HTML5_video");
59 
60 $form = new AutoForm($video);
61 $form->hide("user_id", "video_gallery_id");
62 $form->required("title", "width", "height");
63 $form->annotate("width", "<em>Natural width of video in pixels</em>");
64 $form->annotate("height", "<em>Natural height of video in pixels</em>");
65 $form->annotate("video_file", $useHTML5 ? "<em>Video File in MP4 format</em>" : "<em>Video File in FLV format</em>");
66 $form->annotate("image_file", "<em>First Frame in PNG or JPG format</em>");
67 
69 
70 if ($video_id && $video->video_file)
71 {
72  $form->button("Play Video", "videoLightbox(this, '$video_id'); return false;", false, true);
73 }
74 
76 if ($videoMgr->hasFFMPEG())
77 {
78  $form->hide("width", "height", "image_file");
79 }
80 
81 $form->alias("image_id", "First Frame Image");
82 
83 $uploadRenderer = new FileUploadFieldRenderer($form, "video_file", "Video File", uploadFLV);
84 $uploadRenderer->size = 60;
85 
86 $imageUploadRenderer = new FileUploadFieldRenderer($form, "image_file", "First Frame Image", uploadImage);
87 $imageUploadRenderer->size = 60;
88 
89 $form->allowDelete = true;
90 
91 $redirect = "/admin/videos?video_gallery_id=$video_gallery_id";
92 $form->button("Cancel", $redirect);
93 
94 if ($video_id)
95 {
96  $form->button("Download Video", "/action/video/download?video_id=$video_id");
97 }
98 
99 $form->onSaveComplete = processVideo;
100 
101 if ($method == "POST")
102 {
103  if ($form->save())
104  {
105  redirect($redirect);
106  }
107 }
108 
109 $script .= $form->writeScript();
110 
111 
113 $tabs->page = "/admin/videos";
114 
115 $tabs->writeHTML();
116 ?>
117 <div id="tab_border" style="margin-right: -2px">
118 <?
119 $form->drawForm();
120 ?>
121 </div>
122 <?
123 
125 {
126  global $config;
127 
128  trace("uploadFLV() called for $field", 3);
129 
130  if (!$_FILES[$field])
131  {
132  trace("No upload record for $field", 3);
133  return false;
134  }
135  if ($_FILES[$field]["name"]=="")
136  {
137  trace("Upload name is empty", 3);
138  return false;
139  }
140 
141  $gallery = $video->VideoGallery();
142  $dir = $gallery->getGalleryDirectory();
143 
144  /* Copy across the uploaded file */
145 
146  trace("Upload Base: {$dir}", 3);
147 
148  if (!file_exists($dir))
149  {
150  mkdir($dir);
151  chmod($dir, 0755);
152  }
153 
154  $filename = $_FILES[$field]['name'];
155  $ext = strtolower(substr($filename, -4));
156 
157  trace("Video format: $ext", 3);
158 
159  if ($ext != ".flv" && $ext != ".f4v" && $ext != ".mp4")
160  {
161  throw new FakoliException("Unsupported video format");
162  }
163 
164  $target = $dir . DIRECTORY_SEPARATOR . $filename;
165  trace ("Uploading file to $target", 3);
166 
167  if (file_exists($target))
168  {
169  // If a previous copy of the file already exists, remove it
170  unlink($target);
171  }
172 
173  move_uploaded_file($_FILES[$field]["tmp_name"], $target);
174  chmod($target, 0755);
175  $video->video_file = $filename;
176 
177  $videoMgr = new VideoManager();
178  if ($videoMgr->hasFFMPEG())
179  {
180  $videoMgr->open($target);
181  $video->width = $videoMgr->getFrameWidth();
182  $video->height = $videoMgr->getFrameHeight();
183 
184  $target .= ".png";
185  if (file_exists($target))
186  {
187  unlink($target);
188  }
189 
190  $videoMgr->saveFrame(0.5, $target);
191 
192  $video->image_file = basename($target);
193  }
194 
195  return true;
196 }
197 
198 
200 {
201  global $config;
202 
203  trace("imageUploadHandler() called for $field", 3);
204 
205  if (!$_FILES[$field])
206  {
207  trace("No upload record for $field", 3);
208  return false;
209  }
210  if ($_FILES[$field]["name"]=="")
211  {
212  trace("Upload name is empty", 3);
213  return false;
214  }
215 
216  $gallery = $video->VideoGallery();
217  $dir = $gallery->getGalleryDirectory();
218 
219  /* Copy across the uploaded file */
220 
221  trace("Upload Base: {$dir}", 3);
222 
223  $filename = $_FILES[$field]['name'];
224  $ext = strtolower(substr($filename, -4));
225 
226  if ($ext != ".png" && $ext != ".jpg" && $ext != ".svg")
227  {
228  throw new FakoliException("Unsupported image format");
229  }
230 
231  $filename = tempnam($dir, "V") . $ext;
232 
233  $target = $dir . DIRECTORY_SEPARATOR . $filename;
234  trace ("Uploading file to $target", 3);
235 
236  if (file_exists($target))
237  {
238  // If a previous copy of the file already exists, remove it
239  unlink($target);
240  }
241 
242  move_uploaded_file($_FILES[$field]["tmp_name"], $target);
243  chmod($target, 0755);
244  $video->image_file = basename($filename);
245 
246  return true;
247 }
248 
250 {
251 
252 }
253 ?>
$helpTree style
Definition: tree.inc:46
$dir
Definition: delete.inc:44
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static addTaxonomyFieldRenderers($form, $showSelectAll=true, $group=null, $limitTo=null)
Definition: video.inc:42
static videoGalleryTabs($key)
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
global $config
Definition: import.inc:4
if(!Settings::getValue("debug", "enable_trace_file_downloads")) $filename
Definition: trace.inc:42
$form
Definition: video_form.inc:60
processVideo($form)
Definition: video_form.inc:249
$video_gallery_id
Definition: video_form.inc:39
$uploadRenderer
Definition: video_form.inc:83
if($video_id && $video->video_file) $videoMgr
Definition: video_form.inc:75
uploadImage($field, $video)
Definition: video_form.inc:199
$useHTML5
Definition: video_form.inc:58
$imageUploadRenderer
Definition: video_form.inc:86
$redirect
Definition: video_form.inc:91
$tabs
Definition: video_form.inc:112
$menu_item
Definition: video_form.inc:37
$video_id
Definition: video_form.inc:40
uploadFLV($field, $video)
Definition: video_form.inc:124
if($method=="POST") $script
Definition: video_form.inc:109
$video
Definition: video_form.inc:42