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
parent6e2a00229edc01dcd2689955a16f9674dd9af813 (diff)
added possibility to upload a favicon
-rw-r--r--.gitignore3
-rw-r--r--core/Plugin/Controller.php1
-rw-r--r--lang/en.json1
-rw-r--r--plugins/CoreAdminHome/Controller.php6
-rw-r--r--plugins/CoreAdminHome/CustomLogo.php49
-rw-r--r--plugins/CoreAdminHome/javascripts/generalSettings.js17
-rw-r--r--plugins/CoreAdminHome/templates/generalSettings.twig25
-rw-r--r--plugins/Zeitgeist/templates/admin.twig2
-rw-r--r--plugins/Zeitgeist/templates/dashboard.twig2
9 files changed, 72 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
index 96e5e4c52a..3b5e5a59ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ misc/*.dat
misc/user/logo-header.png
misc/user/logo.png
misc/user/logo.svg
+misc/user/favicon.png
php_errors.log
piwik-min.js
plugins/*.zip
@@ -53,4 +54,4 @@ tests/PHPUnit/proxy/libs
tests/PHPUnit/proxy/piwik.js
tests/PHPUnit/proxy/plugins
tests/PHPUnit/proxy/tests
-config/*.config.ini.php \ No newline at end of file
+config/*.config.ini.php
diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php
index 3e6d4a8e11..af58f852ba 100644
--- a/core/Plugin/Controller.php
+++ b/core/Plugin/Controller.php
@@ -606,6 +606,7 @@ abstract class Controller
$customLogo = new CustomLogo();
$view->isCustomLogo = $customLogo->isEnabled();
+ $view->customFavicon = $customLogo->getPathUserFavicon();
$view->logoHeader = \Piwik\Plugins\API\API::getInstance()->getHeaderLogoUrl();
$view->logoLarge = \Piwik\Plugins\API\API::getInstance()->getLogoUrl();
diff --git a/lang/en.json b/lang/en.json
index 37df529d9b..e47c3bf41d 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -142,6 +142,7 @@
"LatestStableRelease": "The latest stable release",
"LogoNotWriteableInstruction": "To use your custom logo instead of the default Piwik logo, give write permission to this directory: %1$s Piwik needs write access for your logos stored in the files %2$s.",
"LogoUpload": "Select a Logo to upload",
+ "FaviconUpload": "Select a Favicon to upload",
"LogoUploadHelp": "Please upload a file in %s formats with a minimum height of %s pixels.",
"MenuDiagnostic": "Diagnostic",
"MenuGeneralSettings": "General settings",
diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php
index d59557e1b8..41fb7aab2d 100644
--- a/plugins/CoreAdminHome/Controller.php
+++ b/plugins/CoreAdminHome/Controller.php
@@ -55,6 +55,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
$view->branding = array('use_custom_logo' => $logo->isEnabled());
$view->logosWriteable = $logo->isCustomLogoWritable();
$view->pathUserLogo = CustomLogo::getPathUserLogo();
+ $view->pathUserFavicon = CustomLogo::getPathUserFavicon();
$view->pathUserLogoSmall = CustomLogo::getPathUserLogoSmall();
$view->pathUserLogoSVG = CustomLogo::getPathUserSvgLogo();
$view->pathUserLogoDirectory = realpath(dirname($view->pathUserLogo) . '/');
@@ -260,9 +261,10 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
Piwik::checkUserHasSuperUserAccess();
$logo = new CustomLogo();
- $success = $logo->copyUploadedLogoToFilesystem();
+ $successLogo = $logo->copyUploadedLogoToFilesystem();
+ $successFavicon = $logo->copyUploadedFaviconToFilesystem();
- if($success) {
+ if($successLogo || $successFavicon) {
return '1';
}
return '0';
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;
}
diff --git a/plugins/CoreAdminHome/javascripts/generalSettings.js b/plugins/CoreAdminHome/javascripts/generalSettings.js
index 30483202f4..867cdc60d0 100644
--- a/plugins/CoreAdminHome/javascripts/generalSettings.js
+++ b/plugins/CoreAdminHome/javascripts/generalSettings.js
@@ -55,10 +55,14 @@ function isCustomLogoEnabled() {
}
function refreshCustomLogo() {
- var imageDiv = $("#currentLogo");
- if (imageDiv && imageDiv.attr("src")) {
- var logoUrl = imageDiv.attr("src").split("?")[0];
- imageDiv.attr("src", logoUrl + "?" + (new Date()).getTime());
+ var selectors = ['#currentLogo', '#currentFavicon'];
+ var index;
+ for (index = 0; index < selectors.length; index++) {
+ var imageDiv = $(selectors[index]);
+ if (imageDiv && imageDiv.attr("src")) {
+ var logoUrl = imageDiv.attr("src").split("?")[0];
+ imageDiv.attr("src", logoUrl + "?" + (new Date()).getTime());
+ }
}
}
@@ -122,7 +126,10 @@ $(document).ready(function () {
submittingForm.attr("target", frameName);
});
- $('#customLogo').change(function () {$("#logoUploadForm").submit()});
+ $('#customLogo,#customFavicon').change(function () {
+ $("#logoUploadForm").submit();
+ $(this).val('');
+ });
// trusted hosts event handling
var trustedHostSettings = $('#trustedHostSettings');
diff --git a/plugins/CoreAdminHome/templates/generalSettings.twig b/plugins/CoreAdminHome/templates/generalSettings.twig
index bed62b3ac7..78b2f87f7a 100644
--- a/plugins/CoreAdminHome/templates/generalSettings.twig
+++ b/plugins/CoreAdminHome/templates/generalSettings.twig
@@ -235,18 +235,31 @@
<div id='logoSettings'>
<form id="logoUploadForm" method="post" enctype="multipart/form-data" action="index.php?module=CoreAdminHome&format=json&action=uploadCustomLogo">
<table class="adminTable" style='width:550px;'>
- <tr>
- {% if logosWriteable %}
+ {% if logosWriteable %}
+ <tr>
<td>
<label for="customLogo">{{ 'CoreAdminHome_LogoUpload'|translate }}:<br/>
- <span class="form-description">{{ 'CoreAdminHome_LogoUploadHelp'|translate("JPG / PNG / GIF",110) }}</span>
+ <span class="form-description">{{ 'CoreAdminHome_LogoUploadHelp'|translate("JPG / PNG / GIF", 110) }}</span>
</label>
</td>
<td style="width:200px;">
<input name="customLogo" type="file" id="customLogo"/>
<img src="{{ pathUserLogo }}?r={{ random() }}" id="currentLogo" height="150"/>
</td>
- {% else %}
+ </tr>
+ <tr>
+ <td>
+ <label for="customLogo">{{ 'CoreAdminHome_FaviconUpload'|translate }}:<br/>
+ <span class="form-description">{{ 'CoreAdminHome_LogoUploadHelp'|translate("JPG / PNG / GIF", 16) }}</span>
+ </label>
+ </td>
+ <td style="width:200px;">
+ <input name="customFavicon" type="file" id="customFavicon"/>
+ <img src="{{ pathUserFavicon }}?r={{ random() }}" id="currentFavicon" width="16" height="16"/>
+ </td>
+ </tr>
+ {% else %}
+ <tr>
<td>
<div style="display:inline-block;margin-top:10px;" id="CoreAdminHome_LogoNotWriteable">
{{ 'CoreAdminHome_LogoNotWriteableInstruction'
@@ -256,8 +269,8 @@
</div>
</td>
- {% endif %}
- </tr>
+ </tr>
+ {% endif %}
</table>
</form>
</div>
diff --git a/plugins/Zeitgeist/templates/admin.twig b/plugins/Zeitgeist/templates/admin.twig
index 5cada1ff9a..a3330087f7 100644
--- a/plugins/Zeitgeist/templates/admin.twig
+++ b/plugins/Zeitgeist/templates/admin.twig
@@ -8,7 +8,7 @@
<meta charset="utf-8">
<title>{% if not isCustomLogo %}Piwik &rsaquo; {% endif %}{{ 'CoreAdminHome_Administration'|translate }}</title>
<meta name="generator" content="Piwik - Open Source Web Analytics"/>
- <link rel="shortcut icon" href="plugins/CoreHome/images/favicon.ico"/>
+ <link rel="shortcut icon" href="{{ customFavicon|default('plugins/CoreHome/images/favicon.ico') }}"/>
{% include "_jsGlobalVariables.twig" %}
{% include "_piwikTag.twig" %}
diff --git a/plugins/Zeitgeist/templates/dashboard.twig b/plugins/Zeitgeist/templates/dashboard.twig
index 3f1191cd89..90f4e7a0ae 100644
--- a/plugins/Zeitgeist/templates/dashboard.twig
+++ b/plugins/Zeitgeist/templates/dashboard.twig
@@ -12,7 +12,7 @@
<meta name="generator" content="Piwik - Open Source Web Analytics"/>
<meta name="description" content="Web Analytics report for '{{ siteName|escape("html_attr") }}' - Piwik"/>
<meta name="apple-itunes-app" content="app-id=737216887" />
- <link rel="shortcut icon" href="plugins/CoreHome/images/favicon.ico"/>
+ <link rel="shortcut icon" href="{{ customFavicon|default('plugins/CoreHome/images/favicon.ico') }}"/>
{% include "_jsGlobalVariables.twig" %}
{% include "_piwikTag.twig" %}
<!--[if lt IE 9]>