function fetchElement($name, $value, &$node, $control_name)
 {
     /*value contain profiletype id so get watermark from function */
     $watermark = XiptHelperProfiletypes::getProfileTypeData($value, 'watermark');
     $generatedImage = '';
     /*generate image from watermark */
     $imagePath = JPATH_ROOT . DS . DEFAULT_DEMOAVATAR;
     $watermarkPath = JPATH_ROOT . DS . $watermark;
     $watermarkParams = XiptLibProfiletypes::getParams($value, 'watermarkparams');
     if (JFile::exists($imagePath) && JFile::exists($watermarkPath)) {
         $generatedImage = XiptHelperImage::showWatermarkOverImage($imagePath, $watermarkPath, 'ptype_' . $value, $watermarkParams->get('xiWatermarkPosition'));
     }
     if (DS == '\\') {
         $generatedImage = str_replace('\\', '/', $generatedImage);
     }
     $html = '';
     if ($generatedImage == false || $generatedImage == '') {
         $generatedImage = DEFAULT_DEMOAVATAR;
     }
     $html .= '<img src="' . JURI::root() . '/' . $generatedImage . '" width="64" height="64" alt="generatedimage" border=10 />';
     return $html;
 }
 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;
 }
Exemple #3
0
 function generateThumbnail($imageName, $filename, $storage, $newData, $config)
 {
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'helpers' . DS . 'image.php';
     $fileExt = JFile::getExt($filename);
     $thumbnailName = 'watermark_' . $newData->id . '_thumb.' . $fileExt;
     $storageThumbnail = $storage . DS . $thumbnailName;
     $watermarkPath = $storage . DS . $imageName . '.' . $fileExt;
     $watermarkThumbWidth = $config->get('xiThumbWidth', 80);
     $watermarkThumbHeight = $config->get('xiThumbHeight', 20);
     // create a transparent blank image
     // if type of watermark is text call ImageCreateTrueColor else
     //else call imageCreateTransparent
     if ($config->get('typeofwatermark', '0') == '0') {
         $dstimg = ImageCreateTrueColor($watermarkThumbWidth, $watermarkThumbHeight);
     } else {
         $dstimg = XiptLibImage::imageCreateTransparent($watermarkThumbWidth, $watermarkThumbHeight);
     }
     $watermarkType = XiptHelperImage::getImageType($watermarkPath);
     $srcimg = cImageOpen($watermarkPath, $watermarkType);
     //XITODO : also support other formats
     if (imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $watermarkThumbWidth, $watermarkThumbHeight, $config->get('xiWidth', 64), $config->get('xiHeight', 64))) {
         //fix for permissions
         imagepng($dstimg, $storageThumbnail);
         chmod($storageThumbnail, 0744);
     } else {
         XiptError::raiseWarning('XIPT_THUMB_WAR', 'THUMBNAIL NOT SUPPORTED');
     }
     /*if(!cImageCreateThumb( $watermarkPath , $storageThumbnail , XiptHelperImage::getImageType($watermarkPath),$config->get(xiWidth,64)/2,$config->get(xiHeight,64)/2));
     		$info['msg'] .= sprintf(JText::_('ERROR MOVING UPLOADED FILE') , $storageThumbnail);*/
     return;
 }
Exemple #4
0
 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;
 }
Exemple #5
0
 /**
  * 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;
 }