Last active
May 9, 2018 07:39
-
-
Save shukob/fe755b18e0d90867b786f1b7ab275665 to your computer and use it in GitHub Desktop.
Hashtag to link in humhub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function convertHashtags($text) | |
{ | |
return preg_replace_callback( | |
'/#(?!039)([\w]+)/', // all "word" characters, all digits, and underscore | |
// brackets around the string AFTER the hashtag | |
function ($hit) { | |
// $matches[0] is the complete match (including the hashtag) | |
// $matches[1] is the match for the subpattern enclosed in brackets | |
return '[' . $hit[0] . '](' . 'http://localhost:8080/index.php?r=' . Html::encode('search/search/index') . | |
'&' . Html::encode('SearchForm[keyword]') . '=' . strtolower($hit[1]) . ')'; | |
}, $text); | |
} | |
public function run() | |
{ | |
$this->originalText = $this->text; | |
if ($this->encode) { | |
$this->text = Html::encode($this->text); | |
} | |
if (!$this->minimal && !$this->edit) { | |
$this->translateOmbed(); | |
// mark emails | |
$this->text = preg_replace_callback('/[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,3})/', function ($match) { | |
return Html::mailto($match[0]); | |
}, $this->text); | |
} | |
$this->text = self::convertHashtags($this->text); | |
// get user and space details from guids | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment