4 * SHOWING BLOGS 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 * 2.65 add AD code control
22 * 2.64 fix page switch URL generate
23 * 2.62 security fix and tag related
27 ****************************************************************************
29 * THESE PLUG-INS ARE DEDICATED TO ALL THOSE NucleusCMS USERS
30 * WHO FIGHT CORRUPTION AND IRRATIONAL IN EVERY DAY OF THEIR LIVES.
32 ****************************************************************************/
34 class NP_ShowBlogs extends NucleusPlugin
42 function getMinNucleusVersion()
49 return 'Taka + nakahara21 + kimitake + shizuki';
54 return 'http://nakahara21.com/';
62 function getDescription()
67 function supportsFeature($what)
70 case 'SqlTablePrefix':
77 function getEventList()
86 $language = ereg_replace( '[\\|/]', '', getLanguageName());
87 if (file_exists($this->getDirectory() . $language . '.php')) {
88 include_once($this->getDirectory() . $language . '.php');
90 include_once($this->getDirectory() . 'english.php');
96 // $this->createOption('catnametoshow', '[allblog mode only] category name to show (0:catname on blogname, 1:catname only, 2:blogname only)','text','0');
97 // $this->createOption('stickmode', '[currentblog mode only] 0:show all stickyID, 1:show current blog stickyID only', 'text', '1');
98 // $this->createOption('ads', '[Ads code] code displayed under first and second item of the page', 'textarea', '' . "\n");
100 $this->createOption('catformat', _CAT_FORMAT, 'text', '<%category%> on <%blogname%>');
101 // $this->createOption('catnametoshow', _CATNAME_SHOW, 'text', '0');
102 $this->createOption('stickmode', _STICKMODE, 'text', '1');
103 $this->createOption('ads', _ADCODE_1, 'textarea', '' . "\n");
104 $this->createOption('ads2', _ADCODE_2, 'textarea', '' . "\n");
105 $this->createOption('tagMode', _TAG_MODE, 'select', '2', _TAG_SELECT);
106 /* todo can't install ? only warning ?
107 * douyatte 'desc' ni keikoku wo daseba iinoka wakaranai desu
108 $ver_min = (getNucleusVersion() < $this->getMinNucleusVersion());
109 $pat_min = ((getNucleusVersion() == $this->getMinNucleusVersion()) &&
110 (getNucleusPatchLevel() < $this->getMinNucleusPatchLevel()));
111 if ($ver_min) { // || $pat_min) {
113 // uninstall plugin again...
114 include_once($DIR_LIBS . 'ADMIN.php');
115 $admin = new ADMIN();
116 $admin->deleteOnePlugin($this->getID());
119 $admin->error(_ERROR_NUCLEUSVERSIONREQ .
120 $this->getMinNucleusVersion() . ' patch ' .
121 $this->getMinNucleusPatchLevel());
127 function doSkinVar($skinType,
128 $template = 'default/index',
140 global $manager, $CONF, $blog, $blogid, $catid, $itemid, $archive, $subcatid;
142 //***************************************
144 //***************************************
145 /* blogid(blogshortname) you want to hide
149 $hide = array('private');
150 $hide =array('private','atloss');
155 // limit number of pages(months)
158 $catformat = $this->getOption('catformat');
160 /**************************************************************************************/
162 $type = (float) $type;
163 $typeExp = intval(($type - floor($type))*10); //0 or 1 or 9
164 $this->showAdCode = $showAdCode;
166 list ($pageamount, $offset) = sscanf($amount, '%d(%d)');
170 if ($sort != 'ASC' && $sort != 'DESC') {
171 $sticktemplate = $sticky;
175 if (!empty($sticky) && empty($sticktemplate)) {
176 $sticktemplate = $template;
179 if (preg_match("/^(<>)?([0-9\/]+)$/", $bmode, $matches)) {
181 $hide = explode("/", $matches[2]);
185 $show = explode("/", $matches[2]);
190 if (preg_match("/^(<>)?([0-9\/]+)$/", $catmode, $matches)) {
192 $hideCat = explode("/", $matches[2]);
196 $showCat = explode("/", $matches[2]);
204 $b =& $manager->getBlog($CONF['DefaultBlog']);
206 $this->nowbid = $nowbid = intval($b->getID());
211 if ($bmode != 'all') {
212 $where .= ' AND i.iblog = ' . $nowbid;
213 } elseif (isset($hide[0]) && $bmode == 'all') {
214 foreach ($hide as $val) {
215 if (!is_numeric($val)) {
216 $val = getBlogIDFromName(intval($val));
218 $where .= ' AND i.iblog != ' . intval($val);
221 } elseif (isset($show[0]) && $bmode == 'all') {
222 foreach ($show as $val) {
223 if (!is_numeric($val)) {
224 $val = getBlogIDFromName(intval($val));
228 $catblogname = (count($w) > 1) ? 1 : 0;
229 $where .= ' AND i.iblog in (' . implode(',', $w) . ')';
232 if (isset($hidecat[0]) && $catmode == 'all') {
233 foreach($hideCat as $val){
234 if(!is_numeric($val)){
235 $val = getCatIDFromName(intval($val));
237 $where .= ' AND i.icat != ' . intval($val);
240 } elseif (isset($showCat[0]) && $catmode == 'all') {
241 foreach ($showCat as $val) {
242 if (!is_numeric($val)) {
243 $val = getBlogIDFromName(intval($val));
247 $catblogname = (count($w) > 1) ? 1 : 0;
248 $where .= ' AND i.icat in (' . implode(',', $w) . ')';
250 $stickWhere = $where;
252 if ($skinType == 'item' || $skinType == 'index' || $skinType == 'archive') {
253 $catformat = '"' . addslashes($catformat) . '"';
264 $catformat = preg_replace($fArr, $nArr, $catformat);
266 if ($manager->pluginInstalled('NP_TagEX')) {
267 $t_where = $this->_getTagsInum($where, $skinType, $bmode, $amount);
268 $where .= $t_where['where'];
271 if ($skinType == 'item') {
272 $where .= ' and i.inumber != ' . intval($itemid);
275 $sticCatFlag = (!$catid || (!empty($catStick) && $sticktemplate != ''));
276 // if (!$catid && $sticky != '') {
277 if ($sticCatFlag && $sticky != '') {
278 $stickys = explode('/', $sticky);
279 foreach ($stickys as $stickynumber) {
280 $where .= ' AND i.inumber <> ' . intval($stickynumber);
285 $temp = $y = $m = $d = '';
287 sscanf($archive, '%d-%d-%d', $y, $m, $d);
289 $timestamp_start = mktime(0, 0, 0, $m, $d, $y);
290 $timestamp_end = mktime(0, 0, 0, $m, $d+1, $y);
291 $date_str = 'SUBSTRING(i.itime, 1, 10)';
293 $timestamp_start = mktime(0, 0, 0, $m, 1, $y);
294 $timestamp_end = mktime(0, 0, 0, $m+1, 1, $y);
295 $date_str = 'SUBSTRING(i.itime,1,7)';
297 $where .= ' AND i.itime >= ' . mysqldate($timestamp_start) .
298 ' AND i.itime < ' . mysqldate($timestamp_end);
299 } elseif (!empty($monthlimit)) {
300 $timestamp_end = mysqldate($b->getCorrectTime());
301 sscanf($timestamp_end, '"%d-%d-%d %s"', $y, $m, $d, $temp);
302 $timestamp_start = mktime(0, 0, 0, $m-$monthlimit, $d, $y);
303 $where .= ' AND i.itime >= ' . mysqldate($timestamp_start)
304 . ' AND i.itime <= ' . $timestamp_end;
306 $where .= ' AND i.itime <= ' . mysqldate($b->getCorrectTime());
309 if (!empty($catid)) {
310 if ($manager->pluginInstalled('NP_MultipleCategories')) {
311 $mcat_query = $this->_getSubcategoriesWhere($catid);
312 $mtable = $mcat_query['m'];
313 $where .= $mcat_query['w'];
315 $where .= ' AND i.icat=' . intval($catid);
317 $linkparams['catid'] = $todayparams['catid'] = intval($catid);
321 $page_switch = $this->PageSwitch($type, $pageamount, $offset, $where, $sort, $mtable);
322 if ($typeExp != 9 && $skinType != 'item') {
323 echo $page_switch['buf'];
328 $sh_query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body,' .
329 ' m.mname as author, m.mrealname as authorname,' .
330 ' UNIX_TIMESTAMP(i.itime) as timestamp, i.itime,' .
331 ' i.imore as more, m.mnumber as authorid,';
333 $sh_query .= ' c.cname as category,';
335 $sh_query .= ' concat(' . $catformat . ') as category,';
337 $sh_query .= ' i.icat as catid, i.iclosed as closed'
339 . sql_table('member') . ' as m, '
340 . sql_table('category') . ' as c, '
341 . sql_table('item') . ' as i'
343 if ($bmode == 'all') {
344 $sh_query .= ', ' . sql_table('blog') . ' as b ';
346 $sh_query .= ' WHERE i.iauthor = m.mnumber AND i.icat = c.catid';
347 if ($bmode == 'all') {
348 $sh_query .= ' AND b.bnumber = c.cblog';
351 // if ($page_switch['startpos'] == 0 && !$catid && $sticky != '' && $skinType != 'item' && !$this->tagSelected) {
353 $sticCatFlag = ($page_switch['startpos'] == 0 && (!$catid || (!empty($catStick) && $sticktemplate != '')));
354 if ($sticCatFlag && $sticky != '' && $skinType != 'item' && !$this->tagSelected) {
355 foreach ($stickys as $stickynumber) {
356 $sticky_query = $sh_query;
357 $tempblogid = getBlogIDFromItemID($stickynumber);
358 if ($bmode != 'all') {
359 $sticky_query .= ' AND i.iblog = ' . $nowbid;
361 $sticky_query .= ' AND i.inumber = ' . intval($stickynumber)
362 . ' AND i.itime <= ' . mysqldate($b->getCorrectTime())
363 . ' AND i.idraft = 0';
365 $sticky_query .= ' AND i.icat = ' . intval($catid);
368 $sticky_query .= ' AND p.subcategories = ' . intval($subcatid);
370 $sticky_query .= $stickWhere;
371 if ($this->getOption('stickmode') == 1 && intval($nowbid) == $tempblogid) {
372 $b->showUsingQuery($sticktemplate, $sticky_query, 0, 1, 0);
373 } elseif (!$this->getOption('stickmode')) {
374 $b->showUsingQuery($sticktemplate, $sticky_query, 0, 1, 0);
376 //echo $stickynumber;
377 if ($showAdCode > 0 && mysql_num_rows(sql_query($sticky_query))) {
379 echo $this->getOption('ads');
380 } elseif ($ads == 1) {
381 echo $this->getOption('ads2');
382 } elseif ($ads >= 2) {
389 $sh_query .= ' AND i.idraft = 0' . $where;
391 if ($skinType == 'item') {
392 $sh_query .= ' ORDER BY FIND_IN_SET(i.inumber,\'' . @join(',', $t_where['inumsres']) . '\')';
394 $sh_query .= ' ORDER BY i.itime ' . $sort;
397 if ($skinType != 'item') {
398 $this->_showUsingQuery($template, $sh_query, $page_switch['startpos'], $pageamount, $b, $ads);
399 if ($type >= 1 && $typeExp != 1) echo $page_switch['buf'];
400 } elseif ($skinType == 'item') {
401 $sh_query .= ' LIMIT 0, ' . $pageamount;
402 $b->showUsingQuery($template, $sh_query, 0, 1, 1);
407 function _showUsingQuery($template, $showQuery, $q_startpos, $q_amount, $b, $ads)
410 $onlyone_query = $showQuery . ' LIMIT ' . intval($q_startpos) .', 1';
411 $b->showUsingQuery($template, $onlyone_query, 0, 1, 1);
412 if (intval($ads) == 0 && $this->showAdCode > 0) {
413 echo $this->getOption('ads');
415 //------------SECOND AD CODE-------------
416 } elseif (intval($ads) == 1 && $this->showAdCode > 0) {
417 echo $this->getOption('ads2');
421 if ($q_amount < 0) return;
422 $onlyone_query = $showQuery . ' LIMIT ' . intval($q_startpos) . ', 1';
423 $b->showUsingQuery($template, $onlyone_query, 0, 1, 1);
424 if (mysql_num_rows(sql_query($onlyone_query)) && empty($ads) && $this->showAdCode > 0) {
425 echo $this->getOption('ads2');
427 //------------SECOND AD CODE END-------------
430 if ($q_amount <= 0) return;
431 $second_query = $showQuery . ' LIMIT ' . intval($q_startpos) . ',' . intval($q_amount);
432 $b->showUsingQuery($template, $second_query, 0, 1, 1);
435 function event_InitSkinParse($data)
437 global $CONF, $manager;
438 $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
439 if (serverVar('REQUEST_URI') == '') {
440 $uri = (serverVar('QUERY_STRING')) ?
441 serverVar('SCRIPT_NAME') . serverVar('QUERY_STRING') : serverVar('SCRIPT_NAME');
443 $uri = serverVar('REQUEST_URI');
445 $page_str = ($usePathInfo) ? 'page/' : 'page=';
446 if ($manager->pluginInstalled('NP_CustomURL') || $manager->pluginInstalled('NP_Magical')) {
449 list($org_uri, $currPage) = explode($page_str, $uri, 2);
450 if (getVar('page')) {
451 $currPage = intGetVar('page');
453 $_GET['page'] = intval($currPage);
454 $this->currPage = intval($currPage);
455 $this->pagestr = $page_str;
458 function PageSwitch($type, $pageamount, $offset, $where, $sort, $mtable = '')
460 global $CONF, $manager, $archive, $catid, $subcatid;
464 $catid = intval($catid);
465 $subcatid = intval($subcatid);
466 $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
467 $pageamount = intval($pageamount);
468 $offset = intval($offset);
471 sscanf($archive, '%d-%d-%d', $y, $m, $d);
473 $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
475 $archive = sprintf('%04d-%02d', $y, $m);
479 $page_str = $this->pagestr;
480 $currentpage = $this->currPage;
483 if (!empty($catid)) {
484 $catrequest = ($usePathInfo) ? $CONF['CategoryKey'] : 'catid';
485 if (!empty($subcatid)) {
486 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
487 $subrequest = $mplugin->getRequestName(array());
488 if (!empty($archive)) {
490 $catrequest => $catid,
491 $subrequest => $subcatid
493 $pagelink = createArchiveLink($archive, $linkParam);
496 $subrequest => $subcatid
498 $pagelink = createCategoryLink($catid, $linkParam);
501 if (!empty($archive)) {
503 $catrequest => $catid,
505 $pagelink = createArchiveLink($archive, $linkParam);
507 $pagelink = createCategoryLink($catid);
511 if (!empty($archive)) {
512 $pagelink = createArchiveLink($this->nowbid, $archive);
514 $pagelink = createBlogidLink($this->nowbid);
517 if ($manager->pluginInstalled('NP_TagEX')) {
518 $tplugin =& $manager->getPlugin('NP_TagEX');
519 $requestTag = $tplugin->getNoDecodeQuery('tag');
520 if (!empty($requestTag)) {
521 $requestTarray = $tplugin->splitRequestTags($requestTag);
522 $tag = array_shift($requestTarray['and']);
523 $tag = $tplugin->_rawdecode($tag);
524 if (!empty($requestTarray['and'])) {
525 $requestT = implode('+', $requestTarray['and']);
527 if (!empty($requestTarray['or'])) {
528 $requestTor = implode(':', $requestTarray['or']);
530 if (!empty($requestT) && !empty($requestTor)) {
531 $tags = $requestT . ':' . $requestTor;
532 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'), $tags, '+');
533 } elseif (empty($requestT) && !empty($requestTor)) {
534 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'), $requestTor, ':');
536 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'));
541 if (strstr ($pagelink, '//')) {
542 $pagelink = preg_replace("/([^:])\/\//", "$1/", $pagelink);
544 $uri = parse_url($pagelink);
546 if ($pagelink == $CONF['BlogURL']) { // add
548 } elseif ($uri['query']) {
549 $pagelink .= '&';
551 $pagelink = str_replace('&&', '&', $pagelink);
552 } elseif ($usePathInfo && substr($pagelink, -1) != '/') {
554 $pagelink .= '&';
558 if (strstr ($pagelink, '//')) $link = preg_replace("/([^:])\/\//", "$1/", $pagelink);
562 if ($currentpage > 0) {
563 $startpos = ($currentpage - 1) * $pageamount;
569 if (is_numeric($where)) {
570 $totalamount = $where;
571 } elseif (is_array($where)) {
572 $totalamount = count($where);
574 $p_query = 'SELECT COUNT(i.inumber) FROM %s as i%s WHERE i.idraft = 0%s';
575 $p_query = sprintf($p_query, sql_table('item'), $mtable, $where);
576 // $p_query = 'SELECT COUNT(i.inumber) FROM ' . sql_table('item') . ' as i' . $mtable . ' WHERE i.idraft=0' . $where;
577 $entries = sql_query($p_query);
578 if ($row = mysql_fetch_row($entries)) {
579 $totalamount = $row[0];
582 $totalamount = intval($totalamount);
583 if (!$archive && !empty($pagelimit) && ($pagelimit * $pageamount < $totalamount)) {
584 $totalamount = intval($pagelimit) * $pageamount;
587 $startpos += $offset;
588 $totalamount -= $offset;
590 if ($this->maxamount && $this->maxamount < $totalamount) {
591 $totalamount = intval($this->maxamount);
593 $totalpages = ceil($totalamount/$pageamount);
594 $totalpages = intval($totalpages);
595 if ($startpos > $totalamount) {
596 $currentpage = $totalpages;
597 $startpos = $totalamount-$pageamount;
600 $startpos += $offset;
601 $totalamount -= $offset;
603 $totalpages = ceil($totalamount/$pageamount);
604 if ($startpos > $totalamount) {
605 $currentpage = $totalpages;
606 $startpos = $totalamount-$pageamount;
608 $prevpage = ($currentpage > 1) ? $currentpage - 1 : 0;
609 $nextpage = $currentpage + 1;
610 $firstpagelink = $pagelink . $page_str . '1';
611 if ($page_str == 'page_') {
612 $firstpagelink .= '.html';
614 $lastpagelink = $pagelink . $page_str . $totalpages;
615 if ($page_str == 'page_') {
616 $lastpagelink .= '.html';
620 $buf .= '<div class="pageswitch">' . "\n";
621 // $buf .= "<a rel=\"first\" title=\"first page\" href=\"{$firstpagelink}\"><TOP></a> | \n";
622 if (!empty($prevpage)) {
623 $prevpagelink = $pagelink . $page_str . $prevpage;
624 if ($page_str == 'page_') {
625 $prevpagelink .= '.html';
627 $buf .= '<a href="' . $prevpagelink . '" title="Previous page" rel="Prev">«Prev</a> |';
628 } elseif ($type >= 2) {
629 $buf .= "«Prev |";
632 if (intval($type) == 2) {
633 $sepstr = '·';
635 for ($i=1; $i<=$totalpages; $i++) {
636 $i_pagelink = $pagelink . $page_str . $i;
637 if ($page_str == 'page_') {
638 $i_pagelink .= '.html';
640 if ($i == $currentpage) {
641 $buf .= ' <strong>' . $i . '</strong> |' . "\n";
642 } elseif ($totalpages<10 || $i<4 || $i>$totalpages-3) {
643 $buf .= ' <a href="' . $i_pagelink . '" title="Page No.' . $i . '">'
644 . $i . '</a> |' . "\n";
646 if ($i<$currentpage-1 || $i>$currentpage+1) {
647 if (($i == 4 && ($currentpage > 5 || $currentpage == 1)) || $i == $currentpage + 2) {
652 $buf .= ' <a href="' . $i_pagelink . '" title=\"Page No.' . $i . '">'
653 . $i . '</a> |' . "\n";
659 if (intval($type) == 3) {
661 $sepstr = '·';
662 for ($i = 1; $i <= $totalpages; $i++) {
663 $i_pagelink = $pagelink . $page_str . $i;
664 if ($page_str == 'page_') {
665 $i_pagelink .= '.html';
668 if ($i == $currentpage) {
669 $buf .= ' <strong>' . $i . '</strong> ' . $sepstr . "\n";
670 } elseif ($totalpages < 10 || ($i < ($currentpage + $paging) && ($currentpage - $paging) < $i)) {
671 $buf .= ' <a href="' . $i_pagelink . '" title="Page No.' . $i . '">'
672 . $i . '</a> ' . $sepstr . "\n";
673 } elseif ($currentpage - $paging == $i) {
676 } elseif ($currentpage + $paging == $i) {
678 $buf = preg_replace('/$sepstr$/', '', $buf);
683 if ($totalpages >= $nextpage) {
684 $nextpagelink = $pagelink . $page_str . $nextpage;
685 if ($page_str == 'page_') {
686 $nextpagelink .= '.html';
688 $buf .= '| <a href="' . $nextpagelink . '" title="Next page" rel="Next">Next»</a>' . "\n";
689 } elseif ($type >= 2) {
690 $buf .= "| Next»\n";
692 // $buf .= " | <a rel=\"last\" title=\"Last page\" href=\"{$lastpagelink}\"><LAST></a>\n";
694 return array('buf' => $buf, 'startpos' => intval($startpos));
698 function _getSubcategoriesWhere($catid)
702 $mwhere = ' AND ((i.inumber = p.item_id'
703 . ' AND (p.categories REGEXP "(^|,)' . intval($catid) . '(,|$)"'
704 . ' OR i.icat = ' . intval($catid) . '))'
705 . ' OR (i.icat = ' . intval($catid)
706 . ' AND p.item_id IS NULL))';
707 $mtable = ' LEFT JOIN ' . sql_table('plug_multiple_categories') . ' as p'
708 . ' ON i.inumber = p.item_id';
709 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
710 if (method_exists($mplugin, 'getRequestName')) {
711 $mplugin->event_PreSkinParse(array());
715 $mque = 'SELECT * FROM %s WHERE scatid = %d';
716 $tres = sql_query(sprintf($mque, sql_table('plug_multiple_categories_sub'), intval($subcatid)));
717 // $tres = sql_query('SELECT * FROM ' . sql_table('plug_multiple_categories_sub') .
718 // ' WHERE scatid = ' . intval($subcatid));
719 $ra = mysql_fetch_array($tres, MYSQL_ASSOC);
720 if (array_key_exists('parentid', $ra)) {
722 $Children = explode('/', intval($subcatid) . $this->getChildren(intval($subcatid)));
725 for ($i=0;$i<count($Children);$i++) {
726 $temp_whr[] = ' p.subcategories REGEXP "(^|,)' . intval($Children[$i]) . '(,|$)" ';
728 $mwhere .= ' AND ( ';
729 $mwhere .= implode(' OR ', $temp_whr);
732 $mwhere .= ' AND p.subcategories REGEXP "(^|,)' . intval($subcatid) . '(,|$)"';
736 return array(w => $mwhere, m => $mtable);
739 function getParents($subcat_id)
741 $subcatTable = sql_table('plug_multiple_categories_sub');
742 $que = 'SELECT scatid, parentid, sname FROM %s WHERE scatid = %d';
743 $que = sprintf($que, $subcatTable, intval($subcat_id));
744 $res = sql_query($que);
745 list($sid, $parent, $sname) = mysql_fetch_row($res);
747 $r = $this->getParent(intval($parent)) . '/' . intval($sid);
754 function getChildren($subcat_id)
756 $subcatTable = sql_table('plug_multiple_categories_sub');
757 $que = 'SELECT scatid, parentid, sname FROM %s WHERE parentid = %d';
758 $que = sprintf($que, $subcatTable, intval($subcat_id));
760 while ($so = mysql_fetch_object($res)) {
761 $r .= $this->getChildren(intval($so->scatid)) . '/' . intval($so->scatid);
766 function _getTagsInum($where, $skin_type, $bmode, $p_amount)
768 global $manager, $itemid;
769 $tagTable = sql_table('plug_tagex');
770 $tplugin =& $manager->getPlugin('NP_TagEX');
771 $requestTag = $tplugin->getNoDecodeQuery('tag');
772 if (!empty($requestTag) || $skin_type == 'item') {
773 $this->tagSelected = TRUE;
774 if ($bmode == 'all') {
775 $allTags = $tplugin->scanExistTags(0);
777 $allTags = $tplugin->scanExistTags(2);
779 $arr = $tplugin->splitRequestTags($requestTag);
780 if ($skin_type == 'item') {
781 $item =& $manager->getItem(intval($itemid), 0, 0);
782 $q = 'SELECT * FROM %s WHERE inum = %d';
783 $q = sprintf($q, $tagTable, intval($itemid));
784 $res = sql_query($q);
785 while ($o = mysql_fetch_object($res)) {
786 $temp_tags_array = preg_split('/[\n,]+/', trim($o->itags));
787 for ($i=0; $i < count($temp_tags_array); $i++) {
788 $arr['or'][] = trim($temp_tags_array[$i]);
792 if ($skin_type != 'item') {
793 for ($i=0; $i < count($arr['and']); $i++) {
794 $deTag = $tplugin->_rawdecode($arr['and'][$i]);
795 if ($allTags[$deTag]) {
796 if (empty($inumsand)) {
797 $inumsand = $allTags[$deTag];
799 $inumsand = array_intersect($inumsand, $allTags[$deTag]);
804 if (empty($inumsand)) {
808 if (!empty($inumsand)) {
809 $inumsres = array_values($inumsand);
814 for ($i=0;$i<count($arr['or']);$i++) {
815 if ($skin_type == 'item') {
816 $deTag = $arr['or'][$i];
818 $deTag = $tplugin->_rawdecode($arr['or'][$i]);
819 if ($allTags[$deTag]) {
820 $inumsor = array_merge($inumsor, $allTags[$deTag]);
823 if ($inumsres && $inumsor) {
824 $inumsres = array_merge($inumsres, $inumsor);
825 $inumsres = array_unique($inumsres);
826 } elseif (!$inumsres && $inumsor) {
827 $inumsres = array_unique($inumsor);
830 if ($skin_type == 'item') {
831 foreach ($inumsres as $resinum) {
833 $q = 'SELECT itags FROM %s WHERE inum = %d';
834 $q = sprintf($q, $tagTable, intval($resinum));
835 $res = sql_query($q);
836 while ($o = mysql_fetch_object($res)) {
837 $resTags = preg_split("/[\n,]+/", trim($o->itags));
838 for ($i=0; $i < count($resTags); $i++) {
839 $iTags[] = trim($resTags[$i]);
842 $relatedTags = array_intersect($arr['or'], $iTags);
843 $tagCount[$resinum] = count($relatedTags);
847 foreach ($tagCount as $resinum => $val) {
848 $relatedInums[] = intval($resinum);
850 for ($i=0; $i < =$p_amount; $i++) {
851 $inumsres[$i] = array_pop($relatedInums);
854 $where .= ' and i.inumber IN ('. @join(',', $inumsres) . ')';
856 $where .= ' and i.inumber=0';
861 'inumsres' => $inumsres