private function getFileSource($file, $offset)
 {
     $fp = fopen($file, 'r');
     $html = '';
     $lines[] = '';
     do {
         $buffer = fgets($fp, 4096);
         $lines[] = $buffer;
     } while (!feof($fp));
     fclose($fp);
     $start = $offset - $this->srcLines;
     if ($start < 0) {
         $start = 0;
     }
     $lines = array_slice($lines, $start, $this->srcLines * 2 + 1, true);
     $a = array_keys($lines);
     $b = sizeOf($a);
     for ($c = 0; $c < $b; ++$c) {
         $line =& $lines[$a[$c]];
         //$line = preg_replace('/^\s/s', '&nbsp;', preg_replace('/\s\s/s', '&nbsp;&nbsp;', htmlspecialchars($line)));
         $html .= '<li class="line';
         if ($a[$c] == $offset) {
             $html .= ' hl';
         }
         $html .= '"><div class="num">' . $a[$c] . '.</div><div class="code"><div class="border">' . $this->convertPHPHighlighting(str_replace('<br />', '', str_replace('?&gt;', '', str_replace('&lt;?php', '', highlight_string('<?php ' . $line . ' ?>', true))))) . '</div></div></li>';
     }
     return $html;
 }
function printCode($code, $high_light = 0, $lines_number = 0, $line_number_start = 0)
{
    if (!is_array($code)) {
        $code = explode("\n", $code);
    }
    $count_lines = count($code);
    $r = "";
    $line = $line_number_start;
    foreach ($code as $code_line) {
        if ($lines_number) {
            $r1 = "<span class=\"lines_number\">" . $line . ". </span>";
        }
        if ($high_light) {
            if (ereg("<\\?(php)?[^[:graph:]]", $code_line)) {
                $r2 = highlight_string($code_line, 1);
            } else {
                $r2 = ereg_replace("(&lt;\\?php&nbsp;)+", "", highlight_string("<?php " . $code_line, 1));
            }
        } else {
            $r2 = !$line ? "<pre>" : "";
            $r2 .= htmlentities($code_line);
            $r2 .= $line == $count_lines - 1 ? "<br /></pre>" : "";
        }
        $r .= $r1 . $r2;
        $line++;
    }
    return "<div class=\"code\">" . $r . "</div>";
}
Exemple #3
0
function getMessages($user, $reverse, $last)
{
    // get messages
    $time = date("F d Y H:i:s.", filemtime("msg/" . $user));
    $time = prettyDate($time) . ".";
    if ($time == "46 years ago.") {
        $time = "Never ago.";
    }
    $curtime = date("F d Y H:i:s.", time());
    if (!isset($last)) {
        echo "Message last receieved: " . $time . " Current time: " . $curtime . "<br>\n";
    }
    echo "Messages, sorted by recent:<br>\n";
    if (!$reverse) {
        $messages = file("msg/" . $user);
    } else {
        $messages = array_reverse(file("msg/" . $user));
    }
    echo "<div class='scrolls'>";
    foreach ($messages as $message) {
        highlight_string($message) . "<br>";
    }
    echo "</div>";
    if (isset($_POST["api"])) {
        die;
    }
}
Exemple #4
0
 /**
  * Preview code from a string containing PHP code
  *
  * @param string   $code       php code
  * @param int|null $activeLine active line number
  * @param int|null $lineRange  range of lines to render (around active line)
  * @param string   $className  wrapper class name
  * @return string|null
  */
 public static function code($code, $activeLine = null, $lineRange = null, $className = 'code-preview')
 {
     $code = @highlight_string($code, true);
     if (false !== $code) {
         return self::render($code, $activeLine, $lineRange, $className);
     }
 }
