11 $a = $aModuleOverwright ? $aModuleOverwright :
$aModule;
12 if (!$a || $a[
'uri'] !=
'avatar') {
14 $a = $oMain->_aModule;
23 require_once (
$aPathInfo[
'dirname'] .
'/../include.php');
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/');
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/');
31 define (
'CH_AVA_PRE_RESIZE_W', 600);
32 define (
'CH_AVA_PRE_RESIZE_H', 600);
144 if (!$this->_iProfileId) {
145 $this->_oTemplate->displayAccessDenied ();
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);
155 $this->_oTemplate->pageStart();
157 if (
$_GET[
'make_avatar_from_shared_photo'] > 0) {
159 $aVars = array (
'msg' =>
_t(
'_ch_ava_msg_access_denied'));
160 echo $this->_oTemplate->parseHtmlByName (
'error_plank',
$aVars);
166 if (isset(
$_GET[
'join_text']) &&
$_GET[
'join_text']) {
170 if (isset($_POST[
'set_avatar'])) {
172 $aVars = array (
'msg' =>
_t(
'_ch_ava_msg_access_denied'));
174 $aVars = array (
'msg' =>
_t(
'_ch_ava_set_avatar_error'));
176 echo $this->_oTemplate->parseHtmlByName (
'error_plank',
$aVars);
179 if (isset($_POST[
'remove_avatar'])) {
181 if (@unlink($sImagePath)) {
182 $aVars = array (
'msg' =>
_t(
'_ch_ava_msg_avatar_was_deleted'));
183 echo $this->_oTemplate->parseHtmlByName (
'error_plank',
$aVars);
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);
203 $iAvatar = (int)$sImg;
204 if (!$iAvatar || 0 !== strcasecmp($_SERVER[
'REQUEST_METHOD'],
'POST')) {
205 echo
_t(
'_ch_ava_msg_error_occured');
210 echo
_t(
'_ch_ava_msg_access_denied');
215 echo
_t(
'_ch_ava_msg_error_occured');
242 $iAvatar = (int)$sImg;
243 if (!$iAvatar || 0 !== strcasecmp($_SERVER[
'REQUEST_METHOD'],
'POST')) {
244 echo
_t(
'_ch_ava_msg_error_occured');
248 $aDataEntry = $this->_oDb->getAvatarByIdAndOwner ($iAvatar,
$iProfileId, $this->
isAdmin());
250 echo
_t(
'_ch_ava_msg_access_denied');
254 $aProfileCouple = array ();
255 if ($isSetAvatarForCouple) {
257 if ($aProfileMain[
'Couple']) {
263 if (!$this->_oDb->updateProfile ($iAvatar,
$iProfileId,
true)) {
264 echo
_t(
'_ch_ava_msg_access_denied');
268 $this->
onEventChanged ($iProfileIdOrig, $iAvatar, $aProfileCouple ? $aProfileCouple[
'ID'] : 0,
false);
279 $iAvatar = (int)$sImg;
280 if (!$iAvatar || 0 !== strcasecmp($_SERVER[
'REQUEST_METHOD'],
'POST')) {
281 echo
_t(
'_ch_ava_msg_error_occured');
285 $aDataEntry = $this->_oDb->getAvatarByIdAndOwner ($iAvatar,
$iProfileId, $this->
isAdmin());
287 echo
_t(
'_ch_ava_msg_access_denied');
292 echo
_t(
'_ch_ava_msg_error_occured');
310 $this->_oTemplate->displayAccessDenied ();
314 $this->_oTemplate->pageStart();
316 $iId = $this->_oDb->getSettingsCategory();
318 echo
MsgBox(
_t(
'_ch_ava_msg_page_not_found'));
319 $this->_oTemplate->pageCodeAdmin (
_t(
'_ch_ava_administration'));
326 if(isset($_POST[
'save']) && isset($_POST[
'cat'])) {
328 $mixedResult =
$oSettings->saveChanges($_POST);
334 if($mixedResult !==
true && !
empty($mixedResult))
340 echo $this->_oTemplate->adminBlock ($this->_oTemplate->parseHtmlByName(
'default_padding',
$aVars),
_t(
'_ch_ava_administration'));
342 $this->_oTemplate->addCssAdmin (array(
'main.css',
'colors.css'));
343 $this->_oTemplate->addCssAdmin (
'forms_adv.css');
344 $this->_oTemplate->pageCodeAdmin (
_t(
'_ch_ava_administration'));
362 if (@
copy($sOrigPath, $sImagePath)) {
375 if (!$this->_iProfileId)
378 if (!file_exists($sImg))
381 $sImagePath =
CH_AVA_DIR_TMP .
'_' . $this->_iProfileId . CH_AVA_EXT;
384 $o->removeCropOptions ();
385 $o->setJpegOutput (
true);
386 $o->setSize (CH_AVA_W, CH_AVA_W);
387 $o->setSquareResize (
true);
401 if (!$this->_iProfileId)
408 $sImagePath =
CH_AVA_DIR_TMP .
'_' . $this->_iProfileId . CH_AVA_EXT;
409 if (!file_put_contents($sImagePath,
$s))
423 if (!$this->_iProfileId)
426 $aImageFile =
ChWsbService::call(
'photos',
'get_photo_array', array((
int)$iSharedPhotoId,
'file'),
'Search');
442 if (!$aParams || !is_array($aParams)) {
443 return _t(
'_ch_ava_msg_error_occured');
446 if (!file_exists($aParams[
'dir_image'])) {
447 return _t (
'_ch_ava_no_crop_image');
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(),
458 return $this->_oTemplate->parseHtmlByName (
'crop_tool',
$aVars);
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);
497 header(
'Location: ' . CH_WSB_URL_ROOT .
$o->permalink(
'modules/?r=avatar/') .
'&join_text=' .
$sStatusText);
517 while ((
$sFile = readdir($h)) !==
false) {
520 if ($iCounter++ < $iStart)
530 'page_url' =>
'javascript:void(0);',
531 'count' => $iCounter,
534 'on_change_page' =>
"getHtmlData('ch_ava_site_avatars', '" . $this->_oConfig->getBaseUri() .
"get_site_avatars/{page}');",
536 $sAjaxPaginate = $oPaginate->getSimplePaginate(
'', -1, -1,
false);
539 $(document).ready(function() {
540 $('#ch_ava_site_avatars .ch_ava_tar .ch_ava_actions a').bind('click', function (e) {
542 getHtmlData('ch_ava_my_avatars', '" . $this->_oConfig->getBaseUri() .
"set_site_avatar/' + $(this).attr('alt'), function () {
550 'ch_repeat:avatars' => $aFiles,
552 return $sAjaxPaginate .
'<div class="ch-def-padding-thd">' .
$GLOBALS[
'oFunctions']->centerContent($this->_oTemplate->parseHtmlByName (
'avatars_site',
$aVars),
'.ch_ava_tar') .
'</div>' . $sAjaxPaginate . $sScript;
560 $this->_oTemplate->addCss (array(
'main.css',
'colors.css',
'imgareaselect-default.css'));
565 return array($this->_oTemplate->parseHtmlByName (
'manage_avatars',
$aVars), array(), array(),
false);
576 return _t(
'_ch_ava_msg_access_denied');
578 $aProfileCouple = array();
580 if ($aProfileMain[
'Couple'])
582 $aAvatars = $this->_oDb->getAvatarsByAuthor((
int)
$iProfileId);
585 $iAvatarCurrentCouple = $this->_oDb->getCurrentAvatar($aProfileCouple[
'ID'], $this->
isAdmin());
588 foreach ($aAvatars
as $iAvatar) {
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)),
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');
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');
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');
608 getHtmlData('ch_ava_current', '" . $this->_oConfig->getBaseUri() .
"member_thumb/-1');
613 return MsgBox(
_t(
'_Empty')) . $sScript;
616 'ch_repeat:avatars' => $aFiles,
618 return $GLOBALS[
'oFunctions']->centerContent($this->_oTemplate->parseHtmlByName (
'avatars_my',
$aVars),
'.ch_ava_tar') . $sScript;
630 return array(
'perform_delete' =>
true);
636 if($aEvent[
'js_mode'])
637 $sCss = $this->_oTemplate->addCss(
'wall_post.css',
true);
639 $this->_oTemplate->addCss(
'wall_post.css');
642 $sTxtWallObject =
_t(
'_ch_ava_wall_object');
645 'title' =>
_t(
'_ch_ava_wall_title_' . $aEvent[
'action'], $sOwner, $sTxtWallObject),
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'],
662 $sUri = $this->_oConfig->getUri();
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)
671 array(
'unit' =>
$sName,
'action' =>
'add'),
672 array(
'unit' =>
$sName,
'action' =>
'change')
690 if ($iCoupleProfileId) {
698 $GLOBALS[
'MySQL']->cleanCache(
'sys_browse_people');
716 if ($this->
isAdmin())
return true;
717 if (!
$GLOBALS[
'logged'][
'member'])
return false;
719 $aCheck =
checkAction($this->_iProfileId, CH_AVATAR_UPLOAD, $isPerformAction, 0,
false);
725 if ($this->
isAdmin() || (
$GLOBALS[
'logged'][
'member'] && $aDataEntry[
'author_id'] == $this->_iProfileId))
return true;
727 $aCheck =
checkAction($this->_iProfileId, CH_AVATAR_EDIT_ANY, $isPerformAction);
733 if ($this->
isAdmin() || (
$GLOBALS[
'logged'][
'member'] && $aDataEntry[
'author_id'] == $this->_iProfileId))
return true;
735 $aCheck =
checkAction($this->_iProfileId, CH_AVATAR_DELETE_ANY, $isPerformAction);
756 $iAvatar = (int)$iAvatar;
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);
764 if ($this->_oDb->deleteAvatarByIdAndOwner ($iAvatar,
$iProfileId, $this->isAdmin())) {
765 if ($iAvatarCurrent == $iAvatar) {
766 if ($this->_oDb->updateProfile (-1,
$iProfileId, $this->isAdmin())) {
775 function _addAvatar ($sFullPath, $isMove =
false, $isUpdateProfile =
true)
777 if (!file_exists($sFullPath))
780 if (!($iAvatar = $this->_oDb->addAvatar($this->_iProfileId)))
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;
789 $isOk = rename ($sFullPath, $sImageBrowse);
791 $isOk =
copy ($sFullPath, $sImageBrowse);
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);
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);
811 $this->_oDb->deleteAvatarByIdAndOwner ($iAvatar, $this->_iProfileId, $this->
isAdmin());
812 }
else if ($isUpdateProfile) {
814 if ($this->_oDb->updateProfile ($iAvatar, $this->_iProfileId, $this->isAdmin())) {
819 return $isOk ? $iAvatar :
false;
822 function _resizeImage($sImageSrc, $sImageDst, $iWidth, $iHeight, $bSquareResize =
false, $bJpegOutput =
true)
825 $o->setJpegOutput($bJpegOutput);
826 $o->removeCropOptions();
827 $o->setSize($iWidth, $iHeight);
828 $o->setSquareResize ($bSquareResize);
839 $i = strrpos($_FILES[
'image'][
'name'],
'.');
842 $sExt = strtolower(substr($_FILES[
'image'][
'name'], $i + 1));
843 if (!in_array(
$sExt, $this->_aAllowedExt))
847 if (move_uploaded_file($_FILES[
'image'][
'tmp_name'], $sImagePath)) {
848 if ($_POST[
'copy_to_profile_photos']) {
854 'medTitle' =>
_t(
'_ch_ava_avatar'),
855 'medDesc' =>
_t(
'_ch_ava_avatar'),
856 'medTags' =>
_t(
'_ProfilePhotos'),
857 'Categories' => array(
_t(
'_ProfilePhotos')),
859 'albumPrivacy' => $oPrivacy->getDefaultValueModule(
'photos',
'album_view'),
863 ChWsbService::call(
'photos',
'perform_photo_upload', array($sImagePath, $aFileInfo,
false),
'Uploader');
873 $aImageFile =
ChWsbService::call(
'photos',
'get_photo_array', array((
int)$iSharedPhotoId,
'file'),
'Search');
878 if (!@
copy($aImageFile[
'path'], $sImagePath))
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);
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;
898 $o->setSquareResize (
true);
906 @unlink($sSrcImagePath);
909 @unlink($sDstImagePath);