public function composeUploadAction() { $viewer = Engine_Api::_() -> user() -> getViewer(); if (!$viewer -> getIdentity()) { $this -> _redirect('login'); return; } if (!$this -> getRequest() -> isPost()) { $this -> view -> status = false; $this -> view -> error = Zend_Registry::get('Zend_Translate') -> _('Invalid method.'); return; } $video_title = $this -> _getParam('title'); $video_url = $this -> _getParam('uri'); $video_type = $this -> _getParam('type'); $composer_type = $this -> _getParam('c_type', 'wall'); $valid = false; // extract code if ($video_type != Ynvideo_Plugin_Factory::getUploadedType()) { $adapter = Ynvideo_Plugin_Factory::getPlugin((int)$video_type); $adapter -> setParams(array('link' => $video_url)); $valid = $adapter -> isValid(); } // check to make sure the user has not met their quota of # of allowed video uploads // set up data needed to check quota $values['user_id'] = $viewer -> getIdentity(); $paginator = Engine_Api::_() -> getApi('core', 'ynvideo') -> getVideosPaginator($values); //$quota = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'video', 'max'); // TODO [DangTH] : get the max value $this -> view -> quota = $quota = Engine_Api::_() -> ynvideo() -> getAllowedMaxValue('video', $viewer -> level_id, 'max'); $current_count = $paginator -> getTotalItemCount(); if (($current_count >= $quota) && !empty($quota)) { // return error message $this -> view -> message = Zend_Registry::get('Zend_Translate') -> _('You have already uploaded the maximum number of videos allowed. If you would like to upload a new video, please delete an old one first.'); } else if ($valid) { $db = Engine_Api::_() -> getDbtable('videos', 'ynvideo') -> getAdapter(); $db -> beginTransaction(); try { $table = Engine_Api::_() -> getDbtable('videos', 'ynvideo'); $video = $table -> createRow(); $video -> owner_id = $viewer -> getIdentity(); $video -> type = $video_type; $video -> parent_type = 'user'; $video -> parent_id = $viewer -> getIdentity(); if($video_type == 6) { $regex = '/(<iframe.*? src=(\"|\'))(.*?)((\"|\').*)/'; preg_match($regex, $video_url, $matches); if(count($matches) > 2) { $video_url = $matches[3]; } } $video -> code = $video_url; if ($video_type == Ynvideo_Plugin_Factory::getVideoURLType() || $video_type == 6) { $video -> title = Ynvideo_Plugin_Adapter_VideoURL::getDefaultTitle(); } else { if ($adapter -> fetchLink()) { // create video $video -> storeThumbnail($adapter -> getVideoThumbnailImage(), 'small'); $video -> storeThumbnail($adapter -> getVideoLargeImage(), 'large'); $video -> title = $adapter -> getVideoTitle(); $video -> description = $adapter -> description; $video -> duration = $adapter -> getVideoDuration(); $video -> code = $adapter -> getVideoCode(); $video -> save(); } } // If video is from the composer, keep it hidden until the post is complete if ($composer_type) { $video -> search = 0; } $video -> status = 1; $video -> save(); $db -> commit(); } catch (Exception $e) { $db -> rollBack(); throw $e; } // make the video public if ($composer_type === 'wall') { // CREATE AUTH STUFF HERE $auth = Engine_Api::_() -> authorization() -> context; $roles = array( 'owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone' ); foreach ($roles as $i => $role) { $auth -> setAllowed($video, $role, 'view', ($i <= $roles)); $auth -> setAllowed($video, $role, 'comment', ($i <= $roles)); } } $this -> view -> status = true; $this -> view -> video_id = $video -> video_id; $this -> view -> photo_id = $video -> photo_id; $this -> view -> title = $video -> title; $this -> view -> type = $video -> type; $this -> view -> description = $video -> description; if ($video_type == Ynvideo_Plugin_Factory::getVideoURLType() || $video_type == 6) { $this -> view -> src = Zend_Registry::get('StaticBaseUrl') . 'application/modules/Video/externals/images/video.png'; } else { $this -> view -> src = $video -> getPhotoUrl(); } $this -> view -> message = Zend_Registry::get('Zend_Translate') -> _('Video posted successfully.'); } else { $this -> view -> message = Zend_Registry::get('Zend_Translate') -> _('We could not find a video there - please check the URL and try again.'); } }
public function fetchVideoLargeThumbnail($videos = null) { if ($videos) { if ($videos instanceof Ynvideo_Model_Video) { $arrVideos = array($videos); } else { $arrVideos = $videos; } } if ($arrVideos) { foreach ($arrVideos as $video) { if (!$video->large_photo_id) { $adapter = Ynvideo_Plugin_Factory::getPlugin($video->type); $adapter->setParams(array('code' => $video->code, 'video_id' => $video->getIdentity())); $video->storeThumbnail($adapter->getVideoLargeImage(), 'large'); } } } }
public function getRichContent($view = false, $params = array()) { $session = new Zend_Session_Namespace('mobile'); $mobile = $session -> mobile; $count_video = 0; if (isset($session -> count)) $count_video = ++$session -> count; $paramsForCompile = array_merge(array( 'video_id' => $this -> video_id, 'code' => $this -> code, 'view' => $view, 'mobile' => $mobile, 'duration' => $this -> duration, 'count_video' => $count_video ), $params); if ($this -> type == Ynvideo_Plugin_Factory::getUploadedType()) { $responsive_mobile = FALSE; if (defined('YNRESPONSIVE')) { $responsive_mobile = Engine_Api::_() -> ynresponsive1() -> isMobile(); } if (!empty($this -> file1_id)) { $storage_file = Engine_Api::_() -> getItem('storage_file', $this -> file_id); if ($session -> mobile || $responsive_mobile) { $storage_file = Engine_Api::_() -> getItem('storage_file', $this -> file1_id); } if ($storage_file) { $paramsForCompile['location1'] = $storage_file -> getHref(); $paramsForCompile['location'] = ''; } } else { $storage_file = Engine_Api::_() -> getItem('storage_file', $this -> file_id); if ($storage_file) { $paramsForCompile['location'] = $storage_file -> getHref(); $paramsForCompile['location1'] = ''; } } } else if ($this -> type == Ynvideo_Plugin_Factory::getVideoURLType()) { $paramsForCompile['location'] = $this -> code; } $videoEmbedded = Ynvideo_Plugin_Factory::getPlugin((int)$this -> type) -> compileVideo($paramsForCompile); // $view == false means that this rich content is requested from the activity feed if ($view == false) { $video_duration = ""; if ($this -> duration) { if ($this -> duration >= 3600) { $duration = gmdate("H:i:s", $this -> duration); } else { $duration = gmdate("i:s", $this -> duration); } $video_duration = "<span class='video_length'>" . $duration . "</span>"; } // prepare the thumbnail $thumb = Zend_Registry::get('Zend_View') -> itemPhoto($this, 'thumb.large'); if ($this -> photo_id) { $thumb = Zend_Registry::get('Zend_View') -> itemPhoto($this, 'thumb.large'); } else { $thumb = '<img alt="" src="' . Zend_Registry::get('StaticBaseUrl') . 'application/modules/Video/externals/images/video.png">'; } if (!$mobile) { $thumb = '<a id="video_thumb_' . $this -> video_id . $count_video . '" style="" href="javascript:void(0);" onclick="javascript:var myElement = $(this);myElement.style.display=\'none\';var next = myElement.getNext(); next.style.display=\'block\';"> <div class="video_thumb_wrapper">' . $video_duration . $thumb . '</div> </a>'; } else { $thumb = '<a id="video_thumb_' . $this -> video_id . $count_video . '" class="video_thumb" href="javascript:void(0);"> <div class="video_thumb_wrapper">' . $video_duration . $thumb . '</div> </a>'; } // prepare title and description $title = "<a class='smoothbox' href='" . $this -> getPopupHref($params) . "'>". $this-> getTitle()."</a>"; $tmpBody = strip_tags($this -> description); $description = "<div class='video_desc'>" . (Engine_String::strlen($tmpBody) > 255 ? Engine_String::substr($tmpBody, 0, 255) . '...' : $tmpBody) . "</div>"; $class_html5 = ""; if ($this -> type == Ynvideo_Plugin_Factory::getVideoURLType() || $this -> type == Ynvideo_Plugin_Factory::getUploadedType()) { $class_html5 = 'html5_player'; } $totalLike = Engine_Api::_() -> getDbtable('likes', 'yncomment') -> likes($this) -> getLikeCount(); $totalDislike = Engine_Api::_() -> getDbtable('dislikes', 'yncomment') -> getDislikeCount($this); $videoEmbedded = '<div class="video_info">' .$title . $description . '</div>'.$thumb . '<div id="video_object_' . $this -> video_id . '" class="video_object ' . $class_html5 . '">' . $videoEmbedded . '</div>'; $view = Zend_Registry::get('Zend_View'); $videoEmbedded .= '<div class="tfvideo_statistics"> <span>'. $view->translate(array('%s like', '%s likes', $totalLike), $totalLike). '</span> <span>'. $view->translate(array('%s dislike', '%s dislikes', $totalDislike), $totalDislike). '</span> <span>'. $view->translate(array('%s comment', '%s comments', $this -> comment_count), $this -> comment_count).'</span> </div>'; } return $videoEmbedded; }