diff options
-rw-r--r-- | application/LinkDB.php | 11 | ||||
-rw-r--r-- | application/PageBuilder.php | 2 | ||||
-rw-r--r-- | application/Updater.php | 15 | ||||
-rw-r--r-- | index.php | 30 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 31 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 40 | ||||
-rw-r--r-- | tpl/default/css/shaarli.css | 6 | ||||
-rw-r--r-- | tpl/default/includes.html | 2 | ||||
-rw-r--r-- | tpl/default/tagcloud.html | 20 | ||||
-rw-r--r-- | tpl/vintage/tagcloud.html | 2 |
10 files changed, 69 insertions, 90 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index 0d3c85bd..7802cc8a 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -452,14 +452,17 @@ You use the community supported version of the original Shaarli project, by Seba | |||
452 | } | 452 | } |
453 | 453 | ||
454 | /** | 454 | /** |
455 | * Returns the list of all tags | 455 | * Returns the list tags appearing in the links with the given tags |
456 | * Output: associative array key=tags, value=0 | 456 | * @param $filteringTags: tags selecting the links to consider |
457 | * @param $visibility: process only all/private/public links | ||
458 | * @return: a tag=>linksCount array | ||
457 | */ | 459 | */ |
458 | public function allTags() | 460 | public function linksCountPerTag($filteringTags = [], $visibility = 'all') |
459 | { | 461 | { |
462 | $links = empty($filteringTags) ? $this->links : $this->filterSearch(['searchtags' => $filteringTags], false, $visibility); | ||
460 | $tags = array(); | 463 | $tags = array(); |
461 | $caseMapping = array(); | 464 | $caseMapping = array(); |
462 | foreach ($this->links as $link) { | 465 | foreach ($links as $link) { |
463 | foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { | 466 | foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { |
464 | if (empty($tag)) { | 467 | if (empty($tag)) { |
465 | continue; | 468 | continue; |
diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 50e3f124..c86621a2 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php | |||
@@ -89,7 +89,7 @@ class PageBuilder | |||
89 | $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); | 89 | $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); |
90 | $this->tpl->assign('token', getToken($this->conf)); | 90 | $this->tpl->assign('token', getToken($this->conf)); |
91 | if ($this->linkDB !== null) { | 91 | if ($this->linkDB !== null) { |
92 | $this->tpl->assign('tags', $this->linkDB->allTags()); | 92 | $this->tpl->assign('tags', $this->linkDB->linksCountPerTag()); |
93 | } | 93 | } |
94 | // To be removed with a proper theme configuration. | 94 | // To be removed with a proper theme configuration. |
95 | $this->tpl->assign('conf', $this->conf); | 95 | $this->tpl->assign('conf', $this->conf); |
diff --git a/application/Updater.php b/application/Updater.php index 03d93a6f..40a15906 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -329,21 +329,6 @@ class Updater | |||
329 | } | 329 | } |
330 | 330 | ||
331 | /** | 331 | /** |
332 | * While the new default theme is in an unstable state | ||
333 | * continue to use the vintage theme | ||
334 | */ | ||
335 | public function updateMethodDefaultThemeVintage() | ||
336 | { | ||
337 | if ($this->conf->get('resource.theme') !== 'default') { | ||
338 | return true; | ||
339 | } | ||
340 | $this->conf->set('resource.theme', 'vintage'); | ||
341 | $this->conf->write($this->isLoggedIn); | ||
342 | |||
343 | return true; | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * * `markdown_escape` is a new setting, set to true as default. | 332 | * * `markdown_escape` is a new setting, set to true as default. |
348 | * | 333 | * |
349 | * If the markdown plugin was already enabled, escaping is disabled to avoid | 334 | * If the markdown plugin was already enabled, escaping is disabled to avoid |
@@ -225,27 +225,6 @@ function setup_login_state($conf) | |||
225 | } | 225 | } |
226 | $userIsLoggedIn = setup_login_state($conf); | 226 | $userIsLoggedIn = setup_login_state($conf); |
227 | 227 | ||
228 | /** | ||
229 | * PubSubHubbub protocol support (if enabled) [UNTESTED] | ||
230 | * (Source: http://aldarone.fr/les-flux-rss-shaarli-et-pubsubhubbub/ ) | ||
231 | * | ||
232 | * @param ConfigManager $conf Configuration Manager instance. | ||
233 | */ | ||
234 | function pubsubhub($conf) | ||
235 | { | ||
236 | $pshUrl = $conf->get('config.PUBSUBHUB_URL'); | ||
237 | if (!empty($pshUrl)) | ||
238 | { | ||
239 | include_once './publisher.php'; | ||
240 | $p = new Publisher($pshUrl); | ||
241 | $topic_url = array ( | ||
242 | index_url($_SERVER).'?do=atom', | ||
243 | index_url($_SERVER).'?do=rss' | ||
244 | ); | ||
245 | $p->publish_update($topic_url); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | // ------------------------------------------------------------------------------------------ | 228 | // ------------------------------------------------------------------------------------------ |
250 | // Session management | 229 | // Session management |
251 | 230 | ||
@@ -811,7 +790,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
811 | // -------- Tag cloud | 790 | // -------- Tag cloud |
812 | if ($targetPage == Router::$PAGE_TAGCLOUD) | 791 | if ($targetPage == Router::$PAGE_TAGCLOUD) |
813 | { | 792 | { |
814 | $tags= $LINKSDB->allTags(); | 793 | $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all'; |
794 | $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : array(); | ||
795 | $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility); | ||
815 | 796 | ||
816 | // We sort tags alphabetically, then choose a font size according to count. | 797 | // We sort tags alphabetically, then choose a font size according to count. |
817 | // First, find max value. | 798 | // First, find max value. |
@@ -845,6 +826,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
845 | } | 826 | } |
846 | 827 | ||
847 | $data = array( | 828 | $data = array( |
829 | 'search_tags' => implode(' ', $filteringTags), | ||
848 | 'tags' => $tagList, | 830 | 'tags' => $tagList, |
849 | ); | 831 | ); |
850 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); | 832 | $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); |
@@ -1375,7 +1357,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1375 | 'link' => $link, | 1357 | 'link' => $link, |
1376 | 'link_is_new' => false, | 1358 | 'link_is_new' => false, |
1377 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), | 1359 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1378 | 'tags' => $LINKSDB->allTags(), | 1360 | 'tags' => $LINKSDB->linksCountPerTag(), |
1379 | ); | 1361 | ); |
1380 | $pluginManager->executeHooks('render_editlink', $data); | 1362 | $pluginManager->executeHooks('render_editlink', $data); |
1381 | 1363 | ||
@@ -1444,7 +1426,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history) | |||
1444 | 'link_is_new' => $link_is_new, | 1426 | 'link_is_new' => $link_is_new, |
1445 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), | 1427 | 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), |
1446 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), | 1428 | 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), |
1447 | 'tags' => $LINKSDB->allTags(), | 1429 | 'tags' => $LINKSDB->linksCountPerTag(), |
1448 | 'default_private_links' => $conf->get('privacy.default_private_links', false), | 1430 | 'default_private_links' => $conf->get('privacy.default_private_links', false), |
1449 | ); | 1431 | ); |
1450 | $pluginManager->executeHooks('render_editlink', $data); | 1432 | $pluginManager->executeHooks('render_editlink', $data); |
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 7bf98f92..2523467d 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -297,7 +297,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
297 | 'sTuff' => 2, | 297 | 'sTuff' => 2, |
298 | 'ut' => 1, | 298 | 'ut' => 1, |
299 | ), | 299 | ), |
300 | self::$publicLinkDB->allTags() | 300 | self::$publicLinkDB->linksCountPerTag() |
301 | ); | 301 | ); |
302 | 302 | ||
303 | $this->assertEquals( | 303 | $this->assertEquals( |
@@ -325,7 +325,34 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
325 | 'tag4' => 1, | 325 | 'tag4' => 1, |
326 | 'ut' => 1, | 326 | 'ut' => 1, |
327 | ), | 327 | ), |
328 | self::$privateLinkDB->allTags() | 328 | self::$privateLinkDB->linksCountPerTag() |
329 | ); | ||
330 | $this->assertEquals( | ||
331 | array( | ||
332 | 'web' => 4, | ||
333 | 'cartoon' => 2, | ||
334 | 'gnu' => 1, | ||
335 | 'dev' => 1, | ||
336 | 'samba' => 1, | ||
337 | 'media' => 1, | ||
338 | 'html' => 1, | ||
339 | 'w3c' => 1, | ||
340 | 'css' => 1, | ||
341 | 'Mercurial' => 1, | ||
342 | '.hidden' => 1, | ||
343 | 'hashtag' => 1, | ||
344 | ), | ||
345 | self::$privateLinkDB->linksCountPerTag(['web']) | ||
346 | ); | ||
347 | $this->assertEquals( | ||
348 | array( | ||
349 | 'web' => 1, | ||
350 | 'html' => 1, | ||
351 | 'w3c' => 1, | ||
352 | 'css' => 1, | ||
353 | 'Mercurial' => 1, | ||
354 | ), | ||
355 | self::$privateLinkDB->linksCountPerTag(['web'], 'private') | ||
329 | ); | 356 | ); |
330 | } | 357 | } |
331 | 358 | ||
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 11b6444a..fed175df 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -470,46 +470,6 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
470 | } | 470 | } |
471 | 471 | ||
472 | /** | 472 | /** |
473 | * Test updateMethodDefaultThemeVintage with the default theme enabled. | ||
474 | */ | ||
475 | public function testSetDefaultThemeToVintage() | ||
476 | { | ||
477 | $sandboxConf = 'sandbox/config'; | ||
478 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
479 | $this->conf = new ConfigManager($sandboxConf); | ||
480 | |||
481 | $this->conf->set('resource.theme', 'default'); | ||
482 | $updater = new Updater([], [], $this->conf, true); | ||
483 | $this->assertTrue($updater->updateMethodDefaultThemeVintage()); | ||
484 | $this->assertEquals('vintage', $this->conf->get('resource.theme')); | ||
485 | |||
486 | // reload from file | ||
487 | $this->conf = new ConfigManager($sandboxConf); | ||
488 | $this->assertEquals('vintage', $this->conf->get('resource.theme')); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * Test updateMethodDefaultThemeVintage with custom theme enabled => nothing to do. | ||
493 | */ | ||
494 | public function testSetDefaultThemeNothingToDo() | ||
495 | { | ||
496 | $sandboxConf = 'sandbox/config'; | ||
497 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
498 | $this->conf = new ConfigManager($sandboxConf); | ||
499 | |||
500 | $theme = 'myawesometheme'; | ||
501 | $this->conf->set('resource.theme', $theme); | ||
502 | $this->conf->write(true); | ||
503 | $updater = new Updater([], [], $this->conf, true); | ||
504 | $this->assertTrue($updater->updateMethodDefaultThemeVintage()); | ||
505 | $this->assertEquals($theme, $this->conf->get('resource.theme')); | ||
506 | |||
507 | // reload from file | ||
508 | $this->conf = new ConfigManager($sandboxConf); | ||
509 | $this->assertEquals($theme, $this->conf->get('resource.theme')); | ||
510 | } | ||
511 | |||
512 | /** | ||
513 | * Test updateMethodEscapeMarkdown with markdown plugin enabled | 473 | * Test updateMethodEscapeMarkdown with markdown plugin enabled |
514 | * => setting markdown_escape set to false. | 474 | * => setting markdown_escape set to false. |
515 | */ | 475 | */ |
diff --git a/tpl/default/css/shaarli.css b/tpl/default/css/shaarli.css index efdf06d4..4415a1b7 100644 --- a/tpl/default/css/shaarli.css +++ b/tpl/default/css/shaarli.css | |||
@@ -211,7 +211,7 @@ body, .pure-g [class*="pure-u"] { | |||
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | #search, #search-linklist { | 214 | #search, #search-linklist, #search-tagcloud { |
215 | text-align: center; | 215 | text-align: center; |
216 | width: 100%; | 216 | width: 100%; |
217 | } | 217 | } |
@@ -234,6 +234,7 @@ body, .pure-g [class*="pure-u"] { | |||
234 | } | 234 | } |
235 | 235 | ||
236 | #search button, | 236 | #search button, |
237 | #search-tagcloud button, | ||
237 | #search-linklist button { | 238 | #search-linklist button { |
238 | background: transparent; | 239 | background: transparent; |
239 | border: none; | 240 | border: none; |
@@ -251,6 +252,9 @@ body, .pure-g [class*="pure-u"] { | |||
251 | #search-linklist button:hover { | 252 | #search-linklist button:hover { |
252 | color: #fff; | 253 | color: #fff; |
253 | } | 254 | } |
255 | #search-tagcloud button:hover { | ||
256 | color: #d0d0d0; | ||
257 | } | ||
254 | 258 | ||
255 | #search-linklist { | 259 | #search-linklist { |
256 | padding: 5px 0; | 260 | padding: 5px 0; |
diff --git a/tpl/default/includes.html b/tpl/default/includes.html index 91c6ca3b..0350ef66 100644 --- a/tpl/default/includes.html +++ b/tpl/default/includes.html | |||
@@ -11,7 +11,7 @@ | |||
11 | <link type="text/css" rel="stylesheet" href="css/font-awesome.min.css" /> | 11 | <link type="text/css" rel="stylesheet" href="css/font-awesome.min.css" /> |
12 | <link type="text/css" rel="stylesheet" href="inc/awesomplete.css#" /> | 12 | <link type="text/css" rel="stylesheet" href="inc/awesomplete.css#" /> |
13 | <link type="text/css" rel="stylesheet" href="css/shaarli.css" /> | 13 | <link type="text/css" rel="stylesheet" href="css/shaarli.css" /> |
14 | {if="is_file('inc/user.css')"} | 14 | {if="is_file('data/user.css')"} |
15 | <link type="text/css" rel="stylesheet" href="data/user.css#" /> | 15 | <link type="text/css" rel="stylesheet" href="data/user.css#" /> |
16 | {/if} | 16 | {/if} |
17 | {loop="$plugins_includes.css_files"} | 17 | {loop="$plugins_includes.css_files"} |
diff --git a/tpl/default/tagcloud.html b/tpl/default/tagcloud.html index 53c31748..efe6e937 100644 --- a/tpl/default/tagcloud.html +++ b/tpl/default/tagcloud.html | |||
@@ -12,6 +12,24 @@ | |||
12 | {$countTags=count($tags)} | 12 | {$countTags=count($tags)} |
13 | <h2 class="window-title">{'Tag cloud'|t} - {$countTags} {'tags'|t}</h2> | 13 | <h2 class="window-title">{'Tag cloud'|t} - {$countTags} {'tags'|t}</h2> |
14 | 14 | ||
15 | <div id="search-tagcloud" class="pure-g"> | ||
16 | <div class="pure-u-lg-1-4"></div> | ||
17 | <div class="pure-u-1 pure-u-lg-1-2"> | ||
18 | <form method="GET"> | ||
19 | <input type="hidden" name="do" value="tagcloud"> | ||
20 | <input type="text" name="searchtags" placeholder="{'Filter by tag'|t}" | ||
21 | {if="!empty($search_tags)"} | ||
22 | value="{$search_tags}" | ||
23 | {/if} | ||
24 | autocomplete="off" data-multiple data-autofirst data-minChars="1" | ||
25 | data-list="{loop="$tags"}{$key}, {/loop}" | ||
26 | > | ||
27 | <button type="submit" class="search-button"><i class="fa fa-search"></i></button> | ||
28 | </form> | ||
29 | </div> | ||
30 | <div class="pure-u-lg-1-4"></div> | ||
31 | </div> | ||
32 | |||
15 | <div id="plugin_zone_start_tagcloud" class="plugin_zone"> | 33 | <div id="plugin_zone_start_tagcloud" class="plugin_zone"> |
16 | {loop="$plugin_start_zone"} | 34 | {loop="$plugin_start_zone"} |
17 | {$value} | 35 | {$value} |
@@ -21,7 +39,7 @@ | |||
21 | <div id="cloudtag"> | 39 | <div id="cloudtag"> |
22 | {loop="tags"} | 40 | {loop="tags"} |
23 | <a href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a | 41 | <a href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a |
24 | ><span class="count">{$value.count}</span> | 42 | ><a href="?addtag={$key|urlencode}" title="{'Filter by tag'|t}" class="count">{$value.count}</a> |
25 | {loop="$value.tag_plugin"} | 43 | {loop="$value.tag_plugin"} |
26 | {$value} | 44 | {$value} |
27 | {/loop} | 45 | {/loop} |
diff --git a/tpl/vintage/tagcloud.html b/tpl/vintage/tagcloud.html index 05e45273..d93bf4f9 100644 --- a/tpl/vintage/tagcloud.html +++ b/tpl/vintage/tagcloud.html | |||
@@ -12,7 +12,7 @@ | |||
12 | 12 | ||
13 | <div id="cloudtag"> | 13 | <div id="cloudtag"> |
14 | {loop="$tags"} | 14 | {loop="$tags"} |
15 | <span class="count">{$value.count}</span><a | 15 | <a href="?addtag={$key|urlencode}" class="count">{$value.count}</a><a |
16 | href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a> | 16 | href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a> |
17 | {loop="$value.tag_plugin"} | 17 | {loop="$value.tag_plugin"} |
18 | {$value} | 18 | {$value} |