Beispiel #1
0
 public function manageTheme()
 {
     if ($_POST) {
         $configHelper = new JXConfig();
         $file = JRequest::getVar('c_logo', '', 'FILES', 'array');
         $mainframe = JFactory::getApplication();
         if (!empty($file["tmp_name"])) {
             if (!JXImage::isValidType($file['type'])) {
                 $mainframe = JFactory::getApplication();
                 $mainframe->redirect(JRoute::_('index.php?option=com_account&view=account&task=manageTheme', false), JText::_('COM_PROFILE_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             }
             //start image processing
             $logoMaxWidth = 200;
             $logoMaxHeight = 56;
             // Get a hash for the file name.
             $fileName = JUtility::getHash($file['tmp_name'] . time());
             $hashFileName = JString::substr($fileName, 0, 24);
             //avatar store path
             $storage = JPATH_ROOT . DS . 'images';
             $storageImage = $storage . DS . $hashFileName . JXImage::getExtension($file['type']);
             $image = 'images' . '/' . $hashFileName . JXImage::getExtension($file['type']);
             // Generate full image
             list($currentWidth, $currentHeight) = getimagesize($file['tmp_name']);
             // Calculate ratio based on height first as height got lower value
             $ratioToUse = intval($currentHeight / $logoMaxHeight);
             // If logoMaxwidth * ratio > original width, recalculate ratio based on width
             if ($logoMaxWidth * $ratioToUse > $currentWidth) {
                 $ratioToUse = intval($currentWidth / $logoMaxWidth);
             }
             $maxWidth = $ratioToUse * $logoMaxWidth;
             $maxHeight = $logoMaxHeight * $ratioToUse;
             $sourceX = intval(($currentWidth - $maxWidth) / 2);
             $sourceY = intval(($currentHeight - $maxHeight) / 2);
             if (!JXImage::crop($file['tmp_name'], $storageImage, $maxWidth, $maxHeight, $sourceX, $sourceY, $logoMaxWidth, $logoMaxHeight)) {
                 $mainframe->redirect(JRoute::_('index.php?option=com_account&view=account&task=manageTheme', false), JText::sprintf('COM_PROFILE_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error');
             } else {
                 // Remove previous logo
                 $originalFilePath = $configHelper->getCompanyLogoPath();
                 $defaultLogo = basename(JXConfig::DEFAULT_LOGO);
                 // Do not remove default logo
                 if (JFile::exists($originalFilePath) && !stristr($originalFilePath, $defaultLogo)) {
                     JFile::delete($originalFilePath);
                 }
                 $param['logo'] = $image;
             }
         }
         $postdata = JRequest::getVar('params');
         $param[JXConfig::STYLE] = $postdata['style'];
         if (!$configHelper->saveConfig($param)) {
             /* Redirect to clear the previous post values */
             $mainframe->redirect(JRoute::_('index.php?option=com_account&view=account&task=manageTheme', false), JText::_('COM_ACCOUNT_ACTION_SAVE_SETTING_FAIL'), 'error');
         }
         /* Redirect to clear the previous post values */
         $mainframe->redirect(JRoute::_('index.php?option=com_account&view=account&task=manageTheme', false), JText::_('COM_ACCOUNT_ACTION_SAVE_SETTING_SUCCESS'));
     }
     JRequest::setVar('view', 'theme');
     parent::display();
 }
Beispiel #2
0
 public function changeAvatar()
 {
     $my = JXFactory::getUser();
     $mainframe = JFactory::getApplication();
     if ($_POST) {
         $file = JRequest::getVar('avatar', '', 'FILES', 'array');
         if (!JXImage::isValidType($file['type'])) {
             $mainframe->redirect(JRoute::_('index.php?option=com_profile&view=edit&task=changeAvatar', false), JText::_('COM_PROFILE_IMAGE_FILE_NOT_SUPPORTED'), 'error');
             exit;
         }
         $saveAvatar = $this->_saveUploadedAvatar($my, $file['tmp_name'], $file['type']);
         if ($saveAvatar === true) {
             $mainframe->redirect(JRoute::_('index.php?option=com_profile&view=edit&task=changeAvatar', false), JText::_('COM_PROFILE_ACTION_UPLOAD_AVATAR_SUCCESS'));
             exit;
         } else {
             $mainframe->redirect(JRoute::_('index.php?option=com_profile&view=edit&task=changeAvatar', false), $saveAvatar, 'error');
             exit;
         }
     }
     JRequest::setVar('view', 'avatar');
     parent::display();
 }