From: <ir...@us...> - 2012-10-28 12:36:50
|
Revision: 10240 http://sourceforge.net/p/xoops/svn/10240 Author: irmtfan Date: 2012-10-28 12:36:47 +0000 (Sun, 28 Oct 2012) Log Message: ----------- bug fix: getRead_cookie should return array. bug fix: increment topic_views only if the topic is unread Modified Paths: -------------- XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php XoopsModules/newbb/branches/irmtfan/newbb/class/read.php XoopsModules/newbb/branches/irmtfan/newbb/class/topic.php XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php XoopsModules/newbb/branches/irmtfan/newbb/include/vars.php XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php XoopsModules/newbb/branches/irmtfan/newbb/viewtopic.php Modified: XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/changelog-rev10109.txt 2012-10-28 12:36:47 UTC (rev 10240) @@ -1,3 +1,17 @@ +date 2012-10-28 +=================================== +1- bug fix: getRead_cookie should return array. (important) +in newbb/class/read.php + +2- improve: add LAST_INSERT_ID to enhance the mysql performances +in newbb/class/topic.php + +3- improve: set IP as COOKIE prefix for anonymous users +in newbb/include/vars.php, newbb/viewpost.php, newbb/class/forum.php, newbb/class/topic.renderer.php + +4- bug fix: increment topic_views only if the topic is unread (important) +in newbb/viewtopic.php + date 2012-10-22 =================================== 1- bug fix: viewpost.php?status=new AND viewforum.php?forum=FFF&status=unread and list.topic.php?status=unread when read_mode = 1 (cookie) Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/forum.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -221,23 +221,21 @@ } // END irmtfan use read_uid to find the unread posts when the user is logged in } elseif ($xoopsModuleConfig["read_mode"] == 1) { - // START irmtfan fix read_mode = 1 bugs + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) if ( $time_criterion = max($GLOBALS['last_visit'], $startdate) ) { $criteria_post = ' p.post_time > ' . $time_criterion; // for all users - if (is_object($GLOBALS["xoopsUser"])) { // only for members - $topics = array(); - $topic_lastread = newbb_getcookie('LT', true); - if (count($topic_lastread)>0) { - foreach ($topic_lastread as $id => $time) { - if ($time > $time_criterion) $topics[] = $id; - } + $topics = array(); + $topic_lastread = newbb_getcookie('LT', true); + if (count($topic_lastread)>0) { + foreach ($topic_lastread as $id => $time) { + if ($time > $time_criterion) $topics[] = $id; } - if (count($topics)>0) { - $criteria_extra = ' AND t.topic_id NOT IN (' . implode(",", $topics) . ')'; - } } + if (count($topics)>0) { + $criteria_extra = ' AND t.topic_id NOT IN (' . implode(",", $topics) . ')'; + } } - // END irmtfan fix read_mode = 1 bugs + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) } break; case 'pending': @@ -498,23 +496,21 @@ } // END irmtfan use read_uid to find the unread posts when the user is logged in } elseif ($xoopsModuleConfig["read_mode"] == 1) { - // START irmtfan fix read_mode = 1 bugs + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) if ( $time_criterion = max($GLOBALS['last_visit'], $startdate) ) { $criteria_post = ' p.post_time > ' . $time_criterion; // for all users - if (is_object($GLOBALS["xoopsUser"])) { // only for members - $topics = array(); - $topic_lastread = newbb_getcookie('LT', true); - if (count($topic_lastread)>0) { - foreach ($topic_lastread as $id => $time) { - if ($time > $time_criterion) $topics[] = $id; - } + $topics = array(); + $topic_lastread = newbb_getcookie('LT', true); + if (count($topic_lastread)>0) { + foreach ($topic_lastread as $id => $time) { + if ($time > $time_criterion) $topics[] = $id; } - if (count($topics)>0) { - $criteria_extra = ' AND t.topic_id NOT IN (' . implode(",", $topics) . ')'; - } } + if (count($topics)>0) { + $criteria_extra = ' AND t.topic_id NOT IN (' . implode(",", $topics) . ')'; + } } - // END irmtfan fix read_mode = 1 bugs + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) } break; case 'pending': Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/read.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/read.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/read.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -157,7 +157,8 @@ { $cookie_name = ($this->type == "forum") ? "LF" : "LT"; $cookie_var = $item_id; - $lastview = newbb_getcookie($cookie_name); + // irmtfan set true to return array + $lastview = newbb_getcookie($cookie_name, true); return @$lastview[$cookie_var]; } Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/topic.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/topic.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/topic.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -48,10 +48,10 @@ $this->initVar('poll_id', XOBJ_DTYPE_INT); $this->initVar('topic_tags', XOBJ_DTYPE_SOURCE); } - + // irmtfan add LAST_INSERT_ID to enhance the mysql performances function incrementCounter() { - $sql = 'UPDATE ' . $GLOBALS["xoopsDB"]->prefix('bb_topics') . ' SET topic_views = topic_views + 1 WHERE topic_id =' . $this->getVar('topic_id'); + $sql = 'UPDATE ' . $GLOBALS["xoopsDB"]->prefix('bb_topics') . ' SET topic_views = LAST_INSERT_ID(topic_views + 1) WHERE topic_id =' . $this->getVar('topic_id'); $GLOBALS["xoopsDB"]->queryF($sql); } Modified: XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/class/topic.renderer.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -171,26 +171,24 @@ // END irmtfan change criteria to get from uid p.uid = last post submit user id // User cookie } elseif ($this->config["read_mode"] == 1) { - // START irmtfan fix read_mode = 1 bugs + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) $startdate = !empty($this->vars["since"]) ? (time() - newbb_getSinceTime($this->vars["since"])) : 0; if ( $lastvisit = max($GLOBALS['last_visit'], $startdate) ) { if ( $lastvisit > $startdate ) { $this->query["where"][] = 'p.post_time > ' . $lastvisit; } - if (is_object($GLOBALS["xoopsUser"])) { // only for members - $topics = array(); - $topic_lastread = newbb_getcookie('LT', true); - if (count($topic_lastread)>0) { - foreach ($topic_lastread as $id => $time) { - if ($time > $lastvisit) $topics[] = $id; - } + $topics = array(); + $topic_lastread = newbb_getcookie('LT', true); + if (count($topic_lastread)>0) { + foreach ($topic_lastread as $id => $time) { + if ($time > $lastvisit) $topics[] = $id; } - if (count($topics)>0) { - $this->query["where"][] = ' t.topic_id NOT IN (' . implode(",", $topics) . ')'; - } } + if (count($topics)>0) { + $this->query["where"][] = ' t.topic_id NOT IN (' . implode(",", $topics) . ')'; + } } - // END irmtfan fix read_mode = 1 bugs + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) } break; Modified: XoopsModules/newbb/branches/irmtfan/newbb/include/vars.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/include/vars.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/include/vars.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -15,6 +15,8 @@ } include_once XOOPS_ROOT_PATH.'/modules/newbb/include/functions.ini.php'; mod_loadFunctions("session", "newbb"); +// irmtfan include user functions for newbb_getIP +mod_loadFunctions("user", "newbb"); // NewBB cookie structure /* NewBB cookie storage @@ -36,7 +38,7 @@ $forumCookie['path'] = "/"; $forumCookie['secure'] = false; $forumCookie['expire'] = time() + 3600 * 24 * 30; // one month -$forumCookie['prefix'] = 'newbb_'.((is_object($xoopsUser)) ? $xoopsUser->getVar('uid') : 0); +$forumCookie['prefix'] = 'newbb_'.((is_object($xoopsUser)) ? $xoopsUser->getVar('uid') : '0IP' . newbb_getIP()); // irmtfan IP for anons // 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 Modified: XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/viewpost.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -116,21 +116,19 @@ } elseif ($xoopsModuleConfig["read_mode"] == 1) { $criteria_count->add(new Criteria("post_time", intval($last_visit), ">")); // irmtfan add new criteria $criteria_post->add(new Criteria("p.post_time", intval($last_visit), ">")); // irmtfan add new criteria - // START irmtfan fix read_mode = 1 bugs - if (is_object($GLOBALS["xoopsUser"])) { // only for members - $topics = array(); - $topic_lastread = newbb_getcookie('LT', true); - if (count($topic_lastread)>0) { - foreach ($topic_lastread as $id => $time) { - if ($time > intval($last_visit)) $topics[] = $id; - } + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) + $topics = array(); + $topic_lastread = newbb_getcookie('LT', true); + if (count($topic_lastread)>0) { + foreach ($topic_lastread as $id => $time) { + if ($time > intval($last_visit)) $topics[] = $id; } - if (count($topics)>0) { - $criteria_count->add(new Criteria("topic_id", "(".implode(",",$topics).")", "NOT IN")); - $criteria_post->add(new Criteria("p.topic_id", "(".implode(",",$topics).")", "NOT IN")); - } } - // END irmtfan fix read_mode = 1 bugs + if (count($topics)>0) { + $criteria_count->add(new Criteria("topic_id", "(".implode(",",$topics).")", "NOT IN")); + $criteria_post->add(new Criteria("p.topic_id", "(".implode(",",$topics).")", "NOT IN")); + } + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) //$criteria_status_count->add(new Criteria("approved", 1));// irmtfan commented and removed //$criteria_status_post->add(new Criteria("p.approved", 1));// irmtfan commented and removed } Modified: XoopsModules/newbb/branches/irmtfan/newbb/viewtopic.php =================================================================== --- XoopsModules/newbb/branches/irmtfan/newbb/viewtopic.php 2012-10-28 08:29:50 UTC (rev 10239) +++ XoopsModules/newbb/branches/irmtfan/newbb/viewtopic.php 2012-10-28 12:36:47 UTC (rev 10240) @@ -76,13 +76,6 @@ } else { $topic_obj = $topic_handler->get($topic_id); } -// START irmtfan - jump to last post read -if (empty($post_id) && !empty($xoopsModuleConfig['jump_to_topic_last_post_read_enabled'])) { - $topic_last_post_id_read = newbb_getRead("topic", $topic_id); - if (!empty($topic_last_post_id_read) && $topic_last_post_id_read!=$topic_obj->getVar("topic_last_post_id")) - header("Location: ".$_SERVER['REQUEST_URI']."&post_id=".$topic_last_post_id_read); -} -// END irmtfan - jump to last post read if ( !is_object($topic_obj) || !$topic_id = $topic_obj->getVar('topic_id') ) { $redirect = empty($forum_id) ? XOOPS_URL."/modules/".$xoopsModule->getVar("dirname")."/index.php" : XOOPS_URL."/modules/".$xoopsModule->getVar("dirname")."/viewforum.php?forum={$forum_id}"; @@ -99,6 +92,34 @@ exit(); } +// START irmtfan - find if topic is read or unread - for all users (member and anon) +$topic_is_unread = true; +/* if $xoopsModuleConfig["read_mode"] == 0 || + * never read && $xoopsModuleConfig["read_mode"] == 1 || + * never read && $xoopsModuleConfig["read_mode"] == 2 || + * => $topic_last_post_time_or_id_read = NULL + * if !$xoopsUser && $xoopsModuleConfig["read_mode"] == 2 + * => $topic_last_post_time_or_id_read = false + * if !$xoopsUser && $xoopsModuleConfig["read_mode"] == 1 + * => $topic_last_post_time_or_id_read = lastview(newbb_IP{ip}LT) +*/ +$topic_last_post_time_or_id_read = newbb_getRead("topic", $topic_id); +if ( !empty($topic_last_post_time_or_id_read) ) { + if ( $xoopsModuleConfig["read_mode"] == 1 ) { + $post_handler =& xoops_getmodulehandler('post', 'newbb'); + $post_obj =& $post_handler->get($topic_obj->getVar("topic_last_post_id")); + $topic_is_unread = ( $topic_last_post_time_or_id_read < $post_obj->getVar("post_time") ); + } + if ( $xoopsModuleConfig["read_mode"] == 2 ) { + $topic_is_unread = ( $topic_last_post_time_or_id_read < $topic_obj->getVar("topic_last_post_id") ); + // hack jump to last post read if post_id is empty - is there any better way? + if ( empty($post_id) && !empty($xoopsModuleConfig['jump_to_topic_last_post_read_enabled']) && $topic_is_unread) { + header("Location: ".$_SERVER['REQUEST_URI']."&post_id=" . $topic_last_post_time_or_id_read); + } + } +} +// END irmtfan - find if topic is read or unread - for all users (member and anon) + /* Only admin has access to admin mode */ if (!$isadmin) { $status = ""; @@ -115,8 +136,8 @@ $total_posts = $topic_handler->getPostCount($topic_obj, $status); $postsArray = $topic_handler->getAllPosts($topic_obj, $order, $xoopsModuleConfig['posts_per_page'], $start, $post_id, $status); -//Threadersteller zählt nicht -if (!$xoopsUser || ($xoopsUser->getVar('uid') != $topic_obj->getVar('topic_poster')) ) { +//irmtfan - increment topic_views only if the topic is unread +if ($topic_is_unread) { $topic_obj->incrementCounter(); } newbb_setRead("topic", $topic_id, $topic_obj->getVar("topic_last_post_id")); |