Page 1 of 5

[3.2][RC] Local URL To Text

Posted: Sat Dec 27, 2014 6:45 pm
by ___Martin
Extension Name: Local URL To Text
Author: ___Martin

Extension Description: Replaces local URLs (links to forums, topics, posts or member profiles within your board) with a customizable text.

Extension Version: 1.1.1 (release candidate, submitted to extension database: https://www.phpbb.com/customise/db/exte ... l_to_text/)

Requirements: phpBB 3.2

Features:
  • If a user of your board posts a link to a forum, it normally appears as a link like http://yourboard/viewforum.php?f=5.
    With this extension, the link to the forum can rather be displayed as Forum Name.
  • Links to topics can be displayed as Topic Title instead of http://yourboard/viewtopic.php?f=5&t=2.
  • You can also include the name of the forum containing that topic to the link, e.g. Topic Title (Forum Name).
  • Similar text replacements are available for links to posts and to member profile pages.
  • Local links within Custom profile fields can be replaced as well.
  • Supports Pages extension
  • Works with External Links extension
The extension only replaces these links when displaying a message (post, private message, etc.). It does not alter the messages that are stored into the database. So when a topic gets renamed, all links to this topic will display the new topic title automatically.

The text that replaces the local URL links can be customized. The following replacements are available:
  • For forum or category links: forum/category name
  • For topic links: topic title, forum name of containing forum
  • For post links: poster user name, poster user colour, post subject, topic title, forum name, topic title (only if post subject is empty)
  • For member profile links: user name, user colour
  • For links to pages of the Pages extension: page title
  • Option to enable or disable (default) replacement of local links within Custom profile fields
Authorization:
Users will only see content from forums they are authorized to read. E.g. if someone posts a link to a topic that resides in a protected forum, only members with access to this forum will see the title of this topic. Unauthorized members will see the default viewtopic.php?t=xx link.

Screenshots:
Image

Development Repository: https://github.com/Mar-tin-G/LocalUrlToText

Extension Download:
Download at the development repository linked above via the "Download ZIP" button, or use this direct link: https://github.com/Mar-tin-G/LocalUrlTo ... /1.1.1.zip
Create the following folder structure in your board, and extract the files and folders from the downloaded ZIP file there: /ext/martin/localurltotext.
Activate the extension in the Admin Control Panel (ACP) on the Customise > Manage Extensions page.
Set up the text replacements in the ACP on the Extensions > Local URL To Text > Settings page.

Caution: This extension is still in beta status. Please do not use this extension on production boards without testing.

Re: [BETA] Local URL To Text

Posted: Sat Dec 27, 2014 7:05 pm
by HiFiKabin
Looks good. I'm following

Re: [BETA] Local URL To Text

Posted: Sat Dec 27, 2014 7:09 pm
by Nully
Is it different from Convert Local Url To Link Name?
viewtopic.php?f=456&t=2277841

Re: [BETA] Local URL To Text

Posted: Sat Dec 27, 2014 7:22 pm
by frax
Good ext!

Re: [BETA] Local URL To Text

Posted: Sat Dec 27, 2014 8:34 pm
by Raul [ThE KuKa]
I like this ext. ;)

Re: [BETA] Local URL To Text

Posted: Sat Dec 27, 2014 8:59 pm
by lavachapi
Wow, real SEO !

Re: [BETA] Local URL To Text

Posted: Sat Dec 27, 2014 9:22 pm
by david63
Can I just point out that upper case characters are not allowed in vendor or namespace

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 1:01 am
by Zaishen
great, make it final

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 9:07 am
by ___Martin
Thank you for your feedback! :)
Nully wrote:Is it different from Convert Local Url To Link Name?
viewtopic.php?f=456&t=2277841
Yes. HAMMER663's extension converts the local URL links when submitting a message to the database, e.g. when posting a reply, so the posting of the member is modified. My extension does not alter the messages, but rather replaces the local URL links when viewing the message.

