function print_file($filename, $filedata, $showln = true) { $ext = strtolower(vpl_fileExtension($filename)); if (isset(self::$map[$ext])) { $lang = self::$map[$ext]; } else { $lang = 'text'; } $line = 0; $insert_link = function ($found) use($filename, &$line) { $ret = '<span class="vpl_ln">'; $line++; $name = $filename . '.' . $line; $ret .= '<a name="' . $name . '"></a>'; $ret .= sprintf('%5d', $line); $ret .= ' </span>'; return $ret . '<span '; }; $code = '<pre class="vpl_sh vpl_g">'; $code .= '<span syntax="' . $lang . '"'; $code .= $showln ? ' linenumbers="yes"' : ''; $code .= '>' . htmlentities($filedata, ENT_NOQUOTES) . '</span>'; $code .= '</pre>'; $html = format_text($code, FORMAT_HTML, array('noclean' => true)); if (preg_match('(<li )', $html) == 1) { $html = preg_replace_callback('(<li )', $insert_link, $html); $html = preg_replace('(</li>)', '</span>', $html); $html = preg_replace('(<div [^>]*><ol>)', '', $html); $html = preg_replace('(</ol></div>)', '', $html); echo $html; } else { $printer = vpl_sh_factory::get_object('text'); $printer->print_file($filename, $filedata, $showln); } }
static function show($filename1, $data1, $HTMLheader1, $filename2, $data2, $HTMLheader2) { //Get file lines $nl = vpl_detect_newline($data1); $lines1 = explode($nl, $data1); $nl = vpl_detect_newline($data2); $lines2 = explode($nl, $data2); //Get dif as an array of info $diff = self::calculateDiff($lines1, $lines2); if ($diff === false) { return; } $separator = array('<' => ' <<< ', '>' => ' >>> ', '=' => ' === ', '#' => ' ### '); $emptyline = " \n"; $data1 = ''; $data2 = ''; $datal1 = ''; $datal2 = ''; $diffl = ''; $lines1[-1] = ''; $lines2[-1] = ''; foreach ($diff as $line) { $diffl .= $separator[$line->type] . "\n"; if ($line->ln1) { $datal1 .= $line->ln1 . " \n"; $data1 .= $lines1[$line->ln1 - 1] . "\n"; } else { $data1 .= " \n"; $datal1 .= $emptyline; } if ($line->ln2) { $datal2 .= $line->ln2 . " \n"; $data2 .= $lines2[$line->ln2 - 1] . "\n"; } else { $data2 .= " \n"; $datal2 .= $emptyline; } } echo '<div style="width: 100%;min-width: 950px; overflow: auto">'; //Header echo '<div style="float:left; width: 445px">'; echo $HTMLheader1; echo '</div>'; echo '<div style="float:left; width: 445px">'; echo $HTMLheader2; echo '</div>'; echo '<div style="clear:both;"></div>'; //Files echo '<div style="float:left; text-align: right">'; echo '<pre class="' . vpl_sh_base::c_general . '">'; echo $datal1; echo '</pre>'; echo '</div>'; echo '<div style="float:left; width: 390px; overflow:auto">'; $shower = vpl_sh_factory::get_sh($filename1); $shower->print_file($filename1, $data1, false); echo '</div>'; echo '<div style="float:left">'; echo '<pre class="' . vpl_sh_base::c_general . '">'; echo $diffl; echo '</pre>'; echo '</div>'; echo '<div style="float:left; text-align: right;">'; echo '<pre class="' . vpl_sh_base::c_general . '">'; echo $datal2; echo '</pre>'; echo '</div>'; echo '<div style="float:left; width: 390px; overflow:auto">'; $shower = vpl_sh_factory::get_sh($filename2); $shower->print_file($filename2, $data2, false); echo '</div>'; echo '</div>'; echo '<div style="clear:both;"></div>'; }
/** * Print file group **/ function print_files($if_no_exist = true) { global $OUTPUT; $filenames = $this->getFileList(); foreach ($filenames as $name) { if (file_exists($this->dir . self::encodeFileName($name))) { echo '<h3>' . s($name) . '</h3>'; $printer = vpl_sh_factory::get_sh($name); echo $OUTPUT->box_start(); $data = $this->getFileData($name); $printer->print_file($name, $data); echo $OUTPUT->box_end(); } elseif ($if_no_exist) { echo '<h3>' . s($name) . '</h3>'; } } }