Merge pull request #878 from Lucas-C/master
Adding the ability to display subtags in the tagcloud
This commit is contained in:
commit
7481dd6e66
7 changed files with 68 additions and 13 deletions
|
@ -452,14 +452,17 @@ public function filterSearch($filterRequest = array(), $casesensitive = false, $
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of all tags
|
* Returns the list tags appearing in the links with the given tags
|
||||||
* Output: associative array key=tags, value=0
|
* @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();
|
$tags = array();
|
||||||
$caseMapping = 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) {
|
foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) {
|
||||||
if (empty($tag)) {
|
if (empty($tag)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -89,7 +89,7 @@ private function initialize()
|
||||||
$this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
|
$this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
|
||||||
$this->tpl->assign('token', getToken($this->conf));
|
$this->tpl->assign('token', getToken($this->conf));
|
||||||
if ($this->linkDB !== null) {
|
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.
|
// To be removed with a proper theme configuration.
|
||||||
$this->tpl->assign('conf', $this->conf);
|
$this->tpl->assign('conf', $this->conf);
|
||||||
|
|
|
@ -790,7 +790,9 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
|
||||||
// -------- Tag cloud
|
// -------- Tag cloud
|
||||||
if ($targetPage == Router::$PAGE_TAGCLOUD)
|
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.
|
// We sort tags alphabetically, then choose a font size according to count.
|
||||||
// First, find max value.
|
// First, find max value.
|
||||||
|
@ -824,6 +826,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
|
'search_tags' => implode(' ', $filteringTags),
|
||||||
'tags' => $tagList,
|
'tags' => $tagList,
|
||||||
);
|
);
|
||||||
$pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn()));
|
$pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => isLoggedIn()));
|
||||||
|
@ -1351,7 +1354,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
|
||||||
'link' => $link,
|
'link' => $link,
|
||||||
'link_is_new' => false,
|
'link_is_new' => false,
|
||||||
'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
|
'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
|
||||||
'tags' => $LINKSDB->allTags(),
|
'tags' => $LINKSDB->linksCountPerTag(),
|
||||||
);
|
);
|
||||||
$pluginManager->executeHooks('render_editlink', $data);
|
$pluginManager->executeHooks('render_editlink', $data);
|
||||||
|
|
||||||
|
@ -1420,7 +1423,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
|
||||||
'link_is_new' => $link_is_new,
|
'link_is_new' => $link_is_new,
|
||||||
'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
|
'http_referer' => (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']) : ''),
|
||||||
'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
|
'source' => (isset($_GET['source']) ? $_GET['source'] : ''),
|
||||||
'tags' => $LINKSDB->allTags(),
|
'tags' => $LINKSDB->linksCountPerTag(),
|
||||||
'default_private_links' => $conf->get('privacy.default_private_links', false),
|
'default_private_links' => $conf->get('privacy.default_private_links', false),
|
||||||
);
|
);
|
||||||
$pluginManager->executeHooks('render_editlink', $data);
|
$pluginManager->executeHooks('render_editlink', $data);
|
||||||
|
|
|
@ -297,7 +297,7 @@ public function testAllTags()
|
||||||
'sTuff' => 2,
|
'sTuff' => 2,
|
||||||
'ut' => 1,
|
'ut' => 1,
|
||||||
),
|
),
|
||||||
self::$publicLinkDB->allTags()
|
self::$publicLinkDB->linksCountPerTag()
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -325,7 +325,34 @@ public function testAllTags()
|
||||||
'tag4' => 1,
|
'tag4' => 1,
|
||||||
'ut' => 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')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ body, .pure-g [class*="pure-u"] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#search, #search-linklist {
|
#search, #search-linklist, #search-tagcloud {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -234,6 +234,7 @@ body, .pure-g [class*="pure-u"] {
|
||||||
}
|
}
|
||||||
|
|
||||||
#search button,
|
#search button,
|
||||||
|
#search-tagcloud button,
|
||||||
#search-linklist button {
|
#search-linklist button {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -251,6 +252,9 @@ body, .pure-g [class*="pure-u"] {
|
||||||
#search-linklist button:hover {
|
#search-linklist button:hover {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
#search-tagcloud button:hover {
|
||||||
|
color: #d0d0d0;
|
||||||
|
}
|
||||||
|
|
||||||
#search-linklist {
|
#search-linklist {
|
||||||
padding: 5px 0;
|
padding: 5px 0;
|
||||||
|
|
|
@ -12,6 +12,24 @@
|
||||||
{$countTags=count($tags)}
|
{$countTags=count($tags)}
|
||||||
<h2 class="window-title">{'Tag cloud'|t} - {$countTags} {'tags'|t}</h2>
|
<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">
|
<div id="plugin_zone_start_tagcloud" class="plugin_zone">
|
||||||
{loop="$plugin_start_zone"}
|
{loop="$plugin_start_zone"}
|
||||||
{$value}
|
{$value}
|
||||||
|
@ -21,7 +39,7 @@ <h2 class="window-title">{'Tag cloud'|t} - {$countTags} {'tags'|t}</h2>
|
||||||
<div id="cloudtag">
|
<div id="cloudtag">
|
||||||
{loop="tags"}
|
{loop="tags"}
|
||||||
<a href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a
|
<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"}
|
{loop="$value.tag_plugin"}
|
||||||
{$value}
|
{$value}
|
||||||
{/loop}
|
{/loop}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
<div id="cloudtag">
|
<div id="cloudtag">
|
||||||
{loop="$tags"}
|
{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>
|
href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a>
|
||||||
{loop="$value.tag_plugin"}
|
{loop="$value.tag_plugin"}
|
||||||
{$value}
|
{$value}
|
||||||
|
|
Loading…
Reference in a new issue