Cheetah
ChVideosUploader.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbFilesUploader');
9 ch_import('ChWsbCategories');
10 ch_import('ChWsbAlbums');
11 ch_import('ChWsbModule');
12 
18 require_once($sIncPath . 'db.inc.php');
19 
20 $sModule = "video";
22 
24 require_once($sModulesPath . $sModule . '/inc/header.inc.php');
25 require_once($sModulesPath . $sModule . '/inc/constants.inc.php');
26 require_once($sModulesPath . $sModule . '/inc/functions.inc.php');
27 require_once($sModulesPath . $sModule . '/inc/customFunctions.inc.php');
28 
30 {
31  // constructor
32  function __construct()
33  {
34  parent::__construct('Video');
35 
36  $this->oModule = ChWsbModule::getInstance('ChVideosModule');
37  $this->sWorkingFile = CH_WSB_URL_ROOT . $this->oModule->_oConfig->getBaseUri() . 'albums/my/add_objects';
38 
39  $iMaxByAdmin = 1024*1024*(int)getParam($this->oModule->_oConfig->getMainPrefix() . '_max_file_size');
40  if ($iMaxByAdmin > 0 && $iMaxByAdmin < $this->iMaxFilesize)
41  $this->iMaxFilesize = $iMaxByAdmin;
42 
43  $this->sAcceptMimeType = '*';
44  }
45 
46  function getEmbedFormFile()
47  {
48  return $this->_getEmbedFormFile();
49  }
50 
51  function getRecordFormFile($aExtras)
52  {
53  $sCustomRecorderObject = getApplicationContent('video', 'recorder', array('user' => $this->_getAuthorId(), 'password' => $this->_getAuthorPassword(), 'extra' => ''), true);
54  return $this->_getRecordFormFile($sCustomRecorderObject, $aExtras);
55  }
56 
57  function GenSendFileInfoForm($iFileID, $aDefaultValues = array())
58  {
59  $sVideoUrl = "";
60  if(isset($aDefaultValues['image']))
61  $sVideoUrl = $aDefaultValues['image'];
62  else if(!empty($iFileID)) {
63  $aVideoInfo = ChWsbService::call('videos', 'get_video_array', array($iFileID), 'Search');
64  $sVideoUrl = $aVideoInfo['file'];
65  }
66 
67  $sVideoUrl .= (false === strpos($sVideoUrl, '?') ? '?' : '&') . '_t=' . time();
68 
69  $sProtoEl = '<img src="' . $sVideoUrl . '" />';
70 
71  $aPossibleImage = array();
72  $aPossibleImage['preview_image'] = array(
73  'type' => 'custom',
74  'content' => $sProtoEl,
75  'caption' => _t('_ch_videos_preview'),
76  );
77 
78  $aPossibleDuration = array();
79  $aPossibleDuration['duration'] = array(
80  'type' => 'hidden',
81  'name' => 'duration',
82  'value' => isset($aDefaultValues['duration']) ? $aDefaultValues['duration'] : "0"
83  );
84 
85  return $this->_GenSendFileInfoForm($iFileID, $aDefaultValues, $aPossibleImage, $aPossibleDuration);
86  }
87 
89  {
90  if ($bRet = parent::serviceCancelFileInfo())
91  deleteVideo($iFileID, $this->oModule->_oConfig->aFilesConfig);
92  return $bRet;
93  }
94 
95  function servicePerformVideoUpload($sFilePath, $aInfo, $isMoveUploadedFile = false)
96  {
97  $a = $this->performUpload ($sFilePath, $sRealFilename, $aInfo, $isMoveUploadedFile);
98 
99  return isset($a['id']) && $a['id'] ? $a['id'] : false;
100  }
101 
103  {
104  $sResult = $this->_recordVideo();
105  return ($sResult!='') ? $this->GenJquieryInjection() . $sResult : '';
106  }
107 
109  {
110  $sErrorReturn = '<script type="text/javascript">parent.' . $this->_sJsPostObject . '.showErrorMsg("video_embed_failed_message");parent.' . $this->_sJsPostObject . '.resetEmbed();</script>';
111  $sVideoId = substr(trim($_POST['embed']), -11);
112  if(empty($sVideoId)) return $sErrorReturn;
113 
114  $aSiteInfo = getSiteInfo('https://www.youtube.com/watch?v=' . $sVideoId, array(
115  'name' => array(),
116  'duration' => array(),
117  'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
118  ));
119 
120  $aSiteInfo['duration'] = ch_parse_time_duration($aSiteInfo['duration']);
121 
122  $sTitle = $aSiteInfo['name'];
123  $sDesc = $aSiteInfo['description'];
124  $sTags = $aSiteInfo['keywords'];
125  $sImage = $aSiteInfo['thumbnailUrl'];
126  $iDuration = (int)$aSiteInfo['duration'];
127 
128  if(empty($sTitle)) return $sErrorReturn;
129 
130  $sResult = $this->_embedVideo($sVideoId, $sTitle, $sDesc, $sTags, $sImage, $iDuration);
131  return ($sResult!='') ? $this->GenJquieryInjection() . $sResult : '';
132  }
133 
135  {
137  $iAuthorId = $this->_getAuthorId();
138  $sJSVideoId = (int)$_POST['file_id'];
139  switch($_POST['type']) {
140  case 'embed':
141  $iVideoID = (int)embedVideo($iAuthorId, $_POST['video'], $_POST['duration'], $this->oModule->_oConfig->aFilesConfig);
142  $bUpdateCounter = getSettingValue($sModule, "autoApprove") == TRUE_VAL ? true : false;
143  $this->addObjectToAlbum($this->oModule->oAlbums, $_POST['extra_param_album'], $iVideoID, $bUpdateCounter);
144  break;
145  case 'record':
146  $iVideoID = (int)recordVideo($iAuthorId);
147  $this->addObjectToAlbum($this->oModule->oAlbums, $_POST['extra_param_album'], $iVideoID, false);
148  break;
149  case 'upload':
150  default:
151  $iVideoID = $sJSVideoId;
152  break;
153  }
154 
155  if ($iVideoID && $iAuthorId) {
156  $sTitle = $_POST['title'];
157  $sTags = $_POST['tags'];
158  $sDescription = $_POST['description'];
159 
160  $aCategories = array();
161  foreach ($_POST['Categories'] as $sKey => $sVal) {
162  if ($sVal != '')
163  $aCategories[] = $sVal;
164  }
165  $sCategories = implode(CATEGORIES_DIVIDER, $aCategories);
166 
167  if ($this->initFile($iVideoID, $sTitle, $sCategories, $sTags, $sDescription)) {
168  $this->alertAdd($iVideoID);
169  return '<script type="text/javascript">parent.' . $this->_sJsPostObject . '.onSuccessSendingFileInfo("' . $sJSVideoId . '");</script>';
170  }
171  }
172  return '<script type="text/javascript">parent.' . $this->_sJsPostObject . '.showErrorMsg("video_failed_message");</script>';
173  }
174 
175  function _embedVideo($sVideoId, $sTitle, $sDesc, $sTags, $sImage, $iDuration)
176  {
177  $sAuthorCheck = $this->checkAuthorBeforeAdd();
178  if(empty($sAuthorCheck)) {
179  $sEmbedThumbUrl = getEmbedThumbnail($this->_getAuthorId(), $sImage, $this->oModule->_oConfig->aFilesConfig);
180  if($sEmbedThumbUrl) {
181  $this->oModule->isAllowedAdd(true);
182  $aDefault = array('video' => $sVideoId, 'title' => $sTitle, 'description' => $sDesc, 'tags' => $sTags, 'duration' => $iDuration, 'image' => $sEmbedThumbUrl, 'type' => "embed");
183  return $this->GenSendFileInfoForm(1, $aDefault);
184  } else
185  return $this->getFileAddError();
186  } else
187  return $sAuthorCheck;
188  }
189 
190  function _recordVideo()
191  {
192  $sAuthorCheck = $this->checkAuthorBeforeAdd();
193  if(empty($sAuthorCheck)) {
194  $sRecordThumbUrl = getRecordThumbnail($this->_getAuthorId());
195  if($sRecordThumbUrl) {
196  $this->oModule->isAllowedAdd(true);
197  $aDefault = array('image' => $sRecordThumbUrl, 'type' => "record");
198  return $this->GenSendFileInfoForm(1, $aDefault);
199  } else
200  return $this->getFileAddError();
201  } else
202  return $sAuthorCheck;
203  }
204 
210  function performUpload ($sFilePath, $sRealFilename = '', $aInfo = array(), $isMoveUploadedFile = true, $aExtraParams = array())
211  {
212  $bUpdateAlbumCounter = false;
213  $iOwner = $this->_getAuthorId();
214  if ($this->_iOwnerId)
215  $iOwner = $this->oModule->_iProfileId = $this->_iOwnerId;
216 
217  if (!$sRealFilename)
218  $sRealFilename = pathinfo($sFilePath, PATHINFO_BASENAME);
219 
220  // basic checking before upload
221 
222  if ($this->checkAuthorBeforeAdd())
223  return array('error' => _t('_LOGIN_REQUIRED_AE1'));
224 
225  if (!$this->oModule->_oConfig->checkAllowedExtsByFilename($sRealFilename))
226  return array('error' => _t('_sys_txt_wrong_file_extension'));
227 
228  if (!$this->oModule->isAllowedAdd())
229  return array('error' => _t('_Access denied'));
230 
231  // perform upload
232 
233  $GLOBALS['sModule'] = 'video';
234  include($GLOBALS['sModulesPath'] . $GLOBALS['sModule'] . '/inc/header.inc.php');
235 
236  $this->sTempFilename = pathinfo($sRealFilename, PATHINFO_FILENAME);
237  if (!($iMID = uploadVideo(process_db_input($sFilePath), $iOwner, $isMoveUploadedFile, '', process_db_input($sRealFilename), $this->oModule->_oConfig->aFilesConfig)))
238  return array('error' => _t('_sys_txt_upload_failed'));
239 
240  // See if uploaded file is a h264 video. If so, change status and rename the file.
241 
242  $sFile1 = $GLOBALS['dir']['root'] . 'flash/modules/video/files/' . $iMID;
243  $sFile2 = $GLOBALS['dir']['root'] . 'flash/modules/video/files/' . $iMID . '.m4v';
244  $aVideoData = getVideoData($sFile1);
245  if($aVideoData['CodecName'] == 'h264') {
246  $sAutoApprove = 'on' == getParam('videoAutoApprove') ? 'approved' : 'disapproved';
247  rename($sFile1, $sFile2);
248  $aData = array(
249  'Time' => (int)$aVideoData['Duration']*1000,
250  //'Width' => $aVideoData['VideoWidth'],
251  //'Height' => $aVideoData['VideoHeight'],
252  //'AvgFrameRate' => $aVideoData['AvgFrameRate'],
253  //'BitRate' => $aVideoData['BitRate'],
254  'Status' => $sAutoApprove,
255  );
256  $this->oModule->_oDb->updateVideo($iMID, $aData);
257  $bUpdateAlbumCounter = true;
258  } else {
259  $this->oModule->_oDb->updateVideo($iMID, array('Status' => 'pending'));
260  }
261 
262  // update uploaded file info if needed
263 
264  if ($aInfo) {
265  foreach (array('title', 'categories', 'tags', 'desc') as $sKey)
266  $aInfo[$sKey] = isset($aInfo[$sKey]) ? $aInfo[$sKey] : '';
267 
268  $this->initFile($iMID, $aInfo['title'], $aInfo['categories'], $aInfo['tags'], $aInfo['desc']);
269  }
270 
271  // add uploaded file to the album
272 
273  $sAlbum = empty($_POST['extra_param_album']) ? getParam('sys_album_default_name') : $_POST['extra_param_album'];
274  $aAlbumParams = isset($_POST['extra_param_albumPrivacy']) ? array('privacy' => (int)$_POST['extra_param_albumPrivacy']) : array();
275  $this->addObjectToAlbum($this->oModule->oAlbums, !empty($aInfo['album']) ? $aInfo['album'] : $sAlbum, $iMID, $bUpdateAlbumCounter, $iOwner, $aAlbumParams);
276 
277  // perfom action
278 
279  $this->oModule->isAllowedAdd(true, true);
280 
281  // return uploaded file ID
282 
283  return array('id' => $iMID);
284  }
285 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
$sModulePath
$sModulePath
Definition: ChVideosUploader.php:21
$sModulesPath
global $sModulesPath
Definition: ChVideosUploader.php:14
ChWsbFilesUploader
Definition: ChWsbFilesUploader.php:13
ChWsbFilesUploader\initFile
initFile($iMedID, $sTitle, $sCategories='', $sTags='', $sDesc='', $aCustom=array())
Definition: ChWsbFilesUploader.php:940
ChWsbFilesUploader\addObjectToAlbum
addObjectToAlbum(&$oAlbums, $sAlbumUri, $iObjId, $bUpdateCounter=true, $iAuthorId=0, $aAlbumParams=array())
Definition: ChWsbFilesUploader.php:833
ChVideosUploader\serviceCancelFileInfo
serviceCancelFileInfo()
Definition: ChVideosUploader.php:88
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
ChWsbModule\getInstance
static getInstance($sClassName)
Definition: ChWsbModule.php:89
getSiteInfo
getSiteInfo($sSourceUrl, $aProcessAdditionalTags=array())
Definition: utils.inc.php:1460
ChWsbFilesUploader\_getRecordFormFile
_getRecordFormFile($sCustomRecorderObject='', $aExtras=array())
Definition: ChWsbFilesUploader.php:273
uploadVideo
uploadVideo($sFilePath, $sUserId, $isMoveUploadedFile=false, $sImageFilePath='', $sFileName='', $aFilesConfig=array())
Definition: functions.inc.php:99
$sResult
$sResult
Definition: advanced_settings.php:26
ChWsbFilesUploader\checkAuthorBeforeAdd
checkAuthorBeforeAdd()
Definition: ChWsbFilesUploader.php:395
ChVideosUploader\GenSendFileInfoForm
GenSendFileInfoForm($iFileID, $aDefaultValues=array())
Definition: ChVideosUploader.php:57
ChWsbFilesUploader\getFileAddError
getFileAddError($sMessage='')
Definition: ChWsbFilesUploader.php:1008
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
php
ChVideosUploader\_recordVideo
_recordVideo()
Definition: ChVideosUploader.php:190
$sFilesUrl
global $sFilesUrl
Definition: ChVideosUploader.php:16
recordVideo
recordVideo($sUserId, $aFilesConfig=array())
Definition: functions.inc.php:77
ChVideosUploader
Definition: ChVideosUploader.php:30
CATEGORIES_DIVIDER
const CATEGORIES_DIVIDER
Definition: ChWsbCategories.php:10
$aInfo
$aInfo
Definition: constants.inc.php:21
ChVideosUploader\__construct
__construct()
Definition: ChVideosUploader.php:32
ChWsbFilesUploader\_GenSendFileInfoForm
_GenSendFileInfoForm( $iFileID, $aDefaultValues=array(), $aPossibleImage=array(), $aPossibleDuration=array())
Definition: ChWsbFilesUploader.php:669
ChWsbFilesUploader\$_iOwnerId
$_iOwnerId
Definition: ChWsbFilesUploader.php:14
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChVideosUploader\getRecordFormFile
getRecordFormFile($aExtras)
Definition: ChVideosUploader.php:51
$sTitle
$sTitle
Definition: actions.inc.php:13
ChVideosUploader\getEmbedFormFile
getEmbedFormFile()
Definition: ChVideosUploader.php:46
$sTags
$sTags
Definition: actions.inc.php:12
$sFilesPath
global $sFilesPath
Definition: ChVideosUploader.php:15
ChWsbFilesUploader\alertAdd
alertAdd($iMedID, $bCheckPrivacy=false)
Definition: ChWsbFilesUploader.php:972
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
getApplicationContent
getApplicationContent($sModule, $sApp, $aParamValues=array(), $bInline=false, $bEmbedCode=false, $sHtmlId="")
Definition: content.inc.php:166
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
ChWsbFilesUploader\GenJquieryInjection
GenJquieryInjection()
Definition: ChWsbFilesUploader.php:331
ChVideosUploader\serviceAcceptRecordFile
serviceAcceptRecordFile()
Definition: ChVideosUploader.php:102
ch_parse_time_duration
ch_parse_time_duration($sContent)
Definition: utils.inc.php:1522
deleteVideo
deleteVideo($sFile, $aFilesConfig=array())
Definition: functions.inc.php:405
ChWsbFilesUploader\_getEmbedFormFile
_getEmbedFormFile()
Definition: ChWsbFilesUploader.php:216
$sModulesUrl
global $sModulesUrl
Definition: ChVideosUploader.php:23
getRecordThumbnail
getRecordThumbnail($sUserId)
Definition: functions.inc.php:42
ChVideosUploader\servicePerformVideoUpload
servicePerformVideoUpload($sFilePath, $aInfo, $isMoveUploadedFile=false)
Definition: ChVideosUploader.php:95
ChVideosUploader\_embedVideo
_embedVideo($sVideoId, $sTitle, $sDesc, $sTags, $sImage, $iDuration)
Definition: ChVideosUploader.php:175
ChVideosUploader\serviceAcceptEmbedFile
serviceAcceptEmbedFile()
Definition: ChVideosUploader.php:108
getSettingValue
getSettingValue($sWidget, $sSettingKey, $sFile="config", $bFullReturn=false, $sFolder="xml")
Definition: apiFunctions.inc.php:82
$sIncPath
global $sIncPath
Definition: ChVideosUploader.php:13
embedVideo
embedVideo($sUserId, $sVideoId, $iDuration, $aFilesConfig=array())
Definition: functions.inc.php:54
ChWsbFilesUploader\_getAuthorId
_getAuthorId()
Definition: ChWsbFilesUploader.php:102
$sModule
$sModule
Definition: ChVideosUploader.php:20
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChVideosUploader\performUpload
performUpload($sFilePath, $sRealFilename='', $aInfo=array(), $isMoveUploadedFile=true, $aExtraParams=array())
Definition: ChVideosUploader.php:210
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
$sDesc
$sDesc
Definition: actions.inc.php:21
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbFilesUploader\_getAuthorPassword
_getAuthorPassword()
Definition: ChWsbFilesUploader.php:107
ChVideosUploader\serviceAcceptFileInfo
serviceAcceptFileInfo()
Definition: ChVideosUploader.php:134
$oDb
global $oDb
Definition: ChVideosUploader.php:17
getEmbedThumbnail
getEmbedThumbnail($sUserId, $sImageUrl, $aFilesConfig=array())
Definition: functions.inc.php:22
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
getVideoData
getVideoData($sFile)
Definition: utils.inc.php:2008