function newbb_synchronization($type = "") { switch ($type) { case "rate": case "report": case "post": case "topic": case "forum": case "category": case "moderate": case "read": $type = array($type); $clean = $type; break; default: $type = null; $clean = array("category", "forum", "topic", "post", "report", "rate", "moderate", "readtopic", "readforum"); break; } foreach ($clean as $item) { $handler =& xoops_getmodulehandler($item, "newbb"); $handler->cleanOrphan(); unset($handler); } $newbbConfig = newbb_load_config(); if (empty($type) || in_array("post", $type)) { $post_handler =& xoops_getmodulehandler("post", "newbb"); $expires = isset($newbbConfig["pending_expire"]) ? intval($newbbConfig["pending_expire"]) : 7; $post_handler->cleanExpires($expires * 24 * 3600); } if (empty($type) || in_array("topic", $type)) { $topic_handler =& xoops_getmodulehandler("topic", "newbb"); $expires = isset($newbbConfig["pending_expire"]) ? intval($newbbConfig["pending_expire"]) : 7; $topic_handler->cleanExpires($expires * 24 * 3600); //$topic_handler->synchronization(); } /* if (empty($type) || in_array("forum", $type)): $forum_handler =& xoops_getmodulehandler("forum", "newbb"); $forum_handler->synchronization(); endif; */ if (empty($type) || in_array("moderate", $type)) { $moderate_handler =& xoops_getmodulehandler("moderate", "newbb"); $moderate_handler->clearGarbage(); } if (empty($type) || in_array("read", $type)) { $read_handler =& xoops_getmodulehandler("readforum", "newbb"); $read_handler->clearGarbage(); //$read_handler->synchronization(); $read_handler =& xoops_getmodulehandler("readtopic", "newbb"); $read_handler->clearGarbage(); //$read_handler->synchronization(); } return true; }
function xoops_module_update_newbb(&$module, $oldversion = null) { load_functions("config"); mod_clearConfg($module->getVar("dirname", "n")); $newbbConfig = newbb_load_config(); //$oldversion = $module->getVar('version'); //$oldconfig = $module->getVar('hasconfig'); // NewBB 1.0 -- no config //if (empty($oldconfig)) { if ($oldversion == 100) { include_once dirname(__FILE__) . "/module.v100.php"; xoops_module_update_newbb_v100($module); } // NewBB 2.* and CBB 1.* // change group permission name // change forum moderators if ($oldversion < 220) { include_once dirname(__FILE__) . "/module.v220.php"; xoops_module_update_newbb_v220($module); } if ($oldversion < 230) { $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . "/modules/" . $module->getVar("dirname", "n") . "/sql/upgrade_230.sql"); //$module->setErrors("bb_moderates table inserted"); } if ($oldversion < 304) { $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . "/modules/" . $module->getVar("dirname", "n") . "/sql/mysql.304.sql"); } if ($oldversion < 400) { $GLOBALS['xoopsDB']->queryFromFile(XOOPS_ROOT_PATH . "/modules/" . $module->getVar("dirname", "n") . "/sql/mysql.400.sql"); include dirname(__FILE__) . "/module.v400.php"; xoops_module_update_newbb_v400($module); } if ($oldversion < 403) { $sql = "\tALTER TABLE " . $GLOBALS['xoopsDB']->prefix("bb_posts") . " CHANGE `poster_ip` `poster_ipd` varchar(15) NOT NULL default '0.0.0.0'"; $GLOBALS['xoopsDB']->queryF($sql); } if (!empty($newbbConfig["syncOnUpdate"])) { mod_loadFunctions("recon", "newbb"); newbb_synchronization(); } return true; }
function newbb_sinceSelectBox($selected = 100) { $newbbConfig = newbb_load_config(); $select_array = explode(',', $newbbConfig['since_options']); $select_array = array_map('trim', $select_array); $forum_selection_since = '<select name="since">'; foreach ($select_array as $since) { $forum_selection_since .= '<option value="' . $since . '"' . ($selected == $since ? ' selected="selected"' : '') . '>'; if ($since > 0) { $forum_selection_since .= sprintf(_MD_FROMLASTDAYS, $since); } else { $forum_selection_since .= sprintf(_MD_FROMLASTHOURS, abs($since)); } $forum_selection_since .= '</option>'; } $forum_selection_since .= '<option value="365"' . ($selected == 365 ? ' selected="selected"' : '') . '>' . _MD_THELASTYEAR . '</option>'; $forum_selection_since .= '<option value="0"' . ($selected == 0 ? ' selected="selected"' : '') . '>' . _MD_BEGINNING . '</option>'; $forum_selection_since .= '</select>'; return $forum_selection_since; }
/** * Function to respond to a trackback */ function newbb_trackback_response($error = 0, $error_message = '') { $moduleConfig = newbb_load_config(); if (!empty($moduleConfig["rss_utf8"])) { $charset = "utf-8"; $error_message = xoops_utf8_encode($error_message); } else { $charset = _CHARSET; } header('Content-Type: text/xml; charset="' . $charset . '"'); if ($error) { echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; echo "<response>\n"; echo "<error>1</error>\n"; echo "<message>{$error_message}</message>\n"; echo "</response>"; die; } else { echo '<?xml version="1.0" encoding="' . $charset . '"?' . ">\n"; echo "<response>\n"; echo "<error>0</error>\n"; echo "</response>"; } }
function checkTimelimit($action_tag = 'edit_timelimit') { $newbb_config = newbb_load_config(); if (empty($newbb_config["edit_timelimit"])) { return true; } return $this->getVar('post_time') > time() - $newbb_config[$action_tag] * 60; }
function b_newbb_author_show($options) { global $xoopsConfig; global $access_forums; $myts =& MyTextSanitizer::getInstance(); $block = array(); $i = 0; $type = "topic"; $order = "count"; $extra_criteria = ""; $time_criteria = null; if (!empty($options[2])) { mod_loadFunctions("time", "newbb"); $time_criteria = time() - newbb_getSinceTime($options[2]); $extra_criteria = " AND topic_time > " . $time_criteria; } switch ($options[0]) { case 'topic': break; case 'digest': $extra_criteria = " AND topic_digest = 1"; if ($time_criteria) { $extra_criteria .= " AND digest_time > " . $time_criteria; } break; case 'sticky': $extra_criteria .= " AND topic_sticky = 1"; break; case 'post': default: $type = "post"; if ($time_criteria) { $extra_criteria = " AND post_time > " . $time_criteria; } break; } $newbbConfig = newbb_load_config(); if (!isset($access_forums)) { $perm_handler =& xoops_getmodulehandler('permission', 'newbb'); if (!($access_forums = $perm_handler->getForums())) { return $block; } } if (!empty($options[5])) { $allowedforums = array_filter(array_slice($options, 5), "b_newbb_array_filter"); // get allowed forums $allowed_forums = array_intersect($allowedforums, $access_forums); } else { $allowed_forums = $access_forums; } if (empty($allowed_forums)) { return false; } if ($type == "topic") { $forum_criteria = ' AND forum_id IN (' . implode(',', $allowed_forums) . ')'; $approve_criteria = ' AND approved = 1'; $query = 'SELECT DISTINCT topic_poster AS author, COUNT(*) AS count FROM ' . $GLOBALS["xoopsDB"]->prefix('bb_topics') . ' WHERE topic_poster>0 ' . $forum_criteria . $approve_criteria . $extra_criteria . ' GROUP BY topic_poster ORDER BY ' . $order . ' DESC'; } else { $forum_criteria = ' AND forum_id IN (' . implode(',', $allowed_forums) . ')'; $approve_criteria = ' AND approved = 1'; $query = 'SELECT DISTINCT uid AS author, COUNT(*) AS count FROM ' . $GLOBALS["xoopsDB"]->prefix('bb_posts') . ' WHERE uid > 0 ' . $forum_criteria . $approve_criteria . $extra_criteria . ' GROUP BY uid ORDER BY ' . $order . ' DESC'; } $result = $GLOBALS["xoopsDB"]->query($query, $options[1], 0); if (!$result) { //xoops_error($GLOBALS["xoopsDB"]->error()); return $block; } $author = array(); while ($row = $GLOBALS["xoopsDB"]->fetchArray($result)) { $author[$row["author"]]["count"] = $row["count"]; } if (count($author) < 1) { return $block; } mod_loadFunctions("user", "newbb"); $author_name = newbb_getUnameFromIds(array_keys($author), $newbbConfig['show_realname']); foreach (array_keys($author) as $uid) { $author[$uid]["name"] = $myts->htmlSpecialChars($author_name[$uid]); } $block['authors'] =& $author; $block['disp_mode'] = $options[3]; // 0 - full view; 1 - lite view; $block['indexNav'] = intval($options[4]); return $block; }
function NewbbReadHandler(&$db, $type) { $type = "forum" == $type ? "forum" : "topic"; $this->ArtObjectHandler($db, 'bb_reads_' . $type, 'Read' . $type, 'read_id', 'post_id'); $this->type = $type; $newbbConfig = newbb_load_config(); $this->lifetime = !empty($newbbConfig["read_expire"]) ? $newbbConfig["read_expire"] * 24 * 3600 : 30 * 24 * 3600; $this->mode = isset($newbbConfig["read_mode"]) ? $newbbConfig["read_mode"] : 2; }
function NewbbReadtopicHandler(&$db) { $this->NewbbReadHandler($db, "topic"); $newbbConfig = newbb_load_config(); $this->items_per_forum = isset($newbbConfig["read_items"]) ? intval($newbbConfig["read_items"]) : 100; }
function &newbb_search($queryarray, $andor, $limit, $offset, $userid, $forums = 0, $sortby = 0, $searchin = "both", $subquery = "") { global $xoopsDB, $xoopsConfig, $myts, $xoopsUser; $uid = is_object($xoopsUser) && $xoopsUser->isactive() ? $xoopsUser->getVar('uid') : 0; $forum_handler =& xoops_getmodulehandler('forum', 'newbb'); $valid_forums = $forum_handler->getIdsByPermission(); if (is_array($forums) && count($forums) > 0) { $valid_forums = array_intersect($valid_forums, $forums); } elseif (is_numeric($forums) && $forums > 0) { $valid_forums = array_intersect($valid_forums, array($forums)); } $sql = 'SELECT p.uid,f.forum_id, p.topic_id, p.poster_name, p.post_time,'; $sql .= ' f.forum_name, p.post_id, p.subject FROM ' . $xoopsDB->prefix('bb_posts') . ' p, ' . $xoopsDB->prefix('bb_posts_text') . ' pt, ' . $xoopsDB->prefix('bb_forums') . ' f'; $sql .= ' WHERE p.post_id = pt.post_id'; $sql .= ' AND p.approved = 1'; $sql .= ' AND p.forum_id = f.forum_id'; // AND p.uid = u.uid'; // In case exists a userid with which the associated user is removed, this line will block search results. Can do nothing unless xoops changes its way dealing with user removal if (!empty($valid_forums)) { $sql .= ' AND f.forum_id IN (' . implode(',', $valid_forums) . ')'; } $isUser = false; if (is_numeric($userid) && $userid != 0) { $sql .= " AND p.uid=" . $userid . " "; $isUser = true; } else { // TODO if (is_array($userid) && count($userid) > 0) { $userid = array_map('intval', $userid); $sql .= " AND p.uid IN (" . implode(',', $userid) . ") "; $isUser = true; } } $count = count($queryarray); if (is_array($queryarray) && $count > 0) { switch ($searchin) { case 'title': $sql .= " AND ((p.subject LIKE '%{$queryarray['0']}%')"; for ($i = 1; $i < $count; $i++) { $sql .= " {$andor} "; $sql .= "(p.subject LIKE '%{$queryarray[$i]}%')"; } $sql .= ") "; break; case 'text': $sql .= " AND ((pt.post_text LIKE '%{$queryarray['0']}%')"; for ($i = 1; $i < $count; $i++) { $sql .= " {$andor} "; $sql .= "(pt.post_text LIKE '%{$queryarray[$i]}%')"; } $sql .= ") "; break; case 'both': default: $sql .= " AND ((p.subject LIKE '%{$queryarray['0']}%' OR pt.post_text LIKE '%{$queryarray['0']}%')"; for ($i = 1; $i < $count; $i++) { $sql .= " {$andor} "; $sql .= "(p.subject LIKE '%{$queryarray[$i]}%' OR pt.post_text LIKE '%{$queryarray[$i]}%')"; } $sql .= ") "; break; } } if (!$sortby) { $sortby = "p.post_time DESC"; } $sql .= $subquery . " ORDER BY " . $sortby; $result = $xoopsDB->query($sql, $limit, $offset); $ret = array(); $users = array(); $i = 0; while ($myrow = $xoopsDB->fetchArray($result)) { $ret[$i]['link'] = "viewtopic.php?topic_id=" . $myrow['topic_id'] . "&forum=" . $myrow['forum_id'] . "&post_id=" . $myrow['post_id'] . "#forumpost" . $myrow['post_id']; $ret[$i]['title'] = $myrow['subject']; $ret[$i]['time'] = $myrow['post_time']; $ret[$i]['uid'] = $myrow['uid']; $ret[$i]['forum_name'] = $myts->htmlSpecialChars($myrow['forum_name']); $ret[$i]['forum_link'] = "viewforum.php?forum=" . $myrow['forum_id']; $users[$myrow['uid']] = 1; $ret[$i]['poster_name'] = $myrow['poster_name']; $i++; } if (count($users) > 0) { $member_handler =& xoops_gethandler('member'); $userid_array = array_keys($users); $user_criteria = "(" . implode(",", $userid_array) . ")"; $users = $member_handler->getUsers(new Criteria('uid', $user_criteria, 'IN'), true); } else { $users = null; } $newbbConfig = newbb_load_config(); $count = count($ret); for ($i = 0; $i < $count; $i++) { if ($ret[$i]['uid'] > 0) { if (isset($users[$ret[$i]['uid']]) && is_object($users[$ret[$i]['uid']]) && $users[$ret[$i]['uid']]->isActive()) { $poster = $newbbConfig['show_realname'] && $users[$ret[$i]['uid']]->getVar('name') ? $users[$ret[$i]['uid']]->getVar('name') : $users[$ret[$i]['uid']]->getVar('uname'); $poster = $myts->htmlSpecialChars($poster); $ret[$i]['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $ret[$i]['uid'] . '">' . $poster . '</a>'; $title = $myts->htmlSpecialChars($ret[$i]['title']); } else { $ret[$i]['poster'] = $xoopsConfig['anonymous']; $ret[$i]['uid'] = 0; // Have to force this to fit xoops search.php } } else { $ret[$i]['poster'] = empty($ret[$i]['poster_name']) ? $xoopsConfig['anonymous'] : $myts->htmlSpecialChars($ret[$i]['poster_name']); $ret[$i]['uid'] = 0; } } unset($users); return $ret; }
function delete(&$topic, $force = true) { $topic_id = is_object($topic) ? $topic->getVar("topic_id") : intval($topic); if (empty($topic_id)) { return false; } $post_obj =& $this->getTopPost($topic_id); $post_handler =& xoops_getmodulehandler('post', 'newbb'); $post_handler->delete($post_obj, false, $force); $newbbConfig = newbb_load_config(); if (!empty($newbbConfig['do_tag']) && ($tag_handler = @xoops_getmodulehandler('tag', 'tag', true))) { $tag_handler->updateByItem(array(), $topic_id, "newbb"); } return true; }
M - Menu mode V - View mode G - Toggle Short term cookie: (same as session life time) ST - Stored Topic IDs for mark LP - Last Post LF - Forum Last view LT - Topic Last read LVT - Last Visit Temp */ /* -- Cookie settings -- */ $forumCookie['domain'] = ""; $forumCookie['path'] = "/"; $forumCookie['secure'] = false; $forumCookie['expire'] = time() + 3600 * 24 * 30; // one month $forumCookie['prefix'] = 'newbb_' . (is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0); // set LastVisitTemp cookie, which only gets the time from the LastVisit cookie if it does not exist yet // otherwise, it gets the time from the LastVisitTemp cookie $last_visit = newbb_getsession("LV"); $last_visit = $last_visit ? $last_visit : newbb_getcookie("LV"); $last_visit = $last_visit ? $last_visit : time(); // update LastVisit cookie. newbb_setcookie("LV", time(), $forumCookie['expire']); // set cookie life time to one month newbb_setsession("LV", $last_visit); // include customized variables if (is_object($GLOBALS["xoopsModule"]) && "newbb" == $GLOBALS["xoopsModule"]->getVar("dirname", "n")) { $GLOBALS["xoopsModuleConfig"] = newbb_load_config(); } newbb_load_object();