This fairly trivial patch changes URLs like:
http://www.phpbb.com/community/viewtopi ... 4&t=925555
into something like:
Announcements - Londonvasion Registration Now Open!
It does the same with forum links and it adds a username if a link to a specific post was entered.
This is the mod:
Patchfile: http://www.bokt.nl/misc/mods/forumurls.txt
Code: Select all
diff --git a/includes/functions_content.php b/includes/functions_content.php
index 6dde72e..7d9b870 100644
--- a/includes/functions_content.php
+++ b/includes/functions_content.php
@@ -564,7 +564,7 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
$tag = 'l';
$relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url));
$url = $url . '/' . $relative_url;
- $text = ($relative_url) ? $relative_url : $url;
+ $text = fetch_forumtitle($url);
break;
case MAGIC_URL_FULL:
@@ -595,6 +595,76 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
}
/**
+* BartVB Show actual forumname or topic title instead of link to forum URLs
+*/
+function fetch_forumtitle($url)
+{
+ global $db, $auth;
+
+ // Search for relevant URL parameters (preceded by '?' or 'amp;'
+ if(preg_match_all('/(?:\?|&)([ptf])=(\d+)/', $url, $matches))
+ {
+ $post_id = $topic_id = $forum_id = 0;
+ foreach($matches[1] as $set => $param)
+ {
+ switch ($param)
+ {
+ case 'p':
+ $post_id = $matches[2][$set];
+ break;
+ case 't':
+ $topic_id = $matches[2][$set];
+ break;
+ case 'f':
+ $forum_id = $matches[2][$set];
+ break;
+ }
+ }
+
+ if ($forum_id != 0 && !$auth->acl_get('f_read', $forum_id))
+ {
+ return $url;
+ }
+
+ if ($topic_id != 0 || $post_id != 0)
+ {
+ $sql = "SELECT
+ t.forum_id, topic_title, forum_name " . ($post_id != 0 ? ", username" : "") . "
+ FROM " .
+ ($post_id != 0 ? POSTS_TABLE . " p, " . USERS_TABLE . " u, " : "") .
+ TOPICS_TABLE . " t
+ LEFT JOIN " . FORUMS_TABLE . " f ON (t.forum_id = f.forum_id)
+ WHERE " .
+ ($post_id != 0 ? "post_id = $post_id AND p.topic_id = t.topic_id AND p.poster_id = u.user_id " : "topic_id = " . $topic_id);
+ $result = $db->sql_query($sql);
+ if($row = $db->sql_fetchrow($result))
+ {
+ if (!$auth->acl_get('f_read', $row['forum_id']))
+ {
+ return $url;
+ }
+
+ $username = ($post_id != 0) ? $row['username'] . " @ " : '';
+ $forum_abbr = (preg_match('/^(\[.+\])/', $row['forum_name'], $matches)) ? $matches[1] . ' ' : '';
+ return $username . $forum_abbr . $row['topic_title'];
+ }
+ }
+ elseif ($forum_id != 0)
+ {
+ $sql = "SELECT forum_name FROM " . FORUMS_TABLE . " WHERE forum_id = " . $forum_id;
+ $result = $db->sql_query($sql);
+ if ($row = $db->sql_fetchrow($result))
+ {
+ return $row['forum_name'];
+ }
+ }
+ }
+
+ return $url;
+}
+
+
+/**
* make_clickable function
*
* Replace magic urls of form http://xxx.xxx., www.xxx. and [email protected].