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; } }
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)); }
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")); } } }