Cheetah
ChAvaModule.php
Go to the documentation of this file.
1 <?php
2 
8 function ch_avatar_import ($sClassPostfix, $aModuleOverwright = array())
9 {
11  $a = $aModuleOverwright ? $aModuleOverwright : $aModule;
12  if (!$a || $a['uri'] != 'avatar') {
13  $oMain = ChWsbModule::getInstance('ChAvaModule');
14  $a = $oMain->_aModule;
15  }
16  ch_import ($sClassPostfix, $a) ;
17 }
18 
19 ch_import('ChWsbModule');
20 ch_import('ChWsbAlerts');
21 
22 $aPathInfo = pathinfo(__FILE__);
23 require_once ($aPathInfo['dirname'] . '/../include.php');
24 
25 define ('CH_AVA_DIR_SITE_AVATARS', CH_DIRECTORY_PATH_MODULES . 'cheetah/avatar/data/ready/');
26 define ('CH_AVA_URL_SITE_AVATARS', CH_WSB_URL_MODULES . 'cheetah/avatar/data/ready/');
27 
28 define ('CH_AVA_DIR_TMP', CH_DIRECTORY_PATH_MODULES . 'cheetah/avatar/data/tmp/');
29 define ('CH_AVA_URL_TMP', CH_WSB_URL_MODULES . 'cheetah/avatar/data/tmp/');
30 
31 define ('CH_AVA_PRE_RESIZE_W', 600);
32 define ('CH_AVA_PRE_RESIZE_H', 600);
33 
126 {
128  var $_aAllowedExt = array (
129  'jpg',
130  'jpeg',
131  'gif',
132  'png',
133  );
134 
136  {
137  parent::__construct($aModule);
138  $this->_iProfileId = getLoggedId();
139  $GLOBALS['oChAvaModule'] = &$this;
140  }
141 
142  function actionHome ()
143  {
144  if (!$this->_iProfileId) {
145  $this->_oTemplate->displayAccessDenied ();
146  return;
147  }
148 
149  if ('ch_photos_thumb' == getParam('sys_member_info_thumb') && 'ch_photos_icon' == getParam('sys_member_info_thumb_icon')) {
150  $sProfilePhotosUrl = ChWsbService::call('photos', 'get_manage_profile_photo_url', array($this->_iProfileId, 'profile_album_name'));
151  header('Location: ' . $sProfilePhotosUrl);
152  exit;
153  }
154 
155  $this->_oTemplate->pageStart();
156 
157  if ($_GET['make_avatar_from_shared_photo'] > 0) {
158  if (!$this->isAllowedAdd()) {
159  $aVars = array ('msg' => _t('_ch_ava_msg_access_denied'));
160  echo $this->_oTemplate->parseHtmlByName ('error_plank', $aVars);
161  } else {
162  $this->_makeAvatarFromSharedPhoto((int)$_GET['make_avatar_from_shared_photo']);
163  }
164  }
165 
166  if (isset($_GET['join_text']) && $_GET['join_text']) {
167  echo MsgBox(_t(strip_tags($_GET['join_text'])));
168  }
169 
170  if (isset($_POST['set_avatar'])) {
171  if (!$this->isAllowedAdd ())
172  $aVars = array ('msg' => _t('_ch_ava_msg_access_denied'));
173  elseif (!$this->_cropAvatar ())
174  $aVars = array ('msg' => _t('_ch_ava_set_avatar_error'));
175  if (!empty($aVars))
176  echo $this->_oTemplate->parseHtmlByName ('error_plank', $aVars);
177  }
178 
179  if (isset($_POST['remove_avatar'])) {
180  $sImagePath = CH_AVA_DIR_TMP . $this->_iProfileId . CH_AVA_EXT;
181  if (@unlink($sImagePath)) {
182  $aVars = array ('msg' => _t('_ch_ava_msg_avatar_was_deleted'));
183  echo $this->_oTemplate->parseHtmlByName ('error_plank', $aVars);
184  }
185  }
186 
187  ch_avatar_import ('PageMain');
188  $oPage = new ChAvaPageMain ($this);
189  echo $oPage->getCode();
190  $this->_oTemplate->addCss (array('main.css', 'colors.css', 'imgareaselect-default.css'));
191  $this->_oTemplate->addJs ('jquery.imgareaselect.min.js');
192  $this->_oTemplate->pageCode(_t('_ch_ava_page_title_home'), false, false);
193  }
194 
196  {
197  echo $this->serviceGetSiteAvatars ((int)$iPage);
198  exit;
199  }
200 
201  function actionSetSiteAvatar ($sImg)
202  {
203  $iAvatar = (int)$sImg;
204  if (!$iAvatar || 0 !== strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
205  echo _t('_ch_ava_msg_error_occured');
206  exit;
207  }
208 
209  if (!$this->isAllowedAdd()) {
210  echo _t('_ch_ava_msg_access_denied');
211  exit;
212  }
213 
214  if (!$this->_addAvatar (CH_AVA_DIR_SITE_AVATARS . $iAvatar . CH_AVA_EXT)) {
215  echo _t('_ch_ava_msg_error_occured');
216  exit;
217  }
218 
219  $this->isAllowedAdd(true); // perform action
220 
221  echo $this->serviceGetMyAvatars ($this->_iProfileId);
222  exit;
223  }
224 
225  function actionSetAvatar ($iProfileId, $sImg)
226  {
227  $this->_setAvatar ($iProfileId, $sImg, false);
228  }
229 
231  {
232  $this->_setAvatar ($iProfileId, $sImg, true);
233  }
234 
235  function _setAvatar ($iProfileId, $sImg, $isSetAvatarForCouple = false)
236  {
237  if (!$this->isAdmin())
238  $iProfileId = $iProfileIdOrig = $this->_iProfileId;
239  else
240  $iProfileIdOrig = $iProfileId;
241 
242  $iAvatar = (int)$sImg;
243  if (!$iAvatar || 0 !== strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
244  echo _t('_ch_ava_msg_error_occured');
245  exit;
246  }
247 
248  $aDataEntry = $this->_oDb->getAvatarByIdAndOwner ($iAvatar, $iProfileId, $this->isAdmin());
249  if (!$aDataEntry) {
250  echo _t('_ch_ava_msg_access_denied');
251  exit;
252  }
253 
254  $aProfileCouple = array ();
255  if ($isSetAvatarForCouple) {
256  $aProfileMain = getProfileInfo($iProfileId);
257  if ($aProfileMain['Couple']) {
258  $aProfileCouple = getProfileInfo($aProfileMain['Couple']);
259  $iProfileId = $aProfileCouple['ID'];
260  }
261  }
262 
263  if (!$this->_oDb->updateProfile ($iAvatar, $iProfileId, true)) {
264  echo _t('_ch_ava_msg_access_denied');
265  exit;
266  }
267 
268  $this->onEventChanged ($iProfileIdOrig, $iAvatar, $aProfileCouple ? $aProfileCouple['ID'] : 0, false);
269 
270  echo $this->serviceGetMyAvatars ($iProfileIdOrig);
271  exit;
272  }
273 
274  function actionRemoveAvatar ($iProfileId, $sImg)
275  {
276  if (!$this->isAdmin())
278 
279  $iAvatar = (int)$sImg;
280  if (!$iAvatar || 0 !== strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
281  echo _t('_ch_ava_msg_error_occured');
282  exit;
283  }
284 
285  $aDataEntry = $this->_oDb->getAvatarByIdAndOwner ($iAvatar, $iProfileId, $this->isAdmin());
286  if (!$this->isAllowedDelete($aDataEntry)) {
287  echo _t('_ch_ava_msg_access_denied');
288  exit;
289  }
290 
291  if (!$this->_removeAvatar ($iProfileId, $iAvatar)) {
292  echo _t('_ch_ava_msg_error_occured');
293  exit;
294  }
295 
296  $this->isAllowedDelete($aDataEntry, true); // perform action
297 
298  echo $this->serviceGetMyAvatars ($iProfileId);
299  exit;
300  }
301 
303  {
304  echo $GLOBALS['oFunctions']->getMemberThumbnail(-1 == $iProfileId ? $this->_iProfileId : $iProfileId);
305  }
306 
308  {
309  if (!$this->isAdmin()) {
310  $this->_oTemplate->displayAccessDenied ();
311  return;
312  }
313 
314  $this->_oTemplate->pageStart();
315 
316  $iId = $this->_oDb->getSettingsCategory();
317  if(empty($iId)) {
318  echo MsgBox(_t('_ch_ava_msg_page_not_found'));
319  $this->_oTemplate->pageCodeAdmin (_t('_ch_ava_administration'));
320  return;
321  }
322 
323  ch_import('ChWsbAdminSettings');
324 
325  $mixedResult = '';
326  if(isset($_POST['save']) && isset($_POST['cat'])) {
328  $mixedResult = $oSettings->saveChanges($_POST);
329  }
330 
332  $sResult = $oSettings->getForm();
333 
334  if($mixedResult !== true && !empty($mixedResult))
335  $sResult = $mixedResult . $sResult;
336 
337  $aVars = array (
338  'content' => $sResult,
339  );
340  echo $this->_oTemplate->adminBlock ($this->_oTemplate->parseHtmlByName('default_padding', $aVars), _t('_ch_ava_administration'));
341 
342  $this->_oTemplate->addCssAdmin (array('main.css', 'colors.css'));
343  $this->_oTemplate->addCssAdmin ('forms_adv.css');
344  $this->_oTemplate->pageCodeAdmin (_t('_ch_ava_administration'));
345  }
346 
347  // ================================== external actions
348 
360  {
361  $sImagePath = CH_AVA_DIR_TMP . ((int)$iProfileId ? (int)$iProfileId : $this->_iProfileId) . CH_AVA_EXT;
362  if (@copy($sOrigPath, $sImagePath)) {
363  return IMAGE_ERROR_SUCCESS == imageResize($sImagePath, '', CH_AVA_PRE_RESIZE_W, CH_AVA_PRE_RESIZE_H, true) ? true : false;
364  }
365  return false;
366  }
367 
373  function serviceMakeAvatarFromImage ($sImg)
374  {
375  if (!$this->_iProfileId)
376  return false;
377 
378  if (!file_exists($sImg))
379  return false;
380 
381  $sImagePath = CH_AVA_DIR_TMP . '_' . $this->_iProfileId . CH_AVA_EXT;
382 
384  $o->removeCropOptions ();
385  $o->setJpegOutput (true);
386  $o->setSize (CH_AVA_W, CH_AVA_W);
387  $o->setSquareResize (true);
388  if (IMAGE_ERROR_SUCCESS != $o->resize($sImg, $sImagePath))
389  return false;
390 
391  return $this->_addAvatar ($sImagePath, true);
392  }
393 
399  function serviceMakeAvatarFromImageUrl ($sImgUrl)
400  {
401  if (!$this->_iProfileId)
402  return false;
403 
404  $s = ch_file_get_contents ($sImgUrl);
405  if (!$s)
406  return false;
407 
408  $sImagePath = CH_AVA_DIR_TMP . '_' . $this->_iProfileId . CH_AVA_EXT;
409  if (!file_put_contents($sImagePath, $s))
410  return false;
411 
412  return $this->serviceMakeAvatarFromImage($sImagePath);
413  }
414 
421  function serviceMakeAvatarFromSharedPhotoAuto ($iSharedPhotoId)
422  {
423  if (!$this->_iProfileId)
424  return false;
425 
426  $aImageFile = ChWsbService::call('photos', 'get_photo_array', array((int)$iSharedPhotoId, 'file'), 'Search');
427  if (!$aImageFile)
428  return false;
429 
430  return $this->serviceMakeAvatarFromImage($aImageFile['path']);
431  }
432 
440  function serviceCropTool ($aParams)
441  {
442  if (!$aParams || !is_array($aParams)) {
443  return _t('_ch_ava_msg_error_occured');
444  }
445 
446  if (!file_exists($aParams['dir_image'])) {
447  return _t ('_ch_ava_no_crop_image');
448  }
449 
450  ch_import('ChWsbImageResize');
451  $aSizes = ChWsbImageResize::getImageSize ($aParams['dir_image']);
452  $aVars = array (
453  'url_img' => $aParams['url_image'],
454  'img_width' => $aSizes['w'] ? $aSizes['w'] : 0,
455  'img_height' => $aSizes['h'] ? $aSizes['h'] : 0,
456  'action' => CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri(),
457  );
458  return $this->_oTemplate->parseHtmlByName ('crop_tool', $aVars);
459  }
460 
467  {
468  if (!(int)$iProfileId)
469  return false;
470  $aDataEntries = $this->_oDb->getAvatarsByAuthor ((int)$iProfileId);
471  foreach ($aDataEntries as $iEntryId) {
472  if ($this->_oDb->deleteAvatarByIdAndOwner($iEntryId, (int)$iProfileId, $this->isAdmin())) {
473  @unlink (CH_AVA_DIR_USER_AVATARS . $iEntryId . CH_AVA_EXT);
474  @unlink (CH_AVA_DIR_USER_AVATARS . $iEntryId . 'i' . CH_AVA_EXT);
475  @unlink (CH_AVA_DIR_USER_AVATARS . $iEntryId . 'b' . CH_AVA_EXT);
476  $this->onEventDeleted ($iEntryId);
477  }
478  }
479  return true;
480  }
481 
490  {
491  $sPwd = db_value("SELECT `Password` FROM `Profiles` WHERE `ID` = '".(int)$iMemID."' LIMIT 1");
492  if ($sPwd) {
493 
494  ch_import('ChWsbPermalinks');
495  $o = new ChWsbPermalinks();
496 
497  header('Location: ' . CH_WSB_URL_ROOT . $o->permalink('modules/?r=avatar/') . '&join_text=' . $sStatusText); // redirect to upload avatar page
498 
499  return 'EXIT';
500  }
501  return false;
502  }
503 
510  {
511  $iPage = (int)$iPage ? (int)$iPage : 1;
512  $iPerPage = 12;
513  $iCounter = 0;
514  $iStart = ($iPage-1) * $iPerPage;
515  $aFiles = array ();
516  if ($h = opendir(CH_AVA_DIR_SITE_AVATARS)) {
517  while (($sFile = readdir($h)) !== false) {
518  if ('.' == $sFile[0])
519  continue;
520  if ($iCounter++ < $iStart)
521  continue;
522  if ($iCounter - $iStart <= $iPerPage)
523  $aFiles[] = array ('url' => CH_AVA_URL_SITE_AVATARS . $sFile, 'name' => $sFile);
524  }
525  closedir($h);
526  }
527 
528  ch_import('ChWsbPaginate');
529  $oPaginate = new ChWsbPaginate(array(
530  'page_url' => 'javascript:void(0);',
531  'count' => $iCounter,
532  'per_page' => $iPerPage,
533  'page' => $iPage,
534  'on_change_page' => "getHtmlData('ch_ava_site_avatars', '" . $this->_oConfig->getBaseUri() . "get_site_avatars/{page}');",
535  ));
536  $sAjaxPaginate = $oPaginate->getSimplePaginate('', -1, -1, false);
537 
538  $sScript = "<script>
539  $(document).ready(function() {
540  $('#ch_ava_site_avatars .ch_ava_tar .ch_ava_actions a').bind('click', function (e) {
541  var e = $(this);
542  getHtmlData('ch_ava_my_avatars', '" . $this->_oConfig->getBaseUri() . "set_site_avatar/' + $(this).attr('alt'), function () {
543  e.html('" . ch_js_string(_t('_ch_ava_ok'), CH_ESCAPE_STR_APOS) . "');
544  }, 'post');
545  });
546  });
547  </script>";
548 
549  $aVars = array (
550  'ch_repeat:avatars' => $aFiles,
551  );
552  return $sAjaxPaginate . '<div class="ch-def-padding-thd">' . $GLOBALS['oFunctions']->centerContent($this->_oTemplate->parseHtmlByName ('avatars_site', $aVars), '.ch_ava_tar') . '</div>' . $sAjaxPaginate . $sScript;
553  }
554 
555  function serviceManageAvatars ($iProfileId, $isAddJsCss = false)
556  {
557  if (!$this->isAdmin())
558  return '';
559 
560  $this->_oTemplate->addCss (array('main.css', 'colors.css', 'imgareaselect-default.css'));
561 
562  $aVars = array (
563  'content' => $this->serviceGetMyAvatars ($iProfileId),
564  );
565  return array($this->_oTemplate->parseHtmlByName ('manage_avatars', $aVars), array(), array(), false);
566  }
567 
574  {
575  if (!(int)$iProfileId)
576  return _t('_ch_ava_msg_access_denied');
577 
578  $aProfileCouple = array();
579  $aProfileMain = getProfileInfo((int)$iProfileId);
580  if ($aProfileMain['Couple'])
581  $aProfileCouple = getProfileInfo($aProfileMain['Couple']);
582  $aAvatars = $this->_oDb->getAvatarsByAuthor((int)$iProfileId);
583 
584  $iAvatarCurrent = $this->_oDb->getCurrentAvatar((int)$iProfileId, $this->isAdmin());
585  $iAvatarCurrentCouple = $this->_oDb->getCurrentAvatar($aProfileCouple['ID'], $this->isAdmin());
586 
587  $aFiles = array ();
588  foreach ($aAvatars as $iAvatar) {
589  $aFiles[] = array (
590  'url' => CH_AVA_URL_USER_AVATARS . $iAvatar . CH_AVA_EXT,
591  'name' => $iAvatar . CH_AVA_EXT,
592  'ch_if:is_not_main' => array ('condition' => $iAvatarCurrent != $iAvatar, 'content' => array('name' => $iAvatar . CH_AVA_EXT)),
593  'ch_if:is_not_main_couple' => array ('condition' => $aProfileCouple && $iAvatarCurrentCouple != $iAvatar, 'content' => array('name' => $iAvatar . CH_AVA_EXT)),
594  );
595  }
596 
597  $sScript = "<script>
598  $(document).ready(function() {
599  $('#ch_ava_my_avatars .ch_ava_tar .ch_ava_actions a.ch_ava_set_couple').bind('click', function (e) {
600  getHtmlData('ch_ava_my_avatars', '" . $this->_oConfig->getBaseUri() . "set_avatar_couple/$iProfileId/' + $(this).attr('alt'), false, 'post');
601  });
602  $('#ch_ava_my_avatars .ch_ava_tar .ch_ava_actions a.ch_ava_set').bind('click', function (e) {
603  getHtmlData('ch_ava_my_avatars', '" . $this->_oConfig->getBaseUri() . "set_avatar/$iProfileId/' + $(this).attr('alt'), false, 'post');
604  });
605  $('#ch_ava_my_avatars .ch_ava_tar .ch_ava_actions a.ch_ava_del').bind('click', function (e) {
606  getHtmlData('ch_ava_my_avatars', '" . $this->_oConfig->getBaseUri() . "remove_avatar/$iProfileId/' + $(this).attr('alt'), false, 'post');
607  });
608  getHtmlData('ch_ava_current', '" . $this->_oConfig->getBaseUri() . "member_thumb/-1');
609  });
610  </script>";
611 
612  if (!$aFiles)
613  return MsgBox(_t('_Empty')) . $sScript;
614 
615  $aVars = array (
616  'ch_repeat:avatars' => $aFiles,
617  );
618  return $GLOBALS['oFunctions']->centerContent($this->_oTemplate->parseHtmlByName ('avatars_my', $aVars), '.ch_ava_tar') . $sScript;
619  }
620 
626  function serviceGetWallPost ($aEvent)
627  {
628  $aProfile = getProfileInfo($aEvent['owner_id']);
629  if(empty($aProfile))
630  return array('perform_delete' => true);
631 
632  if($aProfile['Status'] != 'Active')
633  return "";
634 
635  $sCss = '';
636  if($aEvent['js_mode'])
637  $sCss = $this->_oTemplate->addCss('wall_post.css', true);
638  else
639  $this->_oTemplate->addCss('wall_post.css');
640 
641  $sOwner = getNickName((int)$aEvent['owner_id']);
642  $sTxtWallObject = _t('_ch_ava_wall_object');
643 
644  return array(
645  'title' => _t('_ch_ava_wall_title_' . $aEvent['action'], $sOwner, $sTxtWallObject),
646  'description' => '',
647  'content' => $sCss . $this->_oTemplate->parseHtmlByName('wall_post', array(
648  'cpt_user_name' => $sOwner,
649  'cpt_added_new' => _t('_ch_ava_wall_' . $aEvent['action']),
650  'cpt_object' => $sTxtWallObject,
651  'post_id' => $aEvent['id'],
652  ))
653  );
654  }
655 
660  function serviceGetWallData ()
661  {
662  $sUri = $this->_oConfig->getUri();
663  $sName = 'ch_' . $sUri;
664 
665  return array(
666  'handlers' => array(
667  array('alert_unit' => $sName, 'alert_action' => 'add', 'module_uri' => $sUri, 'module_class' => 'Module', 'module_method' => 'get_wall_post', 'timeline' => 1, 'outline' => 0),
668  array('alert_unit' => $sName, 'alert_action' => 'change', 'module_uri' => $sUri, 'module_class' => 'Module', 'module_method' => 'get_wall_post', 'timeline' => 1, 'outline' => 0)
669  ),
670  'alerts' => array(
671  array('unit' => $sName, 'action' => 'add'),
672  array('unit' => $sName, 'action' => 'change')
673  )
674  );
675  }
676 
677  // ================================== admin actions
678 
679 
680  // ================================== events
681 
682  function onEventCreate ($iEntryId)
683  {
684  $oAlert = new ChWsbAlerts('ch_avatar', 'add', $iEntryId, $this->_iProfileId);
685  $oAlert->alert();
686  }
687 
688  function onEventChanged ($iProfileId, $iEntryId, $iCoupleProfileId = 0, $isTryToSuspend = true)
689  {
690  if ($iCoupleProfileId) {
691  createUserDataFile($iCoupleProfileId);
692  }
693 
694  if ($isTryToSuspend && $iProfileId && !$this->isAdmin() && !getParam('autoApproval_ifProfile'))
695  $this->_oDb->suspendProfile($iProfileId);
696 
698  $GLOBALS['MySQL']->cleanCache('sys_browse_people');
699 
700  $oAlert = new ChWsbAlerts('ch_avatar', 'change', $iEntryId, $iProfileId);
701  $oAlert->alert();
702  }
703 
704  function onEventDeleted ($iEntryId, $aDataEntry = array())
705  {
706  createUserDataFile($this->_iProfileId);
707  // arise alert
708  $oAlert = new ChWsbAlerts('ch_avatar', 'delete', $iEntryId, $this->_iProfileId);
709  $oAlert->alert();
710  }
711 
712  // ================================== permissions
713 
714  function isAllowedAdd ($isPerformAction = false)
715  {
716  if ($this->isAdmin()) return true;
717  if (!$GLOBALS['logged']['member']) return false;
718  $this->_defineActions();
719  $aCheck = checkAction($this->_iProfileId, CH_AVATAR_UPLOAD, $isPerformAction, 0, false);
721  }
722 
723  function isAllowedEdit ($aDataEntry, $isPerformAction = false)
724  {
725  if ($this->isAdmin() || ($GLOBALS['logged']['member'] && $aDataEntry['author_id'] == $this->_iProfileId)) return true;
726  $this->_defineActions();
727  $aCheck = checkAction($this->_iProfileId, CH_AVATAR_EDIT_ANY, $isPerformAction);
729  }
730 
731  function isAllowedDelete (&$aDataEntry, $isPerformAction = false)
732  {
733  if ($this->isAdmin() || ($GLOBALS['logged']['member'] && $aDataEntry['author_id'] == $this->_iProfileId)) return true;
734  $this->_defineActions();
735  $aCheck = checkAction($this->_iProfileId, CH_AVATAR_DELETE_ANY, $isPerformAction);
737  }
738 
739  function isAdmin ()
740  {
741  return $GLOBALS['logged']['admin'] || $GLOBALS['logged']['moderator'];
742  }
743 
744  function _defineActions ()
745  {
746  defineMembershipActions(array('avatar upload', 'avatar edit any', 'avatar delete any'));
747  }
748 
749  // ================================== other function
750 
751  function _removeAvatar ($iProfileId, $iAvatar)
752  {
753  if (!$this->isAdmin())
755 
756  $iAvatar = (int)$iAvatar;
757 
758  @unlink(CH_AVA_DIR_USER_AVATARS . $iAvatar . CH_AVA_EXT);
759  @unlink(CH_AVA_DIR_USER_AVATARS . $iAvatar . 'i' . CH_AVA_EXT);
760  @unlink(CH_AVA_DIR_USER_AVATARS . $iAvatar . 'b' . CH_AVA_EXT);
761 
762  $iAvatarCurrent = $this->_oDb->getCurrentAvatar($iProfileId, $this->isAdmin());
763 
764  if ($this->_oDb->deleteAvatarByIdAndOwner ($iAvatar, $iProfileId, $this->isAdmin())) {
765  if ($iAvatarCurrent == $iAvatar) {
766  if ($this->_oDb->updateProfile (-1, $iProfileId, $this->isAdmin())) {
767  $this->onEventChanged ($iProfileId, $iAvatar, 0, false);
768  }
769  }
770  return true;
771  }
772  return false;
773  }
774 
775  function _addAvatar ($sFullPath, $isMove = false, $isUpdateProfile = true)
776  {
777  if (!file_exists($sFullPath))
778  return false;
779 
780  if (!($iAvatar = $this->_oDb->addAvatar($this->_iProfileId)))
781  return false;
782 
783  $sImageBrowse = CH_AVA_DIR_USER_AVATARS . $iAvatar . 'b' . CH_AVA_EXT;
784  $sImageThumb = CH_AVA_DIR_USER_AVATARS . $iAvatar . CH_AVA_EXT;
785  $sImageIcon = CH_AVA_DIR_USER_AVATARS . $iAvatar . 'i' . CH_AVA_EXT;
786 
787 
788  if ($isMove)
789  $isOk = rename ($sFullPath, $sImageBrowse);
790  else
791  $isOk = copy ($sFullPath, $sImageBrowse);
792 
793  if ($isOk) {
794  if(!$this->_resizeImage($sImageBrowse, $sImageThumb, CH_AVA_W, CH_AVA_H)) {
795  $this->_oDb->deleteAvatarByIdAndOwner ($iAvatar, $this->_iProfileId, $this->isAdmin());
796  @unlink($sImageBrowse);
797  @unlink($sImageThumb);
798  return false;
799  }
800 
801  if(!$this->_resizeImage($sImageBrowse, $sImageIcon, CH_AVA_ICON_W, CH_AVA_ICON_H)) {
802  $this->_oDb->deleteAvatarByIdAndOwner ($iAvatar, $this->_iProfileId, $this->isAdmin());
803  @unlink($sImageBrowse);
804  @unlink($sImageThumb);
805  @unlink($sImageIcon);
806  return false;
807  }
808  }
809 
810  if (!$isOk) {
811  $this->_oDb->deleteAvatarByIdAndOwner ($iAvatar, $this->_iProfileId, $this->isAdmin());
812  } else if ($isUpdateProfile) {
813  $this->onEventCreate ($iAvatar);
814  if ($this->_oDb->updateProfile ($iAvatar, $this->_iProfileId, $this->isAdmin())) {
815  $this->onEventChanged ($this->_iProfileId, $iAvatar);
816  }
817  }
818 
819  return $isOk ? $iAvatar : false;
820  }
821 
822  function _resizeImage($sImageSrc, $sImageDst, $iWidth, $iHeight, $bSquareResize = false, $bJpegOutput = true)
823  {
825  $o->setJpegOutput($bJpegOutput);
826  $o->removeCropOptions();
827  $o->setSize($iWidth, $iHeight);
828  $o->setSquareResize ($bSquareResize);
829 
830  return $o->resize($sImageSrc, $sImageDst) == IMAGE_ERROR_SUCCESS;
831  }
832 
833  function _uploadImage ($iProfileId = 0)
834  {
835  $iProfileId = (int)$iProfileId;
836  $sImagePath = CH_AVA_DIR_TMP . ($iProfileId ? $iProfileId : $this->_iProfileId) . CH_AVA_EXT;
837 
838 
839  $i = strrpos($_FILES['image']['name'], '.');
840  if (false === $i)
841  return false;
842  $sExt = strtolower(substr($_FILES['image']['name'], $i + 1));
843  if (!in_array($sExt, $this->_aAllowedExt))
844  return false;
845 
846 
847  if (move_uploaded_file($_FILES['image']['tmp_name'], $sImagePath)) {
848  if ($_POST['copy_to_profile_photos']) {
849  if (ChWsbRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader')) {
850  ch_import('ChWsbPrivacyQuery');
851  $oPrivacy = new ChWsbPrivacyQuery();
852 
853  $aFileInfo = array (
854  'medTitle' => _t('_ch_ava_avatar'),
855  'medDesc' => _t('_ch_ava_avatar'),
856  'medTags' => _t('_ProfilePhotos'),
857  'Categories' => array(_t('_ProfilePhotos')),
858  'album' => str_replace('{nickname}', getUsername($iProfileId), getParam('ch_photos_profile_album_name')),
859  'albumPrivacy' => $oPrivacy->getDefaultValueModule('photos', 'album_view'),
860  );
861 
862  $_POST[CH_WSB_UPLOADER_EP_PREFIX . 'album'] = uriFilter($aFileInfo['album']);
863  ChWsbService::call('photos', 'perform_photo_upload', array($sImagePath, $aFileInfo, false), 'Uploader');
864  }
865  }
866  return IMAGE_ERROR_SUCCESS == imageResize($sImagePath, '', CH_AVA_PRE_RESIZE_W, CH_AVA_PRE_RESIZE_H, true) ? true : false;
867  }
868  return false;
869  }
870 
871  function _makeAvatarFromSharedPhoto ($iSharedPhotoId)
872  {
873  $aImageFile = ChWsbService::call('photos', 'get_photo_array', array((int)$iSharedPhotoId, 'file'), 'Search');
874  if (!$aImageFile)
875  return false;
876 
877  $sImagePath = CH_AVA_DIR_TMP . $this->_iProfileId . CH_AVA_EXT;
878  if (!@copy($aImageFile['path'], $sImagePath))
879  return false;
880 
881  return IMAGE_ERROR_SUCCESS == imageResize($sImagePath, '', CH_AVA_PRE_RESIZE_W, CH_AVA_PRE_RESIZE_H, true) ? true : false;
882  }
883 
884  function _cropAvatar ()
885  {
886  $sSrcImagePath = CH_AVA_DIR_TMP . $this->_iProfileId . CH_AVA_EXT;
887  $sDstImagePath = CH_AVA_DIR_TMP . 'tmp' . $this->_iProfileId . CH_AVA_EXT;
889  $o->setJpegOutput (true);
890  $o->setJpegQuality (getParam('ch_avatar_quality'));
891  $o->setSize (CH_AVA_BROWSE_W, CH_AVA_BROWSE_H);
892 
893  if ((int)$_POST['w'] && (int)$_POST['h']) {
894  $o->setSquareResize (false);
895  $aSize = $o->getImageSize($sSrcImagePath);
896  $bRet = $aSize ? $o->crop($aSize['w'], $aSize['h'], (int)$_POST['x1'], (int)$_POST['y1'], (int)$_POST['w'], (int)$_POST['h'], 0, $sSrcImagePath) : IMAGE_ERROR_WRONG_TYPE;
897  } else {
898  $o->setSquareResize (true);
899  $bRet = IMAGE_ERROR_SUCCESS;
900  }
901 
902  if (IMAGE_ERROR_SUCCESS == $bRet && IMAGE_ERROR_SUCCESS == $o->resize($sSrcImagePath, $sDstImagePath))
903  $bRet = $this->_addAvatar ($sDstImagePath, true) ? IMAGE_ERROR_SUCCESS : IMAGE_ERROR_WRONG_TYPE;
904 
905  if (IMAGE_ERROR_SUCCESS == $bRet) {
906  @unlink($sSrcImagePath);
907  return true;
908  }
909  @unlink($sDstImagePath);
910  return false;
911  }
912 }
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
$oSettings
$oSettings
Definition: advanced_settings.php:20
CH_AVA_URL_SITE_AVATARS
const CH_AVA_URL_SITE_AVATARS
Definition: ChAvaModule.php:26
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
ChAvaModule\serviceGetMyAvatars
serviceGetMyAvatars($iProfileId)
Definition: ChAvaModule.php:573
IMAGE_ERROR_WRONG_TYPE
const IMAGE_ERROR_WRONG_TYPE
operation failed, most probably because incorrect image format(or not image file) was provided
Definition: ChWsbImageResize.php:23
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
ChAvaModule\serviceSetImageForCropping
serviceSetImageForCropping($iProfileId, $sOrigPath)
Definition: ChAvaModule.php:359
ChWsbModule\getInstance
static getInstance($sClassName)
Definition: ChWsbModule.php:89
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
ch_avatar_import
ch_avatar_import($sClassPostfix, $aModuleOverwright=array())
Definition: ChAvaModule.php:8
ChAvaModule\_uploadImage
_uploadImage($iProfileId=0)
Definition: ChAvaModule.php:833
ChAvaModule\isAllowedEdit
isAllowedEdit($aDataEntry, $isPerformAction=false)
Definition: ChAvaModule.php:723
ChAvaModule\serviceGetWallPost
serviceGetWallPost($aEvent)
Definition: ChAvaModule.php:626
ch_js_string
ch_js_string($mixedInput, $iQuoteType=CH_ESCAPE_STR_AUTO)
Definition: utils.inc.php:1294
ChAvaModule\_removeAvatar
_removeAvatar($iProfileId, $iAvatar)
Definition: ChAvaModule.php:751
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
$sResult
$sResult
Definition: advanced_settings.php:26
$aModule
$aModule
Definition: classifieds.php:21
ChAvaModule\_defineActions
_defineActions()
Definition: ChAvaModule.php:744
ChAvaModule\_resizeImage
_resizeImage($sImageSrc, $sImageDst, $iWidth, $iHeight, $bSquareResize=false, $bJpegOutput=true)
Definition: ChAvaModule.php:822
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$oAlert
$oAlert
Definition: embed.php:15
CHECK_ACTION_RESULT
const CHECK_ACTION_RESULT
Definition: membership_levels.inc.php:54
ChWsbPrivacyQuery
Definition: ChWsbPrivacyQuery.php:11
ChAvaModule\onEventCreate
onEventCreate($iEntryId)
Definition: ChAvaModule.php:682
php
$iId
$iId
Definition: license.php:15
CH_AVA_PRE_RESIZE_W
const CH_AVA_PRE_RESIZE_W
Definition: ChAvaModule.php:31
ChAvaModule\serviceGetSiteAvatars
serviceGetSiteAvatars($iPage)
Definition: ChAvaModule.php:509
ChAvaModule\actionHome
actionHome()
Definition: ChAvaModule.php:142
$oPage
$oPage
Definition: search_home.php:83
CH_AVA_PRE_RESIZE_H
const CH_AVA_PRE_RESIZE_H
Definition: ChAvaModule.php:32
$sExt
$sExt
Definition: get_file.php:14
$sPwd
$sPwd
Definition: r.php:14
ChAvaModule\actionAdministration
actionAdministration()
Definition: ChAvaModule.php:307
CH_AVA_DIR_TMP
const CH_AVA_DIR_TMP
Definition: ChAvaModule.php:28
$iPerPage
else $iPerPage
Definition: browse.php:61
ChAvaModule\_addAvatar
_addAvatar($sFullPath, $isMove=false, $isUpdateProfile=true)
Definition: ChAvaModule.php:775
ChAvaModule\_makeAvatarFromSharedPhoto
_makeAvatarFromSharedPhoto($iSharedPhotoId)
Definition: ChAvaModule.php:871
copy
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step which gives you legal permission to copy
Definition: license.txt:50
ChAvaModule\isAllowedAdd
isAllowedAdd($isPerformAction=false)
Definition: ChAvaModule.php:714
ChAvaModule\serviceGetWallData
serviceGetWallData()
Definition: ChAvaModule.php:660
ChAvaModule\isAdmin
isAdmin()
Definition: ChAvaModule.php:739
ChAvaModule\serviceMakeAvatarFromImage
serviceMakeAvatarFromImage($sImg)
Definition: ChAvaModule.php:373
ChAvaModule
Definition: ChAvaModule.php:126
ChWsbAlerts
Definition: ChWsbAlerts.php:39
ChAvaModule\onEventChanged
onEventChanged($iProfileId, $iEntryId, $iCoupleProfileId=0, $isTryToSuspend=true)
Definition: ChAvaModule.php:688
exit
exit
Definition: cart.php:21
$sFile
$sFile
Definition: index.php:20
$_GET
$_GET['debug']
Definition: index.php:67
ChWsbImageResize\instance
static instance()
Definition: ChWsbImageResize.php:60
createUserDataFile
createUserDataFile( $userID)
Definition: profiles.inc.php:192
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
CH_WSB_UPLOADER_EP_PREFIX
const CH_WSB_UPLOADER_EP_PREFIX
Definition: ChWsbFilesUploader.php:10
getLoggedId
getLoggedId()
Definition: profiles.inc.php:32
$aProfile
$aProfile
Definition: flash.php:14
ChAvaModule\$_iProfileId
$_iProfileId
Definition: ChAvaModule.php:127
ChAvaModule\actionSetSiteAvatar
actionSetSiteAvatar($sImg)
Definition: ChAvaModule.php:201
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
ChAvaModule\serviceMakeAvatarFromSharedPhotoAuto
serviceMakeAvatarFromSharedPhotoAuto($iSharedPhotoId)
Definition: ChAvaModule.php:421
ChAvaModule\serviceDeleteProfileAvatars
serviceDeleteProfileAvatars($iProfileId)
Definition: ChAvaModule.php:466
uriFilter
uriFilter($s)
Definition: utils.inc.php:931
ch_file_get_contents
ch_file_get_contents($sFileUrl, $aParams=array(), $sMethod='get', $aHeaders=array(), &$sHttpCode=null)
Definition: utils.inc.php:1357
getUsername
getUsername( $ID='')
Definition: profiles.inc.php:443
ChWsbPaginate
Definition: ChWsbPaginate.php:69
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
ChWsbModule
Definition: ChWsbModule.php:41
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
checkAction
checkAction($iMemberId, $actionID, $performAction=false, $iForcedProfID=0, $isCheckMemberStatus=true)
Definition: membership_levels.inc.php:313
ChAvaModule\serviceCropTool
serviceCropTool($aParams)
Definition: ChAvaModule.php:440
$aVars
$aVars
Definition: license.php:101
ChAvaModule\actionGetSiteAvatars
actionGetSiteAvatars($iPage)
Definition: ChAvaModule.php:195
defineMembershipActions
defineMembershipActions($aActionsAll, $sPrefix='CH_')
Definition: membership_levels.inc.php:744
$s
$s
Definition: embed.php:13
ChAvaModule\__construct
__construct(&$aModule)
Definition: ChAvaModule.php:135
ChAvaModule\actionMemberThumb
actionMemberThumb($iProfileId)
Definition: ChAvaModule.php:302
CH_ESCAPE_STR_APOS
const CH_ESCAPE_STR_APOS
escape apostrophes only, for js strings enclosed in apostrophes, for use in
Definition: utils.inc.php:33
ChAvaPageMain
Definition: ChAvaPageMain.php:11
$iPage
$iPage
Definition: browse.php:50
ChAvaModule\$_aAllowedExt
$_aAllowedExt
Definition: ChAvaModule.php:128
ChAvaModule\serviceManageAvatars
serviceManageAvatars($iProfileId, $isAddJsCss=false)
Definition: ChAvaModule.php:555
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
ChAvaModule\actionRemoveAvatar
actionRemoveAvatar($iProfileId, $sImg)
Definition: ChAvaModule.php:274
ChAvaModule\_setAvatar
_setAvatar($iProfileId, $sImg, $isSetAvatarForCouple=false)
Definition: ChAvaModule.php:235
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
$sStatusText
$sStatusText
Definition: db.php:25
IMAGE_ERROR_SUCCESS
const IMAGE_ERROR_SUCCESS
operation was successfull
Definition: ChWsbImageResize.php:22
ChAvaModule\_cropAvatar
_cropAvatar()
Definition: ChAvaModule.php:884
ChAvaModule\onEventDeleted
onEventDeleted($iEntryId, $aDataEntry=array())
Definition: ChAvaModule.php:704
$aPathInfo
$aPathInfo
Definition: ChAvaModule.php:22
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$o
$o
Definition: cmd.php:193
imageResize
imageResize( $srcFilename, $dstFilename, $sizeX, $sizeY, $forceJPGOutput=false, $isSquare=false)
Definition: images.inc.php:29
$iMemID
$iMemID
Definition: get_rss_feed.php:45
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
ChAvaModule\actionSetAvatarCouple
actionSetAvatarCouple($iProfileId, $sImg)
Definition: ChAvaModule.php:230
ChAvaModule\actionSetAvatar
actionSetAvatar($iProfileId, $sImg)
Definition: ChAvaModule.php:225
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChAvaModule\serviceMakeAvatarFromImageUrl
serviceMakeAvatarFromImageUrl($sImgUrl)
Definition: ChAvaModule.php:399
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChAvaModule\isAllowedDelete
isAllowedDelete(&$aDataEntry, $isPerformAction=false)
Definition: ChAvaModule.php:731
ChWsbImageResize\getImageSize
static getImageSize($sPath)
Definition: ChWsbImageResize.php:167
$iProfileId
if( $sMembersList) $iProfileId
Definition: communicator.php:29
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
CH_AVA_DIR_SITE_AVATARS
const CH_AVA_DIR_SITE_AVATARS
Definition: ChAvaModule.php:25
ChAvaModule\serviceJoin
serviceJoin($iMemID, $sStatusText)
Definition: ChAvaModule.php:489