Fixing internal links in code reader
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Abap Reader
|
||||
* @author franzz
|
||||
*/
|
||||
class Reader
|
||||
class Reader extends PhpObject
|
||||
{
|
||||
//objects
|
||||
//private $oMask;
|
||||
@@ -22,6 +22,8 @@ class Reader
|
||||
|
||||
function __construct($sCode, $bImprovedColoring = false)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
|
||||
//settings
|
||||
$this->bImprovedColoring = $bImprovedColoring;
|
||||
|
||||
@@ -135,10 +137,9 @@ class Reader
|
||||
{
|
||||
//Safe characters
|
||||
$sCode = $this->convText2Html($this->sCode);
|
||||
$sServName = $_GET['serv_name'];
|
||||
$sSafeRexExServName = preg_quote(str_replace('http://', '', $sServName), '/');
|
||||
|
||||
$asLines = explode("\n", $sCode);
|
||||
|
||||
//$sServName = $_GET['serv_name'];
|
||||
$asLines = explode("\n", str_replace("\r\n", "\n", $sCode));
|
||||
$asLineClasses = array();
|
||||
$iOffSet = 0;
|
||||
|
||||
@@ -177,15 +178,28 @@ class Reader
|
||||
//Enlarge line
|
||||
//if(mb_strpos($sLine, $sServName) !== false) $sLiClass .= ' bigline';
|
||||
|
||||
//comments (entire line)
|
||||
$sCodeClass = (in_array($sFirstChar, $this->getWords('cComment')))?'comment':'code';
|
||||
|
||||
//Internal & external Urls
|
||||
$sLine = Toolbox::findReplaceLinks($sLine);
|
||||
|
||||
$asColoredLines[] = '<li id="'.($iLineNb+1).'" class="round_right '.$sLiClass.'"><span class="expand_line">'.$sExpandButton.'</span><span class="'.$sCodeClass.'">'.$sLine.'</span></li>';
|
||||
//Comments (entire line)
|
||||
$bComment = in_array($sFirstChar, $this->getWords('cComment'));
|
||||
$sLine = '<li id="'.($iLineNb+1).'" class="round_right '.$sLiClass.'">'.
|
||||
'<span class="expand_line">'.$sExpandButton.'</span>'.
|
||||
'<span class="'.($bComment?'comment':'code').'">'.$sLine.'</span>'.
|
||||
'</li>';
|
||||
|
||||
//Store comment before coloring code
|
||||
if($bComment)
|
||||
{
|
||||
$sKey = '§'.$iLineNb.'§';
|
||||
$sPattern = '`'.preg_quote($sKey).'`su';
|
||||
$asCommentLines[$sPattern] = $sLine;
|
||||
$sLine = $sKey;
|
||||
}
|
||||
|
||||
$asColoredLines[] = $sLine;
|
||||
}
|
||||
$sCode = implode('', $asColoredLines);
|
||||
$sCode = mb_strtolower(implode('', $asColoredLines));
|
||||
|
||||
//Strings
|
||||
foreach($this->getWords('cString') as $sStringWord)
|
||||
@@ -230,6 +244,9 @@ class Reader
|
||||
$sPattern = '/>((([^<]*)['.$sPreChar.']{1})|.{0})([0-9]+)([\W])/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<span class="number">$4</span>$5', $sCode);
|
||||
|
||||
//Add Comments
|
||||
$sCode = preg_replace(array_keys($asCommentLines), array_values($asCommentLines), $sCode);
|
||||
|
||||
return $sCode;
|
||||
}
|
||||
|
||||
@@ -255,7 +272,7 @@ class Reader
|
||||
|
||||
public static function convText2Html($sCode)
|
||||
{
|
||||
return htmlspecialchars(mb_strtolower($sCode), ENT_QUOTES);
|
||||
return htmlspecialchars($sCode, ENT_QUOTES);
|
||||
}
|
||||
|
||||
public function getColoredCode()
|
||||
|
||||
@@ -245,11 +245,20 @@ class ToolBox
|
||||
{
|
||||
$sServerPath = substr(str_replace(array('http://', 'https://'), '', $_GET['serv_name']), 0, -1);
|
||||
|
||||
//building all replacements possibilities
|
||||
foreach(Databap::$TYPES as $sType=>$asTypeInfo)
|
||||
{
|
||||
$sPage = Databap::$HASH_TO_PAGE[$sType];
|
||||
$asHashes = array_keys(Databap::$HASH_TO_PAGE, $sPage);
|
||||
foreach($asHashes as $sHash) $asReplacements[preg_quote($sHash)] = $sPage;
|
||||
$asReplacements[preg_quote(Databap::$PAGE_TITLES[$sPage])] = $sPage;
|
||||
}
|
||||
|
||||
//Phase 1 : Identify internal links : merge cases /#code-1 and code 1, destroy link.
|
||||
$asPatterns = array();
|
||||
foreach(Databap::$HASH_TO_PAGE as $sAlt=>$sPage)
|
||||
foreach($asReplacements as $sHash=>$sPage)
|
||||
{
|
||||
$asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sAlt.'\-([\d]+)`sui'] = '$1$4'.$sPage.' $3';
|
||||
$asPatterns['`(^|\ )(https?://|)'.$sServerPath.'/?\#'.$sHash.'\-([\d]+)`sui'] = '$1$4'.$sPage.' $3';
|
||||
}
|
||||
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
||||
|
||||
@@ -260,19 +269,21 @@ class ToolBox
|
||||
|
||||
//Phase 3: rebuild link
|
||||
$asPatterns = array();
|
||||
foreach(Databap::$HASH_TO_PAGE as $sAlt=>$sPage)
|
||||
foreach($asReplacements as $sHash=>$sPage)
|
||||
{
|
||||
if(mb_strlen($sAlt)>1)
|
||||
if(mb_strlen($sHash)>1)
|
||||
{
|
||||
$sTitle = Databap::$PAGE_TITLES[$sPage];
|
||||
$asPatterns['`(^|\ )'.$sAlt.'\ ([\d]+)(\ |$)`sui'] = '$1<a href="#'.$sPage.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i>'.$sTitle.' n°$2</a>$3';
|
||||
if($sPage=='table') $asPatterns['`(^|\ )'.$sAlt.'\ ([_A-Z0-9]+)(\ |$)`su'] = '$1<a href="#'.$sPage.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i>'.$sTitle.' $2</a>$3';
|
||||
|
||||
//Type + phrase
|
||||
if($sPage=='table') $asPatterns['`(^|\ |\*)(?i)'.$sHash.'(?-i)\ ([_A-Z0-9]+)(\ |$)`su'] = '$1<a href="#'.$sPage.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i><span class="type">'.$sTitle.'</span> <span class="item">$2</span></a>$3';
|
||||
|
||||
//Type + id
|
||||
$asPatterns['`(^|\ |\*)'.$sHash.'\ ([\d]+)(\ |$)`sui'] = '$1<a href="#'.$sPage.'-$2" target="_blank" class="internal_link round"><i class="fa fa-inline fa-c-'.$sPage.'"></i><span class="type">'.$sTitle.'</span> n°<span class="item">$2</span></a>$3';
|
||||
}
|
||||
}
|
||||
$sText = preg_replace(array_keys($asPatterns), array_values($asPatterns), $sText);
|
||||
|
||||
//@file_put_contents('log.html', "\n\n".date('r')."\n".$test, FILE_APPEND);
|
||||
|
||||
return $sText;
|
||||
}
|
||||
|
||||
|
||||
@@ -294,6 +294,12 @@ a.internal_link {
|
||||
a.internal_link:visited, a.external_link:visited {
|
||||
color:grey;
|
||||
}
|
||||
a.internal_link span.type {
|
||||
text-transform:capitalize;
|
||||
}
|
||||
a[href^="table"].internal_link span.item {
|
||||
text-transform:uppercase;
|
||||
}
|
||||
|
||||
.h1_wrap h1 {
|
||||
margin:0 -12px 12px;
|
||||
@@ -1616,6 +1622,7 @@ vertical-align 0% -5% -10% -15% -20% -25% -30%
|
||||
#code_container .code_reader a.internal_link:hover, #code_container .code_reader a.internal_link:hover span {
|
||||
color:#EFAB00;
|
||||
}
|
||||
|
||||
#code_container .code_reader ol li span.hide span {
|
||||
color:#848484;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user