/mvc/elements/code
[return to app]1
<?php
2 if (!isset($code)) {
3 echo $html->div('[no code]');
4 return;
5 }
6
7 $wrap = '
';
8 $codeLines = explode("\n", $code);
9 foreach ($codeLines as $lineNum => $codeLine) {
10 $codeLines[$lineNum] = wordwrap($codeLine, 114, $wrap, true);
11 }
12 $code = implode("\n", $codeLines);
13
14 $code = explode('<br />', $html->phpCode(!is_array($code) ? $code : implode(PHP_EOL, $code)));
15
16 $padIterator = $lineNum = 0;
17 $pixelsPerDigit = 7;
18 $digitLen = strlen(count($code));
19 for ($numberOfZeros = 5; $numberOfZeros > 0; $numberOfZeros--) { // functional to diplay up to 100,000 lines of
code
20 if ($numberOfZeros < $digitLen) {
21 $padIterator += $pixelsPerDigit;
22 }
23 $pad[pow(10, $numberOfZeros)] = $padIterator;
24 }
25
26 $basePower = $charWidth = 10;
27 $padSize = end($pad);
28 echo '<div class="codeblock">';
29 foreach ($code as $line) {
30 if (++$lineNum == $basePower) {
31 $basePower *= $charWidth;
32 $padSize = $pad[$basePower];
33 }
34 echo '<span style="padding-left: ' . $padSize . 'px">' . $lineNum . '</span> '
35 . str_replace($wrap, '<br /><span style="padding-left: ' . ($padSize + $charWidth) . 'px"> </span>',
$line)
36 . '<br />' . PHP_EOL;
37 }
38 echo '</div>';