}
/**
- * Returns the list of all tags
- * Output: associative array key=tags, value=0
+ * Returns the list tags appearing in the links with the given tags
+ * @param $filteringTags: tags selecting the links to consider
+ * @param $visibility: process only all/private/public links
+ * @return: a tag=>linksCount array
*/
- public function allTags()
+ public function linksCountPerTag($filteringTags = [], $visibility = 'all')
{
+ $links = empty($filteringTags) ? $this->links : $this->filterSearch(['searchtags' => $filteringTags], false, $visibility);
$tags = array();
$caseMapping = array();
- foreach ($this->links as $link) {
+ foreach ($links as $link) {
foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) {
if (empty($tag)) {
continue;
$this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
$this->tpl->assign('token', getToken($this->conf));
if ($this->linkDB !== null) {
- $this->tpl->assign('tags', $this->linkDB->allTags());
+ $this->tpl->assign('tags', $this->linkDB->linksCountPerTag());
}
// To be removed with a proper theme configuration.
$this->tpl->assign('conf', $this->conf);
// -------- Tag cloud
if ($targetPage == Router::$PAGE_TAGCLOUD)
{
- $tags= $LINKSDB->allTags();
+ $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all';
+ $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : array();
+ $tags = $LINKSDB->linksCountPerTag($filteringTags, $visibility);
// We sort tags alphabetically, then choose a font size according to count.
// First, find max value.
}
$data = array(
+ 'search_tags' => implode(' ', $filteringTags),
'tags' => $tagList,
);
$pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn()));
'link' => $link,
'link_is_new' => false,
'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
- 'tags' => $LINKSDB->allTags(),
+ 'tags' => $LINKSDB->linksCountPerTag(),
);
$pluginManager->executeHooks('render_editlink', $data);
'link_is_new' => $link_is_new,
'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
- 'tags' => $LINKSDB->allTags(),
+ 'tags' => $LINKSDB->linksCountPerTag(),
'default_private_links' => $conf->get('privacy.default_private_links', false),
);
$pluginManager->executeHooks('render_editlink', $data);
'sTuff' => 2,
'ut' => 1,
),
- self::$publicLinkDB->allTags()
+ self::$publicLinkDB->linksCountPerTag()
);
$this->assertEquals(
'tag4' => 1,
'ut' => 1,
),
- self::$privateLinkDB->allTags()
+ self::$privateLinkDB->linksCountPerTag()
+ );
+ $this->assertEquals(
+ array(
+ 'web' => 4,
+ 'cartoon' => 2,
+ 'gnu' => 1,
+ 'dev' => 1,
+ 'samba' => 1,
+ 'media' => 1,
+ 'html' => 1,
+ 'w3c' => 1,
+ 'css' => 1,
+ 'Mercurial' => 1,
+ '.hidden' => 1,
+ 'hashtag' => 1,
+ ),
+ self::$privateLinkDB->linksCountPerTag(['web'])
+ );
+ $this->assertEquals(
+ array(
+ 'web' => 1,
+ 'html' => 1,
+ 'w3c' => 1,
+ 'css' => 1,
+ 'Mercurial' => 1,
+ ),
+ self::$privateLinkDB->linksCountPerTag(['web'], 'private')
);
}
}
}
-#search, #search-linklist {
+#search, #search-linklist, #search-tagcloud {
text-align: center;
width: 100%;
}
}
#search button,
+#search-tagcloud button,
#search-linklist button {
background: transparent;
border: none;
#search-linklist button:hover {
color: #fff;
}
+#search-tagcloud button:hover {
+ color: #d0d0d0;
+}
#search-linklist {
padding: 5px 0;
{$countTags=count($tags)}
<h2 class="window-title">{'Tag cloud'|t} - {$countTags} {'tags'|t}</h2>
+ <div id="search-tagcloud" class="pure-g">
+ <div class="pure-u-lg-1-4"></div>
+ <div class="pure-u-1 pure-u-lg-1-2">
+ <form method="GET">
+ <input type="hidden" name="do" value="tagcloud">
+ <input type="text" name="searchtags" placeholder="{'Filter by tag'|t}"
+ {if="!empty($search_tags)"}
+ value="{$search_tags}"
+ {/if}
+ autocomplete="off" data-multiple data-autofirst data-minChars="1"
+ data-list="{loop="$tags"}{$key}, {/loop}"
+ >
+ <button type="submit" class="search-button"><i class="fa fa-search"></i></button>
+ </form>
+ </div>
+ <div class="pure-u-lg-1-4"></div>
+ </div>
+
<div id="plugin_zone_start_tagcloud" class="plugin_zone">
{loop="$plugin_start_zone"}
{$value}
<div id="cloudtag">
{loop="tags"}
<a href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a
- ><span class="count">{$value.count}</span>
+ ><a href="?addtag={$key|urlencode}" title="{'Filter by tag'|t}" class="count">{$value.count}</a>
{loop="$value.tag_plugin"}
{$value}
{/loop}
<div id="cloudtag">
{loop="$tags"}
- <span class="count">{$value.count}</span><a
+ <a href="?addtag={$key|urlencode}" class="count">{$value.count}</a><a
href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a>
{loop="$value.tag_plugin"}
{$value}