Permalink
Browse files

Move all hardcoded folder names into config vars

Everything is now set within extensions/config.php.
  • Loading branch information...
1 parent 451907a commit dafc902f08f5d5a7736137a0d5369f546e5d5597 @kolber committed May 26, 2012
View
4 app/asset-types/page.inc.php
@@ -62,9 +62,9 @@ static function template_name($file_path) {
static function template_file($template_name) {
$template_name = preg_replace('/([^.]*\.)?([^.]*)$/', '\\2', $template_name);
- $template_file = glob('./templates/'.$template_name.'.*');
+ $template_file = glob(Config::$templates_folder.'/'.$template_name.'.*');
# return template if one exists
- return isset($template_file[0]) ? $template_file[0] : './templates/default.html';
+ return isset($template_file[0]) ? $template_file[0] : Config::$templates_folder.'/default.html';
}
}
View
8 app/cache.inc.php
@@ -11,11 +11,11 @@ function __construct($file_path, $template_file) {
# generate an md5 hash from the file_path
$this->path_hash = $this->generate_hash($file_path);
# generate an md5 hash from the current state of the site content
- $htaccess = file_exists('./.htaccess') ? '.htaccess:'.filemtime('./.htaccess') : '';
+ $htaccess = file_exists($root_folder.'.htaccess') ? '.htaccess:'.filemtime($root_folder.'.htaccess') : '';
$file_cache = serialize(Helpers::file_cache());
$content_hash = $this->generate_hash($htaccess.$file_cache);
# combine the two hashes to create a cachefile name
- $this->cachefile = './app/_cache/pages/'.$this->cache_prefix.$this->path_hash.'-'.$content_hash;
+ $this->cachefile = Config::$cache_folder.'/pages/'.$this->cache_prefix.$this->path_hash.'-'.$content_hash;
# store the hash
$this->hash = $this->cache_prefix.$this->path_hash.'-'.$content_hash;
}
@@ -32,7 +32,7 @@ function render() {
function delete_old_caches() {
# collect a list of all cache files matching the same file_path hash and delete them
- $old_caches = glob('./app/_cache/pages/'.$this->cache_prefix.$this->path_hash.'-*');
+ $old_caches = glob(Config::$cache_folder.'/pages/'.$this->cache_prefix.$this->path_hash.'-*');
foreach($old_caches as $file) unlink($file);
}
@@ -45,7 +45,7 @@ function create($route) {
ob_start();
echo $page->parse_template();
# if cache folder is writable, write to it
- if(is_writable('./app/_cache/pages') && !$page->data['bypass_cache']) $this->write_cache();
+ if(is_writable(Config::$cache_folder.'/pages') && !$page->data['bypass_cache']) $this->write_cache();
# end buffer
ob_end_flush();
return '';
View
11 app/helpers.inc.php
@@ -31,7 +31,7 @@ static function url_to_file_path($url) {
# if the url is empty, we're looking for the index page
$url = empty($url) ? 'index': $url;
- $file_path = './content';
+ $file_path = Config::$content_folder;
# Split the url and recursively unclean the parts into folder names
$url_parts = explode('/', $url);
foreach($url_parts as $u) {
@@ -53,9 +53,9 @@ static function has_children($dir) {
static function file_cache($dir = false) {
if(!self::$file_cache) {
# build file cache
- self::build_file_cache('./app');
- self::build_file_cache('./content');
- self::build_file_cache('./templates');
+ self::build_file_cache(Config::$app_folder);
+ self::build_file_cache(Config::$content_folder);
+ self::build_file_cache(Config::$templates_folder);
}
if($dir && !isset(self::$file_cache[$dir])) return array();
return $dir ? self::$file_cache[$dir] : self::$file_cache;
@@ -133,7 +133,8 @@ static function last_modified($dir) {
return $last_modified;
}
- static function site_last_modified($dir = './content') {
+ static function site_last_modified($dir = false) {
+ if (!$dir) $dir = Config::$content_folder;
$last_updated = 0;
foreach(Helpers::list_files($dir, '/.*/', false) as $file) {
if(filemtime($file) > $last_updated) $last_updated = filemtime($file);
View
6 app/page-data.inc.php
@@ -28,7 +28,7 @@ static function get_parent($file_path, $url) {
array_pop($split_path);
$parent_path = array(implode('/', $split_path));
- return $parent_path[0] == './content' ? array() : $parent_path;
+ return $parent_path[0] == Config::$content_folder ? array() : $parent_path;
}
static function get_parents($file_path, $url) {
@@ -143,7 +143,7 @@ static function create_vars($page) {
static function create_collections($page) {
# page.root
- $page->root = Helpers::list_files('./content', '/^\d+?\./', true);
+ $page->root = Helpers::list_files(Config::$content_folder, '/^\d+?\./', true);
# page.query
$page->query = $_GET;
# page.parent
@@ -152,7 +152,7 @@ static function create_collections($page) {
# page.parents
$page->parents = self::get_parents($page->file_path, $page->url_path);
# page.siblings
- $parent_path = !empty($parent_path[0]) ? $parent_path[0] : './content';
+ $parent_path = !empty($parent_path[0]) ? $parent_path[0] : Config::$content_folder;
$split_url = explode("/", $page->url_path);
$page->siblings = Helpers::list_files($parent_path, '/^\d+?\.(?!'.$split_url[(count($split_url) - 1)].')/', true);
# page.siblings_and_self
View
5 app/parsers/slir/slirconfig.class.php
@@ -26,6 +26,7 @@
/* $Id: slirconfig-sample.class.php 123 2010-12-21 18:58:03Z joe.lencioni $ */
require_once 'slirconfigdefaults.class.php';
+require_once '../../../extensions/config.php';
/**
* SLIR Config Class
@@ -44,11 +45,11 @@ class SLIRConfig extends SLIRConfigDefaults
public static function init()
{
- self::$cacheDir = '../../_cache/images';
+ self::$cacheDir = '../../../'.Config::$cache_folder.'/images';
self::$documentRoot = '../../..';
// This must be the last line of this function
parent::init();
}
}
-SLIRConfig::init();
+SLIRConfig::init();
View
4 app/parsers/template-parser.inc.php
@@ -14,8 +14,8 @@ static function parse($data, $template) {
$template = self::find_template($template);
Twig_Autoloader::register();
- $loader = new Twig_Loader_Filesystem('templates');
- $cache = is_writable('app/_cache/templates') ? 'app/_cache/templates' : false;
+ $loader = new Twig_Loader_Filesystem(Config::$templates_folder);
+ $cache = is_writable(Config::$cache_folder.'/templates') ? Config::$cache_folder.'/templates' : false;
$twig = new Twig_Environment($loader, array(
'cache' => $cache,
'auto_reload' => true,
View
4 app/stacey.inc.php
@@ -136,8 +136,8 @@ function __construct($get) {
if($e->getMessage() == "404") {
# return 404 headers
header('HTTP/1.0 404 Not Found');
- if(file_exists('./content/404')) {
- $this->create_page('./content/404', '404');
+ if(file_exists(Config::$content_folder.'/404')) {
+ $this->create_page(Config::$content_folder.'/404', '404');
}
else if(file_exists('./public/404.html')) {
echo file_get_contents('./public/404.html');
View
14 extensions/config.php
@@ -0,0 +1,14 @@
+<?php
+
+class Config {
+
+ public static $root_folder = './';
+ public static $app_folder = './app';
+ public static $content_folder = './content';
+ public static $templates_folder = './templates';
+ public static $cache_folder = './app/_cache';
+ public static $extensions_folder = './extensions';
+
+}
+
+?>
View
2 index.php
@@ -7,6 +7,8 @@
} else {
+ # require config
+ require_once './extensions/config.php';
# require helpers class so we can use rglob
require_once './app/helpers.inc.php';
# require the yaml parser

0 comments on commit dafc902

Please sign in to comment.