Skip to content

Commit

Permalink
added histogram feature to archive
Browse files Browse the repository at this point in the history
  • Loading branch information
dklight authored and Michael Klier committed Aug 24, 2009
1 parent 848efc6 commit 7511578
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 23 deletions.
4 changes: 4 additions & 0 deletions conf/default.php
Expand Up @@ -8,6 +8,10 @@
$conf['sortkey'] = 'cdate'; // sort key for blog entries
$conf['sortorder'] = 'descending'; // ascending or descending

$conf['showhistogram'] = 1; // show histogramm in archive
$conf['max_months'] = 100; // max months to show in the histogram
$conf['histogram_height'] = 50; // height of the histogram in pixels

$conf['excluded_pages'] = '!^blog:\d{4}(:\d{2})?$!'; // regex for pages to exclude from bloglisting

// vim:ts=4:sw=4:et:enc=utf-8:
3 changes: 3 additions & 0 deletions conf/metadata.php
Expand Up @@ -15,4 +15,7 @@
'_choices' => array('ascending', 'descending'));
$meta['excluded_pages'] = array('string');

$meta['showhistorgram'] = array('onoff');
$meta['max_months'] = array('numeric');
$meta['histogram_height'] = array('numeric');
// vim:ts=4:sw=4:et:enc=utf-8:
3 changes: 3 additions & 0 deletions lang/en/lang.php
Expand Up @@ -30,4 +30,7 @@
$lang['month_11'] = 'November';
$lang['month_12'] = 'December';

$lang['entries'] = 'entries';
$lang['entry'] = 'entry';
$lang['archive_title'] = 'Blog History';
//Setup VIM: ex: et ts=2 enc=utf-8 :
4 changes: 4 additions & 0 deletions lang/en/settings.php
Expand Up @@ -28,4 +28,8 @@

$lang['excluded_pages'] = 'exclude certain pages from blog listing (regular expression required)';

$lang['showhistorgram'] = 'Display histogram on archive rendering';
$lang['max_months'] = 'Max months to show in the histogram';
$lang['histogram_height'] = 'Height of the histogram (in pixels)';

// vim:ts=4:sw=4:et:enc=utf-8:
21 changes: 13 additions & 8 deletions style.css
Expand Up @@ -14,22 +14,27 @@ div.dokuwiki div.draft {
}

div.dokuwiki div.autoarchive_selector ul {
list-style-type: none;
clear: left;
margin: 0 0.5em 0 0;
list-style-type: none;
clear: left;
margin: 0 0.5em 0 0;
}

div.dokuwiki div.autoarchive_selector ul div.li {
float: left;
margin: 0 1em 0 0;
float: left;
margin: 0 1em 0 0;
}

div.dokuwiki div.autoarchive_selector ul ul {
float: left;
clear: none;
float: left;
clear: none;
}

div.dokuwiki div.autoarchive_selector ul ul div.li {
margin: 0;
margin: 0;
}

img.blog_archive_bar {
background-color: __border__;
width: 5px;
border: 0 none;
}
113 changes: 98 additions & 15 deletions syntax/archive.php
Expand Up @@ -114,26 +114,109 @@ function render($mode, &$renderer, $data) {
if (!$entries) return true; // nothing to display

if ($mode == 'xhtml') {
// Configuration
$archive_mode = $this->getConf('archive_mode');
$max_months = $this->getConf('max_months');
$histogram_height = $this->getConf('histogram_height');


// prevent caching for current month to ensure content is always fresh
if (time() < $end) $renderer->info['cache'] = false;

// let Pagelist Plugin do the work for us
if (plugin_isdisabled('pagelist')
|| (!$pagelist =& plugin_load('helper', 'pagelist'))) {
msg($this->getLang('missing_pagelistplugin'), -1);
return false;
}
$pagelist->setFlags($flags);
$pagelist->startList();
foreach ($entries as $entry) {

// entry in the right date range?
if (($start > $entry['date']) || ($entry['date'] >= $end)) continue;

$pagelist->addPage($entry);
if ($this->getConf('showhistogram')) {
$current_year ='';
$current_month ='';
$ul_open = false;

$histogram = '';
$histogram_count = array();
$histogram_higher = 0;
$posts_count = 0;

$list = '';

// Generate posts list
foreach ($entries as $entry) {
// entry in the right date range?
if (($start > $entry['date']) || ($entry['date'] >= $end)) continue;

if ($current_year != date('o',$entry['date'])) {
if ($ul_open) {
$list.="</ul>";
$ul_open = false;
}
$current_year = date('o',$entry['date']);
$list.='<h2>'.$current_year."</h2>";
}
if ($current_month != date('m',$entry['date'])) {
if ($ul_open) {
$list.="</ul>";
}
$current_month = date('m',$entry['date']);
$list.='<h3 id="m'.date('o-m',$entry['date']).'">'.$this->getLang('month_'.$current_month)."</h3><ul>";
$ul_open = true;
}
$posts_count += 1;
$histogram_count[date('o-m',$entry['date'])] += 1;
if ($histogram_higher < $histogram_count[date('o-m',$entry['date'])]) {
$histogram_higher = $histogram_count[date('o-m',$entry['date'])];
}
$list.='<li>'.date("d",$entry['date']).' - <a href="'.wl($entry['id']).'">'.$entry['title']."</a></li>";
}
$list.="</ul>";

if ($posts_count > $max_posts) {
$posts_count = $max_posts;
}
// Generate histogram
$histogram_count = array_reverse($histogram_count);
$month_count = 0;
foreach ($histogram_count as $key => $month_reference) {
// Check the max_months parameter
if ($month_count >= $max_months) {
break;
}
if ($month_reference > 0) {
// Height in "px"
$current_height = $histogram_height / $histogram_higher * $month_reference;
} else {
// Height in "px"
$current_height = 1;
}
// Generate the alt attribute
$alt = $key.': '.$month_reference.' ';
if ($month_reference > 1) {
$alt .= $this->getLang('entries');
} else {
$alt .= $this->getLang('entry');
}
$histogram .= '<a href="#m'.$key.'" title="#m'.$key.'">';
$histogram .= '<img class="blog_archive_bar" alt="'.$alt.'" height="'.$current_height."\" src=\"/lib/images/blank.gif\"/></a>" . DOKU_LF;
$month_count += 1;
}
// Add histogram and posts list
$renderer->doc .= "<div class=\"level1\"><h1>".$this->getLang('archive_title')."</h1>".$histogram.'<br/><br/>'.$list.'</div>';
} else {
// prevent caching for current month to ensure content is always fresh
if (time() < $end) $renderer->info['cache'] = false;

// let Pagelist Plugin do the work for us
if (plugin_isdisabled('pagelist')
|| (!$pagelist =& plugin_load('helper', 'pagelist'))) {
msg($this->getLang('missing_pagelistplugin'), -1);
return false;
}
$pagelist->setFlags($flags);
$pagelist->startList();
foreach ($entries as $entry) {

// entry in the right date range?
if (($start > $entry['date']) || ($entry['date'] >= $end)) continue;

$pagelist->addPage($entry);
}
$renderer->doc .= $pagelist->finishList();
}
$renderer->doc .= $pagelist->finishList();
return true;

// for metadata renderer
Expand Down

0 comments on commit 7511578

Please sign in to comment.