From 5238e3f80d1f1d6d2dc723c1949066fec7d44c05 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Sat, 18 Oct 2008 13:44:02 +0000 Subject: [PATCH] Moved to Display git-svn-id: http://svn.cleancode.org/svn/pickles@80 4d10bc64-7434-11dc-a737-d2d0f8310089 --- classes/Viewer/Common.php | 108 ---------------------------- classes/Viewer/JSON.php | 51 ------------- classes/Viewer/PHP.php | 100 -------------------------- classes/Viewer/RSS.php | 100 -------------------------- classes/Viewer/Smarty.php | 146 -------------------------------------- 5 files changed, 505 deletions(-) delete mode 100644 classes/Viewer/Common.php delete mode 100644 classes/Viewer/JSON.php delete mode 100644 classes/Viewer/PHP.php delete mode 100644 classes/Viewer/RSS.php delete mode 100644 classes/Viewer/Smarty.php diff --git a/classes/Viewer/Common.php b/classes/Viewer/Common.php deleted file mode 100644 index 960a67b..0000000 --- a/classes/Viewer/Common.php +++ /dev/null @@ -1,108 +0,0 @@ -. - * - * @author Joshua John Sherman - * @copyright Copyright 2007, 2008 Joshua John Sherman - * @link http://phpwithpickles.org - * @license http://www.gnu.org/copyleft/lesser.html - * @package PICKLES - */ - -/** - * Common Viewer Class - * - * This is the class that each viewer class should be extending from. - */ -abstract class Viewer_Common extends Object { - - /** - * Constructor - * - * Runs the parent's constructor and adds the model to the object. - * - * @param object $model Object for the model we're loading - */ - public function __construct(Config $config, Error $error) { - parent::__construct(); - - $this->config = $config; - $this->error = $error; - - /** - * @todo This may need to be flipped on only for Smarty and PHP templates - */ - // Obliterates any passed in PHPSESSID (thanks Google) - if (stripos($_SERVER['REQUEST_URI'], '?PHPSESSID=') !== false) { - list($request_uri, $phpsessid) = split('\?PHPSESSID=', $_SERVER['REQUEST_URI'], 2); - header('HTTP/1.1 301 Moved Permanently'); - header('Location: ' . $request_uri); - exit(); - } - - // XHTML compliancy stuff - ini_set('arg_separator.output', '&'); - ini_set('url_rewriter.tags', 'a=href,area=href,frame=src,input=src,fieldset='); - - header('Content-type: text/html; charset=UTF-8'); - - if ($this->config->getDebug() === true) { - $superglobals = array($GLOBALS, $_SERVER, $_GET, $_POST, $_FILES, $_COOKIE, $_SESSION, $_REQUEST, $_ENV); - ?> -
-

PICKLES Debug Console

