3 class NP_DateLink extends NucleusPlugin
5 function getEventList()
22 return 'http://nakahara21.com';
25 function getMinNucleusVersion()
35 function getDescription()
37 return '<%DateLink%> on TEMPLATE displays links to the archives for the same date. ';
40 function supportsFeature($what)
43 case 'SqlTablePrefix':
52 $this->createOption('dl_limit', 'Limit to create links (years)', 'text', '3');
53 $this->createOption('dl_header', 'Header of links','text', '<ul>');
54 $this->createOption('dl_footer', 'Footer of links','text', '</ul>');
55 $this->createOption('template_ago', 'Template for older (Blank for no link.)', 'text', '<li><a href="<%linkurl%>" title="Archive for <%date%>">« <%year%> year(s) ago</a></li>');
56 $this->createOption('template_after', 'Template for newer (Blank for no link.)', 'text', '<li><a href="<%linkurl%>" title="Archive for <%date%>"><%year%> year(s) after »</a></li>');
57 $this->createOption('template_separator', 'Separator for links', 'text', '');
60 function doTemplateVar(&$item)
62 $today = $item->timestamp;
63 $tcat = intval($item->catid);
64 if ($linkForPrint = $this->LinksDate($today, $tcat, $this->getOption('dl_limit'))) {
65 echo $this->getOption('dl_header');
66 echo @join($this->getOption('template_separator'), $linkForPrint);
67 echo $this->getOption('dl_footer');
71 function LinksDate($timestamp, $catid, $limitYear)
73 global $manager, $blog, $CONF, $archive;
75 if (!$this->getOption('template_ago') && !$this->getOption('template_after')) {
79 $blogid = intval(getBlogIDFromCatID($catid));
80 $b =& $manager->getBlog($blogid);
81 $from = array('<%linkurl%>', '<%date%>', '<%year%>');
83 for ($i=$limitYear;$i>0;$i--) {
84 if (!$this->getOption('template_ago')) break;
85 $target_date = date('Y-m-d', strtotime("-" . $i . " years", $timestamp));
86 $s = $this->getArchiveForDate($target_date, $b);
88 $linkurl = createArchiveLink($blogid, $target_date);
94 $print_data[] = str_replace($from, $to, $this->getOption('template_ago'));
98 for ($i=1;$i<=$limitYear;$i++) {
99 if (!$this->getOption('template_after')) break;
100 $target_date = date('Y-m-d', strtotime("+" . $i . " years", $timestamp));
101 $s = $this->getArchiveForDate($target_date, $b);
103 $linkurl = createArchiveLink($blogid, $target_date);
109 $print_data[] = str_replace($from, $to, $this->getOption('template_after'));
116 function getArchiveForDate ($target_date, $blog)
118 $query = 'SELECT inumber FROM ' . sql_table('item')
119 . ' WHERE iblog = ' . $blog->getID() . ' AND itime BETWEEN "'
120 . $target_date . ' 00:00:00" AND "'
121 . $target_date . ' 23:59:59"'
123 . ' AND itime <= ' . mysqldate($blog->getCorrectTime())
125 $result = sql_query($query);
126 if (mysql_num_rows($result)) return TRUE;