/build.properties
/dist
/lib/
+/src/gen-rewritemap.php
/www/*.phar
/www/*.phar.bz2
<?php
+$pharFile = \Phar::running();
+if ($pharFile == '') {
+ $phorkieDir = __DIR__ . '/../';
+} else {
+ //remove phar:// from the path
+ $phorkieDir = dirname(substr($pharFile, 7)) . '/';
+}
+
$GLOBALS['phorkie']['cfg'] = array(
'debug' => false,
- 'gitdir' => __DIR__ . '/../repos/git/',
- 'workdir' => __DIR__ . '/../repos/work/',
+ 'gitdir' => $phorkieDir . 'repos/git/',
+ 'workdir' => $phorkieDir . 'repos/work/',
'tpl' => __DIR__ . '/templates/',
- 'baseurl' => '/',
+ 'baseurl' => null,
'avatars' => true,
'css' => '',
'iconpng' => '',//phorkie browser icon (favicon)
--- /dev/null
+<?php
+/**
+ * Convert the .htaccess rewrite rules into an array of pattern-replacement
+ * pairs.
+ * Writes src/gen-rewritemap.php
+ */
+$lines = file(__DIR__ . '/../www/.htaccess');
+$patterns = array();
+foreach ($lines as $line) {
+ if (substr($line, 0, 11) == 'RewriteRule') {
+ list($n, $pattern, $replace) = explode(' ', rtrim($line));
+ $patterns['#' . $pattern . '#'] = $replace;
+ }
+}
+file_put_contents(
+ __DIR__ . '/../src/gen-rewritemap.php',
+ "<?php\n/* automatically created from www/.htaccess */\nreturn "
+ . var_export($patterns, true)
+ . ";\n?>\n"
+);
+?>
*/
public function toHtml(File $file, Tool_Result $res = null)
{
- if (!class_exists('\\GeSHi', true)) {
- require_once 'geshi.php';
+ /**
+ * Yes, geshi needs to be in your include path
+ * We use the geshi pear package.
+ */
+ if (!class_exists('\\geshi', true)) {
+ require_once $GLOBALS['phorkie']['cfg']['geshi'];
}
- $geshi = new \GeSHi($file->getContent(), $this->getType($file));
+ $geshi = new \geshi($file->getContent(), $this->getType($file));
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_header_type(GESHI_HEADER_DIV);
}
}
- if (!class_exists('GeSHi', true)) {
- @include_once 'geshi.php';
- if (!class_exists('GeSHi', false)) {
- $this->fail('PEAR package not installed: pear.geshi.org/geshi');
+ if (!class_exists('geshi', true)) {
+ $geshi = stream_resolve_include_path(
+ $GLOBALS['phorkie']['cfg']['geshi']
+ );
+ if ($geshi === false) {
+ $this->fail('GeSHi not available');
}
}
return $file;
}
-}
+ public static function detectBaseUrl()
+ {
+ if (!isset($_SERVER['REQUEST_URI'])
+ || !isset($_SERVER['SCRIPT_NAME'])
+ ) {
+ return '/';
+ }
+
+ $scriptName = $_SERVER['SCRIPT_NAME'];
+ $requestUri = $_SERVER['REQUEST_URI'];
+ if (substr($scriptName, -4) != '.php') {
+ //a phar
+ return $scriptName . '/';
+ }
+
+ if (substr($requestUri, -4) != '.php') {
+ $requestUri .= '.php';
+ }
+ $snl = strlen($scriptName);
+ if (substr($requestUri, -$snl) == $scriptName) {
+ return substr($requestUri, 0, -$snl) . '/';
+ }
+
+ return '/';
+ }
+}
?>
*
* @author Christian Weiske <cweiske@cweiske.de>
*/
-if (file_exists(__DIR__ . '/../../lib/autoload.php')) {
+if (file_exists(__DIR__ . '/../../lib/PEAR.php')) {
+ //phing-installed dependencies available ("phing collectdeps")
+ set_include_path(
+ __DIR__ . '/../'
+ . PATH_SEPARATOR . __DIR__ . '/../../lib/'
+ . PATH_SEPARATOR . '.'
+ );
+} else if (file_exists(__DIR__ . '/../../lib/autoload.php')) {
//composer-installed dependencies available
set_include_path(
__DIR__ . '/../'
return 'www/index.php';
}
- if (substr($path, -4) == '.css') {
+ $path = rewriteWithHtaccess($path);
+
+ if (substr($path, -4) == '.css' || substr($path, -3) == '.js') {
header('Expires: ' . date('r', time() + 86400 * 7));
}
- return $path;
+ return 'www' . $path;
+}
+
+function rewriteWithHtaccess($path)
+{
+ //remove the trailing slash /
+ $cpath = substr($path, 1);
+ $bFoundMatch = false;
+ $map = include(__DIR__ . '/../src/gen-rewritemap.php');
+ foreach ($map as $pattern => $replace) {
+ if (preg_match($pattern, $cpath, $matches)) {
+ $bFoundMatch = true;
+ break;
+ }
+ }
+ if (!$bFoundMatch) {
+ return $path;
+ }
+ $newcpath = preg_replace($pattern, $replace, $cpath);
+ if (strpos($newcpath, '?') === false) {
+ return '/' . $newcpath;
+ }
+ list($cfile, $getParams) = explode('?', $newcpath, 2);
+ if ($getParams != '') {
+ parse_str($getParams, $_GET);
+ }
+ return '/' . $cfile;
}
//Phar::interceptFileFuncs();
);
require_once __DIR__ . '/../data/config.default.php';
-if (file_exists(__DIR__ . '/../data/config.php')) {
- require_once __DIR__ . '/../data/config.php';
+$pharFile = \Phar::running();
+if ($pharFile == '') {
+ $cfgFilePath = __DIR__ . '/../data/config.php';
+} else {
+ //remove phar:// from the path
+ $cfgFilePath = substr($pharFile, 7) . '.config.php';
+}
+$GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = false;
+if (file_exists($cfgFilePath)) {
+ $GLOBALS['phorkie']['cfgfiles'][$cfgFilePath] = true;
+ require_once $cfgFilePath;
+}
+
+if ($GLOBALS['phorkie']['cfg']['baseurl'] === null) {
+ $GLOBALS['phorkie']['cfg']['baseurl'] = Tools::detectBaseUrl();
}
// Set/Get git commit session variables