- $array) { - ?> -

- -

$_REQUEST

-
-

$_SESSION

-
-

$_SERVER

-
-
- diff --git a/classes/Viewer/JSON.php b/classes/Viewer/JSON.php deleted file mode 100644 index eb5e3dd..0000000 --- a/classes/Viewer/JSON.php +++ /dev/null @@ -1,51 +0,0 @@ -. - * - * @author Joshua John Sherman - * @copyright Copyright 2007, 2008 Joshua John Sherman - * @link http://phpwithpickles.org - * @license http://www.gnu.org/copyleft/lesser.html - * @package PICKLES - */ - -/** - * JSON Viewer - * - * Displays data in JavaScript Object Notation. Requires PHP 5 >= 5.2.0 or - * PECL json 1.2.0 or 1.2.1 - * - * @link http://json.org/ - * @link http://us.php.net/json_encode - * @link http://pecl.php.net/package/json - */ -class Viewer_JSON extends Viewer_Common { - - /** - * Displays the data in JSON format - */ - public function display() { - if (!function_exists('json_encode')) { - echo '{ "type" : "error", "message" : "json_encode() not found" }'; - } else { - echo json_encode($this->data); - } - } -} - -?> diff --git a/classes/Viewer/PHP.php b/classes/Viewer/PHP.php deleted file mode 100644 index 2f461c9..0000000 --- a/classes/Viewer/PHP.php +++ /dev/null @@ -1,100 +0,0 @@ -. - * - * @author Joshua John Sherman - * @copyright Copyright 2007, 2008 Joshua John Sherman - * @link http://phpwithpickles.org - * @license http://www.gnu.org/copyleft/lesser.html - * @package PICKLES - */ - -/** - * PHP Viewer - * - * Displays the associated PHP templates for the Model. This is - * very similar to the Smarty viewer, but less overhead since it's - * straight PHP. The PHP viewer also utilizes a different caching - * system than Smarty. The general rules around the caching will - * be the same though. - */ -class Viewer_PHP extends Viewer_Common { - - private $template = null; - private $shared_template = null; - - /** - * Displays the PHP templated pages - */ - public function display() { - - // Establishes the template names - $this->template = SITE_PATH . '../templates/' . $this->model_name . '.php'; - $this->shared_template = PICKLES_PATH . 'templates/' . $this->shared_name . '.php'; - - //if (filemtime($this->template)) { - // readfile('/var/www/josh/pickles/var/joshtronic.localhost/smarty/cache/home.html'); - //} - - /** - * @todo There's a bug with the store home page since it's a redirect, maybe - */ - if (!file_exists($this->template)) { - if (file_exists($this->shared_template)) { - $this->template = $this->shared_template; - } - } - - // Brings these variables to scope - /** - * @todo Section or model needs to go, having both seems dumb. - */ - $section = $this->section; - $model = $this->model_name; - $template = $this->template; - - // Loads the data from the config - $config = $this->config->getPublicData(); - - // Loads the data from the model - $data = $this->data; - - // If there's data set, this brings it into scope - if (isset($this->data) && is_array($this->data)) { - extract($this->data); - } - - // If the index.php file is present, load it, else load the template directly - /** - * @todo Should there be additional logic to allow the model or the - * template to determine whether or not the index should be loaded? - */ - if (file_exists(SITE_PATH . '../templates/index.php')) { - require_once SITE_PATH . '../templates/index.php'; - } - else if (file_exists($this->template)) { - require_once $this->template; - } - - /** - * @todo Resurrect my buffer clean up code - */ - } -} - -?> diff --git a/classes/Viewer/RSS.php b/classes/Viewer/RSS.php deleted file mode 100644 index fc67983..0000000 --- a/classes/Viewer/RSS.php +++ /dev/null @@ -1,100 +0,0 @@ -. - * - * @author Joshua John Sherman - * @copyright Copyright 2007, 2008 Joshua John Sherman - * @link http://phpwithpickles.org - * @license http://www.gnu.org/copyleft/lesser.html - * @package PICKLES - */ - -/** - * RSS Viewer - * - * Displays data in RSS version 2.0 format. - * - * @link http://cyber.law.harvard.edu/rss/rss.html - * @todo Need to add support for RSS v1.0 as well as ATOM feeds. This may - * result in my abstracting out these classes a bit more (Probably a - * Feed viewer that would take a parameter to determine which type of - * of feed to use). - */ -class Viewer_RSS extends Viewer_Common { - - /** - * Displays the RSS feed data - * - * Uses a combination of configuration options and a properly formatted data - * array to create an RSS v2.0 feed. - * - * @todo Error handling is non-existant. - */ - public function display() { - if (isset($this->data->channel)) { - $channel = $this->data['channel']; - $channel = $this->config->rss->$channel; - - if (isset($this->data->items)) { - $items = $this->data['items']; - } - else { - $this->error->addError('No items were provided'); - } - } - else { - $this->error->addError('No channel was specified'); - } - - header('Content-type: application/rss+xml; charset=UTF-8'); - echo ''; - ?> - - - <?=$channel['title'];?> - http:// - - - - $item) { - $date = date('r', strtotime($item['date'])); - - if ($key == 0) { - echo "{$date}"; - } - ?> - - <?=$item['title'];?> - - ]]> - - - - - - - - diff --git a/classes/Viewer/Smarty.php b/classes/Viewer/Smarty.php deleted file mode 100644 index ee8b91e..0000000 --- a/classes/Viewer/Smarty.php +++ /dev/null @@ -1,146 +0,0 @@ -. - * - * @author Joshua John Sherman - * @copyright Copyright 2007, 2008 Joshua John Sherman - * @link http://phpwithpickles.org - * @license http://www.gnu.org/copyleft/lesser.html - * @package PICKLES - */ - -/** - * Smarty Viewer - * - * Displays the associated Smarty templates for the Model. - * - * @link http://smarty.net/ - */ -class Viewer_Smarty extends Viewer_Common { - - /** - * Displays the Smarty generated pages - */ - public function display() { - - $smarty = new Smarty(); - - // Establishes our paths - $smarty->template_dir = SITE_PATH . '../templates/'; - - $cache_dir = SMARTY_PATH . 'cache'; - $compile_dir = SMARTY_PATH . 'compile'; - - if (!file_exists($cache_dir)) { mkdir($cache_dir, 0777, true); } - if (!file_exists($compile_dir)) { mkdir($compile_dir, 0777, true); } - - $smarty->cache_dir = $cache_dir ; - $smarty->compile_dir = $compile_dir; - - /** - * @todo move this to the config - */ - // Enables caching - $smarty->caching = 1; - $smarty->compile_check = true; - $smarty->cache_lifetime = 3600; - - var_dump($smarty->is_cached('index.tpl', $this->model_name)); - - // Loads the trim whitespace filter - $smarty->load_filter('output','trimwhitespace'); - - // Includes the PICKLES custom Smarty functions - $directory = PICKLES_PATH . 'functions/smarty/'; - - if (is_dir($directory)) { - if ($handle = opendir($directory)) { - while (($file = readdir($handle)) !== false) { - if (!preg_match('/^\./', $file)) { - list($type, $name, $ext) = split('\.', $file); - require_once $directory . $file; - $smarty->register_function($name, "smarty_{$type}_{$name}"); - } - } - closedir($handle); - } - } - - // Establishes the template names - $template = SITE_PATH . '../templates/' . $this->model_name . '.tpl'; - $shared_template = PICKLES_PATH . 'templates/' . $this->shared_name . '.tpl'; - - /** - * @todo There's a bug with the store home page since it's a redirect - */ - if (!file_exists($template)) { - if (file_exists($shared_template)) { - $template = $shared_template; - } - } - - // Pass all of our controller values to Smarty - $smarty->assign('section', $this->section); - $smarty->assign('model', $this->model_name); - $smarty->assign('template', $template); - - // Loads the data from the config - $data = $this->config->getPublicData(); - - if (isset($data) && is_array($data)) { - $smarty->assign('config', $data); - } - - // Loads the model's data - if (isset($this->data) && is_array($this->data)) { - foreach ($this->data as $variable => $value) { - $smarty->assign($variable, $value); - } - } - - /** - * @todo There's no error checking for the index... should it be shared, - * and should the error checking occur anyway since any shit could - * happen? - */ - /* - $template = '../templates/index.tpl'; - $shared_template = str_replace('../', '../../pickles/', $template); - - if (!file_exists($template)) { - if (file_exists($shared_template)) { - $template = $shared_template; - } - } - */ - - // If the index.tpl file is present, load it, else load the template directly - /** - * @todo Should there be additional logic to allow the model or the - * template to determine whether or not the index should be loaded? - */ - if ($smarty->template_exists('index.tpl')) { - $smarty->display('index.tpl', $this->model_name); - } - else { - $smarty->display($template); - } - } -} - -?>