[phpcvsview-cvs-updates] phpcvsview func_FileView.php,1.15,1.16
Status: Pre-Alpha
Brought to you by:
bcheesem
From: Brian C. <bch...@us...> - 2005-02-18 10:30:32
|
Update of /cvsroot/phpcvsview/phpcvsview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7462 Modified Files: func_FileView.php Log Message: Added Cache functionality. Index: func_FileView.php =================================================================== RCS file: /cvsroot/phpcvsview/phpcvsview/func_FileView.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** func_FileView.php 4 Feb 2005 09:45:24 -0000 1.15 --- func_FileView.php 18 Feb 2005 10:30:24 -0000 1.16 *************** *** 26,93 **** echo GetPageHeader($env['CVSSettings']['html_title'], $env['CVSSettings']['html_header']); ! // Connect to the CVS server. ! if ($CVSServer->Connect() === true) { ! ! // Authenticate against the server. ! $Response = $CVSServer->Authenticate(); ! if ($Response !== true) { ! return; } ! ! // Get a RLOG of the module path specified in $env['mod_path']. ! $CVSServer->RLog($env['mod_path']); ! ! // "Export" the file. ! $Response = $CVSServer->ExportFile($File, $Revision); ! if ($Response !== true) { ! return; } ! ! // Add the quick link navigation bar. ! echo GetQuickLinkBar($lang['code_view'], true, true, $Revision); ! ! echo "<hr />\n"; ! ! if ($config['GeSHi']['Enable']) { ! // Create the GeSHi instance and parse the output. ! // TODO: setup code to auto identify the highlighting class to use for current file. ! $FileExt = substr($File, strrpos($File, '.')+1); ! $Language = guess_highlighter($FileExt); ! if (is_array($Language)) { ! $Language = $Language[0]; } ! ! $geshi = new GeSHi($CVSServer->FILECONTENTS, $Language, $config['GeSHi']['HighlightersPath']); ! $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); ! $geshi->set_line_style('background: #fcfcfc;'); ! $geshi->set_tab_width(4); ! $hlcontent = $geshi->parse_code(); ! // Display the file contents. ! echo '<table class="source"><tr><td>'; ! echo $hlcontent; ! echo '</td></tr></table>'; ! } ! else ! { ! $search = array('<', '>', '\n', '\t'); ! $replace = array('<', '>', '', ' '); ! $content = str_replace($search, $replace, $CVSServer->FILECONTENTS); ! $source = explode('\n', $content); ! $soure_size = sizeof($source); ! ! echo "<pre>\n"; ! for($i = 1; $i <= $soure_size; $i++) { ! echo '<a name="'.$i.'" class="numberedLine"> '.str_repeat(' ', strlen($soure_size) - strlen($i)). $i.'.</a> ' . $source[$i-1] . "\n"; } ! echo "</pre>\n"; } - echo "<hr />"; - - // Close the connection. - $CVSServer->Disconnect(); - } else { - echo $lang['err_connect']; } echo GetPageFooter(); } --- 26,126 ---- echo GetPageHeader($env['CVSSettings']['html_title'], $env['CVSSettings']['html_header']); ! // Add the quick link navigation bar. ! echo GetQuickLinkBar($lang['code_view'], true, true, $Revision)."<hr />\n"; ! ! // Check and see if this file and version has already been viewed and exists in the cache. ! if ($config['Cache']['Enable']) { ! $CachedFileName = $config['Cache']['Location']; ! if (!file_exists($CachedFileName)) { ! mkdir($CachedFileName, 0750); } ! } ! $CachedFileName .= "/".str_replace("/", "_", $File).",$Revision"; ! if (file_exists($CachedFileName) && $config['Cache']['Enable']) { ! $fd = fopen($CachedFileName, "r"); ! if ($fd !== false) { ! fpassthru($fd); ! fclose($fd); } ! } ! else ! { ! // Connect to the CVS server. ! if ($CVSServer->Connect() === true) { ! ! // Authenticate against the server. ! $Response = $CVSServer->Authenticate(); ! if ($Response !== true) { ! return; } ! ! // Get a RLOG of the module path specified in $env['mod_path']. ! $CVSServer->RLog($env['mod_path']); ! ! // "Export" the file. ! $Response = $CVSServer->ExportFile($File, $Revision); ! if ($Response !== true) { ! return; ! } ! ! if ($config['GeSHi']['Enable']) { ! // Create the GeSHi instance and parse the output. ! // TODO: setup code to auto identify the highlighting class to use for current file. ! $FileExt = substr($File, strrpos($File, '.')+1); ! $Language = guess_highlighter($FileExt); ! if (is_array($Language)) { ! $Language = $Language[0]; ! } ! ! $geshi = new GeSHi($CVSServer->FILECONTENTS, $Language, $config['GeSHi']['HighlightersPath']); ! $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); ! $geshi->set_line_style('background: #fcfcfc;'); ! $geshi->set_tab_width(4); ! $hlcontent = $geshi->parse_code(); ! ! // Store in the current cache. ! $fd = fopen($CachedFileName, "w"); ! if ($fd !== false) { ! fwrite($fd, '<table class="source"><tr><td>'.$hlcontent.'</td></tr></table>'); ! fclose($fd); ! } ! // Display the file contents. ! echo '<table class="source"><tr><td>'; ! echo $hlcontent; ! echo '</td></tr></table>'; } ! else ! { ! $search = array('<', '>', '\n', '\t'); ! $replace = array('<', '>', '', ' '); ! $content = str_replace($search, $replace, $CVSServer->FILECONTENTS); ! $source = explode('\n', $content); ! $soure_size = sizeof($source); ! ! $fd = fopen($CachedFileName, "w"); ! if ($fd !== false) { ! fwrite($fd, "<pre>\n"); ! } ! echo "<pre>\n"; ! for($i = 1; $i <= $soure_size; $i++) { ! $line = '<a name="'.$i.'" class="numberedLine"> '.str_repeat(' ', strlen($soure_size) - strlen($i)). $i.'.</a> ' . $source[$i-1] . "\n"; ! if ($fd !== false) { ! fwrite($fd, $line); ! } ! echo $line; ! } ! if ($fd !== false) { ! fwrite($fd, "</pre>\n"); ! } ! echo "</pre>\n"; ! } ! // Close the connection. ! $CVSServer->Disconnect(); ! } else { ! echo $lang['err_connect']; } } + echo "<hr />"; echo GetPageFooter(); } |