From c2e725c6919f05634b0cafce5cd48cc85ede7af0 Mon Sep 17 00:00:00 2001
From: Tim Gerundt
Date: Mon, 27 Jun 2011 21:47:16 +0200
Subject: [PATCH] Web: Show also last post time from active forum topics
---
htdocs/devinfo/index.php | 7 ++-
htdocs/site/activetopics.php | 103 ++++++++++++++++++++++++++++++-----
2 files changed, 96 insertions(+), 14 deletions(-)
diff --git a/htdocs/devinfo/index.php b/htdocs/devinfo/index.php
index e7964eaee..397defb0c 100644
--- a/htdocs/devinfo/index.php
+++ b/htdocs/devinfo/index.php
@@ -71,7 +71,12 @@ the latest sources in a zip or tgz archive from the github website.
$activetopics = new Forum_ActiveTopics('http://sourceforge.net/apps/phpbb/cppcheck/');
print("\n");
?>
diff --git a/htdocs/site/activetopics.php b/htdocs/site/activetopics.php
index 577825087..686514259 100644
--- a/htdocs/site/activetopics.php
+++ b/htdocs/site/activetopics.php
@@ -59,15 +59,20 @@ class Forum_ActiveTopics {
$html = strip_tags($html, '');
$html = preg_replace(array('#\t#', '#&sid=[a-z0-9]+#'), '', $html);
if (preg_match_all('#(.*?)#im', $html, $matches)) {
- $lastPostUsers = array();
- if (preg_match_all('#\nby (.*?)#i', $html, $lastPosts)) {
- $lastPostUserLinks = $lastPosts[1];
- $lastPostUserNames = $lastPosts[2];
+ $lastPosts = array();
+ if (preg_match_all('#\nby (.*?) ([A-Za-z0-9,: ]+) \n#i', $html, $lastPostMatches)) {
+ $lastPostUserLinks = $lastPostMatches[1];
+ $lastPostUserNames = $lastPostMatches[2];
+ $lastPostTimes = $lastPostMatches[3];
for ($i = 0; $i < count($lastPostUserLinks); $i++) { //for all users...
$link = $this->_forumHome . $lastPostUserLinks[$i];
$name = $lastPostUserNames[$i];
+ $timestamp = strtotime($lastPostTimes[$i]);
+ if ($timestamp === false || $timestamp === -1) {
+ $timestamp = 0;
+ }
- $lastPostUsers[] = new Forum_User($link, $name);
+ $lastPosts[] = new Forum_LastPost(new Forum_User($link, $name), $timestamp);
}
}
$links = $matches[1];
@@ -75,9 +80,9 @@ class Forum_ActiveTopics {
for ($i = 0; $i < count($links); $i++) { //for all topics...
$link = $this->_forumHome . $links[$i];
$title = $titles[$i];
- $lastPostUser = $lastPostUsers[$i];
+ $lastPost = $lastPosts[$i];
- $this->_topics[] = new Forum_Topic($link, $title, $lastPostUser);
+ $this->_topics[] = new Forum_Topic($link, $title, $lastPost);
}
}
}
@@ -98,20 +103,20 @@ class Forum_Topic {
/**
* ...
- * @var Forum_User ...
+ * @var Forum_LastPost ...
*/
- private $_lastPostUser;
+ private $_lastPost;
/**
* ...
* @param string $link ...
* @param string $title ...
- * @param Forum_User $lastPostUser ...
+ * @param Forum_LastPost $lastPost ...
*/
- public function __construct($link, $title, $lastPostUser = null) {
+ public function __construct($link, $title, $lastPost = null) {
$this->_link = $link;
$this->_title = $title;
- $this->_lastPostUser = $lastPostUser;
+ $this->_lastPost = $lastPost;
}
/**
@@ -130,12 +135,36 @@ class Forum_Topic {
return $this->_title;
}
+ /**
+ * ...
+ * @return Forum_LastPost ...
+ */
+ public function getLastPost() {
+ return $this->_lastPost;
+ }
+
/**
* ...
* @return Forum_User ...
+ * @deprecated
*/
public function getLastPostUser() {
- return $this->_lastPostUser;
+ if (!empty($this->_lastPost)) {
+ return $this->_lastPost->getUser();
+ }
+ return null;
+ }
+
+ /**
+ * ...
+ * @return integer ...
+ * @deprecated
+ */
+ public function getLastPostTimestamp() {
+ if (!empty($this->_lastPost)) {
+ return $this->_lastPost->getTimestamp();
+ }
+ return 0;
}
}
@@ -185,4 +214,52 @@ class Forum_User {
return $this->_name;
}
}
+
+class Forum_LastPost {
+ /**
+ * ...
+ * @var Forum_User ...
+ */
+ private $_user;
+
+ /**
+ * ...
+ * @var integer ...
+ */
+ private $_timestamp;
+
+ /**
+ * ...
+ * @param Forum_User $user ...
+ * @param integer $timestamp ...
+ */
+ public function __construct($user, $timestamp) {
+ $this->_user = $user;
+ $this->_timestamp = $timestamp;
+ }
+
+ /**
+ * ...
+ * @return Forum_User ...
+ */
+ public function getUser() {
+ return $this->_user;
+ }
+
+ /**
+ * ...
+ * @return integer ...
+ */
+ public function getTimestamp() {
+ return $this->_timestamp;
+ }
+
+ /**
+ * ...
+ * @return string ...
+ */
+ public function getDate($format) {
+ return date($format, $this->_timestamp);
+ }
+}
?>