Cheetah
ChPhotosModule.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbFilesModule');
9 
10 define('PROFILE_PHOTO_CATEGORY', 'Profile photos');
11 
13 {
15  function __construct (&$aModule)
16  {
17  parent::__construct($aModule);
18  $this->aSectionsAdmin['pending'] = array(
19  'exclude_btns' => array('featured', 'unfeatured')
20  );
21  $this->iHeaderCacheTime = (int)$this->_oConfig->getGlParam('header_cache');
22  }
23 
24  function actionGetCurrentImage ($iPicId)
25  {
26  $iPicId = (int)$iPicId;
27  if ($iPicId > 0) {
28  ch_import('Search', $this->_aModule);
29  $oMedia = new ChPhotosSearch();
30  $aInfo = $oMedia->serviceGetPhotoArray($iPicId, 'file');
31  $aInfo['ownerUrl'] = getProfileLink($aInfo['owner']);
32  $aInfo['ownerName'] = getNickName($aInfo['owner']);
33  $aInfo['date'] = defineTimeInterval($aInfo['date']);
34  $oMedia->getRatePart();
35  $aInfo['rate'] = $oMedia->oRate->getJustVotingElement(0, 0, $aInfo['rate']);
36  $aLinkAddon = $oMedia->getLinkAddByPrams();
37  $oPaginate = new ChWsbPaginate(array(
38  'count' => (int)$_GET['total'],
39  'per_page' => 1,
40  'page' => (int)$_GET['page'],
41  'on_change_page' => 'getCurrentImage({page})',
42  ));
43  $aInfo['paginate'] = $oPaginate->getPaginate();
44  header('Content-Type:text/javascript; charset=utf-8');
45  echo json_encode($aInfo);
46  }
47  }
48 
49  function actionGetImage ($sParamValue, $sParamValue1)
50  {
52  $sParamValue1 = clear_xss($sParamValue1);
53  $iPointPos = strrpos($sParamValue1, '.');
54 
55  $iId = (int)$this->_oDb->getIdByHash(substr($sParamValue1, 0, $iPointPos));
56  if(empty($iId)) {
57  header("Location: " . $this->_oTemplate->getIconUrl('no_image.png'));
58  exit;
59  }
60 
61  $aInfo = $this->_oDb->getFileInfo(array('fileId' => $iId));
62  if(empty($aInfo) || !is_array($aInfo)) {
63  header("Location: " . $this->_oTemplate->getIconUrl('no_image.png'));
64  exit;
65  }
66 
67  if($aInfo['AllowAlbumView'] != CH_WSB_PG_HIDDEN && !$this->isAllowedView($aInfo)) {
68  header("Location: " . $this->_oTemplate->getIconUrl('private.png'));
69  exit;
70  }
71 
72  $sExt = substr($sParamValue1, $iPointPos + 1);
73  switch ($sExt) {
74  case 'png':
75  $sCntType = 'image/x-png';
76  break;
77  case 'gif':
78  $sCntType = 'image/gif';
79  break;
80  default:
81  $sCntType = 'image/jpeg';
82  }
83  $sPath = $this->_oConfig->getFilesPath() . $iId . str_replace('{ext}', $sExt, $this->_oConfig->aFilePostfix[$sParamValue]);
84  $sAdd = '';
85  if ($this->iHeaderCacheTime > 0) {
86  $iLastModTime = filemtime($sPath);
87  $sAdd = ", max-age={$this->iHeaderCacheTime}, Last-Modified: " . gmdate("D, d M Y H:i:s", $iLastModTime) . " GMT";
88  }
89  header("Cache-Control: must-revalidate, post-check=0, pre-check=0" . $sAdd);
90  header("Content-Type:" . $sCntType);
91  header("Content-Length: " . filesize($sPath));
92  readfile($sPath);
93  }
94 
95  function actionCropPerform($iPhotoID)
96  {
97  header('Content-Type:text/html; charset=utf-8');
98 
99  $aInfo = $this->_oDb->getFileInfo(array('fileId' => $iPhotoID));
100 
101  if (empty($aInfo))
102  die(json_encode(array(
103  'status' => 'error',
104  'message' => _t('_sys_media_not_found'),
105  )));
106 
107  if (!$this->isAllowedEdit($aInfo))
108  die(json_encode(array(
109  'status' => 'error',
110  'message' => _t('_Access denied'),
111  )));
112 
114  $sSrcFileName = $this->_oConfig->getFilesPath() . $aInfo['medID'] . str_replace('{ext}', $aInfo['medExt'], $this->_oConfig->aFilesConfig['original']['postfix']);
115  $sTmpFileName = CH_DIRECTORY_PATH_ROOT . 'tmp/' . $this->_oConfig->getMainPrefix() . mt_rand() . '.' . $aInfo['medExt'];
116  $bCropResult = $o->crop(
117  (float)$_POST['imgW'], (float)$_POST['imgH'],
118  (float)$_POST['imgX1'], (float)$_POST['imgY1'],
119  (float)$_POST['cropW'], (float)$_POST['cropH'],
120  -(float)$_POST['rotation'],
121  $sSrcFileName, $sTmpFileName);
122 
123  if (IMAGE_ERROR_SUCCESS !== $bCropResult)
124  die(json_encode(array(
125  'status' => 'error',
126  'message' => $o->getError(),
127  )));
128 
129  $_POST['extra_param_album'] = $aInfo['albumUri'];
130  $aInfo['Categories'] = preg_split('/[' . CATEGORIES_DIVIDER . ']/', $aInfo['Categories'], 0, PREG_SPLIT_NO_EMPTY);
131  ch_import('Uploader', $this->_aModule);
132  $sClassName = $this->_oConfig->getClassPrefix() . 'Uploader';
133  $oUploader = new $sClassName();
134  $a = $oUploader->performUpload ($sTmpFileName, pathinfo($sSrcFileName, PATHINFO_BASENAME), $aInfo, false);
135  @unlink($sTmpFileName);
136 
137  if (!empty($a['error']))
138  die(json_encode(array(
139  'status' => 'error',
140  'message' => $a['error'],
141  )));
142 
143 
144  $aInfoNew = $this->_oDb->getFileInfo(array('fileId' => $a['id']));
145 
146  ch_import('Search', $this->_aModule);
147  $oSearch = new ChPhotosSearch();
148  $sImgUrl = $oSearch->getImgUrl($aInfoNew['Hash'], 'file');
149 
150  echo(json_encode(array(
151  'status' => 'success',
152  'url' => $sImgUrl,
153  'redirect_url' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aInfoNew['medUri'],
154  )));
155  }
156 
157  function actionCrop($iPhotoID)
158  {
159  $aInfo = $this->_oDb->getFileInfo(array('fileId' => $iPhotoID));
160 
161  if (empty($aInfo)) {
162  $this->_oTemplate->displayPageNotFound();
163  return;
164  }
165 
166  if (!$this->isAllowedEdit($aInfo)) {
167  $this->_oTemplate->displayAccessDenied();
168  return;
169  }
170 
171  ch_import('PageView', $this->_aModule);
172  $sClassName = $this->_oConfig->getClassPrefix() . 'PageView';
173  $oPage = new $sClassName($this, $aInfo, $this->_oConfig->getMainPrefix() . '_crop');
174  $sCode = $oPage->getCode();
175 
176  $this->aPageTmpl['header'] = $aInfo['medTitle'];
177  $GLOBALS['oTopMenu']->setCustomSubHeader(_t('_sys_album_x_photo_x', $aInfo['albumCaption'], $aInfo['medTitle']));
178  $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
179  _t('_' . $this->_oConfig->getMainPrefix()) => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'home/',
180  $aInfo['albumCaption'] => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'browse/album/' . $aInfo['albumUri'] . '/owner/' . $aInfo['NickName'],
181  $sKey => '',
182  ));
183 
184  $this->_oTemplate->pageCode($this->aPageTmpl, array('page_main_code' => $sCode));
185  }
186 
187  function actionSetAvatar ($iPhotoID)
188  {
189  if ($this->serviceSetAvatar($iPhotoID)) {
190  $aInfo = $this->_oDb->getFileInfo(array('fileId' => $iPhotoID));
191  $sRedirect = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aInfo['medUri'];
192  $sJQueryJS = genAjaxyPopupJS($iPhotoID, 'ajaxy_popup_result_div', $sRedirect);
193  $sLangKey = '_Success';
194  } else {
195  $sJQueryJS = genAjaxyPopupJS($iPhotoID, 'ajaxy_popup_result_div');
196  $sLangKey = '_Error occured';
197  }
198  header('Content-Type: text/html; charset=UTF-8');
199  echo MsgBox(_t($sLangKey)) . $sJQueryJS;
200  exit;
201  }
202 
203  function serviceSetAvatar($iPhotoID, $iAuthorId = 0)
204  {
205  if (!$iAuthorId)
206  $iAuthorId = getLoggedId();
207 
208  if (!($aFileInfo = $this->_oDb->getFileInfo(array('fileId' => $iPhotoID))))
209  return false;
210 
211  if ($aFileInfo['medProfId'] != $iAuthorId)
212  return false;
213 
214  ch_import('ChWsbAlbums');
215  $sProfileAlbumUri = ChWsbAlbums::getAbumUri($this->_oConfig->getGlParam('profile_album_name'), $iAuthorId);
216  if ($sProfileAlbumUri != $aFileInfo['albumUri'])
217  return false;
218 
219  return $this->_oDb->setAvatar($iPhotoID, $aFileInfo['albumId']);
220  }
221 
223  {
224  return PROFILE_PHOTO_CATEGORY;
225  }
226 
227  function serviceGetBlockFavorited ($iBlockId)
228  {
229  if ($this->_iProfileId == 0)
230  return;
231  ch_import('Search', $this->_aModule);
232  $oMedia = new ChPhotosSearch();
233  $oMedia->clearFilters(array('activeStatus', 'allow_view', 'album_status', 'albumType', 'ownerStatus'), array('albumsObjects', 'albums'));
234  if (isset($oMedia->aAddPartsConfig['favorite']) && !empty($oMedia->aAddPartsConfig['favorite'])) {
235  $oMedia->aCurrent['join']['favorite'] = $oMedia->aAddPartsConfig['favorite'];
236  $oMedia->aCurrent['restriction']['fav'] = array(
237  'value' => $iUserId,
238  'field' => $oMedia->aAddPartsConfig['favorite']['userField'],
239  'operator' => '=',
240  'table' => $oMedia->aAddPartsConfig['favorite']['table']
241  );
242  }
243  $oMedia->aCurrent['paginate']['perPage'] = (int)$this->oConfig->getGlParam('number_top');
244  $sCode = $oMedia->displayResultBlock();
245  if ($oMedia->aCurrent['paginate']['totalNum'] > 0) {
246  $oMedia->aConstants['linksTempl']['favorited'] = 'browse/favorited';
247  $sCode = $GLOBALS['oFunctions']->centerContent($sCode, '.sys_file_search_unit');
248  $aTopMenu = array();
249  $aBottomMenu = $oMedia->getBottomMenu('favorited', 0, '');
250  return array($sCode, $aTopMenu, $aBottomMenu, false);
251  }
252  }
253 
254  function serviceGetMemberMenuItem ($sIcon = 'picture-o')
255  {
256  return parent::serviceGetMemberMenuItem ($sIcon);
257  }
258 
259  function serviceGetMemberMenuItemAddContent ($sIcon = 'picture-o')
260  {
261  return parent::serviceGetMemberMenuItemAddContent ($sIcon);
262  }
263 
264  function isAllowedShare(&$aDataEntry)
265  {
266  if($aDataEntry['AllowAlbumView'] != CH_WSB_PG_ALL)
267  return false;
268 
269  return true;
270  }
271 
272  function serviceGetQuickUploaderUrl($iProfileId, $sSelectedAlbum = '')
273  {
274  ch_import('ChWsbAlbums');
275 
276  $aDefaultAlbums = $this->_oConfig->getDefaultAlbums();
277  if(!empty($sSelectedAlbum) && in_array($sSelectedAlbum, $aDefaultAlbums))
278  $sSelectedAlbum = ChWsbAlbums::getAbumUri($this->_oConfig->getGlParam($sSelectedAlbum), $iProfileId);
279 
280  return CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'upload/' . $sSelectedAlbum;
281  }
282 
283  function serviceGetAlbumUploaderUrl($iProfileId, $sSelectedAlbum = '')
284  {
285  ch_import('ChWsbAlbums');
286 
287  $aDefaultAlbums = $this->_oConfig->getDefaultAlbums();
288  if(!empty($sSelectedAlbum) && in_array($sSelectedAlbum, $aDefaultAlbums))
289  $sSelectedAlbum = ChWsbAlbums::getAbumUri($this->_oConfig->getGlParam($sSelectedAlbum), $iProfileId);
290 
291  return CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'albums/my/add_objects/' . $sSelectedAlbum . '/owner/' . getUsername($iProfileId);
292  }
293 
294  function serviceGetManageProfilePhotoUrl($iProfileId, $sSelectedAlbum = '')
295  {
296  ch_import('ChWsbAlbums');
297 
298  $aDefaultAlbums = $this->_oConfig->getDefaultAlbums();
299  if(!empty($sSelectedAlbum) && in_array($sSelectedAlbum, $aDefaultAlbums))
300  $sSelectedAlbum = ChWsbAlbums::getAbumUri($this->_oConfig->getGlParam($sSelectedAlbum), $iProfileId);
301 
302  return CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() . 'albums/my/manage_profile_photos/' . $sSelectedAlbum . '/owner/' . getUsername($iProfileId);
303  }
304 
305  function serviceGetWallPost($aEvent)
306  {
307  return $this->getWallPost($aEvent, 'picture-o');
308  }
309 
310  function serviceGetWallPostOutline($aEvent)
311  {
312  return $this->getWallPostOutline($aEvent, 'picture-o');
313  }
314 
315  function actionView ($sUri) {
316  $aInfo = $this->_oDb->getFileInfo(array('fileUri' => $sUri));
317  if(isBlocked($aInfo['medProfId'], getLoggedId())) {
318  $this->_oTemplate->pageCode($this->aPageTmpl, array('page_main_code' => MsgBox(_t('_sys_txt_error_you_are_blocked'))));
319  return;
320  }
321 
322  parent::actionView($sUri);
323  }
324 
325  function actionBrowse ($sParamName = '', $sParamValue = '', $sParamValue1 = '', $sParamValue2 = '', $sParamValue3 = '') {
326  if ($sParamName == 'album' && $sParamValue1 == 'owner') {
327  $iOwnerId = getID($sParamValue2);
328  if(isBlocked($iOwnerId, getLoggedId())) {
329  $this->_oTemplate->pageCode($this->aPageTmpl, array('page_main_code' => MsgBox(_t('_sys_txt_error_you_are_blocked'))));
330  return;
331  }
332  }
333 
334  parent::actionBrowse($sParamName, $sParamValue, $sParamValue1, $sParamValue2, $sParamValue3);
335  }
336 
337  function actionAlbums ($sParamName = '', $sParamValue = '', $sParamValue1 = '', $sParamValue2 = '', $sParamValue3 = '') {
338  if($sParamName == 'browse' && $sParamValue == 'owner') {
339  $iOwnerId = getID($sParamValue1);
340  if(isBlocked($iOwnerId, getLoggedId())) {
341  $this->_oTemplate->pageCode($this->aPageTmpl, array('page_main_code' => MsgBox(_t('_sys_txt_error_you_are_blocked'))));
342  return;
343  }
344  }
345 
346  parent::actionAlbums($sParamName, $sParamValue, $sParamValue1, $sParamValue2, $sParamValue3);
347  }
348 
349 }
ChPhotosModule\__construct
__construct(&$aModule)
Definition: ChPhotosModule.php:15
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
ChPhotosSearch
Definition: ChPhotosSearch.php:11
ChPhotosModule\actionGetImage
actionGetImage($sParamValue, $sParamValue1)
Definition: ChPhotosModule.php:49
ChPhotosModule\serviceGetProfileCat
serviceGetProfileCat()
Definition: ChPhotosModule.php:222
ChPhotosModule\actionSetAvatar
actionSetAvatar($iPhotoID)
Definition: ChPhotosModule.php:187
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
defineTimeInterval
defineTimeInterval($iTime, $bAutoDateConvert=true, $bShort=false)
Definition: utils.inc.php:831
ChWsbFilesModule\isAllowedView
isAllowedView(&$aFile, $isPerformAction=false)
Definition: ChWsbFilesModule.php:1173
ChPhotosModule\actionCrop
actionCrop($iPhotoID)
Definition: ChPhotosModule.php:157
$sCode
$sCode
Definition: explanation.php:19
$aModule
$aModule
Definition: classifieds.php:21
ChPhotosModule\serviceGetBlockFavorited
serviceGetBlockFavorited($iBlockId)
Definition: ChPhotosModule.php:227
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChPhotosModule\actionAlbums
actionAlbums($sParamName='', $sParamValue='', $sParamValue1='', $sParamValue2='', $sParamValue3='')
Definition: ChPhotosModule.php:337
php
CH_WSB_PG_HIDDEN
const CH_WSB_PG_HIDDEN
Definition: ChWsbPrivacy.php:17
$iId
$iId
Definition: license.php:15
PROFILE_PHOTO_CATEGORY
const PROFILE_PHOTO_CATEGORY
Definition: ChPhotosModule.php:10
ChPhotosModule\actionBrowse
actionBrowse($sParamName='', $sParamValue='', $sParamValue1='', $sParamValue2='', $sParamValue3='')
Definition: ChPhotosModule.php:325
ChPhotosModule\$iHeaderCacheTime
$iHeaderCacheTime
Definition: ChPhotosModule.php:14
$oPage
$oPage
Definition: search_home.php:83
$sExt
$sExt
Definition: get_file.php:14
$sParamValue
$sParamValue
Definition: actions.inc.php:16
ChPhotosModule\serviceGetAlbumUploaderUrl
serviceGetAlbumUploaderUrl($iProfileId, $sSelectedAlbum='')
Definition: ChPhotosModule.php:283
ChWsbFilesModule\getWallPostOutline
getWallPostOutline($aEvent, $sIcon='save', $aParams=array())
Definition: ChWsbFilesModule.php:2034
ChWsbFilesModule\isAllowedEdit
isAllowedEdit(&$aFile, $isPerformAction=false)
Definition: ChWsbFilesModule.php:1127
CATEGORIES_DIVIDER
const CATEGORIES_DIVIDER
Definition: ChWsbCategories.php:10
ChPhotosModule\serviceGetMemberMenuItemAddContent
serviceGetMemberMenuItemAddContent($sIcon='picture-o')
Definition: ChPhotosModule.php:259
$aInfo
$aInfo
Definition: constants.inc.php:21
ChPhotosModule\actionGetCurrentImage
actionGetCurrentImage($iPicId)
Definition: ChPhotosModule.php:24
exit
exit
Definition: cart.php:21
$_GET
$_GET['debug']
Definition: index.php:67
ChWsbImageResize\instance
static instance()
Definition: ChWsbImageResize.php:60
$sParamName
$sParamName
Definition: actions.inc.php:15
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
ChPhotosModule
Definition: ChPhotosModule.php:13
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
$sJQueryJS
$sJQueryJS
Definition: list_pop.php:32
ChWsbFilesModule
Definition: ChWsbFilesModule.php:13
ChPhotosModule\serviceGetWallPost
serviceGetWallPost($aEvent)
Definition: ChPhotosModule.php:305
ChPhotosModule\serviceGetWallPostOutline
serviceGetWallPostOutline($aEvent)
Definition: ChPhotosModule.php:310
getUsername
getUsername( $ID='')
Definition: profiles.inc.php:443
ChWsbFilesModule\getWallPost
getWallPost($aEvent, $sIcon='save', $aParams=array())
Definition: ChWsbFilesModule.php:1900
ChWsbPaginate
Definition: ChWsbPaginate.php:69
ChPhotosModule\serviceGetMemberMenuItem
serviceGetMemberMenuItem($sIcon='picture-o')
Definition: ChPhotosModule.php:254
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
CH_WSB_PG_ALL
const CH_WSB_PG_ALL
Definition: ChWsbPrivacy.php:12
getProfileLink
getProfileLink( $iID, $sLinkAdd='')
Definition: profiles.inc.php:484
ChPhotosModule\serviceSetAvatar
serviceSetAvatar($iPhotoID, $iAuthorId=0)
Definition: ChPhotosModule.php:203
isBlocked
isBlocked($iFirstProfile, $iSecondProfile)
Definition: utils.inc.php:128
genAjaxyPopupJS
genAjaxyPopupJS($iTargetID, $sDivID='ajaxy_popup_result_div', $sRedirect='')
Definition: design.inc.php:242
ChPhotosModule\serviceGetManageProfilePhotoUrl
serviceGetManageProfilePhotoUrl($iProfileId, $sSelectedAlbum='')
Definition: ChPhotosModule.php:294
ChPhotosModule\actionView
actionView($sUri)
Definition: ChPhotosModule.php:315
getID
getID( $str, $with_email=1)
Definition: admin.inc.php:139
IMAGE_ERROR_SUCCESS
const IMAGE_ERROR_SUCCESS
operation was successfull
Definition: ChWsbImageResize.php:22
ChPhotosModule\serviceGetQuickUploaderUrl
serviceGetQuickUploaderUrl($iProfileId, $sSelectedAlbum='')
Definition: ChPhotosModule.php:272
ChPhotosModule\actionCropPerform
actionCropPerform($iPhotoID)
Definition: ChPhotosModule.php:95
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$o
$o
Definition: cmd.php:193
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ChWsbAlbums\getAbumUri
static getAbumUri($sName, $iUserId)
Definition: ChWsbAlbums.php:50
ChPhotosModule\isAllowedShare
isAllowedShare(&$aDataEntry)
Definition: ChPhotosModule.php:264
clear_xss
clear_xss($val)
Definition: utils.inc.php:700