Refactoring Display logic
This commit is contained in:
parent
1f4d4acf94
commit
012c3f8717
6 changed files with 135 additions and 193 deletions
|
@ -13,7 +13,6 @@
|
|||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
* @usage <code>require_once 'pickles.php';</code>;
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -77,6 +76,9 @@ class Controller extends Object
|
|||
unset($new_basename, $new_module_class, $new_module_filename, $new_css_class, $new_js_filename);
|
||||
}
|
||||
|
||||
// Defaults the module return variable
|
||||
$module_return = null;
|
||||
|
||||
// Loads the module or errors out
|
||||
if (isset($module_filename) && $module_filename != null && file_exists($module_filename))
|
||||
{
|
||||
|
@ -90,7 +92,7 @@ class Controller extends Object
|
|||
// Checks that our default method exists
|
||||
if (method_exists($module, '__default'))
|
||||
{
|
||||
var_dump($module->__default());
|
||||
$module_return = $module->__default();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +101,10 @@ class Controller extends Object
|
|||
// @todo Error handling
|
||||
// @todo Should we be creating a new generic Module?
|
||||
}
|
||||
|
||||
|
||||
// Starts up the display engine
|
||||
$display_class = 'Display_' . (isset($module->engine) ? $module->engine : DISPLAY_PHP);
|
||||
$display = new $display_class($module->template, $module_return);
|
||||
|
||||
exit('EOF');
|
||||
|
||||
|
@ -136,19 +141,6 @@ class Controller extends Object
|
|||
if (ini_get('session.auto_start') == 0) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Performs a logout if requested
|
||||
/**
|
||||
* @todo Maybe the logout shouldn't be an internal thing, what if
|
||||
* the user wanted to call the logout page something else? or
|
||||
* better yet, they want to next it, like /users/logout?
|
||||
* @todo May want to make it work from /store/admin/logout and not
|
||||
* just from /
|
||||
*/
|
||||
if ($module['requested']['name'] == 'logout') {
|
||||
$security = new Security($config, $db);
|
||||
$security->logout();
|
||||
}
|
||||
}
|
||||
|
||||
// Potentially requests use authentication
|
||||
|
|
|
@ -3,50 +3,56 @@
|
|||
/**
|
||||
* Common Display Class File for PICKLES
|
||||
*
|
||||
* PICKLES is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
* PHP version 5
|
||||
*
|
||||
* PICKLES is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* Licensed under the GNU General Public License Version 3
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with PICKLES. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Joshua John Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007, 2008 Joshua John Sherman
|
||||
* @package pickles
|
||||
* @author Josh Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
* @license http://www.gnu.org/copyleft/lesser.html
|
||||
* @package PICKLES
|
||||
*/
|
||||
|
||||
/**
|
||||
* Common Display Class
|
||||
*
|
||||
* This is the class that each viewer class should be extending from.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
abstract class Display_Common extends Object {
|
||||
abstract class Display_Common extends Object
|
||||
{
|
||||
/**
|
||||
* Template
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
protected $template = null;
|
||||
|
||||
/**
|
||||
* Module Return Data
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected $module_return = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Runs the parent's constructor and adds the module to the object.
|
||||
*/
|
||||
public function __construct(Config $config, Error $error) {
|
||||
public function __construct($template, $module_return)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->config = $config;
|
||||
$this->error = $error;
|
||||
|
||||
/**
|
||||
* @todo This may need to be flipped on only for Smarty and PHP templates
|
||||
*/
|
||||
// @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) {
|
||||
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);
|
||||
|
@ -57,57 +63,27 @@ abstract class Display_Common extends Object {
|
|||
ini_set('arg_separator.output', '&');
|
||||
ini_set('url_rewriter.tags', 'a=href,area=href,frame=src,input=src,fieldset=');
|
||||
|
||||
// @todo Uncomment or remove
|
||||
//header('Content-type: text/html; charset=UTF-8');
|
||||
|
||||
if ($this->config->getDebug() === true) {
|
||||
?>
|
||||
<style>
|
||||
div.debug {
|
||||
border: 2px solid #000;
|
||||
padding: 5px;
|
||||
margin: 10px;
|
||||
background-color: #FFF;
|
||||
color: #000;
|
||||
}
|
||||
</style>
|
||||
<div class="debug">
|
||||
<h1>PICKLES Debug Console</h1><br />
|
||||
<?php
|
||||
foreach ($GLOBALS as $name => $array) {
|
||||
if (count($array) > 0 && $name != 'GLOBALS') {
|
||||
?>
|
||||
<h2>$<?=$name;?></h2>
|
||||
<?php
|
||||
var_dump($array);
|
||||
|
||||
echo '<br />';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
/*
|
||||
function display_buffer() {
|
||||
$buffer = str_replace(
|
||||
array(' ', "\r\n", "\n", "\t"),
|
||||
null,
|
||||
ob_get_contents()
|
||||
);
|
||||
ob_end_clean();
|
||||
exit($buffer);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
$this->template = $template;
|
||||
$this->module_return = $module_return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract rendering function that is overloaded within the loaded viewer
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
public abstract function render();
|
||||
|
||||
public function prepare() { }
|
||||
/**
|
||||
* Preparation for display
|
||||
*/
|
||||
public function prepare()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -3,25 +3,16 @@
|
|||
/**
|
||||
* JSON Display Class File for PICKLES
|
||||
*
|
||||
* PICKLES is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
* PHP version 5
|
||||
*
|
||||
* PICKLES is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* Licensed under the GNU General Public License Version 3
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with PICKLES. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Joshua John Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007, 2008, 2009 Joshua John Sherman
|
||||
* @package pickles
|
||||
* @author Josh Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
* @license http://www.gnu.org/copyleft/lesser.html
|
||||
* @package PICKLES
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -30,20 +21,24 @@
|
|||
* 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
|
||||
* @link http://json.org/
|
||||
* @link http://us.php.net/json_encode
|
||||
* @link http://pecl.php.net/package/json
|
||||
*/
|
||||
class Display_JSON extends Display_Common {
|
||||
|
||||
class Display_JSON extends Display_Common
|
||||
{
|
||||
/**
|
||||
* Renders the data in JSON format
|
||||
*/
|
||||
public function render() {
|
||||
if (!function_exists('json_encode')) {
|
||||
public function render()
|
||||
{
|
||||
if (!function_exists('json_encode'))
|
||||
{
|
||||
echo '{ "type" : "error", "message" : "json_encode() not found" }';
|
||||
} else {
|
||||
echo json_encode($this->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo json_encode($this->module_return);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,25 +3,16 @@
|
|||
/**
|
||||
* PHP Display Class File for PICKLES
|
||||
*
|
||||
* PICKLES is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
* PHP version 5
|
||||
*
|
||||
* PICKLES is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* Licensed under the GNU General Public License Version 3
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with PICKLES. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Joshua John Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007, 2008 Joshua John Sherman
|
||||
* @package pickles
|
||||
* @author Josh Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
* @license http://www.gnu.org/copyleft/lesser.html
|
||||
* @package PICKLES
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -33,24 +24,15 @@
|
|||
* system than Smarty. The general rules around the caching will
|
||||
* be the same though.
|
||||
*/
|
||||
class Display_PHP extends Display_Common {
|
||||
|
||||
private $template_path = null;
|
||||
private $template = null;
|
||||
private $shared_template = null;
|
||||
|
||||
public function __construct(Config $config, Error $error) {
|
||||
parent::__construct($config, $error);
|
||||
|
||||
// Establishes the template path
|
||||
$this->template_path = SITE_PATH . '../templates/';
|
||||
}
|
||||
|
||||
public function prepare() {
|
||||
|
||||
class Display_PHP extends Display_Common
|
||||
{
|
||||
public function prepare()
|
||||
{
|
||||
// Enables caching
|
||||
if ($this->caching == true) {
|
||||
if (is_numeric($this->caching)) {
|
||||
if ($this->caching == true)
|
||||
{
|
||||
if (is_numeric($this->caching))
|
||||
{
|
||||
//$this->smarty->cache_lifetime = $this->caching;
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +44,8 @@ class Display_PHP extends Display_Common {
|
|||
/**
|
||||
* Renders the PHP templated pages
|
||||
*/
|
||||
public function render() {
|
||||
|
||||
public function render()
|
||||
{
|
||||
//if (filemtime($this->template)) {
|
||||
// readfile('/var/www/josh/pickles/var/joshtronic.localhost/smarty/cache/home.html');
|
||||
//}
|
||||
|
@ -71,8 +53,10 @@ class Display_PHP extends Display_Common {
|
|||
/**
|
||||
* @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)) {
|
||||
if (!file_exists($this->template))
|
||||
{
|
||||
if (file_exists($this->shared_template))
|
||||
{
|
||||
$this->template = $this->shared_template;
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +85,12 @@ class Display_PHP extends Display_Common {
|
|||
* @todo Should there be additional logic to allow the module or the
|
||||
* template to determine whether or not the index should be loaded?
|
||||
*/
|
||||
if (file_exists($this->template_path . 'index.php')) {
|
||||
if (file_exists($this->template_path . 'index.php'))
|
||||
{
|
||||
require_once $this->template_path . 'index.php';
|
||||
}
|
||||
else if (file_exists($this->template)) {
|
||||
elseif (file_exists($this->template))
|
||||
{
|
||||
require_once $this->template;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,25 +3,16 @@
|
|||
/**
|
||||
* RSS Display Class File for PICKLES
|
||||
*
|
||||
* PICKLES is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
* PHP version 5
|
||||
*
|
||||
* PICKLES is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* Licensed under the GNU General Public License Version 3
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with PICKLES. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Joshua John Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007, 2008, 2009 Joshua John Sherman
|
||||
* @package pickles
|
||||
* @author Josh Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
* @license http://www.gnu.org/copyleft/lesser.html
|
||||
* @package PICKLES
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -35,8 +26,8 @@
|
|||
* Feed viewer that would take a parameter to determine which type of
|
||||
* of feed to use).
|
||||
*/
|
||||
class Display_RSS extends Display_Common {
|
||||
|
||||
class Display_RSS extends Display_Common
|
||||
{
|
||||
/**
|
||||
* Render the RSS feed data
|
||||
*
|
||||
|
@ -45,22 +36,28 @@ class Display_RSS extends Display_Common {
|
|||
*
|
||||
* @todo Error handling is non-existant.
|
||||
*/
|
||||
public function render() {
|
||||
if (isset($this->data->channel) || is_object($this->data['channel'])) {
|
||||
public function render()
|
||||
{
|
||||
if (isset($this->data->channel) || is_object($this->data['channel']))
|
||||
{
|
||||
$channel = $this->data['channel'];
|
||||
|
||||
if (!is_object($this->data['channel'])) {
|
||||
if (!is_object($this->data['channel']))
|
||||
{
|
||||
$channel = $this->config->rss->$channel;
|
||||
}
|
||||
|
||||
if (isset($this->data->items)) {
|
||||
if (isset($this->data->items))
|
||||
{
|
||||
$items = $this->data['items'];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$this->error->addError('No items were provided');
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$this->error->addError('No channel was specified');
|
||||
}
|
||||
|
||||
|
@ -73,7 +70,8 @@ class Display_RSS extends Display_Common {
|
|||
<link>http://<?=$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];?></link>
|
||||
<description><?=$channel->description;?></description>
|
||||
<?php
|
||||
if (isset($channel->image)) {
|
||||
if (isset($channel->image))
|
||||
{
|
||||
?>
|
||||
<image>
|
||||
<url><?=$channel->image;?></url>
|
||||
|
@ -87,11 +85,14 @@ class Display_RSS extends Display_Common {
|
|||
<language><?=isset($channel->language) ? $channel->language : 'en-us';?></language>
|
||||
<generator version="pre-beta 0.0.0">PICKLES (http://phpwithpickles.org)</generator>
|
||||
<?php
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $key => $item) {
|
||||
if (is_array($items))
|
||||
{
|
||||
foreach ($items as $key => $item)
|
||||
{
|
||||
$date = date('r', strtotime($item['date']));
|
||||
|
||||
if ($key == 0) {
|
||||
if ($key == 0)
|
||||
{
|
||||
echo "<lastBuildDate>{$date}</lastBuildDate>";
|
||||
}
|
||||
?>
|
||||
|
@ -112,4 +113,5 @@ class Display_RSS extends Display_Common {
|
|||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -3,25 +3,16 @@
|
|||
/**
|
||||
* Smarty Display Class File for PICKLES
|
||||
*
|
||||
* PICKLES is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version.
|
||||
* PHP version 5
|
||||
*
|
||||
* PICKLES is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* Licensed under the GNU General Public License Version 3
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with PICKLES. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Joshua John Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007, 2008, 2009 Joshua John Sherman
|
||||
* @package pickles
|
||||
* @author Josh Sherman <josh@phpwithpickles.org>
|
||||
* @copyright Copyright 2007-2010, Gravity Boulevard, LLC
|
||||
* @license http://www.gnu.org/licenses/gpl.html GPL v3
|
||||
* @link http://phpwithpickles.org
|
||||
* @license http://www.gnu.org/copyleft/lesser.html
|
||||
* @package PICKLES
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -31,8 +22,8 @@
|
|||
*
|
||||
* @link http://smarty.net/
|
||||
*/
|
||||
class Display_Smarty extends Display_Common {
|
||||
|
||||
class Display_Smarty extends Display_Common
|
||||
{
|
||||
private $smarty = null;
|
||||
|
||||
public function __construct(Config $config, Error $error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue