Cheetah
functions.inc.php
Go to the documentation of this file.
1 <?php
2 
8 function uploadMusic($sFilePath, $sUserId, $sFileName, $bUploaded = true)
9 {
12 
13  $bMp3 = strtolower(substr($sFileName, -4)) == MP3_EXTENSION;
14  $sTempFileName = $sFilesPathMp3 . $sUserId . TEMP_FILE_NAME;
15  @unlink($sTempFileName);
16 
17  if(file_exists($sFilePath)) {
18  if(is_uploaded_file($sFilePath))
19  move_uploaded_file($sFilePath, $sTempFileName);
20  else copy($sFilePath, $sTempFileName);
21  @chmod($sTempFileName, 0644);
22  if(file_exists($sTempFileName) && filesize($sTempFileName)>0) {
23  $sDBModule = DB_PREFIX . ucfirst($sModule);
24  $sStatus = STATUS_PENDING;
25  $sExtension = "";
26  /*
27  if($bMp3) {
28  $sStatus = getSettingValue($sModule, "autoApprove") == TRUE_VAL ? STATUS_APPROVED : STATUS_DISAPPROVED;
29  $sExtension = MP3_EXTENSION;
30  }
31  */
32  $sUri = mp3_genUri($sFileName);
33  $sUriPart = empty($sUri) ? "" : "`Uri`='" . $sUri . "', ";
34 
35  getResult("INSERT INTO `" . $sDBModule . "Files` SET `Title`='" . $sFileName . "', " . $sUriPart . "`Description`='" . $sFileName . "', `Date`='" . time() . "', `Owner`='" . $sUserId . "', `Status`='" . $sStatus . "'");
36  $sFileId = getLastInsertId();
37  rename($sTempFileName, $sFilesPathMp3 . $sFileId . $sExtension);
38  return $sFileId;
39  }
40  }
41  return false;
42 }
43 
44 function checkRecord($sUserId)
45 {
47  $sFilePath = $sFilesPathMp3 . $sUserId . TEMP_FILE_NAME . MP3_EXTENSION;
48  return file_exists($sFilePath) && filesize($sFilePath) > 0;
49 }
50 
51 function publishRecordedFile($sUserId, $sTitle, $sCategory, $sTags, $sDesc)
52 {
55 
56  $sTempFile = $sFilesPathMp3 . $sUserId . TEMP_FILE_NAME;
57  $sPlayFile = $sTempFile . MP3_EXTENSION;
58  if(file_exists($sPlayFile) && filesize($sPlayFile)>0) {
59  $sDBModule = DB_PREFIX . ucfirst($sModule);
60  $sUri = mp3_genUri($sTitle);
61  $sUriPart = empty($sUri) ? "" : "`Uri`='" . $sUri . "', ";
62  //$sAutoApprove = getSettingValue($sModule, "autoApprove") == TRUE_VAL ? STATUS_APPROVED : STATUS_DISAPPROVED;
63  $sAutoApprove = 'on' == getParam('audioAutoApprove') ? STATUS_APPROVED : STATUS_DISAPPROVED;
64  getResult("INSERT INTO `" . $sDBModule . "Files` SET `Categories`='" . $sCategory . "', `Title`='" . $sTitle . "', " . $sUriPart . "`Tags`='" . $sTags . "', `Description`='" . $sDesc . "', `Date`='" . time() . "', `Owner`='" . $sUserId . "', `Status`='" . $sAutoApprove . "'");
65  $sFileId = getLastInsertId();
66  rename($sPlayFile, $sFilesPathMp3 . $sFileId . MP3_EXTENSION);
67 
68  $aFilesConfig = ChWsbService::call('sounds', 'get_files_config');
69  foreach ($aFilesConfig as $a)
70  if (isset($a['image']) && $a['image'])
71  @rename($sTempFile . $a['postfix'], $sFilesPathMp3 . $sFileId . $a['postfix']);
72 
73  return $sFileId;
74  }
75 
76  return false;
77 }
78 
79 function initFile($sId, $sTitle, $sCategory, $sTags, $sDesc)
80 {
82 
84 
85  $sUri = mp3_genUri($sTitle);
86  $sUriPart = empty($sUri) ? "" : "`Uri`='" . $sUri . "', ";
87 
88  $sDBModule = DB_PREFIX . ucfirst($sModule);
89 
90  getResult("UPDATE `" . $sDBModule . "Files` SET `Categories`= ?, `Title`= ?, " . $sUriPart . "`Tags`= ?, `Description`= ? WHERE `ID`= ?", [
91  $sCategory,
92  $sTitle,
93  $sTags,
94  $sDesc,
95  $sId
96  ]);
97 
98  return $oDb->getAffectedRows() > 0 ? true : false;
99 }
100 
101 function convertMain($sId)
102 {
106 
107  $sTempFile = $sFilesPathMp3 . $sId;
108 
109  if(!file_exists($sTempFile)) $sTempFile .= TEMP_FILE_NAME;
110  $sPlayFile = $sTempFile . MP3_EXTENSION;
111 
112  $aBitrates = array(64, 96, 128, 192, 256);
113  //$iBitrate = (int)getSettingValue($sModule, "convertBitrate");
114  $iBitrate = (int)getParam($sModule, "audioBitrate");
115  if(!in_array($iBitrate, $aBitrates))
116  $iBitrate = 128;
117 
118  $sCommand = $sFfmpegPath . " -y -i " . $sTempFile . " -vn -ar 44100 -ab " . $iBitrate . "k " . $sPlayFile;
119  popen($sCommand, "r");
120 
121  $bResult = file_exists($sPlayFile) && filesize($sPlayFile) > 0;
122  if($bResult) @unlink($sTempFile);
123 
124  $sOverride = false;
125  $oAlert = new ChWsbAlerts('ch_sounds', 'convert', $sId, getLoggedId(), array(
126  'result' => &$bResult,
127  'ffmpeg' => $sFfmpegPath,
128  'tmp_file' => $sTempFile,
129  'bitrate' => $iBitrate,
130  ));
131  $oAlert->alert();
132 
133  return $bResult;
134 }
135 
136 function convert($sId)
137 {
141 
142  $sDBModule = DB_PREFIX . ucfirst($sModule);
143  getResult("UPDATE `" . $sDBModule . "Files` SET `Date`='" . time() . "', `Status`='" . STATUS_PROCESSING . "' WHERE `ID`='" . $sId . "'");
144 
146 
147  if($bResult) {
148  //$sAutoApprove = getSettingValue($sModule, "autoApprove") == TRUE_VAL ? STATUS_APPROVED : STATUS_DISAPPROVED;
149  $sAutoApprove = 'on' == getParam('audioAutoApprove') ? STATUS_APPROVED : STATUS_DISAPPROVED;
150  getResult("UPDATE `" . $sDBModule . "Files` SET `Date`='" . time() . "', `Status`='" . $sAutoApprove . "' WHERE `ID`='" . $sId . "'");
151  } else {
152  getResult("UPDATE `" . $sDBModule . "Files` SET `Status`='" . STATUS_FAILED . "' WHERE `ID`='" . $sId . "'");
153  }
154  return $bResult;
155 }
156 
158 {
159  return round(round(filesize($sFile) / (1024 * 1024), 3) * 60000, 0);
160 }
161 
162 function renameFile($sUserId, $sFileId)
163 {
165 
166  $aFilesConfig = ChWsbService::call('sounds', 'get_files_config');
167  foreach ($aFilesConfig as $a)
168  if (isset($a['image']) && $a['image'])
169  @rename($sFilesPathMp3 . $sUserId . TEMP_FILE_NAME . $a['postfix'], $sFilesPathMp3 . $sFileId . $a['postfix']);
170 
171  $sTempFile = $sFilesPathMp3 . $sUserId . TEMP_FILE_NAME . MP3_EXTENSION;
172  return rename($sTempFile, $sFilesPathMp3 . $sFileId . MP3_EXTENSION);
173 }
174 
175 function deleteTempMp3s($sUserId, $bSourceOnly = false)
176 {
178 
179  $sTempFile = $sUserId . TEMP_FILE_NAME;
180  @unlink($sFilesPathMp3 . $sTempFile);
181  if($bSourceOnly) return;
182  @unlink($sFilesPathMp3 . $sTempFile . MP3_EXTENSION);
183 
184  $aFilesConfig = ChWsbService::call('sounds', 'get_files_config');
185  foreach ($aFilesConfig as $a)
186  if (isset($a['image']) && $a['image'])
187  @unlink($sFilesPathMp3 . $sTempFile . $a['postfix']);
188 }
189 
196 {
199  $sDBModule = DB_PREFIX . ucfirst($sModule);
201  $sDBModule = DB_PREFIX . ucfirst($sModule);
202 
203  getResult("DELETE FROM `" . $sDBModule . "Files` WHERE `ID`='" . $sFile . "'");
204  getResult("DELETE FROM `" . $sDBModule . "PlayLists` WHERE `FileId`='" . $sFile . "'");
206  $sFileName = $sFilesPathMp3 . $sFile . MP3_EXTENSION;
207  $bResult = @unlink($sFileName);
208  return $bResult;
209 }
210 
211 function getMp3Token($sId)
212 {
215  $sDBModule = DB_PREFIX . ucfirst($sModule);
216 
217  if(file_exists($sFilesPathMp3 . $sId . MP3_EXTENSION)) {
218  $iCurrentTime = time();
219  $sToken = md5($iCurrentTime);
220  getResult("INSERT INTO `" . $sDBModule . "Tokens`(`ID`, `Token`, `Date`) VALUES('" . $sId . "', '" . $sToken . "', '" . $iCurrentTime . "')");
221  return $sToken;
222  }
223  return "";
224 }
getLastInsertId
getLastInsertId()
Definition: db.inc.php:66
$sFilesPathMp3
global $sFilesPathMp3
Definition: ChWsbCronMp3.php:19
mp3_parseTags
mp3_parseTags($iId)
Definition: customFunctions.inc.php:16
mp3_genUri
mp3_genUri($s)
Definition: customFunctions.inc.php:21
$sToken
$sToken
Definition: get_file.php:13
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
convert
convert($sId)
Definition: functions.inc.php:136
checkRecord
checkRecord($sUserId)
Definition: functions.inc.php:44
renameFile
renameFile($sUserId, $sFileId)
Definition: functions.inc.php:162
convertMain
convertMain($sId)
Definition: functions.inc.php:101
$oAlert
$oAlert
Definition: embed.php:15
publishRecordedFile
publishRecordedFile($sUserId, $sTitle, $sCategory, $sTags, $sDesc)
Definition: functions.inc.php:51
php
$sModule
if(!file_exists($sRayHeaderPath)) $sModule
Definition: index.php:14
initFile
initFile($sId, $sTitle, $sCategory, $sTags, $sDesc)
Definition: functions.inc.php:79
copy
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step which gives you legal permission to copy
Definition: license.txt:50
ChWsbAlerts
Definition: ChWsbAlerts.php:39
$sFile
$sFile
Definition: index.php:20
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$sTitle
$sTitle
Definition: actions.inc.php:13
$sTags
$sTags
Definition: actions.inc.php:12
$oDb
global $oDb
Definition: db.inc.php:39
getMp3Token
getMp3Token($sId)
Definition: functions.inc.php:211
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
deleteFile
deleteFile($sFile)
Definition: functions.inc.php:195
$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
deleteTempMp3s
deleteTempMp3s($sUserId, $bSourceOnly=false)
Definition: functions.inc.php:175
getDuration
getDuration($sFile)
Definition: functions.inc.php:157
$sDBModule
$sDBModule
Definition: header.inc.php:26
$sFfmpegPath
$sFfmpegPath
Definition: header.inc.php:60
$sId
$sId
Definition: actions.inc.php:8
uploadMusic
uploadMusic($sFilePath, $sUserId, $sFileName, $bUploaded=true)
Definition: functions.inc.php:8
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
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
ChWsbDb\getInstance
static getInstance()
Definition: ChWsbDb.php:82
$sStatus
$sStatus
Definition: actions.inc.php:11
getResult
getResult($sQuery)
Definition: db.inc.php:45