Fixing internal links in code reader

This commit is contained in:
lutranf
2014-08-29 18:17:56 +02:00
parent 7635525783
commit 7adbc1c356
3 changed files with 54 additions and 19 deletions

View File

@@ -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()