Skip to content
Browse files

added histogram feature to archive

  • Loading branch information...
1 parent 848efc6 commit 75115785100d87241ee3bd27a491fb9750654308 @dklight dklight committed with Michael Klier Aug 24, 2009
Showing with 125 additions and 23 deletions.
  1. +4 −0 conf/default.php
  2. +3 −0 conf/metadata.php
  3. +3 −0 lang/en/lang.php
  4. +4 −0 lang/en/settings.php
  5. +13 −8 style.css
  6. +98 −15 syntax/archive.php
View
4 conf/default.php
@@ -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:
View
3 conf/metadata.php
@@ -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:
View
3 lang/en/lang.php
@@ -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 :
View
4 lang/en/settings.php
@@ -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:
View
21 style.css
@@ -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;
+}
View
113 syntax/archive.php
@@ -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

0 comments on commit 7511578

Please sign in to comment.
Something went wrong with that request. Please try again.