Web: Show also last post time from active forum topics
This commit is contained in:
parent
272eb445fb
commit
c2e725c691
|
@ -71,7 +71,12 @@ the latest sources in a zip or tgz archive</a> from the github website.</p>
|
||||||
$activetopics = new Forum_ActiveTopics('http://sourceforge.net/apps/phpbb/cppcheck/');
|
$activetopics = new Forum_ActiveTopics('http://sourceforge.net/apps/phpbb/cppcheck/');
|
||||||
print("<ul class=\"rssfeeditems\">\n");
|
print("<ul class=\"rssfeeditems\">\n");
|
||||||
foreach ($activetopics->getTopics(0, 10) as $topic) { //for all active topics...
|
foreach ($activetopics->getTopics(0, 10) as $topic) { //for all active topics...
|
||||||
print(" <li><a href=\"".$topic->getLink()."\">".$topic->getTitle()."</a><em>last post by <strong>".$topic->getLastPostUser()."</strong></em></li>\n");
|
$lastPostLine = '';
|
||||||
|
if ($topic->getLastPost() != null) {
|
||||||
|
$lastPost = $topic->getLastPost();
|
||||||
|
$lastPostLine = sprintf('last post by <strong>%1$s</strong> at %2$s', $lastPost->getUser(), $lastPost->getDate('Y-m-d H:i'));
|
||||||
|
}
|
||||||
|
print(" <li><a href=\"".$topic->getLink()."\">".$topic->getTitle()."</a> <em>".$lastPostLine."</em></li>\n");
|
||||||
}
|
}
|
||||||
print("</ul>\n");
|
print("</ul>\n");
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -59,15 +59,20 @@ class Forum_ActiveTopics {
|
||||||
$html = strip_tags($html, '<a><dd>');
|
$html = strip_tags($html, '<a><dd>');
|
||||||
$html = preg_replace(array('#\t#', '#&sid=[a-z0-9]+#'), '', $html);
|
$html = preg_replace(array('#\t#', '#&sid=[a-z0-9]+#'), '', $html);
|
||||||
if (preg_match_all('#<a href="\./(.*?)" class="topictitle">(.*?)</a>#im', $html, $matches)) {
|
if (preg_match_all('#<a href="\./(.*?)" class="topictitle">(.*?)</a>#im', $html, $matches)) {
|
||||||
$lastPostUsers = array();
|
$lastPosts = array();
|
||||||
if (preg_match_all('#<dd class="lastpost">\nby <a href="\./(.*?)">(.*?)</a>#i', $html, $lastPosts)) {
|
if (preg_match_all('#<dd class="lastpost">\nby <a href="\./(.*?)">(.*?)</a><a href=".*?"></a> ([A-Za-z0-9,: ]+) \n</dd>#i', $html, $lastPostMatches)) {
|
||||||
$lastPostUserLinks = $lastPosts[1];
|
$lastPostUserLinks = $lastPostMatches[1];
|
||||||
$lastPostUserNames = $lastPosts[2];
|
$lastPostUserNames = $lastPostMatches[2];
|
||||||
|
$lastPostTimes = $lastPostMatches[3];
|
||||||
for ($i = 0; $i < count($lastPostUserLinks); $i++) { //for all users...
|
for ($i = 0; $i < count($lastPostUserLinks); $i++) { //for all users...
|
||||||
$link = $this->_forumHome . $lastPostUserLinks[$i];
|
$link = $this->_forumHome . $lastPostUserLinks[$i];
|
||||||
$name = $lastPostUserNames[$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];
|
$links = $matches[1];
|
||||||
|
@ -75,9 +80,9 @@ class Forum_ActiveTopics {
|
||||||
for ($i = 0; $i < count($links); $i++) { //for all topics...
|
for ($i = 0; $i < count($links); $i++) { //for all topics...
|
||||||
$link = $this->_forumHome . $links[$i];
|
$link = $this->_forumHome . $links[$i];
|
||||||
$title = $titles[$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 $link ...
|
||||||
* @param string $title ...
|
* @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->_link = $link;
|
||||||
$this->_title = $title;
|
$this->_title = $title;
|
||||||
$this->_lastPostUser = $lastPostUser;
|
$this->_lastPost = $lastPost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,12 +135,36 @@ class Forum_Topic {
|
||||||
return $this->_title;
|
return $this->_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ...
|
||||||
|
* @return Forum_LastPost ...
|
||||||
|
*/
|
||||||
|
public function getLastPost() {
|
||||||
|
return $this->_lastPost;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ...
|
* ...
|
||||||
* @return Forum_User ...
|
* @return Forum_User ...
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public function getLastPostUser() {
|
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;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue