aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/Languages.php21
-rw-r--r--application/PageBuilder.php1
-rw-r--r--index.php12
-rw-r--r--tests/LanguagesTest.php41
-rw-r--r--tpl/tools.html2
5 files changed, 66 insertions, 11 deletions
diff --git a/application/Languages.php b/application/Languages.php
new file mode 100644
index 00000000..c8b0a25a
--- /dev/null
+++ b/application/Languages.php
@@ -0,0 +1,21 @@
1<?php
2
3/**
4 * Wrapper function for translation which match the API
5 * of gettext()/_() and ngettext().
6 *
7 * Not doing translation for now.
8 *
9 * @param string $text Text to translate.
10 * @param string $nText The plural message ID.
11 * @param int $nb The number of items for plural forms.
12 *
13 * @return String Text translated.
14 */
15function t($text, $nText = '', $nb = 0) {
16 if (empty($nText)) {
17 return $text;
18 }
19 $actualForm = $nb > 1 ? $nText : $text;
20 return sprintf($actualForm, $nb);
21}
diff --git a/application/PageBuilder.php b/application/PageBuilder.php
index 1ca0260a..42932f32 100644
--- a/application/PageBuilder.php
+++ b/application/PageBuilder.php
@@ -80,6 +80,7 @@ class PageBuilder
80 if (!empty($GLOBALS['plugin_errors'])) { 80 if (!empty($GLOBALS['plugin_errors'])) {
81 $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); 81 $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']);
82 } 82 }
83 $this->tpl->assign('token', getToken($this->conf));
83 // To be removed with a proper theme configuration. 84 // To be removed with a proper theme configuration.
84 $this->tpl->assign('conf', $this->conf); 85 $this->tpl->assign('conf', $this->conf);
85 } 86 }
diff --git a/index.php b/index.php
index 55b12adc..9ae798ba 100644
--- a/index.php
+++ b/index.php
@@ -53,6 +53,7 @@ require_once 'application/config/ConfigPlugin.php';
53require_once 'application/FeedBuilder.php'; 53require_once 'application/FeedBuilder.php';
54require_once 'application/FileUtils.php'; 54require_once 'application/FileUtils.php';
55require_once 'application/HttpUtils.php'; 55require_once 'application/HttpUtils.php';
56require_once 'application/Languages.php';
56require_once 'application/LinkDB.php'; 57require_once 'application/LinkDB.php';
57require_once 'application/LinkFilter.php'; 58require_once 'application/LinkFilter.php';
58require_once 'application/LinkUtils.php'; 59require_once 'application/LinkUtils.php';
@@ -783,8 +784,6 @@ function renderPage($conf, $pluginManager)
783 if ($targetPage == Router::$PAGE_LOGIN) 784 if ($targetPage == Router::$PAGE_LOGIN)
784 { 785 {
785 if ($conf->get('security.open_shaarli')) { header('Location: ?'); exit; } // No need to login for open Shaarli 786 if ($conf->get('security.open_shaarli')) { header('Location: ?'); exit; } // No need to login for open Shaarli
786 $token=''; if (ban_canLogin($conf)) $token=getToken($conf); // Do not waste token generation if not useful.
787 $PAGE->assign('token',$token);
788 if (isset($_GET['username'])) { 787 if (isset($_GET['username'])) {
789 $PAGE->assign('username', escape($_GET['username'])); 788 $PAGE->assign('username', escape($_GET['username']));
790 } 789 }
@@ -1105,7 +1104,6 @@ function renderPage($conf, $pluginManager)
1105 } 1104 }
1106 else // show the change password form. 1105 else // show the change password form.
1107 { 1106 {
1108 $PAGE->assign('token',getToken($conf));
1109 $PAGE->renderPage('changepassword'); 1107 $PAGE->renderPage('changepassword');
1110 exit; 1108 exit;
1111 } 1109 }
@@ -1152,7 +1150,6 @@ function renderPage($conf, $pluginManager)
1152 } 1150 }
1153 else // Show the configuration form. 1151 else // Show the configuration form.
1154 { 1152 {
1155 $PAGE->assign('token',getToken($conf));
1156 $PAGE->assign('title', $conf->get('general.title')); 1153 $PAGE->assign('title', $conf->get('general.title'));
1157 $PAGE->assign('redirector', $conf->get('redirector.url')); 1154 $PAGE->assign('redirector', $conf->get('redirector.url'));
1158 list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone')); 1155 list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone'));
@@ -1172,7 +1169,6 @@ function renderPage($conf, $pluginManager)
1172 if ($targetPage == Router::$PAGE_CHANGETAG) 1169 if ($targetPage == Router::$PAGE_CHANGETAG)
1173 { 1170 {
1174 if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { 1171 if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) {
1175 $PAGE->assign('token', getToken($conf));
1176 $PAGE->assign('tags', $LINKSDB->allTags()); 1172 $PAGE->assign('tags', $LINKSDB->allTags());
1177 $PAGE->renderPage('changetag'); 1173 $PAGE->renderPage('changetag');
1178 exit; 1174 exit;
@@ -1347,7 +1343,6 @@ function renderPage($conf, $pluginManager)
1347 $data = array( 1343 $data = array(
1348 'link' => $link, 1344 'link' => $link,
1349 'link_is_new' => false, 1345 'link_is_new' => false,
1350 'token' => getToken($conf),
1351 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), 1346 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
1352 'tags' => $LINKSDB->allTags(), 1347 'tags' => $LINKSDB->allTags(),
1353 ); 1348 );
@@ -1414,11 +1409,10 @@ function renderPage($conf, $pluginManager)
1414 $data = array( 1409 $data = array(
1415 'link' => $link, 1410 'link' => $link,
1416 'link_is_new' => $link_is_new, 1411 'link_is_new' => $link_is_new,
1417 'token' => getToken($conf), // XSRF protection.
1418 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), 1412 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
1419 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), 1413 'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
1420 'tags' => $LINKSDB->allTags(), 1414 'tags' => $LINKSDB->allTags(),
1421 'default_private_links' => $conf->get('default_private_links', false), 1415 'default_private_links' => $conf->get('privacy.default_private_links', false),
1422 ); 1416 );
1423 $pluginManager->executeHooks('render_editlink', $data); 1417 $pluginManager->executeHooks('render_editlink', $data);
1424 1418
@@ -1492,7 +1486,6 @@ function renderPage($conf, $pluginManager)
1492 // -------- Show upload/import dialog: 1486 // -------- Show upload/import dialog:
1493 if ($targetPage == Router::$PAGE_IMPORT) 1487 if ($targetPage == Router::$PAGE_IMPORT)
1494 { 1488 {
1495 $PAGE->assign('token',getToken($conf));
1496 $PAGE->assign('maxfilesize',getMaxFileSize()); 1489 $PAGE->assign('maxfilesize',getMaxFileSize());
1497 $PAGE->renderPage('import'); 1490 $PAGE->renderPage('import');
1498 exit; 1491 exit;
@@ -1734,7 +1727,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
1734 'search_term' => $searchterm, 1727 'search_term' => $searchterm,
1735 'search_tags' => $searchtags, 1728 'search_tags' => $searchtags,
1736 'redirector' => $conf->get('redirector.url'), // Optional redirector URL. 1729 'redirector' => $conf->get('redirector.url'), // Optional redirector URL.
1737 'token' => $token,
1738 'links' => $linkDisp, 1730 'links' => $linkDisp,
1739 'tags' => $LINKSDB->allTags(), 1731 'tags' => $LINKSDB->allTags(),
1740 ); 1732 );
diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php
new file mode 100644
index 00000000..79c136c8
--- /dev/null
+++ b/tests/LanguagesTest.php
@@ -0,0 +1,41 @@
1<?php
2
3require_once 'application/Languages.php';
4
5/**
6 * Class LanguagesTest.
7 */
8class LanguagesTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * Test t() with a simple non identified value.
12 */
13 public function testTranslateSingleNotID()
14 {
15 $text = 'abcdé 564 fgK';
16 $this->assertEquals($text, t($text));
17 }
18
19 /**
20 * Test t() with a non identified plural form.
21 */
22 public function testTranslatePluralNotID()
23 {
24 $text = '%s sandwich';
25 $nText = '%s sandwiches';
26 $this->assertEquals('0 sandwich', t($text, $nText));
27 $this->assertEquals('1 sandwich', t($text, $nText, 1));
28 $this->assertEquals('2 sandwiches', t($text, $nText, 2));
29 }
30
31 /**
32 * Test t() with a non identified invalid plural form.
33 */
34 public function testTranslatePluralNotIDInvalid()
35 {
36 $text = 'sandwich';
37 $nText = 'sandwiches';
38 $this->assertEquals('sandwich', t($text, $nText, 1));
39 $this->assertEquals('sandwiches', t($text, $nText, 2));
40 }
41}
diff --git a/tpl/tools.html b/tpl/tools.html
index 9e45caad..8e285f44 100644
--- a/tpl/tools.html
+++ b/tpl/tools.html
@@ -9,7 +9,7 @@
9 <br><br> 9 <br><br>
10 <a href="?do=pluginadmin"><b>Plugin administration</b><span>: Enable, disable and configure plugins.</span></a> 10 <a href="?do=pluginadmin"><b>Plugin administration</b><span>: Enable, disable and configure plugins.</span></a>
11 <br><br> 11 <br><br>
12 {if="$openshaarli"}<a href="?do=changepasswd"><b>Change password</b><span>: Change your password.</span></a> 12 {if="!$openshaarli"}<a href="?do=changepasswd"><b>Change password</b><span>: Change your password.</span></a>
13 <br><br>{/if} 13 <br><br>{/if}
14 <a href="?do=changetag"><b>Rename/delete tags</b><span>: Rename or delete a tag in all links</span></a> 14 <a href="?do=changetag"><b>Rename/delete tags</b><span>: Rename or delete a tag in all links</span></a>
15 <br><br> 15 <br><br>