4 * BreadCrumbsList PLUG-IN FOR NucleusCMS
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * (see nucleus/documentation/index.html#license for more info)
13 * @author Original Author nakahara21
14 * @copyright 2005-2006 nakahara21
15 * @license http://www.gnu.org/licenses/gpl.txt GNU GENERAL PUBLIC LICENSE Version 2, June 1991
17 * @link http://japan.nucleuscms.org/wiki/plugins:itemnaviex
19 * 0.993 Henceforth to template
20 * 0.992 display mode '0' fix
21 * 0.991 add sub-blog home mode
24 **************************************************************************
26 * THESE PLUG-INS ARE DEDICATED TO ALL THOSE NucleusCMS USERS
27 * WHO FIGHT CORRUPTION AND IRRATIONAL IN EVERY DAY OF THEIR LIVES.
29 **************************************************************************/
31 class NP_ItemNaviEX extends NucleusPlugin
35 return 'Navigation Bar';
40 return 'nakahara21 + shizuki';
45 return 'http://japan.nucleuscms.org/wiki/plugins:itemnaviex';
53 function getDescription()
55 // include language file for this plugin
56 $language = ereg_replace( '[\\|/]', '', getLanguageName());
57 if (file_exists($this->getDirectory() . $language . '.php')) {
58 include_once($this->getDirectory() . $language . '.php');
60 include_once($this->getDirectory() . 'english.php');
62 $description = _NP_INEX_DESC;
63 // $description = 'Add link to prev item and next item. '
64 // . 'Usage: <%ItemNaviEX%> or <%ItemNaviEX(0)%>'
65 // . ' or <%ItemNaviEX(1)%> or <%ItemNaviEX(2)%>';
69 function supportsFeature($what)
72 case 'SqlTablePrefix':
79 function scanEndKey($array)
81 $keys = array_keys($array);
86 function createNaviLink($unitArray)
89 $tempLink = '<a href="' . htmlspecialchars($unitArray[1], ENT_QUOTES, _CHARSET) . '">'
90 . htmlspecialchars($unitArray[0], ENT_QUOTES, _CHARSET) . '</a>';
92 $tempLink = htmlspecialchars($unitArray[0], ENT_QUOTES, _CHARSET);
97 function checkParent()
100 // if ($manager->pluginInstalled('NP_MultipleCategories')) {
101 // $mplugin =& $manager->getPlugin('NP_MultipleCategories');
102 // if (method_exists($mplugin,"getRequestName")) {
103 $query = 'SHOW FIELDS FROM ' . sql_table('plug_multiple_categories_sub');
104 $res = sql_query($query);
105 while ($co = mysql_fetch_assoc($res)) {
106 if ($co['Field'] == 'parentid') {
114 function doSkinVar($skinType, $showHome = 1)
116 global $manager, $CONF, $blog, $itemid, $itemidprev, $itemidnext;
117 global $catid, $subcatid, $archive, $archiveprev, $archivenext, $param;
121 $itemid = intval($itemid);
122 $catid = intval($catid);
123 $subcatid = intval($subcatid);
124 $itemidprev = intval($itemidprev);
125 $itemidnext = intval($itemidnext);
126 if (isset($archive)) {
127 sscanf($archive,'%d-%d-%d', $y, $m, $d);
128 if ($y && $m && !empty($d)) {
129 $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
130 } elseif ($y && $m && empty($d)) {
131 $archive = sprintf('%04d-%02d', $y, $m);
134 if (isset($archiveprev)) {
135 sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
136 if ($y && $m && !empty($d)) {
137 $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
138 } elseif ($y && $m && empty($d)) {
139 $archiveprev = sprintf('%04d-%02d', $y, $m);
142 if (isset($archiveprev)) {
143 sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
144 if ($y && $m && !empty($d)) {
145 $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
146 } elseif ($y && $m && empty($d)) {
147 $archiveprev = sprintf('%04d-%02d', $y, $m);
150 if ($showHome == '') {
153 $showHome = intval($showHome);
157 $blogid = getBlogIDFromCatID($catid);
158 $b =& $manager->getBlog($blogid);
162 $b =& $manager->getBlog($CONF['DefaultBlog']);
164 $blogid = intval($b->getID());
168 $where .= ' and i.iblog=' . $blogid;
169 if (!empty($catid)) {
170 if ($manager->pluginInstalled('NP_MultipleCategories')) {
171 $where .= ' and ((i.inumber = p.item_id'
172 . ' and (p.categories REGEXP "(^|,)' . $catid . '(,|$)"'
173 . ' or i.icat = ' . $catid . '))'
174 . ' or (i.icat = ' . $catid
175 . ' and p.item_id IS NULL))';
176 $mtable = ' LEFT JOIN ' . sql_table('plug_multiple_categories') . ' as p'
177 . ' ON i.inumber = p.item_id';
178 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
179 if ($subcatid && method_exists($mplugin, 'getRequestName')) {
181 if ($this->checkParent()) {
183 $Children = explode('/', $subcatid . $this->getChildren($subcatid));
186 for ($i=0;$i<count($Children);$i++) {
187 $temp_whr[] = ' p.subcategories REGEXP "(^|,)' . intval($Children[$i]) . '(,|$)" ';
191 $where .= join(' or ', $temp_whr);
194 $where .= ' and p.subcategories REGEXP "(^|,)' . $subcatid . '(,|$)"';
199 $where .= ' and i.icat=' . $catid;
203 $subNaviUnit = array();
204 $this->linkparams = array();
205 $nextLabel = $this->getOption('PNNextLabel');
206 $prevLabel = $this->getOption('PNPrevLabel');
207 //store Home =====================================
208 //*// comment out this block when HOME is sub-blog top
209 if ($showHome == 1) {
210 // $defBlogid =intval($CONF['DefaultBlog']);
211 $tempBlog =& $manager->getBlog(intval($CONF['DefaultBlog']));
214 // 1 => createBlogidLink($defBlogid),
215 1 => $tempBlog->getURL(),
216 2 => createArchiveListLink($blogid)
220 //store Blog =====================================
221 if ($showHome == 1 && ($blogid <> $CONF['DefaultBlog'])) {
223 0 => getBlogNameFromID($blogid),
224 1 => createBlogidLink($blogid),
225 2 => createArchiveListLink($blogid)
227 } elseif ($showHome >= 2 || ($showHome == 0 && ($catid || $itemid))) {
229 0 => 'Home', // when HOME is sub-blog top
230 1 => createBlogidLink($blogid), // when HOME is sub-blog top
231 2 => createArchiveListLink($blogid)
235 //store Category =====================================
236 if (!empty($catid)) {
237 $this->linkparams['catid'] = $catid;
239 0 => $b->getCategoryName($catid),
240 1 => createCategoryLink($catid),
241 // 1 => createBlogidLink($blogid, $this->linkparams),
242 2 => createArchiveListLink($blogid, $this->linkparams)
246 //store subCategory =====================================
247 if (!empty($subcatid)) {
248 if ($manager->pluginInstalled('NP_MultipleCategories')) {
249 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
250 if (method_exists($mplugin, 'getRequestName')) {
251 $subrequest = $mplugin->getRequestName(array());
252 $this->linkparams[$subrequest] = $subcatid;
253 if ($this->checkParent()) {
254 $tog = $this->getParenta($subcatid, $blogid);
255 for ($i=0; $i<count($this->r); $i++) {
256 $naviUnit[] = $this->r[$i];
261 0 => $mplugin->_getScatNameFromID($subcatid),
262 1 => createCategoryLink($catid, array($subrequest => $subcatid)),
263 // 1 => createCategoryLink($catid, array('subcatid' => $subcatid)),
264 // 1 => createBlogidLink($blogid, $this->linkparams),
265 2 => createArchiveListLink($blogid, $this->linkparams)
272 //store Page ===================================== todo How to get PageNo. ? ...cookie...
273 if (intRequestVar('page') != 0) {
275 0 => 'Page.' . intRequestVar('page'),
276 2 => createArchiveListLink($blogid, $this->linkparams)
280 //store Item =====================================
281 if ($skinType == 'item') {
282 $item =& $manager->getItem($itemid, 0, 0);
287 $query = 'SELECT i.ititle, i.inumber'
288 . ' FROM ' . sql_table('item') . ' as i' . $mtable
289 . ' WHERE i.idraft = 0'
290 . " and i.itime < '" . $item['itime'] . "' " . $where
291 . ' ORDER BY i.itime DESC';
292 $res = sql_query($query);
293 if ($ares = mysql_fetch_row($res)) {
294 $alink = createItemLink($ares[1], $this->linkparams);
295 $subNaviUnit[1] = '<a href="'
296 . htmlspecialchars($alink, ENT_QUOTES, _CHARSET)
297 . '" rel="prev"> ' . $prevLabel . ' '
298 . shorten($ares[0], 14, '...')
302 $query = 'SELECT i.ititle, i.inumber'
303 . ' FROM ' . sql_table('item') . ' as i' . $mtable
304 . ' WHERE i.idraft = 0'
305 . " and i.itime > '" . $item['itime'] . "' " . $where
306 . ' ORDER BY i.itime ASC';
307 $res = sql_query($query);
308 if ($ares = mysql_fetch_row($res)) {
309 $alink = createItemLink($ares[1], $this->linkparams);
310 $subNaviUnit[2] = '<a href="'
311 . htmlspecialchars($alink, ENT_QUOTES, _CHARSET)
313 . shorten($ares[0], 14, '...')
314 . ' ' . $nextLabel . '</a>';
319 //store ArchiveList =====================================
320 if ($skinType == 'archivelist' || $skinType == 'archive') {
322 0 => $this->getOption('archivelinkLabel'),
323 // 0 => 'ArchiveList',
324 1 => createArchiveListLink($blogid, $this->linkparams)
328 if ($skinType == 'archive') {
329 sscanf($archive,'%d-%d-%d', $y, $m, $d);
331 $archiveMonth = $y . '-' . $m;
334 1 => createArchiveLink($blogid, $archiveMonth, $this->linkparams)
337 $timestamp_start = mktime(0, 0, 0, $m, 1, $y);
338 $timestamp_end = mktime(0, 0, 0, $m+1, 1, $y);
339 $date_str = 'SUBSTRING(i.itime, 1, 7)';
341 $timestamp_start = mktime(0, 0, 0, $m, $d, $y);
342 $timestamp_end = mktime(0, 0, 0, $m, $d+1, $y);
343 $date_str = 'SUBSTRING(i.itime, 1, 10)';
346 0 => $y . '-' . $m . '-' . $d,
347 1 => createArchiveLink($blogid, $archive, $this->linkparams)
351 //=============================
352 $query = 'SELECT ' . $date_str . ' as Date'
353 . ' FROM ' . sql_table('item') . ' as i' . $mtable
354 . ' WHERE i.idraft = 0'
355 . ' and i.itime < ' . mysqldate($timestamp_start) . $where
357 . ' ORDER BY i.itime DESC';
358 $res = sql_query($query);
359 if ($ares = mysql_fetch_row($res)) {
360 // $prev_date = $ares[0];
361 sscanf($ares[0], '%d-%d-%d', $y, $m, $d);
363 $prev_date = sprintf('%04d-%02d', $y, $m);
365 $prev_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
367 $prev_alink = createArchiveLink($blogid, $prev_date, $this->linkparams);
368 $subNaviUnit[1] = '<a href="'
369 . htmlspecialchars($prev_alink, ENT_QUOTES, _CHARSET)
370 . '" class="prevlink" rel="prev">'
371 . ' ' . $prevLabel . ' '
372 . htmlspecialchars($prev_date, ENT_QUOTES, _CHARSET)
374 // $abuf .= '<a href="'.$prev_alink.'" class="prevlink" rel="prev">'.$prev_date.'</a>';
376 // $today_link = createBlogidLink($b->getID(), $this->linkparams);
377 // $abuf .= ' ( <a href="'.$today_link.'">Today</a> )';
379 $abuf .= ' | <strong>' . htmlspecialchars($archive, ENT_QUOTES, _CHARSET) . '</strong> ';
380 //=============================
381 $query = 'SELECT ' . $date_str . ' as Date'
382 . ' FROM ' . sql_table('item') . ' as i' . $mtable
383 . ' WHERE i.idraft = 0'
384 . ' and i.itime < ' . mysqldate($b->getCorrectTime())
385 . ' and i.itime >= ' . mysqldate($timestamp_end) . $where
387 . ' ORDER BY i.itime ASC';
388 $res = sql_query($query);
389 if ($ares = mysql_fetch_row($res)) {
390 // $next_date = $ares[0];
391 sscanf($ares[0],'%d-%d-%d', $y, $m, $d);
393 $next_date = sprintf('%04d-%02d', $y, $m);
395 $next_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
397 $next_alink = createArchiveLink($blogid, $next_date, $this->linkparams);
398 $subNaviUnit[2] = '<a href="'
399 . htmlspecialchars($next_alink, ENT_QUOTES, _CHARSET)
400 . '" class="nextlink" rel="next">'
401 . htmlspecialchars($next_date, ENT_QUOTES, _CHARSET)
402 . ' ' . $nextLabel . '</a>';
403 // $a2buf = ' | <a href="'.$next_alink.'" class="nextlink" rel="next">'.$next_date.'</a>';
405 // $today_link = createBlogidLink($b->getID(), $this->linkparams);
406 // $a2buf .= ' | ( <a href="'.$today_link.'">Today</a> )';
409 //============================= // end of archive(s)
412 // todo Henceforth to template
413 // echo ' <div style="text-align: center;">';
414 // echo ' <span style="text-align:right;">';
415 // echo ' <span class="prevnextnavi">';
416 $endKey = $this->scanEndKey($naviUnit);
417 // if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
418 // echo '<a href="' . $naviUnit[$endKey][2] . '">» ArchiveList</a>';
420 // echo @join(' :: ', $subNaviUnit);
426 <%subnavi%> --> prev. and next link
427 <%archivedata%> --> ArchiveList link
430 $subNaviData['subnavi'] = implode($this->getOption('PNSeparator'), $subNaviUnit);
431 if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
432 if (!empty($naviUnit)) {
433 $subNaviData['archivedata'] .= '<a href="'
434 . $naviUnit[$endKey][2]
435 . '">' . $this->getOption('archivelinkLabel') . '</a>';
438 $subnaviTemplate = $this->getOption('subnaviTemplate');
439 $navigateData['subnaviblock'] = TEMPLATE::fill($subnaviTemplate, $subNaviData);
440 // echo TEMPLATE::fill($subnaviTemplate, $subNaviData);
443 unset($naviUnit[$endKey][1]);
444 $naviVar = array_map(array(&$this, 'createNaviLink'), $naviUnit);
446 // echo '<span class="breadcrumbslist">', @join(' > ', $naviVar);
448 $topicPathData['topicpath'] = implode($this->getOption('topicPathSeparator'), $naviVar);
450 //add Taginfo =====================================
451 // display selected TAGs whith link mod by shizuki
452 if ($manager->pluginInstalled('NP_TagEX')) {
453 // if (requestVar('tag')) {
454 $tagPlugin =& $manager->getPlugin('NP_TagEX');
455 $requestT = $tagPlugin->getNoDecodeQuery('tag');
456 if (!empty($requestT)) {
457 $requestTarray = $tagPlugin->splitRequestTags($requestT);
458 $reqAND = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['and']);
459 if ($requestTarray['or']) {
460 $reqOR = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['or']);
463 $reqTags = array_merge($reqAND, $reqOR);
467 for ($i=0;$i<count($reqTags);$i++) {
468 $tag = trim($reqTags[$i]);
469 $taglist[$i] = '<a href="' . $tagPlugin->creatTagLink($tag, 0) . '">'
470 . htmlspecialchars($tag, ENT_QUOTES, _CHARSET) . '</a>';
472 // echo ' <small style="font-family:Tahoma;">';
473 // echo ' (Tag for "'.$tagPlugin->_rawdecode(requestVar('tag')).'")';
474 // echo ' (Tag for "' . @join(' / ', $taglist) . '")';
477 <%tags%> --> selected TAGs with own link
479 $tagsData['tags'] = implode(' / ', $taglist);
480 $tagListTemplate = $this->getOption('tagListTemplate');
481 $topicPathData['taglist'] = TEMPLATE::fill($tagListTemplate, $tagsData);
486 <%topicpath%> --> topicpath
487 <%taglist%> --> selected TAG list
489 $topicPathTemplate = $this->getOption('topicPathTemplate');
490 $navigateData['topicpathblock'] = TEMPLATE::fill($topicPathTemplate, $topicPathData);
491 // echo TEMPLATE::fill($topicPathTemplate, $topicPathData);
492 $navigateBlockTemplate = $this->getOption('ItemNaviTemplate');
497 echo TEMPLATE::fill($navigateBlockTemplate, $navigateData);
503 function getParenta($subcat_id, $blogid=0)
505 $subcat_id = intval($subcat_id);
506 $blogid = intval($blogid);
508 $que = 'SELECT scatid, parentid, sname, catid FROM %s WHERE scatid = %d';
509 $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
510 $res = sql_query($que);
511 list ($sid, $parent, $sname, $cat_id) = mysql_fetch_row($res);
512 if (intval($parent) != 0) {
513 $this->r[] = $this->getParenta(intval($parent), $blogid);
514 $this->linkparams[subcatid] = $sid;
517 1 => createBlogidLink($blogid, $this->linkparams),
518 2 => createArchiveListLink($blogid, $this->linkparams)
521 $this->linkparams[subcatid] = $sid;
524 1 => createBlogidLink($blogid, $this->linkparams),
525 2 => createArchiveListLink($blogid, $this->linkparams)
531 function getParent($subcat_id)
533 $subcat_id = intval($subcat_id);
534 $que = 'SELECT scatid, parentid, sname FROM %s WHERE scatid = %d';
535 $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
536 $res = sql_query($que);
537 list ($sid, $parent, $sname) = mysql_fetch_row($res);
538 if (intval($parent) != 0) {
539 $r = $this->getParent(intval($parent)) . " -> <a href=$subcat_id>$sname</a>";
541 $r = "<a href=$subcat_id>" . htmlspecialchars($sname) . "</a>";
546 function getChildren($subcat_id)
548 $subcat_id = intval($subcat_id);
549 $que = 'SELECT scatid, parentid, sname FROM %s WHERE parentid = %d';
550 $que = sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id);
551 $res = sql_query($que);
552 while ($so = mysql_fetch_object($res)) {
553 $r .= $this->getChildren($so->scatid) . '/' . intval($so->scatid);
560 // include language file for this plugin
561 $language = ereg_replace( '[\\|/]', '', getLanguageName());
562 if (file_exists($this->getDirectory() . $language . '.php')) {
563 include_once($this->getDirectory() . $language . '.php');
565 include_once($this->getDirectory() . 'english.php');
567 $sub = '<div style="text-align:right;"><%archivedata%><%subnavi%></div>';
568 $path = '<div style="text-align:left;"><%topicpath%><%taglist%></div>';
569 $tags = ' (Selected TAG(s) : <small style="font-family:Tahoma;"><%tags%></small>)';
570 $navi = '<div class="itemnaviex"><%subnaviblock%><%topicpathblock%></div>';
571 $this->createOption('subnaviTemplate', _INEXOP_SUB, 'text', $sub);
572 $this->createOption('PNSeparator', _INEXOP_PNSP, 'tect', ' :: ');
573 $this->createOption('PNNextLabel', _INEXOP_PNNX, 'tect', '»');
574 $this->createOption('PNPrevLabel', _INEXOP_PNPR, 'tect', '«');
575 $this->createOption('topicPathTemplate', _INEXOP_PATH, 'text', $path);
576 $this->createOption('topicPathSeparator', _INEXOP_PSEP, 'text', ' > ');
577 $this->createOption('tagListTemplate', _INEXOP_TAGS, 'text', $tags);
578 $this->createOption('ItemNaviTemplate', _INEXOP_NAVI, 'text', $navi);
579 $this->createOption('archivelinkLabel', _INEXOP_ALBL, 'text', '» ArchiveList');