Exemple #5
0
function processor_enscript($formatter, $value)
{
    global $DBInfo;
    $enscript = 'enscript ';
    ##enscript --help-pretty-print |grep "^Name" |cut -d" " -f 2
    $syntax = array("ada", "asm", "awk", "c", "changelog", "cpp", "diff", "diffu", "delphi", "elisp", "fortran", "haskell", "html", "idl", "java", "javascript", "mail", "makefile", "nroff", "objc", "pascal", "perl", "postscript", "python", "scheme", "sh", "sql", "states", "synopsys", "tcl", "verilog", "vhdl", "vba", "php");
    $options = array("number");
    $vartmp_dir =& $DBInfo->vartmp_dir;
    $line = '';
    if ($value[0] == '#' and $value[1] == '!') {
        list($line, $value) = explode("\n", $value, 2);
    }
    # get parameters
    if ($line) {
        $line = substr($line, 2);
        $tag = strtok($line, ' ');
        $type = strtok(' ');
        $extra = strtok('');
        if ($tag != 'enscript') {
            $extra = $type;
            $type = $tag;
        }
    }
    $option = '';
    if ($extra == "number") {
        $option = '-C ';
    }
    $src = $value;
    if (!in_array($type, $syntax)) {
        return "<pre class='code'>\n{$line}\n{$src}\n</pre>\n";
    }
    if ($type == 'php') {
        ob_start();
        highlight_string($src);
        $html = ob_get_contents();
        ob_end_clean();
    } else {
        $tmpf = tempnam($vartmp_dir, "FOO");
        $fp = fopen($tmpf, "w");
        fwrite($fp, $src);
        fclose($fp);
        #-E%s -W html -J "" -B --color --word-wrap
        #$cmd="ENSCRIPT_LIBRARY=/home/httpd/wiki/lib $enscript -q -o - -E$type -W html --color --word-wrap ".$tmpf;
        if (!empty($DBInfo->enscript_style)) {
            $cmd = "{$enscript} -q -o - {$option} -E{$type} --language=html {$DBInfo->enscript_style} --color --word-wrap " . $tmpf;
        } else {
            $cmd = "{$enscript} -q -o - {$option} -E{$type} --language=html --style=ifh --color --word-wrap " . $tmpf;
        }
        $fp = popen($cmd . $formatter->NULL, 'r');
        $html = '';
        while ($s = fgets($fp, 1024)) {
            $html .= $s;
        }
        pclose($fp);
        $html = eregi_replace('^.*<pre>', '<div class="wikiPre"><pre class="wiki">', $html);
        $html = eregi_replace('<\\/PRE>.*$', '</pre></div>', $html);
        unlink($tmpf);
    }
    return $html;
}
 public function highlight($string)
 {
     $string = highlight_string("<?php " . $string, true);
     $find = array('<span style="color: #0000BB">&lt;?php&nbsp;</span>', '&lt;?php&nbsp;');
     $string = str_replace($find, '', $string);
     return $string;
 }
function dump()
{
    // Search the function caller
    $backtrace = debug_backtrace();
    $trace = current($backtrace);
    // If parent function is debug, shift
    if (empty($trace['file']) && @$backtrace[1]['function'] == 'call_user_func_array') {
        next($backtrace);
        // Skip call_user_func_array
        $trace = next($backtrace);
    }
    // Cut root dir from file path
    $root = str_replace('\\', '/', defined('ROOT_DIR') ? ROOT_DIR : $_SERVER['DOCUMENT_ROOT']);
    $file = str_replace('\\', '/', $trace['file']);
    $file = preg_replace('/^' . preg_quote($root, '/') . '/', '', $file);
    // Environment detection
    $http = PHP_SAPI != 'cli' && !(defined('DEBUG_OUTPUT') && DEBUG_OUTPUT == 'text');
    $dump = $http ? 'var_dump' : 'print_r';
    $args = ($a = func_get_args()) ? $a : array("checkpoint!");
    // Output file path
    echo $http ? "<!-- don't be evil --><code style='color: green'><b>" . $file . "</b> on line <b>" . @$trace['line'] . "</b></code><br /><br />" : "{$file} on line {$trace['line']}\n";
    // Output variables
    foreach ($args as $cur) {
        ob_start();
        $dump($cur);
        $cur = ob_get_contents();
        ob_end_clean();
        if (!extension_loaded('xdebug') && $http) {
            $cur = highlight_string("<?php\n\n{$cur}\n?>", true);
        }
        echo $cur;
    }
    echo $http ? "<hr><br />" : "\n" . str_repeat('-', 70) . "\n\n";
}
 public function render(&$____code, $____local_assigns, $____file_path)
 {
     $this->_options['variables'] = $____local_assigns;
     $this->_options['code'] =& $____code;
     $this->_options['functions'] = array('');
     $this->_options['file_path'] = $____file_path;
     if ($this->_templateNeedsCompilation()) {
         $TemplateEngine = $this->_getTemplateEngineInstance($this->_templateEngine);
         $TemplateEngine->init(array('code' => $____code, 'helper_loader' => $this->_AkActionView->getHelperLoader()));
         $____code = $TemplateEngine->toPhp();
         if ($____code === false) {
             if (AK_PRODUCTION_MODE) {
                 trigger_error(join("\n", $TemplateEngine->getErrors()), E_USER_ERROR);
                 return false;
             } else {
                 trigger_error("Could not compile " . $this->_options['file_path'] . "\n\n" . join("\n", $TemplateEngine->getErrors()), E_USER_ERROR);
                 echo highlight_string($TemplateEngine->getParsedCode(), true);
                 die;
             }
         }
         if (AK_TEMPLATE_SECURITY_CHECK && $this->_templateNeedsValidation()) {
             if (!$this->_assertForValidTemplate()) {
                 return false;
             }
         }
         $this->_saveCompiledTemplate();
     }
     (array) $____local_assigns;
     extract($____local_assigns, EXTR_SKIP);
     ob_start();
     include $this->_getCompiledTemplatePath();
     empty($shared) || $this->_AkActionView->addSharedAttributes($shared);
     return ob_get_clean();
 }
