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://nakahara21.com
19 * 0.991 add sub-blog home mode
22 **************************************************************************
24 * THESE PLUG-INS ARE DEDICATED TO ALL THOSE NucleusCMS USERS
25 * WHO FIGHT CORRUPTION AND IRRATIONAL IN EVERY DAY OF THEIR LIVES.
27 **************************************************************************/
29 class NP_ItemNaviEX extends NucleusPlugin
33 return 'Navigation Bar';
38 return 'nakahara21 + shizuki';
43 return 'http://nakahara21.com/';
51 function getDescription()
53 return 'Add link to prev item and next item. Usage: <%ItemNaviEX()%> or <%ItemNaviEX(0)%>';
56 function supportsFeature($what)
59 case 'SqlTablePrefix':
66 function scanEndKey($array)
68 $keys = array_keys($array);
73 function createNaviLink($unitArray)
76 $tempLink = '<a href="' . htmlspecialchars($unitArray[1]) . '">' . htmlspecialchars($unitArray[0]) . '</a>';
78 $tempLink = htmlspecialchars($unitArray[0]);
83 function checkParent()
86 // if ($manager->pluginInstalled('NP_MultipleCategories')) {
87 // $mplugin =& $manager->getPlugin('NP_MultipleCategories');
88 // if (method_exists($mplugin,"getRequestName")) {
89 $res = sql_query('SHOW FIELDS FROM ' . sql_table('plug_multiple_categories_sub'));
90 while ($co = mysql_fetch_assoc($res)) {
91 if ($co['Field'] == 'parentid') {
99 function doSkinVar($skinType, $showHome = 1)
101 global $manager, $CONF, $blog, $itemid, $itemidprev, $itemidnext;
102 global $catid, $subcatid, $archive, $archiveprev, $archivenext, $param;
106 $itemid = intval($itemid);
107 $catid = intval($catid);
108 $subcatid = intval($subcatid);
109 $itemidprev = intval($itemidprev);
110 $itemidnext = intval($itemidnext);
111 if (isset($archive)) {
112 sscanf($archive,'%d-%d-%d', $y, $m, $d);
113 if ($y && $m && !empty($d)) {
114 $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
115 } elseif ($y && $m && empty($d)) {
116 $archive = sprintf('%04d-%02d', $y, $m);
119 if (isset($archiveprev)) {
120 sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
121 if ($y && $m && !empty($d)) {
122 $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
123 } elseif ($y && $m && empty($d)) {
124 $archiveprev = sprintf('%04d-%02d', $y, $m);
127 if (isset($archiveprev)) {
128 sscanf($archiveprev,'%d-%d-%d', $y, $m, $d);
129 if ($y && $m && !empty($d)) {
130 $archiveprev = sprintf('%04d-%02d-%02d', $y, $m, $d);
131 } elseif ($y && $m && empty($d)) {
132 $archiveprev = sprintf('%04d-%02d', $y, $m);
135 if ($showHome == '') {
140 $blogid = getBlogIDFromCatID($catid);
141 $b =& $manager->getBlog($blogid);
145 $b =& $manager->getBlog($CONF['DefaultBlog']);
147 $blogid = intval($b->getID());
151 $where .= ' and i.iblog=' . $blogid;
152 if (!empty($catid)) {
153 if ($manager->pluginInstalled('NP_MultipleCategories')) {
154 $where .= ' and ((i.inumber = p.item_id and (p.categories REGEXP "(^|,)' . $catid . '(,|$)"' .
155 ' or i.icat = ' . $catid . ')) or (i.icat = ' . $catid . ' and p.item_id IS NULL))';
156 $mtable = ' LEFT JOIN ' . sql_table('plug_multiple_categories') . ' as p ON i.inumber = p.item_id';
157 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
158 if ($subcatid && method_exists($mplugin, 'getRequestName')) {
160 if ($this->checkParent()) {
162 $Children = explode('/', $subcatid . $this->getChildren($subcatid));
165 for ($i=0;$i<count($Children);$i++) {
166 $temp_whr[] = ' p.subcategories REGEXP "(^|,)' . intval($Children[$i]) . '(,|$)" ';
170 $where .= join(' or ', $temp_whr);
173 $where .= ' and p.subcategories REGEXP "(^|,)' . $subcatid . '(,|$)"';
178 $where .= ' and i.icat=' . $catid;
183 $subNaviUnit = array();
184 $this->linkparams = array();
185 //store Home =====================================
186 // comment out this block when HOME is sub-blog top
187 if ($showHome == 1) {
190 1 => $CONF['IndexURL'],
191 2 => createArchiveListLink($blogid)
195 //store Blog =====================================
196 if ($showHome == 1 && ($blogid <> $CONF['DefaultBlog'])) {
198 0 => getBlogNameFromID($blogid),
199 1 => createBlogidLink($blogid),
200 2 => createArchiveListLink($blogid)
202 } elseif ($showHome >= 2) {
204 0 => 'Home', // when HOME is sub-blog top
205 1 => $CONF['BlogURL'] . '/', // when HOME is sub-blog top
206 2 => createArchiveListLink($blogid)
210 //store Category =====================================
211 if (!empty($catid)) {
212 $this->linkparams['catid'] = $catid;
214 0 => $b->getCategoryName($catid),
215 1 => createCategoryLink($catid),
216 // 1 => createBlogidLink($blogid, $this->linkparams),
217 2 => createArchiveListLink($blogid, $this->linkparams)
221 //store subCategory =====================================
222 if (!empty($subcatid)) {
223 if ($manager->pluginInstalled('NP_MultipleCategories')) {
224 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
225 if (method_exists($mplugin, 'getRequestName')) {
226 $subrequest = $mplugin->getRequestName(array());
227 $this->linkparams[$subrequest] = $subcatid;
228 if ($this->checkParent()) {
229 $tog = $this->getParenta($subcatid, $blogid);
230 for ($i=0;$i<count($this->r);$i++) {
231 $naviUnit[] = $this->r[$i];
236 0 => $mplugin->_getScatNameFromID($subcatid),
237 1 => createCategoryLink($catid, array($subrequest => $subcatid)),
238 // 1 => createCategoryLink($catid, array('subcatid' => $subcatid)),
239 // 1 => createBlogidLink($blogid, $this->linkparams),
240 2 => createArchiveListLink($blogid, $this->linkparams)
247 //store Page ===================================== todo How to get PageNo. ? ...cookie...
248 if (requestVar('page')) {
250 0 => 'Page.' . intRequestVar('page'),
251 2 => createArchiveListLink($blogid, $this->linkparams)
255 //store Item =====================================
256 if ($skinType == 'item') {
257 $item =& $manager->getItem($itemid, 0, 0);
263 $query = 'SELECT i.ititle, i.inumber'
264 . ' FROM ' . sql_table('item') . ' as i' . $mtable
265 . ' WHERE i.idraft = 0'
266 . " and i.itime < '" . $item['itime'] . "' " . $where;
267 $query .= ' ORDER BY i.itime DESC';
268 $res = sql_query($query);
269 if ($ares = mysql_fetch_row($res)) {
270 $alink = createItemLink($ares[1], $this->linkparams);
271 $subNaviUnit[1] = '<a href="' . htmlspecialchars($alink) . '" rel="prev"> « ' .
272 shorten($ares[0], 14, '...') . '</a>';
277 $query = 'SELECT i.ititle, i.inumber'
278 . ' FROM ' . sql_table('item') . ' as i' . $mtable
279 . ' WHERE i.idraft = 0'
280 . " and i.itime > '" . $item['itime'] . "' " . $where;
281 $query .= ' ORDER BY i.itime ASC';
282 $res = sql_query($query);
283 if ($ares = mysql_fetch_row($res)) {
284 $alink = createItemLink($ares[1], $this->linkparams);
285 $subNaviUnit[2] = '<a href="' . htmlspecialchars($alink) . '" rel="next"> ' .
286 shorten($ares[0], 14, '...') . ' »</a>';
292 //store ArchiveList =====================================
293 if ($skinType == 'archivelist' || $skinType == 'archive') {
296 1 => createArchiveListLink($blogid, $this->linkparams)
300 if ($skinType == 'archive') {
301 sscanf($archive,'%d-%d-%d', $y, $m, $d);
303 $archiveMonth = $y . '-' . $m;
306 1 => createArchiveLink($blogid, $archiveMonth, $this->linkparams)
309 $timestamp_start = mktime(0, 0, 0, $m, 1, $y);
310 $timestamp_end = mktime(0, 0, 0, $m+1, 1, $y);
311 $date_str = 'SUBSTRING(i.itime, 1, 7)';
313 $timestamp_start = mktime(0, 0, 0, $m, $d, $y);
314 $timestamp_end = mktime(0, 0, 0, $m, $d+1, $y);
315 $date_str = 'SUBSTRING(i.itime, 1, 10)';
318 0 => $y . '-' . $m . '-' . $d,
319 1 => createArchiveLink($blogid, $archive, $this->linkparams)
323 //=============================
324 $query = 'SELECT ' . $date_str . ' as Date'
325 . ' FROM ' . sql_table('item') . ' as i' . $mtable
326 . ' WHERE i.idraft = 0'
327 . ' and i.itime < ' . mysqldate($timestamp_start) . $where;
328 $query .= ' GROUP BY Date';
329 $query .= ' ORDER BY i.itime DESC';
330 $res = sql_query($query);
331 if ($ares = mysql_fetch_row($res)) {
332 // $prev_date = $ares[0];
333 sscanf($ares[0], '%d-%d-%d', $y, $m, $d);
335 $prev_date = sprintf('%04d-%02d', $y, $m);
337 $prev_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
339 $prev_alink = createArchiveLink($blogid, $prev_date, $this->linkparams);
340 $subNaviUnit[1] = '<a href="' . htmlspecialchars($prev_alink) . '" class="prevlink" rel="prev">' .
341 ' « ' . htmlspecialchars($prev_date) . '</a>';
342 // $abuf .= '<a href="'.$prev_alink.'" class="prevlink" rel="prev">'.$prev_date.'</a>';
344 // $today_link = createBlogidLink($b->getID(), $this->linkparams);
345 // $abuf .= ' ( <a href="'.$today_link.'">Today</a> )';
347 $abuf .= ' | <strong>' . htmlspecialchars($archive) . '</strong> ';
348 //=============================
349 $query = 'SELECT ' . $date_str . ' as Date'
350 . ' FROM ' . sql_table('item') . ' as i' . $mtable
351 . ' WHERE i.idraft = 0'
352 . ' and i.itime < ' . mysqldate($b->getCorrectTime())
353 . ' and i.itime >= ' . mysqldate($timestamp_end) . $where;
354 $query .= ' GROUP BY Date';
355 $query .= ' ORDER BY i.itime ASC';
356 $res = sql_query($query);
357 if ($ares = mysql_fetch_row($res)) {
358 // $next_date = $ares[0];
359 sscanf($ares[0],'%d-%d-%d', $y, $m, $d);
361 $next_date = sprintf('%04d-%02d', $y, $m);
363 $next_date = sprintf('%04d-%02d-%02d', $y, $m, $d);
365 $next_alink = createArchiveLink($blogid, $next_date, $this->linkparams);
366 $subNaviUnit[2] = '<a href="' . htmlspecialchars($next_alink) . '" class="nextlink" rel="next">'
367 . htmlspecialchars($next_date) . ' »</a>';
368 // $a2buf = ' | <a href="'.$next_alink.'" class="nextlink" rel="next">'.$next_date.'</a>';
370 // $today_link = createBlogidLink($b->getID(), $this->linkparams);
371 // $a2buf .= ' | ( <a href="'.$today_link.'">Today</a> )';
374 //============================= // end of archive(s)
377 // todo Henceforth to template
378 // echo ' <div style="text-align: center;">';
379 // echo ' <span style="text-align:right;">';
380 echo ' <span class="prevnextnavi">';
381 $endKey = $this->scanEndKey($naviUnit);
382 if ($skinType != 'archivelist' && $skinType != 'archive' && $skinType != 'item') {
383 echo '<a href="' . $naviUnit[$endKey][2] . '">» ArchiveList</a>';
385 echo @join(' :: ', $subNaviUnit);
390 unset($naviUnit[$endKey][1]);
391 $naviVar = array_map(array(&$this, 'createNaviLink'), $naviUnit);
392 echo '<span class="breadcrumbslist">', @join(' > ', $naviVar);
394 //add Taginfo =====================================
395 // display selected TAGs whith link mod by shizuki
396 if ($manager->pluginInstalled('NP_TagEX')) {
397 // if (requestVar('tag')) {
398 $tagPlugin =& $manager->getPlugin('NP_TagEX');
399 $requestT = $tagPlugin->getNoDecodeQuery('tag');
400 if (!empty($requestT)) {
401 $requestTarray = $tagPlugin->splitRequestTags($requestT);
402 $reqAND = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['and']);
403 if ($requestTarray['or']) {
404 $reqOR = array_map(array(&$tagPlugin, "_rawdecode"), $requestTarray['or']);
407 $reqTags = array_merge($reqAND, $reqOR);
411 for ($i=0;$i<count($reqTags);$i++) {
412 $tag = trim($reqTags[$i]);
413 $taglist[$i] = '<a href="' . $tagPlugin->creatTagLink($tag, 0) . '">'
414 . htmlspecialchars($tag) . '</a>';
416 echo ' <small style="font-family:Tahoma;">';
417 // echo ' (Tag for "'.$tagPlugin->_rawdecode(requestVar('tag')).'")';
418 echo ' (Tag for "' . @join(' / ', $taglist) . '")';
427 function getParenta($subcat_id, $blogid=0)
429 $subcat_id = intval($subcat_id);
430 $blogid = intval($blogid);
432 $que = 'SELECT scatid, parentid, sname, catid FROM %s WHERE scatid = %d';
433 $res = sql_query(sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id));
434 list ($sid, $parent, $sname, $cat_id) = mysql_fetch_row($res);
435 if (intval($parent) != 0) {
436 $this->r[] = $this->getParenta(intval($parent), $blogid);
437 $this->linkparams[subcatid] = $sid;
440 1 => createBlogidLink($blogid, $this->linkparams),
441 2 => createArchiveListLink($blogid, $this->linkparams)
444 $this->linkparams[subcatid] = $sid;
447 1 => createBlogidLink($blogid, $this->linkparams),
448 2 => createArchiveListLink($blogid, $this->linkparams)
454 function getParent($subcat_id)
456 $subcat_id = intval($subcat_id);
457 $que = 'SELECT scatid, parentid, sname FROM %s WHERE scatid = %d';
458 $res = sql_query(sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id));
459 list ($sid, $parent, $sname) = mysql_fetch_row($res);
460 if (intval($parent) != 0) {
461 $r = $this->getParent(intval($parent)) . " -> <a href=$subcat_id>$sname</a>";
463 $r = "<a href=$subcat_id>" . htmlspecialchars($sname) . "</a>";
468 function getChildren($subcat_id)
470 $subcat_id = intval($subcat_id);
471 $que = 'SELECT scatid, parentid, sname FROM %s WHERE parentid = %d';
472 $res = sql_query(sprintf($que, sql_table('plug_multiple_categories_sub'), $subcat_id));
473 while ($so = mysql_fetch_object($res)) {
474 $r .= $this->getChildren($so->scatid) . '/' . intval($so->scatid);