OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@898 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_ArchiveListEX / trunk / NP_ArchiveListEX.php
1 <?
2
3 class NP_ArchiveListEX extends NucleusPlugin {
4
5         // name of plugin
6         function getName() {
7                 return 'ArchiveListEX'; 
8         }
9         
10         // author of plugin
11         function getAuthor()  { 
12                 return 'nakahara21'; 
13         }
14         
15         // an URL to the plugin website
16         function getURL() 
17         {
18                 return 'http://nakahara21.com/'; 
19         }
20         
21         // version of the plugin
22         function getVersion() {
23                 return '1.01'; 
24         }
25         
26         function supportsFeature($what) { 
27                 switch($what){ 
28                         case 'SqlTablePrefix': 
29                                 return 1; 
30                         default: 
31                                 return 0; 
32                 } 
33         }
34
35         // a description to be shown on the installed plugins listing
36         function getDescription() { 
37                 return 'Show all item title on each archive list. ';
38         }
39
40         function doAction($type) {
41                 
42                 $archiveMonth = intRequestVar('a');
43                 $bid = intRequestVar('b');
44                 $tid = intRequestVar('t');
45
46                 switch ($type) {
47                         case 'ga' :
48                                 echo '<ul>'.$this->getArchives($tid, $bid, $archiveMonth).'</ul>';
49                                 break;
50                         default :
51                                 return 'No such action';
52                                 break;
53                 }
54         }
55
56         function getArchives($tid, $bid, $archiveMonth){
57                 global $manager;
58                 $b =& $manager->getBlog($bid);
59                 
60                 list($year, $month) = sscanf($archiveMonth, "%4s%2s");
61
62                 $extraQuery = ' and SUBSTRING(itime,1,4)=' . $year
63                                         . ' and SUBSTRING(itime,6,2)=' . $month;
64                 
65                 $template = TEMPLATE::getNameFromId($tid);
66
67                 ob_start();
68                 $b->readLogAmount($template, 0, $extraQuery, 0, 1, 0);
69                 $contents =  ob_get_contents();
70                 ob_end_clean();
71
72                 if (_CHARSET != 'UTF-8'){
73                         $contents = mb_convert_encoding($contents, 'UTF-8', _CHARSET);
74                 }
75                 
76                 return $contents;
77         }
78
79
80         function doSkinVar($skinType, $template = 'default/index', $mode = 'month', $limit = 0) { 
81                 global $manager, $blog, $CONF, $catid, $itemid; 
82
83                 $params = func_get_args();
84                 if ($params[1]){ $template = $params[1]; }
85                 if ($params[2]){
86                         if ($params[2] == 'month' | $params[2] == 'day'){ $mode = $params[2]; }
87                         else{ $limit = intval($params[2]); }
88                 }
89                 if ($params[3]){ $limit = intval($params[3]); }
90
91         if ($blog) { 
92                 $b =& $blog; 
93         } else { 
94                 $b =& $manager->getBlog($CONF['DefaultBlog']); 
95         } 
96
97                 if ($catid) {
98                         $this->linkparams = array('catid' => $catid);
99                 }
100
101 //switch($skinType) { 
102 //      case 'archivelist': 
103
104                 $tid = TEMPLATE::getIdFromName($template);
105                 $template = TEMPLATE::read($template);
106                 $data['blogid'] = $b->getID();
107
108                 $jshref = $CONF['PluginURL'].'sharedlibs/miniajax.js';
109                 $href = htmlspecialchars($CONF['ActionURL'], ENT_QUOTES) . '?action=plugin&name=ArchiveListEX&type=ga&t='.$tid.'&b='.$b->getID().'&a=';
110
111
112 ?>
113 <script type="text/javascript" src="<?php echo $jshref; ?>"></script>
114 <script type="text/javascript"><!--
115 function getData(id){
116         ajax.update("<?php echo $href; ?>"+id, "result"+id);
117 }
118 // --></script>
119 <?php
120
121 //===================================
122                 $query = 'SELECT count(*) as sum, itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) as Day FROM '.sql_table('item')
123                 . ' WHERE iblog=' . $b->getID()
124                 . ' and itime <=' . mysqldate($b->getCorrectTime())     // don't show future items!
125                 . ' and idraft=0'; // don't show draft items
126                 
127                 if ($catid)
128                         $query .= ' and icat=' . intval($catid);
129 /**/            
130                 $query .= ' GROUP BY Year, Month';
131                 if ($mode == 'day')
132                         $query .= ', Day';
133                 
134                         
135 //              $query .= ' ORDER BY itime ASC';        
136                 $query .= ' ORDER BY itime DESC';       
137                 
138                 if ($limit > 0) 
139                         $query .= ' LIMIT ' . $limit;
140                 
141                 $res = sql_query($query);
142
143                 $oldYear = 0;
144                 while ($current = mysql_fetch_object($res)) {
145                         $current->itime = strtotime($current->itime);   // string time -> unix timestamp
146                         if ($mode == 'day') {
147                                 $archivedate = date('Y-m-d',$current->itime);
148                                 $archive['day'] = date('d',$current->itime);
149                         } else {
150                                 $archivedate = date('Y-m',$current->itime);                     
151                         }
152                         $data['month'] = date('m',$current->itime);
153                         $data['year'] = date('Y',$current->itime);
154                         $data['archivelink'] = createArchiveLink($b->getID(),$archivedate,$this->linkparams);
155                         $data['sum'] = $current->sum;
156                         $data['monthid'] = $current->Year.$current->Month;
157                         
158                         if($oldYear && $data['year'] != $oldYear){
159                                 $tempf = TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
160                                 echo $lastFooter = strftime($tempf,$current->itime);
161                         }
162
163                         if($data['year'] != $oldYear){
164                                 $temph = TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);
165                                 echo strftime($temph,$current->itime);
166                         }
167
168                         $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
169                         echo strftime($temp,$current->itime);
170
171                         $oldYear = $data['year'];
172
173                 }
174                 mysql_free_result($res);
175                 echo $lastFooter;
176
177 //              break;
178 //===================================
179 //      default: 
180 //                              echo "tttt";
181 //              } 
182         }
183 }
184 ?>