29 parent::__construct(
'Photo');
32 $this->sWorkingFile = CH_WSB_URL_ROOT . $this->oModule->_oConfig->getBaseUri() .
'albums/my/add_objects';
34 $this->sAcceptMimeType =
'image/*';
35 $this->bImageAutoRotate = 1;
40 $sKey = $this->oModule->_oConfig->getGlParam(
'flickr_photo_api');
53 if(isset($aDefaultValues[
'image']))
54 $sPhotoUrl = $aDefaultValues[
'image'];
55 else if(!
empty($iFileID)) {
56 $aPhotoInfo =
ChWsbService::call(
'photos',
'get_photo_array', array($iFileID),
'Search');
57 $sPhotoUrl = $aPhotoInfo[
'file'];
59 $sProtoEl =
'<img src="' . $sPhotoUrl .
'" />';
61 $aPossibleImage = array();
62 $aPossibleImage[
'preview_image'] = array(
64 'content' => $sProtoEl,
65 'caption' =>
_t(
'_ch_photos_preview'),
79 $sErrorReturn =
'<script type="text/javascript">parent.' . $this->_sJsPostObject .
'.showErrorMsg("photo_embed_failed_message");parent.' . $this->_sJsPostObject .
'.resetEmbed();</script>';
84 if(!preg_match(
"/^https?:\/\/(www.)?flickr.com\/photos\/([0-9A-Za-z_@-]+)\/([0-9]{10}|[0-9]{11})\/.*$/i", $sEmbed, $aMatches))
87 if(
empty($aMatches[3]))
90 $sPhotoId = $aMatches[3];
92 $sApiKey = $this->oModule->_oConfig->getGlParam(
'flickr_photo_api');
93 $sPhotoUrl = str_replace(
"#api_key#", $sApiKey, FLICKR_PHOTO_RSS);
94 $sPhotoUrl = str_replace(
"#photo#", $sPhotoId, $sPhotoUrl);
101 $sErrorReturn =
'<script type="text/javascript">parent.' . $this->_sJsPostObject .
'.changeErrorMsgBoxMsg("photo_embed_failed_message", "'.$sNewError.
'"); parent.' . $this->_sJsPostObject .
'.showErrorMsg("photo_embed_failed_message");parent.' . $this->_sJsPostObject .
'.resetEmbed();</script>';
102 return $sErrorReturn;
106 if(
empty($sPhotoData))
return $sErrorReturn;
115 $sImage = str_replace(
"#id#", $sPhotoId, FLICKR_PHOTO_URL);
116 $sImage = str_replace(
"#farm#", $aPhoto[
'farm'], $sImage);
117 $sImage = str_replace(
"#server#", $aPhoto[
'server'], $sImage);
120 if(isset($aPhoto[
'originalsecret'])) {
121 $aPhoto[
'secret'] = $aPhoto[
'originalsecret'];
122 $sExt = $aPhoto[
'originalformat'];
125 $sImage = str_replace(
"#secret#", $aPhoto[
'secret'], $sImage);
126 $sImage = str_replace(
"#mode#",
$sMode, $sImage);
127 $sImage = str_replace(
"#ext#",
$sExt, $sImage);
144 $iPhotoId = (int)$this->
performPhotoUpload($sFilesPath . $iAuthorId . IMAGE_EXTENSION, array(),
false,
false);
154 if($iPhotoId && $iAuthorId) {
159 $sDescription = $_POST[
'description'];
161 $aCategories = array();
162 foreach($_POST[
'Categories']
as $sKey => $sVal)
164 $aCategories[] = $sVal;
170 return '<script type="text/javascript">parent.' . $this->_sJsPostObject .
'.onSuccessSendingFileInfo("' .
$iFileId .
'");</script>';
174 return '<script type="text/javascript">parent.' . $this->_sJsPostObject .
'.showErrorMsg("photo_failed_message");</script>';
180 if(
empty($sAuthorCheck)) {
182 if($sEmbedThumbUrl) {
183 $aDefault = array(
'photo' => $sPhotoId,
'title' =>
$sTitle,
'description' =>
$sDesc,
'tags' =>
$sTags,
'image' => $sEmbedThumbUrl,
'type' =>
"embed");
188 return $sAuthorCheck;
195 return $this->
performPhotoUpload($sTmpFilename, $aFileInfo, $isUpdateThumb,
false, 0, $iAuthorId);
200 return $this->
performPhotoUpload($sTmpFilename, $aFileInfo, $isUpdateThumb,
false, $iPhotoID);
208 function performUpload ($sFilePath, $sRealFilename =
'',
$aInfo = array(), $isMoveUploadedFile =
true, $aExtraParams = array())
211 if ($this->_iOwnerId)
215 $sRealFilename = pathinfo($sFilePath, PATHINFO_BASENAME);
220 return array(
'error' =>
_t(
'_LOGIN_REQUIRED_AE1'));
222 if (!$this->oModule->_oConfig->checkAllowedExtsByFilename($sRealFilename))
223 return array(
'error' =>
_t(
'_sys_txt_wrong_file_extension'));
225 if (!$this->oModule->isAllowedAdd())
226 return array(
'error' =>
_t(
'_Access denied'));
230 $this->sTempFilename = pathinfo($sRealFilename, PATHINFO_FILENAME);
232 return array(
'error' =>
_t(
'_sys_txt_upload_failed'));
234 return array(
'id' => $iMID);
240 'maxWidth' => $this->oModule->_oConfig->getGlParam(
'client_width'),
241 'maxHeight' => $this->oModule->_oConfig->getGlParam(
'client_height'),
249 if(
empty($sAuthorCheck)) {
252 if($sRecordThumbUrl) {
253 $aDefault = array(
'image' => $sRecordThumbUrl,
'type' =>
"record");
258 return $sAuthorCheck;
263 $aCustom[
'Approved'] =
getParam(
'ch_photos_activation') ==
'on' ?
'approved' :
'pending';
268 function performPhotoUpload($sTmpFile, $aFileInfo, $bAutoAssign2Profile =
false, $isMoveUploadedFile =
true, $iChangingPhotoID = 0, $iAuthorId = 0)
278 if (!$this->oModule->_iProfileId)
280 if (!$iAuthorId || file_exists($sTmpFile) ==
false || !$this->oModule->isAllowedAdd(FALSE, FALSE, FALSE))
283 $sMediaDir = $this->oModule->_oConfig->getFilesPath();
290 $sTempFileName = $sMediaDir . $iAuthorId .
'_temp';
291 @unlink($sTempFileName);
293 if (($isMoveUploadedFile && is_uploaded_file($sTmpFile)) || !$isMoveUploadedFile) {
295 if ($isMoveUploadedFile) {
296 move_uploaded_file($sTmpFile, $sTempFileName);
299 $sTempFileName = $sTmpFile;
302 @chmod($sTempFileName, 0644);
303 if(file_exists($sTempFileName) && filesize($sTempFileName)>0) {
304 $aSize = getimagesize($sTempFileName);
306 @unlink($sTempFileName);
311 case IMAGETYPE_JPEG: $sExtension =
'.jpg';
break;
312 case IMAGETYPE_GIF: $sExtension =
'.gif';
break;
313 case IMAGETYPE_PNG: $sExtension =
'.png';
break;
315 @unlink($sTempFileName);
320 $iImgWidth = (int)$aSize[0];
321 $iImgHeight = (int)$aSize[1];
322 $sDimension = $iImgWidth.
'x'.$iImgHeight;
323 $sFileSize = sprintf(
"%u", filesize($sTempFileName) / 1024);
325 if ($iChangingPhotoID==0) {
326 if (is_array($aFileInfo) && count($aFileInfo)>0) {
327 $aFileInfo[
'dimension'] = $sDimension;
330 $sExtDb = trim($sExtension,
'.');
331 $sMedUri = $sCurTime =
time();
333 $sTitleDescTemp = ($this->sTempFilename !=
'') ? $this->sTempFilename : $iAuthorId .
'_temp';
334 if (
getParam(
'ch_photos_activation') ==
'on') {
335 $bAutoActivate =
true;
338 $bAutoActivate =
false;
342 $sAlbum = $_POST[
'extra_param_album'];
343 $aAlbumParams = isset($_POST[
'extra_param_albumPrivacy']) ? array(
'privacy' => (
int)$_POST[
'extra_param_albumPrivacy']) : array();
345 $iLastID = $this->oModule->_oDb->insertData(array(
'medProfId'=>$iAuthorId,
'medExt'=>$sExtDb,
'medTitle'=>$sTitleDescTemp,
'medUri'=>
genRndPwd(8,
false).$sMedUri,
'medDesc'=>$sTitleDescTemp,
'medTags'=>
'',
'Categories'=>
PROFILE_PHOTO_CATEGORY,
'medSize'=>$sDimension,
'Approved'=>
$sStatus,
'medDate'=>$sCurTime));
346 $this->
addObjectToAlbum($this->oModule->oAlbums, $sAlbum, $iLastID, $bAutoActivate, $iAuthorId, $aAlbumParams);
347 $this->oModule->isAllowedAdd(
true,
true);
350 $iLastID = $iChangingPhotoID;
354 $sFunc = ($isMoveUploadedFile) ?
'rename' :
'copy';
355 if (! $sFunc($sTempFileName, $sMediaDir . $iLastID . $sExtension)) {
356 @unlink($sTempFileName);
360 $this->sSendFileInfoFormCaption = $iLastID . $sExtension .
" ({$sDimension}) ({$sFileSize}kb)";
362 $sFile = $sMediaDir . $iLastID . $sExtension;
365 if (
getParam(
'enable_watermark') ==
'on') {
366 $iTransparent =
getParam(
'transparent1');
367 $sWaterMark =
$dir[
'profileImage'] .
getParam(
'Water_Mark');
369 if (strlen(
getParam(
'Water_Mark')) && file_exists($sWaterMark))
374 foreach ($this->oModule->_oConfig->aFilesConfig
as $sKey => $aValue) {
375 if (!isset($aValue[
'size_def']))
377 $iWidth = (int)$this->oModule->_oConfig->getGlParam($sKey .
'_width');
378 $iHeight = (int)$this->oModule->_oConfig->getGlParam($sKey .
'_height');
380 $iWidth = $aValue[
'size_def'];
382 $iHeight = $aValue[
'size_def'];
383 $sNewFilePath = $sMediaDir . $iLastID . $aValue[
'postfix'];
384 $iRes =
imageResize(
$sFile, $sNewFilePath, $iWidth, $iHeight,
true, isset($aValue[
'square']) && $aValue[
'square']);
387 @chmod($sNewFilePath, 0644);
391 $bAutoAssign2Profile = ($aOwnerInfo[
'Avatar']==0) ?
true : $bAutoAssign2Profile;
392 if ($bAutoAssign2Profile && $iLastID > 0) {
397 if (is_array($aFileInfo) && count($aFileInfo) > 0)
412 $sMedUri =
uriGenerate($aFileInfo[
'medTitle'], $this->oModule->_oDb->sFileTable, $this->oModule->_oDb->aFileFields[
'medUri']);
413 return $this->oModule->_oDb->updateData($iMediaID, array(
'medTitle' => $aFileInfo[
'medTitle'],
'medUri' => $sMedUri,
'medDesc' => $aFileInfo[
'medDesc'],
'medDate' =>
time()));