Knowledge Base
Categories
Latest Articles
- How to resolve the issue of unable to Create or Save Draft on Contest app v4.02 on phpFox v4.6.1b5
- Fixing unable to delete videos in Ultimate Video
- Missed "Can add a new blog?"
- Error: Fatal error: require() ... C:\xampp2\htdocs\phpfox\PF.Base\include\library\phpfox\template\template.class.php
- [Social Media Importer] Add "Import Photo" menu on Advanced Photo app
- [Social Chat] Change color of Chat box
- PHP module "Multibyte String" is missing
- PHP module "PHP ZipArchive" is missing
- [phpFox] Unable to remove caches in memcache on apps of third party
- Error: PHP module 'PHP Exec is missing'
Most Viewed Articles
Featured Articles
As the release of new version of Ultimate Video, some might encounter the issue of unable to delete video. Please follow this guide to resolve the issue.
Edit the file content of .../PF.Site/Apps/YouNet_UltimateVideos/Service/Process.php to:
<?php
/**
* Created by PhpStorm.
* User: davidnguyen
* Date: 7/27/16
* Time: 9:23 AM
*/
namespace Apps\YouNet_UltimateVideos\Service;
use Phpfox;
use Phpfox_Plugin;
use Phpfox_Service;
use Phpfox_Database;
use Phpfox_Error;
use Phpfox_Url;
require_once dirname(dirname(__FILE__)) . '/Google/autoload.php';
defined('PHPFOX') or exit('NO DICE!');
class Process extends Phpfox_Service
{
private $_aCategories = array();
public function __construct()
{
$this->_sTable = Phpfox::getT('ynultimatevideo_videos');
}
protected function database()
{
return Phpfox_Database::instance();
}
public function Oauth2callback()
{
$video_id = $this -> _getParam('video_id', 0);
if(!isset($_SESSION['ynultimatevideo_youtube_video']))
{
$_SESSION['ynultimatevideo_youtube_video'] = $video_id;
}
$settings = Engine_Api::_()->getApi('settings', 'core');
$token = '';
if(isset($_SESSION['ynultimatevideo_youtube_token']))
$token = $_SESSION['ynultimatevideo_youtube_token'];
$OAUTH2_CLIENT_ID = $settings->getSetting('ynultimatevideo_youtube_clientid', "");
$OAUTH2_CLIENT_SECRET = $settings->getSetting('ynultimatevideo_youtube_secret', "");
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setAccessType('offline');
$client->setScopes('https://www.googleapis.com/auth/youtube';);
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on")
{
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"];
}
$redirect = $pageURL.$this -> view -> url(array('action' => 'oauth2callback'), 'ynultimatevideo_general', true);
$client->setRedirectUri($redirect);
if($token)
{
$client->setAccessToken($token);
if($client->isAccessTokenExpired())
{
unset($_SESSION['ynultimatevideo_youtube_token']);
$state = mt_rand();
$client->setState($state);
$_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
$this -> _redirectCustom($authUrl);
}
}
if (isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$token = $client->getAccessToken();
}
if(!$token)
{
$state = mt_rand();
$client->setState($state);
$_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
$this -> _redirectCustom($authUrl);
}
else
{
$_SESSION['ynultimatevideo_youtube_token'] = $token;
if(isset($_SESSION['ynultimatevideo_youtube_video']) && !$video_id)
{
$video_id = $_SESSION['ynultimatevideo_youtube_video'];
}
unset($_SESSION['ynultimatevideo_youtube_video']);
$video = Engine_Api::_() -> getItem('ynultimatevideo_video', $video_id);
if($video)
{
$video -> user_token = $token;
$video -> save();
// Add to jobs
Engine_Api::_() -> getDbtable('jobs', 'core') -> addJob('ynultimatevideo_uploadyoutube', array('item' => $video -> getGuid()));
}
// redirect to manage page
return $this -> _helper -> redirector -> gotoRoute(array('action' => 'manage'), 'ynultimatevideo_general', true);
}
}
public function getCategoriesFromForm($aVals)
{
if (isset($aVals['category']) && count($aVals['category']))
{
if(empty($aVals['category'][0]))
{
return false;
}
else if(!is_array($aVals['category']))
{
$this->_aCategories[] = $aVals['category'];
}
else{
foreach ($aVals['category'] as $iCategory)
{
if (empty($iCategory))
{
continue;
}
if (!is_numeric($iCategory))
{
continue;
}
$this->_aCategories[] = $iCategory;
}
}
return true;
}
}
public function add($aVals, $aVideo = null,$isFeed = false){
$oFilter = Phpfox::getLib('parse.input');
if ($aVideo === null)
{
}
if($iFlood = user('ynuv_time_before_share_other_video',0) != 0)
{
$aFlood = array(
'action' => 'last_post', // The SPAM action
'params' => array(
'field' => 'time_stamp', // The time stamp field
'table' => $this->_sTable, // Database table we plan to check
'condition' => 'user_id = ' . Phpfox::getUserId(), // Database WHERE query
'time_stamp' => $iFlood * 60 // Seconds);
)
);
// actually check if flooding
if (Phpfox::getLib('spam')->check($aFlood))
{
if($isFeed)
Phpfox::addMessage(_p('uploading_video_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime());
return \Phpfox_Error::set(_p('uploading_video_a_little_too_soon') . ' ' . Phpfox::getLib('spam')->getWaitTime());
}
}
if(!$this->getCategoriesFromForm($aVals)){
if($isFeed)
Phpfox::addMessage(_p('provide_a_category_this_video_will_belong_to'));
return \Phpfox_Error::set(_p('provide_a_category_this_video_will_belong_to'));
}
$sVideoTitle = '';
$adapter = Phpfox::getService('ultimatevideo') -> getClass($aVals['video_source']);
if($aVals['video_source'] == "VideoURL")
{
$adapter->setParams(array('code' => $aVals['video_code']));
$vImagePath = $adapter->getVideoLargeImage();
$vDuration = $adapter -> getVideoDuration();
}
elseif($aVals['video_source'] != "Uploaded")
{
if($aVals['video_source'] == 'Facebook'){
$adapter -> setParams(array('link' => $aVals['video_url']));
}
elseif($aVals['video_source'] != "Dailymotion" && $aVals['video_source'] != "Embed"){
$adapter -> setParams(array('code' => $aVals['video_code']));
}
elseif($aVals['video_source'] == "Dailymotion"){
$adapter -> setParams(array('link' => $aVals['video_code']));
$adapter -> setParams(array('code' => $aVals['video_code']));
}
elseif($aVals['video_source'] == "Embed"){
$adapter -> setParams(array('link' => $aVals['video_embed']));
$adapter -> setParams(array('code' => $aVals['video_code']));
}
if($adapter -> isValid()){
if($aVals['video_source'] != "Embed") {
$adapter -> fetchLink();
$vDuration = $adapter -> getVideoDuration();
$vOriginalImagePath = $adapter -> getVideoLargeImage();
if($vOriginalImagePath && $aVals['video_source'] != "Facebook"){
$vImagePath = $this->downloadImage($vOriginalImagePath);
}
elseif($vOriginalImagePath && $aVals['video_source'] == "Facebook"){
$vImagePath = $vOriginalImagePath;
}
else{
$vImagePath = "";
}
}
else{
$vImagePath = "";
$vDuration = 0;
}
$sVideoTitle = $adapter->getVideoTitle();
}
else {
if($isFeed)
Phpfox::addMessage(_p('video_code_is_not_valid_please_try_again'));
return \Phpfox_Error::set(_p('video_code_is_not_valid_please_try_again'));
}
}
else{
$vImagePath = "";
$vDuration = 0;
}
if(empty($sVideoTitle))
{
$sVideoTitle = _p('video_uploaded_on_space'). Phpfox::getTime('m/d/Y',PHPFOX_TIME);
}
if(empty($aVals['title']))
{
$aVals['title'] = $sVideoTitle;
}
// Check callback.
$aCallback = null;
$bCheckPage = false;
if (isset($aVals['callback_module']))
{
$aCallback = [
'item_id' => $aVals['callback_item_id'],
'module' => $aVals['callback_module']
];
if (($aCallback['module'] == "pages") || ($aCallback['module'] == "groups")){
$bCheckPage = true;
}
}
if(!isset($aVals['privacy']))
{
$aVals['privacy'] = 0;
}
$description = $aVals['description'];
$description = $oFilter->prepare($description);
$aSql = array(
'user_id' => Phpfox::getUserId(),
'status' => isset($aVals['video_source']) && ($aVals['video_source'] != 'Uploaded') ? 1 : 0,
'parent_user_id' => (isset($aVals['parent_user_id']) ? (int) $aVals['parent_user_id'] : '0'),
'type' => Phpfox::getService('ultimatevideo') -> getSourTypeIdFromName($aVals['video_source']),
'item_id' => ($aCallback === null ? (isset($aVals['parent_user_id']) ? (int) $aVals['parent_user_id'] : '0') : $aCallback['item_id']),
'module_id' => ($aCallback === null ? '' : $aCallback['module']),
'title' => $oFilter->clean($aVals['title'], 255),
'privacy' => (int) (isset($aVals['privacy']) ? (int) $aVals['privacy'] : 0),
'time_stamp' => PHPFOX_TIME,
'category_id' => end($this->_aCategories),
'code' => $aVals['video_code'],
'description' => (empty($aVals['description'])) ? "" : $description,
'video_path' => isset($aVals['video_path']) ? $aVals['video_path'] : "",
'video_server_id' => Phpfox::getLib('request')->getServer('PHPFOX_SERVER_ID'),
'duration' => $vDuration,
'image_path' => $vImagePath,
'image_server_id' => Phpfox::getLib('request')->getServer('PHPFOX_SERVER_ID'),
'is_approved' => (!user('ynuv_should_be_approve_before_display_video')) ? 1 : 0,
'allow_upload_channel' => (isset($aVals['allow_upload_channel'])) ? 1 : 0,
);
$iVideoId = $this->database()->insert($this->_sTable, $aSql);
if (!empty($aVals['location'])) {
$aLocation = [
'location_name' => !empty($aVals['location']['name']) ? Phpfox::getLib('parse.input')->clean($aVals['location']['name']) : null,
'location_latlng' => null
];
if ((!empty($aVals['location']['latlng']))) {
$aMatch = explode(',', $aVals['location']['latlng']);
$aMatch['latitude'] = floatval($aMatch[0]);
$aMatch['longitude'] = floatval($aMatch[1]);
$aLocation['location_latlng'] = json_encode(array(
'latitude' => $aMatch['latitude'],
'longitude' => $aMatch['longitude']
));
}
$this->database()->update($this->_sTable, $aLocation, 'video_id =' . (int)$iVideoId);
}
// insert custom field by category
if (isset($aVals['custom']) && count($aVals['custom']) > 0) {
Phpfox::getService('ultimatevideo.custom.process')->addValue($aVals['custom'], $iVideoId);
}
//add tag
if(isset($aVals['tag_list']) && !empty($aVals['tag_list']) && Phpfox::VERSION >= '3.7.0' && Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support'))
{
$sTags = $aVals['tag_list'];
Phpfox::getService('tag.process')->add('ynultimatevideo', $iVideoId, Phpfox::getUserId(), $sTags, false);
$this->cache()->remove('ultimatevideo.video', 'substr');
}
$iFeedId = 0;
if($iVideoId && $aVals['video_source'] != "Uploaded" && !user('ynuv_should_be_approve_before_display_video'))
{
if (isset($aVals['callback_module']) && Phpfox::isModule($aVals['callback_module']) && Phpfox::hasCallback($aVals['callback_module'], 'getFeedDetails'))
{
(Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->callback(Phpfox::callback($aVals['callback_module'] . '.getFeedDetails', $aVals['callback_item_id']))->add('ultimatevideo_video', $iVideoId, $aVals['privacy'], (isset($aVals['privacy_comment']) ? (int) $aVals['privacy_comment'] : 0), $aVals['callback_item_id']) : null);
}
else{
((Phpfox::isModule('feed') && !defined('PHPFOX_SKIP_FEED_ENTRY')) ? $iFeedId = Phpfox::getService('feed.process')->add('ultimatevideo_video', $iVideoId, $aVals['privacy'], 0, 0, $aVideo['user_id']) : null);
}
}
$variable = user('ultimatevideo.points_ultimatevideo_video');
$checkInt = filter_var($variable, FILTER_VALIDATE_INT);
if ($checkInt && $variable > 0) {
if ($iVideoId && !user('ynuv_should_be_approve_before_display_video')) {
$this->updateCountVideoForCategory(end($this->_aCategories), "add");
Phpfox::getService('user.activity')->update(Phpfox::getUserId(), 'ultimatevideo_video', '+');
}
}
if ($aVals['privacy'] == '4')
{
Phpfox::getService('privacy.process')->add('ultimatevideo', $iVideoId, (isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array()));
}
// plugin call
(($sPlugin = Phpfox_Plugin::get('ultimatevideo.service_process_add__end')) ? eval($sPlugin) : false);
return $iVideoId;
}
public function update($aVals, $iVideoId){
$oFilter = Phpfox::getLib('parse.input');
if(!$this->getCategoriesFromForm($aVals)){
return \Phpfox_Error::set(_p('provide_a_category_this_video_will_belong_to'));
}
// Check callback.
$aCallback = null;
if (isset($aVals['callback_module']) && Phpfox::hasCallback($aVals['callback_module'], 'uploadVideo'))
{
$aCallback = Phpfox::callback($aVals['callback_module'] . '.uploadVideo', $aVals);
}
$description = $aVals['description'];
$description = $oFilter->prepare($description);
$aSql = array(
'title' => (empty($aVals['title'])) ? "" : $oFilter->clean($aVals['title'], 255),
'privacy' => (int) (isset($aVals['privacy']) ? (int) $aVals['privacy'] : 0),
'category_id' => end($this->_aCategories),
'description' => (empty($aVals['description'])) ? "" : $description,
'allow_upload_channel' => (isset($aVals['allow_upload_channel'])) ? 1 : 0,
'time_stamp' => PHPFOX_TIME,
);
$this->database()->update($this->_sTable, $aSql,'video_id = '.(int)$iVideoId);
// update custom field by category
if (isset($aVals['custom']) && count($aVals['custom']) > 0) {
$this->database()->delete(Phpfox::getT('ynultimatevideo_custom_value'), 'video_id = ' . (int)$iVideoId);
Phpfox::getService('ultimatevideo.custom.process')->addValue($aVals['custom'], $iVideoId);
}
//update tag
if(isset($aVals['tag_list']) && Phpfox::VERSION >= '3.7.0' && Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support'))
{
Phpfox::getService('tag.process')->update('ynultimatevideo', $iVideoId, Phpfox::getUserId(), $aVals['tag_list']);
$this->cache()->remove('ultimatevideo.video', 'substr');
}
//update privacy
if (Phpfox::isModule('privacy'))
{
if ($aVals['privacy'] == '4')
{
Phpfox::getService('privacy.process')->update('ultimatevideo', $iVideoId, (isset($aVals['privacy_list']) ? $aVals['privacy_list'] : array()));
}
else
{
Phpfox::getService('privacy.process')->delete('ultimatevideo', $iVideoId);
}
}
return $iVideoId;
}
public function downloadImage($sImgUrl)
{
if (!$sImgUrl) {
return '';
}
$pos = stripos($sImgUrl, ".bmp");
if ($pos > 0) {
return $sImgUrl;
}
//Check Folder Storage
$sNewsPicStorage = Phpfox::getParam('core.dir_pic') . 'ynultimatevideo';
if (!is_dir($sNewsPicStorage)) {
@mkdir($sNewsPicStorage, 0777, 1);
@chmod($sNewsPicStorage, 0777);
}
// Generate Image object and store image to the temp file
$iToken = rand();
$oImage = \Phpfox::getLib('request')->send($sImgUrl, array(), 'GET');
if (empty($oImage) && (substr($sImgUrl, 0, 8) == 'https://';)) {
$sImgUrl = 'http://'; . substr($sImgUrl, 8);
$oImage = Phpfox::getLib('request')->send($sImgUrl, array(), 'GET');
}
$sTempImage = 'ynultimatevideo_temp_thumbnail_' . $iToken . '_' . PHPFOX_TIME;
\Phpfox::getLib('file')->writeToCache($sTempImage, $oImage);
// Save image
$ThumbNail = Phpfox::getLib('file')->getBuiltDir($sNewsPicStorage . PHPFOX_DS) . md5('image_' . $iToken . '_' . PHPFOX_TIME) . '%s.jpg';
Phpfox::getLib('image')->createThumbnail(PHPFOX_DIR_CACHE . $sTempImage,sprintf($ThumbNail, '_' . 1024), 1024, 1024);
Phpfox::getLib('image')->createThumbnail(PHPFOX_DIR_CACHE . $sTempImage,sprintf($ThumbNail, '_' . 500), 500, 500);
Phpfox::getLib('image')->createThumbnail(PHPFOX_DIR_CACHE . $sTempImage,sprintf($ThumbNail, '_' . 250), 250, 250);
Phpfox::getLib('image')->createThumbnail(PHPFOX_DIR_CACHE . $sTempImage,sprintf($ThumbNail, '_' . 120), 120, 120);
@unlink(PHPFOX_DIR_CACHE . $sTempImage);
$sFileName = str_replace(Phpfox::getParam('core.dir_pic'), "", $ThumbNail);
$sFileName = str_replace("\\", "/", $sFileName);
// Return logo file
return $sFileName;
}
public function featureVideo($iVideoId, $iIsFeatured)
{
if(!user('ynuv_can_feature_video') && !Phpfox::isAdmin())
{
return false;
}
$oVideo = Phpfox::getService('ultimatevideo');
$this->database()->update($this->_sTable,array('is_featured' => $iIsFeatured ),"video_id = {$iVideoId}");
$oVideoTitle = $this->database()->select('title')->from($this->_sTable)->where("video_id = {$iVideoId}")->execute('getSlaveField');
if($iIsFeatured)
{
$iOwnerId = $oVideo->getVideoOwnerId($iVideoId);
if($iOwnerId)
{
// Add notification
$iSenderUserId = $iOwnerId;
if((int)Phpfox::getUserId() > 0)
{
$iSenderUserId = Phpfox::getUserId();
}
Phpfox::getService("notification.process")->add("ultimatevideo_videofeature",$iVideoId, $iOwnerId, $iSenderUserId);
}
}
return true;
}
public function approvedVideo($iVideoId, $iIsApproved)
{
if(!user('ynuv_can_approve_video') && !Phpfox::isAdmin())
{
return false;
}
$oVideo = Phpfox::getService('ultimatevideo');
$this->database()->update($this->_sTable,array('is_approved' => $iIsApproved ),"video_id = {$iVideoId}");
$aVideo = $this->database()->select('*')->from($this->_sTable)->where("video_id = {$iVideoId}")->execute('getRow');
if($iIsApproved)
{
$iOwnerId = $oVideo->getVideoOwnerId($iVideoId);
if($iOwnerId)
{
// Add notification
$iSenderUserId = $iOwnerId;
if((int)Phpfox::getUserId() > 0)
{
$iSenderUserId = Phpfox::getUserId();
}
Phpfox::getService("notification.process")->add("ultimatevideo_videoapprove",$iVideoId, $iOwnerId, $iSenderUserId);
// Send mail
$text = _p('your_video_space').'<a href="'.Phpfox_Url::instance()->permalink('ultimatevideo',$iVideoId, $aVideo['title']).'">'.$aVideo['title'].'</a>'._p(' is approved.');
$aOwnerEmail = array($oVideo->getOwnerEmail($iOwnerId));
//Phpfox::getLib('mail')->to($aOwnerEmail)
// ->subject(_p('Your video is featured'))
// ->message($text)
// ->send();
}
if (isset($aVideo['module_id']) && Phpfox::isModule($aVideo['module_id']) && Phpfox::hasCallback($aVideo['module_id'], 'getFeedDetails'))
{
(Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->callback(Phpfox::callback($aVideo['module_id'] . '.getFeedDetails', $aVideo['item_id']))->add('ultimatevideo_video', $iVideoId, $aVideo['privacy'], (isset($aVideo['privacy_comment']) ? (int) $aVideo['privacy_comment'] : 0), $aVideo['item_id'], $aVideo['user_id']) : null);
}
else{
((Phpfox::isModule('feed') && !defined('PHPFOX_SKIP_FEED_ENTRY')) ? $iFeedId = Phpfox::getService('feed.process')->add('ultimatevideo_video', $iVideoId, $aVideo['privacy'], 0, 0, $aVideo['user_id']) : null);
}
Phpfox::getService('user.activity')->update($iOwnerId, 'ultimatevideo_video', '+');
}
return true;
}
public function canDelete($aVideo)
{
$bPass = false;
if ($aVideo['video_id']) {
// Check if is owner of groups / pages
if ($aVideo['module_id'] == 'pages' && Phpfox::isModule('pages') && Phpfox::getService('pages')->isAdmin($aVideo['item_id'])) {
$bPass = true; // is owner of page
} elseif ($aVideo['module_id'] == 'groups' && Phpfox::isModule('groups') && Phpfox::getService('groups')->isAdmin($aVideo['item_id'])) {
$bPass = true; // is owner of page
}
elseif(user('ynuv_can_delete_video_of_other_user') || (Phpfox::getUserId() == $aVideo['user_id'] && user('ynuv_can_delete_own_video')))
{
$bPass = true;
}
}
return $bPass;
}
public function deleteVideo($iVideoId, $bForce = false)
{
$aVideo = $this->database()->select('*')
->from($this->_sTable)
->where("video_id =" . (int)$iVideoId)
->execute('getRow');
if ($bForce || $this->canDelete($aVideo)) {
if (Phpfox::isModule('tag')) {
Phpfox::getService('tag.process')->deleteForItem($aVideo['user_id'], $iVideoId, 'ynultimatevideo');
$this->cache()->remove('tag', 'substr');
$this->cache()->remove('ultimatevideo.video', 'substr');
}
if (!empty($aVideo['image_path'])) {
$sImagePath = $aVideo['image_path'];
$aImages = array(
Phpfox::getParam('core.dir_pic') . sprintf($sImagePath, '_120'),
Phpfox::getParam('core.dir_pic') . sprintf($sImagePath, '_250'),
Phpfox::getParam('core.dir_pic') . sprintf($sImagePath, '_500'),
Phpfox::getParam('core.dir_pic') . sprintf($sImagePath, '_1024')
);
foreach ($aImages as $sImage) {
if (file_exists($sImage)) {
@unlink($sImage);
}
if (Phpfox::getParam('core.allow_cdn') && $aVideo['image_server_id'] > 0) {
foreach ($aImages as $sImage) {
Phpfox::getLib('cdn')->remove($sImage);
}
}
}
}
if (!empty($aVideo['video_path'])) {
$sFilePath = 'ynultimatevideo/' . $aVideo['video_path'];
$aFiles = array(
Phpfox::getParam('core.dir_file') . sprintf($sFilePath, ''),
);
foreach ($aFiles as $sFile) {
if (file_exists($sFile)) {
@unlink($sFile);
}
}
if (Phpfox::getParam('core.allow_cdn') && $aVideo['video_server_id'] > 0) {
foreach ($aFiles as $sFile) {
Phpfox::getLib('cdn')->remove($sFile);
}
}
}
$this->database()->delete(Phpfox::getT('ynultimatevideo_ratings'), "video_id = " . (int)$iVideoId);
$aPlaylists = Phpfox::getService('ultimatevideo.playlist')->getAllPlaylistOfVideo($iVideoId);
if (!empty($aPlaylists)) {
foreach ($aPlaylists as $key => $aPlaylist) {
Phpfox::getService('ultimatevideo.playlist.process')->updateCountVideoForPlaylist($aPlaylist['playlist_id'],
'delete');
}
}
$this->database()->delete(Phpfox::getT('ynultimatevideo_playlist_data'), "video_id = " . (int)$iVideoId);
$this->database()->delete(Phpfox::getT('ynultimatevideo_history'),
"item_id = " . (int)$iVideoId . " AND item_type ='0'");
$this->database()->delete(Phpfox::getT('ynultimatevideo_favorites'), "video_id = " . (int)$iVideoId);
$this->database()->delete(Phpfox::getT('ynultimatevideo_watchlaters'), "video_id = " . (int)$iVideoId);
$this->database()->delete(Phpfox::getT('ynultimatevideo_custom_value'), "video_id = " . (int)$iVideoId);
$this->database()->delete($this->_sTable, "video_id = " . (int)$iVideoId);
(Phpfox::isModule('feed') ? Phpfox::getService('feed.process')->delete('ultimatevideo_video',
(int)$iVideoId) : null);
Phpfox::getService('tag.process')->deleteForItem(Phpfox::getUserId(), $iVideoId, 'ynultimatevideo');
$this->updateCountVideoForCategory($aVideo['category_id'], "delete");
$variable = user('ultimatevideo.points_ultimatevideo_video');
$checkInt = filter_var($variable, FILTER_VALIDATE_INT);
if ($checkInt && $variable > 0) {
Phpfox::getService('user.activity')->update($aVideo['user_id'], 'ultimatevideo_video', '-');
}
//Delete pages feed
if ($aVideo['module_id'] == 'pages') {
$sType = 'ultimatevideo_video';
$aFeeds = $this->database()->select('feed_id, user_id')
->from(Phpfox::getT($aVideo['module_id'] . '_feed'))
->where('type_id = \'' . $sType . '\' AND item_id = ' . (int)$iVideoId)
->execute('getRows');
if (count($aFeeds)) {
foreach ($aFeeds as $aFeed) {
$this->database()->delete(Phpfox::getT($aVideo['module_id'] . '_feed'),
'feed_id = ' . $aFeed['feed_id']);
}
}
}
}
return true;
}
public function updateCountVideoForCategory($iCategoryId, $sType)
{
$totalCount = $this->database()->select('used')
->from(Phpfox::getT('ynultimatevideo_category'))
->where('category_id = '.(int)$iCategoryId )
->execute('getSlaveField');
switch($sType)
{
case "add":
$totalCount = (int)$totalCount + 1;
$this->database()->update(Phpfox::getT('ynultimatevideo_category'),array('used' => $totalCount),'category_id = '.(int)$iCategoryId);
break;
case "delete":
$totalCount = (int)$totalCount - 1;
$this->database()->update(Phpfox::getT('ynultimatevideo_category'),array('used'=> $totalCount ),'category_id = '.(int)$iCategoryId);
break;
}
}
public function convertVideos()
{
$iLimit = setting('ynuv_cron_limit_per_time',5);
$aVideos = $this->database()->select('*')
->from($this->_sTable)
->where('status = 0 AND type = 3')
->limit($iLimit)
->order('time_stamp DESC')
->execute('getSlaveRows');
if(count($aVideos)){
foreach ($aVideos as $key => $aVideo) {
if(!empty($aVideo['user_token']) && $aVideo['allow_upload_channel'] == 1)
{
$this->uploadVideoToChannel($aVideo);
}
else
{
$this->_convertVideo($aVideo);
}
}
}
}
private function _convertVideo($aVideo)
{
if(isset($aVideo['vieo_id'])){
echo _p('argument_was_not_a_valid_video');
return;
}
// Make sure FFMPEG path is set
$ffmpeg_path = setting('ynuv_ffmpeg_path');
$status = 2;
if (!$ffmpeg_path)
{
echo _p('ffmpeg_not_configured');
return;
}
// Make sure FFMPEG can be run
if (!@file_exists($ffmpeg_path) || !@is_executable($ffmpeg_path))
{
$output = null;
$return = null;
exec($ffmpeg_path . ' -version', $output, $return);
if ($return > 0)
{
echo _p('ffmpeg_found_but_is_not_executable');
return;
}
}
// Check we can execute
if (!function_exists('shell_exec'))
{
echo _p('unable_to_execute_shell_commands_using_shell_exec_the_function_is_disabled');
return;
}
// Check the video directory
$tmpDir = PHPFOX_DIR_FILE . 'ynultimatevideo' . PHPFOX_DS;
if (!is_dir($tmpDir))
{
if (!mkdir($tmpDir, 0777, true))
{
echo _p('video_directory_did_not_exist_and_could_not_be_created');
return;
}
}
if (!is_writable($tmpDir))
{
echo _p('video_directory_is_not_writable');
return;
}
//2 video is in convert process
$this->updateStatusVideo(2,$aVideo['video_id']);
$filetype = $aVideo['code'];
$videoPath = Phpfox::getParam('core.dir_file').'ynultimatevideo/'.sprintf($aVideo['video_path'],'');
if (!file_exists($videoPath))
{
//4 file not found
$this->updateStatusVideo(4,$aVideo['video_id']);
echo _p('could_not_pull_to_temporary_file');
return;
}
// Get rotate
$ffprobe = str_replace('ffmpeg', 'ffprobe', $ffmpeg_path);
$cmd = $ffprobe . " " . $videoPath . " -show_streams 2>/dev/null";
$result = shell_exec($cmd);
$orientation = 0;
if (strpos($result, 'TAG:rotate') !== FALSE) {
$result = explode("\n", $result);
foreach ($result as $line) {
if (strpos($line, 'TAG:rotate') !== FALSE) {
$stream_info = explode("=", $line);
$orientation = $stream_info[1];
}
}
}
$iToken = rand();
if (!is_dir(PHPFOX_DIR_CACHE . 'ynultimatevideo'))
{
@mkdir(PHPFOX_DIR_CACHE . 'ynultimatevideo', 0777, 1);
@chmod(PHPFOX_DIR_CACHE . 'ynultimatevideo', 0777);
}
$outputPath = PHPFOX_DIR_CACHE . 'ynultimatevideo' . DIRECTORY_SEPARATOR . $iToken . '_' . PHPFOX_TIME . '_vconvert.mp4';
$thumbTempPath = PHPFOX_DIR_CACHE . 'ynultimatevideo' . DIRECTORY_SEPARATOR . $iToken . '_' . PHPFOX_TIME . '_vthumb_large.jpg';
//Convert to Mp4 (h264 - HTML5, mpeg4 - IOS)
$videoCommand = $ffmpeg_path . ' '
. '-i ' . escapeshellarg($videoPath) . ' '
. '-ab 64k' . ' '
. '-ar 44100' . ' '
. '-q:v 5' . ' '
. '-r 25' . ' ';
$videoCommand .= '-vcodec libx264' . ' '
. '-acodec aac' . ' '
. '-strict experimental' . ' '
. '-preset veryfast' . ' '
. '-f mp4' . ' ';
// Add rotate command
if ($orientation > 0)
{
$transpose = 1;
switch ($orientation)
{
case 90 :
$transpose = 1;

KT
This code does not work. It causes error. I tried it multiple times. Can the correct file be placed in the phpfox store product for easy download?