3 NP_ArchiveIndex by yu(http://nucleus.datoka.jp/)
4 Based on NP_ArchiveListEX ver0.6 by nakahara21(http://xx.nakahara21.net/)
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 (see nucleus/documentation/index.html#license for more info)
15 <%ArchiveIndex(5)%> //set item amount of each category on archive index
16 <%ArchiveIndex(5,10,desc)%> //set page amount, show category description
17 <%ArchiveIndex(5,10,none)%> //set page amount, don't show category description
22 [FIX] small fixes on 'Template: List (begin)' and 'Template: List element'.
24 [ADD] Works with NP_UpdateTime and NP_ContentsList.
28 // plugin needs to work on Nucleus versions <=2.0 as well
29 if (!function_exists('sql_table')){
30 function sql_table($name) {
31 return 'nucleus_' . $name;
35 class NP_ArchiveIndex extends NucleusPlugin {
37 function getName() { return 'Archive Index'; }
38 function getAuthor() { return 'nakahara21 + yu'; }
39 function getURL() { return 'http://works.datoka.jp/index.php?itemid=167'; }
40 function getVersion() { return '0.81'; }
41 function getMinNucleusVersion() { return 220; }
42 function supportsFeature($what) {
44 case 'SqlTablePrefix':
51 // a description to be shown on the installed plugins listing
52 function getDescription() {
53 return "Show all item title on archive list. [Optional] amount: limit the amount of links shown (e.g. if you only want to show 5 links on each list by category index). page amount: the amount of links in a page. show_catdesc: show category description. 'desc' or 'none'. Usage: <%ArchiveIndex%>, <%ArchiveIndex(5)%>, <%ArchiveIndex(5,10)%>, <%ArchiveIndex(5,10,desc)%>";
59 $this->createOption('itemOrder', 'Order of title (index)', 'select', 'time,DESC', 'title,DESC|title,DESC|title,ASC|title,ASC|time,DESC|time,DESC|time,ASC|time,ASC');
60 $this->createOption('itemOrder2', 'Order of title (when a category is selected)', 'select', 'time,DESC', 'title,DESC|title,DESC|title,ASC|title,ASC|time,DESC|time,DESC|time,ASC|time,ASC');
61 $this->createOption('catDesc','Show category description.','yesno','yes');
62 $this->createOption('flg_showupd','Show update information (NP_UpdateTime).','yesno','no');
63 $this->createOption('flg_sortupd','Sort with update information (NP_UpdateTime).','yesno','no');
64 $this->createOption('idateFormat','Date format for item list','text','Y-m-d H:i');
66 $this->createOption('tempListBegin','Template: List (begin)','text','<table><thead title="%catdesc%"><tr><th colspan="2"><a href="%caturl%">%catname%</a></th></tr></thead><tbody>');
67 $this->createOption('tempListElement','Template: List element','text','<tr%bg%><td><span class="title%up%">%titlelink%</span></td><td class="detail">%detail%</td></tr>');
68 $this->createOption('tempListMore','Template: List element (morelink)','text','<tr class="more"><td>%pagenavi%</td><td class="detail">%morelink%</td></tr>');
69 $this->createOption('tempListEnd','Template: List (end)','text','</tbody></table>');
72 $this->createBlogOption('switch','Use blog option?','yesno','no');
73 $this->createBlogOption('itemOrder', 'Order of title (index)', 'select', 'time,DESC', 'title,DESC|title,DESC|title,ASC|title,ASC|time,DESC|time,DESC|time,ASC|time,ASC');
74 $this->createBlogOption('itemOrder2', 'Order of title (when a category is selected)', 'select', 'time,DESC', 'title,DESC|title,DESC|title,ASC|title,ASC|time,DESC|time,DESC|time,ASC|time,ASC');
75 $this->createBlogOption('catDesc','Show category description.','yesno','yes');
76 $this->createBlogOption('flg_showupd','Show update information (NP_UpdateTime).','yesno','no');
77 $this->createBlogOption('flg_sortupd','Sort with update information (NP_UpdateTime).','yesno','no');
78 $this->createBlogOption('idateFormat','Date format for item list','text','Y-m-d H:i');
80 $this->createBlogOption('tempListBegin','Template: List (begin)','text','<table><thead title="%catdesc%"><th><a href="%caturl%">%catname%</a></th><th></th></thead><tbody>');
81 $this->createBlogOption('tempListElement','Template: List element','text','<tr %bg%><td><span class="title%up%">%titlelink%</span></td><td class="detail">%detail%</td></tr>');
82 $this->createBlogOption('tempListMore','Template: List element (morelink)','text','<tr class="more"><td>%pagenavi%</td><td class="detail">%morelink%</td></tr>');
83 $this->createBlogOption('tempListEnd','Template: List (end)','text','</tbody></table>');
86 function unInstall() {
90 function doSkinVar($skinType, $amount, $pamount=10, $show_catdesc='') {
91 global $manager, $member, $blog, $CONF, $catid, $itemid;
93 if ($blog) $b =& $blog;
94 else $b =& $manager->getBlog($CONF['DefaultBlog']);
98 $op_itemOrder = $this->getOption('itemOrder');
99 $op_itemOrder2 = $this->getOption('itemOrder2');
100 $op_catDesc = $this->getOption('catDesc');
101 $op_flg_showupd = $this->getOption('flg_showupd');
102 $op_flg_sortupd = $this->getOption('flg_sortupd');
103 $op_idateFormat = $this->getOption('idateFormat');
104 $op_tempListBegin = $this->getOption('tempListBegin');
105 $op_tempListElement = $this->getOption('tempListElement');
106 $op_tempListMore = $this->getOption('tempListMore');
107 $op_tempListEnd = $this->getOption('tempListEnd');
110 if ($this->getBlogOption($bid, 'switch') == 'yes') {
111 $op_itemOrder = $this->getBlogOption($bid, 'itemOrder');
112 $op_itemOrder2 = $this->getBlogOption($bid, 'itemOrder2');
113 $op_catDesc = $this->getBlogOption($bid, 'catDesc');
114 $op_flg_showupd = $this->getBlogOption($bid, 'flg_showupd');
115 $op_flg_sortupd = $this->getBlogOption($bid, 'flg_sortupd');
116 $op_idateFormat = $this->getBlogOption($bid, 'idateFormat');
117 $op_tempListBegin = $this->getBlogOption($bid, 'tempListBegin');
118 $op_tempListElement = $this->getBlogOption($bid, 'tempListElement');
119 $op_tempListMore = $this->getBlogOption($bid, 'tempListMore');
120 $op_tempListEnd = $this->getBlogOption($bid, 'tempListEnd');
123 if (!is_numeric($amount)) $amount = 5;
124 if (!is_numeric($pamount)) $pamount = 10;
126 if ($show_catdesc == '') {
127 if ($op_catDesc == 'yes') $show_catdesc = 'desc';
128 else $show_catdesc = 'none';
134 $b =& $manager->getBlog($CONF['DefaultBlog']);
136 $blogid = $b->getID();
139 $this->linkparams = array('catid' => $catid);
142 //get value from request
143 $page = intRequestVar('ap');
145 $item_order = requestVar('ao');
146 //check value (also used to make flip link)
147 list($itarget, $iorder) = @split(' ',$item_order);
148 if(!($itarget=='time' or $itarget=='title' or $iorder =='desc' or $iorder =='asc')) {
149 $item_order = $op_itemOrder2;
150 list($itarget, $iorder) = @split(',',$item_order);
154 $item_order = $op_itemOrder;
155 list($itarget, $iorder) = @split(',',$item_order);
157 $iorder = strtolower($iorder);
160 $idateformat = $op_idateFormat;
161 $archivedate = date('Y-m');
164 if ($manager->pluginInstalled('NP_UpdateTime')) {
165 $flg_showupdate = ($op_flg_showupd == 'yes');
166 $flg_sortupdate = ($op_flg_sortupd == 'yes');
168 if ($flg_showupdate or $flg_sortupdate) {
170 $query = 'SELECT r.up_id as itemid, UNIX_TIMESTAMP(r.updatetime) as utime, i.itime as itime FROM '.sql_table('plugin_rectime') . ' as r, '.sql_table('item') .' as i WHERE r.up_id=i.inumber and r.updatetime>i.itime'
171 . ' ORDER BY itemid ASC';
172 $ut_res = sql_query($query);
173 while ($utinfo = mysql_fetch_object($ut_res)) {
175 $catid != $this->_getCategoryIDFromItemID($utinfo->itemid)) continue;
176 $up_ids[] = $utinfo->itemid;
177 $up_tstamps[] = $utinfo->utime;
178 if ($flg_sortupdate) $up_datetimes[$utinfo->itemid] = $utinfo->itime; // for title prop.
179 else $up_datetimes[$utinfo->itemid] = date($idateformat, $utinfo->utime);
181 mysql_free_result($ut_res);
184 if ($flg_sortupdate and count($up_ids)) {
185 $str_up_ids = join(',', $up_ids);
186 $str_up_tstamps = join(',', $up_tstamps);
189 $query = 'SELECT inumber, ititle, icat, IF(inumber IN('.$str_up_ids.'), ELT(INTERVAL(inumber,'.$str_up_ids.'), '.$str_up_tstamps.'), UNIX_TIMESTAMP(itime)) as itime, iauthor FROM '.sql_table('item');
192 $query = 'SELECT inumber, ititle, icat, UNIX_TIMESTAMP(itime) as itime, iauthor FROM '.sql_table('item');
195 $query .= ' WHERE iblog=' . $blogid
196 .' and UNIX_TIMESTAMP(itime)<='. $now .' and idraft=0';
199 $query .= ' and icat=' . intval($catid);
201 //item count in the category
202 $resnum = sql_query($query);
203 $itemnum = mysql_num_rows($resnum);
204 mysql_free_result($resnum);
205 $pagemax = ceil($itemnum / $pamount);
208 if ($itarget == 'title') $query .= ' ORDER BY ititle';
209 else $query .= ' ORDER BY itime';
210 if ($iorder == 'asc') $query .= ' ASC';
211 else $query .= ' DESC';
214 if ($page < 1) $page = 1;
215 $poffset = ($page-1) * $pamount;
216 $query .= " LIMIT $poffset,$pamount";
218 $res = sql_query($query);
220 //set data by category
222 $list_item = array();
224 while ($current = mysql_fetch_object($res)) {
225 $cnt_item[$current->icat]++;
226 if (!$catid and $cnt_item[$current->icat] > $amount) { //check the amount
230 $inumber = $current->inumber; //itemid
231 $idetail = date($idateformat, $current->itime); //itemdate
233 $list_cat[$current->icat][] = $inumber;
234 $list_item[$inumber]['ititle'] = htmlspecialchars(strip_tags($current->ititle));
235 $list_item[$inumber]['itemlink'] = createItemLink($inumber,$this->linkparams);
236 $list_item[$inumber]['idetail'] = $idetail;
238 mysql_free_result($res);
240 //prepare list by category
242 foreach ($list_cat as $icat => $arr_icat) {
243 // buffer category name
244 $icatName = $b->getCategoryName($icat);
245 if (!$catid) $icatDesc = $b->getCategoryDesc($icat);
246 else $icatDesc = '» Back to index';
248 if (!$catid) $extra = array('catid' => $icat);
249 else $extra = array();
250 $arclist_link = createArchiveListLink($blogid, $extra);
252 $temp_list_b = $op_tempListBegin;
253 $rep_from = array('/%caturl%/','/%catname%/','/%catdesc%/');
254 $rep_to = array($arclist_link, $icatName, $icatDesc);
255 $temp_list_b = preg_replace($rep_from, $rep_to, $temp_list_b);
256 $temp_list_e = $op_tempListEnd;
259 $arr_title = array();
260 foreach ($arr_icat as $inumber) {
262 $ititle = $list_item[$inumber]['ititle'];
263 if (empty($ititle)) $ititle = '(no title)';
264 $itemlink = $list_item[$inumber]['itemlink'];
265 $idetail = $list_item[$inumber]['idetail'];
270 if ($icnt % 2 == 1) $bg = " class='stripe'";
271 if (count($up_ids) and in_array($inumber, $up_ids)) {
272 if($flg_showupdate) $upstr = '-up ';
273 if($flg_sortupdate) $titledesc = " title='Posted on ". $up_datetimes[$inumber] ."'";
274 else $titledesc = " title='Updated on ". $up_datetimes[$inumber] ."'";
276 $titlelink = "<a href='$itemlink' $titledesc>$ititle</a>";
278 $temp_list_el = $op_tempListElement;
279 $rep_from = array('/%bg%/','/%titlelink%/','/%detail%/','/%up%/');
280 $rep_to = array($bg, $titlelink, $idetail, $upstr);
281 $temp_list_el = preg_replace($rep_from, $rep_to, $temp_list_el);
282 $arr_title[] = $temp_list_el."\n";
285 if (!$catid and $icnt >= $amount) break;
288 // last list (navigation)
290 if ($cnt_item[$icat] <= $amount) { // category description
291 $arclist_link = '<span class="nomore">» More</span>';
292 if ($show_catdesc == 'desc') $icatDescStr = '<span class="catdesc">'.$icatDesc.'</span>';
293 else $icatDescStr = '';
295 $temp_list_more = $op_tempListMore;
296 $rep_from = array('/%pagenavi%/','/%morelink%/');
297 $rep_to = array($icatDescStr, $arclist_link);
298 $temp_list_more = preg_replace($rep_from, $rep_to, $temp_list_more);
299 $arr_title[] = "$temp_list_more\n";
301 else { // category description with more link
302 $extra = array('catid' => $icat);
303 $arclist_link = '<a href="'. createArchiveListLink($blogid, $extra) .'">» More</a>';
304 if ($show_catdesc == 'desc') $icatDescStr = '<span class="catdesc">'.$icatDesc.'</span>';
305 else $icatDescStr = '';
307 $temp_list_more = $op_tempListMore;
308 $rep_from = array('/%pagenavi%/','/%morelink%/');
309 $rep_to = array($icatDescStr, $arclist_link);
310 $temp_list_more = preg_replace($rep_from, $rep_to, $temp_list_more);
311 $arr_title[] = "$temp_list_more\n";
314 else { // sort order, page navi and all category link
315 //make 'order switch'
316 $itarget_flip = ($itarget=='title') ? 'time' : 'title'; //mode change
317 $iorder_flip = ($iorder =='desc') ? 'asc' : 'desc'; //order change
318 $itarget_flip_order = ($itarget_flip =='title') ? 'asc' : 'desc'; //ini-order on mode change
320 if ($itarget == 'title') {
321 $iorder_str = ($iorder == 'desc') ? 'Z-A' : 'A-Z';
322 $iorder_flip_str = ($iorder == 'desc') ? 'A-Z' : 'Z-A';
325 $iorder_str = ($iorder == 'desc') ? 'New' : 'Old';
326 $iorder_flip_str = ($iorder == 'desc') ? 'Old' : 'New';
329 $orderURL = serverVar('REQUEST_URI');
330 $orderURL = preg_replace('/[?&]ap=[0-9]*/','',$orderURL); //delete to add 'ap' param to last
331 $orderURL = preg_replace('/[?&]ao=[^&0-9]*/','',$orderURL);
333 if (strpos($orderURL,'?')===false) $orderURL .= "?ao=";
334 else $orderURL .= "&ao=";
336 $orderURL1 = $orderURL . "$itarget_flip+$itarget_flip_order";
337 $orderURL2 = $orderURL . "$itarget+$iorder_flip";
338 $pagenavi = "Sort: <strong>$itarget</strong>/<a href='$orderURL1'>$itarget_flip</a>, ";
339 $pagenavi.= "<strong>$iorder_str</strong>/<a href='$orderURL2'>$iorder_flip_str</a>";
341 //make 'page navi link'
342 $pagenavi.= " Page:";
343 for ($i=1; $i<=$pagemax; $i++) {
344 if ($i==$page) $pagenavi.= "<strong> $i </strong>";
346 $pageURL = serverVar('REQUEST_URI');
347 $pageURL = preg_replace('/([?&]ap=)[0-9]*/','',$pageURL);
348 if (strpos($pageURL,'?')===false) $pageURL .= "?ap=$i";
349 else $pageURL .= "&ap=$i";
350 $pagenavi.= "<a href='$pageURL'> $i </a>";
353 //and make 'all category link'
354 $arclist_link = '<a href="'. createArchiveListLink($blogid) .'">» Back to index</a>';
356 $temp_list_more = $op_tempListMore;
357 $rep_from = array('/%pagenavi%/','/%morelink%/');
358 $rep_to = array($pagenavi, $arclist_link);
359 $temp_list_more = preg_replace($rep_from, $rep_to, $temp_list_more);
360 $arr_title[] = "$temp_list_more\n";
363 $arr_out[$icatName] .=
364 $temp_list_b ."\n". join('',$arr_title) . $temp_list_e ."\n";
368 if ($manager->pluginInstalled('NP_ContentsList')) {
369 $plugin =& $manager->getPlugin('NP_ContentsList');
371 $query = 'SELECT rid as catid FROM '. sql_table('plug_contentslist_rank') .' WHERE blog=0 AND rank<20 ORDER BY rank ASC'; // you can delete 'AND rank<20'
372 $cl_res = sql_query($query);
374 $arr_out2 = $arr_out;
376 while ($clrank = mysql_fetch_object($cl_res)) {
377 $icatName = $b->getCategoryName($clrank->catid);
378 $arr_out[] = $arr_out2[$icatName];
388 foreach ($arr_out as $value) {
392 } //end of function doSkinVar
396 function _getCategoryIDFromItemID($itemid) {
397 return quickQuery('SELECT icat as result FROM '.sql_table('item').' WHERE inumber='.intval($itemid));