From 4ab390e4ee723cce68fbce30323b805a74a5f1c6 Mon Sep 17 00:00:00 2001
From: Tim Gerundt
Date: Fri, 24 Jun 2011 18:34:48 +0200
Subject: [PATCH] Web: Show active forum topics at dev info page
---
htdocs/devinfo/index.php | 12 +++
htdocs/site/activetopics.php | 188 +++++++++++++++++++++++++++++++++++
2 files changed, 200 insertions(+)
create mode 100644 htdocs/site/activetopics.php
diff --git a/htdocs/devinfo/index.php b/htdocs/devinfo/index.php
index 70728ebf8..e7964eaee 100644
--- a/htdocs/devinfo/index.php
+++ b/htdocs/devinfo/index.php
@@ -64,6 +64,18 @@ the latest sources in a zip or tgz archive from the github website.
print("\n");
?>
View complete Trac timeline…
+Active Forum Topics
+\n");
+ foreach ($activetopics->getTopics(0, 10) as $topic) { //for all active topics...
+ print(" getLink()."\">".$topic->getTitle()."last post by ".$topic->getLastPostUser()."\n");
+ }
+ print("\n");
+?>
+View all active topics…
Doxygen
- Output
diff --git a/htdocs/site/activetopics.php b/htdocs/site/activetopics.php
new file mode 100644
index 000000000..577825087
--- /dev/null
+++ b/htdocs/site/activetopics.php
@@ -0,0 +1,188 @@
+_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, '- ');
+ $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];
+ for ($i = 0; $i < count($lastPostUserLinks); $i++) { //for all users...
+ $link = $this->_forumHome . $lastPostUserLinks[$i];
+ $name = $lastPostUserNames[$i];
+
+ $lastPostUsers[] = new Forum_User($link, $name);
+ }
+ }
+ $links = $matches[1];
+ $titles = $matches[2];
+ for ($i = 0; $i < count($links); $i++) { //for all topics...
+ $link = $this->_forumHome . $links[$i];
+ $title = $titles[$i];
+ $lastPostUser = $lastPostUsers[$i];
+
+ $this->_topics[] = new Forum_Topic($link, $title, $lastPostUser);
+ }
+ }
+ }
+}
+
+class Forum_Topic {
+ /**
+ * ...
+ * @var string ...
+ */
+ private $_link;
+
+ /**
+ * ...
+ * @var string ...
+ */
+ private $_title;
+
+ /**
+ * ...
+ * @var Forum_User ...
+ */
+ private $_lastPostUser;
+
+ /**
+ * ...
+ * @param string $link ...
+ * @param string $title ...
+ * @param Forum_User $lastPostUser ...
+ */
+ public function __construct($link, $title, $lastPostUser = null) {
+ $this->_link = $link;
+ $this->_title = $title;
+ $this->_lastPostUser = $lastPostUser;
+ }
+
+ /**
+ * ...
+ * @return string ...
+ */
+ public function getLink() {
+ return $this->_link;
+ }
+
+ /**
+ * ...
+ * @return string ...
+ */
+ public function getTitle() {
+ return $this->_title;
+ }
+
+ /**
+ * ...
+ * @return Forum_User ...
+ */
+ public function getLastPostUser() {
+ return $this->_lastPostUser;
+ }
+}
+
+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;
+ }
+}
+?>