Exemple #9
0
 public function highlight($data)
 {
     $src = highlight_string($data, true);
     $src = str_replace("\n", '', $src);
     $src = preg_replace('/<br[^>]*>/', PHP_EOL, $src);
     $src = preg_replace_callback('/<span style="color: #([0-F]+)">/', function ($m) {
         switch ($m[1]) {
             case '0000BB':
                 // Idents
                 return "";
             case 'FF8000':
                 // Comments
                 return "";
             case '007700':
                 // Symbols
                 return "";
             case 'DD0000':
                 // Strings
                 return "";
             default:
                 return "";
         }
     }, $src);
     // Ensure no tags are left
     $src = preg_replace('/<[^>]+>/', '', $src);
     $src = str_replace('&nbsp;', ' ', $src);
     $src = html_entity_decode($src);
     $src = $src . "";
     return $src;
 }
    public static function showMethod($class, $methods)
    {
        $rclass     = new ReflectionClass($class);
        $definition = implode("", array_slice(file($rclass->getFileName()), $rclass->getStartLine()-1, 1));

        $code       = "\n".$definition."\n....\n\n";

        if (!is_array($methods))
            $methods = array($methods);

        foreach ($methods as $method) {
            $method     = new ReflectionMethod($class, $method);
            $filename   = $method->getFileName();
            $start_line = $method->getStartLine()-1;
            $end_line   = $method->getEndLine();
            $length     = $end_line - $start_line;
            $source     = file($filename);
            $content    = implode("", array_slice($source, $start_line, $length));

            $code .= $content."\n\n";
        }

        $code = highlight_string("<?php ".$code, true);
        $code = str_replace('&lt;?php&nbsp;', '', $code);

        return "<pre>\n" . $code . "\n</pre>";
    }
 /**
  * @see	\wcf\system\bbcode\highlighter\Highlighter::highlight()
  */
 public function highlight($code)
 {
     // add starting php tag
     $phpTagsAdded = false;
     if (mb_strpos($code, '<?') === false) {
         $phpTagsAdded = true;
         $code = '<?php ' . $code . ' ?>';
     }
     // do highlight
     $highlightedCode = highlight_string($code, true);
     // clear code
     $highlightedCode = str_replace('<code>', '', $highlightedCode);
     $highlightedCode = str_replace('</code>', '', $highlightedCode);
     // remove added php tags
     if ($phpTagsAdded) {
         $regex = new Regex('([^\\2]*)(&lt;\\?php&nbsp;)(.*)(&nbsp;.*\\?&gt;)([^\\4]*)', Regex::CASE_INSENSITIVE | Regex::DOT_ALL);
         $highlightedCode = $regex->replace($highlightedCode, '\\1\\3\\5');
     }
     // remove breaks
     $highlightedCode = str_replace("\n", "", $highlightedCode);
     $highlightedCode = str_replace('<br />', "\n", $highlightedCode);
     // get tabs back
     $highlightedCode = str_replace('&nbsp;&nbsp;&nbsp;&nbsp;', "\t", $highlightedCode);
     // replace non breaking space with normal space, white-space is preserved by CSS
     $highlightedCode = str_replace('&nbsp;', " ", $highlightedCode);
     // convert colors to classes
     $highlightedCode = strtr($highlightedCode, self::$colorToClass);
     // replace double quotes by entity
     return Regex::compile('(?<!\\<span class=)"(?!\\>)')->replace($highlightedCode, '&quot;');
 }
 /**
  * apply PHP highlight_string
  *
  * @param string $text source string
  *
  * @return string
  */
 public function php($text)
 {
     $text = trim($text);
     $addedOpenTag = false;
     if (!strpos($text, "<?php") && substr($text, 0, 5) !== "<?php") {
         $text = "<?php " . $text;
         $addedOpenTag = true;
     }
     $oldlevel = error_reporting(0);
     //There is a bug in the highlight function(php < 5.3) that it doesn't render
     //backslashes properly like in \s. So here we replace any backslashes
     $text = str_replace("\\", "XxxX", $text);
     $buffer = highlight_string($text, true);
     // Require PHP 4.20+
     //Placing backspaces back again
     $buffer = str_replace("XxxX", "\\", $buffer);
     error_reporting($oldlevel);
     $pos_open = $pos_close = 0;
     if ($addedOpenTag) {
         $pos_open = strpos($buffer, '&lt;?php&nbsp;');
     }
     $str_open = $addedOpenTag ? substr($buffer, 0, $pos_open) : "";
     $length_open = $addedOpenTag ? $pos_open + 14 : 0;
     $str_internal = substr($buffer, $length_open);
     $buffer = $str_open . $str_internal;
     return $buffer;
 }
