/** * get all video support type, ex. array(1=>youtube, 2=>vimeo) * @param string $return_key choose: name or title * @return array [id=>name] * */ public static function getAllSupportTypes($return_key = 'title') { if (NULL === self::$_supportTypes) { self::$_supportTypes = array(1 => array('name' => 'youtube', 'title' => 'YouTube Video'), 2 => array('name' => 'vimeo', 'title' => 'Vimeo Video'), self::$_uploadedType => array('name' => 'uploaded', 'title' => 'Uploaded Video'), 4 => array('name' => 'dailymotion', 'title' => 'Dailymotion Video'), self::$_videoUrlType => array('name' => 'videoURL', 'title' => 'URL Video'), 6 => array('name' => 'embed', 'title' => 'Embed Video')); } $ret = array(); foreach (self::$_supportTypes as $key => $row) { $ret[$key] = $row[$return_key]; } return $ret; }
public function createAction() { if (!$this->_helper->requireUser->isValid()) { return; } if (!$this->_helper->requireAuth()->setAuthParams('video', null, 'create')->isValid()) { return; } // Upload video if (isset($_GET['ul'])) { return $this->_forward('upload-video', null, null, array('format' => 'json')); } if (isset($_FILES['Filedata']) && !empty($_FILES['Filedata']['name'])) { $_POST['id'] = $this->uploadVideoAction(); } // Render $this->_helper->content->setEnabled(); // set up data needed to check quota $viewer = Engine_Api::_()->user()->getViewer(); $values['user_id'] = $viewer->getIdentity(); $paginator = Engine_Api::_()->getApi('core', 'video')->getVideosPaginator($values); $this->view->quota = $quota = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'video', 'max'); $this->view->current_count = $paginator->getTotalItemCount(); // Create form $this->view->form = $form = new Video_Form_Video(); if ($this->_getParam('type', false)) { $form->getElement('type')->setValue($this->_getParam('type')); } // if this is from a failed attempt if ($this->_getParam('retry')) { /* $video = Engine_Api::_()->getItem('video', $this->_getParam('retry')); $form->getElement('search')->setValue($video->search); $form->getElement('title')->setValue($video->title); $form->getElement('description')->setValue($video->description); $form->getElement('category_id')->setValue($video->category_id); // prepare tags $videoTags = $video->tags()->getTagMaps(); $tagString = ''; foreach( $videoTags as $tagmap ) { if( $tagString !== '' ) $tagString .= ', '; $tagString .= $tagmap->getTag()->getTitle(); } $this->view->tagNamePrepared = $tagString; $form->tags->setValue($tagString); // get more information? // delete the video? $video->delete();*/ } if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { $values = $form->getValues('url'); //$form->set = $values['url']; // set title and description using getinfromation() here? return; } // Process $values = $form->getValues(); $values['owner_id'] = $viewer->getIdentity(); $insert_action = false; $db = Engine_Api::_()->getDbtable('videos', 'video')->getAdapter(); $db->beginTransaction(); try { // Create video $table = Engine_Api::_()->getDbtable('videos', 'video'); if ($values['type'] == 3) { $video = Engine_Api::_()->getItem('video', $this->_getParam('id')); } else { $video = $table->createRow(); } $video->setFromArray($values); $video->save(); if ($values['type'] == Video_Plugin_Factory::getVideoURLType()) { $video->status = 1; $video->save(); $adapter = Video_Plugin_Factory::getPlugin((int) $values['type']); $adapter->getVideoImage($video->getIdentity()); } else { // Now try to create thumbnail $thumbnail = $this->handleThumbnail($video->type, $video->code); $ext = ltrim(strrchr($thumbnail, '.'), '.'); $thumbnail_parsed = @parse_url($thumbnail); if (@GetImageSize($thumbnail)) { $valid_thumb = true; } else { $valid_thumb = false; } if ($valid_thumb && $thumbnail && $ext && $thumbnail_parsed && in_array($ext, array('jpg', 'jpeg', 'gif', 'png'))) { $tmp_file = APPLICATION_PATH . '/temporary/link_' . md5($thumbnail) . '.' . $ext; $thumb_file = APPLICATION_PATH . '/temporary/link_thumb_' . md5($thumbnail) . '.' . $ext; $src_fh = fopen($thumbnail, 'r'); $tmp_fh = fopen($tmp_file, 'w'); stream_copy_to_stream($src_fh, $tmp_fh, 1024 * 1024 * 2); $image = Engine_Image::factory(); $image->open($tmp_file)->resize(120, 240)->write($thumb_file)->destroy(); try { $thumbFileRow = Engine_Api::_()->storage()->create($thumb_file, array('parent_type' => $video->getType(), 'parent_id' => $video->getIdentity())); // Remove temp file @unlink($thumb_file); @unlink($tmp_file); } catch (Exception $e) { } $information = $this->handleInformation($video->type, $video->code); $video->duration = $information['duration']; if (!$video->description) { $video->description = $information['description']; } $video->photo_id = $thumbFileRow->file_id; $video->status = 1; $video->save(); // Insert new action item $insert_action = true; } } if ($values['ignore'] == true) { $video->status = 1; $video->save(); $insert_action = true; } // CREATE AUTH STUFF HERE $auth = Engine_Api::_()->authorization()->context; $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone'); if (isset($values['auth_view'])) { $auth_view = $values['auth_view']; } else { $auth_view = "everyone"; } $viewMax = array_search($auth_view, $roles); foreach ($roles as $i => $role) { $auth->setAllowed($video, $role, 'view', $i <= $viewMax); } $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone'); if (isset($values['auth_comment'])) { $auth_comment = $values['auth_comment']; } else { $auth_comment = "everyone"; } $commentMax = array_search($auth_comment, $roles); foreach ($roles as $i => $role) { $auth->setAllowed($video, $role, 'comment', $i <= $commentMax); } // Add tags $tags = preg_split('/[,]+/', $values['tags']); $video->tags()->addTagMaps($viewer, $tags); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $db->beginTransaction(); try { if ($insert_action) { $owner = $video->getOwner(); $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($owner, $video, 'video_new'); if ($action != null) { Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $video); } } // Rebuild privacy $actionTable = Engine_Api::_()->getDbtable('actions', 'activity'); foreach ($actionTable->getActionsByObject($video) as $action) { $actionTable->resetActivityBindings($action); } $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } if ($video->type == 3) { return $this->_helper->redirector->gotoRoute(array('action' => 'manage'), 'video_general', true); } return $this->_helper->redirector->gotoRoute(array('user_id' => $viewer->getIdentity(), 'video_id' => $video->getIdentity()), 'video_view', true); }