This is another approach.
Greez.
From 9d4517705b4a1647e2039ddda9d4bda7632b0e96 Mon Sep 17 00:00:00 2001
From: Manuel Tortosa <[email protected]>
Date: Sun, 3 Oct 2010 11:32:28 +0200
Subject: [PATCH] Add pkgbuild syntax highlight with GeShi

---
 web/html/pkgbuild_view.php   |   35 +++++++++++++++++++++++++++++++++++
 web/lib/config.inc.proto     |    3 +++
 web/template/pkg_details.php |    2 +-
 3 files changed, 39 insertions(+), 1 deletions(-)
 create mode 100644 web/html/pkgbuild_view.php

diff --git a/web/html/pkgbuild_view.php b/web/html/pkgbuild_view.php
new file mode 100644
index 0000000..759145c
--- /dev/null
+++ b/web/html/pkgbuild_view.php
@@ -0,0 +1,35 @@
+<?php
+set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR . $GESHI_PATH);
+
+include('aur.inc');
+include('config.inc');
+include_once('geshi.php'); 
+
+$file = URL_DIR . "/". urlencode(basename($_GET['p']))."/".urlencode(basename($_GET['p']))."/PKGBUILD"; 
+
+if (is_file($file)) {
+	$text = file_get_contents($file);
+} else {
+	$text = "";
+}
+
+$language = 'bash';
+
+html_header(); 
+?>
+
+<div class='pgbox'>
+	<div class='pgbuildbody'>
+		<?php if ($text != "") {
+			$geshi = new GeSHi($text, $language);
+			$geshi->set_header_type(GESHI_HEADER_DIV); ?> 
+			<span class='f4'> <?php echo $geshi->parse_code() ?> </span>
+		<?php } else { ?> 
+			<span class='f4'> <?php print __("Sorry, this file it's not a valid PKGBUILD") ?> </span> 
+		<?php } ?>
+	</div>
+</div>
+
+<?php 
+html_footer(AUR_VERSION); 
+?>
\ No newline at end of file
diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto
index 6ffaf2e..0277ff2 100644
--- a/web/lib/config.inc.proto
+++ b/web/lib/config.inc.proto
@@ -47,3 +47,6 @@ $SUPPORTED_LANGS = array(
 # Idle seconds before timeout
 $LOGIN_TIMEOUT = 7200;
 
+# Set this to true if you want to display the pkgbuild using GeShi
+define( "USE_GESHI", false );
+$GESHI_PATH = "../lib";
\ No newline at end of file
diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php
index 9c76ab3..a19bfeb 100644
--- a/web/template/pkg_details.php
+++ b/web/template/pkg_details.php
@@ -66,7 +66,7 @@ $submitted_time = ($row["SubmittedTS"] == 0) ? "(unknown)" : gmdate("r", intval(
 <?php
 		if ($row['LocationID'] == 2) {
 			$urlpath = URL_DIR . $row['Name'] . '/' . $row['Name'];
-			print "<a href='$urlpath.tar.gz'>".__("Tarball")."</a> :: <a href='$urlpath'>".__("Files")."</a> :: <a href='$urlpath/PKGBUILD'>PKGBUILD</a></span>";
+			print "<a href='$urlpath.tar.gz'>".__("Tarball")."</a> :: <a href='$urlpath'>".__("Files")."</a> ::" . ((USE_GESHI) ? ("<a href='pkgbuild_view.php?p=".$row['Name']) : ("<a href='$urlpath/PKGBUILD")) . "'>".__("PKGBUILD")."</a></span>";
 		}
 
 		if ($row["OutOfDate"] == 1) {
-- 
1.7.1

Reply via email to