Exemple #13
0
 public function highLight(string $str, array $settings = []) : string
 {
     $phpFamily = !empty($settings['php:family']) ? 'font-family:' . $settings['php:family'] : 'font-family:Consolas';
     $phpSize = !empty($settings['php:size']) ? 'font-size:' . $settings['php:size'] : 'font-size:12px';
     $phpStyle = !empty($settings['php:style']) ? $settings['php:style'] : '';
     $htmlFamily = !empty($settings['html:family']) ? 'font-family:' . $settings['html:family'] : '';
     $htmlSize = !empty($settings['html:size']) ? 'font-size:' . $settings['html:size'] : '';
     $htmlColor = !empty($settings['html:color']) ? $settings['html:color'] : '';
     $htmlStyle = !empty($settings['html:style']) ? $settings['html:style'] : '';
     $comment = !empty($settings['comment:color']) ? $settings['comment:color'] : '#969896';
     $commentStyle = !empty($settings['comment:style']) ? $settings['comment:style'] : '';
     $default = !empty($settings['default:color']) ? $settings['default:color'] : '#000000';
     $defaultStyle = !empty($settings['default:style']) ? $settings['default:style'] : '';
     $keyword = !empty($settings['keyword:color']) ? $settings['keyword:color'] : '#a71d5d';
     $keywordStyle = !empty($settings['keyword:style']) ? $settings['keyword:style'] : '';
     $string = !empty($settings['string:color']) ? $settings['string:color'] : '#183691';
     $stringStyle = !empty($settings['string:style']) ? $settings['string:style'] : '';
     $background = !empty($settings['background']) ? $settings['background'] : '';
     $tags = isset($settings['tags']) ? $settings['tags'] : true;
     ini_set("highlight.comment", "{$comment}; {$phpFamily}; {$phpSize}; {$phpStyle}; {$commentStyle}");
     ini_set("highlight.default", "{$default}; {$phpFamily}; {$phpSize}; {$phpStyle}; {$defaultStyle}");
     ini_set("highlight.keyword", "{$keyword}; {$phpFamily}; {$phpSize}; {$phpStyle}; {$keywordStyle} ");
     ini_set("highlight.string", "{$string};  {$phpFamily}; {$phpSize}; {$phpStyle}; {$stringStyle}");
     ini_set("highlight.html", "{$htmlColor}; {$htmlFamily}; {$htmlSize}; {$htmlStyle}");
     // ----------------------------------------------------------------------------------------------
     // HIGHLIGHT
     // ----------------------------------------------------------------------------------------------
     $string = highlight_string($str, true);
     // ----------------------------------------------------------------------------------------------
     $string = Security::scriptTagEncode(Security::phpTagEncode(Security::htmlDecode($string)));
     $tagArray = $tags === true ? ['<div style="' . $background . '">&#60;&#63;php', '&#63;&#62;</div>'] : ['<div style="' . $background . '">', '</div>'];
     return str_replace(['&#60;&#63;php', '&#63;&#62;'], $tagArray, $string);
 }
