function isDefaultAvatarOfProfileType($path, $isDefaultCheckRequired = false) { //if default check required //we should not ignore case for windows if ($isDefaultCheckRequired) { $val1 = JString::stristr(DEFAULT_AVATAR, $path); $val2 = JString::stristr(DEFAULT_AVATAR_THUMB, $path); if ($val1 || $val2) { return true; } } //if user avatar contains "STORAGE_PATH/avatar_" then it is default avatar if (JString::stristr($path, PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . 'avatar_')) { return true; } static $allAvatars = null; //it will improve the performance if ($allAvatars == null) { $searchFor = 'avatar'; $allAvatars = array(); $records = XiptFactory::getInstance('profiletypes', 'model')->loadRecords(0); foreach ($records as $record) { array_push($allAvatars, $record->{$searchFor}); } if (empty($allAvatars)) { return true; } } foreach ($allAvatars as $av) { if (empty($av)) { continue; } if (JString::stristr($av, $path)) { return true; } if (JString::stristr($path, XiptHelperImage::getThumbAvatarFromFull($av))) { return true; } } return false; }
function onProfileAvatarUpdate($userid, $old_avatar_path, $new_avatar_path) { // When admin is removing a user's avatar // we need to apply default avatar of profiletype $isAdmin = XiptHelperUtils::isAdmin(JFactory::getUser()->id); $view = JRequest::getVar('view', '', 'GET'); $task = JRequest::getVar('task', '', 'GET'); $new_avatar_path = XiptHelperUtils::getRealPath($new_avatar_path); if ($isAdmin && $view == 'profile' && $task == 'removepicture') { //setup $new_avatar $ptype = XiptLibProfiletypes::getUserData($userid, 'PROFILETYPE'); $avatar = XiptLibProfiletypes::getProfiletypeData($ptype, 'avatar'); //if users avatar is custom avatar then thumb is stored as thumb_XXXX.png //else if it is a default avatar(JomSocial OR Profiletype) then stored as XXX_thumb.png //HERE the new_avatar will be default jomsocial avatar so search _thumb if (JString::stristr($new_avatar_path, 'thumb')) { $new_avatar_path = XiptHelperImage::getThumbAvatarFromFull($avatar); } else { $new_avatar_path = $avatar; } } //check if avatar is ptype default avatar if (XiptLibProfiletypes::isDefaultAvatarOfProfileType($old_avatar_path, false)) { //HERE we should search for _thumb, not for thumb_ /**XITODO:: Properly test following:: * In JS2.2 :: When our default avatar is user.png then JS delete this avatar from(Community/assets/user.png) * becoz at delete time its only consider default.jpg (components/com_community/assets/default.jpg)as default value and * if avatar is user.png (Community/assets/user.png) then this path is not set into database * but it saved by XiPT 3.1. * JS2.2 does not delete default.jpg(Community/assets/default.jpg) So we changed path. * (Not understanding:: Call 2 manish) :) */ if (JString::stristr($old_avatar_path, 'thumb')) { //$old_avatar_path = DEFAULT_AVATAR_THUMB; $old_avatar_path = 'components/com_community/assets/default_thumb.jpg'; } else { //$old_avatar_path = DEFAULT_AVATAR; $old_avatar_path = 'components/com_community/assets/default.jpg'; } } //Now apply watermark to images // for that we don't require to add watermark // XITODO : format it in proper way if (!XiptLibProfiletypes::getParams(XiptLibProfiletypes::getUserData($userid), 'watermarkparams')->get('enableWaterMark', 0)) { return true; } //check if uploadable avatar is not default ptype avatar /**XITODO:: Properly testing following * In JS 2.2:: user.png consider as a default avatar for every user and dont save this avatar path in community user table * So XiPT 3.1 also consider user.png as default avatar * But may be Xipt installed on existing data then at reset all time, may b apply watr-mrk on * community/assets/defauult.jpg (not usr.png). * Need properly testing and if get above thing then restict. :) */ if (XiptLibProfiletypes::isDefaultAvatarOfProfileType($new_avatar_path, true)) { return true; } //check what is new image , if thumb or original $what = JString::stristr($new_avatar_path, 'thumb') ? 'thumb' : 'avatar'; $watermarkInfo = XiptHelperImage::getWatermark($userid); if (false == $watermarkInfo) { return true; } XiptHelperImage::addWatermarkOnAvatar($userid, $new_avatar_path, $watermarkInfo, $what); return true; }
/** * It updates user's oldAvtar to newAvatars * @param $userid * @param $newAvatar * @return unknown_type */ function updateCommunityUserDefaultAvatar($userid, $newAvatar) { /* * IMP : Implemented in setup * we migrate profiletype avatars to profiletype-1, 2 etc. * So that we do not need to tense about old avatar of profiletype * */ //reload : so that we do not override previous information if any updated in database. //self::reloadCUser($userid); $user = CFactory::getUser($userid); $userAvatar = $user->_avatar; //Before save, avatar path Change in URL formate $newAvatar = XiptHelperUtils::getUrlpathFromFilePath($newAvatar); //We must enforce this as we never want to overwrite a custom avatar $isDefault = XiptLibProfiletypes::isDefaultAvatarOfProfileType($userAvatar, true); // $changeAvatarOnSyncUp = self::_changeAvatarOnSyncUp($userAvatar); if ($isDefault == false) { return false; } // we can safely update avatar so perform the operation // $user->set('_avatar',$newAvatar); // $user->set('_thumb', XiptHelperImage::getThumbAvatarFromFull($newAvatar)); // // if(!$user->save()) // return false; // $query = new XiptQuery(); if (!$query->update('#__community_users')->set(" avatar = '{$newAvatar}' ")->set(" thumb = '" . XiptHelperImage::getThumbAvatarFromFull($newAvatar) . "' ")->where(" userid = {$userid} ")->dbLoadQuery()->query()) { return false; } //enforce JomSocial to clean cached user self::reloadCUser($userid); return true; }