function b_sitemap_xhnewbb() { include_once dirname(__FILE__) . '/perm_functions.php'; $db =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); $sitemap = array(); $whr_forum = 'f.forum_id IN (' . implode(',', xhnewbb_get_forums_can_read()) . ')'; $sql = "SELECT c.cat_id,c.cat_title,f.forum_id,f.forum_name FROM " . $db->prefix("xhnewbb_forums") . " f LEFT JOIN " . $db->prefix("xhnewbb_categories") . " c ON f.cat_id=c.cat_id WHERE ({$whr_forum}) ORDER BY c.cat_order, f.forum_weight, f.forum_id"; if (!($result = $db->query($sql))) { die(__LINE__ . 'SQL Error'); } while ($row = $db->fetchArray($result)) { $cat_id = intval($row['cat_id']); if (empty($sitemap['parent'][$cat_id])) { $sitemap['parent'][$cat_id] = array('id' => $cat_id, 'title' => $myts->makeTboxData4Show($row['cat_title']), 'url' => 'index.php?cat=' . $cat_id); } $sitemap['parent'][$cat_id]['child'][] = array('id' => intval($row['forum_id']), 'title' => $myts->makeTboxData4Show($row['forum_name']), 'image' => 2, 'url' => 'viewforum.php?forum=' . intval($row['forum_id'])); } return $sitemap; }
function xhnewbb_search($keywords, $andor, $limit, $offset, $userid) { $db =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); $andor = strtoupper($andor); $userid = intval($userid); // XOOPS Search module $showcontext = empty($_GET['showcontext']) ? 0 : 1; $select4con = $showcontext ? "t.post_text" : "'' AS post_text"; require_once dirname(__FILE__) . '/perm_functions.php'; $whr_forum = "p.forum_id IN (" . implode(",", xhnewbb_get_forums_can_read()) . ")"; $whr_uid = $userid > 0 ? "p.uid={$userid}" : "1"; $whr_query = $andor == 'OR' ? '0' : '1'; if (is_array($keywords)) { foreach ($keywords as $word) { // I know this is not a right escaping, but I can't believe $keywords :-) $word4sql = addslashes(stripslashes($word)); $whr_query .= $andor == 'EXACT' ? ' AND' : ' ' . $andor; $whr_query .= " (p.subject LIKE '%{$word4sql}%' OR t.post_text LIKE '%{$word4sql}%')"; } } $sql = "SELECT p.post_id,p.topic_id,p.post_time,p.uid,p.subject,{$select4con} FROM " . $db->prefix("xhnewbb_posts") . " p LEFT JOIN " . $db->prefix("xhnewbb_posts_text") . " t ON t.post_id=p.post_id LEFT JOIN " . $db->prefix("xhnewbb_forums") . " f ON f.forum_id=p.forum_id WHERE ({$whr_forum}) AND ({$whr_uid}) AND ({$whr_query}) ORDER BY p.post_time DESC"; $result = $db->query($sql, $limit, $offset); $ret = array(); $context = ''; while (list($post_id, $topic_id, $post_time, $uid, $subject, $text) = $db->fetchRow($result)) { // get context for module "search" if (function_exists('search_make_context') && $showcontext) { if (function_exists('easiestml')) { $text = easiestml($text); } $full_context = strip_tags($myts->displayTarea($text, 1, 1, 1, 1, 1)); $context = search_make_context($full_context, $keywords); } $ret[] = array('link' => "viewtopic.php?topic_id={$topic_id}&post_id={$post_id}#forumpost{$post_id}", 'title' => $subject, 'time' => $post_time, 'uid' => $uid, "context" => $context); } return $ret; }
$whr_term .= " (p.subject LIKE '%{$word4sql}%') {$andor}"; break; case 'text': default: $whr_term .= " (pt.post_text LIKE '%{$word4sql}%') {$andor}"; break; } } $whr_term = substr($whr_term, 0, -3); } else { $whr_term = '1'; $term4disp = ''; } // forum_id require_once dirname(__FILE__) . '/include/perm_functions.php'; $whr_forum = "p.forum_id IN (" . implode(",", xhnewbb_get_forums_can_read()) . ")"; $forum = intval(@$_POST['forum']); if (!empty($forum)) { $whr_forum .= "AND p.forum_id={$forum}"; } // uname if (!empty($_POST['search_username'])) { $uname = $myts->stripSlashesGPC($_POST['search_username']); $uname4disp = htmlspecialchars($uname, ENT_QUOTES); $uname4sql = addslashes($uname); $whr_uname = "u.uname='{$uname4sql}'"; } else { $whr_uname = '1'; $uname4disp = ''; } $allowed_sortbys = array("p.post_time", "p.post_time desc", "t.topic_title", "t.topic_title desc", "t.topic_views", "t.topic_views desc", "t.topic_replies", "t.topic_replies desc", "f.forum_name", "f.forum_name desc", "u.uname", "u.uname desc");
function b_xhnewbb_main_show($options) { global $xoopsUser; $max_topics = empty($options[0]) ? 10 : intval($options[0]); $show_fullsize = empty($options[1]) ? false : true; $now_order = empty($options[2]) ? 'time' : trim($options[2]); $now_class = empty($options[3]) ? 'public' : trim($options[3]); $is_markup = empty($options[4]) ? false : true; $posttitle = empty($options[5]) ? false : true; $categories = empty($options[6]) ? array() : explode(',', $options[6]); $db =& Database::getInstance(); $myts =& MyTextSanitizer::getInstance(); $block = array(); $uid = is_object(@$xoopsUser) ? $xoopsUser->getVar('uid') : 0; $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname('xhnewbb'); $config_handler =& xoops_gethandler('config'); $configs = $config_handler->getConfigList($module->mid()); // allow markup or not if (empty($configs['xhnewbb_allow_mark'])) { $is_markup = false; } // use solved or not if (empty($configs['xhnewbb_use_solved'])) { $sel_solved = '1 AS topic_solved'; } else { $sel_solved = 't.topic_solved'; } // order switch ($now_order) { case 'views': $odr = 't.topic_views DESC'; break; case 'replies': $odr = 't.topic_replies DESC'; break; case 'time': default: $odr = 't.topic_time DESC'; break; } // private or public switch ($now_class) { case 'both': $whr_class = "1"; break; case 'private': $whr_class = "f.forum_type=1"; break; case 'public': default: $whr_class = "f.forum_type=0"; break; } // forums can be read by current viewer require_once dirname(dirname(__FILE__)) . '/include/perm_functions.php'; $whr_forum = "t.forum_id IN (" . implode(",", xhnewbb_get_forums_can_read()) . ")"; // categories if (empty($categories)) { $whr_categories = '1'; $block['categories'] = ''; } else { for ($i = 0; $i < count($categories); $i++) { $categories[$i] = intval($categories[$i]); } $whr_categories = 'f.cat_id IN (' . implode(',', $categories) . ')'; $block['categories'] = implode(',', $categories); } if ($uid > 0 && $is_markup) { $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.topic_time, t.topic_views, t.topic_replies, {$sel_solved}, t.forum_id, f.forum_name, p.post_id, p.uid, p.subject, u2t.u2t_marked FROM " . $db->prefix("xhnewbb_topics") . " t LEFT JOIN " . $db->prefix("xhnewbb_forums") . " f ON f.forum_id=t.forum_id LEFT JOIN " . $db->prefix("xhnewbb_posts") . " p ON p.topic_id=t.topic_id AND p.post_time >= t.topic_time-2 LEFT JOIN " . $db->prefix("xhnewbb_users2topics") . " u2t ON u2t.topic_id=t.topic_id AND u2t.uid={$uid} WHERE ({$whr_class}) AND ({$whr_forum}) AND ({$whr_categories}) ORDER BY u2t.u2t_marked<=>1 DESC , {$odr}"; } else { $query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.topic_time, t.topic_views, t.topic_replies, {$sel_solved}, t.forum_id, f.forum_name, p.post_id, p.uid, p.subject, 0 AS u2t_marked FROM " . $db->prefix("xhnewbb_topics") . " t LEFT JOIN " . $db->prefix("xhnewbb_forums") . " f ON f.forum_id=t.forum_id LEFT JOIN " . $db->prefix("xhnewbb_posts") . " p ON p.topic_id=t.topic_id AND p.post_time >= t.topic_time-2 WHERE ({$whr_class}) AND ({$whr_forum}) AND ({$whr_categories}) ORDER BY {$odr}"; } if (!($result = $db->query($query, $max_topics, 0))) { return false; } $block['full_view'] = $show_fullsize; $block['disp_last_subject'] = $posttitle; $block['lang_forum'] = _MB_XHNEWBB_FORUM; $block['lang_topic'] = _MB_XHNEWBB_TOPIC; $block['lang_replies'] = _MB_XHNEWBB_RPLS; $block['lang_views'] = _MB_XHNEWBB_VIEWS; $block['lang_lastpost'] = _MB_XHNEWBB_LPOST; $block['lang_visitforums'] = _MB_XHNEWBB_VSTFRMS; $block['lang_listalltopics'] = _MB_XHNEWBB_LISTALLTOPICS; while ($arr = $db->fetchArray($result)) { $topic['forum_id'] = $arr['forum_id']; $topic['forum_name'] = $myts->makeTboxData4Show($arr['forum_name']); $topic['id'] = $arr['topic_id']; $topic['title'] = $myts->makeTboxData4Show($arr['topic_title']); $topic['replies'] = $arr['topic_replies']; $topic['views'] = $arr['topic_views']; $topic['post_id'] = $arr['topic_last_post_id']; // $lastpostername = $db->query("SELECT post_id, uid, subject FROM ".$db->prefix("xhnewbb_posts")." WHERE post_id = ".$topic['post_id']); // while ($tmpdb=$db->fetchArray($lastpostername)) { // $tmpuser = XoopsUser::getUnameFromId($tmpdb['uid']); // if ( $options[1] != 0 ) { // $topic['time'] = formatTimestamp($arr['topic_time'],'m')." $tmpuser"; // Ryuji_edit(2003-11-11) hack start $topic['date'] = formatTimestamp($arr['topic_time'], 'm'); $topic['poster'] = XoopsUser::getUnameFromId($arr['uid']); $topic['last_subject'] = $myts->makeTboxData4Show($arr['subject']); // Ryuji_edit(2003-11-11) hack end // } // } $topic['solved'] = $arr['topic_solved']; $topic['u2t_marked'] = $arr['u2t_marked']; $block['topics'][] =& $topic; unset($topic); } return $block; }