Permalink
Browse files

Whitespace cleanup

  • Loading branch information...
1 parent cf50808 commit d37ab0a3ff9783a5b96e0f8bfa72f9c07dfd8f83 @kolber committed Aug 5, 2010
@@ -1,11 +1,11 @@
<?php
Class AssetFactory {
-
- static $store;
- static $asset_subclasses = array();
+
+ static $store;
+ static $asset_subclasses = array();
- static function &create($file_path) {
+ static function &create($file_path) {
#
# a little bit of magic here to find any classes which extend 'Asset'
#
@@ -15,45 +15,45 @@ static function &create($file_path) {
$data = array();
if(!is_string($file_path)) return $data;
- # split by file extension
- preg_match('/\.([\w\d]+?)$/', $file_path, $split_path);
-
- if(isset($split_path[1]) && !is_dir($file_path)) {
- # set the default asset type
- $asset = 'Asset';
- # loop through our asset_subclasses to see if this filetype should be handled in a special way
- foreach(self::$asset_subclasses as $asset_type => $identifiers) {
- # if a match is found, set $asset to be the name of the matching class
- if(in_array(strtolower($split_path[1]), $identifiers)) $asset = $asset_type;
- }
-
- # create a new asset and return its data
- $asset = new $asset($file_path);
- return $asset->data;
+ # split by file extension
+ preg_match('/\.([\w\d]+?)$/', $file_path, $split_path);
+
+ if(isset($split_path[1]) && !is_dir($file_path)) {
+ # set the default asset type
+ $asset = 'Asset';
+ # loop through our asset_subclasses to see if this filetype should be handled in a special way
+ foreach(self::$asset_subclasses as $asset_type => $identifiers) {
+ # if a match is found, set $asset to be the name of the matching class
+ if(in_array(strtolower($split_path[1]), $identifiers)) $asset = $asset_type;
+ }
+
+ # create a new asset and return its data
+ $asset = new $asset($file_path);
+ return $asset->data;
- } else {
- # new page
- $page = new Page(Helpers::file_path_to_url($file_path));
- return $page->data;
- }
- }
+ } else {
+ # new page
+ $page = new Page(Helpers::file_path_to_url($file_path));
+ return $page->data;
+ }
+ }
- static function &get($key) {
- # if object doesn't exist, create it
- if(!isset(self::$store[$key])) self::$store[$key] =& self::create($key);
- return self::$store[$key];
- }
-
- static function get_asset_subclasses() {
- # if asset_subclasses hasn't been filled yet
- if(empty(self::$asset_subclasses)) {
- # loop through each declared class
- foreach(get_declared_classes() as $class) {
- # if the class extends 'Asset', then push it into our asset_subclasses hash
- if(strtolower(get_parent_class($class)) == 'asset') self::$asset_subclasses[$class] = eval('return '.$class.'::$identifiers;');
- }
- }
- }
+ static function &get($key) {
+ # if object doesn't exist, create it
+ if(!isset(self::$store[$key])) self::$store[$key] =& self::create($key);
+ return self::$store[$key];
+ }
+
+ static function get_asset_subclasses() {
+ # if asset_subclasses hasn't been filled yet
+ if(empty(self::$asset_subclasses)) {
+ # loop through each declared class
+ foreach(get_declared_classes() as $class) {
+ # if the class extends 'Asset', then push it into our asset_subclasses hash
+ if(strtolower(get_parent_class($class)) == 'asset') self::$asset_subclasses[$class] = eval('return '.$class.'::$identifiers;');
+ }
+ }
+ }
}
@@ -1,35 +1,35 @@
<?php
Class Asset {
-
- var $data;
- var $link_path;
- var $file_name;
- static $identifiers;
-
- function __construct($file_path) {
- # create and store data required for this asset
- $this->set_default_data($file_path);
- }
-
- function construct_link_path($file_path) {
- return preg_replace('/^\.\//', Helpers::relative_root_path(), $file_path);
- }
-
- function set_default_data($file_path) {
- # store link path
- $this->link_path = $this->construct_link_path($file_path);
-
- # extract filename from path
- $split_path = explode('/', $file_path);
- $this->file_name = array_pop($split_path);
-
- # set @url & @name variables
- $this->data['@url'] = $this->link_path;
- $this->data['@file_name'] = $this->file_name;
- $this->data['@name'] = ucfirst(preg_replace(array('/[-_]/', '/\.[\w\d]+?$/', '/^\d+?\./'), array(' ', '', ''), $this->file_name));
- }
-
+
+ var $data;
+ var $link_path;
+ var $file_name;
+ static $identifiers;
+
+ function __construct($file_path) {
+ # create and store data required for this asset
+ $this->set_default_data($file_path);
+ }
+
+ function construct_link_path($file_path) {
+ return preg_replace('/^\.\//', Helpers::relative_root_path(), $file_path);
+ }
+
+ function set_default_data($file_path) {
+ # store link path
+ $this->link_path = $this->construct_link_path($file_path);
+
+ # extract filename from path
+ $split_path = explode('/', $file_path);
+ $this->file_name = array_pop($split_path);
+
+ # set @url & @name variables
+ $this->data['@url'] = $this->link_path;
+ $this->data['@file_name'] = $this->file_name;
+ $this->data['@name'] = ucfirst(preg_replace(array('/[-_]/', '/\.[\w\d]+?$/', '/^\d+?\./'), array(' ', '', ''), $this->file_name));
+ }
+
}
?>
@@ -3,25 +3,25 @@
Class Html extends Asset {
static $identifiers = array('html', 'htm', 'php');
-
- function __construct($file_path) {
- # create and store data required for this asset
- parent::__construct($file_path);
- # create and store additional data required for this asset
- $this->set_extended_data($file_path);
- }
-
- function set_extended_data($file_path) {
- if(is_readable($file_path)) {
- ob_start();
- include $file_path;
- $this->data['@content'] = ob_get_contents();
- ob_end_clean();
- } else {
- $this->data['@content'] = '';
- }
- }
-
+
+ function __construct($file_path) {
+ # create and store data required for this asset
+ parent::__construct($file_path);
+ # create and store additional data required for this asset
+ $this->set_extended_data($file_path);
+ }
+
+ function set_extended_data($file_path) {
+ if(is_readable($file_path)) {
+ ob_start();
+ include $file_path;
+ $this->data['@content'] = ob_get_contents();
+ ob_end_clean();
+ } else {
+ $this->data['@content'] = '';
+ }
+ }
+
}
?>
@@ -3,37 +3,37 @@
Class Image extends Asset {
static $identifiers = array('jpg', 'jpeg', 'gif', 'png');
-
- function __construct($file_path) {
- # create and store data required for this asset
- parent::__construct($file_path);
- # create and store additional data required for this asset
- $this->set_extended_data($file_path);
- }
-
- function set_extended_data($file_path) {
- $small_version_path = preg_replace('/(\.[\w\d]+?)$/', '_sml$1', $this->link_path);
- $large_version_path = preg_replace('/(\.[\w\d]+?)$/', '_lge$1', $this->link_path);
-
- # if a matching _sml version exists, set @small
- $small_relative_path = preg_replace('/(\.\.\/)+/', './', $small_version_path);
- if(file_exists($small_relative_path) && !is_dir($small_relative_path)) {
- $this->data['@small'] = $small_version_path;
- }
-
- # if a matching _lge version exists, set @large
- $large_relative_path = preg_replace('/(\.\.\/)+/', './', $large_version_path);
- if(file_exists($large_relative_path) && !is_dir($large_relative_path)) {
- $this->data['@large'] = $large_version_path;
- }
-
- # set @width & @height variables
- $img_data = getimagesize($file_path, $info);
- preg_match_all('/\d+/', $img_data[3], $dimensions);
- $this->data['@width'] = $dimensions[0][0];
- $this->data['@height'] = $dimensions[0][1];
-
- # set iptc variables
+
+ function __construct($file_path) {
+ # create and store data required for this asset
+ parent::__construct($file_path);
+ # create and store additional data required for this asset
+ $this->set_extended_data($file_path);
+ }
+
+ function set_extended_data($file_path) {
+ $small_version_path = preg_replace('/(\.[\w\d]+?)$/', '_sml$1', $this->link_path);
+ $large_version_path = preg_replace('/(\.[\w\d]+?)$/', '_lge$1', $this->link_path);
+
+ # if a matching _sml version exists, set @small
+ $small_relative_path = preg_replace('/(\.\.\/)+/', './', $small_version_path);
+ if(file_exists($small_relative_path) && !is_dir($small_relative_path)) {
+ $this->data['@small'] = $small_version_path;
+ }
+
+ # if a matching _lge version exists, set @large
+ $large_relative_path = preg_replace('/(\.\.\/)+/', './', $large_version_path);
+ if(file_exists($large_relative_path) && !is_dir($large_relative_path)) {
+ $this->data['@large'] = $large_version_path;
+ }
+
+ # set @width & @height variables
+ $img_data = getimagesize($file_path, $info);
+ preg_match_all('/\d+/', $img_data[3], $dimensions);
+ $this->data['@width'] = $dimensions[0][0];
+ $this->data['@height'] = $dimensions[0][1];
+
+ # set iptc variables
if(isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
# @title
@@ -46,9 +46,9 @@ function set_extended_data($file_path) {
if(isset($iptc["2#025"][0]))
$this->data['@keywords'] = $iptc["2#025"][0];
}
-
- }
-
+
+ }
+
}
?>
@@ -2,54 +2,54 @@
Class Page {
- var $url_path;
- var $file_path;
- var $template_name;
- var $template_file;
- var $data;
- var $all_pages;
-
- function __construct($url) {
- # store url and converted file path
- $this->file_path = Helpers::url_to_file_path($url);
- $this->url_path = $url;
+ var $url_path;
+ var $file_path;
+ var $template_name;
+ var $template_file;
+ var $data;
+ var $all_pages;
+
+ function __construct($url) {
+ # store url and converted file path
+ $this->file_path = Helpers::url_to_file_path($url);
+ $this->url_path = $url;
$this->template_name = $this->template_name();
- $this->template_file = $this->template_file();
-
- # create/set all content variables
- PageData::create($this);
- # sort data array by key length
- #
- # this ensures that something like '@title' doesn't turn '@page_title'
- # into '@page_Contents of @title variable' in the final rendered template
- #
- uksort($this->data, array('Helpers', 'sort_by_length'));
+ $this->template_file = $this->template_file();
+
+ # create/set all content variables
+ PageData::create($this);
+ # sort data array by key length
+ #
+ # this ensures that something like '@title' doesn't turn '@page_title'
+ # into '@page_Contents of @title variable' in the final rendered template
+ #
+ uksort($this->data, array('Helpers', 'sort_by_length'));
- }
-
- function parse_template() {
- return TemplateParser::parse($this->data, file_get_contents($this->template_file));
- }
-
- # magic variable assignment
- function __set($name, $value) {
- $prefix = is_array($value) ? '$' : '@';
- $this->data[$prefix.strtolower($name)] = $value;
- }
-
- function template_name() {
- $txts = array_keys(Helpers::list_files($this->file_path, '/\.txt$/'));
- # return first matched .txt file
- return (!empty($txts)) ? preg_replace('/\.txt$/', '', $txts[0]) : false;
- }
-
- function template_file() {
+ }
+
+ function parse_template() {
+ return TemplateParser::parse($this->data, file_get_contents($this->template_file));
+ }
+
+ # magic variable assignment
+ function __set($name, $value) {
+ $prefix = is_array($value) ? '$' : '@';
+ $this->data[$prefix.strtolower($name)] = $value;
+ }
+
+ function template_name() {
+ $txts = array_keys(Helpers::list_files($this->file_path, '/\.txt$/'));
+ # return first matched .txt file
+ return (!empty($txts)) ? preg_replace('/\.txt$/', '', $txts[0]) : false;
+ }
+
+ function template_file() {
$template_file = glob('./templates/'.$this->template_name.'.*');
# return template if one exists
- return isset($template_file[0]) ? $template_file[0] : false;
- }
-
+ return isset($template_file[0]) ? $template_file[0] : false;
+ }
+
}
?>
Oops, something went wrong.

0 comments on commit d37ab0a

Please sign in to comment.