[ABD] Topic title instead of forum link

Any abandoned MODs will be moved to this forum.

WARNING: MODs in this forum are not currently being supported or maintained by the original MOD author. Proceed at your own risk.
Forum rules
IMPORTANT: MOD Development Forum rules

WARNING: MODs in this forum are not currently being supported nor updated by the original MOD author. Proceed at your own risk.
BartVB
Consultant
Consultant
Posts: 1288
Joined: Thu Aug 02, 2001 1:32 pm
Location: The Netherlands

[ABD] Topic title instead of forum link

Post by BartVB »

First of all; I don't plan on actively maintaining or supporting this mod :) If someone wants to adopt it: by all means!

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].

Last edited by Sam on Mon Aug 16, 2010 7:40 pm, edited 1 time in total.
Reason: Marked mod as abandoned, if the original poster wishes to continue this, please PM any MOD team member to have it unlocked.
I Hate oversized sigs and Love Penguins :D
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

Re: [DEV] Topic title instead of forum link

Post by alecrust »

Sounds good. Will it do it to just internal links or external links too?
BartVB
Consultant
Consultant
Posts: 1288
Joined: Thu Aug 02, 2001 1:32 pm
Location: The Netherlands

Re: [DEV] Topic title instead of forum link

Post by BartVB »

Only internal, ofcourse it's possible to just fetch the <title> of remote URLs but that would be too slow and would have quite a bit more security implications.

Oh, forgot to mention that all forums on my board are named something like:

[AN] Annoucements

i.e. every forum is prefixed by an abbreviation. This abbreviation is extracted from the forum name and used in the link. This would be rather useless on a 'normal' board. The script is also not really optimized for speed, a message with 20 internal links results in 20 extra DB queries. Because this is only when posting (editing/quoting) this shouldn't be too much of a problem. The query is also extremely trivial (primary key lookup).
I Hate oversized sigs and Love Penguins :D
User avatar
alecrust
Registered User
Posts: 348
Joined: Thu Mar 27, 2008 11:24 am
Location: London, UK

Re: [DEV] Topic title instead of forum link

Post by alecrust »

Sounds great, only wanted internal links.

Can you think of any potential problems that this MOD might cause? There's gotta be some!
BartVB
Consultant
Consultant
Posts: 1288
Joined: Thu Aug 02, 2001 1:32 pm
Location: The Netherlands

Re: [DEV] Topic title instead of forum link

Post by BartVB »

None that I can think of except for performance with posts that contain huge amounts of links. This code has been running for more than a year on an older version of phpBB 3, hasn't been extensively tested the current 3.0 code but AFAIK there are no problems.
I Hate oversized sigs and Love Penguins :D
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: [DEV] Topic title instead of forum link

Post by mtrs »

Thank you for this mod, I'm testing it on my phpbb3.0.1 board.

I think it would be easier for people who are not familiar with diff file to see find-replace commands instead.

So, I put down what I understand from the install file..

Open
includes/functions_content.php

Find

Code: Select all

$text			= ($relative_url) ? $relative_url : $url;
(I couldn't find this Find part but the one below, so replaced that one)
or

Code: Select all

$text			= $relative_url;
Replace with

Code: Select all

$text			= fetch_forumtitle($url);
Find

Code: Select all

/**
 * make_clickable function
Add before

Code: Select all

/**
*  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;
}
 
I have a question. After installing this mod, when I edit and submit a messages, links in that message change accordingly. Can we also change all the posts' links, like using bbcode parser?
I abandoned all of my mods.
BartVB
Consultant
Consultant
Posts: 1288
Joined: Thu Aug 02, 2001 1:32 pm
Location: The Netherlands

Re: [DEV] Topic title instead of forum link

Post by BartVB »

We could but that would be really detrimental for performance... With this mod phpBB only need to lookup the relevant titles once. If you do this within the bbcode parser each link needs DB lookups on every view of that message.

If you want this in all your messages you would be better of writing a (fairly simple) conversion script.
I Hate oversized sigs and Love Penguins :D
Nicole86
Registered User
Posts: 25
Joined: Wed Jun 18, 2008 3:12 pm
Location: AT

Re: [DEV] Topic title instead of forum link

Post by Nicole86 »

This mod change the internal links correct, but when "&" in title, the mod display it as "&" :(
User avatar
heredia21
Registered User
Posts: 942
Joined: Sun Apr 18, 2010 6:14 pm

Re: [DEV] Topic title instead of forum link

Post by heredia21 »

Nicole86 wrote:This mod change the internal links correct, but when "&" in title, the mod display it as "&" :(
Any fix for this yet?
Best BlackBerry website for all users! BlackBerry News - http://blackberryempire.com
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: [DEV] Topic title instead of forum link

Post by 4_seven »

open

includes/functions_content.php

find

Code: Select all

	$text	= htmlspecialchars($text);
after add

Code: Select all

	$text	= str_replace('&', '&', $text);
but note, that the post must be reparsed to see effect, so edit it, make may a dot and re-send it.
Current Mods | Mod Base | php(BB) programming | No help via PM
User avatar
heredia21
Registered User
Posts: 942
Joined: Sun Apr 18, 2010 6:14 pm

Re: [DEV] Topic title instead of forum link

Post by heredia21 »

Thanks!
Best BlackBerry website for all users! BlackBerry News - http://blackberryempire.com
User avatar
Inner Circle
Registered User
Posts: 24
Joined: Fri Mar 19, 2010 10:19 pm
Location: Germany

Re: [DEV] Topic title instead of forum link

Post by Inner Circle »

Nice one!
A Place for Gamer:
www.gamerkollektiv.net/forum
User avatar
heredia21
Registered User
Posts: 942
Joined: Sun Apr 18, 2010 6:14 pm

Re: [DEV] Topic title instead of forum link

Post by heredia21 »

How about for outside links?
Best BlackBerry website for all users! BlackBerry News - http://blackberryempire.com
User avatar
Oyabun1
Former Team Member
Posts: 23162
Joined: Sun May 17, 2009 1:05 pm
Location: Australia
Name: Bill

Re: [DEV] Topic title instead of forum link

Post by Oyabun1 »

Seems that was covered in the third post in the topic.
BartVB wrote:... it's possible to just fetch the <title> of remote URLs but that would be too slow and would have quite a bit more security implications.
                      Support Request Template
3.0.x: Knowledge Base Styles Support MOD Requests
3.1.x: Knowledge BaseStyles SupportExtension Requests
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: [DEV] Topic title instead of forum link

Post by 4_seven »

BartVB wrote:First of all; I don't plan on actively maintaining or supporting this mod :) If someone wants to adopt it: by all means!
Further [DEV] and Support here..
http://www.phpbb.com/community/viewtopi ... #p12797703
Current Mods | Mod Base | php(BB) programming | No help via PM

Return to “[3.0.x] Abandoned MODs”