mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-18 23:46:39 +00:00
created a configuration object model, and other minor changes...
git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@6 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
@@ -11,7 +11,7 @@ $config = array(
|
||||
|
||||
// File system settings
|
||||
|
||||
'show_hidden' => true,
|
||||
'show_hidden' => false,
|
||||
|
||||
// Display settings
|
||||
|
||||
|
||||
@@ -19,18 +19,11 @@ Author: Jim Myhrberg
|
||||
//>STAGE> init
|
||||
//==========================
|
||||
|
||||
|
||||
//>Section> define_constants
|
||||
define('DIR_URL', $dir_url);
|
||||
define('DIR_PATH', $dir_path);
|
||||
define('QUERY_STRING', $query_string);
|
||||
|
||||
define('DLIST_URL', $config['url']);
|
||||
define('TEMPLATE', $config['template']);
|
||||
define('TPL_URL', DLIST_URL.'templates/'.TEMPLATE.'/');
|
||||
//>Section> start_timer:10
|
||||
$timer = new speedometer();
|
||||
|
||||
|
||||
//>Section> port_correction
|
||||
//>Section> port_correction:20
|
||||
if ( stristr($_SERVER['HTTP_HOST'], ':') !== false ) {
|
||||
$http_host = explode(':', $_SERVER['HTTP_HOST'], 2);
|
||||
$_SERVER['SERVER_PORT'] = $http_host[1];
|
||||
@@ -40,9 +33,22 @@ preg_match("/(.*)Port [0-9]{2,8}(.*)/", $_SERVER['SERVER_SIGNATURE'], $serverinf
|
||||
$_SERVER['SERVER_SIGNATURE'] = $serverinfo[1].'Port '.$_SERVER['SERVER_PORT'].$serverinfo[2];
|
||||
|
||||
|
||||
//>Section> set_vars
|
||||
//>Section> define_constants:30
|
||||
define('DIR_URL', $dir_url);
|
||||
define('DIR_PATH', $dir_path);
|
||||
define('QUERY_STRING', $query_string);
|
||||
|
||||
define('DLIST_URL', $config->url);
|
||||
define('TEMPLATE', $config->template);
|
||||
define('TPL_PATH', 'templates/'.TEMPLATE.'/');
|
||||
define('TPL_URL', DLIST_URL.TPL_PATH);
|
||||
|
||||
|
||||
//>Section> dynamic_vars
|
||||
$do_readdir = true;
|
||||
$do_render = true;
|
||||
$do_sort_items = true;
|
||||
$do_sort_reverse = false;
|
||||
|
||||
|
||||
//==========================
|
||||
@@ -50,21 +56,32 @@ $do_render = true;
|
||||
//==========================
|
||||
|
||||
|
||||
//>Section> init_dList
|
||||
//>Section> readdir
|
||||
if ( $do_readdir ) {
|
||||
//>Section> readdir.start
|
||||
$dlist = new dirlist();
|
||||
if ($config['show_hidden']) $dlist->show_hidden = true;
|
||||
//>Section> readdir.options
|
||||
if ( empty($do_sort_items) ) {
|
||||
$dlist->sort_items = false;
|
||||
} elseif (!empty($do_sort_reverse)) $dlist->reverse = true;
|
||||
if ($config->show_hidden) $dlist->show_hidden = true;
|
||||
//>Section> readdir.read
|
||||
$dlist->read(DIR_PATH);
|
||||
//>Section> readdir.end
|
||||
}
|
||||
|
||||
|
||||
//==========================
|
||||
//>STAGE> render
|
||||
//==========================
|
||||
|
||||
|
||||
//>Section> end_timer:10
|
||||
$timer->end();
|
||||
|
||||
|
||||
//>Section> echo
|
||||
print_r($dlist->list);
|
||||
print_r($config);
|
||||
|
||||
|
||||
//_END;
|
||||
|
||||
64
libs/config.lib.php
Normal file
64
libs/config.lib.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
class config {
|
||||
|
||||
/*
|
||||
|
||||
Class: config v0.1 beta
|
||||
|
||||
Copyright © 2006 Jim Myhrberg. All rights reserved.
|
||||
zynode@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
|
||||
function config ($input=false) {
|
||||
if ( !empty($input) ) $this->parse($input);
|
||||
}
|
||||
|
||||
function parse ($input, $overwrite=true) {
|
||||
if ( is_array($input) ) {
|
||||
$this->parse_array($input, $overwrite);
|
||||
} elseif ( is_string($input) ) {
|
||||
if ( preg_match("/.php$/", $input) ) {
|
||||
$this->parse_php_file($input, 'config', $overwrite);
|
||||
} else {
|
||||
$this->parse_ini_file($input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parse_array ($input, $overwrite=true) {
|
||||
if ( is_array($input) ) {
|
||||
foreach( $input as $key => $value ) {
|
||||
if ( is_array($value) ) {
|
||||
foreach( $value as $k => $v ) {
|
||||
if ( ($empty = empty($this->$key)) || $overwrite ) {
|
||||
$this->$key = ( $empty ) ? array($k=>$v) : array_merge($this->$key, array($k=>$v)) ;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $overwrite || empty($this->$key) ) $this->$key = $value;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function parse_php_file ($file, $var='config', $overwrite=true) {
|
||||
if ( is_readable($file) ) {
|
||||
include($file);
|
||||
$this->parse_array($$var, $overwrite);
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
function parse_ini_file ($file, $overwrite=true) {
|
||||
if ( is_readable($file) ) {
|
||||
$this->parse_array(parse_ini_file($file, true), $overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -18,7 +18,7 @@ class dirlist {
|
||||
|
||||
// Sorting
|
||||
var $sort_items = true;
|
||||
var $sort_reverse = false;
|
||||
var $reverse = false;
|
||||
|
||||
// Smart date formatting
|
||||
var $smartdate = '{date}, {time}';
|
||||
@@ -73,7 +73,7 @@ class dirlist {
|
||||
}
|
||||
}
|
||||
if ( $this->sort_items ) {
|
||||
( $this->sort_reverse ) ? krsort($this->list) : ksort($this->list) ;
|
||||
( $this->reverse ) ? krsort($this->list) : ksort($this->list) ;
|
||||
}
|
||||
return true;
|
||||
}else{ $this->error = true; return false; }
|
||||
|
||||
@@ -122,6 +122,7 @@ class execHandler {
|
||||
} elseif( is_string($input) ) {
|
||||
$result = glob($input);
|
||||
}
|
||||
$result = array_filter($result);
|
||||
if ( is_array($result) ) $result = array_unique($result);
|
||||
$this->files_to_load = array_merge($this->files_to_load, $result);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ Author: Jim Myhrberg
|
||||
//==========================
|
||||
|
||||
|
||||
//>After> core.define_constants
|
||||
$config->parse(TPL_PATH.'settings.php');
|
||||
|
||||
|
||||
//_END;
|
||||
?>
|
||||
7
templates/simple/settings.php
Normal file
7
templates/simple/settings.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
$config = array(
|
||||
'template_name' => 'simple',
|
||||
);
|
||||
|
||||
?>
|
||||
31
view.php
31
view.php
@@ -12,32 +12,45 @@
|
||||
require_once('config.php');
|
||||
require_once('resources/init.php');
|
||||
require_once('libs/speedometer.lib.php');
|
||||
require_once('libs/config.lib.php');
|
||||
require_once('libs/dirlist.lib.php');
|
||||
require_once('libs/exechandler.lib.php');
|
||||
|
||||
$time = new speedometer();
|
||||
|
||||
// initialize config object
|
||||
$config = new config($config);
|
||||
|
||||
|
||||
// initialize debug stopwatch
|
||||
if ($config->debug) $debug_time = new speedometer();
|
||||
|
||||
|
||||
// initialize execHandler and main scripts
|
||||
$exec = new execHandler();
|
||||
$exec->cache_dir = 'cache/exec/';
|
||||
if ( $config['debug'] ) {
|
||||
$exec->debug = true;
|
||||
$exec->update_frequency = 0;
|
||||
}
|
||||
|
||||
// debug?
|
||||
if ( $config->debug ) $exec->debug = true;
|
||||
|
||||
// paths to load
|
||||
$exec->addPath(
|
||||
array(
|
||||
'exec/core.exc.php',
|
||||
'templates/'.$config['template'].'/render.exc.php',
|
||||
'exec/*',
|
||||
'templates/'.$config->template.'/render.exc.php',
|
||||
'plugins/*.exc.php',
|
||||
)
|
||||
);
|
||||
$exec->cache();
|
||||
include($exec->include_file);
|
||||
|
||||
print_r($exec->execution_order);
|
||||
|
||||
|
||||
$time->end();
|
||||
if ($config['debug']) echo "<br />\npage generated in ".$time->time." sec.<br />\n";
|
||||
if ($config->debug) {
|
||||
$debug_time->end();
|
||||
echo "<br />\npage generated in ".$debug_time->time." sec.<br />\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user