bludit/bl-plugins/tags/plugin.php

84 lines
2.0 KiB
PHP
Raw Normal View History

2015-08-29 07:02:09 +02:00
<?php
class pluginTags extends Plugin {
public function init()
{
$this->dbFields = array(
'label'=>'Tags',
'sort'=>'date'
2015-08-29 07:02:09 +02:00
);
}
public function form()
{
global $Language;
$html = '<div>';
$html .= '<label>'.$Language->get('Plugin label').'</label>';
2015-08-29 07:02:09 +02:00
$html .= '<input name="label" id="jslabel" type="text" value="'.$this->getDbField('label').'">';
$html .= '</div>';
$html .= '<div>';
$html .= $Language->get('tag-sort-order').': <select name="sort">';
foreach(array('alpha'=>'tag-sort-alphabetical', 'count'=>'tag-sort-count', 'date'=>'tag-sort-date') as $key=>$value) {
if ($key == $this->getDbField('sort')) {
$html .= '<option value="'.$key.'" selected>'.$Language->get($value).'</option>';
} else {
$html .= '<option value="'.$key.'">'.$Language->get($value).'</option>';
}
}
$html .= '</select>';
$html .= '</div>';
2015-08-29 07:02:09 +02:00
return $html;
}
public function siteSidebar()
{
global $Language;
global $dbTags;
2015-08-29 20:07:47 +02:00
global $Url;
2015-08-29 07:02:09 +02:00
2015-08-30 01:26:46 +02:00
$db = $dbTags->db['postsIndex'];
2015-09-08 02:51:48 +02:00
$filter = $Url->filters('tag');
2015-08-30 01:26:46 +02:00
2015-08-29 07:02:09 +02:00
$html = '<div class="plugin plugin-tags">';
$html .= '<h2>'.$this->getDbField('label').'</h2>';
$html .= '<div class="plugin-content">';
$html .= '<ul>';
2016-01-22 23:20:22 +01:00
$tagArray = array();
2015-08-29 07:02:09 +02:00
foreach($db as $tagKey=>$fields)
{
2016-01-22 20:27:53 +01:00
$tagArray[] = array('tagKey'=>$tagKey, 'count'=>$dbTags->countPostsByTag($tagKey), 'name'=>$fields['name']);
}
2015-08-29 07:02:09 +02:00
// Sort the array based on options
if ($this->getDbField('sort') == "count")
{
usort($tagArray, function($a, $b) {
return $b['count'] - $a['count'];
});
}
elseif ($this->getDbField('sort') == "alpha")
{
usort($tagArray, function($a, $b) {
return strcmp($a['tagKey'], $b['tagKey']);
});
2015-08-29 07:02:09 +02:00
}
foreach($tagArray as $tagKey=>$fields)
{
// Print the parent
$html .= '<li><a href="'.HTML_PATH_ROOT.$filter.'/'.$fields['tagKey'].'">'.$fields['name'].' ('.$fields['count'].')</a></li>';
}
2015-08-29 07:02:09 +02:00
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
2016-01-22 20:27:53 +01:00
}