2011-06-24 18:34:48 +02:00
|
|
|
<?php
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
class Forum_ActiveTopics {
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @var string ...
|
|
|
|
*/
|
|
|
|
private $_forumHome;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @var array ...
|
|
|
|
*/
|
|
|
|
private $_topics;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @param string $forumHome ...
|
|
|
|
*/
|
|
|
|
public function __construct($forumHome) {
|
|
|
|
$this->_forumHome = $forumHome;
|
|
|
|
$this->_topics = array();
|
|
|
|
|
|
|
|
$this->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @param int $start ...
|
|
|
|
* @param int $end ...
|
|
|
|
* @return array ...
|
|
|
|
*/
|
|
|
|
public function getTopics($start = 0, $end = 0) {
|
|
|
|
if ($end == 0) {
|
|
|
|
return array_slice($this->_topics, $start);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return array_slice($this->_topics, $start, $end);
|
|
|
|
}
|
|
|
|
//return $this->_topics;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @param int $days ...
|
|
|
|
*/
|
|
|
|
public function update($days = 30) {
|
|
|
|
$this->_topics = array();
|
|
|
|
$html = file_get_contents($this->_forumHome . 'search.php?st=' . $days . '&search_id=active_topics');
|
|
|
|
$html = strip_tags($html, '<a><dd>');
|
|
|
|
$html = preg_replace(array('#\t#', '#&sid=[a-z0-9]+#'), '', $html);
|
|
|
|
if (preg_match_all('#<a href="\./(.*?)" class="topictitle">(.*?)</a>#im', $html, $matches)) {
|
2011-06-27 21:47:16 +02:00
|
|
|
$lastPosts = array();
|
|
|
|
if (preg_match_all('#<dd class="lastpost">\nby <a href="\./(.*?)">(.*?)</a><a href=".*?"></a> ([A-Za-z0-9,: ]+) \n</dd>#i', $html, $lastPostMatches)) {
|
|
|
|
$lastPostUserLinks = $lastPostMatches[1];
|
|
|
|
$lastPostUserNames = $lastPostMatches[2];
|
|
|
|
$lastPostTimes = $lastPostMatches[3];
|
2011-06-24 18:34:48 +02:00
|
|
|
for ($i = 0; $i < count($lastPostUserLinks); $i++) { //for all users...
|
|
|
|
$link = $this->_forumHome . $lastPostUserLinks[$i];
|
|
|
|
$name = $lastPostUserNames[$i];
|
2011-06-27 21:47:16 +02:00
|
|
|
$timestamp = strtotime($lastPostTimes[$i]);
|
|
|
|
if ($timestamp === false || $timestamp === -1) {
|
|
|
|
$timestamp = 0;
|
|
|
|
}
|
2011-06-24 18:34:48 +02:00
|
|
|
|
2011-06-27 21:47:16 +02:00
|
|
|
$lastPosts[] = new Forum_LastPost(new Forum_User($link, $name), $timestamp);
|
2011-06-24 18:34:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$links = $matches[1];
|
|
|
|
$titles = $matches[2];
|
|
|
|
for ($i = 0; $i < count($links); $i++) { //for all topics...
|
|
|
|
$link = $this->_forumHome . $links[$i];
|
|
|
|
$title = $titles[$i];
|
2011-06-27 21:47:16 +02:00
|
|
|
$lastPost = $lastPosts[$i];
|
2011-06-24 18:34:48 +02:00
|
|
|
|
2011-06-27 21:47:16 +02:00
|
|
|
$this->_topics[] = new Forum_Topic($link, $title, $lastPost);
|
2011-06-24 18:34:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Forum_Topic {
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @var string ...
|
|
|
|
*/
|
|
|
|
private $_link;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @var string ...
|
|
|
|
*/
|
|
|
|
private $_title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
2011-06-27 21:47:16 +02:00
|
|
|
* @var Forum_LastPost ...
|
2011-06-24 18:34:48 +02:00
|
|
|
*/
|
2011-06-27 21:47:16 +02:00
|
|
|
private $_lastPost;
|
2011-06-24 18:34:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @param string $link ...
|
|
|
|
* @param string $title ...
|
2011-06-27 21:47:16 +02:00
|
|
|
* @param Forum_LastPost $lastPost ...
|
2011-06-24 18:34:48 +02:00
|
|
|
*/
|
2011-06-27 21:47:16 +02:00
|
|
|
public function __construct($link, $title, $lastPost = null) {
|
2011-06-24 18:34:48 +02:00
|
|
|
$this->_link = $link;
|
|
|
|
$this->_title = $title;
|
2011-06-27 21:47:16 +02:00
|
|
|
$this->_lastPost = $lastPost;
|
2011-06-24 18:34:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @return string ...
|
|
|
|
*/
|
|
|
|
public function getLink() {
|
|
|
|
return $this->_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @return string ...
|
|
|
|
*/
|
|
|
|
public function getTitle() {
|
|
|
|
return $this->_title;
|
|
|
|
}
|
|
|
|
|
2011-06-27 21:47:16 +02:00
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @return Forum_LastPost ...
|
|
|
|
*/
|
|
|
|
public function getLastPost() {
|
|
|
|
return $this->_lastPost;
|
|
|
|
}
|
|
|
|
|
2011-06-24 18:34:48 +02:00
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @return Forum_User ...
|
2011-06-27 21:47:16 +02:00
|
|
|
* @deprecated
|
2011-06-24 18:34:48 +02:00
|
|
|
*/
|
|
|
|
public function getLastPostUser() {
|
2011-06-27 21:47:16 +02:00
|
|
|
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;
|
2011-06-24 18:34:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Forum_User {
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @var string ...
|
|
|
|
*/
|
|
|
|
private $_link;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @var string ...
|
|
|
|
*/
|
|
|
|
private $_name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @param string $link ...
|
|
|
|
* @param string $name ...
|
|
|
|
*/
|
|
|
|
public function __construct($link, $name) {
|
|
|
|
$this->_link = $link;
|
|
|
|
$this->_name = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @return string ...
|
|
|
|
*/
|
|
|
|
public function getLink() {
|
|
|
|
return $this->_link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @return string ...
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
return $this->_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
public function __toString() {
|
|
|
|
return $this->_name;
|
|
|
|
}
|
|
|
|
}
|
2011-06-27 21:47:16 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2011-06-24 18:34:48 +02:00
|
|
|
?>
|