aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLucas Cimon <lucas.cimon@gmail.com>2017-05-18 20:28:11 +0200
committerLucas Cimon <lucas.cimon@gmail.com>2017-05-24 13:09:35 +0200
commit6ccd0b218fbd34de750f55b78f3dc43bb3d9fa8e (patch)
treeae99823d461435577abd25b8bb24ef07692b99a1
parent61c15aa5554431893ea5ebe800a9a625dca5aff9 (diff)
downloadShaarli-6ccd0b218fbd34de750f55b78f3dc43bb3d9fa8e.tar.gz
Shaarli-6ccd0b218fbd34de750f55b78f3dc43bb3d9fa8e.tar.zst
Shaarli-6ccd0b218fbd34de750f55b78f3dc43bb3d9fa8e.zip
Adding ability to display subtags in tagcloud
-rw-r--r--application/LinkDB.php11
-rw-r--r--application/PageBuilder.php2
-rw-r--r--index.php9
-rw-r--r--tests/LinkDBTest.php31
-rw-r--r--tpl/default/css/shaarli.css6
-rw-r--r--tpl/default/tagcloud.html20
-rw-r--r--tpl/vintage/tagcloud.html2
7 files changed, 68 insertions, 13 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/index.php b/index.php
index 468dd091..fb8b96b5 100644
--- a/index.php
+++ b/index.php
@@ -790,7 +790,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
790 // -------- Tag cloud 790 // -------- Tag cloud
791 if ($targetPage == Router::$PAGE_TAGCLOUD) 791 if ($targetPage == Router::$PAGE_TAGCLOUD)
792 { 792 {
793 $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);
794 796
795 // 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.
796 // First, find max value. 798 // First, find max value.
@@ -824,6 +826,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
824 } 826 }
825 827
826 $data = array( 828 $data = array(
829 'search_tags' => implode(' ', $filteringTags),
827 'tags' => $tagList, 830 'tags' => $tagList,
828 ); 831 );
829 $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn())); 832 $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn()));
@@ -1351,7 +1354,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
1351 'link' => $link, 1354 'link' => $link,
1352 'link_is_new' => false, 1355 'link_is_new' => false,
1353 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), 1356 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
1354 'tags' => $LINKSDB->allTags(), 1357 'tags' => $LINKSDB->linksCountPerTag(),
1355 ); 1358 );
1356 $pluginManager->executeHooks('render_editlink', $data); 1359 $pluginManager->executeHooks('render_editlink', $data);
1357 1360
@@ -1420,7 +1423,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
1420 'link_is_new' => $link_is_new, 1423 'link_is_new' => $link_is_new,
1421 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''), 1424 'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
1422 'source' => (isset($_GET['source']) ? $_GET['source'] : ''), 1425 'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
1423 'tags' => $LINKSDB->allTags(), 1426 'tags' => $LINKSDB->linksCountPerTag(),
1424 'default_private_links' => $conf->get('privacy.default_private_links', false), 1427 'default_private_links' => $conf->get('privacy.default_private_links', false),
1425 ); 1428 );
1426 $pluginManager->executeHooks('render_editlink', $data); 1429 $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/tpl/default/css/shaarli.css b/tpl/default/css/shaarli.css
index 73fade5f..ef9ee23b 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/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}