Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-05-15 02:39:34 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-05-15 02:39:34 +0400
commite8b4a64f8aa02f39bff555572c3865c587665317 (patch)
treebfdbd6694d422766da8a057b702d463988302efe /plugins/CoreAdminHome/CustomLogo.php
parent6e2a00229edc01dcd2689955a16f9674dd9af813 (diff)
added possibility to upload a favicon
Diffstat (limited to 'plugins/CoreAdminHome/CustomLogo.php')
-rw-r--r--plugins/CoreAdminHome/CustomLogo.php49
1 files changed, 31 insertions, 18 deletions
diff --git a/plugins/CoreAdminHome/CustomLogo.php b/plugins/CoreAdminHome/CustomLogo.php
index ca845fe4fb..f4c95c49b3 100644
--- a/plugins/CoreAdminHome/CustomLogo.php
+++ b/plugins/CoreAdminHome/CustomLogo.php
@@ -17,6 +17,7 @@ class CustomLogo
{
const LOGO_HEIGHT = 300;
const LOGO_SMALL_HEIGHT = 100;
+ const FAVICON_HEIGHT = 32;
public function getLogoUrl($pathOnly = false)
{
@@ -129,6 +130,11 @@ class CustomLogo
return self::rewritePath('misc/user/logo.png');
}
+ public static function getPathUserFavicon()
+ {
+ return self::rewritePath('misc/user/favicon.png');
+ }
+
public static function getPathUserSvgLogo()
{
return self::rewritePath('misc/user/logo.svg');
@@ -146,20 +152,36 @@ class CustomLogo
public function copyUploadedLogoToFilesystem()
{
+ $uploadFieldName = 'customLogo';
+
+ $success = $this->uploadImage($uploadFieldName, self::LOGO_SMALL_HEIGHT, $this->getPathUserLogoSmall());
+ $success = $success && $this->uploadImage($uploadFieldName, self::LOGO_HEIGHT, $this->getPathUserLogo());
+
+ return $success;
+ }
+
+ public function copyUploadedFaviconToFilesystem()
+ {
+ $uploadFieldName = 'customFavicon';
+
+ return $this->uploadImage($uploadFieldName, self::FAVICON_HEIGHT, $this->getPathUserFavicon());
+ }
- if (empty($_FILES['customLogo'])
- || !empty($_FILES['customLogo']['error'])
+ private function uploadImage($uploadFieldName, $targetHeight, $userPath)
+ {
+ if (empty($_FILES[$uploadFieldName])
+ || !empty($_FILES[$uploadFieldName]['error'])
) {
return false;
}
- $file = $_FILES['customLogo']['tmp_name'];
+ $file = $_FILES[$uploadFieldName]['tmp_name'];
if (!file_exists($file)) {
return false;
}
list($width, $height) = getimagesize($file);
- switch ($_FILES['customLogo']['type']) {
+ switch ($_FILES[$uploadFieldName]['type']) {
case 'image/jpeg':
$image = imagecreatefromjpeg($file);
break;
@@ -173,30 +195,21 @@ class CustomLogo
return false;
}
- $widthExpected = round($width * self::LOGO_HEIGHT / $height);
- $smallWidthExpected = round($width * self::LOGO_SMALL_HEIGHT / $height);
+ $smallWidthExpected = round($width * $targetHeight / $height);
- $logo = imagecreatetruecolor($widthExpected, self::LOGO_HEIGHT);
- $logoSmall = imagecreatetruecolor($smallWidthExpected, self::LOGO_SMALL_HEIGHT);
+ $logoSmall = imagecreatetruecolor($smallWidthExpected, $targetHeight);
// Handle transparency
- $background = imagecolorallocate($logo, 0, 0, 0);
$backgroundSmall = imagecolorallocate($logoSmall, 0, 0, 0);
- imagecolortransparent($logo, $background);
imagecolortransparent($logoSmall, $backgroundSmall);
- if ($_FILES['customLogo']['type'] == 'image/png') {
- imagealphablending($logo, false);
+ if ($_FILES[$uploadFieldName]['type'] == 'image/png') {
imagealphablending($logoSmall, false);
- imagesavealpha($logo, true);
imagesavealpha($logoSmall, true);
}
- imagecopyresized($logo, $image, 0, 0, 0, 0, $widthExpected, self::LOGO_HEIGHT, $width, $height);
- imagecopyresized($logoSmall, $image, 0, 0, 0, 0, $smallWidthExpected, self::LOGO_SMALL_HEIGHT, $width, $height);
-
- imagepng($logo, PIWIK_DOCUMENT_ROOT . '/' . $this->getPathUserLogo(), 3);
- imagepng($logoSmall, PIWIK_DOCUMENT_ROOT . '/' . $this->getPathUserLogoSmall(), 3);
+ imagecopyresized($logoSmall, $image, 0, 0, 0, 0, $smallWidthExpected, $targetHeight, $width, $height);
+ imagepng($logoSmall, PIWIK_DOCUMENT_ROOT . '/' . $userPath, 3);
return true;
}