Skip to content

New feature: Upload logo from backend #2580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
OpenMage

This source file is subject to the Academic Free License (AFL 3.0)
that is bundled with this package in the file LICENSE_AFL.txt.
It is also available at https://opensource.org/license/afl-3-0-php
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* System config image field backend model for Zend PDF generator
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <[email protected]>
*/
class Mage_Adminhtml_Model_System_Config_Backend_Image_Logo extends Mage_Adminhtml_Model_System_Config_Backend_Image
{
/**
* The tail part of directory path for uploading
*/
const UPLOAD_DIR = 'header/logo';

/**
* Token for the root part of directory path for uploading
*/
const UPLOAD_ROOT_TOKEN = 'system/filesystem/media';

/**
* Upload max file size in kilobytes
*
* @var int
*/
protected $_maxFileSize = 2048;

/**
* Return path to directory for upload file
*
* @return string
*/
protected function _getUploadDir() {
$uploadDir = $this->_appendScopeInfo(self::UPLOAD_DIR);
$uploadRoot = $this->_getUploadRoot(self::UPLOAD_ROOT_TOKEN);
$uploadDir = $uploadRoot . DS . $uploadDir;
return $uploadDir;
}

/**
* Makes a decision about whether to add info about the scope
*
* @return boolean
*/
protected function _addWhetherScopeInfo() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
OpenMage

This source file is subject to the Academic Free License (AFL 3.0)
that is bundled with this package in the file LICENSE_AFL.txt.
It is also available at https://opensource.org/license/afl-3-0-php
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* System config image field backend model for Zend PDF generator
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <[email protected]>
*/
class Mage_Adminhtml_Model_System_Config_Backend_Image_Logosmall extends Mage_Adminhtml_Model_System_Config_Backend_Image_Logo
{
const UPLOAD_DIR = 'header/logo_small';

/**
* Return path to directory for upload file
*
* @return string
*/
protected function _getUploadDir()
{
$uploadDir = $this->_appendScopeInfo(self::UPLOAD_DIR);
$uploadRoot = $this->_getUploadRoot(self::UPLOAD_ROOT_TOKEN);
$uploadDir = $uploadRoot . DS . $uploadDir;
return $uploadDir;
}
}

23 changes: 19 additions & 4 deletions app/code/core/Mage/Page/Block/Html/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
class Mage_Page_Block_Html_Header extends Mage_Core_Block_Template
{
const LOGO_DIR = 'header/logo/';
const LOGO_SMALL_DIR = 'header/logo_small/';

public function _construct()
{
$this->setTemplate('page/html/header.phtml');
Expand Down Expand Up @@ -57,9 +60,15 @@ public function setLogo($logo_src, $logo_alt)
public function getLogoSrc()
{
if (empty($this->_data['logo_src'])) {
$this->_data['logo_src'] = Mage::getStoreConfig('design/header/logo_src');
if (file_exists(Mage::getBaseDir('media') . DS . self::LOGO_DIR . Mage::getStoreConfig('design/header/logo_src'))) {
$mediaBaseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$this->_data['logo_src'] = $mediaBaseUrl . self::LOGO_DIR . Mage::getStoreConfig('design/header/logo_src');
} else {
$this->_data['logo_src'] = Mage::getStoreConfig('design/header/logo_src');
$this->_data['logo_src'] = $this->getSkinUrl($this->_data['logo_src']);
}
}
return $this->getSkinUrl($this->_data['logo_src']);
return $this->_data['logo_src'];
}

/**
Expand All @@ -68,9 +77,15 @@ public function getLogoSrc()
public function getLogoSrcSmall()
{
if (empty($this->_data['logo_src_small'])) {
$this->_data['logo_src_small'] = Mage::getStoreConfig('design/header/logo_src_small');
if (file_exists(Mage::getBaseDir('media') . DS . self::LOGO_DIR . Mage::getStoreConfig('design/header/logo_src_small'))) {
$mediaBaseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$this->_data['logo_src_small'] = $mediaBaseUrl . self::LOGO_DIR . Mage::getStoreConfig('design/header/logo_src_small');
} else {
$this->_data['logo_src_small'] = Mage::getStoreConfig('design/header/logo_src_small');
$this->_data['logo_src_small'] = $this->getSkinUrl($this->_data['logo_src_small']);
}
}
return $this->getSkinUrl($this->_data['logo_src_small']);
return $this->_data['logo_src_small'];
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/code/core/Mage/Page/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<logo_src translate="label">
<label>Logo Image Src</label>
<sort_order>10</sort_order>
<frontend_type>image</frontend_type>
<backend_model>adminhtml/system_config_backend_image_logo</backend_model>
<base_url type="media" scope_info="1">header/logo</base_url>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand All @@ -142,6 +145,9 @@
<logo_src_small translate="label">
<label>Small Logo Image Src</label>
<sort_order>25</sort_order>
<frontend_type>image</frontend_type>
<backend_model>adminhtml/system_config_backend_image_logosmall</backend_model>
<base_url type="media" scope_info="1">header/logo_small</base_url>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down
Binary file added media/header/logo/images/logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/header/logo_small/images/logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.