Cheetah
functions.inc.php
Go to the documentation of this file.
1 <?php
2 
8 function vcPrepareCommand($sTemplate, $aOptions)
9 {
10  foreach($aOptions as $sKey => $sValue)
11  $sTemplate = str_replace("#" . $sKey . "#", $sValue, $sTemplate);
12  return $sTemplate;
13 }
14 
15 function vcUsex264()
16 {
18  //return getSettingValue($sModule, "usex264") == TRUE_VAL;
19  return 'on' == getParam('usex264') ? true : false;
20 }
21 
22 function uploadFile($sFilePath, $sUserId)
23 {
26 
27  $sTempFileName = $sFilesPath . $sUserId . VC_TEMP_FILE_NAME;
28  @unlink($sTempFileName);
29 
30  if(is_uploaded_file($sFilePath)) {
31  move_uploaded_file($sFilePath, $sTempFileName);
32  @chmod($sTempFileName, 0666);
33  if(file_exists($sTempFileName) && filesize($sTempFileName)>0) {
34  $sDBModule = DB_PREFIX . ucfirst($sModule);
35  getResult("INSERT INTO `" . $sDBModule . "Files` SET `Date`='" . time() . "', `Owner`='" . $sUserId . "', `Status`='" . VC_STATUS_PENDING . "'");
36  $sFileId = getLastInsertId();
37  rename($sTempFileName, $sFilesPath . $sFileId);
38  return $sFileId;
39  }
40  }
41  return false;
42 }
43 
44 function publishRecordedVideoFile($sUserId)
45 {
48 
49  $sPlayFile = $sFilesPath . $sUserId . VC_TEMP_FILE_NAME . VC_FLV_EXTENSION;
50  if(file_exists($sPlayFile) && filesize($sPlayFile)>0) {
51  $sDBModule = DB_PREFIX . ucfirst($sModule);
52  getResult("INSERT INTO `" . $sDBModule . "Files` SET `Date`='" . time() . "', `Owner`='" . $sUserId .
53 "', `Status`='" . VC_STATUS_PENDING . "'");
54  $sFileId = getLastInsertId();
55  rename($sPlayFile, $sFilesPath . $sFileId);
56  @rename($sFilesPath . $sUserId . VC_TEMP_FILE_NAME . VC_IMAGE_EXTENSION, $sFilesPath . $sFileId . VC_IMAGE_EXTENSION);
57  @rename($sFilesPath . $sUserId . VC_TEMP_FILE_NAME . VC_THUMB_FILE_NAME . VC_IMAGE_EXTENSION, $sFilesPath . $sFileId . VC_THUMB_FILE_NAME . VC_IMAGE_EXTENSION);
58  return $sFileId;
59  } else return false;
60 }
61 
62 function initVideoFile($sId, $sTitle, $sCategory, $sTags, $sDesc)
63 {
66 
67  $sDBModule = DB_PREFIX . ucfirst($sModule);
68 
69  getResult("UPDATE `" . $sDBModule . "Files` SET `Categories`='" . $sCategory . "', `Title`='" . $sTitle . "', `Tags`='" . $sTags . "', `Description`='" . $sDesc . "' WHERE `ID`='" . $sId . "'");
70  return $oDb->getAffectedRows() > 0 ? true : false;
71 }
72 
73 function _getVideoSize($sInputFile)
74 {
76 
77  if(!file_exists($sInputFile) || filesize($sInputFile)==0) {
78  if(strpos($sInputFile, $sFilesPath) === FALSE) return $sInputFile;
79  else return VC_VIDEO_SIZE_16_9;
80  }
81 
82  $sFile = $sFilesPath . time() . VC_IMAGE_EXTENSION;
83  $sTmpl = vcPrepareCommand($GLOBALS['aConvertTmpls']['image'], array("input" => $sInputFile, "size" => "", "second" => 0, "output" => $sFile));
84  if(convertFile($sFile, $sTmpl)) {
85  $aSize = getimagesize($sFile);
86  @unlink($sFile);
87  $iRelation = $aSize[0]/$aSize[1];
88  $i169Dif = abs($iRelation - 16/9);
89  $i43Dif = abs($iRelation - 4/3);
90 
91  if($i169Dif > $i43Dif) return VC_VIDEO_SIZE_4_3;
92  else return VC_VIDEO_SIZE_16_9;
93  }
94  return VC_VIDEO_SIZE_16_9;
95 }
96 
97 function _getConverterTmpl($sInputFile, $sSize, $bSound = true)
98 {
100 
101  $bUsex264 = vcUsex264();
102  if($bSound)
103  $sSound = $bUsex264 ? " -acodec aac -strict experimental -b:a 128k -ar 44100 " : " -acodec libmp3lame -b:a 128k -ar 44100 ";
104  else
105  $sSound = " -an ";
106 
107  return vcPrepareCommand($GLOBALS['aConvertTmpls'][$bUsex264 ? 'playX264' : 'play'], array("input" => $sInputFile, "bitrate" => _getVideoBitrate(), "size" => _getVideoSize($sSize), "audio_options" => $sSound));
108 }
109 
111 {
113 
114  //$iBitrate = (int)getSettingValue($sModule, "bitrate");
115  $iBitrate = (int)getParam('videoBitrate');
116  if(!$iBitrate)
117  $iBitrate = 512;
118 
119  return $iBitrate;
120 }
121 
122 function convertFile($sFile, $sCommand)
123 {
124  popen($sCommand, "r");
125  if(file_exists($sFile))
126  @chmod($sFile, 0666);
127  return file_exists($sFile) && filesize($sFile) > 0;
128 }
129 
130 function _convertMain($sId, $sTmpl = "")
131 {
134 
135  $sTempFile = $sFilesPath . $sId;
136  $sResultFile = $sTempFile . (vcUsex264() ? VC_M4V_EXTENSION : VC_FLV_EXTENSION);
137 
138  $bResult = true;
139  if(!file_exists($sResultFile) || filesize($sResultFile)==0) {
140  if(empty($sTmpl))
141  $sTmpl = _getConverterTmpl($sTempFile, $sTempFile, true);
142  $sTmpl = vcPrepareCommand($sTmpl, array("output" => $sResultFile));
143  $bResult = convertFile($sResultFile, $sTmpl);
144  if(!$bResult) {
145  $sTmpl = _getConverterTmpl($sTempFile, $sTempFile, false);
146  $sTmpl = vcPrepareCommand($sTmpl, array("output" => $sResultFile));
147  $bResult = convertFile($sResultFile, $sTmpl);
148  }
149  }
150  if($bResult && vcUsex264())
151  $bResult = moveMp4Meta($sResultFile);
152  @chmod($sResultFile, 0666);
153  return $bResult && _grabImages($sResultFile, $sTempFile);
154 }
155 
156 function _convert($sId)
157 {
160 
161  $sTempFile = $sFilesPath . $sId;
162  $sSourceFile = $sTempFile;
163 
164  $bUseX264 = vcUsex264();
165  $sTmpl = vcPrepareCommand($GLOBALS['aConvertTmpls'][$bUseX264 ? "playX264" : "play"], array("bitrate" => _getVideoBitrate(), "audio_options" => $bUseX264 ? " -acodec aac -strict experimental -b:a 128k -ar 44100 " : " -acodec libmp3lame -b:a 128k -ar 44100 "));
166  if(file_exists($sTempFile) && filesize($sTempFile)>0)
167  $sTmpl = vcPrepareCommand($sTmpl, array("input" => $sTempFile, "size" => _getVideoSize($sTempFile)));
168  else {
169  $sSourceFile .= VC_FLV_EXTENSION;
170  if(file_exists($sSourceFile) && filesize($sSourceFile)>0)
171  $sTmpl = vcPrepareCommand($sTmpl, array("input" => $sSourceFile, "size" => _getVideoSize($sSourceFile)));
172  }
173  if(empty($sTmpl)) return false;
174 
175  $sDBModule = DB_PREFIX . ucfirst($sModule);
176  getResult("UPDATE `" . $sDBModule . "Files` SET `Date`='" . time() . "', `Status`='" . VC_STATUS_PROCESSING . "' WHERE `ID`='" . $sId . "'");
177 
178  $bResult = _convertMain($sId, $sTmpl);
179  if(!$bResult) return false;
180 
181  $oAlert = new ChWsbAlerts('ch_video_comments', 'convert', $sId, getLoggedId(), array(
182  'result' => &$bResult,
183  'ffmpeg' => $GLOBALS['sFfmpegPath'],
184  'tmp_file' => $sTempFile,
185  'bitrate' => _getVideoBitrate(),
186  'size' => _getVideoSize($sTempFile),
187  ));
188  $oAlert->alert();
189 
190  if($bResult) {
191  //$sAutoApprove = getSettingValue($sModule, "autoApprove") == TRUE_VAL ? VC_STATUS_APPROVED : VC_STATUS_DISAPPROVED;
192  $sAutoApprove = 'on' == getParam('videoAutoApprove') ? STATUS_APPROVED : STATUS_DISAPPROVED;
193  getResult("UPDATE `" . $sDBModule . "Files` SET `Date`='" . time() . "', `Status`='" . $sAutoApprove . "' WHERE `ID`='" . $sId . "'");
194  } else {
195  getResult("UPDATE `" . $sDBModule . "Files` SET `Status`='" . VC_STATUS_FAILED . "' WHERE `ID`='" . $sId . "'");
196  }
198  return $bResult;
199 }
200 
201 function _grabImages($sInputFile, $sOutputFile, $iSecond = 0, $bForse = false)
202 {
203  $sImageFile = $sOutputFile . VC_IMAGE_EXTENSION;
204  $sThumbFile = $sOutputFile . VC_THUMB_FILE_NAME . VC_IMAGE_EXTENSION;
205 
206  if(!$bForse && file_exists($sImageFile) && filesize($sImageFile)>0) $bResult = true;
207  else $bResult = convertFile($sImageFile, _getGrabImageTmpl($sInputFile, $sImageFile, "", $iSecond));
208  if(!$bResult) return false;
209 
210  if(!$bForse && file_exists($sThumbFile) && filesize($sThumbFile)>0) $bResult = true;
211  else $bResult = convertFile($sThumbFile, _getGrabImageTmpl($sInputFile, $sThumbFile, "-s " . VC_THUMB_SIZE, $iSecond));
212  return $bResult;
213 }
214 
215 function _getGrabImageTmpl($sInputFile, $sOutputFile, $sSize = "", $iSecond = 0)
216 {
217  global $aConvertTmpls;
218 
219  return vcPrepareCommand($aConvertTmpls["image"], array("input" => $sInputFile, "second" => $iSecond, "size" => (empty($sSize) ? "" : $sSize), "output" => $sOutputFile));
220 }
221 
222 function _deleteTempFiles($sUserId, $bSourceOnly = false)
223 {
225 
226  $sTempFile = $sUserId . VC_TEMP_FILE_NAME;
227  @unlink($sFilesPath . $sTempFile);
228  if($bSourceOnly) return;
229  @unlink($sFilesPath . $sTempFile . VC_IMAGE_EXTENSION);
230  @unlink($sFilesPath . $sTempFile . VC_THUMB_FILE_NAME . VC_IMAGE_EXTENSION);
231  @unlink($sFilesPath . $sTempFile . VC_FLV_EXTENSION);
232  @unlink($sFilesPath . $sTempFile . VC_M4V_EXTENSION);
233 }
234 
241 {
244  $sDBModule = DB_PREFIX . ucfirst($sModule);
245 
246  getResult("DELETE FROM `" . $sDBModule . "Files` WHERE `ID`='" . $sFile . "'");
247 
248  $sFileName = $sFilesPath . $sFile;
249  @unlink($sFileName);
250  @unlink($sFileName . VC_MOBILE_EXTENSION);
251  $bResult = (@unlink($sFileName . VC_FLV_EXTENSION) || @unlink($sFileName . VC_M4V_EXTENSION)) &&
252  @unlink($sFileName . VC_IMAGE_EXTENSION) &&
253  @unlink($sFileName . VC_THUMB_FILE_NAME . VC_IMAGE_EXTENSION);
254 
255  $oAlert = new ChWsbAlerts('ch_video_comments', 'delete', $sFile, getLoggedId(), array(
256  'result' => &$bResult,
257  'files_path' => $sFilesPath,
258  ));
259  $oAlert->alert();
260 
261  return $bResult;
262 }
263 
264 function _getToken($sId)
265 {
267 
268  if(file_exists($sFilesPath . $sId . VC_FLV_EXTENSION) || file_exists($sFilesPath . $sId . VC_M4V_EXTENSION)) {
269  $iCurrentTime = time();
270  $sToken = md5($iCurrentTime);
271  getResult("INSERT INTO `" . MODULE_DB_PREFIX . "Tokens`(`ID`, `Token`, `Date`) VALUES('" . $sId . "', '" . $sToken . "', '" . $iCurrentTime . "')");
272  return $sToken;
273  }
274  return "";
275 }
getLastInsertId
getLastInsertId()
Definition: db.inc.php:66
$sToken
$sToken
Definition: get_file.php:13
_getVideoBitrate
_getVideoBitrate()
Definition: functions.inc.php:110
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
_getVideoSize
_getVideoSize($sInputFile)
Definition: functions.inc.php:73
publishRecordedVideoFile
publishRecordedVideoFile($sUserId)
Definition: functions.inc.php:44
_convert
_convert($sId)
Definition: functions.inc.php:156
$oAlert
$oAlert
Definition: embed.php:15
php
$sModule
if(!file_exists($sRayHeaderPath)) $sModule
Definition: index.php:14
_getToken
_getToken($sId)
Definition: functions.inc.php:264
_deleteTempFiles
_deleteTempFiles($sUserId, $bSourceOnly=false)
Definition: functions.inc.php:222
ChWsbAlerts
Definition: ChWsbAlerts.php:39
$sFile
$sFile
Definition: index.php:20
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
initVideoFile
initVideoFile($sId, $sTitle, $sCategory, $sTags, $sDesc)
Definition: functions.inc.php:62
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$sTitle
$sTitle
Definition: actions.inc.php:13
_getConverterTmpl
_getConverterTmpl($sInputFile, $sSize, $bSound=true)
Definition: functions.inc.php:97
$sTags
$sTags
Definition: actions.inc.php:12
$oDb
global $oDb
Definition: db.inc.php:39
vcPrepareCommand
vcPrepareCommand($sTemplate, $aOptions)
Definition: functions.inc.php:8
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
$bResult
$bResult
Definition: get_file.php:11
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
_deleteFile
_deleteFile($sFile)
Definition: functions.inc.php:240
_getGrabImageTmpl
_getGrabImageTmpl($sInputFile, $sOutputFile, $sSize="", $iSecond=0)
Definition: functions.inc.php:215
_grabImages
_grabImages($sInputFile, $sOutputFile, $iSecond=0, $bForse=false)
Definition: functions.inc.php:201
$sDBModule
$sDBModule
Definition: header.inc.php:26
moveMp4Meta
moveMp4Meta($sFilePath)
Definition: apiFunctions.inc.php:268
$sId
$sId
Definition: actions.inc.php:8
convertFile
convertFile($sFile, $sCommand)
Definition: functions.inc.php:122
$sFilesPath
$sFilesPath
Definition: header.inc.php:10
vcUsex264
vcUsex264()
Definition: functions.inc.php:15
_convertMain
_convertMain($sId, $sTmpl="")
Definition: functions.inc.php:130
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$sDesc
$sDesc
Definition: actions.inc.php:21
uploadFile
uploadFile($sFilePath, $sUserId)
Definition: functions.inc.php:22
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbDb\getInstance
static getInstance()
Definition: ChWsbDb.php:82
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
getResult
getResult($sQuery)
Definition: db.inc.php:45