<?php /** This plugin can be used to display the last few monthly archiv links. Also it will display and count the items per month. This plugin is designed to give a more flexible possibility to customize the HTML - Output. The whole output is fully editable in the Plugin option managment. In the pluginsource is no HTML code !! Options in Plugin Management * display year names in short or long form * Comma seperated monthnames in your language * HTML formatting Start Template: could be a '<ul>' Tag * HTML formatting Link Template: Format the archiv links in your preferred style and used the defined placeholders <%archivlink%>, <%monthname%>. Optional placeholders are <%year%>, <%activ%> and <%itemcount%> * Comment - No Archiv links found Skin Parameters * the first parameter define how many archiv links will be show: o <%MonthlyArchivLinks(5)%>: show 5 latest archiv links all blogs; * the second parameter defines from which blog the archivlinks will come: o if no 2nd parameter is defined, the plugin will show the archiv links among all blogs o <%MonthlyArchivLinks(5,actual)%>: show 5 archiv links from the actual blog; o <%MonthlyArchivLinks(5,3)%>: show 5 archiv links from the blog number 3; o <%MonthlyArchivLinks(5,default)%>: show 5 archiv links from the default blog; o <%MonthlyArchivLinks(5,cat)%>: show 5 archiv links from the current category; Updates would be available at http://wiki.nucleuscms.org/MonthlyArchivLinks and http://www.alfmiti.net/download/NP_MonthlyArchivLinks.phps Changelog: * 0.1 initial relase -- 1.7.2004 * 0.12 added htmlentities to get monthnames,(added to nucleus wiki) -- 7.8.2004 */ class NP_MonthlyArchivLinks extends NucleusPlugin { // set Default Templates var $startTemplate = "\t<!-- start monthly archiv links -->\n<ul>\n"; var $linkTemplate = "\t<li><a<%active%>href=\"<%archivlink%>\"><%monthname%> <%year%></a> [<%item_count%>]</li>\n"; var $endTemplate = "</ul>\n\t<!-- end monthly archiv links -->\n"; var $activeStyle = "class=\"active\""; // set default vars var $monthNames = 'January,February,March,April,May,June,July,August,September,October,November,December'; var $noArchivLinks = 'No archiv links'; function getName() { return 'MonthlyArchivLinks'; } function getAuthor() { return 'ALF mit I'; } function getURL() { return 'http://www.alfmiti.net/'; } function getVersion() { return '0.1'; } function getDescription() { return 'This plugin can be used to display the last few monthly archiv links.'. 'Also it will display and count the items per month.'. 'The whole output is fully editable in the Plugin option managment'; } function supportsFeature($feature) { switch($feature) { case 'SqlTablePrefix': return 1; default: return 0; } } function install() { $desc = "used mandatory placeholders are: <%archivlink%>, <%monthname%>; optional are: <%active%>, <%year%>, <%item_count%>."; $this->createOption('showYear','Year - Format (i.e 04 or 2004)','select','long','short year name|short|long year name|long'); $this->createOption('monthNames','Comma seperated Monthnames in your Language','textarea',$this->monthNames); $this->createOption('startTemplate','HTML - Start Template :','textarea',$this->startTemplate); $this->createOption('linkTemplate','HTML - Link Template : '.$desc,'textarea',$this->linkTemplate); $this->createOption('endTemplate','HTML - End Template :','textarea',$this->endTemplate); $this->createOption('activeStyle','HTML - Active Style (class=* or style=*) :','textarea',$this->activeStyle); $this->createOption('noArchivLinks','Message No Archiv Links :','textarea',$this->noArchivLinks); } // skinvar plugin can have a blogname as second parameter function doSkinVar($skinType) { global $manager, $blog, $catid, $CONF; $params = func_get_args(); $monthNames = $this->getOption('monthNames'); $showYear = $this->getOption('showYear'); $startTemplate = $this->getOption('startTemplate'); $linkTemplate = $this->getOption('linkTemplate'); $endTemplate = $this->getOption('endTemplate'); $activeStyle = $this->getOption('activeStyle'); // get defaults or set paramas $numberOfLinks = empty($params[1]) ? 5 : $params[1]; $showYear = empty($showYear) ? 'no' : $showYear; $monthNames = empty($monthNames) ? $this->monthNames : $monthNames; $startTemplate = empty($startTemplate) ? $this->startTemplate : $startTemplate; $linkTemplate = empty($linkTemplate) ? $this->linkTemplate : $linkTemplate; $endTemplate = empty($endTemplate) ? $this->endTemplate : $endTemplate; // prepare monthnames array $monthnameLng = explode(',','0,'.$monthNames); foreach ($monthnameLng as $key=>$value) { $monthnameLng[$key] = htmlentities(trim($value)); } $blogid = $blog->getID(); if (!isset($params[2])) $params[2] = 'All'; // switch given 2nd parameter switch ($params[2]) { case 'All': // show archivlinks from all blogs $condition = ''; break; case 'actual': // show archivlinks from the actual blog $condition = ' AND iblog='.$blogid.' '; break; case 'default': // show archivlinks from the default blog $condition = ' AND iblog='.$CONF['DefaultBlog'].' '; break; case 'cat': // show archivlinks from the current blog $condition = $skinType != 'archive' ? ' AND icat='.$catid.' ' : ''; break; default: // show archivlinks from the selected blog id $condition = ' AND iblog='.$params[2].' '; break; } // set correct locale setlocale(LC_TIME,$this->getOption('Locale')); $timestampNow = $blog->getCorrectTime(); $query = 'SELECT count(inumber) AS item_count, '. 'MONTH(itime) AS month, YEAR(itime) AS year '. 'FROM '.sql_table('item').' '. 'WHERE UNIX_TIMESTAMP(itime) < '.$timestampNow.' '.$condition. 'GROUP BY month ORDER by itime DESC LIMIT 0,'.$numberOfLinks; $res = sql_query($query); // if there no results return; if (@mysql_num_rows($res) == 0) { echo $noArchivLinks; return; } $archivVar = getVar('archive'); echo $startTemplate; while($row = mysql_fetch_object($res)) { $archivlink = createArchiveLink($blogid,$row->year.'-'.$row->month); $displayYear = $showYear == 'short' ? substr($row->year,2) : $row->year; $isActiveLink = $archivVar == $row->year.'-'.$row->month ? ' '.$activeStyle.' ' : ' '; // format output with template $output = str_replace('<%archivlink%>',$archivlink,$linkTemplate); $output = str_replace('<%year%>',$displayYear,$output); $output = str_replace('<%item_count%>',$row->item_count,$output); $output = str_replace('<%monthname%>',$monthnameLng[$row->month],$output); $output = str_replace('<%active%>', $isActiveLink, $output); // ugly template vars cleanup $output = preg_replace('/<%(.*)%>/','',$output); echo $output; } echo $endTemplate; } } ?>