Hashtag MOD

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Scam Warning
TheDani
Registered User
Posts: 395
Joined: Tue Apr 10, 2012 12:48 pm

Hashtag MOD

Post by TheDani »

#hashtags are used in Twitter, Instagram, Facebook, blogs, etc. It is a very popular way to tag keywords, which when tagged, becomes a link. People use it everywhere, they even used it on Facebook long before Facebook added hashtag functionality. Any MOD writers in for this?
User avatar
AmigoJack
Registered User
Posts: 6128
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Hashtag MOD

Post by AmigoJack »

What'd be the purpose of that if you already have a keyword search? Just turning a word automatically into a link if it begins with a #?
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
DionDesigns
Registered User
Posts: 516
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.

Re: Hashtag MOD

Post by DionDesigns »

AmigoJack wrote:What'd be the purpose of that if you already have a keyword search?
Um, maybe to be compatible with the way Twitter handles hashtags? Anyway...seems to me this can be done with a BBCode. Something like this:

BBCode usage:

Code: Select all

[ht]{IDENTIFIER}[/ht]
HTML replacement:

Code: Select all

<a href="./search.php?keywords=%2B{IDENTIFIER}&sr=posts&ch=300"><b>#{IDENTIFIER}</b></a>
User avatar
RMcGirr83
Former Team Member
Posts: 22107
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Hashtag MOD

Post by RMcGirr83 »

<b> should only be used when there are no other more suitable elements. In this case it should be <strong>
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺
TheDani
Registered User
Posts: 395
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani »

Half of the purpose is that the usage is:

Code: Select all

#{keyword}
User avatar
DionDesigns
Registered User
Posts: 516
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.

Re: Hashtag MOD

Post by DionDesigns »

RMcGirr83 wrote:<b> should only be used when there are no other more suitable elements. In this case it should be <strong>
If I require a tag for boldface, I prefer <b> to <strong> because <b> will always select the 700 font weight. <strong> selects the next heavier weight available, which may or may not be the 700 weight.
TheDani wrote:Half of the purpose is that the usage is:

Code: Select all

#{keyword}
I agree. Try the BBCode and let me know how it works for you. Hmm. The BBcode replacement code above isn't XHTML Strict, so if that matters to you, use this instead:

Code: Select all

<a href="./search.php?keywords=%2B{IDENTIFIER}&sr=posts&ch=300"><b>#{IDENTIFIER}</b></a>
TheDani
Registered User
Posts: 395
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani »

BBCode usage

Code: Select all

#{IDENTIFIER}
HTML replacement

Code: Select all

<a href="./search.php?keywords=%2B{IDENTIFIER}&sr=posts&ch=300"><b>#{IDENTIFIER}</b></a>
Gives:
Your BBCode is constructed in an invalid form.
User avatar
AmigoJack
Registered User
Posts: 6128
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Hashtag MOD

Post by AmigoJack »

Of course: can you name one BBCode without a square bracket? FAQ: What is BBCode. That's why DionDesigns proposed it the way he did.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
RMcGirr83
Former Team Member
Posts: 22107
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Hashtag MOD

Post by RMcGirr83 »

DionDesigns wrote:
RMcGirr83 wrote:<b> should only be used when there are no other more suitable elements. In this case it should be <strong>
If I require a tag for boldface, I prefer <b> to <strong> because <b> will always select the 700 font weight. <strong> selects the next heavier weight available, which may or may not be the 700 weight.
I am not talking about font weight (visual appearance), I am speaking of semantics. If using a hashtag I would think that the OP would want that tag to "stick out" more for bots (not to mention blind people). A bot may interpret the strong tag to indicate that element is more important than the others.

http://en.wikipedia.org/wiki/Separation ... nd_content

Even twitter doesn't do this correctly...they use <b> but this is getting a bit off topic.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺
TheDani
Registered User
Posts: 395
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani »

AmigoJack wrote:Of course: can you name one BBCode without a square bracket? FAQ: What is BBCode. That's why DionDesigns proposed it the way he did.
Yes, by using [ht]{IDENTIFIER}[/ht]. But that kinda defeats the purpose.

Whether the hashtag becomes bold isn't very important really.
User avatar
tbackoff
Former Team Member
Posts: 7068
Joined: Thu Jun 04, 2009 1:41 am
Location: cheerleading practice
Name: Tabitha Backoff

Re: Hashtag MOD

Post by tbackoff »

I dug this up from an old topic. I haven't tested this yet, and I'm unsure of it's security (Rich? AmigoJack?).

OPEN: /viewtopic.php

FIND: (around line 1400)

Code: Select all

    $message = smiley_text($message); 
AFTER, ADD:

Code: Select all

    // hashtag code, UNTESTED
    $message = preg_replace('/(\s)?#(.\w+?)\b/', '\1<a href="' . $phpbb_root_path . 'search.' . $phpEx . '?keywords=\2&terms=all&author=&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search">#\2</a>', $message); 
Flying is the second best thrill to cheerleaders; being caught is the first.
User avatar
RMcGirr83
Former Team Member
Posts: 22107
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Hashtag MOD

Post by RMcGirr83 »

Looks okay to me but I would probably use append_sid
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then you can support me by buying a beer 🍺
TheDani
Registered User
Posts: 395
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani »

Use append_id where/how? I'm not into phpBB-coding.

There is a bug in that code.

Code: Select all

[b]Hello[/b]
becomes

Code: Select all

&#91;b&#93;Hello&#91;/b&#93;
(bbcode inside the code bbcode, the inner [ becomes &#91; and ] becomes &#93;)
User avatar
AmigoJack
Registered User
Posts: 6128
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン

Re: Hashtag MOD

Post by AmigoJack »

t_backoff wrote:dug this up
There are several issues with that one:
  1. Find/add are wrong, since it then would only affect a post text when viewing a topic. It wouldn't affect search results or forum descriptions or poll options or signatures or everything else.
  2. As I suspected, it will break links - try the one below and you'll realize that the anchor is falsely seen as a hashtag:

    Code: Select all

    [url=http://en.wikipedia.org/wiki/PhpBB#MODs]no hashtags at all[/url]
  3. The URI to the search doesn't need all those parameters, keyword= is enough. ;)
No. Instead:

Open /includes/functions_content.php and find:

Code: Select all

function smiley_text($text, $force_option = false)
{ 
Replace with:

Code: Select all

/*** 2013-06-20 BEGIN AmigoJack, t_backoff
    http://www.phpbb.com/community/viewtopic.php?t=2186935 ***/
function hashtag_callback( $aMatch ) {
    global $phpbb_root_path, $phpEx;
    if( preg_match( '#(color|background|text-shadow)[:=]|style="#i', $aMatch[1] ) ) return $aMatch[0];
    return $aMatch[1]. '<a href="'. append_sid( "{$phpbb_root_path}search.$phpEx", 'keywords='. $aMatch[2] ). '">#'. $aMatch[2]. '</a>';
}

function smiley_text($text, $force_option = false)
{
    $text= preg_replace_callback( '/(^|style="[^"#]+|[^\\s]*[\\s]+|>)#([\\p{Lu}\\p{Ll}\\p{N}\\w\\d]+)\\b/um', 'hashtag_callback', $text );
/*** 2013-06-20 END ***/ 
As a test case, use this post text:

Code: Select all

#StartOfLine
in the middle #1337 and
the #under_score
with a #dot.appended and
the [url=http://en.wikipedia.org/wiki/PhpBB#MODs]link_anchor[/url]
[b]what #else?[/b]
and #ソニック Katakanas
Might not work if your PHP version is too old or your PCRE module doesn't support Unicode - in that case precisely replace \\p{Lu}\\p{Ll}\\p{N}\\w\\d]+)\\b/u with \\w\\d]+)\\b/. Tested.

(Edited from 2h ago, since preg_replace using modificator e is a security threat.
Last edited by AmigoJack on Tue Jul 09, 2013 6:24 am, edited 2 times in total.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
TheDani
Registered User
Posts: 395
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani »

Very nice. Seems to be working fine. Thank you!

Return to “[3.0.x] MOD Requests”