More simplification

This commit is contained in:
Timothy Warren 2015-06-04 15:46:30 -04:00
parent 140fef2cda
commit 906bec446f
19 changed files with 39 additions and 155 deletions

View File

@ -1,37 +0,0 @@
<?php
/**
* meta
*
* Hierarchial data tool
*
* @package meta
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/meta
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
namespace meta;
/**
* Base controller class to hold common functionality
*
* @param package meta
*/
abstract class Controller extends \miniMVC\Controller {
/**
* Create the controller and build page header
*/
public function __construct()
{
parent::__construct();
$this->load_model('meta\data_model');
$db = \miniMVC\db::get_instance();
$this->page->queries =& $db->queries;
}
}

View File

View File

@ -18,7 +18,7 @@
*
* @package meta
*/
class category extends meta\controller {
class category extends \miniMVC\Controller {
/**
* Initialize the Controller

View File

@ -18,7 +18,7 @@
*
* @package meta
*/
class genre extends meta\controller {
class genre extends \miniMVC\Controller {
/**
* Default controller method
@ -32,7 +32,7 @@ class genre extends meta\controller {
return;
}
// --------------------------------------------------------------------------
/**
@ -58,7 +58,7 @@ class genre extends meta\controller {
// Render the basic page
$this->index();
}
// --------------------------------------------------------------------------
/**
@ -74,7 +74,7 @@ class genre extends meta\controller {
// is a valid integer
$id = (int) miniMVC\get_last_segment();
}
$genre = $this->data_model->get_genre_by_id($id);
$categories = $this->data_model->get_categories($id);
@ -86,7 +86,7 @@ class genre extends meta\controller {
$this->render('genre_detail', $data);
}
// --------------------------------------------------------------------------
/**
@ -112,7 +112,7 @@ class genre extends meta\controller {
$this->detail($id);
}
// --------------------------------------------------------------------------
/**
@ -144,10 +144,10 @@ class genre extends meta\controller {
public function delete()
{
$type = strip_tags($_POST['type']);
$valid_types = ['genre', 'category', 'section', 'data'];
$res = (in_array($type, $valid_types))
$res = (in_array($type, $valid_types))
? $this->data_model->delete($type, (int) $_POST['id'])
: 0;
@ -184,7 +184,7 @@ class genre extends meta\controller {
$type = strip_tags($_POST['type']);
$name = strip_tags($_POST['name']);
$val = (isset($_POST['val'])) ? $_POST['val'] : NULL;
if ($this->data_model->is_valid_type($type))
{
if ($type != 'data')
@ -195,12 +195,12 @@ class genre extends meta\controller {
{
$res = $this->data_model->update_data($id, $name, $val);
}
$res = (int) $res;
exit(mb_trim($res));
}
exit(0);
}
}

View File

@ -18,7 +18,7 @@
*
* @package meta
*/
class section extends meta\controller {
class section extends \miniMVC\Controller {
/**
* Constructor

View File

@ -7,6 +7,7 @@
<?= $head_tags ?>
<?php if (!empty($base)) { ?><base href="<?=$base ?>" /><?php } ?>
<?= $head_tags ?>
<script src="<?= SCRIPT_PATH.'wysiwyg'; ?>"></script>
<?= $head_js ?>
</head>
<body<?= (!empty($body_class)) ? "class=\"" . $body_class . "\"" : ""; ?><?= (!empty($body_id)) ? " id=\"" . $body_id . "\"" : ""; ?>>

View File

@ -4,7 +4,6 @@
<a href="<?= miniMVC\site_url('category/detail/'.$p['category_id']) ?>"><?= $p['category'] ?></a> >
<?= $section ?>
</p>
<script src="<?= SCRIPT_PATH.'wysiwyg'; ?>"></script>
<form class="add" action="<?= miniMVC\site_url("section/add_data") ?>" method="post" onsubmit="window.edit_wysiwyg.toggle()">
<fieldset>
<legend>Add Data</legend>

View File

@ -1,5 +1,7 @@
{
"require": {
"aura/router": "2.0.*@dev"
"filp/whoops": "1.1.*",
"aura/router": "2.2.*",
"aviat4ion/query": "2.0.*"
}
}

View File

@ -24,13 +24,15 @@
namespace miniMVC;
use \Whoops\Handler\PrettyPageHandler;
use \Whoops\Handler\JsonResponseHandler;
error_reporting(-1);
// Set the default paths
define('MM_BASE_PATH', __DIR__);
define('MM_SYS_PATH', __DIR__.'/sys/');
define('MM_APP_PATH', __DIR__.'/app/');
define('MM_MOD_PATH', MM_APP_PATH.'modules/');
// Autoload vendors
require(MM_BASE_PATH . '/vendor/autoload.php');
@ -44,6 +46,11 @@ require(MM_SYS_PATH . 'common.php');
// Start the autoloader
spl_autoload_register('miniMVC\autoload');
// Setup error handling
$whoops = new \Whoops\Run();
$defaultHandler = new PrettyPageHandler();
$whoops->pushHandler($defaultHandler);
// And away we go!
init();

View File

@ -61,77 +61,7 @@ function autoload($name)
}
// --------------------------------------------------------------------------
// ! Error handling / messages
// --------------------------------------------------------------------------
/**
* Function to run on script shutdown
* -used to catch most fatal errors, and
* display them cleanly
*
* @return void
*/
function shutdown()
{
// Catch the last error
$error = error_get_last();
// types of errors that are fatal
$fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
// Display pretty error page
if (in_array($error['type'], $fatal))
{
$file = str_replace(MM_BASE_PATH, "", $error['file']);
$err_msg = "<h2>Fatal Error: </h2>
{$error['message']}<br /><br />
<strong>File:</strong> {$file}<br /><br />
<strong>Line:</strong> {$error['line']}";
show_error($err_msg);
}
}
// --------------------------------------------------------------------------
/**
* Custom error handler
*
* @param int $severity
* @param string $message
* @param string $filepath
* @param int $line
* @return ErrorException
*/
function on_error($severity, $message, $filepath, $line)
{
throw new \ErrorException($message, 0, $severity, $filepath, $line);
}
// --------------------------------------------------------------------------
/**
* Custom exception handlererror_get_last
*
* @param Exception $exception
* @return void
*/
function on_exception($exception)
{
// This is passed to the error template
$message = $exception->getMessage();
// Contain the content for buffering
ob_start();
include(MM_APP_PATH . '/views/errors/error_php_exception.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
// ! Messages
// --------------------------------------------------------------------------
/**
@ -295,16 +225,6 @@ if ( ! function_exists('do_include'))
*/
function init()
{
// Catch fatal errors, don't show them
if (function_exists('error_get_last'))
{
register_shutdown_function('miniMVC\shutdown');
}
//Set error handlers
set_error_handler('miniMVC\on_error');
set_exception_handler('miniMVC\on_exception');
// Load Database classes
require_once(MM_SYS_PATH . 'db/autoload.php');
@ -418,7 +338,7 @@ function route()
*/
function run($controller, $func, $args = array())
{
$path = MM_MOD_PATH . "meta/controllers/{$controller}.php";
$path = MM_APP_PATH . "controllers/{$controller}.php";
if (is_file($path))
{

View File

@ -42,6 +42,11 @@ class Controller {
{
$this->page = new Page();
}
$this->load_model('meta\data_model');
$db = \miniMVC\db::get_instance();
$this->page->queries =& $db->queries;
}
// --------------------------------------------------------------------------
@ -59,8 +64,7 @@ class Controller {
$file_name = end($segments);
// The module is set via the router
$module = strtolower(MM_MOD);
$path = MM_MOD_PATH . "{$module}/models/{$file_name}.php";
$path = MM_APP_PATH . "models/{$file_name}.php";
if (is_file($path))
{
@ -92,9 +96,9 @@ class Controller {
{
return $this->page->load_view($file, $data, $return);
}
// --------------------------------------------------------------------------
/**
* Automate loading of header and footer
*

View File

@ -137,7 +137,7 @@ class Page {
{
die();
}
if ( ! empty($this->headers))
{
// Set headers
@ -614,18 +614,7 @@ class Page {
*/
public function load_view($file, array $data=array(), $return=FALSE)
{
$path = "";
// The module is set via the router
$module = strtolower(MM_MOD);
$path = MM_MOD_PATH . "{$module}/views/{$file}.php";
// If it's not a module, or doesn't exist in the module view folder
// look in the app view folder
if ( ! is_file($path))
{
$path = MM_APP_PATH . "views/{$file}.php";
}
$path = MM_APP_PATH . "views/{$file}.php";
// Contain the content for buffering
ob_start();

1
sys/db
View File

@ -1 +0,0 @@
/var/www/htdocs/dev.timshomepage.net/github/Query/