This implies that while HAMMER663's extension is called only once when submitting messages, my extension is called for every view of a message. To reduce the load, my extension tries to minimize database queries.

This also implies that the link texts that HAMMER663's extension creates could be out of date. Imagine a topic that someone posts a link to, but then a while later the topic is renamed. The link texts of HAMMER663's extension will still contain the old topic title, while the link texts of my extension will display the new title.

Another difference would be that in the current version of HAMMER663's extension you (as board admin) are not able to customize the way the text links are created.

david63 wrote:Can I just point out that upper case characters are not allowed in vendor or namespace
Whoops, thank you for pointing that out. I will fix this in the next release.

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 9:39 am
by HiFiKabin
I don't know if its a bug, or just the way things happen (similar to smilies)

Let me explain:-

Image
imgurl

If you quote a post with the link as the first item, it does not appear as text, if its preceeded by text it shows correctly.

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 10:13 am
by ___Martin
Thanks HiFiKabin. I can confirm this behaviour: if a local URL link is posted within a BBCode tag (be it quote, b, list) without any whitespace between the closing square bracket ("]") and the link itself, phpBB does not recognize this as a link and does not automatically parse this URL.

Unfortunately the same behaviour can be seen when posting smilies, as you mentioned. Since the extension relies on phpBB to identify and parse local URLs, I currently don't know how to workaround this.

See this screenshot: neither a local URL link is recognized when immediately following a quote or b BBCode, nor is a smiley recognized. If there is any whitespace or text preceding the link/smiley, they are parsed.
Image


Unfortunately the phpBB bug tracker and Area51 are down at the moment, but I will try to research if this behaviour is intended when they come back online.

EDIT: found a topic describing the same problem: viewtopic.php?f=466&t=2281816

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 10:25 am
by HiFiKabin
Yes, I thought it must be the way that phpBB worked.

No problem, its a great extension.

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 11:51 am
by ___Martin
With these code modifications the parse "bug" could be fixed. They add the closing square bracket ("]") as a valid character that preceeds a magic URL or a smiley, enabling parsing of magic URLs and smilies following the "]" character directly.

Warning: do NOT modify your core phpBB files!
I post these modifications here only as a reminder to post a request to improve the message parser of phpBB. As these modifications could have side effects that I am not aware of, do NOT use them in your phpBB board!

Changes in includes\functions.content line 791: (first line is the old code, second line the new code)

Code: Select all

'#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#iu',
'#(^|[\n\t (>.\]])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#iu',
Changes in includes\message_parser.php line 1441:

Code: Select all

$num_matches = preg_match_all('#(?<=^|[\n .])(?:' . implode('|', $match) . ')(?![^<>]*>)#u', $this->message, $matches);
$num_matches = preg_match_all('#(?<=^|[\n .\]])(?:' . implode('|', $match) . ')(?![^<>]*>)#u', $this->message, $matches);
Changes in includes\message_parser.php line 1455:

Code: Select all

$this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .])' . implode('(?![^<>]*>)#u' . chr(0) . '#(?<=^|[\n .])', $match) . '(?![^<>]*>)#u'), $replace, $this->message));
$this->message = trim(preg_replace(explode(chr(0), '#(?<=^|[\n .\]])' . implode('(?![^<>]*>)#u' . chr(0) . '#(?<=^|[\n .\]])', $match) . '(?![^<>]*>)#u'), $replace, $this->message));

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 1:04 pm
by M.Gaetan89
Nice extension!
When replacing a link to a user profile, would it be possible to colorized the link with the user's group color?

Re: [BETA] Local URL To Text

Posted: Sun Dec 28, 2014 1:23 pm
by Schtorsch
Hm, I tested the extension and get the correct result at my first post.
From the second post it doesn´t work for me. At preview it looks correct - but if I send the posting the link is the URL and not the topic title...

Whats going wrong?

EDIT: Seems to be an extension for external links. Disabled -> now the mod works fine. :)
I have to search a better mod for external links...