18 parent::__construct(
'File');
21 $this->sWorkingFile = CH_WSB_URL_ROOT . $this->oModule->_oConfig->getBaseUri() .
'albums/my/add_objects';
23 $iMaxByAdmin = 1024*1024*(int)
getParam($this->oModule->_oConfig->getMainPrefix() .
'_max_file_size');
24 if ($iMaxByAdmin > 0 && $iMaxByAdmin < $this->iMaxFilesize)
25 $this->iMaxFilesize = $iMaxByAdmin;
31 if(isset($aDefaultValues[
'image']))
32 $sFileUrl = $aDefaultValues[
'image'];
33 else if(!
empty($iFileID)) {
35 $sFileUrl = $aFileInfo[
'file'];
37 $sProtoEl =
'<img src="' . $sFileUrl .
'" />';
39 $aPossibleImage = array();
40 $aPossibleImage[
'preview_image'] = array(
42 'content' => $sProtoEl,
43 'caption' =>
_t(
'_ch_files_preview'),
52 $sJSFileId = (int)$_POST[
'file_id'];
53 switch($_POST[
'type']) {
56 $iFileID = $sJSFileId;
60 if ($iFileID && $iAuthorId) {
63 $sDescription = $_POST[
'description'];
64 $iAllowDownload = (int)$_POST[
'AllowDownload'];
66 $aCategories = array();
67 foreach ($_POST[
'Categories']
as $sVal) {
69 $aCategories[] = $sVal;
73 if ($this->
initFile($iFileID,
$sTitle, $sCategories,
$sTags, $sDescription, array(
'AllowDownload' => $iAllowDownload))) {
75 return '<script type="text/javascript">parent.' . $this->_sJsPostObject .
'.onSuccessSendingFileInfo("' . $sJSFileId .
'");</script>';
78 return '<script type="text/javascript">parent.' . $this->_sJsPostObject .
'.showErrorMsg("file_failed_message");</script>';
91 function performUpload ($sFilePath, $sRealFilename =
'',
$aInfo = array(), $isMoveUploadedFile =
true, $aExtraParams = array())
98 $sRealFilename = pathinfo($sFilePath, PATHINFO_BASENAME);
103 return array(
'error' =>
_t(
'_LOGIN_REQUIRED_AE1'));
105 if (!$this->oModule->_oConfig->checkAllowedExtsByFilename($sRealFilename))
106 return array(
'error' =>
_t(
'_sys_txt_wrong_file_extension'));
108 if (!$this->oModule->isAllowedAdd())
109 return array(
'error' =>
_t(
'_Access denied'));
111 $iFileSize = filesize($sFilePath);
112 if (!$iFileSize || $iFileSize > $this->iMaxFilesize)
113 return array(
'error' =>
_t(
'_' . $this->oModule->_oConfig->getMainPrefix() .
'_size_error',
_t_format_size($this->iMaxFilesize)));
115 $this->sTempFilename = pathinfo($sRealFilename, PATHINFO_FILENAME);
116 if (!($iMID = $this->
performFileUpload($sFilePath, array(), $isMoveUploadedFile, $sRealFilename, isset($aExtraParams[
'file_type']) ? $aExtraParams[
'file_type'] :
'')))
117 return array(
'error' =>
_t(
'_sys_txt_upload_failed'));
119 return array(
'id' => $iMID);
124 $aCustom[
'Approved'] =
getParam(
'ch_files_activation') ==
'on' ?
'approved' :
'pending';
128 function performFileUpload($sTmpFile, $aFileInfo, $isMoveUploadedFile =
true, $sOriginalFilename =
'', $sFileType =
'')
133 if (!$this->oModule->_iProfileId)
135 if (! $this->_iOwnerId || file_exists($sTmpFile) ==
false || !$this->oModule->isAllowedAdd())
138 $sMediaDir = $this->oModule->_oConfig->getFilesPath();
145 $sTempFileName = $sMediaDir . $this->_iOwnerId .
'_temp';
146 @unlink($sTempFileName);
148 if (($isMoveUploadedFile && is_uploaded_file($sTmpFile)) || !$isMoveUploadedFile) {
150 if ($isMoveUploadedFile) {
151 move_uploaded_file($sTmpFile, $sTempFileName);
154 $sTempFileName = $sTmpFile;
157 @chmod($sTempFileName, 0666);
158 if (file_exists($sTempFileName)) {
160 $sExtension = strrchr($sOriginalFilename,
'.');
161 $iFileSize = filesize($sTempFileName);
162 $sFileSize = sprintf(
"%u", $iFileSize / 1024);
165 if (is_array($aFileInfo) && count($aFileInfo) > 0) {
166 $aFileInfo[
'medSize'] = $iFileSize;
168 'AllowDownload' => (
int)$aFileInfo[
'AllowDownload'],
169 'Type' => $aFileInfo[
'Type'],
173 'medProfId' => $this->_iOwnerId,
174 'medTitle' => $sOriginalFilenameSafe,
175 'medDesc' => $sOriginalFilenameSafe,
176 'medExt' => trim($sExtension,
'.'),
177 'medDate' => $sCurTime,
178 'medUri' =>
genRndPwd(8,
false) . $sCurTime,
179 'medSize' => $iFileSize
182 if (
getParam(
'ch_files_activation') ==
'on') {
183 $bAutoActivate =
true;
184 $aPassArray[
'Approved'] =
'approved';
186 $bAutoActivate =
false;
187 $aPassArray[
'Approved'] =
'pending';
192 $iLastID = $this->oModule->_oDb->insertData($aPassArray);
193 $this->
addObjectToAlbum($this->oModule->oAlbums, $_POST[
'extra_param_album'], $iLastID, $bAutoActivate);
194 $this->oModule->isAllowedAdd(
true,
true);
197 $sFunc = ($isMoveUploadedFile) ?
'rename' :
'copy';
198 $sFilePostfix =
'_' . sha1($sCurTime);
199 if (! $sFunc($sTempFileName, $sMediaDir . $iLastID . $sFilePostfix)) {
200 @unlink($sTempFileName);
204 $this->sSendFileInfoFormCaption = $iLastID . $sExtension .
" ({$sFileSize}kb)";
206 $sFile = $sMediaDir . $iLastID . $sExtension;
215 $aForm = parent::getUploadFormArray(
$aForm, $aAddObjects);
216 $aForm[
'AllowView'] = $this->oModule->oPrivacy->getGroupChooser($this->_iOwnerId, $this->oModule->_oConfig->getUri(),
'download');