Exemple #14
0
function render($markdown)
{
    /* Code blocks */
    $markdown = preg_replace("/^```php\n([^`]+)```/m", highlight_string("\$1"), $markdown);
    /* Titles */
    $markdown = preg_replace("/^\\#\\s+(.*)\$/m", "<h1>\$1</h1>", $markdown);
    $markdown = preg_replace("/^\\##\\s+(.*)\$/m", "<h2>\$1</h2>", $markdown);
    $markdown = preg_replace("/^\\###\\s+(.*)\$/m", "<h3>\$1</h3>", $markdown);
    $markdown = preg_replace("/^\\####\\s+(.*)\$/m", "<h4>\$1</h4>", $markdown);
    $markdown = preg_replace("/^\\#####\\s+(.*)\$/m", "<h5>\$1</h5>", $markdown);
    $markdown = preg_replace("/^\\######\\s+(.*)\$/m", "<h6>\$1</h6>", $markdown);
    /* Inline statements */
    $markdown = preg_replace("/`([^`]+)`/m", "<code>\$1</code>", $markdown);
    $markdown = preg_replace("/\\*\\*([^**]+)\\*\\*/m", "<strong>\$1</strong>", $markdown);
    $markdown = preg_replace("/\\*([^*]+)\\*/m", "<em>\$1</em>", $markdown);
    $markdown = preg_replace("/~~([^~]+)~~/m", "<s>\$1</s>", $markdown);
    /* Links */
    $markdown = preg_replace("/\\[([^\\]]+)\\]\\(([^)]+)\\)/m", "<a href=\"\$2\">\$1</a>", $markdown);
    /* Line breaks */
    $markdown = preg_replace("/[ ]{2,2}\n/", "<br>\n", $markdown);
    /* Paragraphs */
    $paragraphs = explode("\n\n", $markdown);
    $markdown = "";
    foreach ($paragraphs as $p) {
        $p = trim($p);
        if (preg_match("/^</", $p)) {
            $markdown .= $p . "\n";
        } else {
            $markdown .= "<p>{$p}</p>\n";
        }
    }
    return $markdown;
}
 public function viewBlockAction()
 {
     $blockClass = $this->getRequest()->get('block');
     $absoluteFilepath = Mage::helper('debug')->getBlockFilename($blockClass);
     $source = highlight_string(file_get_contents($absoluteFilepath), true);
     echo $this->_debugPanel("Block Source: <code>{$blockClass}</code>", '' . $source . '');
 }
Exemple #16
0
function dump_highlight($var, $depth = null)
{
    $out = dump($var);
    $out = highlight_string("<?php\n" . $out, true);
    $out = preg_replace('@&lt;\\?php<br />@s', '', $out, 1);
    return $out;
}
Exemple #17
0
 function php($text)
 {
     $text = trim($text);
     $addedtag_open = 0;
     if (!strpos($text, "<?php") and substr($text, 0, 5) != "<?php") {
         $text = "<?php\n" . $text;
         $addedtag_open = 1;
     }
     $addedtag_close = 0;
     if (!strpos($text, "?>")) {
         $text .= "?>";
         $addedtag_close = 1;
     }
     $oldlevel = error_reporting(0);
     $buffer = highlight_string($text, true);
     // Require PHP 4.20+
     error_reporting($oldlevel);
     $pos_open = $pos_close = 0;
     if ($addedtag_open) {
         $pos_open = strpos($buffer, '&lt;?php');
     }
     if ($addedtag_close) {
         $pos_close = strrpos($buffer, '?&gt;');
     }
     $str_open = $addedtag_open ? substr($buffer, 0, $pos_open) : "";
     $str_close = $pos_close ? substr($buffer, $pos_close + 5) : "";
     $length_open = $addedtag_open ? $pos_open + 8 : 0;
     $length_text = $pos_close ? $pos_close - $length_open : 0;
     $str_internal = $length_text ? substr($buffer, $length_open, $length_text) : substr($buffer, $length_open);
     $buffer = $str_open . $str_internal . $str_close;
     return $buffer;
 }
