mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-18 23:46:39 +00:00
Initial import
git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@1 a5845835-ea0f-0410-a762-dd0bfe9bfde8
This commit is contained in:
1
cache/exec/.htaccess
vendored
Normal file
1
cache/exec/.htaccess
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Deny from all
|
||||||
26
config.php
Normal file
26
config.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$config = array(
|
||||||
|
|
||||||
|
// Main settings
|
||||||
|
|
||||||
|
'url' => '/dlist2/',
|
||||||
|
'index_files' => array('index', 'default', 'main'),
|
||||||
|
'debug' => false,
|
||||||
|
|
||||||
|
|
||||||
|
// Display settings
|
||||||
|
|
||||||
|
'template' => 'simple',
|
||||||
|
'iconset' => 'osx',
|
||||||
|
'allow_override' => true,
|
||||||
|
|
||||||
|
// Server settings
|
||||||
|
|
||||||
|
'default_scheme' => 'http',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
?>
|
||||||
55
exec/core.exc.php
Normal file
55
exec/core.exc.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php die();
|
||||||
|
|
||||||
|
//
|
||||||
|
// core
|
||||||
|
//
|
||||||
|
// Created by Jim Myhrberg on 21-Mar-2006.
|
||||||
|
// Copyright (c) zynode.info. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
//_HEAD;
|
||||||
|
/* --- Configuration ---
|
||||||
|
Name: core
|
||||||
|
Priority: 40
|
||||||
|
Author: Jim Myhrberg
|
||||||
|
*/
|
||||||
|
//_SCRIPT;
|
||||||
|
|
||||||
|
//==========================
|
||||||
|
//>STAGE> init
|
||||||
|
//==========================
|
||||||
|
|
||||||
|
//>Section> port_correction
|
||||||
|
if ( stristr($_SERVER['HTTP_HOST'], ':') !== false ) {
|
||||||
|
$http_host = explode(':', $_SERVER['HTTP_HOST'], 2);
|
||||||
|
$_SERVER['SERVER_PORT'] = $http_host[1];
|
||||||
|
unset($http_host);
|
||||||
|
}
|
||||||
|
preg_match("/(.*)Port [0-9]{2,8}(.*)/", $_SERVER['SERVER_SIGNATURE'], $serverinfo);
|
||||||
|
$_SERVER['SERVER_SIGNATURE'] = $serverinfo[1].'Port '.$_SERVER['SERVER_PORT'].$serverinfo[2];
|
||||||
|
|
||||||
|
//>Section> set_vars
|
||||||
|
$do_readdir = true;
|
||||||
|
$do_render = true;
|
||||||
|
|
||||||
|
//==========================
|
||||||
|
//>STAGE> main
|
||||||
|
//==========================d
|
||||||
|
|
||||||
|
//>Section> init_dList
|
||||||
|
if ( $do_readdir ) {
|
||||||
|
$dlist = new dirlist();
|
||||||
|
// $dlist->show_hidden = true;
|
||||||
|
$dlist->read($dir_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================
|
||||||
|
//>STAGE> render
|
||||||
|
//==========================
|
||||||
|
|
||||||
|
//>Section> echo
|
||||||
|
print_r($dlist->list);
|
||||||
|
|
||||||
|
|
||||||
|
//_END;
|
||||||
|
?>
|
||||||
191
libs/dirlist.lib.php
Normal file
191
libs/dirlist.lib.php
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class dirlist {
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
dirlist v2.0 beta
|
||||||
|
Copyright © 2006 Jim Myhrberg.
|
||||||
|
zynode@gmail.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// General settings
|
||||||
|
var $default_sort = 'name,mtime,size';
|
||||||
|
var $folders_first = true;
|
||||||
|
var $show_hidden = false;
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
var $sort_items = true;
|
||||||
|
var $sort_reverse = false;
|
||||||
|
|
||||||
|
// Smart date formatting
|
||||||
|
var $smartdate = '{date}, {time}';
|
||||||
|
var $smartdate_date = 'F d, Y';
|
||||||
|
var $smartdate_time = 'H:i';
|
||||||
|
|
||||||
|
|
||||||
|
// Internals
|
||||||
|
var $error = false;
|
||||||
|
var $this_dir;
|
||||||
|
var $list = array();
|
||||||
|
var $sort_by = array();
|
||||||
|
|
||||||
|
var $stats_count = 0;
|
||||||
|
var $stats_files = 0;
|
||||||
|
var $stats_folders = 0;
|
||||||
|
var $stats_totalsize = 0;
|
||||||
|
|
||||||
|
// Construtor
|
||||||
|
function dirlist() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
// ----- [ Main Functions ] ---------------------
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
function read ($dir) {
|
||||||
|
if(!preg_match("/\/$/", $dir)) $dir .= '/';
|
||||||
|
$this->sort_by = explode(',', $this->default_sort);
|
||||||
|
if($dh = @opendir($dir)) {
|
||||||
|
$this->this_dir = $this->getDetails($dir);
|
||||||
|
while(false !== ($item = readdir($dh))) {
|
||||||
|
$hidden_item = ( $this->show_hidden ) ? false : preg_match("/^\./", $item) ;
|
||||||
|
if( ($item != '.' && $item != '..') && !$hidden_item ) {
|
||||||
|
$item_details = $this->getDetails($dir.$item);
|
||||||
|
// stats
|
||||||
|
$this->stats_count++;
|
||||||
|
if ( $item_details['type'] == 'file' ) {
|
||||||
|
$this->stats_totalsize += $item_details['size_raw'];
|
||||||
|
$this->stats_files++;
|
||||||
|
} else {
|
||||||
|
$this->stats_folders++;
|
||||||
|
}
|
||||||
|
// sorting
|
||||||
|
$list_key = ( $this->folders_first ) ? $item_details['type'].'|' : '' ;
|
||||||
|
foreach( $this->sort_by as $v ) {
|
||||||
|
if ( $v == 'size' ) $v = 'size_raw';
|
||||||
|
$list_key .= ( $v == 'size_raw' || $v == 'mtime' ) ? str_pad($item_details[$v], 28, '0', STR_PAD_LEFT).'|' : $item_details[$v].'|' ;
|
||||||
|
}
|
||||||
|
$this->list[$list_key] = $this->getDetails($dir.$item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $this->sort_items ) {
|
||||||
|
( $this->sort_reverse ) ? krsort($this->list) : ksort($this->list) ;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}else{ $this->error = true; return false; }
|
||||||
|
closedir($dh);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDetails ($item) {
|
||||||
|
$item = str_replace("\\", '/', $item);
|
||||||
|
$return['name'] = ( preg_match("/^.*\/(.*)/", $item, $name) ) ? $name[1] : $item ;
|
||||||
|
|
||||||
|
// Owner and Group
|
||||||
|
if ( ($group = $this->getGroup($item)) != false ) $return = array_merge($return, $group);
|
||||||
|
if ( ($owner = $this->getOwner($item)) != false ) $return = array_merge($return, $owner);
|
||||||
|
|
||||||
|
// Last Modified
|
||||||
|
$return['mtime'] = filemtime($item);
|
||||||
|
$return['mtimef'] = $this->smartDate($return['mtime'], $this->smartdate_date, $this->smartdate_time, $this->smartdate);
|
||||||
|
|
||||||
|
// Permissions and CHMOD value
|
||||||
|
$return['perms'] = $this->format_perms(fileperms($item));
|
||||||
|
$return['chmod'] = substr(sprintf('%o', fileperms($item)), -4);
|
||||||
|
|
||||||
|
$return['type_raw'] = filetype($item);
|
||||||
|
|
||||||
|
if ( is_file($item) ) {
|
||||||
|
$return['type'] = 'file';
|
||||||
|
$return['ext'] = ( preg_match("/^.*\.(.*)/", $return['name'], $ext) ) ? $ext[1] : '' ;
|
||||||
|
$return['size_raw'] = filesize($item);
|
||||||
|
$return['size'] = $this->format_filesize($return['size_raw']);
|
||||||
|
} elseif ( is_dir($item) ) {
|
||||||
|
$return['type'] = 'dir';
|
||||||
|
$return['ext'] = '';
|
||||||
|
$return['size_raw'] = '';
|
||||||
|
$return['size'] = '-';
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
// ----- [ Internal Functions ] -----------------
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
function format_filesize($bytes) {
|
||||||
|
$types = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||||
|
for($n = 0; $bytes >= 1024; $n++) $bytes = $bytes / 1024;
|
||||||
|
$bytes = number_format($bytes, 2);
|
||||||
|
if ( !empty($bytes[1]) ) {
|
||||||
|
$bytes = explode('.', $bytes);
|
||||||
|
$bytes[1] = rtrim($bytes[1], '0');
|
||||||
|
$bytes = ( $bytes[1] != '' ) ? $bytes[0].'.'.$bytes[1] : $bytes[0] ;
|
||||||
|
}
|
||||||
|
return $bytes.' '.$types[$n];
|
||||||
|
}
|
||||||
|
|
||||||
|
function smartDate ($timestamp, $datef='jS M, Y', $timef='H:i', $mainf='{date}, {time}') {
|
||||||
|
$array = array('Today'=>0, 'Yesterday'=>-1, '2 days ago'=>-2, '3 days ago'=>-3, 'Tomorrow'=>1);
|
||||||
|
$now = time();
|
||||||
|
// check if timestamp is more than 96 hours ago
|
||||||
|
if ( $timestamp >= ($now - 345600) ) {
|
||||||
|
$check = date("d:m:Y", $timestamp);
|
||||||
|
foreach ( $array as $key => $value ) {
|
||||||
|
$test = date("d:m:Y", ($now + (86400 * $value) ) );
|
||||||
|
if( $check == $test ) {
|
||||||
|
$return = str_replace('{date}', $key, $mainf);
|
||||||
|
return str_replace('{time}', date($timef, $timestamp), $return);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$return = str_replace('{date}', date($datef, $timestamp), $mainf);
|
||||||
|
return str_replace('{time}', date($timef, $timestamp), $return);
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_perms($perms) {
|
||||||
|
if (($perms & 0xC000) == 0xC000) { $info = 's';
|
||||||
|
} elseif (($perms & 0xA000) == 0xA000) { $info = 'l';
|
||||||
|
} elseif (($perms & 0x8000) == 0x8000) { $info = '-';
|
||||||
|
} elseif (($perms & 0x6000) == 0x6000) { $info = 'b';
|
||||||
|
} elseif (($perms & 0x4000) == 0x4000) { $info = 'd';
|
||||||
|
} elseif (($perms & 0x2000) == 0x2000) { $info = 'c';
|
||||||
|
} elseif (($perms & 0x1000) == 0x1000) { $info = 'p';
|
||||||
|
} else { $info = 'u'; }
|
||||||
|
// Owner
|
||||||
|
$info .= (($perms & 0x0100) ? 'r' : '-');
|
||||||
|
$info .= (($perms & 0x0080) ? 'w' : '-');
|
||||||
|
$info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
|
||||||
|
// Group
|
||||||
|
$info .= (($perms & 0x0020) ? 'r' : '-');
|
||||||
|
$info .= (($perms & 0x0010) ? 'w' : '-');
|
||||||
|
$info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
|
||||||
|
// World
|
||||||
|
$info .= (($perms & 0x0004) ? 'r' : '-');
|
||||||
|
$info .= (($perms & 0x0002) ? 'w' : '-');
|
||||||
|
$info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOwner ($item) {
|
||||||
|
if ( function_exists('posix_getpwuid') ) {
|
||||||
|
$id = fileowner($item);
|
||||||
|
$name = posix_getpwuid($id);
|
||||||
|
return array('ownerid'=>$id, 'owner'=>$name['name']);
|
||||||
|
} else { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroup ($item) {
|
||||||
|
if ( function_exists('posix_getgrgid') ) {
|
||||||
|
$id = filegroup($item);
|
||||||
|
$name = posix_getgrgid($id);
|
||||||
|
return array('groupid'=>$id, 'group'=>$name['name']);
|
||||||
|
} else { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
457
libs/exechandler.lib.php
Normal file
457
libs/exechandler.lib.php
Normal file
@@ -0,0 +1,457 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class execHandler {
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
execHandler v0.7 beta
|
||||||
|
Copyright © 2006 Jim Myhrberg.
|
||||||
|
zynode@gmail.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
// ----- [ Configuration ] ----------------------
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
|
||||||
|
// Caching
|
||||||
|
|
||||||
|
var $cache_dir = 'cache';
|
||||||
|
var $cache_name = 'default';
|
||||||
|
var $cache_data = '.data.cache.php';
|
||||||
|
var $cache_details = '.details.cache.php';
|
||||||
|
var $cache_time = '.time.cache.php';
|
||||||
|
var $update_frequency = 0;
|
||||||
|
var $php_opentag = "<?php\n";
|
||||||
|
var $php_closetag = "\n?>";
|
||||||
|
|
||||||
|
|
||||||
|
// Execution Stage Priority
|
||||||
|
|
||||||
|
var $default_stages = array(
|
||||||
|
'init' => 10,
|
||||||
|
'main' => 50,
|
||||||
|
'render' => 80,
|
||||||
|
'term' => 90,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Debug?
|
||||||
|
|
||||||
|
var $debug = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Misc. Settings
|
||||||
|
|
||||||
|
var $default_priority = 40;
|
||||||
|
var $php_extension = 'php';
|
||||||
|
var $exec_extension = 'exc';
|
||||||
|
var $default_stage_code = 'main';
|
||||||
|
var $escape_chars = '/\[]{}().^$*';
|
||||||
|
|
||||||
|
|
||||||
|
// Syntax Configuration
|
||||||
|
|
||||||
|
var $file_start = '//_HEAD;';
|
||||||
|
var $code_delim = '//_SCRIPT;';
|
||||||
|
var $file_end = '//_END;';
|
||||||
|
|
||||||
|
var $delim = '//>';
|
||||||
|
var $stage_delim = 'STAGE>';
|
||||||
|
var $section_delim = 'Section>';
|
||||||
|
var $insert_before = 'Before>';
|
||||||
|
var $insert_after = 'After>';
|
||||||
|
var $replace_delim = 'Replace>';
|
||||||
|
|
||||||
|
var $priority_delim = ':';
|
||||||
|
var $config_comment_chars = '#|;|//';
|
||||||
|
var $include_seperator = ',';
|
||||||
|
|
||||||
|
|
||||||
|
// Error Messages
|
||||||
|
|
||||||
|
var $error_cache_dir = 'ERROR: ExecHandler could not write to cache directory.';
|
||||||
|
var $error_read_cache_files = 'ERROR: ExecHandler count not read the specified cache files.';
|
||||||
|
var $error_cache_update = 'ERROR: ExecHandler cound not update cache file.';
|
||||||
|
|
||||||
|
|
||||||
|
// Data Storage Setup
|
||||||
|
|
||||||
|
var $code = array();
|
||||||
|
var $execution_order = array();
|
||||||
|
var $files = array();
|
||||||
|
var $order_id = array();
|
||||||
|
var $files_to_load = array();
|
||||||
|
var $compiled_code = false;
|
||||||
|
var $include_file = false;
|
||||||
|
var $stages = array();
|
||||||
|
|
||||||
|
|
||||||
|
// Construct Function
|
||||||
|
|
||||||
|
function execHandler($cache_name=false) {
|
||||||
|
if ( !empty($cache_name) ) $this->cache_name = $cache_name;
|
||||||
|
$this->stages = $this->default_stages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
// ----- [ Public Functions ] -------------------
|
||||||
|
// ==============================================
|
||||||
|
/*
|
||||||
|
These functions are intended for use within your
|
||||||
|
script. The other functions are internal and only
|
||||||
|
used by execHandler itself.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function cache ($force=false) {
|
||||||
|
if ( !($cache_ok = $this->check_cache()) ) {
|
||||||
|
echo "reloading\n";
|
||||||
|
$this->loadFile($this->files_to_load);
|
||||||
|
$this->compile();
|
||||||
|
$this->save_cache();
|
||||||
|
}
|
||||||
|
print_r($cache_ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPath ($input) {
|
||||||
|
$result = array();
|
||||||
|
if ( is_array($input) ) {
|
||||||
|
foreach( $input as $key => $value ) $result = array_merge($result, glob($value));
|
||||||
|
} elseif( is_string($input) ) {
|
||||||
|
$result = glob($input);
|
||||||
|
}
|
||||||
|
if ( is_array($result) ) $result = array_unique($result);
|
||||||
|
$this->files_to_load = array_merge($this->files_to_load, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadFile ($input) {
|
||||||
|
if ( is_array($input) ) {
|
||||||
|
foreach( $input as $file ) {
|
||||||
|
$result = $this->load_file($file);
|
||||||
|
if ( $result == false ) return false;
|
||||||
|
}
|
||||||
|
} elseif ( is_string($input) ) {
|
||||||
|
return $this->load_file($input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function compile () {
|
||||||
|
$this->compiled_code = '';
|
||||||
|
$this->sort_stage_list();
|
||||||
|
foreach( $this->stages as $stage => $stage_priority ) {
|
||||||
|
if( $this->debug ) $this->compiled_code .= "\n\n//==========================\n// Stage: ".$stage."\n//==========================\n";
|
||||||
|
foreach( $this->execution_order[$stage] as $key => $code ) {
|
||||||
|
if( $this->debug ) {
|
||||||
|
$this->compiled_code .= "\n// Code Piece: ".$code."\n";
|
||||||
|
$this->compiled_code .= $this->clean_up_code($this->code[$stage][$code]);
|
||||||
|
} else {
|
||||||
|
$this->compiled_code .= $this->code[$stage][$code];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
// ----- [ Core Functions ] ---------------------
|
||||||
|
// ==============================================
|
||||||
|
/*
|
||||||
|
The engine that drives this thing, without these
|
||||||
|
functions execHandler would not work. It wouldn't
|
||||||
|
work without any of the other funtions either,
|
||||||
|
but you get the point :P
|
||||||
|
*/
|
||||||
|
|
||||||
|
function load_file ($file, $included=false) {
|
||||||
|
if ( !isset($this->files[$file]) ) {
|
||||||
|
$content = $this->rfile($file);
|
||||||
|
if ( $content != false ) {
|
||||||
|
$content = $this->parse($content, $file);
|
||||||
|
$content['md5'] = md5_file($file);
|
||||||
|
$content['file'] = $file;
|
||||||
|
if ( $included ) $content['included'] = true;
|
||||||
|
$this->files[$file] = $content;
|
||||||
|
return true;
|
||||||
|
}else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sort_stage_list () {
|
||||||
|
$stages = array_flip($this->stages);
|
||||||
|
ksort($stages, SORT_NUMERIC);
|
||||||
|
$this->stages = array_flip($stages);
|
||||||
|
foreach( $this->execution_order as $key => $value ) {
|
||||||
|
if ( is_array($this->execution_order[$key]) ) ksort($this->execution_order[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse ($string, $file) {
|
||||||
|
// Filter Out Main Content
|
||||||
|
$file_start = $this->addslashes($this->file_start);
|
||||||
|
$code_delim = $this->addslashes($this->code_delim);
|
||||||
|
$file_end = $this->addslashes($this->file_end);
|
||||||
|
preg_match("/^".$file_start."$(.*)^".$code_delim."$(.*)^".$file_end."$/ims", $string, $code);
|
||||||
|
|
||||||
|
// Read Settings
|
||||||
|
$settings = $this->read_file_settings($code[1], $file);
|
||||||
|
|
||||||
|
// Parse Main Code
|
||||||
|
$code = explode($this->delim.$this->stage_delim, $code[2]);
|
||||||
|
array_shift($code);
|
||||||
|
|
||||||
|
// Stage Loop
|
||||||
|
$n = '001';
|
||||||
|
foreach ( $code as $value ) {
|
||||||
|
preg_match("/^(.*?)$(?s)(.*)/im", $value, $stage_code);
|
||||||
|
if ( preg_match("/(.*)".$this->priority_delim."([0-9]{1,2})/i", trim($stage_code[1]), $stage) ) {
|
||||||
|
$stage_priority = $stage[2];
|
||||||
|
$stage = $stage[1];
|
||||||
|
} else {
|
||||||
|
$stage = trim($stage_code[1]);
|
||||||
|
}
|
||||||
|
$stage_code = explode($this->delim, trim($stage_code[2]));
|
||||||
|
|
||||||
|
// handle code at root of stage (not within a section)
|
||||||
|
if ( empty($this->stages[$stage]) || (!empty($stage_priority) && $this->stages[$stage] != $stage_priority) ) {
|
||||||
|
$this->stages[$stage] = ( !empty($stage_priority) ) ? $stage_priority : $this->default_priority ;
|
||||||
|
}
|
||||||
|
$stage_code[0] = $this->clean_up_code($stage_code[0]);
|
||||||
|
if ( !empty($stage_code[0]) ) {
|
||||||
|
$this->code[$stage][$settings['name'].'.'.$this->default_stage_code] = "\n".$stage_code[0];
|
||||||
|
$this->execution_order[$stage][$this->default_priority.'|'.$settings['name'].':'.$n.':'.$this->default_stage_code.'__main']
|
||||||
|
= $settings['name'].'.'.$this->default_stage_code;
|
||||||
|
$this->order_id[$stage][$settings['name'].'.'.$this->default_stage_code]
|
||||||
|
= $this->default_priority.'|'.$settings['name'].':'.$n.':'.'.'.$this->default_stage_code.'__main';
|
||||||
|
$n = str_pad($n+1, 3, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
array_shift($stage_code);
|
||||||
|
|
||||||
|
// Section Loop
|
||||||
|
foreach( $stage_code as $value ) {
|
||||||
|
preg_match("/^(.*?)$(?s)(.*)/im", $value, $section_code);
|
||||||
|
if ( preg_match("/^(.*?)\s+(.*)/", trim($section_code[1]), $handler) ) {
|
||||||
|
$section = $handler[2];
|
||||||
|
$handler = $handler[1];
|
||||||
|
} else {
|
||||||
|
$section = trim($section_code[1]);
|
||||||
|
$handler = '';
|
||||||
|
}
|
||||||
|
if ( preg_match("/(.*)".$this->priority_delim."(.*)/", $section, $priority) ) {
|
||||||
|
$section = $priority[1];
|
||||||
|
$priority = $priority[2];
|
||||||
|
} else { $priority = $this->default_priority; }
|
||||||
|
|
||||||
|
$section_code = $this->clean_up_code($section_code[2]);
|
||||||
|
|
||||||
|
if ( !empty($section_code) ) {
|
||||||
|
|
||||||
|
// replace
|
||||||
|
if ( $handler == $this->replace_delim ) {
|
||||||
|
$this->code[$stage][$section] = "\n".$section_code;
|
||||||
|
}
|
||||||
|
// insert before & after
|
||||||
|
elseif ( $handler == $this->insert_before || $handler == $this->insert_after ) {
|
||||||
|
$placement = ( $handler == $this->insert_before ) ? '___before' : '_zafter' ;
|
||||||
|
$this->code[$stage][$settings['name'].'.'.$section] = "\n".$section_code;
|
||||||
|
$this->execution_order[$stage][$this->order_id[$stage][$section].$placement.'|'.$priority.'|'.$settings['name'].':'.$n]
|
||||||
|
= $settings['name'].'.'.$section;
|
||||||
|
}
|
||||||
|
// section
|
||||||
|
elseif ( $handler == $this->section_delim || $handler == '' ) {
|
||||||
|
$this->code[$stage][$settings['name'].'.'.$section] = "\n".$section_code;
|
||||||
|
$this->execution_order[$stage][$priority.'|'.$settings['name'].':'.$n.':'.$section.'__main']
|
||||||
|
= $settings['name'].'.'.$section;
|
||||||
|
$this->order_id[$stage][$settings['name'].'.'.$section] = $priority.'|'.$settings['name'].':'.$n.':'.$section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$n = str_pad($n+1, 3, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
// END: Section Loop
|
||||||
|
|
||||||
|
}
|
||||||
|
// END: Stage Loop
|
||||||
|
|
||||||
|
// include files
|
||||||
|
if ( !empty($settings['include']) ) $this->include_files($settings['include'], dirname($file));
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Cache Functions
|
||||||
|
|
||||||
|
function check_cache () {
|
||||||
|
if(!preg_match("/\/$/", $this->cache_dir)) $this->cache_dir .= '/';
|
||||||
|
|
||||||
|
$time_file = $this->cache_dir.$this->cache_name.$this->cache_time;
|
||||||
|
$details_file = $this->cache_dir.$this->cache_name.$this->cache_details;
|
||||||
|
$data_file = $this->cache_dir.$this->cache_name.$this->cache_data;
|
||||||
|
|
||||||
|
if ( is_readable($time_file) && is_readable($details_file) && is_readable($data_file) ) {
|
||||||
|
$time = $this->rfile($time_file);
|
||||||
|
if ( time() > ($time + ($this->update_frequency * 60)) ) {
|
||||||
|
$read_details = file($details_file);
|
||||||
|
foreach( $read_details as $key => $value ) {
|
||||||
|
$value = explode('=', trim($value));
|
||||||
|
$details[$value[0]] = $value[1];
|
||||||
|
if ( !isset($value[2]) ) $file_list[] = $value[0];
|
||||||
|
}
|
||||||
|
if ( $this->array_compare($this->files_to_load, $file_list) ) {
|
||||||
|
if ( !$this->validate_files($details) ) return false;
|
||||||
|
} else return false;
|
||||||
|
if ( !$this->write2file($time_file, time()) ) {
|
||||||
|
die($this->error_cache_update.' ('.$details_file.')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else return false;
|
||||||
|
|
||||||
|
$this->include_file = $data_file;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_cache ($force_compile=false) {
|
||||||
|
if(!preg_match("/\/$/", $this->cache_dir)) $this->cache_dir .= '/';
|
||||||
|
if ( is_writeable($this->cache_dir) ) {
|
||||||
|
$cache_details = '';
|
||||||
|
foreach( $this->files as $key => $value ) {
|
||||||
|
$cache_details .= $value['file'].'='.$value['md5'];
|
||||||
|
if ( isset($value['included']) ) $cache_details .= '=included';
|
||||||
|
$cache_details .= "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($this->compiled_code) || $force_compile ) $this->compile();
|
||||||
|
|
||||||
|
$time_write = $this->write2file($this->cache_dir.$this->cache_name.$this->cache_time, time());
|
||||||
|
$details_write = $this->write2file($this->cache_dir.$this->cache_name.$this->cache_details, $cache_details);
|
||||||
|
$data_write
|
||||||
|
= $this->write2file($this->cache_dir.$this->cache_name.$this->cache_data, $this->php_opentag.$this->compiled_code.$this->php_closetag);
|
||||||
|
if ( $time_write && $details_write && $data_write ) {
|
||||||
|
$this->include_file = $this->cache_dir.$this->cache_name.$this->cache_data;
|
||||||
|
return(true);
|
||||||
|
} else die($this->error_cache_dir);
|
||||||
|
} else die($this->error_cache_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
// ----- [ Internal Functions ] -----------------
|
||||||
|
// ==============================================
|
||||||
|
/*
|
||||||
|
I do believe its pretty obvious what these
|
||||||
|
functions do. At least what they are for, their
|
||||||
|
exact role within execHandler can seem weird
|
||||||
|
or useless by soley looking at the functions :P
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Filesystem
|
||||||
|
|
||||||
|
function rfile ($file){
|
||||||
|
if (!isset($file)) return false;
|
||||||
|
if (is_file($file)) {
|
||||||
|
if (!($fh = fopen($file,'r'))) return false;
|
||||||
|
$file_data = fread($fh, filesize($file));
|
||||||
|
fclose($fh);
|
||||||
|
} else { return false; }
|
||||||
|
return $file_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function write2file($file, $string, $mode="wb", $lock=2){
|
||||||
|
if ( !isset($file) ) return false;
|
||||||
|
$fp = fopen($file, $mode);
|
||||||
|
if ($fp != false) {
|
||||||
|
flock($fp,$lock);
|
||||||
|
$re = fwrite($fp,$string);
|
||||||
|
$re2 = fclose($fp);
|
||||||
|
if ($re != false && $re2 != false) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Parsing
|
||||||
|
|
||||||
|
function addslashes ($string) {
|
||||||
|
return addcslashes($string, $this->escape_chars);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_script_name ($file) {
|
||||||
|
$filename = explode('.', basename($file));
|
||||||
|
while ( $filename[count($filename)-1] == $this->php_extension || $filename[count($filename)-1] == $this->exec_extension ) {
|
||||||
|
array_pop($filename);
|
||||||
|
}
|
||||||
|
return implode('.', $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
function read_file_settings ($input, $file) {
|
||||||
|
preg_match_all("/^(.*?):(.*)$/Um", $input, $array);
|
||||||
|
while( list($k,$v) = each($array[1]) ) {
|
||||||
|
if(!preg_match("/^(".$this->addslashes($this->config_comment_chars).")/", $v)) $return[strtolower($v)] = trim($array[2][$k]);
|
||||||
|
}
|
||||||
|
if ( empty($return['name']) ) $return['name'] = $this->get_script_name($file);
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function include_files ($input, $dirname='.') {
|
||||||
|
$include_files = explode($this->include_seperator, $input);
|
||||||
|
foreach( $include_files as $key => $value ) {
|
||||||
|
if ( $dirname == '.' && is_readable($value) ) {
|
||||||
|
$this->load_file($value, true);
|
||||||
|
} elseif ( is_readable($dirname.'/'.$value) ) {
|
||||||
|
$this->load_file($dirname.'/'.$value, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Compiling
|
||||||
|
|
||||||
|
function clean_up_code ($string, $comments=true, $emptylines=true) {
|
||||||
|
if ( $comments ) $string = $this->remove_comments($string);
|
||||||
|
if ( $emptylines ) $string = $this->remove_empty_lines($string);
|
||||||
|
return trim($string);
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_comments ($string) {
|
||||||
|
$string = preg_replace("/\/\*.*?\*\//ms", '', $string);
|
||||||
|
$string = preg_replace("/^(\/\/|#).*$/m", '', $string);
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_empty_lines ($string) {
|
||||||
|
$string = str_replace("\r", "\n", $string);
|
||||||
|
$string = preg_replace("/\n+/m", "\n", $string);
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
|
||||||
|
function validate_files ($input) {
|
||||||
|
if ( is_array($input) ) {
|
||||||
|
foreach( $input as $key => $value ) {
|
||||||
|
if ( $value != md5_file($key) ) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function array_compare ($array1, $array2, $mode='value') {
|
||||||
|
if ( $mode == 'value' ) {
|
||||||
|
$array1 = array_values($array1);
|
||||||
|
$array2 = array_values($array2);
|
||||||
|
} elseif ( $mode == 'key' ) {
|
||||||
|
$array1 = array_flip($array1);
|
||||||
|
$array2 = array_flip($array2);
|
||||||
|
}
|
||||||
|
sort($array1);
|
||||||
|
sort($array2);
|
||||||
|
if ( implode('', $array1) != implode('', $array2) ) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
27
libs/speedometer.lib.php
Normal file
27
libs/speedometer.lib.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class speedometer {
|
||||||
|
|
||||||
|
var $digits = 6;
|
||||||
|
|
||||||
|
var $start;
|
||||||
|
var $time;
|
||||||
|
|
||||||
|
function speedometer ($digits=false) {
|
||||||
|
if ( !empty($digits) ) $this->digits = $digits;
|
||||||
|
$this->start = $this->getmicrotime();
|
||||||
|
}
|
||||||
|
|
||||||
|
function end () {
|
||||||
|
$end = $this->getmicrotime();
|
||||||
|
return $this->time = number_format( ($end - $this->start), $this->digits);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getmicrotime () {
|
||||||
|
list($usec, $sec) = explode(' ', microtime());
|
||||||
|
$r = floatval($usec) + floatval($sec);
|
||||||
|
return($r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
39
resources/init.php
Normal file
39
resources/init.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
// process requested path
|
||||||
|
if ( stristr($_SERVER['REQUEST_URI'], '?') !== false ) {
|
||||||
|
$dir_url = explode('?', $_SERVER['REQUEST_URI']);
|
||||||
|
$query_string = $dir_url[1];
|
||||||
|
$dir_url = urldecode($dir_url[0]);
|
||||||
|
} else {
|
||||||
|
$query_string = '';
|
||||||
|
$dir_url = urldecode($_SERVER['REQUEST_URI']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// path lookup
|
||||||
|
$dir_path = apache_lookup_uri($dir_url);
|
||||||
|
$dir_path = ( is_array($dir_path) ) ? $dir_path['filename'] : $dir_path->filename ;
|
||||||
|
if(!preg_match("/\/$/", $dir_path)) $dir_path .= '/';
|
||||||
|
if(!preg_match("/\/$/", $dir_url)) $redirect = '/';
|
||||||
|
|
||||||
|
|
||||||
|
// check for index files and redirect if found
|
||||||
|
if ( empty($redirect) ) {
|
||||||
|
foreach($config['index_files'] as $what) {
|
||||||
|
$indexsearch = glob($dir_path.$what.'.*');
|
||||||
|
if(isset($indexsearch[0])) { $redirect = basename($indexsearch[0]); break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !empty($redirect) ) {
|
||||||
|
if(!empty($_SERVER['SCRIPT_URI'])) {
|
||||||
|
$scheme = parse_url($_SERVER['SCRIPT_URI']);
|
||||||
|
$scheme = $scheme['scheme'];
|
||||||
|
} else $scheme = $config['default_scheme'];
|
||||||
|
if($query_string != '') $query_string = '?'.$query_string;
|
||||||
|
header("Location: ".$scheme.'://'.$_SERVER['HTTP_HOST'].$dir_url.$redirect.$query_string);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
24
templates/simple/render.exc.php
Normal file
24
templates/simple/render.exc.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php die();
|
||||||
|
|
||||||
|
//
|
||||||
|
// render
|
||||||
|
//
|
||||||
|
// Created by Jim Myhrberg on 21-Mar-2006.
|
||||||
|
// Copyright (c) zynode.info. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
//_HEAD;
|
||||||
|
/* --- Configuration ---
|
||||||
|
Name: render
|
||||||
|
Priority: 40
|
||||||
|
Author: Jim Myhrberg
|
||||||
|
*/
|
||||||
|
//_SCRIPT;
|
||||||
|
|
||||||
|
//==========================
|
||||||
|
//>STAGE> init
|
||||||
|
//==========================
|
||||||
|
echo "hello";
|
||||||
|
|
||||||
|
//_END;
|
||||||
|
?>
|
||||||
33
view.php
Normal file
33
view.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once('config.php');
|
||||||
|
require_once('resources/init.php');
|
||||||
|
require_once('libs/speedometer.lib.php');
|
||||||
|
require_once('libs/dirlist.lib.php');
|
||||||
|
require_once('libs/exechandler.lib.php');
|
||||||
|
|
||||||
|
$time = new speedometer();
|
||||||
|
|
||||||
|
|
||||||
|
$exec = new execHandler();
|
||||||
|
$exec->cache_dir = 'cache/exec/';
|
||||||
|
if ( $config['debug'] ) {
|
||||||
|
$exec->debug = true;
|
||||||
|
$exec->update_frequency = 0;
|
||||||
|
}
|
||||||
|
$exec->addPath(
|
||||||
|
array(
|
||||||
|
'exec/core.exc.php',
|
||||||
|
'templates/'.$config['template'].'/render.exc.php',
|
||||||
|
'plugins/*.exc.php',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$exec->cache();
|
||||||
|
include($exec->include_file);
|
||||||
|
|
||||||
|
|
||||||
|
$time->end();
|
||||||
|
if ($config['debug']) echo "<br />\npage generated in ".$time->time." sec.<br />\n";
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user