Skip to content

Commit

Permalink
* admin screens,
Browse files Browse the repository at this point in the history
 * removed the remains of CDN/jquery feature
Refs #4019
  • Loading branch information
mattab committed Jun 26, 2013
1 parent 8f6d151 commit 12e81ae
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 95 deletions.
8 changes: 0 additions & 8 deletions config/global.ini.php
Expand Up @@ -268,14 +268,6 @@
; the page will automatically refresh every 5 minutes. Set to 0 to disable automatic refresh
multisites_refresh_after_seconds = 300

; by default, Piwik uses self-hosted AJAX libraries.
; If set to 1, Piwik uses a Content Distribution Network
use_ajax_cdn = 0

; required AJAX library versions
jquery_version = 1.10.1
jqueryui_version = 1.10.3

; Set to 1 if you're using https on your Piwik server and Piwik can't detect it,
; e.g., a reverse proxy using https-to-http, or a web server that doesn't
; set the HTTPS environment variable.
Expand Down
154 changes: 91 additions & 63 deletions core/Twig.php
Expand Up @@ -46,9 +46,26 @@ public function __construct($theme = self::DEFAULT_THEME)
);
$this->twig->addExtension(new Twig_Extension_Debug());
$this->twig->clearTemplateCache();
// Add default filters
$this->addFilters();
// Register namespaces

$this->addFilter_translate();
$this->addFilter_urlRewriteWithParameters();
$this->addFilter_sumTime();
$this->addFilter_money();
$this->addFilter_truncate();
/*
$this->load_filter('output', 'cachebuster');
$this->load_filter('output', 'trimwhitespace');*/


$this->addFunction_includeAssets();
$this->addFunction_linkTo();
$this->addFunction_loadJavascriptTranslations();
$this->addFunction_sparkline();
$this->addFunction_postEvent();
}

protected function addFunction_includeAssets()
{
$includeAssetsFunction = new Twig_SimpleFunction('includeAssets', function ($params) {
if (!isset($params['type'])) {
throw new Exception("The smarty function includeAssets needs a 'type' parameter.");
Expand All @@ -69,12 +86,32 @@ public function __construct($theme = self::DEFAULT_THEME)
}
});
$this->twig->addFunction($includeAssetsFunction);
$urlFunction = new Twig_SimpleFunction('linkTo', function($params) {
return 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified($params);
});
$this->twig->addFunction($urlFunction);
}

protected function addFunction_postEvent()
{
$postEventFunction = new Twig_SimpleFunction('postEvent', function ($eventName) {
$str = '';
Piwik_PostEvent($eventName, $str);
return $str;
}, array('is_safe' => array('html')));
$this->twig->addFunction($postEventFunction);
}

$loadJsTranslationsFunction = new Twig_SimpleFunction('loadJavascriptTranslations', function(array $plugins, $disableScriptTag = false) {
protected function addFunction_sparkline()
{
$sparklineFunction = new Twig_SimpleFunction('sparkline', function ($src) {
$graph = new Piwik_Visualization_Sparkline();
$width = $graph->getWidth();
$height = $graph->getHeight();
return sprintf('<img class="sparkline" alt="" src="%s" width="%d" height="%d" />', $src, $width, $height);
}, array('is_safe' => array('html')));
$this->twig->addFunction($sparklineFunction);
}

protected function addFunction_loadJavascriptTranslations()
{
$loadJsTranslationsFunction = new Twig_SimpleFunction('loadJavascriptTranslations', function (array $plugins, $disableScriptTag = false) {
static $pluginTranslationsAlreadyLoaded = array();
if (in_array($plugins, $pluginTranslationsAlreadyLoaded)) {
return;
Expand All @@ -92,21 +129,14 @@ public function __construct($theme = self::DEFAULT_THEME)
return $jsCode;
}, array('is_safe' => array('html')));
$this->twig->addFunction($loadJsTranslationsFunction);
}

$sparklineFunction = new Twig_SimpleFunction('sparkline', function($src) {
$graph = new Piwik_Visualization_Sparkline();
$width = $graph->getWidth();
$height = $graph->getHeight();
return sprintf('<img class="sparkline" alt="" src="%s" width="%d" height="%d" />', $src, $width, $height);
}, array('is_safe' => array('html')));
$this->twig->addFunction($sparklineFunction);

$postEventFunction = new Twig_SimpleFunction('postEvent', function($eventName) {
$str = '';
Piwik_PostEvent($eventName, $str);
return $str;
}, array('is_safe' => array('html')));
$this->twig->addFunction($postEventFunction);
protected function addFunction_linkTo()
{
$urlFunction = new Twig_SimpleFunction('linkTo', function ($params) {
return 'index.php' . Piwik_Url::getCurrentQueryStringWithParametersModified($params);
});
$this->twig->addFunction($urlFunction);
}

/**
Expand All @@ -126,20 +156,50 @@ public function getTwigEnvironment()
return $this->twig;
}

public function initFilters()
protected function addFilter_truncate()
{
/*
$this->load_filter('output', 'cachebuster');
$truncateFilter = new Twig_SimpleFilter('truncate', function ($string, $size) {
if (strlen($string) < $size) {
return $string;
} else {
return array_shift(str_split($string, $size)) . "...";
}
});
$this->twig->addFilter($truncateFilter);
}

$use_ajax_cdn = Piwik_Config::getInstance()->General['use_ajax_cdn'];
if ($use_ajax_cdn) {
$this->load_filter('output', 'ajaxcdn');
}
protected function addFilter_money()
{
$moneyFilter = new Twig_SimpleFilter('money', function ($amount) {
if (func_num_args() != 2) {
throw new Exception('the smarty modifier money expects one parameter: the idSite.');
}
$idSite = func_get_args();
$idSite = $idSite[1];
return Piwik::getPrettyMoney($amount, $idSite);
});
$this->twig->addFilter($moneyFilter);
}

$this->load_filter('output', 'trimwhitespace');*/
protected function addFilter_sumTime()
{
$sumtimeFilter = new Twig_SimpleFilter('sumtime', function ($numberOfSeconds) {
return Piwik::getPrettyTimeFromSeconds($numberOfSeconds);
});
$this->twig->addFilter($sumtimeFilter);
}

protected function addFilter_urlRewriteWithParameters()
{
$urlRewriteFilter = new Twig_SimpleFilter('urlRewriteWithParameters', function ($parameters) {
$parameters['updated'] = null;
$url = Piwik_Url::getCurrentQueryStringWithParametersModified($parameters);
return $url;
});
$this->twig->addFilter($urlRewriteFilter);
}

private function addFilters()
protected function addFilter_translate()
{
$translateFilter = new Twig_SimpleFilter('translate', function ($stringToken) {
if (func_num_args() <= 1) {
Expand All @@ -157,38 +217,6 @@ private function addFilters()
return $stringTranslated;
});
$this->twig->addFilter($translateFilter);

$urlRewriteFilter = new Twig_SimpleFilter('urlRewriteWithParameters', function ($parameters) {
$parameters['updated'] = null;
$url = Piwik_Url::getCurrentQueryStringWithParametersModified($parameters);
return $url;
});
$this->twig->addFilter($urlRewriteFilter);

$sumtimeFilter = new Twig_SimpleFilter('sumtime', function($numberOfSeconds) {
return Piwik::getPrettyTimeFromSeconds($numberOfSeconds);
});
$this->twig->addFilter($sumtimeFilter);

$moneyFilter = new Twig_SimpleFilter('money', function($amount)
{
if (func_num_args() != 2) {
throw new Exception('the smarty modifier money expects one parameter: the idSite.');
}
$idSite = func_get_args();
$idSite = $idSite[1];
return Piwik::getPrettyMoney($amount, $idSite);
});
$this->twig->addFilter($moneyFilter);

$truncateFilter = new Twig_SimpleFilter('truncate', function($string, $size) {
if(strlen($string) < $size) {
return $string;
} else {
return array_shift(str_split($string, $size)) . "...";
}
});
$this->twig->addFilter($truncateFilter);
}

private function addPluginNamespaces(Twig_Loader_Filesystem $loader)
Expand Down
2 changes: 1 addition & 1 deletion plugins/PrivacyManager/templates/privacySettings.twig
Expand Up @@ -215,7 +215,7 @@
<br/>
{% endif %}
<strong>{{ 'PrivacyManager_NextDelete'|translate }}:</strong>
{{ deleteData.nextRunPretty }}
{{ deleteData.nextRunPretty|raw }}
<br/>
<br/>
<em><a id="purgeDataNowLink" href="#">{{ 'PrivacyManager_PurgeNow'|translate }}</a></em>
Expand Down
1 change: 1 addition & 0 deletions plugins/UserCountry/Controller.php
Expand Up @@ -279,6 +279,7 @@ public function setCurrentLocationProvider()
if ($provider === false) {
throw new Exception("Invalid provider ID: '$providerId'.");
}
echo 1;
}
}

Expand Down
7 changes: 4 additions & 3 deletions plugins/UserCountry/templates/_updaterManage.twig
@@ -1,7 +1,8 @@
<div id="geoipdb-update-info" {% if not geoIPDatabasesInstalled %}style="display:none"{% endif %}>
<p>{{ 'UserCountry_GeoIPUpdaterInstructions'|translate('<a href="http://www.maxmind.com/en/download_files?rId=piwik" _target="blank">','</a>','<a href="http://www.maxmind.com/?rId=piwik">','</a>') }}
<p>{{ 'UserCountry_GeoIPUpdaterInstructions'|translate('<a href="http://www.maxmind.com/en/download_files?rId=piwik" _target="blank">','</a>',
'<a href="http://www.maxmind.com/?rId=piwik">','</a>')|raw }}
<br/><br/>
{{ 'UserCountry_GeoLiteCityLink'|translate("<a href='"~geoLiteUrl~"'>",geoLiteUrl,'</a>') }}
{{ 'UserCountry_GeoLiteCityLink'|translate("<a href='"~geoLiteUrl~"'>",geoLiteUrl,'</a>')|raw }}
{% if geoIPDatabasesInstalled %}
<br/><br/>{{ 'UserCountry_GeoIPUpdaterIntro'|translate }}:
{% endif %}
Expand Down Expand Up @@ -43,7 +44,7 @@
<td width="164">
{% set lastTimeRunNote %}
{% if lastTimeUpdaterRun is not empty %}
{{ 'UserCountry_UpdaterWasLastRun'|translate(lastTimeUpdaterRun) }}
{{ 'UserCountry_UpdaterWasLastRun'|translate(lastTimeUpdaterRun)|raw }}
{% else %}
{{ 'UserCountry_UpdaterHasNotBeenRun'|translate }}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion plugins/UserCountry/templates/adminIndex.twig
Expand Up @@ -120,7 +120,7 @@
</div>
<div id="geoipdb-screen2-download" style="display:none">
<p class='loadingPiwik'><img src='./plugins/Zeitgeist/images/loading-blue.gif'/>
{{ 'UserCountry_DownloadingDb'|translate('<a href="'+geoLiteUrl+'">GeoLiteCity.dat</a>') }}...</p>
{{ 'UserCountry_DownloadingDb'|translate('<a href="'+geoLiteUrl+'">GeoLiteCity.dat</a>')|raw }}...</p>
<div id="geoip-download-progress"></div>
</div>
{% endif %}
Expand Down
19 changes: 0 additions & 19 deletions tests/PHPUnit/Core/ReleaseCheckListTest.php
Expand Up @@ -112,25 +112,6 @@ public function testPiwikTrackerDebugIsOff()
$this->assertTrue($GLOBALS['PIWIK_TRACKER_DEBUG'] === false);
}

/**
* @group Core
* @group ReleaseCheckList
*/
public function testAjaxLibraryVersions()
{
Piwik::createConfigObject();
Piwik_Config::getInstance()->setTestEnvironment();

$jqueryJs = file_get_contents(PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery.js', false, NULL, 0, 512);
$this->assertTrue((boolean)preg_match('/jQuery (?:JavaScript Library )?v?([0-9.]+)/', $jqueryJs, $matches));
$this->assertEquals(Piwik_Config::getInstance()->General['jquery_version'], $matches[1]);

$jqueryuiJs = file_get_contents(PIWIK_DOCUMENT_ROOT . '/libs/jquery/jquery-ui.js', false, NULL, 0, 512);
$this->assertTrue((boolean)preg_match('/jQuery UI (?:- v)?([0-9.]+)/', $jqueryuiJs, $matches));
$this->assertEquals(Piwik_Config::getInstance()->General['jqueryui_version'], $matches[1]);

}

/**
* @group Core
* @group ReleaseCheckList
Expand Down

0 comments on commit 12e81ae

Please sign in to comment.