Exemple #18
0
 /**
  * 根据trace信息分析源码,生成异常处理详细数据
  *
  * @param Exception $e
  * @return array
  */
 function cpExceptionSource(Exception $e)
 {
     $trace = $e->getTrace();
     $result = array();
     $result['main'] = array('file' => $e->getFile(), 'line' => $e->getLine(), 'message' => $e->getMessage());
     $result['main']['show_file'] = $this->hiddenFileRealPath($result['main']['file']);
     foreach ($result as &$_i) {
         $file = new SplFileObject($_i['file']);
         foreach ($file as $line => $code) {
             if ($line < $_i['line'] + 6 && $line > $_i['line'] - 7) {
                 $h_string = highlight_string("<?php{$code}", true);
                 $_i['source'][$line] = str_replace("&lt;?php", "", $h_string);
             }
         }
     }
     if (!empty($trace)) {
         foreach ($trace as $tn => &$t) {
             if (isset($t['file'])) {
                 $trace_fileinfo = new SplFileObject($t['file']);
                 $t['show_file'] = $this->hiddenFileRealPath($t['file']);
                 foreach ($trace_fileinfo as $t_line => $t_code) {
                     if ($t_line < $t['line'] + 6 && $t_line > $t['line'] - 7) {
                         $h_string = highlight_string("<?php{$t_code}", true);
                         $t['source'][$t_line] = str_replace("&lt;?php", "", $h_string);
                     }
                 }
                 $result['trace'][$tn] = $t;
             }
         }
     }
     return $result;
 }
    public function getCode($template, $gatewayName = null)
    {
        $payumConfigHtml = '';
        if ($gatewayName) {
            ob_start();
            include __DIR__ . '/../../../../../app/config/payum.yml';
            $config = Yaml::parse(ob_get_clean());
            $payumConfig = Yaml::dump(array('payum' => array('security' => $config['payum']['security'], 'gateways' => array($gatewayName => $config['payum']['gateways'][$gatewayName]))), $inline = 10);
            $payumConfigHtml = "<p><strong>Payum config:</strong></p><pre># app/config/payum.yml\n\n{$payumConfig}</pre>";
        }
        // highlight_string highlights php code only if '<?php' tag is present.
        $controller = highlight_string("<?php" . $this->getControllerCode(), true);
        $controller = str_replace('<span style="color: #0000BB">&lt;?php&nbsp;&nbsp;&nbsp;&nbsp;</span>', '&nbsp;&nbsp;&nbsp;&nbsp;', $controller);
        $template = htmlspecialchars($this->getTemplateCode($template), ENT_QUOTES, 'UTF-8');
        // remove the code block
        $template = str_replace('{% set code = code(_self) %}', '', $template);
        return <<<EOF
<p><strong><a name="whats-inside?">What's inside?</a></strong></p>

{$payumConfigHtml}

<p><strong>Controller Code</strong></p>
<pre>{$controller}</pre>

<p><strong>Template Code</strong></p>
<pre>{$template}</pre>
EOF;
    }
 function bbcode_callback($matches)
 {
     $type = $matches[1];
     $input = trim($matches[2], "\r\n");
     switch ($type) {
         case 'code':
             $search_replace = array('&' => '&amp;', ' ' => '&#160;', '&lt;' => '&#60;', '<' => '&#60;', '&gt;' => '&#62;', '>' => '&#62;', '&quot;' => '&#34;', ':' => '&#58;', '[' => '&#91;', ']' => '&#93;', ')' => '&#41;', '(' => '&#40;', '*' => '&#42;', '\\t' => '&#160;&#160;&#160;&#160;', '\\"' => '"', "\\'" => "'");
             $input = strtr($input, $search_replace);
             break;
         case 'php':
             if (substr($input, 0, 2) != '<?') {
                 $input = "<?php\n\n{$input}\n\n?>";
             }
             ob_start();
             highlight_string($input);
             $input = ob_get_contents();
             ob_end_clean();
             $input = str_replace('<br />', "\n", $input);
             break;
         default:
             return false;
     }
     $input = "<div class=\"bb-{$type}-title\">" . strtoupper($type) . ":</div>" . "<div class=\"bb-{$type}\">{$input}</div>";
     return $input;
 }
Exemple #21
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $source =& $this->source;
     $this->sanify_colors($string, $comment, $keyword, $bg, $default, $html);
     $this->set_colors($string, $comment, $keyword, $bg, $default, $html);
     if ($wrap) {
         /* Wrap with "<?php\n" and "\n?>" required by
          * highlight_string(): */
         $source = "<?php\n" . $source . "\n?>";
     } else {
         $source = str_replace(array('< ?php', '? >'), array('<?php', '?>'), $source);
     }
     $str = highlight_string($source, true);
     if ($wrap) {
         /* Remove "<?php\n" and "\n?>" again: */
         $str = str_replace(array('&lt;?php<br />', '?&gt;'), '', $str);
     }
     /* We might have made some empty font tags. */
     foreach (array($string, $comment, $keyword, $bg, $default, $html) as $color) {
         $search = "<font color=\"{$color}\"></font>";
         $str = str_replace($search, '', $str);
     }
     /* Remove also empty span tags. */
     foreach (array($string, $comment, $keyword, $bg, $default, $html) as $color) {
         $search = "<span style=\"color: {$color}\"></span>";
         $str = str_replace($search, '', $str);
     }
     /* restore default colors in case of multiple invocations of
        this plugin on one page */
     $this->restore_colors();
     return new RawXml($str);
 }
Exemple #22
0
 /**
  * @param $str
  * @return mixed|string
  */
 function codeHighlight($str)
 {
     // The highlight string function encodes and highlights
     // brackets so we need them to start raw
     $str = str_replace(array('&lt;', '&gt;'), array('<', '>'), $str);
     // Replace any existing PHP tags to temporary markers so they don't accidentally
     // break the string out of PHP, and thus, thwart the highlighting.
     $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
     // The highlight_string function requires that the text be surrounded
     // by PHP tags, which we will remove later
     $str = '<?php ' . $str . ' ?>';
     // <?
     // All the magic happens here, baby!
     $str = highlight_string($str, TRUE);
     // Prior to PHP 5, the highligh function used icky <font> tags
     // so we'll replace them with <span> tags.
     if (abs(PHP_VERSION) < 5) {
         $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str);
         $str = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $str);
     }
     // Remove our artificially added PHP, and the syntax highlighting that came with it
     $str = preg_replace('/<span style="color: #([A-Z0-9]+)">&lt;\\?php(&nbsp;| )/i', '<span style="color: #$1">', $str);
     $str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\\?&gt;<\\/span>\\n<\\/span>\\n<\\/code>/is', "\$1</span>\n</span>\n</code>", $str);
     $str = preg_replace('/<span style="color: #[A-Z0-9]+"\\><\\/span>/i', '', $str);
     // Replace our markers back to PHP tags.
     $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);
     return $str;
 }
