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://japan.nucleuscms.org/wiki/plugins:showblogs
19 * 2.66.1 fix sticky mode
20 * 2.66 default argument bug fix
21 * 2.65 add AD code control
24 * 2.64 fix page switch URL generate
25 * 2.62 security fix and tag related
29 ****************************************************************************
31 * THESE PLUG-INS ARE DEDICATED TO ALL THOSE NucleusCMS USERS
32 * WHO FIGHT CORRUPTION AND IRRATIONAL IN EVERY DAY OF THEIR LIVES.
34 ****************************************************************************/
36 class NP_ShowBlogs extends NucleusPlugin
44 function getMinNucleusVersion()
51 return 'Taka + nakahara21 + kimitake + shizuki';
56 return 'http://japan.nucleuscms.org/wiki/plugins:showblogs';
64 function getDescription()
69 function supportsFeature($what)
72 case 'SqlTablePrefix':
79 function getEventList()
88 $language = ereg_replace( '[\\|/]', '', getLanguageName());
89 if (file_exists($this->getDirectory() . $language . '.php')) {
90 include_once($this->getDirectory() . $language . '.php');
92 include_once($this->getDirectory() . 'english.php');
98 // $this->createOption('catnametoshow', '[allblog mode only] category name to show (0:catname on blogname, 1:catname only, 2:blogname only)','text','0');
99 // $this->createOption('stickmode', '[currentblog mode only] 0:show all stickyID, 1:show current blog stickyID only', 'text', '1');
100 // $this->createOption('ads', '[Ads code] code displayed under first and second item of the page', 'textarea', '' . "\n");
102 $this->createOption('catformat', _CAT_FORMAT, 'text', '<%category%> on <%blogname%>');
103 // $this->createOption('catnametoshow', CATNAME_SHOW, 'text', '0');
104 // $this->createOption('stickmode', _STICKMODE, 'text', '1');
105 $this->createOption('stickmode', _STICKMODE, 'select', '1', _STICKSELECT);
106 $this->createOption('ads', _ADCODE_1, 'textarea', '' . "\n");
107 $this->createOption('ads2', _ADCODE_2, 'textarea', '' . "\n");
108 $this->createOption('tagMode', _TAG_MODE, 'select', '2', _TAG_SELECT);
109 /* todo can't install ? only warning ?
110 * douyatte 'desc' ni keikoku wo daseba iinoka wakaranai desu
111 $ver_min = (getNucleusVersion() < $this->getMinNucleusVersion());
112 $pat_min = ((getNucleusVersion() == $this->getMinNucleusVersion()) &&
113 (getNucleusPatchLevel() < $this->getMinNucleusPatchLevel()));
114 if ($ver_min) { // || $pat_min) {
116 // uninstall plugin again...
117 include_once($DIR_LIBS . 'ADMIN.php');
118 $admin = new ADMIN();
119 $admin->deleteOnePlugin($this->getID());
122 $admin->error(_ERROR_NUCLEUSVERSIONREQ .
123 $this->getMinNucleusVersion() . ' patch ' .
124 $this->getMinNucleusPatchLevel());
130 function doSkinVar($skinType,
131 $template = 'default/index',
132 $amount = 10, // amount/page
133 $bmode = '', // show or hide Blogs
134 $type = 1, // pagw switch type
135 $sort = 'DESC', // item sort mode (DESC or ASC)
136 $sticky = '', // sticky item id
138 $catmode = 'all', // show or hide categories
139 $showAdCode = 1, // AdCode switch
140 $catStick = 0 // show sticky item when category selected ?
143 global $manager, $CONF, $blog, $blogid, $catid, $itemid, $archive, $subcatid;
146 $template = 'default/index';
149 // initialize hide blogID
151 // initialize show blogID
153 // limit number of pages(months)
156 $catformat = $this->getOption('catformat');
158 $params = func_get_args();
165 if (is_numeric($params[3]) ||is_float($params[3])) {
171 if (preg_match("/^(<>)?([0-9\/]+)$/", $bmode, $matches)) {
173 $hide = explode("/", $matches[2]);
177 $show = explode("/", $matches[2]);
182 $type = (float) $type;
183 $typeExp = intval(($type - floor($type))*10); //0 or 1 or 9
184 $this->showAdCode = $showAdCode;
186 list ($pageamount, $offset) = sscanf($amount, '%d(%d)');
191 if ($sort != 'ASC') {
195 /* if ($sort != 'ASC' && $sort != 'DESC') {
196 $sticktemplate = $sticky;
201 if (!empty($sticky) && empty($sticktemplate)) {
202 $sticktemplate = $template;
205 if (preg_match("/^(<>)?([0-9\/]+)$/", $catmode, $matches)) {
207 $hideCat = explode("/", $matches[2]);
211 $showCat = explode("/", $matches[2]);
219 $b =& $manager->getBlog($CONF['DefaultBlog']);
221 $this->nowbid = $nowbid = intval($b->getID());
226 if ($bmode != 'all') {
227 $where .= ' AND i.iblog = ' . $nowbid;
228 } elseif (isset($hide[0]) && $bmode == 'all') {
229 foreach ($hide as $val) {
230 if (!is_numeric($val)) {
231 $val = getBlogIDFromName(intval($val));
233 $where .= ' AND i.iblog != ' . intval($val);
236 } elseif (isset($show[0]) && $bmode == 'all') {
237 foreach ($show as $val) {
238 if (!is_numeric($val)) {
239 $val = getBlogIDFromName(intval($val));
243 $catblogname = (count($w) > 1) ? 1 : 0;
244 $where .= ' AND i.iblog in (' . implode(',', $w) . ')';
247 if (isset($hidecat[0]) && $catmode == 'all') {
248 foreach($hideCat as $val){
249 if(!is_numeric($val)){
250 $val = getCatIDFromName(intval($val));
252 $where .= ' AND i.icat != ' . intval($val);
255 } elseif (isset($showCat[0]) && $catmode == 'all') {
256 foreach ($showCat as $val) {
257 if (!is_numeric($val)) {
258 $val = getBlogIDFromName(intval($val));
262 $catblogname = (count($w) > 1) ? 1 : 0;
263 $where .= ' AND i.icat in (' . implode(',', $w) . ')';
265 // $stickWhere = $where;
267 if ($skinType == 'item' || $skinType == 'index' || $skinType == 'archive') {
268 $catformat = '"' . addslashes($catformat) . '"';
279 $catformat = preg_replace($fArr, $nArr, $catformat);
281 if ($manager->pluginInstalled('NP_TagEX')) {
282 $t_where = $this->_getTagsInum($where, $skinType, $bmode, $amount);
283 $where .= $t_where['where'];
286 if ($skinType == 'item') {
287 $where .= ' and i.inumber != ' . intval($itemid);
290 $sticCatFlag = (!$catid || (!empty($catStick) && $sticktemplate != ''));
291 // if (!$catid && $sticky != '') {
292 if ($sticCatFlag && $sticky != '') {
293 $stickys = explode('/', $sticky);
294 foreach ($stickys as $stickynumber) {
295 $where .= ' AND i.inumber <> ' . intval($stickynumber);
300 $temp = $y = $m = $d = '';
302 sscanf($archive, '%d-%d-%d', $y, $m, $d);
304 $timestamp_start = mktime(0, 0, 0, $m, $d, $y);
305 $timestamp_end = mktime(0, 0, 0, $m, $d+1, $y);
306 $date_str = 'SUBSTRING(i.itime, 1, 10)';
308 $timestamp_start = mktime(0, 0, 0, $m, 1, $y);
309 $timestamp_end = mktime(0, 0, 0, $m+1, 1, $y);
310 $date_str = 'SUBSTRING(i.itime,1,7)';
312 $where .= ' AND i.itime >= ' . mysqldate($timestamp_start)
313 . ' AND i.itime < ' . mysqldate($timestamp_end);
314 } elseif (!empty($monthlimit)) {
315 $timestamp_end = mysqldate($b->getCorrectTime());
316 sscanf($timestamp_end, '"%d-%d-%d %s"', $y, $m, $d, $temp);
317 $timestamp_start = mktime(0, 0, 0, $m-$monthlimit, $d, $y);
318 $where .= ' AND i.itime >= ' . mysqldate($timestamp_start)
319 . ' AND i.itime <= ' . $timestamp_end;
321 $where .= ' AND i.itime <= ' . mysqldate($b->getCorrectTime());
324 if (!empty($catid)) {
325 if ($manager->pluginInstalled('NP_MultipleCategories')) {
326 $mcat_query = $this->_getSubcategoriesWhere($catid);
327 $mtable = $mcat_query['m'];
328 $where .= $mcat_query['w'];
330 $where .= ' AND i.icat=' . intval($catid);
332 $linkparams['catid'] = $todayparams['catid'] = intval($catid);
336 $page_switch = $this->PageSwitch($type, $pageamount, $offset, $where, $sort, $mtable);
337 if ($typeExp != 9 && $skinType != 'item') {
338 echo $page_switch['buf'];
343 $sh_query = 'SELECT '
344 . 'i.inumber as itemid, '
345 . 'i.ititle as title, '
346 . 'i.ibody as body, '
347 . 'm.mname as author, '
348 . 'm.mrealname as authorname, '
349 . 'UNIX_TIMESTAMP(i.itime) as timestamp, '
351 . 'i.imore as more, '
352 . 'm.mnumber as authorid,';
354 $sh_query .= ' c.cname as category,';
356 $sh_query .= ' concat(' . $catformat . ') as category,';
358 $sh_query .= ' i.icat as catid,'
359 . ' i.iclosed as closed'
361 . sql_table('member') . ' as m, '
362 . sql_table('category') . ' as c, '
363 . sql_table('item') . ' as i'
365 if ($bmode == 'all') {
366 $sh_query .= ', ' . sql_table('blog') . ' as b ';
368 $sh_query .= ' WHERE i.iauthor = m.mnumber'
369 . ' AND i.icat = c.catid';
370 if ($bmode == 'all') {
371 $sh_query .= ' AND b.bnumber = c.cblog';
374 // if ($page_switch['startpos'] == 0 && !$catid && $sticky != '' && $skinType != 'item' && !$this->tagSelected) {
376 $sticCatFlag = ($page_switch['startpos'] == 0 && (!$catid || (!empty($catStick) && $sticktemplate != '')));
377 if ($sticCatFlag && $sticky != '' && $skinType != 'item' && !$this->tagSelected) {
378 foreach ($stickys as $stickynumber) {
379 $sticky_query = $sh_query;
380 $tempblogid = getBlogIDFromItemID($stickynumber);
381 if ($bmode != 'all' && $this->getOption('stickmode') == 1) {
382 $sticky_query .= ' AND i.iblog = ' . $nowbid;
384 $sticky_query .= ' AND i.inumber = ' . intval($stickynumber)
385 . ' AND i.itime <= ' . mysqldate($b->getCorrectTime())
386 . ' AND i.idraft = 0';
388 $sticky_query .= ' AND i.icat = ' . intval($catid);
391 $sticky_query .= ' AND p.subcategories = ' . intval($subcatid);
393 /* $sticky_query .= $stickWhere;
394 if ($bmode == 'all') {
395 $b->showUsingQuery($sticktemplate, $sticky_query, 0, 1, 0);
396 } elseif ($this->getOption('stickmode') == 1 && intval($nowbid) == $tempblogid) {
397 $b->showUsingQuery($sticktemplate, $sticky_query, 0, 1, 0);
398 } elseif (!$this->getOption('stickmode')) {
399 $b->showUsingQuery($sticktemplate, $sticky_query, 0, 1, 0);
404 ($this->getOption('stickmode') == 1 && intval($nowbid) == $tempblogid) ||
405 (!$this->getOption('stickmode'))
407 $b->showUsingQuery($sticktemplate, $sticky_query, 0, 1, 0);
410 //echo $stickynumber;
411 if ($showAdCode > 0 && mysql_num_rows(sql_query($sticky_query))) {
413 echo $this->getOption('ads');
414 } elseif ($ads == 1) {
415 echo $this->getOption('ads2');
416 } elseif ($ads >= 2) {
423 $sh_query .= ' AND i.idraft = 0' . $where;
425 if ($skinType == 'item') {
426 $sh_query .= ' ORDER BY FIND_IN_SET(i.inumber,\'' . @join(',', $t_where['inumsres']) . '\')';
428 $sh_query .= ' ORDER BY i.itime ' . $sort;
431 if ($skinType != 'item') {
432 $this->_showUsingQuery($template, $sh_query, $page_switch['startpos'], $pageamount, $b, $ads);
433 if ($type >= 1 && $typeExp != 1) echo $page_switch['buf'];
434 } elseif ($skinType == 'item') {
435 $sh_query .= ' LIMIT 0, ' . $pageamount;
436 $b->showUsingQuery($template, $sh_query, 0, 1, 1);
441 function _showUsingQuery($template, $showQuery, $q_startpos, $q_amount, $b, $ads)
444 $onlyone_query = $showQuery . ' LIMIT ' . intval($q_startpos) .', 1';
445 $b->showUsingQuery($template, $onlyone_query, 0, 1, 1);
446 if (intval($ads) == 0 && $this->showAdCode > 0) {
447 echo $this->getOption('ads');
449 //------------SECOND AD CODE-------------
450 } elseif (intval($ads) == 1 && $this->showAdCode > 0) {
451 echo $this->getOption('ads2');
455 if ($q_amount < 0) return;
456 $onlyone_query = $showQuery . ' LIMIT ' . intval($q_startpos) . ', 1';
457 $b->showUsingQuery($template, $onlyone_query, 0, 1, 1);
458 if (mysql_num_rows(sql_query($onlyone_query)) && empty($ads) && $this->showAdCode > 0) {
459 echo $this->getOption('ads2');
461 //------------SECOND AD CODE END-------------
464 if ($q_amount <= 0) return;
465 $second_query = $showQuery . ' LIMIT ' . intval($q_startpos) . ',' . intval($q_amount);
466 $b->showUsingQuery($template, $second_query, 0, 1, 1);
469 function event_InitSkinParse($data)
471 global $CONF, $manager;
472 $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
473 if (serverVar('REQUEST_URI') == '') {
474 $uri = (serverVar('QUERY_STRING')) ?
475 serverVar('SCRIPT_NAME') . serverVar('QUERY_STRING') : serverVar('SCRIPT_NAME');
477 $uri = serverVar('REQUEST_URI');
479 $page_str = ($usePathInfo) ? 'page/' : 'page=';
480 if ($manager->pluginInstalled('NP_CustomURL') || $manager->pluginInstalled('NP_Magical')) {
483 list($org_uri, $currPage) = explode($page_str, $uri, 2);
484 if (getVar('page')) {
485 $currPage = intGetVar('page');
487 $_GET['page'] = intval($currPage);
488 $this->currPage = intval($currPage);
489 $this->pagestr = $page_str;
492 function PageSwitch($type, $pageamount, $offset, $where, $sort, $mtable = '')
494 global $CONF, $manager, $archive, $catid, $subcatid;
498 $catid = intval($catid);
499 $subcatid = intval($subcatid);
500 $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
501 $pageamount = intval($pageamount);
502 $offset = intval($offset);
505 sscanf($archive, '%d-%d-%d', $y, $m, $d);
507 $archive = sprintf('%04d-%02d-%02d', $y, $m, $d);
509 $archive = sprintf('%04d-%02d', $y, $m);
513 $page_str = $this->pagestr;
514 $currentpage = $this->currPage;
517 if (!empty($catid)) {
518 $catrequest = ($usePathInfo) ? $CONF['CategoryKey'] : 'catid';
519 if (!empty($subcatid)) {
520 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
521 $subrequest = $mplugin->getRequestName(array());
522 if (!empty($archive)) {
524 $catrequest => $catid,
525 $subrequest => $subcatid
527 $pagelink = createArchiveLink($archive, $linkParam);
530 $subrequest => $subcatid
532 $pagelink = createCategoryLink($catid, $linkParam);
535 if (!empty($archive)) {
537 $catrequest => $catid,
539 $pagelink = createArchiveLink($archive, $linkParam);
541 $pagelink = createCategoryLink($catid);
545 if (!empty($archive)) {
546 $pagelink = createArchiveLink($this->nowbid, $archive);
548 $pagelink = createBlogidLink($this->nowbid);
551 if ($manager->pluginInstalled('NP_TagEX')) {
552 $tplugin =& $manager->getPlugin('NP_TagEX');
553 $requestTag = $tplugin->getNoDecodeQuery('tag');
554 if (!empty($requestTag)) {
555 $requestTarray = $tplugin->splitRequestTags($requestTag);
556 $tag = array_shift($requestTarray['and']);
557 $tag = $tplugin->_rawdecode($tag);
558 if (!empty($requestTarray['and'])) {
559 $requestT = implode('+', $requestTarray['and']);
561 if (!empty($requestTarray['or'])) {
562 $requestTor = implode(':', $requestTarray['or']);
564 if (!empty($requestT)) {
565 if (!empty($requestTor)) {
566 $reqtags = $requestT . ':' . $requestTor;
567 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'), $reqtags, '+');
569 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'), $requestT, '+');
571 } elseif (empty($requestT) && !empty($requestTor)) {
572 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'), $requestTor, ':');
574 $pagelink = $tplugin->creatTagLink($tag, $this->getOption('tagMode'));
579 if (strstr ($pagelink, '//')) {
580 $pagelink = preg_replace("/([^:])\/\//", "$1/", $pagelink);
582 $uri = parse_url($pagelink);
584 if ($pagelink == $CONF['BlogURL']) { // add
586 } elseif ($uri['query']) {
587 $pagelink .= '&';
589 $pagelink = str_replace('&&', '&', $pagelink);
590 } elseif ($usePathInfo && substr($pagelink, -1) != '/') {
592 $pagelink .= '&';
596 if (strstr ($pagelink, '//')) $link = preg_replace("/([^:])\/\//", "$1/", $pagelink);
600 if ($currentpage > 0) {
601 $startpos = ($currentpage - 1) * $pageamount;
607 if (is_numeric($where)) {
608 $totalamount = $where;
609 } elseif (is_array($where)) {
610 $totalamount = count($where);
612 $p_query = 'SELECT COUNT(i.inumber) FROM %s as i%s WHERE i.idraft = 0%s';
613 $p_query = sprintf($p_query, sql_table('item'), $mtable, $where);
614 // $p_query = 'SELECT COUNT(i.inumber) FROM ' . sql_table('item') . ' as i' . $mtable . ' WHERE i.idraft=0' . $where;
615 $entries = sql_query($p_query);
616 if ($row = mysql_fetch_row($entries)) {
617 $totalamount = $row[0];
620 $totalamount = intval($totalamount);
621 if (!$archive && !empty($pagelimit) && ($pagelimit * $pageamount < $totalamount)) {
622 $totalamount = intval($pagelimit) * $pageamount;
625 $startpos += $offset;
626 $totalamount -= $offset;
628 if ($this->maxamount && $this->maxamount < $totalamount) {
629 $totalamount = intval($this->maxamount);
631 $totalpages = ceil($totalamount/$pageamount);
632 $totalpages = intval($totalpages);
633 if ($startpos > $totalamount) {
634 $currentpage = $totalpages;
635 $startpos = $totalamount-$pageamount;
638 $startpos += $offset;
639 $totalamount -= $offset;
641 $totalpages = ceil($totalamount/$pageamount);
642 if ($startpos > $totalamount) {
643 $currentpage = $totalpages;
644 $startpos = $totalamount-$pageamount;
646 $prevpage = ($currentpage > 1) ? $currentpage - 1 : 0;
647 $nextpage = $currentpage + 1;
648 $firstpagelink = $pagelink . $page_str . '1';
649 if ($page_str == 'page_') {
650 $firstpagelink .= '.html';
652 $lastpagelink = $pagelink . $page_str . $totalpages;
653 if ($page_str == 'page_') {
654 $lastpagelink .= '.html';
658 $buf .= '<div class="pageswitch">' . "\n";
659 // $buf .= "<a rel=\"first\" title=\"first page\" href=\"{$firstpagelink}\"><TOP></a> | \n";
660 if (!empty($prevpage)) {
661 $prevpagelink = $pagelink . $page_str . $prevpage;
662 if ($page_str == 'page_') {
663 $prevpagelink .= '.html';
665 $buf .= '<a href="' . $prevpagelink . '" title="Previous page" rel="Prev">«Prev</a> |';
666 } elseif ($type >= 2) {
667 $buf .= "«Prev |";
670 if (intval($type) == 2) {
671 $sepstr = '·';
673 for ($i=1; $i<=$totalpages; $i++) {
674 $i_pagelink = $pagelink . $page_str . $i;
675 if ($page_str == 'page_') {
676 $i_pagelink .= '.html';
678 if ($i == $currentpage) {
679 $buf .= ' <strong>' . $i . '</strong> |' . "\n";
680 } elseif ($totalpages<10 || $i<4 || $i>$totalpages-3) {
681 $buf .= ' <a href="' . $i_pagelink . '" title="Page No.' . $i . '">'
682 . $i . '</a> |' . "\n";
684 if ($i<$currentpage-1 || $i>$currentpage+1) {
685 if (($i == 4 && ($currentpage > 5 || $currentpage == 1)) || $i == $currentpage + 2) {
690 $buf .= ' <a href="' . $i_pagelink . '" title=\"Page No.' . $i . '">'
691 . $i . '</a> |' . "\n";
697 if (intval($type) == 3) {
699 $sepstr = '·';
700 for ($i = 1; $i <= $totalpages; $i++) {
701 $i_pagelink = $pagelink . $page_str . $i;
702 if ($page_str == 'page_') {
703 $i_pagelink .= '.html';
706 if ($i == $currentpage) {
707 $buf .= ' <strong>' . $i . '</strong> ' . $sepstr . "\n";
708 } elseif ($totalpages < 10 || ($i < ($currentpage + $paging) && ($currentpage - $paging) < $i)) {
709 $buf .= ' <a href="' . $i_pagelink . '" title="Page No.' . $i . '">'
710 . $i . '</a> ' . $sepstr . "\n";
711 } elseif ($currentpage - $paging == $i) {
714 } elseif ($currentpage + $paging == $i) {
716 $buf = preg_replace('/$sepstr$/', '', $buf);
721 if ($totalpages >= $nextpage) {
722 $nextpagelink = $pagelink . $page_str . $nextpage;
723 if ($page_str == 'page_') {
724 $nextpagelink .= '.html';
726 $buf .= '| <a href="' . $nextpagelink . '" title="Next page" rel="Next">Next»</a>' . "\n";
727 } elseif ($type >= 2) {
728 $buf .= "| Next»\n";
730 // $buf .= " | <a rel=\"last\" title=\"Last page\" href=\"{$lastpagelink}\"><LAST></a>\n";
732 return array('buf' => $buf, 'startpos' => intval($startpos));
736 function _getSubcategoriesWhere($catid)
739 $subcatTable = sql_table('plug_multiple_categories_sub');
741 $mwhere = ' AND ((i.inumber = p.item_id'
742 . ' AND (p.categories REGEXP "(^|,)' . intval($catid) . '(,|$)"'
743 . ' OR i.icat = ' . intval($catid) . '))'
744 . ' OR (i.icat = ' . intval($catid)
745 . ' AND p.item_id IS NULL))';
746 $mtable = ' LEFT JOIN ' . sql_table('plug_multiple_categories') . ' as p'
747 . ' ON i.inumber = p.item_id';
748 $mplugin =& $manager->getPlugin('NP_MultipleCategories');
749 if (method_exists($mplugin, 'getRequestName')) {
750 $mplugin->event_PreSkinParse(array());
753 $subcatid = intval($subcatid);
755 $mque = 'SELECT * FROM %s WHERE scatid = %d';
756 $tres = sql_query(sprintf($mque, $subcatTable, $subcatid));
757 // $tres = sql_query('SELECT * FROM ' . sql_table('plug_multiple_categories_sub') .
758 // ' WHERE scatid = ' . intval($subcatid));
759 $ra = mysql_fetch_array($tres, MYSQL_ASSOC);
760 if (array_key_exists('parentid', $ra)) {
762 $Children = explode('/', $subcatid . $this->getChildren($subcatid));
765 for ($i=0;$i<count($Children);$i++) {
766 $temp_whr[] = ' p.subcategories REGEXP "(^|,)' . intval($Children[$i]) . '(,|$)" ';
768 $mwhere .= ' AND ( ';
769 $mwhere .= implode(' OR ', $temp_whr);
772 $mwhere .= ' AND p.subcategories REGEXP "(^|,)' . $subcatid . '(,|$)"';
782 function getParents($subcat_id)
784 $subcatTable = sql_table('plug_multiple_categories_sub');
785 $que = 'SELECT scatid, parentid, sname FROM %s WHERE scatid = %d';
786 $que = sprintf($que, $subcatTable, intval($subcat_id));
787 $res = sql_query($que);
788 list($sid, $parent, $sname) = mysql_fetch_row($res);
790 $r = $this->getParent(intval($parent)) . '/' . intval($sid);
797 function getChildren($subcat_id)
799 $subcatTable = sql_table('plug_multiple_categories_sub');
800 $que = 'SELECT scatid, parentid, sname FROM %s WHERE parentid = %d';
801 $que = sprintf($que, $subcatTable, intval($subcat_id));
802 $res = sql_query($que);
803 while ($so = mysql_fetch_object($res)) {
804 $r .= $this->getChildren(intval($so->scatid)) . '/' . intval($so->scatid);
809 function _getTagsInum($where, $skin_type, $bmode, $p_amount)
811 global $manager, $itemid;
812 $tagTable = sql_table('plug_tagex');
813 $tplugin =& $manager->getPlugin('NP_TagEX');
814 $requestTag = $tplugin->getNoDecodeQuery('tag');
815 if (!empty($requestTag) || $skin_type == 'item') {
816 $this->tagSelected = TRUE;
818 $allTags = $tplugin->scanExistTags(0);
820 $allTags = $tplugin->scanExistTags(2);
822 $arr = $tplugin->splitRequestTags($requestTag);
823 if ($skin_type == 'item') {
824 $item =& $manager->getItem(intval($itemid), 0, 0);
825 $q = 'SELECT * FROM %s WHERE inum = %d';
826 $res = sql_query(sprintf($q, $tagTable, intval($itemid)));
827 while ($o = mysql_fetch_object($res)) {
828 $temp_tags_array = preg_split('/[\n,]+/', trim($o->itags));
829 for ($i=0; $i < count($temp_tags_array); $i++) {
830 $arr['or'][] = trim($temp_tags_array[$i]);
834 if ($skin_type != 'item') {
835 for ($i=0; $i < count($arr['and']); $i++) {
836 $deTag = $tplugin->_rawdecode($arr['and'][$i]);
837 if ($allTags[$deTag]) {
838 if (empty($inumsand)) {
839 $inumsand = $allTags[$deTag];
841 $inumsand = array_intersect($inumsand, $allTags[$deTag]);
846 if (empty($inumsand)) {
850 if (!empty($inumsand)) {
851 $inumsres = array_values($inumsand);
856 for ($i=0; $i < count($arr['or']); $i++) {
857 if ($skin_type == 'item') {
858 $deTag = $arr['or'][$i];
860 $deTag = $tplugin->_rawdecode($arr['or'][$i]);
862 if ($allTags[$deTag]) {
863 $inumsor = array_merge($inumsor, $allTags[$deTag]);
866 if ($inumsres && $inumsor) {
867 $inumsres = array_merge($inumsres, $inumsor);
868 $inumsres = array_unique($inumsres);
869 } elseif (!$inumsres && $inumsor) {
870 $inumsres = array_unique($inumsor);
873 if ($skin_type == 'item') {
874 foreach ($inumsres as $resinum) {
876 $q = 'SELECT itags FROM %s WHERE inum = %d';
877 $q = sprintf($q, $tagTable, intval($resinum));
878 $res = sql_query($q);
879 while ($o = mysql_fetch_object($res)) {
880 $resTags = preg_split("/[\n,]+/", trim($o->itags));
881 for ($i=0; $i < count($resTags); $i++) {
882 $iTags[] = trim($resTags[$i]);
885 $relatedTags = array_intersect($arr['or'], $iTags);
886 $tagCount[$resinum] = count($relatedTags);
890 foreach ($tagCount as $resinum => $val) {
891 $relatedInums[] = intval($resinum);
893 for ($i=0; $i <= $p_amount; $i++) {
894 $inumsres[$i] = array_pop($relatedInums);
897 $where .= ' and i.inumber IN ('. @join(',', $inumsres) . ')';
899 $where .= ' and i.inumber=0';
904 'inumsres' => $inumsres