Exemplo n.º 1
0
 function resetUserAvatar($pid, $newavatar, $oldavatar, $newavatarthumb)
 {
     //get all users for profiletype
     $users = XiptLibProfiletypes::getAllUsers($pid);
     //Change all avatar and thumb path in url formate
     $newavatar = XiptHelperUtils::getUrlpathFromFilePath($newavatar);
     $newavatarthumb = XiptHelperUtils::getUrlpathFromFilePath($newavatarthumb);
     $cnt = count($users);
     for ($i = 0; $i < $cnt; $i++) {
         //if user is admin unset value
         if (XiptHelperUtils::isAdmin($users[$i])) {
             unset($users[$i]);
         }
     }
     $users = array_values($users);
     $cnt = count($users);
     if ($cnt > 0) {
         // XITODO : Change IN query to sub query
         //update user avatar and thumb of all users who doesn't have custom avatar
         $query = new XiptQuery();
         $result = $query->update('#__community_users')->set(" avatar = '{$newavatar}' ")->set(" thumb = '{$newavatarthumb}' ")->where(" avatar = '{$oldavatar}' ")->where(" userid  IN (" . implode(",", $users) . ") ")->dbLoadQuery()->query();
         if (!$result) {
             return XiptError::raiseWarning(500, XiptText::_("ERROR_IN_DATABASE_WHEN_SAVING_AVATAR_IN_COMMUNITY_USER_TABLE"));
         }
         return true;
     }
 }
Exemplo n.º 2
0
 function _saveWatermark($id)
 {
     $model = $this->getModel();
     //Collect Newly saved data
     $newData = $model->loadRecords(0);
     $newData = $newData[$id];
     $config = new XiptParameter('', '');
     $config->bind($newData->watermarkparams);
     // if enable water mark is false then no need to create watermark
     if (!$config->get('enableWaterMark')) {
         return false;
     }
     //no change condition i.e if type of watermark is image
     // but no image is selected then return
     if (empty($_FILES['watermarkparams']['tmp_name']['xiImage']) && $config->get('typeofwatermark', '0') == '1') {
         return false;
     }
     // generate watermark image
     //XITODO : improve nomenclature
     $imageGenerator = new XiptLibImage($config);
     $storage = PROFILETYPE_AVATAR_STORAGE_PATH;
     $imageName = 'watermark_' . $id;
     // create watermark according to the type of watermark selected
     if ($config->get('typeofwatermark', '0') == '1') {
         $filename = $imageGenerator->createImageWatermark($storage, $imageName);
     } else {
         $filename = $imageGenerator->genImage($storage, $imageName);
     }
     //XITODO : assert on filename
     $image = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . $filename;
     $data = array('watermark' => XiptHelperUtils::getUrlpathFromFilePath($image));
     $this->generateThumbnail($imageName, $filename, $storage, $newData, $config);
     // now save model
     $model->save($data, $id);
     return $image;
 }
Exemplo n.º 3
0
" 
				name="profiletypes" 
				value="<?php 
    echo $pType->id;
    ?>
" <?php 
    echo $selected;
    ?>
 />
			<?php 
    echo $pType->name;
    ?>
		</div>

		<div id="Details">
			<div id="Avatar">
				<img src="<?php 
    echo JURI::root() . XiptHelperUtils::getUrlpathFromFilePath($pType->avatar);
    ?>
" 
				     height="60px" 
 			  	     width="60px"/>
			</div>
			<p id="Description"> <?php 
    echo $pType->tip;
    ?>
 </p>
		</div>
	</div>
<?php 
}
Exemplo n.º 4
0
        ?>
" />	
			</td>
			
			<td align="center" id="watermark<?php 
        echo $field->id;
        ?>
">
					<?php 
        $wm = $field->watermarkparams;
        $wmparams = new XiptParameter($wm, '');
        if ($wmparams->get('enableWaterMark', 0)) {
            ?>
				
				<img src="<?php 
            echo JURI::root() . XiptHelperUtils::getUrlpathFromFilePath($field->watermark);
            ?>
"  border="0" alt="<?php 
            echo $field->watermark;
            ?>
" />	
					<?php 
        }
        ?>
				</td>
			
			<td align="center" id="jusertype<?php 
        echo $field->id;
        ?>
">
				<?php 
Exemplo n.º 5
0
					<div class="paramTitle">						
					<label class="hasTip" title="<?php 
echo XiptText::_('DEFAULT_AVATAR');
?>
::<?php 
echo XiptText::_('DEFAULT_AVATAR_DESC');
?>
">
							<?php 
echo XiptText::_('DEFAULT_AVATAR');
?>
					</label>
					</div>
					<div class="paramValue">
					<img src="<?php 
echo JURI::root() . XiptHelperUtils::getUrlpathFromFilePath($this->data->avatar);
?>
" width="64" height="64" border="0" alt="<?php 
echo $this->data->avatar;
?>
" />
					<div class='clr'></div>
					<input class="inputbox button" type="file" id="file-upload" name="FileAvatar" style="color: #666;" />
					<div class='clr'></div>
					<?php 
$link = XiptRoute::_('index.php?option=com_xipt&view=profiletypes&task=removeAvatar&id=' . $this->data->id . '&oldAvatar=' . $this->data->avatar, false);
?>
											<a href="<?php 
echo $link;
?>
"><?php 
Exemplo n.º 6
0
 function uploadAndSetImage($file, $id, $what)
 {
     $mainframe =& JFactory::getApplication();
     CFactory::load('helpers', 'image');
     $config = CFactory::getConfig();
     $uploadLimit = (double) $config->get('maxuploadsize');
     $uploadLimit = $uploadLimit * 1024 * 1024;
     // @rule: Limit image size based on the maximum upload allowed.
     if (filesize($file['tmp_name']) > $uploadLimit) {
         $mainframe->enqueueMessage(XiptText::_('IMAGE_FILE_SIZE_EXCEEDED'), 'error');
         $mainframe->redirect(CRoute::_('index.php?option=com_xipt&view=profiletypes&task=edit&id=' . $id, false));
     }
     if (!cValidImage($file['tmp_name'])) {
         $mainframe->enqueueMessage(XiptText::_('IMAGE_FILE_NOT_SUPPORTED'), 'error');
     } else {
         switch ($what) {
             case 'avatar':
                 $imageMaxWidth = AVATAR_WIDTH;
                 $thumbWidth = AVATAR_WIDTH_THUMB;
                 $thumbHeight = AVATAR_HEIGHT_THUMB;
                 $imgPrefix = 'avatar_';
                 break;
             case 'watermark':
                 $imageMaxWidth = WATERMARK_WIDTH;
                 $thumbWidth = WATERMARK_WIDTH_THUMB;
                 $thumbHeight = WATERMARK_HEIGHT_THUMB;
                 $imgPrefix = 'watermark_';
                 break;
         }
         $storage = PROFILETYPE_AVATAR_STORAGE_PATH;
         $storageImage = $storage . DS . $imgPrefix . $id . cImageTypeToExt($file['type']);
         $storageThumbnail = $storage . DS . $imgPrefix . $id . '_thumb' . cImageTypeToExt($file['type']);
         $image = PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . DS . $imgPrefix . $id . cImageTypeToExt($file['type']);
         //$thumbnail			= PROFILETYPE_AVATAR_STORAGE_REFERENCE_PATH . $imgPrefix . $id.'_thumb' . cImageTypeToExt( $file['type'] );
         //here check if folder exist or not. if not then create it.
         if (JFolder::exists($storage) == false) {
             JFolder::create($storage);
         }
         // Only resize when the width exceeds the max.
         if (!cImageResizePropotional($file['tmp_name'], $storageImage, $file['type'], $imageMaxWidth)) {
             $mainframe->enqueueMessage(XiptText::sprintf('COM_XIPT_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
         }
         // Generate thumbnail
         if (!cImageCreateThumb($file['tmp_name'], $storageThumbnail, $file['type'], $thumbWidth, $thumbHeight)) {
             $mainframe->enqueueMessage(XiptText::sprintf('COM_XIPT_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error');
         }
         $oldFile = XiptLibProfiletypes::getProfiletypeData($id, $what);
         // If old file is default_thumb or default, we should not remove it.
         if (!Jstring::stristr($oldFile, DEFAULT_AVATAR) && !Jstring::stristr($oldFile, DEFAULT_AVATAR_THUMB) && $oldFile != $image && $oldFile != '') {
             // File exists, try to remove old files first.
             $oldFile = JString::str_ireplace('/', DS, $oldFile);
             //only delete when required
             if (JFile::exists($oldFile)) {
                 JFile::delete($oldFile);
             }
         }
         //here due to extension mismatch we can break the functionality of avatar
         if ($what === 'avatar') {
             /* No need to update thumb here , script will update both avatar and thumb */
             //$newThumb   = XiptHelperImage::getThumbAvatarFromFull($newAvatar);
             $oldAvatar = XiptLibProfiletypes::getProfiletypeData($id, 'avatar');
             $allUsers = XiptLibProfiletypes::getAllUsers($id);
             if ($allUsers) {
                 $filter[] = 'avatar';
                 $newData['avatar'] = $image;
                 $oldData['avatar'] = $oldAvatar;
                 foreach ($allUsers as $userid) {
                     XiptLibProfiletypes::updateUserProfiletypeFilteredData($userid, $filter, $oldData, $newData);
                 }
             }
         }
         //now update profiletype with new avatar or watermark
         if (!XiptFactory::getInstance('profiletypes', 'model')->save(array($what => XiptHelperUtils::getUrlpathFromFilePath($image)), $id)) {
             XiptError::raiseError(__CLASS__ . '.' . __LINE__, XiptText::_("ERROR_IN_DATABASE"));
         }
     }
 }
Exemplo n.º 7
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;
 }