Exemple #23
0
 /**
  * Converts PHP code into highlighted syntax using ANSI escape codes to pretty print on console.
  *
  * @param $str
  * @return string
  */
 public function highlight($str)
 {
     $str = highlight_string($str, true);
     $str = html_entity_decode($str);
     $replace = array('|</span>|' => "", '|<code>|' => '', '|</code>|' => '', '|<br //>|' => "\n");
     foreach ($replace as $html => $ansi) {
         $str = preg_replace($html, $ansi, $str);
     }
     // Replace all color spans with actual escape sequences
     $str = preg_replace_callback('|<span style="color: #([A-Z0-9]{6})">|', function ($matches) {
         switch ($matches[1]) {
             case '007700':
                 // green
                 return "";
             case 'DD0000':
                 // red
                 return "";
             case '0000BB':
                 // blue
                 return "";
             default:
                 // gray
                 return "";
         }
     }, $str);
     $arr_html = explode('<br />', $str);
     $out = '';
     foreach ($arr_html as $line) {
         $line = str_replace(chr(13), '', $line);
         $out .= $line . "\n";
     }
     return $out;
 }
    public function successMessage()
    {
        if (Yii::app()->hasModule($this->moduleID)) {
            return 'The module has been generated successfully. You may ' . CHtml::link('try it now', Yii::app()->createUrl($this->moduleID), array('target' => '_blank')) . '.';
        }
        $output = <<<EOD
<p>The module has been generated successfully.</p>
<p>To access the module, you need to modify the application configuration as follows:</p>
EOD;
        $code = <<<EOD
<?php
return array(
    'modules'=>array(
        '{$this->moduleID}',
    ),
    ......
);
EOD;
        $output2 = <<<EOD
<p>You will also need to add entries to the event_type and element_type tables, create tables for each element type, and any additional tables you may require. A migration to do this has been created for you which you can run using:</p>
EOD;
        $code2 = <<<EOD
./yiic migrate --migrationPath=application.modules.{$this->moduleID}.migrations
EOD;
        return $output . highlight_string($code, true) . $output2 . highlight_string($code2, true);
    }
 /**
  * Show the highlighted source code
  */
 public function show()
 {
     $span = new TElement('span');
     $span->style = 'font-size:10pt';
     $span->add(highlight_string($this->content, TRUE));
     $span->show();
 }
 function serialize($debug = false)
 {
     if ($debug) {
         highlight_string("Transport :" . print_r($this->infos, true));
     }
     return openurl_serialize_kev_mtx::serialize($this->infos);
 }
 function generate()
 {
     $thisTable = $this->tableObject;
     if ($thisTable->getDatabase() == "") {
         $dbName = "database";
     } else {
         $dbName = $thisTable->getDatabase();
     }
     $thisDatabaseQuery = new databaseQuery();
     $sql = "SELECT * FROM " . $thisTable->getTableName();
     $fieldNames = $thisTable->getFieldNameArray();
     $result = $thisDatabaseQuery->executeDirectQuery($sql);
     $code = "";
     $code .= "<?xml version=\"1.0\" ?>\n";
     $code .= "<" . $dbName . ">\n";
     while (!$result->EOF) {
         $code .= "\t<" . $thisTable->getTableName() . ">\n";
         $fields = $result->fields;
         for ($a = 0; $a < count($fieldNames); $a++) {
             $thisFieldName = $fieldNames[$a];
             $code .= "\t\t<" . $thisFieldName . ">";
             $code .= $fields[$thisFieldName];
             $code .= "</" . $thisFieldName . ">\n";
         }
         $code .= "\t</" . $thisTable->getTableName() . ">\n";
         $result->MoveNext();
     }
     // end while
     $code .= "</" . $dbName . ">\n";
     highlight_string($code);
     exit;
     $code = "";
     // Returning Generated Code
     return $code;
 }
