Esempio n. 1
0
 function resetall($id = 0, $limit = RESETALL_USER_LIMIT, $start = 0)
 {
     $mainframe = JFactory::getApplication();
     $start = JRequest::getVar('start', $start);
     $id = JRequest::getVar('id', $id);
     //getting from session
     $session = JFactory::getSession();
     $oldPtData = $session->get('oldPtData', '', 'jspt');
     $newPtData = $session->get('newPtData', '', 'jspt');
     $newPtData = unserialize($newPtData);
     $allUsers = XiptLibProfiletypes::getAllUsers($id);
     if (!$allUsers) {
         $msg = XiptText::_('NO_USER_TO_RESET');
         $mainframe->redirect('index.php?option=com_xipt&view=profiletypes', $msg);
     }
     $total = count($allUsers);
     $users = array_chunk($allUsers, $limit);
     if (empty($users[$start])) {
         $info['id'] = $id;
         $info['msg'] = XiptText::_('PROFILETYPE_SAVED');
         $preTask = $session->set('preTask', '', 'jspt');
         $preTask = $preTask == 'apply' ? 'edit' : 'display';
         $session->clear('oldPtData', 'jspt');
         $session->clear('newPtData', 'jspt');
         $link = XiptRoute::_('index.php?option=com_xipt&view=profiletypes&task=' . $preTask . '&id=' . $id . '', false);
         $mainframe->redirect($link, $info['msg']);
     }
     $users = $users[$start];
     //XITODO : needs cleanup Remove hardcoding
     $featuresToReset = array('jusertype', 'template', 'group', 'watermark', 'avatar');
     $filteredOldData = array();
     $filteredNewData = array();
     // when privacy controlled by admin
     if (1 == $newPtData->privacy->get('jsPrivacyController')) {
         array_push($featuresToReset, 'privacy');
     }
     foreach ($featuresToReset as $feature) {
         $filteredOldData[$feature] = $oldPtData->{$feature};
         $filteredNewData[$feature] = $newPtData->{$feature};
     }
     foreach ($users as $user) {
         XiptLibProfiletypes::updateUserProfiletypeFilteredData($user, $featuresToReset, $filteredOldData, $filteredNewData);
     }
     $start = $start + 1;
     if (!XIPT_TEST_MODE == 0) {
         return $start;
     }
     return $this->getView()->resetall($id, $start, $total, $limit);
     //$mainframe->redirect(XiPTRoute::_("index.php?option=com_xipt&view=profiletypes&task=resetall&start=$start&id=$id",false));
 }
Esempio n. 2
0
 /**
  * The user data have been saved.
  * We will save user's data (profiletype and template) into Xipt tables
  * @param $userId
  * @param $saveSuccess
  * @return unknown_type
  */
 function onAfterProfileUpdate($userId, $saveSuccess)
 {
     // data was not saved, do nothing
     if (false == $saveSuccess) {
         return true;
     }
     // the JomSocial already store values in field tables
     // now we need to apply that information to our tables
     //	    $cuser        = CFactory::getUser($userId);
     //	    $profiletype  = $cuser->getInfo(PROFILETYPE_CUSTOM_FIELD_CODE);
     //	    $template     = $cuser->getInfo(TEMPLATE_CUSTOM_FIELD_CODE);
     $profiletype = XiptHelperUtils::getInfo($userId, PROFILETYPE_CUSTOM_FIELD_CODE);
     $template = XiptHelperUtils::getInfo($userId, TEMPLATE_CUSTOM_FIELD_CODE);
     // Changing Profile From Front End If The Template allow is None then Set Profiletype template.
     // If Template is Allowed on Profile Type Then Take User Define Template From Front End.
     $oldPtype = XiptLibProfiletypes::getUserData($userId, 'PROFILETYPE');
     $OldallowToChangeTemplate = XiptHelperProfiletypes::getProfileTypeData($oldPtype, 'allowt');
     $NewallowToChangeTemplate = XiptHelperProfiletypes::getProfileTypeData($profiletype, 'allowt');
     //update profiletype only
     XiptLibProfiletypes::updateUserProfiletypeData($userId, $profiletype, $template, 'ALL');
     //update template seperately
     $filter[] = 'template';
     $allowToChangeTemplate = XiptFactory::getSettings('allow_templatechange', 0);
     if (($NewallowToChangeTemplate == 0 || $OldallowToChangeTemplate == 0) && $allowToChangeTemplate == 0) {
         $newData['template'] = XiptLibProfiletypes::getProfiletypeData($profiletype, 'template');
     } else {
         $newData['template'] = $template;
     }
     XiptLibProfiletypes::updateUserProfiletypeFilteredData($userId, $filter, null, $newData);
     $this->showActivity($userId, $profiletype, $oldPtype);
     return true;
 }
Esempio n. 3
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"));
         }
     }
 }