adding internal hashs in the regex
This commit is contained in:
@@ -273,11 +273,14 @@ class ToolBox
|
||||
//TODO implement link pattern
|
||||
public static function findReplaceLinks($sText, $sLinkPattern='')
|
||||
{
|
||||
//Parameters
|
||||
$sPreChar = '(^|\ |\*|\'|\()';
|
||||
$sPostChar = '(\ |\.|\:|\)|$)';
|
||||
$sServerPath = substr(str_replace(array('http://', 'https://'), '', $_GET['serv_name']), 0, -1);
|
||||
|
||||
//Fix Carriage Return / Line Feed OS issue
|
||||
$sText = self::fixEOL($sText);
|
||||
|
||||
$sServerPath = substr(str_replace(array('http://', 'https://'), '', $_GET['serv_name']), 0, -1);
|
||||
|
||||
//building all replacements possibilities
|
||||
foreach(Databap::$TYPES as $sType=>$asTypeInfo)
|
||||
{
|
||||
@@ -292,22 +295,25 @@ class ToolBox
|
||||
foreach($asReplacements as $sHash=>$sPage)
|
||||
{
|
||||
//Type + id
|
||||
$asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sHash.'\-([\d]+)`mui'] = '$1$4'.$sPage.' $3';
|
||||
$asPatterns['`'.$sPreChar.'(https?://|)'.$sServerPath.'/?\#'.$sHash.'\-([\d]+)'.$sPostChar.'`mui'] = '$1$4'.$sPage.' $3';
|
||||
|
||||
//Type + phrase
|
||||
if($sPage=='table') $asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#(?i)'.$sHash.'(?-i)\-([_A-Z0-9]+)`mu'] = '$1$4'.$sPage.' $3';
|
||||
if($sPage=='table') $asPatterns['`'.$sPreChar.'(https?://|)'.$sServerPath.'/?\#(?i)'.$sHash.'(?-i)\-([_A-Z0-9]+)'.$sPostChar.'`mu'] = '$1$4'.$sPage.' $3';
|
||||
}
|
||||
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
||||
|
||||
//Phase 2: Identify remaining links (external)
|
||||
$asPatterns = array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`mui', '`((?<!//)(www\.\S+[[:alnum:]]/?))`mui');
|
||||
$asLinks = array('<a href="$1" class="external_link" target="_blank"><i class="fa fa-inline fa-c-share"></i>$1</a> ', '<a href="http://$1" class="external_link" target="_blank"><i class="fa fa-inline fa-c-share"></i>$1</a>');
|
||||
$sText = preg_replace($asPatterns, $asLinks, $sText);
|
||||
//Pahse 2: Replacing directly all remaining links
|
||||
//Phase 2a: Internal hashes
|
||||
$asPatterns = array();
|
||||
foreach(Databap::$HASH_TO_PAGE as $sHash=>$sPage) $asPatterns['`'.$sPreChar.'(https?://|)'.$sServerPath.'/?\#(?i)'.$sHash.'(?-i)'.$sPostChar.'`mui'] = '$1<a href="#'.$sPage.'" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i>'.Databap::$PAGE_TITLES[$sPage].'</a>$3';
|
||||
|
||||
//Phase 2b: External links
|
||||
$asPatterns['`((?:https?|ftp)://\S+[[:alnum:]]/?)`mui'] = '<a href="$1" class="external_link" target="_blank"><i class="fa fa-inline fa-c-share"></i>$1</a> ';
|
||||
$asPatterns['`((?<!//)(www\.\S+[[:alnum:]]/?))`mui'] = '<a href="http://$1" class="external_link" target="_blank"><i class="fa fa-inline fa-c-share"></i>$1</a>';
|
||||
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
||||
|
||||
//Phase 3: Rebuild link
|
||||
$asPatterns = array();
|
||||
$sPreChar = '(^|\ |\*|\'|\()';
|
||||
$sPostChar = '(\ |\.|\:|\)|$)';
|
||||
foreach($asReplacements as $sHash=>$sPage)
|
||||
{
|
||||
if(mb_strlen($sHash)>1)
|
||||
|
||||
Reference in New Issue
Block a user