8 require_once(CH_DIRECTORY_PATH_CLASSES .
'ChWsbTemplate.php');
10 define(
'CH_WSB_UPLOADER_EP_PREFIX',
'extra_param_');
34 parent::__construct();
36 $this->sTempFilename =
'';
39 $this->sUploadTypeLC = strtolower($this->sUploadTypeNC);
43 $this->_sJsPostObject =
'o' . $this->sUploadTypeNC .
'Upload';
44 $this->sSendFileInfoFormCaption =
'';
46 $GLOBALS[
'oSysTemplate']->addJsTranslation(array(
47 '_ch_' . $this->sUploadTypeLC .
's_val_title_err',
48 '_ch_' . $this->sUploadTypeLC .
's_val_descr_err'
52 $this->_aExtras = array();
57 $this->iMaxFilesize = min(
return_bytes(ini_get(
'upload_max_filesize')),
64 'UploadOwnerId' => array(
66 'name' =>
'UploadOwnerId',
67 'value' => $this->_iOwnerId,
69 'UploadPostAction' => array(
71 'name' =>
'UploadPostAction',
74 'UploadPostType' => array(
76 'name' =>
'UploadPostType',
77 'value' => $sPostType,
79 'UploadContentType' => array(
81 'name' =>
'UploadContentType',
82 'value' => $sContentType,
91 foreach ($this->_aExtras
as $sKey => $mixedValue) {
95 'value' => $mixedValue
109 return !
isMember() ?
'' : $_COOKIE[
'memberPassword'];
115 foreach ($aRequest
as $sKey => $sValue) {
126 $aFile = $this->oModule->_oDb->getFileInfo(array(
'fileId' =>
$iFileId));
131 $oAlbums =
new ChWsbAlbums(
'ch_' . $this->sUploadTypeLC .
's', $iAuthorId);
132 $aAlbum = $oAlbums->getAlbumInfo(array(
'fileId' => $aFile[
'albumId'],
'owner' => $iAuthorId));
133 if (
empty($aAlbum)) {
137 $aExtra[
'privacy_view'] = $aAlbum[
'AllowAlbumView'];
138 if (!isset($aExtra[
'album'])) {
139 $aExtra[
'album'] = $aAlbum[
'Uri'];
150 $this->_aExtras = $aExtras;
151 $sMode = isset(
$_GET[
'mode']) ? strip_tags(
$_GET[
'mode']) : $this->_aExtras[
'mode'];
152 unset($this->_aExtras[
'mode']);
155 if (!
empty($this->_aExtras[
'txt'])) {
156 $aTxt = $this->_aExtras[
'txt'];
157 unset($this->_aExtras[
'txt']);
160 $aUplMethods = $this->oModule->_oConfig->getUploadersMethods();
162 if (
empty($aUploaders)) {
163 $aUploaders = array_keys($aUplMethods);
166 if (array_key_exists(
$sMode, $aUplMethods)) {
167 if (is_array($aUplMethods[
$sMode])) {
168 $aUplMethods[
$sMode][
'params'] = array_merge(is_array($aUplMethods[
$sMode][
'params']) ? $aUplMethods[
$sMode][
'params'] : array(),
169 array(
'extras' => $this->_aExtras));
172 } elseif (is_string($aUplMethods[
$sMode]) && method_exists($this, $aUplMethods[
$sMode])) {
180 <iframe style=
"display:none;" name=
"__upload_type___upload_frame"></iframe>
181 <script
src=
"__modules_url__cheetah/__upload_type__s/js/upload.js" type=
"text/javascript"
182 language=
"javascript"></script>
183 <script
type=
"text/javascript">
184 var __js_post_object__ =
new Ch__upload_type_nc__Upload({
185 iOwnerId: __owner_id__
189 <div
id=
"__upload_type___accepted_files_block"></div>
191 <div
id=
"__upload_type___success_message" style=
"display:none;">__box_upl_succ__</div>
192 <div
id=
"__upload_type___failed_file_message" style=
"display:none;">__box_upl_file_err__</div>
193 <div
id=
"__upload_type___failed_message" style=
"display:none;">__box_upl_err__</div>
194 <div
id=
"__upload_type___embed_failed_message" style=
"display:none;">__box_emb_err__</div>
196 $sTempl = ob_get_clean();
198 'upload_type' => $this->sUploadTypeLC,
199 'modules_url' => CH_WSB_URL_MODULES,
200 'js_post_object' => $this->_sJsPostObject,
201 'upload_type_nc' => $this->sUploadTypeNC,
202 'owner_id' => $this->_iOwnerId,
204 'box_upl_succ' =>
MsgBox(
_t(
'_ch_' . $this->sUploadTypeLC .
's_upl_succ')),
205 'box_upl_file_err' =>
MsgBox(
_t(
'_sys_txt_upload_failed')),
206 'box_upl_err' =>
MsgBox(
_t(
'_ch_' . $this->sUploadTypeLC .
's_upl_err')),
207 'box_emb_err' =>
MsgBox(
_t(
'_ch_' . $this->sUploadTypeLC .
's_emb_err')),
208 'txt_select_files' =>
_t(!
empty($aTxt[
'select_files']) ? $aTxt[
'select_files'] :
'_sys_txt_select_files')
210 $this->
addCss(
'upload_media_comm.css');
219 'form_attrs' => array(
220 'id' => $this->sUploadTypeLC .
'_upload_form',
222 'action' => $this->sWorkingFile,
224 'enctype' =>
'multipart/form-data',
225 'target' => $this->sUploadTypeLC .
'_upload_frame'
229 'type' =>
'block_header',
230 'caption' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_embed')
235 'caption' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_Embed'),
241 'content' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_Embed_example'),
243 'hidden_action' => array(
246 'value' =>
'accept_embed'
251 'value' =>
_t(
'_Continue'),
253 'onclick' =>
"return parent." . $this->_sJsPostObject .
".checkEmbed(true) && parent." . $this->_sJsPostObject .
"._loading(true); sh{$this->sUploadTypeNC}EnableSubmit(false);",
260 foreach ($this->_aExtras
as $sKey => $mixedValue) {
264 'value' => $mixedValue
276 'form_attrs' => array(
277 'id' => $this->sUploadTypeLC .
'_upload_form',
279 'action' => $this->sWorkingFile,
281 'enctype' =>
'multipart/form-data',
282 'target' => $this->sUploadTypeLC .
'_upload_frame'
286 'type' =>
'block_header',
287 'caption' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_record')
292 'content' => $sCustomRecorderObject,
295 'hidden_action' => array(
298 'value' =>
'accept_record'
303 'value' =>
_t(
'_Continue'),
306 'disabled' =>
'disabled'
313 foreach ($this->_aExtras
as $sKey => $mixedValue) {
317 'value' => $mixedValue
328 return $GLOBALS[
'oFunctions']->loadingBox(
'upload-loading-container');
333 return '<script src="' . CH_WSB_URL_ROOT .
'plugins/jquery/jquery.js" type="text/javascript" language="javascript"></script>';
343 $aData = explode(
"<" . $sTag, $sData, 2);
344 if (strpos($aData[1],
">") > 0) {
345 $aData = explode(
">", $aData[1], 2);
348 $sData = substr($aData[1], 1);
350 $aData = explode(
"</" . $sTag .
">", $sData, 2);
352 $iCdataIndex = strpos($sData,
"<![CDATA[");
353 if (is_numeric($iCdataIndex) && $iCdataIndex == 0) {
354 return $this->getStringPart($sData,
"<![CDATA[",
"]]>");
362 $aData = explode(
"<" . $sTag, $sData, 2);
363 $iTagIndex1 = strpos($aData[1],
"/>");
364 $iTagIndex = strpos($aData[1],
">");
366 if (!is_integer($iTagIndex1) || $iTagIndex1 > $iTagIndex) {
367 $aData = explode(
">", $aData[1], 2);
369 $aData = explode(
"/>", $aData[1], 2);
372 $sAttributes = str_replace(
"'",
'"', trim($aData[0]));
373 $aAttributes = array();
375 $sPattern =
'(([^=])+="([^"])+")';
376 preg_match_all($sPattern, $sAttributes, $aMatches);
378 $aMatches = $aMatches[0];
379 for ($i = 0; $i < count($aMatches); $i++) {
380 $aData = explode(
'="', $aMatches[$i]);
381 $aAttributes[trim($aData[0])] = substr($aData[1], 0, strlen($aData[1]) - 1);
384 return empty($sAttribute) ? $aAttributes : $aAttributes[$sAttribute];
389 $aParts = explode($sLeft, $sData, 2);
390 $aParts = explode($sRight, $aParts[1], 2);
392 return count($aParts) == 2 ? $aParts[0] :
"";
397 if (!$this->_iOwnerId) {
398 return $this->
_getAuthorId() ?
"" :
'<script type="text/javascript">alert("' .
ch_js_string(
_t(
'_LOGIN_REQUIRED_AE1')) .
'");</script>';
410 'form_attrs' => array(
411 'id' => $this->sUploadTypeLC .
'_upload_form',
415 'enctype' =>
'multipart/form-data',
416 'target' => $this->sUploadTypeLC .
'_upload_frame'
421 'name' =>
'submit_form',
422 'value' =>
_t(
'_Submit'),
428 foreach ($this->_aExtras
as $sKey => $mixedValue) {
432 'value' => $mixedValue
443 $aUploaders = $this->oModule->_oConfig->getUploaders();
445 $aCustomFormData = array();
446 foreach ($this->_aExtras
as $sKey => $mixedValue) {
451 'upload_type' => $this->sUploadTypeLC,
453 'static_path' => parse_url(CH_WSB_URL_PLUGINS, PHP_URL_PATH),
454 'plugins_url' => CH_WSB_URL_PLUGINS,
455 'preview_size' => 240,
457 array(
'action' => $aUploaders[
'html5'][
'action'])),
458 'reload_url' => $this->sWorkingFile,
459 'custom_data' => json_encode($aCustomFormData),
460 'max_file_size' => $this->iMaxFilesize,
462 'image_auto_orientation' => $this->bImageAutoRotate,
463 'accept_mime_type' => $this->sAcceptMimeType,
464 'multiple' => $aExtras[
'from_wall'] ?
'' :
'multiple',
465 'max_file_size_exceeded' =>
ch_js_string(
_t(
'_sys_txt_upload_size_error',
485 function performUpload($sFilePath, $sRealFilename =
'',
$aInfo = array(), $isMoveUploadedFile =
true, $aExtraParams = array())
498 if (isset($aFiles[
'tmp_name'])) {
499 $sFilePath = $aFiles[
'tmp_name'];
500 $sFileName = $_FILES[
'file'][
'name'];
503 foreach ($aFiles
as $name => $file) {
511 if (isset($files[
'tmp_name'])) {
512 $filename = $files[
'tmp_name'];
513 list($mime) = explode(
';', @mime_content_type($filename));
515 if (strpos($mime,
'image') !==
false) {
516 $size = getimagesize($filename);
517 $base64 = base64_encode(file_get_contents($filename));
519 $images[$name] = array(
526 'size' => filesize($filename)
528 'dataURL' =>
'data:' . $mime .
';base64,' . $base64
532 foreach ($files
as $name => $file) {
540 if (!
empty($_SERVER[
'HTTP_ORIGIN'])) {
542 header(
'Access-Control-Allow-Origin: ' . $_SERVER[
'HTTP_ORIGIN']);
543 header(
'Access-Control-Allow-Methods: POST, GET, OPTIONS');
544 header(
'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type');
545 header(
'Access-Control-Allow-Credentials: true');
548 if (strtoupper($_SERVER[
'REQUEST_METHOD']) !=
'POST') {
552 require_once(CH_DIRECTORY_PATH_PLUGINS .
'file-api/server/FileAPI.class.php');
570 'images' => $aImages,
571 'data' => array(
'_REQUEST' =>
$_REQUEST,
'_FILES' => $aFiles),
577 'statusText' =>
'OK',
586 header(
"Content-type: text/html; charset=utf-8");
588 $sPattern =
'title-';
589 $sOutput =
"<script>parent.$(parent.document).trigger('ch-files-cleanup');</script>";
591 if (strtoupper($_SERVER[
'REQUEST_METHOD']) !=
'POST') {
595 foreach ($_POST
as $k =>
$s) {
596 if (0 !== strpos($k, $sPattern)) {
600 if (!(
$iId = (
int)str_replace($sPattern,
'', $k))) {
616 $aUploaders = $this->oModule->_oConfig->getUploaders();
618 'form_attrs' => array(
619 'id' => $this->sUploadTypeLC .
'_upload_form',
622 array(
'action' => $aUploaders[
'regular'][
'action'])),
624 'enctype' =>
'multipart/form-data',
625 'target' => $this->sUploadTypeLC .
'_upload_frame'
629 'type' =>
'block_header',
630 'caption' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_upload')
635 'caption' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_browse'),
638 'multiplyable' => $aExtras[
'from_wall'] ?
'false' :
'true',
639 'onchange' =>
"parent." . $this->_sJsPostObject .
".onFileChangedEvent(this);"
645 'value' =>
_t(
'_Continue'),
648 'onclick' =>
"return parent." . $this->_sJsPostObject .
"._loading(true);",
649 'disabled' =>
'disabled'
656 foreach ($this->_aExtras
as $sKey => $mixedValue) {
660 'value' => $mixedValue
671 $aDefaultValues = array(),
672 $aPossibleImage = array(),
673 $aPossibleDuration = array()
675 header(
"Content-type: text/html; charset=utf-8");
677 '_ch_' . $this->sUploadTypeLC .
's_val_title_err',
678 '_ch_' . $this->sUploadTypeLC .
's_val_descr_err'
682 $oCategories->getTagObjectConfig();
683 $aFormCategories[
'categories'] = $oCategories->getGroupChooser(
'ch_' . $this->sUploadTypeLC .
's',
684 $this->_iOwnerId,
true);
685 $aFormCategories[
'categories'][
'required'] =
false;
688 if ($this->_aExtras[$sKey] !=
'') {
692 'value' => stripslashes($this->_aExtras[$sKey])
696 $oAlbum =
new ChWsbAlbums(
'ch_' . $this->sUploadTypeLC .
's');
697 $aAlbumList = $oAlbum->getAlbumList(array(
'owner' => $this->_iOwnerId));
699 if (count($aAlbumList) > 0) {
700 foreach ($aAlbumList
as $aValue) {
701 $aList[$aValue[
'ID']] = stripslashes($aValue[
'Caption']);
704 $sDefName = $oAlbum->getAlbumDefaultName();
705 $aList[$sDefName] = stripslashes($sDefName);
707 $aAlbums[
'album'] = array(
708 'type' =>
'select_box',
710 'caption' =>
_t(
'_sys_album'),
715 $sCaptionVal = ($this->sSendFileInfoFormCaption !=
'') ? $this->sSendFileInfoFormCaption :
_t(
'_Info');
717 $aInputValues = array(
'title',
'tags',
'description',
'type', $this->sUploadTypeLC);
718 foreach ($aInputValues
as $sField) {
719 $sEmpty = $sField ==
'type' ?
'upload' :
'';
720 $sTemp = isset($aDefaultValues[$sField]) ? strip_tags($aDefaultValues[$sField]) : $sEmpty;
721 $aDefaultValues[$sField] = $sTemp;
724 'form_attrs' => array(
725 'id' => $this->sUploadTypeLC .
'_file_info_form',
727 'action' => $this->sWorkingFile,
728 'target' =>
'upload_file_info_frame_' . $iFileID
732 'type' =>
'block_header',
733 'caption' => $sCaptionVal,
734 'collapsable' =>
false
739 'caption' =>
_t(
'_Title'),
741 'value' => $aDefaultValues[
'title']
746 'caption' =>
_t(
'_Tags'),
747 'info' =>
_t(
'_Tags_desc'),
748 'value' => $aDefaultValues[
'tags']
750 'description' => array(
751 'type' =>
'textarea',
752 'name' =>
'description',
753 'caption' =>
_t(
'_Description'),
754 'value' => $aDefaultValues[
'description']
761 'hidden_action' => array(
764 'value' =>
'accept_file_info'
766 $this->sUploadTypeLC => array(
768 'name' => $this->sUploadTypeLC,
769 'value' => $aDefaultValues[$this->sUploadTypeLC]
774 'value' => $aDefaultValues[
'type']
780 foreach ($this->_aExtras
as $sKey => $mixedValue) {
784 'value' => $mixedValue
791 if (is_array($aPossibleImage) && count($aPossibleImage) > 0) {
792 $aForm[
'inputs'] = array_merge(
$aForm[
'inputs'], $aPossibleImage);
795 if (is_array($aPossibleDuration) && count($aPossibleDuration) > 0) {
796 $aForm[
'inputs'] = array_merge(
$aForm[
'inputs'], $aPossibleDuration);
799 $aForm[
'inputs'][] = array(
800 'type' =>
'input_set',
805 'value' =>
_t(
'_Submit'),
808 'onclick' =>
"return parent." . $this->_sJsPostObject .
".doValidateFileInfo(this, '" . $iFileID .
"');",
814 'value' =>
_t(
'_ch_' . $this->sUploadTypeLC .
's_admin_delete'),
817 'onclick' =>
"return parent." . $this->_sJsPostObject .
".cancelSendFileInfo('" . $iFileID .
"', '" . (
'record' == $aDefaultValues[
'type'] ||
'embed' == $aDefaultValues[
'type'] ?
'' : $this->sWorkingFile) .
"'); ",
825 'form' =>
$oForm->getCode()
827 $sForm = str_replace(array(
"'",
"\r",
"\n"), array(
"\'"),
$sForm);
829 return "<script src='" . CH_WSB_URL_ROOT .
"inc/js/jquery.webForms.js' type='text/javascript' language='javascript'></script><script type='text/javascript'>parent." . $this->_sJsPostObject .
".genSendFileInfoForm('" . $iFileID .
"', '" .
$sForm .
"'); parent." . $this->_sJsPostObject .
"._loading(false);</script>";
837 $bUpdateCounter =
true,
839 $aAlbumParams = array()
844 $iObjId = (int)$iObjId;
845 $aAlbumInfo = $oAlbums->getAlbumInfo(array(
'fileUri' =>
uriFilter($sAlbumUri),
'owner' => $iAuthorId),
847 if (is_array($aAlbumInfo) && count($aAlbumInfo) > 0) {
848 $iAlbumID = (int)$aAlbumInfo[
'ID'];
850 if (isset($aAlbumParams[
'privacy'])) {
851 $iPrivacy = (int)$aAlbumParams[
'privacy'];
852 } elseif ($sAlbumUri == $oAlbums->getAlbumDefaultName()) {
857 $iPrivacy = $oPrivacy->getDefaultValueModule($this->oModule->_oConfig->getUri(),
'album_view');
864 'caption' => $sAlbumUri,
865 'owner' => $iAuthorId,
866 'AllowAlbumView' => $iPrivacy
868 $iAlbumID = $oAlbums->addAlbum($aData,
false);
870 $oAlbums->addObject($iAlbumID, $iObjId, $bUpdateCounter);
875 if (is_array($aAddObjects) && !
empty($aAddObjects)) {
876 foreach ($aAddObjects
as $aField) {
886 return $this->oModule->_oConfig->checkAllowedExts(strtolower(
$sExt));
900 $aUploaders = $this->oModule->_oConfig->getUploaders();
901 foreach ($aUploaders
as $k => $r) {
906 if (is_array($r[
'handle'])) {
908 } elseif (is_string($r[
'handle']) && method_exists($this, $r[
'handle'])) {
909 $sCode = $this->{$r[
'handle']}();
922 for ($i = 0; $i < count($_FILES[
'file'][
'tmp_name']); $i++) {
923 if ($_FILES[
'file'][
'error'][$i]) {
924 if ($_FILES[
'file'][
'error'][$i] == UPLOAD_ERR_INI_SIZE) {
930 $sResult .= $this->
_shareFile($_FILES[
'file'][
'tmp_name'][$i],
true, $_FILES[
'file'][
'name'][$i],
931 array(
'file_type' => $_FILES[
'file'][
'type'][$i]));
942 $sMedUri =
uriGenerate(
$sTitle, $this->oModule->_oDb->sFileTable, $this->oModule->_oDb->aFileFields[
'medUri']);
946 $sMedUri = dechex($iMedID . str_replace(
'.',
'0', microtime(
true)));
950 'Categories' => $sCategories,
960 $bRes = $this->oModule->_oDb->updateData($iMedID,
$aFields);
964 $oTag->reparseObjTags($this->oModule->_oConfig->sPrefix, $iMedID);
966 $oCateg->reparseObjTags($this->oModule->_oConfig->sPrefix, $iMedID);
977 if (!$bCheckPrivacy || !isset($aExtra[
'privacy_view']) || (
int)$aExtra[
'privacy_view'] != (
int)
CH_WSB_PG_HIDDEN) {
978 $oZ =
new ChWsbAlerts($this->oModule->_oConfig->sPrefix,
'add', $iMedID, $this->_iOwnerId, $aExtra);
985 $iFileID = (int)
$_GET[
'file_id'];
986 if ($iFileID && $this->oModule->serviceRemoveObject($iFileID)) {
993 function _shareFile($sFilePath, $isMoveUploadedFile =
true, $sRealFilename =
'', $aExtraParams = array())
995 $a = $this->
performUpload($sFilePath, $sRealFilename, array(), $isMoveUploadedFile, $aExtraParams);
998 if (isset($a[
'id']) && $a[
'id']) {
999 $aDefault = array(
'title' => $this->sTempFilename);
1001 return $this->GenSendFileInfoForm($a[
'id'], $aDefault);
1012 return '<script type="text/javascript">alert("' .
ch_js_string(
$sMessage) .
'"); parent.' . $this->_sJsPostObject .
'._loading(false);</script>';
1017 $aUploaders = array_keys($this->oModule->_oConfig->getUploaderList());
1027 return $this->oModule->_oConfig->getUploaderList();
1046 if (
getParam($this->oModule->_oConfig->aGlParams[
'auto_activation']) ==
'on') {
1047 $bAutoActivate =
true;
1050 $bAutoActivate =
false;
1053 $sFileTitle = $aFileInfo[
'medTitle'];
1054 $sFileDesc = $aFileInfo[
'medDesc'];
1055 $sFileTags = $aFileInfo[
'medTags'];
1057 $sDimension = isset($aFileInfo[
'dimension']) ? $aFileInfo[
'dimension'] : (int)$aFileInfo[
'medSize'];
1059 $sAlbum = mb_strlen($_POST[
'extra_param_album']) > 0 ? $_POST[
'extra_param_album'] :
getParam(
'sys_album_default_name');
1060 $sAlbum = isset($aFileInfo[
'album']) ? $aFileInfo[
'album'] : $sAlbum;
1062 $sMedUri =
uriGenerate($sFileTitle, $this->oModule->_oDb->sFileTable,
1063 $this->oModule->_oDb->aFileFields[
'medUri']);
1064 $sExtDb = trim(
$sExt,
'.');
1068 'medProfId' => $iAuthorId,
1069 'medExt' => $sExtDb,
1070 'medTitle' => $sFileTitle,
1071 'medUri' => $sMedUri,
1072 'medDesc' => $sFileDesc,
1073 'medTags' => $sFileTags,
1074 'Categories' => $sCategory,
1075 'medSize' => $sDimension,
1077 'medDate' => $sCurTime,
1079 $aData = array_merge($aData, $aExtraData);
1080 $iInsertedID = $this->oModule->_oDb->insertData($aData);
1082 if (0 < $iInsertedID) {
1084 $oTag->reparseObjTags($this->oModule->_oConfig->sPrefix, $iInsertedID);
1087 $oCateg->reparseObjTags($this->oModule->_oConfig->sPrefix, $iInsertedID);
1089 $aAlbumParams = isset($aFileInfo[
'albumPrivacy']) ? array(
'privacy' => $aFileInfo[
'albumPrivacy']) : array();
1090 $this->
addObjectToAlbum($this->oModule->oAlbums, $sAlbum, $iInsertedID, $bAutoActivate, $iAuthorId,
1093 return $iInsertedID;