Cheetah
ChSoundsUploader.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbFilesUploader');
9 ch_import('ChWsbCategories');
10 ch_import('ChWsbModule');
11 ch_import('ChWsbAlbums');
12 
18 require_once($sIncPath . 'db.inc.php');
19 
20 $sModule = "mp3";
22 
24 
26 $sModule = "mp3";
27 require_once($sModulesPath . $sModule . '/inc/header.inc.php');
28 require_once($sModulesPath . $sModule . '/inc/constants.inc.php');
29 require_once($sModulesPath . $sModule . '/inc/functions.inc.php');
30 require_once($sModulesPath . $sModule . '/inc/customFunctions.inc.php');
31 
33 {
34  // constructor
35  function __construct()
36  {
37  parent::__construct('Sound');
38 
39  $this->oModule = ChWsbModule::getInstance('ChSoundsModule');
40  $this->sWorkingFile = CH_WSB_URL_ROOT . $this->oModule->_oConfig->getBaseUri() . 'albums/my/add_objects';
41 
42  $iMaxByAdmin = 1024*1024*(int)getParam($this->oModule->_oConfig->getMainPrefix() . '_max_file_size');
43  if ($iMaxByAdmin > 0 && $iMaxByAdmin < $this->iMaxFilesize)
44  $this->iMaxFilesize = $iMaxByAdmin;
45 
46  $this->sAcceptMimeType = 'audio/*';
47  }
48 
49  function getRecordFormFile($aExtras)
50  {
51  $sCustomRecorderObject = getApplicationContent('mp3', 'recorder', array('user' => $this->_getAuthorId(), 'password' => $this->_getAuthorPassword(), 'extra' => ''), true);
52  return $this->_getRecordFormFile($sCustomRecorderObject, $aExtras);
53  }
54 
55  function GenSendFileInfoForm($iFileID, $aDefaultValues = array())
56  {
57  $aPossibleDuration = array();
58  $aPossibleDuration['duration'] = array(
59  'type' => 'hidden',
60  'name' => 'duration',
61  'value' => isset($aDefaultValues['duration']) ? $aDefaultValues['duration'] : "0"
62  );
63 
64  return $this->_GenSendFileInfoForm($iFileID, $aDefaultValues, array(), $aPossibleDuration);
65  }
66 
67  function servicePerformMusicUpload($sFilePath, $aInfo, $isMoveUploadedFile = false)
68  {
69  $a = $this->performUpload ($sFilePath, $sRealFilename, $aInfo, $isMoveUploadedFile);
70 
71  return isset($a['id']) && $a['id'] ? $a['id'] : false;
72  }
73 
75  {
76  $sResult = $this->_recordMusic();
77  return ($sResult!='') ? $this->GenJquieryInjection() . $sResult : '';
78  }
79 
81  {
82  $iAuthorId = $this->_getAuthorId();
83  $sJSMusicId = (int)$_POST['file_id'];
84  switch($_POST['type']) {
85  case 'record':
87  $sFileName = $iAuthorId . TEMP_FILE_NAME . MP3_EXTENSION;
88  $iMusicID = uploadMusic($sFilesPathMp3 . $sFileName, $iAuthorId, $sFileName, false);
89  $this->addObjectToAlbum($this->oModule->oAlbums, $_POST['extra_param_album'], $iMusicID, false);
90  break;
91  case 'upload':
92  default:
93  $iMusicID = $sJSMusicId;
94  break;
95  }
96 
97  if ($iMusicID && $iAuthorId) {
98  $sTitle = $_POST['title'];
99  $sTags = $_POST['tags'];
100  $sDescription = $_POST['description'];
101 
102  $aCategories = array();
103  foreach ($_POST['Categories'] as $sKey => $sVal) {
104  if ($sVal != '')
105  $aCategories[] = $sVal;
106  }
107  $sCategories = implode(CATEGORIES_DIVIDER, $aCategories);
108 
109  if ($this->initFile($iMusicID, $sTitle, $sCategories, $sTags, $sDescription)) {
110  $this->alertAdd($iMusicID);
111  return '<script type="text/javascript">parent.' . $this->_sJsPostObject . '.onSuccessSendingFileInfo("' . $sJSMusicId . '");</script>';
112  }
113  }
114  return '<script type="text/javascript">parent.' . $this->_sJsPostObject . '.showErrorMsg("sound_failed_message");</script>';
115  }
116 
117  function _embedMusic($sMusicId, $sTitle, $sDesc, $sTags, $sImage, $iDuration)
118  {
119  $sAuthorCheck = $this->checkAuthorBeforeAdd();
120  if(empty($sAuthorCheck)) {
121  $sEmbedThumbUrl = getEmbedThumbnail($this->_getAuthorId(), $sImage);
122  if($sEmbedThumbUrl) {
123  $aDefault = array('music' => $sMusicId, 'title' => $sTitle, 'description' => $sDesc, 'tags' => $sTags, 'duration' => $iDuration, 'image' => $sEmbedThumbUrl, 'type' => "embed");
124  return $this->GenSendFileInfoForm(1, $aDefault);
125  } else
126  return $this->getFileAddError();
127  } else
128  return $sAuthorCheck;
129  }
130 
131  function _recordMusic()
132  {
133  $sAuthorCheck = $this->checkAuthorBeforeAdd();
134  if(empty($sAuthorCheck)) {
135  if(checkRecord($this->_getAuthorId()))
136  return $this->GenSendFileInfoForm(1, array('type' => "record"));
137  else
138  return $this->getFileAddError();
139  } else
140  return $sAuthorCheck;
141  }
142 
148  function performUpload ($sFilePath, $sRealFilename = '', $aInfo = array(), $isMoveUploadedFile = true, $aExtraParams = array())
149  {
150  $bUpdateAlbumCounter = false;
151  $iOwner = $this->_getAuthorId();
152  if ($this->_iOwnerId)
153  $iOwner = $this->oModule->_iProfileId = $this->_iOwnerId;
154 
155  if (!$sRealFilename)
156  $sRealFilename = pathinfo($sFilePath, PATHINFO_BASENAME);
157 
158  // basic checking before upload
159 
160  if ($this->checkAuthorBeforeAdd())
161  return array('error' => _t('_LOGIN_REQUIRED_AE1'));
162 
163  if (!$this->oModule->_oConfig->checkAllowedExtsByFilename($sRealFilename))
164  return array('error' => _t('_sys_txt_wrong_file_extension'));
165 
166  if (!$this->oModule->isAllowedAdd())
167  return array('error' => _t('_Access denied'));
168 
169  // perform upload
170 
171  $GLOBALS['sModule'] = 'mp3';
172  include($GLOBALS['sModulesPath'] . $GLOBALS['sModule'] . '/inc/header.inc.php');
173 
174  $this->sTempFilename = pathinfo($sRealFilename, PATHINFO_FILENAME);
175  if (!($iMID = uploadMusic(process_db_input($sFilePath), $iOwner, process_db_input($sRealFilename), $isMoveUploadedFile)))
176  return array('error' => _t('_sys_txt_upload_failed'));
177 
178  // See if uploaded file is already a mp3 audio file. If so, change status and rename the file.
179  $sFile1 = $GLOBALS['dir']['root'] . 'flash/modules/mp3/files/' . $iMID;
180  $sFile2 = $GLOBALS['dir']['root'] . 'flash/modules/mp3/files/' . $iMID . '.mp3';
181  $aAudioData = getAudioData($sFile1);
182  if($aAudioData['CodecName'] == 'mp3') {
183  $sAutoApprove = 'on' == getParam('audioAutoApprove') ? 'approved' : 'disapproved';
184  rename($sFile1, $sFile2);
185  $aData = array(
186  'Time' => (int)$aAudioData['Duration']*1000,
187  //'BitRate' => $aAudioData['BitRate'],
188  'Status' => $sAutoApprove,
189  );
190  $this->oModule->_oDb->updateAudio($iMID, $aData);
191  $bUpdateAlbumCounter = true;
192  } else {
193  $this->oModule->_oDb->updateAudio($iMID, array('Status' => 'pending'));
194  }
195 
196  // update uploaded file info if needed
197 
198  if ($aInfo) {
199  foreach (array('title', 'categories', 'tags', 'desc') as $sKey)
200  $aInfo[$sKey] = isset($aInfo[$sKey]) ? $aInfo[$sKey] : '';
201 
202  $this->initFile($iMID, $aInfo['title'], $aInfo['categories'], $aInfo['tags'], $aInfo['desc']);
203  }
204 
205  // add uploaded file to the album
206 
207  $sExt = strtolower(pathinfo($sRealFilename, PATHINFO_EXTENSION));
208  $sAlbum = !empty($_POST['extra_param_album']) > 0 ? $_POST['extra_param_album'] : getParam('sys_album_default_name');
209  $sAlbum = isset($aInfo['album']) ? $aInfo['album'] : $sAlbum;
210  //$sAutoActive = $sExt == 'mp3' && getSettingValue($sModule, "autoApprove") == true;
211  $this->addObjectToAlbum($this->oModule->oAlbums, $sAlbum, $iMID, $bUpdateAlbumCounter);
212 
213  $this->oModule->isAllowedAdd(true, true);
214 
215  return array('id' => $iMID);
216 
217  }
218 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChSoundsUploader\__construct
__construct()
Definition: ChSoundsUploader.php:35
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
ChSoundsUploader\serviceAcceptRecordFile
serviceAcceptRecordFile()
Definition: ChSoundsUploader.php:74
$sModulePath
$sModulePath
Definition: ChSoundsUploader.php:21
ChWsbModule\getInstance
static getInstance($sClassName)
Definition: ChWsbModule.php:89
ChWsbFilesUploader\_getRecordFormFile
_getRecordFormFile($sCustomRecorderObject='', $aExtras=array())
Definition: ChWsbFilesUploader.php:273
$sResult
$sResult
Definition: advanced_settings.php:26
ChWsbFilesUploader\checkAuthorBeforeAdd
checkAuthorBeforeAdd()
Definition: ChWsbFilesUploader.php:395
checkRecord
checkRecord($sUserId)
Definition: functions.inc.php:44
ChSoundsUploader\getRecordFormFile
getRecordFormFile($aExtras)
Definition: ChSoundsUploader.php:49
ChWsbFilesUploader\getFileAddError
getFileAddError($sMessage='')
Definition: ChWsbFilesUploader.php:1008
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$sIncPath
global $sIncPath
Definition: ChSoundsUploader.php:13
$sFilesPathMp3
global $sFilesPathMp3
Definition: ChSoundsUploader.php:23
php
$sExt
$sExt
Definition: get_file.php:14
getAudioData
getAudioData($sFile)
Definition: utils.inc.php:2026
ChSoundsUploader\servicePerformMusicUpload
servicePerformMusicUpload($sFilePath, $aInfo, $isMoveUploadedFile=false)
Definition: ChSoundsUploader.php:67
CATEGORIES_DIVIDER
const CATEGORIES_DIVIDER
Definition: ChWsbCategories.php:10
$aInfo
$aInfo
Definition: constants.inc.php:21
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
$sTitle
$sTitle
Definition: actions.inc.php:13
ChSoundsUploader\_embedMusic
_embedMusic($sMusicId, $sTitle, $sDesc, $sTags, $sImage, $iDuration)
Definition: ChSoundsUploader.php:117
$oDb
global $oDb
Definition: ChSoundsUploader.php:17
$sFilesPath
global $sFilesPath
Definition: ChSoundsUploader.php:16
$sTags
$sTags
Definition: actions.inc.php:12
ChSoundsUploader
Definition: ChSoundsUploader.php:33
ChSoundsUploader\performUpload
performUpload($sFilePath, $sRealFilename='', $aInfo=array(), $isMoveUploadedFile=true, $aExtraParams=array())
Definition: ChSoundsUploader.php:148
ChSoundsUploader\GenSendFileInfoForm
GenSendFileInfoForm($iFileID, $aDefaultValues=array())
Definition: ChSoundsUploader.php:55
ChWsbFilesUploader\alertAdd
alertAdd($iMedID, $bCheckPrivacy=false)
Definition: ChWsbFilesUploader.php:972
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChSoundsUploader\serviceAcceptFileInfo
serviceAcceptFileInfo()
Definition: ChSoundsUploader.php:80
_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
ChWsbFilesUploader\GenJquieryInjection
GenJquieryInjection()
Definition: ChWsbFilesUploader.php:331
ChSoundsUploader\_recordMusic
_recordMusic()
Definition: ChSoundsUploader.php:131
ChWsbFilesUploader\_getAuthorId
_getAuthorId()
Definition: ChWsbFilesUploader.php:102
uploadMusic
uploadMusic($sFilePath, $sUserId, $sFileName, $bUploaded=true)
Definition: functions.inc.php:8
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$sDesc
$sDesc
Definition: actions.inc.php:21
$sModule
global $sModule
Definition: ChSoundsUploader.php:15
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbFilesUploader\_getAuthorPassword
_getAuthorPassword()
Definition: ChWsbFilesUploader.php:107
$sModulesPath
global $sModulesPath
Definition: ChSoundsUploader.php:14
getEmbedThumbnail
getEmbedThumbnail($sUserId, $sImageUrl, $aFilesConfig=array())
Definition: functions.inc.php:22
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10