Exemple #28
0
 public function Exception($exception)
 {
     $trace = $exception->getTrace();
     $trace = array_reverse($trace);
     $class = isset($trace[0]['class']) ? $trace[0]['class'] : '';
     $function = isset($trace[0]['function']) ? $trace[0]['function'] : '';
     $error['file'] = $trace[0]['file'];
     $error['line'] = $trace[0]['line'];
     if (empty($error['file']) or empty($error['line'])) {
         $error['file'] = $exception->getFile();
         $error['line'] = $exception->getLine();
     }
     $error['trace'] = "";
     foreach ((array) $trace as $k => $v) {
         array_walk($v['args'], function (&$item, $key) {
             $item = str_replace("\n", "", var_export($item, true));
         });
         if (isset($v['file'])) {
             $error['trace'] .= '#' . $k . ' ' . $v['file'] . '(' . $v['line'] . '): ' . (isset($v['class']) ? $v['class'] . '->' : '') . $v['function'] . '(' . implode(', ', $v['args']) . ')' . "\n";
         }
     }
     $error['message'] = $exception->getMessage();
     $error['type'] = get_class($exception);
     $fileContent = self::getContextFileLineError($error['file'], $error['line']);
     $fileContent = highlight_string("<?php \n" . $fileContent . "...*/", true);
     $error['detail'] = $fileContent;
     ob_clean();
     include 'ErrorHandle.tpl';
     exit;
 }
Exemple #29
0
 public static function php1($str, $withLines = false, $firstLine = 0, $currentLine = 0)
 {
     // The highlight string function encodes and highlights
     // brackets so we need them to start raw
     $str = str_replace(array('&lt;', '&gt;'), array('<', '>'), $str);
     // Replace any existing PHP tags to temporary markers so they don't accidentally
     // break the string out of PHP, and thus, thwart the highlighting.
     $str = str_replace(array('<?', '?>', '<%', '%>', '\\', '</script>'), array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), $str);
     // The highlight_string function requires that the text be surrounded
     // by PHP tags, which we will remove later
     $str = '<?php ' . $str . ' ?>';
     // <?
     // All the magic happens here, baby!
     $str = highlight_string($str, true);
     // Remove our artificially added PHP, and the syntax highlighting that came with it
     $str = preg_replace('/<span style="color: #([A-Z0-9]+)">&lt;\\?php(&nbsp;| )/i', '<span style="color: #$1">', $str);
     //$str = preg_replace('/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is', "$1</span>\n</span>\n</code>", $str);
     //$str = preg_replace('/<span style="color: #[A-Z0-9]+"\><\/span>/i', '', $str);
     // Replace our markers back to PHP tags.
     $str = str_replace(array('phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'), array('&lt;?', '?&gt;', '&lt;%', '%&gt;', '\\', '&lt;/script&gt;'), $str);
     //var_dump( $str );exit();
     if ($withLines) {
         $str = substr(substr($str, 0, -15), 35);
         $str = trim(str_replace('<br /></span>', '</span><br />', str_replace('<br /><br /></span>', '</span><br /><br />', $str)));
         $str1 = '<span style="color: #000000"><table>';
         foreach (explode('<br />', $str) as $line) {
             //$str1 .= '<tr><td>'.($l+$firstLine).'</td><td>'.$line."</td></tr>\n";
             $str1 .= $line . "\n";
         }
         $str1 .= '</table></span>';
         return $str1;
     }
     return $str;
 }
Exemple #30
-1
function syntax_hilight($enscript_path, $code, $lang)
{
    if ($lang == 'php') {
        $buffer = highlight_string($code, true);
        $buffer = preg_replace('/^.*<code>/', '', $buffer);
        $buffer = preg_replace('/<\\/code>.*$/', '', $buffer);
        $buffer = str_replace("\n", "", $buffer);
        $buffer = str_replace("&nbsp;", " ", $buffer);
        $buffer = '<br /><br />' . implode("\n", explode("<br />", $buffer));
    } else {
        $lang = escapeshellarg($lang);
        $argv = "-C -q -p - -E --highlight={$lang} --language=html --color";
        $desc = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'a'));
        if (!is_resource($pipe = proc_open($enscript_path . ' ' . $argv, $desc, $pipes))) {
            die("Error");
        }
        fwrite($pipes[0], $code);
        fclose($pipes[0]);
        $buffer = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        proc_close($pipe);
        $buffer = eregi_replace('^.*<PRE>', '<pre>', $buffer);
        $buffer = eregi_replace('</PRE>.*$', '</pre>', $buffer);
    }
    $buffer = eregi_replace('<FONT COLOR="', '<span style="color:', $buffer);
    $buffer = eregi_replace('</FONT>', '</style>', $buffer);
    return $buffer;
}