コード例 #1
0
ファイル: account.php プロジェクト: ErickLopez76/offiria
 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();
 }
コード例 #2
0
ファイル: edit.php プロジェクト: ErickLopez76/offiria
 public function ajaxSaveThumbnail()
 {
     $my = JXFactory::getUser();
     $filePath = JPATH_ROOT . DS . $my->getAvatarPath();
     $fileType = JXImage::getImageType($filePath);
     $thumbnailStore = $my->getThumbAvatarPath();
     $originalFile = JXImage::getImageFileName(JPATH_ROOT . DS . $thumbnailStore);
     $originalFilePath = JPATH_ROOT . DS . $thumbnailStore;
     $newFileName = 'thumb_' . JXImage::getHashName($originalFile) . JXImage::getExtension($fileType);
     $thumbnailStore = str_replace($originalFile, $newFileName, $thumbnailStore);
     $xPos = JRequest::getInt('x_pos', 0);
     $yPos = JRequest::getInt('y_pos', 0);
     $imgWidth = JRequest::getInt('width', 0);
     $imgHeight = JRequest::getInt('height', 0);
     if (!JXImage::crop($filePath, JPATH_ROOT . DS . $thumbnailStore, $imgWidth, $imgHeight, $xPos, $yPos)) {
         $this->_showUploadError(true, '0', $my->getThumbAvatarURL());
         exit;
     }
     $this->_deleteUserCurrentAvatar($my, false);
     $my->setParam('avatar_thumb', $thumbnailStore);
     $my->save();
     $this->_showUploadError(false, '1', $my->getThumbAvatarURL());
     exit;
 }