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
path: root/core
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2008-08-14 22:09:06 +0400
committermattpiwik <matthieu.aubry@gmail.com>2008-08-14 22:09:06 +0400
commit72d560fd4c8c66febafe3aabda47e9b583f2c390 (patch)
tree4d7d4ca8e30621e9691b08dfaa7a8b9c4c53634f /core
parent72d460ee245585b6c550430b52342333c2b19b60 (diff)
git-svn-id: http://dev.piwik.org/svn/trunk@598 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core')
-rw-r--r--core/Common.php71
-rw-r--r--core/Controller.php5
-rw-r--r--core/ErrorHandler.php3
-rw-r--r--core/FrontController.php11
-rw-r--r--core/LogStats/Visit.php7
-rw-r--r--core/Piwik.php15
-rw-r--r--core/Plugin.php63
-rw-r--r--core/PluginsManager.php233
-rw-r--r--core/Site.php2
-rw-r--r--core/TablePartitioning.php3
-rw-r--r--core/Translate.php56
-rw-r--r--core/Url.php10
-rw-r--r--core/ViewDataTable/GenerateGraphData.php2
-rw-r--r--core/Visualization/Chart.php1
14 files changed, 256 insertions, 226 deletions
diff --git a/core/Common.php b/core/Common.php
index f02c7abde0..1a7d84b50e 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -205,8 +205,7 @@ class Piwik_Common
}
}
elseif( !is_null($value)
- && !is_bool($value)
- )
+ && !is_bool($value))
{
throw new Exception("The value to escape has not a supported type. Value = ".var_export($value, true));
}
@@ -508,6 +507,21 @@ class Piwik_Common
}
/**
+ * Returns the browser language code, eg. "en-gb,en;q=0.5"
+ *
+ * @return string
+ */
+ static public function getBrowserLanguage()
+ {
+ $browserLang = Piwik_Common::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']);
+ if(is_null($browserLang))
+ {
+ $browserLang = '';
+ }
+ return $browserLang;
+ }
+
+ /**
* Returns the visitor country based only on the Browser 'accepted language' information
*
* @param string $lang browser lang
@@ -539,72 +553,74 @@ class Piwik_Common
'gb' => 'uk',
);
-
if(empty($lang) || strlen($lang) < 2)
{
return 'xx';
}
- $lang = str_replace( array_keys($replaceLangCodeByCountryCode),
- array_values($replaceLangCodeByCountryCode),
- $lang
- );
-
+ $browserLanguage = str_replace(
+ array_keys($replaceLangCodeByCountryCode),
+ array_values($replaceLangCodeByCountryCode),
+ $lang
+ );
+ $validLanguages = array_keys($countryList);
+ return Piwik_Common::extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages);
+ }
+
+ static public function extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages)
+ {
// Ex: "fr"
- if(strlen($lang) == 2)
+ if(strlen($browserLanguage) == 2)
{
- if(isset($countryList[$lang]))
+ if(in_array($browserLanguage, $validLanguages))
{
- return $lang;
+ return $browserLanguage;
}
}
// when comma
- $offcomma = strpos($lang, ',');
-
+ $offcomma = strpos($browserLanguage, ',');
if($offcomma == 2)
{
// in 'fr,en-us', keep first two chars
- $domain = substr($lang, 0, 2);
- if(isset($countryList[$domain]))
+ $domain = substr($browserLanguage, 0, 2);
+ if(in_array($domain, $validLanguages))
{
return $domain;
}
// catch the second language Ex: "fr" in "en,fr"
- $domain = substr($lang, 3, 2);
- if(isset($countryList[$domain]))
+ $domain = substr($browserLanguage, 3, 2);
+ if(in_array($domain, $validLanguages))
{
return $domain;
}
}
// detect second code Ex: "be" in "fr-be"
- $off = strpos($lang, '-');
- if($off!==false)
+ $off = strpos($browserLanguage, '-');
+ if($off !== false)
{
- $domain = substr($lang, $off+1, 2);
-
- if(isset($countryList[$domain]))
+ $domain = substr($browserLanguage, $off + 1, 2);
+ if(in_array($domain, $validLanguages))
{
return $domain;
}
}
// catch the second language Ex: "fr" in "en;q=1.0,fr;q=0.9"
- if(preg_match("/^[a-z]{2};q=[01]\.[0-9],(?P<domain>[a-z]{2});/", $lang, $parts))
+ if(preg_match("/^[a-z]{2};q=[01]\.[0-9],(?P<domain>[a-z]{2});/", $browserLanguage, $parts))
{
$domain = $parts['domain'];
-
- if(isset($GLOBALS['countryList'][$domain][0]))
+ if(in_array($domain, $validLanguages))
{
return $domain;
}
}
// finally try with the first ever langage code
- $domain = substr($lang, 0, 2);
- if(isset($countryList[$domain]))
+ $domain = substr($browserLanguage, 0, 2);
+ if(in_array($domain, $validLanguages))
{
return $domain;
}
@@ -613,7 +629,6 @@ class Piwik_Common
return 'xx';
}
-
/**
* Generate random string
*
diff --git a/core/Controller.php b/core/Controller.php
index de1a1b2d53..9faa0fb817 100644
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -213,7 +213,10 @@ abstract class Piwik_Controller
try {
$currentPeriod = Piwik_Common::getRequestVar('period');
- $view->idSite = Piwik_Common::getRequestVar('idSite');
+ $idSite = Piwik_Common::getRequestVar('idSite');
+ $view->idSite = $idSite;
+ $site = new Piwik_Site($idSite);
+ $view->siteName = $site->getName();
} catch(Exception $e) {
self::redirectToIndex(Piwik::getModule(), Piwik::getAction());
}
diff --git a/core/ErrorHandler.php b/core/ErrorHandler.php
index a985e14e6e..3b7608d54f 100644
--- a/core/ErrorHandler.php
+++ b/core/ErrorHandler.php
@@ -33,10 +33,9 @@ function Piwik_ErrorHandler($errno, $errstr, $errfile, $errline)
$backtrace = ob_get_contents();
ob_end_clean();
-
try {
Zend_Registry::get('logger_error')->log($errno, $errstr, $errfile, $errline, $backtrace);
- }catch(Exception $e){
+ } catch(Exception $e) {
// in case the error occurs before the logger creation, we simply display it
print("<pre>$errstr \nin '$errfile' at the line $errline\n\n$backtrace\n</pre>");
exit;
diff --git a/core/FrontController.php b/core/FrontController.php
index 0e51db1c7e..b93af2ab85 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -250,14 +250,17 @@ class Piwik_FrontController
$exceptionToThrow = $e;
}
- Piwik::loadPlugins();
+ Piwik_Translate::getInstance()->loadEnglishTranslation();
+ $pluginsManager = Piwik_PluginsManager::getInstance();
+ $pluginsManager->setPluginsToLoad( Zend_Registry::get('config')->Plugins->Plugins->toArray() );
+
if($exceptionToThrow)
{
throw $exceptionToThrow;
}
Piwik::createDatabaseObject();
Piwik::createLogObject();
- Piwik::installLoadedPlugins();
+ Piwik_PluginsManager::getInstance()->installLoadedPlugins();
Piwik::install();
Piwik_PostEvent('FrontController.initAuthenticationObject');
@@ -274,6 +277,10 @@ class Piwik_FrontController
Zend_Registry::set('access', $access);
Zend_Registry::get('access')->loadAccess();
+ Piwik_Translate::getInstance()->loadUserTranslation();
+ $pluginsManager->setLanguageToLoad( Piwik_Translate::getInstance()->getLanguageToLoad() );
+ $pluginsManager->postLoadPlugins();
+
Piwik::raiseMemoryLimitIfNecessary();
} catch(Exception $e) {
Piwik_ExitWithMessage($e->getMessage());
diff --git a/core/LogStats/Visit.php b/core/LogStats/Visit.php
index a148ab7d4c..78622f28f1 100644
--- a/core/LogStats/Visit.php
+++ b/core/LogStats/Visit.php
@@ -250,13 +250,8 @@ class Piwik_LogStats_Visit implements Piwik_LogStats_Visit_Interface
$ip = Piwik_Common::getIp();
$ip = ip2long($ip);
- $browserLang = substr(Piwik_Common::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']), 0, 20);
- if(is_null($browserLang))
- {
- $browserLang = '';
- }
+ $browserLang = substr(Piwik_Common::getBrowserLanguage(), 0, 20);
-
$configurationHash = $this->getConfigHash(
$os,
$browserName,
diff --git a/core/Piwik.php b/core/Piwik.php
index 9d1044dd41..8b4651c9b1 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -410,17 +410,6 @@ class Piwik
return $title;
}
- static public function loadPlugins()
- {
- Piwik_PluginsManager::getInstance()->setLanguageToLoad( Piwik_Translate::getInstance()->getLanguageToLoad() );
- Piwik_PluginsManager::getInstance()->setPluginsToLoad( Zend_Registry::get('config')->Plugins->Plugins->toArray() );
- }
-
- static public function installLoadedPlugins()
- {
- Piwik_PluginsManager::getInstance()->installLoadedPlugins();
- }
-
static public function getTableCreateSql( $tableName )
{
$tables = Piwik::getTablesCreateSql();
@@ -812,10 +801,9 @@ class Piwik
static public function getTablesInstalled( $forceReload = true )
{
- if(is_null(self::$tablesInstalled)
+ if(is_null(self::$tablesInstalled)
|| $forceReload === true)
{
-
$db = Zend_Registry::get('db');
$config = Zend_Registry::get('config');
$prefixTables = $config->database->tables_prefix;
@@ -830,7 +818,6 @@ class Piwik
// at this point we have only the piwik tables which is good
// but we still miss the piwik generated tables (using the class Piwik_TablePartitioning)
-
$allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_numeric%'");
$allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_blob%'");
diff --git a/core/Plugin.php b/core/Plugin.php
index a909d2ed2a..9d49a19a96 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -29,27 +29,7 @@ abstract class Piwik_Plugin
* 'LogStatsPlugin' => bool // should we load this plugin during the stats logging process?
*/
abstract function getInformation();
-
- /**
- * Returns the plugin name
- * @var string
- */
- public function getName()
- {
- $info = $this->getInformation();
- return $info['name'];
- }
-
- /**
- * Returns the UserCountry part when the plugin class is Piwik_UserCountry
- *
- * @return string
- */
- public function getClassName()
- {
- return substr(get_class($this), strlen("Piwik_"));
- }
-
+
/**
* Returns the list of hooks registered with the methods names
* @var array
@@ -58,16 +38,7 @@ abstract class Piwik_Plugin
{
return array();
}
-
- /**
- * Returns the names of the required plugins
- * @var array
- */
- public function getListRequiredPlugins()
- {
- return array();
- }
-
+
/**
* Executed after loading plugin and registering translations
* Useful for code that uses translated strings from the plugin.
@@ -98,5 +69,35 @@ abstract class Piwik_Plugin
{
return;
}
+
+ /**
+ * Returns the names of the required plugins
+ * @var array
+ */
+ public function getListRequiredPlugins()
+ {
+ return array();
+ }
+
+ /**
+ * Returns the plugin name
+ * @var string
+ */
+ public function getName()
+ {
+ $info = $this->getInformation();
+ return $info['name'];
+ }
+
+ /**
+ * Returns the UserCountry part when the plugin class is Piwik_UserCountry
+ *
+ * @return string
+ */
+ public function getClassName()
+ {
+ return substr(get_class($this), strlen("Piwik_"));
+ }
+
}
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index 88fe7fca87..ad530cd65d 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -9,7 +9,6 @@
* @package Piwik
*/
-
require_once "Plugin.php";
require_once "Event/Dispatcher.php";
@@ -106,32 +105,6 @@ class Piwik_PluginsManager
} catch(Exception $e) {}
}
- /**
- * TODO horrible dirty hack because the Config class is not clean enough. Needs to rewrite the Config
- * __set and __get in a cleaner way, also see the __destruct which writes the configuration file.
- *
- * @return array
- */
- protected function getInstalledPlugins()
- {
- if(!class_exists('Zend_Registry'))
- {
- throw new Exception("Not possible to list installed plugins (case LogStats module)");
- }
- if(!is_null(Zend_Registry::get('config')->PluginsInstalled->PluginsInstalled))
- {
- return Zend_Registry::get('config')->PluginsInstalled->PluginsInstalled->toArray();
- }
- elseif(is_array(Zend_Registry::get('config')->PluginsInstalled))
- {
- return Zend_Registry::get('config')->PluginsInstalled;
- }
- else
- {
- return Zend_Registry::get('config')->PluginsInstalled->toArray();
- }
- }
-
public function installLoadedPlugins()
{
foreach($this->getLoadedPlugins() as $plugin)
@@ -144,42 +117,6 @@ class Piwik_PluginsManager
}
}
- protected function installPluginIfNecessary( Piwik_Plugin $plugin )
- {
- $pluginName = $plugin->getClassName();
-
- // is the plugin already installed or is it the first time we activate it?
- $pluginsInstalled = $this->getInstalledPlugins();
- if(!in_array($pluginName,$pluginsInstalled))
- {
- $this->installPlugin($plugin);
- $pluginsInstalled[] = $pluginName;
- Zend_Registry::get('config')->PluginsInstalled = $pluginsInstalled;
- }
-
- $information = $plugin->getInformation();
-
- // if the plugin is to be loaded during the statistics logging
- if(isset($information['LogStatsPlugin'])
- && $information['LogStatsPlugin'] === true)
- {
- $pluginsLogStats = Zend_Registry::get('config')->Plugins_LogStats->Plugins_LogStats;
- if(is_null($pluginsLogStats))
- {
- $pluginsLogStats = array();
- }
- else
- {
- $pluginsLogStats = $pluginsLogStats->toArray();
- }
- if(!in_array($pluginName, $pluginsLogStats))
- {
- $pluginsLogStats[] = $pluginName;
- Zend_Registry::get('config')->Plugins_LogStats = $pluginsLogStats;
- }
- }
- }
-
public function activatePlugin($pluginName)
{
$plugins = Zend_Registry::get('config')->Plugins->Plugins->toArray();
@@ -227,15 +164,14 @@ class Piwik_PluginsManager
$this->doLoadAlwaysActivatedPlugins = false;
}
- /**
- * Add a plugin in the loaded plugins array
- *
- * @param string plugin name without prefix (eg. 'UserCountry')
- * @param Piwik_Plugin $newPlugin
- */
- protected function addLoadedPlugin( $pluginName, Piwik_Plugin $newPlugin )
+ public function postLoadPlugins()
{
- $this->loadedPlugins[$pluginName] = $newPlugin;
+ $plugins = $this->getLoadedPlugins();
+ foreach($plugins as $plugin)
+ {
+ $this->loadTranslation( $plugin, $this->languageToLoad );
+ $plugin->postLoad();
+ }
}
/**
@@ -285,15 +221,13 @@ class Piwik_PluginsManager
public function loadPlugins()
{
$this->pluginsToLoad = array_unique($this->pluginsToLoad);
-
- $pluginsToLoad = $this->pluginsToLoad;
-
+
if($this->doLoadAlwaysActivatedPlugins)
{
- $pluginsToLoad = array_merge($this->pluginsToLoad, $this->pluginToAlwaysActivate);
+ $this->pluginsToLoad = array_merge($this->pluginsToLoad, $this->pluginToAlwaysActivate);
}
- foreach($pluginsToLoad as $pluginName)
+ foreach($this->pluginsToLoad as $pluginName)
{
$newPlugin = $this->loadPlugin($pluginName);
@@ -302,11 +236,8 @@ class Piwik_PluginsManager
if($this->doLoadPlugins
&& $this->isPluginActivated($pluginName))
{
- $this->registerTranslation( $newPlugin, $this->languageToLoad );
$this->addPluginObservers( $newPlugin );
$this->addLoadedPlugin( $pluginName, $newPlugin);
-
- $newPlugin->postLoad();
}
}
}
@@ -356,43 +287,12 @@ class Piwik_PluginsManager
}
return $newPlugin;
}
-
- public function installPlugin( Piwik_Plugin $plugin )
- {
- try{
- $plugin->install();
- } catch(Exception $e) {
- throw new Piwik_Plugin_Exception($plugin->getName(), $e->getMessage()); }
- }
- public function installPlugins()
- {
- foreach($this->getLoadedPlugins() as $plugin)
- {
- try{
- $plugin->install();
- } catch(Exception $e) {
- throw new Piwik_Plugin_Exception($plugin->getName(), $e->getMessage());
- }
- }
- }
public function setLanguageToLoad( $code )
{
$this->languageToLoad = $code;
}
-
- /**
- * For the given plugin, add all the observers of this plugin.
- */
- private function addPluginObservers( Piwik_Plugin $plugin )
- {
- $hooks = $plugin->getListHooksRegistered();
-
- foreach($hooks as $hookName => $methodToCall)
- {
- $this->dispatcher->addObserver( array( $plugin, $methodToCall), $hookName );
- }
- }
+
public function unloadPlugin( $plugin )
{
if(!($plugin instanceof Piwik_Plugin ))
@@ -420,12 +320,48 @@ class Piwik_PluginsManager
$this->unloadPlugin($plugin);
}
}
+
+ private function installPlugins()
+ {
+ foreach($this->getLoadedPlugins() as $plugin)
+ {
+ try{
+ $plugin->install();
+ } catch(Exception $e) {
+ throw new Piwik_Plugin_Exception($plugin->getName(), $e->getMessage());
+ }
+ }
+ }
+
+ /**
+ * For the given plugin, add all the observers of this plugin.
+ */
+ private function addPluginObservers( Piwik_Plugin $plugin )
+ {
+ $hooks = $plugin->getListHooksRegistered();
+
+ foreach($hooks as $hookName => $methodToCall)
+ {
+ $this->dispatcher->addObserver( array( $plugin, $methodToCall), $hookName );
+ }
+ }
+
+ /**
+ * Add a plugin in the loaded plugins array
+ *
+ * @param string plugin name without prefix (eg. 'UserCountry')
+ * @param Piwik_Plugin $newPlugin
+ */
+ private function addLoadedPlugin( $pluginName, Piwik_Plugin $newPlugin )
+ {
+ $this->loadedPlugins[$pluginName] = $newPlugin;
+ }
/**
* @param Piwik_Plugin $plugin
* @param string $langCode
*/
- protected function registerTranslation( $plugin, $langCode )
+ private function loadTranslation( $plugin, $langCode )
{
// we are certainly in LogStats mode, Zend is not loaded
if(!class_exists('Zend_Loader'))
@@ -470,8 +406,76 @@ class Piwik_PluginsManager
Piwik_Translate::getInstance()->addTranslationArray($translations);
}
-}
+ private function installPlugin( Piwik_Plugin $plugin )
+ {
+ try{
+ $plugin->install();
+ } catch(Exception $e) {
+ throw new Piwik_Plugin_Exception($plugin->getName(), $e->getMessage()); }
+ }
+
+ /**
+ * TODO horrible dirty hack because the Config class is not clean enough. Needs to rewrite the Config
+ * __set and __get in a cleaner way, also see the __destruct which writes the configuration file.
+ *
+ * @return array
+ */
+ private function getInstalledPlugins()
+ {
+ if(!class_exists('Zend_Registry'))
+ {
+ throw new Exception("Not possible to list installed plugins (case LogStats module)");
+ }
+ if(!is_null(Zend_Registry::get('config')->PluginsInstalled->PluginsInstalled))
+ {
+ return Zend_Registry::get('config')->PluginsInstalled->PluginsInstalled->toArray();
+ }
+ elseif(is_array(Zend_Registry::get('config')->PluginsInstalled))
+ {
+ return Zend_Registry::get('config')->PluginsInstalled;
+ }
+ else
+ {
+ return Zend_Registry::get('config')->PluginsInstalled->toArray();
+ }
+ }
+ private function installPluginIfNecessary( Piwik_Plugin $plugin )
+ {
+ $pluginName = $plugin->getClassName();
+
+ // is the plugin already installed or is it the first time we activate it?
+ $pluginsInstalled = $this->getInstalledPlugins();
+ if(!in_array($pluginName,$pluginsInstalled))
+ {
+ $this->installPlugin($plugin);
+ $pluginsInstalled[] = $pluginName;
+ Zend_Registry::get('config')->PluginsInstalled = $pluginsInstalled;
+ }
+
+ $information = $plugin->getInformation();
+
+ // if the plugin is to be loaded during the statistics logging
+ if(isset($information['LogStatsPlugin'])
+ && $information['LogStatsPlugin'] === true)
+ {
+ $pluginsLogStats = Zend_Registry::get('config')->Plugins_LogStats->Plugins_LogStats;
+ if(is_null($pluginsLogStats))
+ {
+ $pluginsLogStats = array();
+ }
+ else
+ {
+ $pluginsLogStats = $pluginsLogStats->toArray();
+ }
+ if(!in_array($pluginName, $pluginsLogStats))
+ {
+ $pluginsLogStats[] = $pluginName;
+ Zend_Registry::get('config')->Plugins_LogStats = $pluginsLogStats;
+ }
+ }
+ }
+}
class Piwik_Plugin_Exception extends Exception
{
@@ -484,7 +488,6 @@ class Piwik_Plugin_Exception extends Exception
}
}
-
/**
* Post an event to the dispatcher which will notice the observers
*/
@@ -499,4 +502,4 @@ function Piwik_PostEvent( $eventName, &$object = null, $info = array() )
function Piwik_AddAction( $hookName, $function )
{
Piwik_PluginsManager::getInstance()->dispatcher->addObserver( $function, $hookName );
-} \ No newline at end of file
+}
diff --git a/core/Site.php b/core/Site.php
index 12370dde65..d9001b6393 100644
--- a/core/Site.php
+++ b/core/Site.php
@@ -28,10 +28,12 @@ class Piwik_Site
self::$infoSites[$this->id] = Piwik_SitesManager_API::getSiteFromId($idsite);
}
}
+
function getName()
{
return self::$infoSites[$this->id]['name'];
}
+
function getMainUrl()
{
return self::$infoSites[$this->id]['main_url'];
diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php
index eda912f995..328da71736 100644
--- a/core/TablePartitioning.php
+++ b/core/TablePartitioning.php
@@ -31,14 +31,13 @@ abstract class Piwik_TablePartitioning
abstract protected function generateTableName() ;
-
public function setTimestamp( $timestamp )
{
$this->timestamp = $timestamp;
$this->generatedTableName = null;
$this->getTableName();
}
-
+
public function getTableName()
{
// table name already processed
diff --git a/core/Translate.php b/core/Translate.php
index 7f4ea56583..a2d5f92af5 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -15,10 +15,9 @@
class Piwik_Translate
{
static private $instance = null;
+ private $englishLanguageLoaded = false;
/**
- * Returns singleton
- *
* @return Piwik_Translate
*/
static public function getInstance()
@@ -30,20 +29,27 @@ class Piwik_Translate
}
return self::$instance;
}
-
- private function __construct()
+
+ public function loadEnglishTranslation()
{
- $translations = array();
-
- $language = $this->getFallbackLanguageToLoad();
- require_once "lang/" . $language .".php";
+ require "lang/en.php";
$this->addTranslationArray($translations);
-
+ $this->setLocale();
+ $this->englishLanguageLoaded = true;
+ }
+
+ public function loadUserTranslation()
+ {
$language = $this->getLanguageToLoad();
- require_once "lang/" . $language .".php";
- $this->addTranslationArray($translations);
+ if($language === 'en'
+ && $this->englishLanguageLoaded)
+ {
+ return;
+ }
- setlocale(LC_ALL, $GLOBALS['Piwik_translations']['General_Locale']);
+ require "lang/" . $language . ".php";
+ $this->addTranslationArray($translations);
+ $this->setLocale();
}
public function addTranslationArray($translation)
@@ -57,13 +63,18 @@ class Piwik_Translate
}
/**
- * @return string the language filename prefix, eg "en" for english
- * @throws exception if the language set in the config file is not a valid filename
+ * @return string the language filename prefix, eg 'en' for english
+ * @throws exception if the language set is not a valid filename
*/
public function getLanguageToLoad()
{
- $language = Zend_Registry::get('config')->Language->current;
+ $language = null;
+ Piwik_PostEvent('Translate.getLanguageToLoad', $language);
+ if(is_null($language))
+ {
+ $language = Zend_Registry::get('config')->General->default_language;
+ }
if( Piwik_Common::isValidFilename($language))
{
return $language;
@@ -74,20 +85,14 @@ class Piwik_Translate
}
}
- protected function getFallbackLanguageToLoad()
- {
- return Zend_Registry::get('config')->Language->fallback;
- }
-
/**
* Generate javascript translations array
*
* @return string containing javascript code with translations array (including <script> tag)
- *
*/
- public function getJavascriptTranslations($moduleList)
+ public function getJavascriptTranslations(array $moduleList)
{
- if( !$moduleList )
+ if( empty($moduleList) )
{
return '';
}
@@ -123,6 +128,11 @@ class Piwik_Translate
return $js;
}
+
+ private function setLocale()
+ {
+ setlocale(LC_ALL, $GLOBALS['Piwik_translations']['General_Locale']);
+ }
}
function Piwik_Translate($index)
diff --git a/core/Url.php b/core/Url.php
index f6ece7c37d..f0279fc2e3 100644
--- a/core/Url.php
+++ b/core/Url.php
@@ -44,6 +44,16 @@ class Piwik_Url
}
}
+ static public function redirectToReferer()
+ {
+ $referer = self::getReferer();
+ if($referer !== false)
+ {
+ self::redirectToUrl($referer);
+ }
+ self::redirectToUrl(Piwik_URL::getCurrentUrlWithoutQueryString());
+ }
+
static public function redirectToUrl( $url )
{
header("Location: $url");
diff --git a/core/ViewDataTable/GenerateGraphData.php b/core/ViewDataTable/GenerateGraphData.php
index 6174dbba9c..53ee435ddd 100644
--- a/core/ViewDataTable/GenerateGraphData.php
+++ b/core/ViewDataTable/GenerateGraphData.php
@@ -48,7 +48,7 @@ abstract class Piwik_ViewDataTable_GenerateGraphData extends Piwik_ViewDataTable
*
* @var int
*/
- protected $graphLimit = 5;
+ protected $graphLimit = 6;
/**
* Sets the number max of elements to display (number of pie slice, vertical bars, etc.)
diff --git a/core/Visualization/Chart.php b/core/Visualization/Chart.php
index 6e58ba721f..a80ac489db 100644
--- a/core/Visualization/Chart.php
+++ b/core/Visualization/Chart.php
@@ -10,7 +10,6 @@
*/
require_once "Visualization/OpenFlashChart.php";
-
/**
* Generates the data in the Open Flash Chart format, from the given data.
* Uses Open flash chart PHP library @see Piwik_Visualization_OpenFlashChart