OSDN Git Service

1bc45e8bf6b42286ac1300d53eea828228b70c0f
[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://xx.nakahara21.net/'; 
19         }
20         
21         // version of the plugin
22         function getVersion() {
23                 return '0.6'; 
24         }
25         
26         // a description to be shown on the installed plugins listing
27         function getDescription() { 
28                 return 'Show all item title on each archive list. <br />[Required] template: name of the template to use <br />[Optional] mode: [month]shows an entry for each month , [day]shows an entry for each day  <br />[Optional] limit:  limits the amount of links shown (e.g. if you only want to show links to the past 3 months)<br /><br />Usage1: &lt;%ArchiveListEX(default)%&gt; or &lt;%ArchiveListEX(default,month)%&gt; instead of &lt;%archivelist(default)%&gt;,<br />Usage2:  &lt;%ArchiveListEX(default,day,5)%&gt; instead of &lt;%archivedaylist(default,5)%&gt;,<br />Usage3:  &lt;%ArchiveListEX(default,5)%&gt;';
29         }
30
31    function doSkinVar($skinType, $template = 'default', $mode = 'month', $limit = 0) { 
32                 global $manager, $blog, $CONF, $catid, $itemid; 
33
34                 $params = func_get_args();
35                 if ($params[1]){ $template = $params[1]; }
36                 if ($params[2]){
37                         if ($params[2] == 'month' | $params[2] == 'day'){ $mode = $params[2]; }
38                         else{ $limit = intval($params[2]); }
39                 }
40                 if ($params[3]){ $limit = intval($params[3]); }
41
42         if ($blog) { 
43                 $b =& $blog; 
44         } else { 
45                 $b =& $manager->getBlog($CONF['DefaultBlog']); 
46         } 
47         $blogid = $b->getID();
48
49                 if ($catid) {
50                         $this->linkparams = array('catid' => $catid);
51                 }
52
53 switch($skinType) { 
54         case 'archivelist': 
55
56 //**********************************************
57 if($_REQUEST['mode'] == "remarks"){
58
59                 $numberOfWritebacks   = 50; // defaults to 50
60
61                 // select
62         $query = "SELECT c.cnumber, c.cuser, c.cbody, c.citem, c.cmember, c.ctime ,UNIX_TIMESTAMP(c.ctime) as ctimest ,i.inumber, i.ititle 
63         FROM nucleus_comment c ,nucleus_item i 
64         WHERE c.citem = i.inumber 
65         ORDER by ctime DESC 
66         LIMIT 0,".$numberOfWritebacks;
67
68         $comments = mysql_query($query);
69 //             echo ' <ul class="nobullets"> ';
70
71         while($row = mysql_fetch_object($comments)) {
72              $cid  = $row->cnumber;
73              $ititle  = htmlspecialchars(strip_tags($row->ititle));
74              $ct  = $row->ctimest;
75              $ctst  = date("Y-m-d H:i",$ct);
76              $ctext  = $row->cbody;
77 //             $ctext  = strip_tags($text);
78 //             $ctext = substr($text, 0, $numberOfCharacters);
79 //             $ctext = mb_substr($ctext, 0, -1);
80
81              if (!$row->cmember) $myname = $row->cuser;
82              else {
83                    $mem = new MEMBER;
84                    $mem->readFromID(intval($row->cmember));
85                    $myname = $mem->getDisplayName();
86              }
87              $itemid= $row->citem;
88              $itemlink = createItemLink($row->citem, '');
89              $l_comments =  "<li class=itembody>¢£ <span class=\"iteminfo\"><a href=\"".$b->getURL().$itemlink."#c".$cid."\">¡Ø".$ititle."¡Ù ¤Ø¤Î¥³¥á¥ó¥È</a></span><br />".$ctext."<br /><span class=\"iteminfo\">".$myname." posted on $ctst</span></li>" ;
90 //             echo $l_comments;
91              
92                                 if(!$arr_res){$arr_res = array();}
93 //                              array_push($arr_res,array($ct => $l_comments));
94              $arr_res[$ct] = $l_comments;
95              
96          }
97
98
99 //=========================
100
101         $query = "SELECT t.title, t.excerpt, t.tb_id, t.blog_name, t.timestamp ,UNIX_TIMESTAMP(t.timestamp) as ttimest ,t.url ,i.inumber, i.ititle 
102         FROM nucleus_plugin_tb t ,nucleus_item i 
103         WHERE t.tb_id = i.inumber 
104         ORDER by timestamp DESC 
105         LIMIT 0,".$numberOfWritebacks;
106
107         $comments = mysql_query($query);
108
109         while($row = mysql_fetch_object($comments)) {
110              $text  = $row->excerpt;
111 //             $text  = strip_tags($text);
112 //             $ctext = mb_substr($text, 0, $numberOfCharacters);
113
114              $title = $row->title;
115 //             $ctitle = substr($title, 0, $numberOfTitleCharacters+1);
116 //             $ctitle = mb_substr($ctitle, 0, -1);
117
118              $blogname = $row->blog_name;
119              $tbtime = $row->ttimest;
120              $ititle  = htmlspecialchars(strip_tags($row->ititle));
121              $url = $row->url;
122              $ttst  = date("Y-m-d H:i",$tbtime);
123
124              $itemlink = createItemLink($row->tb_id, '');
125 //             echo "<li><a href=\"".$b->getURL().$itemlink."#trackback\">¢£".$tbtime.":";
126 //             echo $blogname."¤«¤é";
127 //             echo $ctitle.$ctext;
128 //             echo "....</a></li>";
129              
130              $l_tbs = "<li class=itembody>¢¡ <span class=\"iteminfo\"><a href=\"".$b->getURL().$itemlink."#trackback\">¡Ø".$ititle."¡Ù¤Ø¤Î¥È¥é¥Ã¥¯¥Ð¥Ã¥¯</a></span><br />## ".$title." ##<br />".$text."<br /><span class=\"iteminfo\">¡Ø<a href=\"$url\">{$blogname}</a>¡Ù pinged on ".$ttst."</span></li>";
131
132 //                              if(!$arr_res){$arr_res = array();}
133 //                              array_push($arr_res,$l_tbs);
134              $arr_res[$tbtime] = $l_tbs;
135
136
137
138          }
139 //=========================
140
141
142
143 krsort ($arr_res);
144 $output = array_slice ($arr_res, 0, $numberOfWritebacks);
145 //             print_r($output);
146
147                 echo '<h3>¥³¥á¥ó¥È¤È¥È¥é¥Ã¥¯¥Ð¥Ã¥¯ ºÇ¿·'.$numberOfWritebacks.'·ï</h3>';
148                 echo ' <ul class="nobullets"> ';
149
150                 foreach($output as $key => $value){
151                         echo $value."\n";
152                 }
153                 echo " </ul> ";
154
155 //**********************************************
156 }else{
157
158                 $template = TEMPLATE::read($template);
159                 $data['blogid'] = $blogid;
160 //===================================
161                 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);
162 //===================================
163                 echo '<a href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'">HOME</a> ';
164                 if($catid){
165                         $catName = $blog->getCategoryName($catid);      //¥«¥Æ¥´¥ê¤Î̾Á°¤òget
166 //                      $catName = $blog->getCategoryDesc($catid);      //¥«¥Æ¥´¥ê¤ÎÀâÌÀ¤òget
167                         $archivealllistlink = createArchiveListLink($blogid,"");
168                         echo ' > <a href="'.$archivealllistlink.'">Archive List</a>';
169                         echo ' > Category : <u> '.$catName.' </u> ';
170                 }else{
171 //                      echo 'Category : ÁªÂò¤·¤Æ¤¤¤Þ¤»¤ó';
172                         echo ' > Archive List';
173                         echo '';
174                 }
175 //===================================
176                 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
177 //===================================
178                 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);
179                 $now = time();
180                 $query = 'SELECT UNIX_TIMESTAMP(itime) as itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) as Day FROM nucleus_item'
181                 . ' WHERE iblog=' . $blogid
182                 . ' and UNIX_TIMESTAMP(itime)<=' . $now // don't show future items!
183                 . ' and idraft=0'; // don't show draft items
184                 
185                 if ($catid)
186                         $query .= ' and icat=' . intval($catid);
187                 
188                 $query .= ' GROUP BY Year, Month';
189                 if ($mode == 'day')
190                         $query .= ', Day';
191                 
192                         
193 //              $query .= ' ORDER BY itime ASC';        //¥¢¡¼¥«¥¤¥Ö¥ê¥¹¥È¾º½ç
194                 $query .= ' ORDER BY itime DESC';       //¥¢¡¼¥«¥¤¥Ö¥ê¥¹¥È¹ß½ç
195                 
196                 if ($limit > 0) 
197                         $query .= ' LIMIT ' . $limit;
198                 
199                 $res = sql_query($query);
200
201                 while ($current = mysql_fetch_object($res)) {
202                         if ($mode == 'day') {
203                                 $archivedate = date('Y-m-d',$current->itime);
204                                 $archive['day'] = date('d',$current->itime);
205                         } else {
206                                 $archivedate = date('Y-m',$current->itime);                     
207                         }
208                         $data['month'] = date('m',$current->itime);
209                         $data['year'] = date('Y',$current->itime);
210                         $data['archivelink'] = createArchiveLink($blogid,$archivedate,$this->linkparams);
211
212                         $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
213                         echo strftime($temp,$current->itime);
214                         
215         //======================================================                
216         echo '<ul>';
217                 $adquery = 'SELECT inumber, ititle, icat FROM nucleus_item'
218                 . ' WHERE iblog=' . $blogid
219                 . ' and UNIX_TIMESTAMP(itime)<=' . $now // don't show future items!
220                 . ' and idraft=0' // don't show draft items
221                 . ' and SUBSTRING(itime,1,4)=' . $data['year']  // year
222                 . ' and SUBSTRING(itime,6,2)=' . $data['month'];        // month
223                 if ($mode == 'day')
224                         $adquery .= ' and SUBSTRING(itime,9,2)=' . $archive['day']; //day
225                 
226                 if ($catid)
227                         $adquery .= ' and icat=' . intval($catid);
228                 
229 //              $adquery .= ' ORDER BY itime ASC';      //¥¿¥¤¥È¥ë°ìÍ÷¾º½ç
230                 $adquery .= ' ORDER BY itime DESC';     //¥¿¥¤¥È¥ë°ìÍ÷¹ß½ç
231                 
232 //              if ($limit > 0) 
233 //                      $adquery .= ' LIMIT ' . $limit;
234                 
235                 $adres = sql_query($adquery);
236                 
237                 while ($adcurrent = mysql_fetch_object($adres)) {
238                         $ititle = htmlspecialchars(strip_tags($adcurrent->ititle));
239                         $inumber = $adcurrent->inumber;
240                         $itemlink = createItemLink($inumber,$this->linkparams);
241
242                         if($catid){
243                         echo '<li><a href="'.$itemlink.'">'. $ititle . '</a></li>'."\n";
244                         }else{
245                         $icatName = $blog->getCategoryName($adcurrent->icat);   //¥«¥Æ¥´¥ê¤Î̾Á°¤òget
246 //                      $icatName = $blog->getCategoryDesc($adcurrent->icat);   //¥«¥Æ¥´¥ê¤ÎÀâÌÀ¤òget
247                         //¥¿¥¤¥È¥ë°ìÍ÷¤Ë³¤¤¤Æ¥«¥Æ¥´¥ê̾¤òɽ¼¨
248 //                      echo '<li><a href="'.$itemlink.'">'. $ititle . ' <small>::' . $icatName .'</small></a></li>'."\n";
249                         //¥¿¥¤¥È¥ë°ìÍ÷¤Ë¥Þ¥¦¥¹¤ò¤¢¤ï¤»¤ë¤È¥«¥Æ¥´¥ê̾¤ò¥Õ¥í¡¼¥Èɽ¼¨
250                         echo '<li><a href="'.$itemlink.'" title="Category:'.$icatName.'">'. $ititle . '</a></li>'."\n";
251                         }
252                 }
253                 mysql_free_result($adres);
254         echo '</ul>';
255         //======================================================
256                 }
257                 mysql_free_result($res);
258                 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
259
260 }
261
262                 break;
263 //===================================
264         default: 
265 //                              echo "tttt";
266                 } 
267         }
268 }
269 ?>