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: 356
Joined: Tue Apr 10, 2012 12:48 pm

Hashtag MOD

Post by TheDani » Mon Jun 17, 2013 11:20 pm

#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: 5638
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Hashtag MOD

Post by AmigoJack » Tue Jun 18, 2013 6:34 am

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: Hashtag MOD

Post by DionDesigns » Tue Jun 18, 2013 7:09 am

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
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Hashtag MOD

Post by RMcGirr83 » Tue Jun 18, 2013 11:25 am

<b> should only be used when there are no other more suitable elements. In this case it should be <strong>
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

TheDani
Registered User
Posts: 356
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani » Tue Jun 18, 2013 11:49 am

Half of the purpose is that the usage is:

Code: Select all

#{keyword}

User avatar
DionDesigns
Registered User
Posts: 515
Joined: Sun Feb 26, 2012 11:22 pm
Location: Uncertain due to momentum.
Contact:

Re: Hashtag MOD

Post by DionDesigns » Wed Jun 19, 2013 3:19 am

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: 356
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani » Wed Jun 19, 2013 9:33 am

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: 5638
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Hashtag MOD

Post by AmigoJack » Wed Jun 19, 2013 10:27 am

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Hashtag MOD

Post by RMcGirr83 » Wed Jun 19, 2013 10:40 am

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.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

TheDani
Registered User
Posts: 356
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani » Wed Jun 19, 2013 10:48 am

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: 7022
Joined: Thu Jun 04, 2009 1:41 am
Location: cheerleading practice
Name: Tabitha Backoff

Re: Hashtag MOD

Post by tbackoff » Wed Jun 19, 2013 11:19 am

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
Recognised Extension Developer
Posts: 21034
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: Hashtag MOD

Post by RMcGirr83 » Wed Jun 19, 2013 2:11 pm

Looks okay to me but I would probably use append_sid
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

TheDani
Registered User
Posts: 356
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani » Thu Jun 20, 2013 12:25 am

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: 5638
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Hashtag MOD

Post by AmigoJack » Thu Jun 20, 2013 7:05 am

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 worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
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.

TheDani
Registered User
Posts: 356
Joined: Tue Apr 10, 2012 12:48 pm

Re: Hashtag MOD

Post by TheDani » Thu Jun 20, 2013 11:10 am

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

Locked

Return to “[3.0.x] MOD Requests”