From 140fef2cda3d3166b4d281c31f222be061688f77 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 4 Jun 2015 14:30:42 -0400 Subject: [PATCH] Simplify and add lightness --- .gitignore | 4 +- README.md | 0 app/classes/controller.php | 34 +- app/config/config.php | 9 +- app/config/routes.php | 28 +- app/modules/meta/controllers/category.php | 6 +- app/modules/meta/controllers/genre.php | 139 +++- app/modules/meta/controllers/section.php | 6 +- app/modules/meta/controllers/welcome.php | 167 ---- app/modules/meta/models/data_model.php | 216 +++--- app/modules/meta/models/user_model.php | 120 --- app/modules/meta/views/category_detail.php | 26 +- app/modules/meta/views/edit_form.php | 0 app/modules/meta/views/genre_detail.php | 16 +- app/modules/meta/views/genres.php | 4 +- app/modules/meta/views/login.php | 14 - app/modules/meta/views/outline.php | 6 +- app/modules/meta/views/section_detail.php | 44 +- app/modules/setup/controllers/setup.php | 33 - app/views/errors/error_404.php | 0 app/views/errors/error_db.php | 0 app/views/errors/error_general.php | 0 app/views/errors/error_php_exception.php | 0 app/views/footer.php | 2 +- app/views/header.php | 5 +- app/views/message.php | 0 app/views/theme_footer.php | 7 +- app/views/theme_header.php | 4 +- assets/config/css_groups.php | 3 +- assets/config/js_groups.php | 1 + assets/css/message.css | 0 assets/css/normalize.css | 0 assets/css/prism.css | 127 ++++ assets/css/theme.css | 6 +- assets/js/kis-lite-dom.js | 840 ++++++--------------- assets/js/meta.js | 156 ++-- assets/js/prism.js | 12 + composer.json | 5 + favicon.ico | Bin 0 -> 1150 bytes index.php | 8 +- phpdoc.dist.xml | 7 +- sys/common.php | 143 +--- sys/core/Controller.php | 15 + sys/core/Model.php | 0 sys/core/Page.php | 11 +- sys/core/db.php | 10 +- sys/db | 2 +- sys/libraries/Bcrypt.php | 201 ----- sys/libraries/Data_Store.php | 153 ---- sys/libraries/Session.php | 124 --- 50 files changed, 824 insertions(+), 1890 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 app/classes/controller.php mode change 100644 => 100755 app/config/config.php mode change 100644 => 100755 app/config/routes.php mode change 100644 => 100755 app/modules/meta/controllers/category.php mode change 100644 => 100755 app/modules/meta/controllers/genre.php mode change 100644 => 100755 app/modules/meta/controllers/section.php delete mode 100644 app/modules/meta/controllers/welcome.php mode change 100644 => 100755 app/modules/meta/models/data_model.php delete mode 100644 app/modules/meta/models/user_model.php mode change 100644 => 100755 app/modules/meta/views/category_detail.php mode change 100644 => 100755 app/modules/meta/views/edit_form.php mode change 100644 => 100755 app/modules/meta/views/genre_detail.php mode change 100644 => 100755 app/modules/meta/views/genres.php delete mode 100644 app/modules/meta/views/login.php mode change 100644 => 100755 app/modules/meta/views/outline.php mode change 100644 => 100755 app/modules/meta/views/section_detail.php delete mode 100644 app/modules/setup/controllers/setup.php mode change 100644 => 100755 app/views/errors/error_404.php mode change 100644 => 100755 app/views/errors/error_db.php mode change 100644 => 100755 app/views/errors/error_general.php mode change 100644 => 100755 app/views/errors/error_php_exception.php mode change 100644 => 100755 app/views/footer.php mode change 100644 => 100755 app/views/header.php mode change 100644 => 100755 app/views/message.php mode change 100644 => 100755 app/views/theme_footer.php mode change 100644 => 100755 app/views/theme_header.php mode change 100644 => 100755 assets/config/css_groups.php mode change 100644 => 100755 assets/css/message.css mode change 100644 => 100755 assets/css/normalize.css create mode 100755 assets/css/prism.css mode change 100644 => 100755 assets/css/theme.css mode change 100755 => 100644 assets/js/kis-lite-dom.js mode change 100644 => 100755 assets/js/meta.js create mode 100755 assets/js/prism.js create mode 100644 composer.json create mode 100644 favicon.ico mode change 100644 => 100755 index.php mode change 100644 => 100755 phpdoc.dist.xml mode change 100644 => 100755 sys/common.php mode change 100644 => 100755 sys/core/Controller.php mode change 100644 => 100755 sys/core/Model.php mode change 100644 => 100755 sys/core/Page.php mode change 100644 => 100755 sys/core/db.php mode change 160000 => 120000 sys/db delete mode 100644 sys/libraries/Bcrypt.php delete mode 100644 sys/libraries/Data_Store.php delete mode 100644 sys/libraries/Session.php diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 0c70654..f0c566c --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ sys/*.sqlite docs/* -assets/js/cache/* \ No newline at end of file +assets/js/cache/* +vendor/* +composer.lock \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/app/classes/controller.php b/app/classes/controller.php old mode 100644 new mode 100755 index 72b3813..7a699c4 --- a/app/classes/controller.php +++ b/app/classes/controller.php @@ -29,37 +29,9 @@ abstract class Controller extends \miniMVC\Controller { { parent::__construct(); $this->load_model('meta\data_model'); - $this->load_model('meta\user_model'); - - $this->session =& \miniMVC\Session::get_instance(); - - // Check if user is logged in - $this->check_login_status(); - - $this->page->build_header(); - } - - /** - * Require user login for access - */ - private function check_login_status() - { - if ( ! isset($this->session->uid)) - { - // Redirect to login - } - - return; - - } - - /** - * Destruct controller and build page footer - */ - public function __destruct() - { - $this->page->set_foot_js_group('js'); - $this->page->build_footer(); + $db = \miniMVC\db::get_instance(); + + $this->page->queries =& $db->queries; } } diff --git a/app/config/config.php b/app/config/config.php old mode 100644 new mode 100755 index 841e1a9..01cae91 --- a/app/config/config.php +++ b/app/config/config.php @@ -31,12 +31,7 @@ | slash. | */ -// Determine the default site url -$ri = $_SERVER['REQUEST_URI']; -$ind_pos = stripos($ri, "index.php"); -$default_path = ($ind_pos !== FALSE) ? substr($ri, 0, $ind_pos) : $ri; -$default_baseurl = "//" . str_replace("//", "/", $_SERVER['HTTP_HOST']. $default_path); -define('BASE_URL', $default_baseurl); +define('BASE_URL', '//' . $_SERVER['HTTP_HOST'] . '/'); /* |-------------------------------------------------------------------------- @@ -46,7 +41,7 @@ define('BASE_URL', $default_baseurl); | This determines whether "index.php" is in generated urls | */ -define('URL_INDEX_FILE', 'index.php/'); +define('URL_INDEX_FILE', ''); /* |-------------------------------------------------------------------------- diff --git a/app/config/routes.php b/app/config/routes.php old mode 100644 new mode 100755 index 0e42238..af8a56c --- a/app/config/routes.php +++ b/app/config/routes.php @@ -29,20 +29,22 @@ // -------------------------------------------------------------------------- -return array( +$routes = [ // Default Paths - 'default_controller' => 'welcome', - 'default_module' => 'meta', - 'delete' => 'meta/welcome/delete', - 'update' => 'meta/welcome/update_item', - 'genre' => 'meta/genre/index', - 'genre/add' => 'meta/genre/add', - 'genre/add_category' => 'meta/genre/add_category', - 'category' => 'meta/category/index', - 'category/add_section' => 'meta/category/add_section', - 'section' => 'meta/section/index', - 'section/add_data' => 'meta/section/add_data', + 'default_controller' => 'genre', '404_route' => '', -); +]; + +// Add default routes +$router->add('home', '/'); +$router->add(null, '/{controller}/{action}/{id}'); +$router->add('no_id', '/{controller}/{action}'); + +// Custom routes +$router->add('outline', '/outline'); +$router->add('edit', '/edit'); +$router->add('delete', '/delete'); +$router->addPost('data_add', '/section/add_data'); +$router->addPost('update', '/update'); // End of routes.php \ No newline at end of file diff --git a/app/modules/meta/controllers/category.php b/app/modules/meta/controllers/category.php old mode 100644 new mode 100755 index f461ae5..27b2052 --- a/app/modules/meta/controllers/category.php +++ b/app/modules/meta/controllers/category.php @@ -31,7 +31,7 @@ class category extends meta\controller { /** * Returns the sections / editing options for a category */ - public function index($id = 0) + public function detail($id = 0) { if ($id === 0) { @@ -50,7 +50,7 @@ class category extends meta\controller { 'category_id' => $id ); - $this->load_view('category_detail', $data); + $this->render('category_detail', $data); } /** @@ -74,7 +74,7 @@ class category extends meta\controller { $this->page->set_message('error', 'Section already exists for this category'); } - $this->index($id); + $this->detail($id); } } diff --git a/app/modules/meta/controllers/genre.php b/app/modules/meta/controllers/genre.php old mode 100644 new mode 100755 index ba35019..1837d54 --- a/app/modules/meta/controllers/genre.php +++ b/app/modules/meta/controllers/genre.php @@ -20,39 +20,20 @@ */ class genre extends meta\controller { - /** - * Initialize the Controller - */ - public function __construct() - { - parent::__construct(); - } - /** * Default controller method */ - public function index($id = 0) + public function index() { - if ($id === 0) - { - // Re-route to detail page if the last segment - // is a valid integer - $id = (int) miniMVC\get_last_segment(); - } + $data = array(); + $data['genres'] = $this->data_model->get_genres(); - if ($id === 0) - { - // Otherwise, display list of genres - $data = array(); - $data['genres'] = $this->data_model->get_genres(); + $this->render('genres', $data); - $this->load_view('genres', $data); - - return; - } - - return $this->detail($id); + return; } + + // -------------------------------------------------------------------------- /** * Adds a new genre @@ -77,14 +58,23 @@ class genre extends meta\controller { // Render the basic page $this->index(); } + + // -------------------------------------------------------------------------- /** * Returns the categories / editing options for a genre * * @param int */ - public function detail($id) + public function detail($id = 0) { + if ($id === 0) + { + // Re-route to detail page if the last segment + // 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); @@ -94,8 +84,10 @@ class genre extends meta\controller { 'genre_id' => $id ); - $this->load_view('genre_detail', $data); + $this->render('genre_detail', $data); } + + // -------------------------------------------------------------------------- /** * Adds a category to the current genre @@ -120,6 +112,97 @@ class genre extends meta\controller { $this->detail($id); } + + // -------------------------------------------------------------------------- + + /** + * Display an outline of the data for a table of contents + */ + public function outline() + { + $outline_data = $this->data_model->get_outline_data(); + $this->render('outline', array('outline' => $outline_data)); + } + + // -------------------------------------------------------------------------- + + /** + * Get a message for ajax insertion + */ + public function message() + { + $type = strip_tags($_GET['type']); + $message = $_GET['message']; + + $this->page->set_output( + $this->page->set_message($type, $message, TRUE) + ); + } + + // -------------------------------------------------------------------------- + + public function delete() + { + $type = strip_tags($_POST['type']); + + $valid_types = ['genre', 'category', 'section', 'data']; + + $res = (in_array($type, $valid_types)) + ? $this->data_model->delete($type, (int) $_POST['id']) + : 0; + + exit(mb_trim($res)); + } + + // -------------------------------------------------------------------------- + + public function edit() + { + $type = strip_tags($_GET['type']); + $id = (int) $_GET['id']; + + if ($this->data_model->is_valid_type($type)) + { + $data = call_user_func(array($this->data_model, "get_{$type}_by_id"), $id); + + $form_array = array( + 'name' => is_array($data) ? $data['key'] : "", + 'val' => is_array($data) ? $data['value'] : $data, + 'type' => $type, + 'id' => $id + ); + + exit($this->load_view('edit_form', $form_array, TRUE)); + } + } + + // -------------------------------------------------------------------------- + + public function update() + { + $id = (int) $_POST['id']; + $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') + { + $res = $this->data_model->update($type, $id, $name); + } + else + { + $res = $this->data_model->update_data($id, $name, $val); + } + + $res = (int) $res; + + exit(mb_trim($res)); + } + + exit(0); + } } // End of genre.php \ No newline at end of file diff --git a/app/modules/meta/controllers/section.php b/app/modules/meta/controllers/section.php old mode 100644 new mode 100755 index ec7dc8d..1c33efb --- a/app/modules/meta/controllers/section.php +++ b/app/modules/meta/controllers/section.php @@ -31,7 +31,7 @@ class section extends meta\controller { /** * Default controller method */ - public function index($id=0) + public function detail($id=0) { if ($id === 0) { @@ -50,7 +50,7 @@ class section extends meta\controller { 'section_id' => $id ); - $this->load_view('section_detail', $data); + $this->render('section_detail', $data); } /** @@ -77,7 +77,7 @@ class section extends meta\controller { ? $this->page->set_message('success', 'Added data') : $this->page->set_message('error', 'Data already exists'); - $this->index($section_id); + $this->detail($section_id); } } diff --git a/app/modules/meta/controllers/welcome.php b/app/modules/meta/controllers/welcome.php deleted file mode 100644 index e3619ee..0000000 --- a/app/modules/meta/controllers/welcome.php +++ /dev/null @@ -1,167 +0,0 @@ -data_model->get_genres(); - - $this->load_view('genres', $data); - } - - // -------------------------------------------------------------------------- - - /** - * Authenticate a user - */ - public function login() - { - $this->load_view('login'); - } - - // -------------------------------------------------------------------------- - - /** - * Logout - */ - public function logout() - { - - } - - // -------------------------------------------------------------------------- - - /** - * Display an outline of the data for a table of contents - */ - public function outline() - { - $outline_data = $this->data_model->get_outline_data(); - $this->load_view('outline', array('outline' => $outline_data)); - } - - // -------------------------------------------------------------------------- - - /** - * Get a message for ajax insertion - */ - public function message() - { - $type = strip_tags($_GET['type']); - $message = $_GET['message']; - - $this->page->set_output( - $this->page->set_message($type, $message, TRUE) - ); - } - - // -------------------------------------------------------------------------- - - public function delete() - { - $type = strip_tags($_POST['type']); - - switch($type) - { - case "genre": - case "category": - case "section": - case "data": - $res = (int) $this->data_model->delete($type, (int) $_POST['id']); - break; - - default: - $res = 0; - break; - } - die(trim($res)); - } - - // -------------------------------------------------------------------------- - - public function edit() - { - $type = strip_tags($_GET['type']); - $id = (int) $_GET['id']; - - if ($this->data_model->is_valid_type($type)) - { - $data = call_user_func(array($this->data_model, "get_{$type}_by_id"), $id); - - $form_array = array( - 'name' => is_array($data) ? $data['key'] : "", - 'val' => is_array($data) ? $data['value'] : $data, - 'type' => $type, - 'id' => $id - ); - - exit($this->load_view('edit_form', $form_array, TRUE)); - } - } - - // -------------------------------------------------------------------------- - - public function update_item() - { - $id = (int) $_POST['id']; - $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') - { - $res = $this->data_model->update($type, $id, $name); - } - else - { - $res = $this->data_model->update_data($id, $name, $val); - } - - $res = (int) $res; - - exit(trim($res)); - } - - exit(0); - } -} - -// End of welcome.php \ No newline at end of file diff --git a/app/modules/meta/models/data_model.php b/app/modules/meta/models/data_model.php old mode 100644 new mode 100755 index 1c5c255..8f64e2e --- a/app/modules/meta/models/data_model.php +++ b/app/modules/meta/models/data_model.php @@ -15,6 +15,8 @@ namespace meta; +use \miniMVC\db; + /** * Main Model for database interaction * @@ -42,9 +44,7 @@ class data_model extends \miniMVC\Model { public function __construct() { parent::__construct(); - - $this->session =& \miniMVC\Session::get_instance(); - $this->db =& \miniMVC\db::get_instance(); + $this->db = db::get_instance(); } // -------------------------------------------------------------------------- @@ -113,7 +113,7 @@ class data_model extends \miniMVC\Model { ->where('id', (int) $id) ->update($type); - return ( ! empty($query)) ; + return (bool) $query; } // -------------------------------------------------------------------------- @@ -128,19 +128,13 @@ class data_model extends \miniMVC\Model { */ public function update_data($data_id, $key, $val) { - try{ - // Save the data - $this->db->set('key', $key) - ->set('value', $val) - ->where('id', (int) $data_id) - ->update('data'); - } - catch(\PDOException $e) - { - return FALSE; - } + // Save the data + $query = $this->db->set('key', $key) + ->set('value', $val) + ->where('id', (int) $data_id) + ->update('data'); - return TRUE; + return (bool) $query; } // -------------------------------------------------------------------------- @@ -161,13 +155,13 @@ class data_model extends \miniMVC\Model { ->limit(1) ->get(); - // Fetch the data as a workaround - // for databases that do not support - // grabbing result counts (SQLite / Firebird) - $array = $query->fetchAll(\PDO::FETCH_ASSOC); - if (count($array) < 1) + $res = $query->fetch(); + + if (count($res) < 1) { - $this->db->set('genre', $genre) + $id = $this->get_next_id("genre"); + $this->db->set('id', $id) + ->set('genre', $genre) ->insert('genre'); return TRUE; @@ -195,13 +189,13 @@ class data_model extends \miniMVC\Model { ->limit(1) ->get(); - // Fetch the data as a workaround - // for databases that do not support - // grabbing result counts (SQLite / Firebird) - $array = $query->fetchAll(); - if (count($array)< 1) + $res = $query->fetch(); + + if (count($res) < 1) { - $this->db->set('category', $cat) + $id = $this->get_next_id('category'); + $this->db->set('id', $id) + ->set('category', $cat) ->set('genre_id', $genre_id) ->insert('category'); @@ -234,7 +228,9 @@ class data_model extends \miniMVC\Model { $array = $q->fetchAll(); if (count($array) < 1) { - $this->db->set('section', $section) + $id = $this->get_next_id('section'); + $this->db->set('id', $id) + ->set('section', $section) ->set('category_id', (int) $category_id) ->insert('section'); @@ -262,10 +258,14 @@ class data_model extends \miniMVC\Model { ->where('key', $key) ->get(); - if ($this->db->num_rows() > 0) return FALSE; + $res = $q->fetch(); + + if (count($res) > 0) return FALSE; // Save the data - $this->db->set('key', $key) + $id = $this->get_next_id('data'); + $this->db->set('id', $id) + ->set('key', $key) ->set('value', $val) ->set('section_id', (int) $section_id) ->insert('data'); @@ -274,8 +274,6 @@ class data_model extends \miniMVC\Model { return TRUE; } - - // -------------------------------------------------------------------------- // ! Data Retrieval // -------------------------------------------------------------------------- @@ -290,8 +288,8 @@ class data_model extends \miniMVC\Model { { $query = $this->db->select('genre, genre_id, category, category_id') ->from('section s') - ->join('category c', 'c.id=s.category_id') - ->join('genre g', 'g.id=c.genre_id') + ->join('category c', 'c.id=s.category_id', 'inner') + ->join('genre g', 'g.id=c.genre_id', 'inner') ->where('s.id', $section_id) ->get(); @@ -310,7 +308,7 @@ class data_model extends \miniMVC\Model { $genres = array(); $query = $this->db->select('id, genre') ->from('genre') - ->order_by('genre', 'asc') + ->orderBy('genre', 'asc') ->get(); while($row = $query->fetch(\PDO::FETCH_ASSOC)) @@ -377,6 +375,7 @@ class data_model extends \miniMVC\Model { $query = $this->db->select('id, category') ->from('category') ->where('genre_id', (int) $genre_id) + ->orderBy('category', 'asc') ->get(); while($row = $query->fetch(\PDO::FETCH_ASSOC)) @@ -422,6 +421,7 @@ class data_model extends \miniMVC\Model { $query = $this->db->select('id, section') ->from('section') ->where('category_id', (int) $category_id) + ->orderBy('section', 'asc') ->get(); while($row = $query->fetch(\PDO::FETCH_ASSOC)) @@ -467,6 +467,7 @@ class data_model extends \miniMVC\Model { $query = $this->db->select('id, key, value') ->from('data') ->where('section_id', (int) $section_id) + ->orderBy('key', 'asc') ->get(); while($row = $query->fetch(\PDO::FETCH_ASSOC)) @@ -510,6 +511,7 @@ class data_model extends \miniMVC\Model { // Get the sections $s_query = $this->db->from('section') ->where('category_id', (int) $category_id) + ->orderBy('section', 'asc') ->get(); $sections = array(); @@ -525,7 +527,8 @@ class data_model extends \miniMVC\Model { if ( ! empty($sections)) { $d_query = $this->db->from('data') - ->where_in('section_id', array_keys($sections)) + ->whereIn('section_id', array_keys($sections)) + ->orderBy('key', 'asc') ->get(); while($row = $d_query->fetch(\PDO::FETCH_ASSOC)) @@ -557,62 +560,24 @@ class data_model extends \miniMVC\Model { public function get_outline_data() { // Get the genres - $g_query = $this->db->from('genre') + $query = $this->db->select('g.id, genre, + c.id AS cat_id, category, + s.id AS section_id, section') + ->from('genre g') + ->join('category c', 'c.genre_id=g.id', 'inner') + ->join('section s', 's.category_id=c.id', 'inner') + ->orderBy('genre', 'asc') + ->orderBy('category', 'asc') + ->orderBy('section', 'asc') ->get(); - $genres = array(); + $return = array(); - while ($row = $g_query->fetch(\PDO::FETCH_ASSOC)) + // Create the nested array + while ($row = $query->fetch(\PDO::FETCH_ASSOC)) { - $genres[$row['id']] = $row['genre']; - } - - // Get the categories - $c_query = $this->db->from('category') - ->get(); - - $categories = array(); - - while($row = $c_query->fetch(\PDO::FETCH_ASSOC)) - { - $categories[$row['genre_id']][$row['id']] = $row['category']; - } - - // Get the sections - $s_query = $this->db->from('section') - ->get(); - - $sections = array(); - - while($row = $s_query->fetch(\PDO::FETCH_ASSOC)) - { - $sections[$row['category_id']][$row['id']] = $row['section']; - } - - - // Organize into a nested array - foreach($genres as $genre_id => $genre) - { - $return[$genre_id][$genre] = array(); - $g =& $return[$genre_id][$genre]; - - // Categories for this genre - if (isset($categories[$genre_id])) - { - $g = $categories[$genre_id]; - - foreach($categories[$genre_id] as $category_id => $category) - { - $g[$category_id] = array($category => array()); - $c =& $g[$category_id][$category]; - - // Sections for this category - if (isset($sections[$category_id])) - { - $c = $sections[$category_id]; - } - } - } + extract($row); + $return[$id][$genre][$cat_id][$category][$section_id] = $section; } return $return; @@ -649,7 +614,7 @@ class data_model extends \miniMVC\Model { { $query = $this->db->select('id') ->from($type) - ->order_by('id', 'DESC') + ->orderBy('id', 'DESC') ->limit(1) ->get(); @@ -660,6 +625,77 @@ class data_model extends \miniMVC\Model { // -------------------------------------------------------------------------- + /** + * Get the next id for database insertion + * + * @param string $table_name + * @param string $field + * @return int + */ + public function get_next_id($table_name, $field="id") + { + + $query = $this->db->select("MAX($field) as last_id") + ->from($table_name) + ->limit(1) + ->get(); + + $row = $query->fetch(\PDO::FETCH_ASSOC); + + if (empty($row)) + { + $id = 1; + } + else + { + $id = intval($row['last_id']) + 1; + } + + return $id; + } + + // -------------------------------------------------------------------------- + + public function create_tables() + { + $tables = [ + 'genre' => $this->db->util->create_table('genre', [ + 'id' => 'INT NOT NULL PRIMARY KEY', + 'genre' => 'VARCHAR(255)' + ]), + 'category' => $this->db->util->create_table('category', [ + 'id' => 'INT NOT NULL PRIMARY KEY', + 'genre_id' => 'INT NOT NULL', + 'category' => 'VARCHAR(255)' + ],[ + 'genre_id' => ' REFERENCES "genre" ' + ]), + 'section' => $this->db->util->create_table('section', [ + 'id' => 'INT NOT NULL PRIMARY KEY', + 'category_id' => 'INT NOT NULL', + 'section' => 'VARCHAR(255)' + ],[ + 'category_id' => ' REFERENCES "category" ' + ]), + 'data' => $this->db->util->create_table('data', [ + 'id' => 'INT NOT NULL PRIMARY KEY', + 'section_id' => 'INT NOT NULL', + 'key' => 'VARCHAR(255)', + 'value' => 'BLOB SUB_TYPE TEXT' + ],[ + 'section_id' => ' REFERENCES "section"' + ]) + ]; + + foreach($tables as $table => $sql) + { + // Add the table + $this->db->query($sql); + echo "{$sql};
"; + + } + } + } // End of data_model.php \ No newline at end of file diff --git a/app/modules/meta/models/user_model.php b/app/modules/meta/models/user_model.php deleted file mode 100644 index 883b40d..0000000 --- a/app/modules/meta/models/user_model.php +++ /dev/null @@ -1,120 +0,0 @@ -bcrypt = new \Bcrypt(15); - $this->db =& \miniMVC\db::get_instance(); - $this->session =& \miniMVC\Session::get_instance(); - } - - // -------------------------------------------------------------------------- - - /** - * Add a user for access - * - * @param string - * @param string - * @param string - */ - public function add_user($username, $pass1, $pass2) - { - // Check for the existing username - $query = $this->db->select('username') - ->from('user') - ->where('username', $username) - ->get(); - - $res = $query->fetch(\PDO::FETCH_ASSOC); - - if (empty($res)) return FALSE; - - // Verify that passwords match - if ($pass1 !== $pass2) return FALSE; - - // Add user - $hashed = $this->bcrypt->hash($pass1); - - $this->db->set('username', $username) - ->set('hash', $hashed) - ->insert('user'); - - return TRUE; - } - - // -------------------------------------------------------------------------- - - /** - * Check and see if the login is valid - * - * @param string - * @param string - * @return bool - */ - public function check_login($username, $pass) - { - $query = $this->db->from('user') - ->where('username', $username) - ->get(); - - $row = $query->fetch(\PDO::FETCH_ASSOC); - - // The user does not exist - if (empty($row)) - { - return FALSE; - } - - return $this->bcrypt->verify($pass, $row['hash']); - } - -} - -// End of user_model.php \ No newline at end of file diff --git a/app/modules/meta/views/category_detail.php b/app/modules/meta/views/category_detail.php old mode 100644 new mode 100755 index 8bf3609..3e6a40e --- a/app/modules/meta/views/category_detail.php +++ b/app/modules/meta/views/category_detail.php @@ -1,5 +1,5 @@
" method="post"> @@ -22,27 +22,23 @@
  • ">

    - + - $dd): ?> - $v): ?> - ") !== FALSE) ? 'multiline' : 'pair' ?> -
    - -
    -
    - -
    - -
    + $v): ?> + ") !== FALSE || strpos($v, "
    ") !== FALSE) ? 'multiline' : 'pair' ?> +
    +
    +
    + +
    +
    + - - diff --git a/app/modules/meta/views/edit_form.php b/app/modules/meta/views/edit_form.php old mode 100644 new mode 100755 diff --git a/app/modules/meta/views/genre_detail.php b/app/modules/meta/views/genre_detail.php old mode 100644 new mode 100755 index d9033b2..aa08922 --- a/app/modules/meta/views/genre_detail.php +++ b/app/modules/meta/views/genre_detail.php @@ -19,23 +19,11 @@
      $cat): ?>
    • - "> - + "> + -
        - data_model->get_sections($id); ?> - $section): ?> -
      • - "> - - - - -
      • - -
    diff --git a/app/modules/meta/views/genres.php b/app/modules/meta/views/genres.php old mode 100644 new mode 100755 index a85f804..7bcb194 --- a/app/modules/meta/views/genres.php +++ b/app/modules/meta/views/genres.php @@ -18,10 +18,10 @@
      $name): ?>
    • - "> + "> - + diff --git a/app/modules/meta/views/login.php b/app/modules/meta/views/login.php deleted file mode 100644 index 4a5f01a..0000000 --- a/app/modules/meta/views/login.php +++ /dev/null @@ -1,14 +0,0 @@ -

      Login

      - - -
      -
      -
      - -
      -
      - -
       
      -
      -
      - \ No newline at end of file diff --git a/app/modules/meta/views/outline.php b/app/modules/meta/views/outline.php old mode 100644 new mode 100755 index e0f8a65..058d233 --- a/app/modules/meta/views/outline.php +++ b/app/modules/meta/views/outline.php @@ -20,7 +20,7 @@ $cat_array): ?>
      - "> + ">
      @@ -29,14 +29,14 @@ $sect_array): ?>
    • - "> + ">
        $section): ?>
      • - "> + ">
      • diff --git a/app/modules/meta/views/section_detail.php b/app/modules/meta/views/section_detail.php old mode 100644 new mode 100755 index e8e3d0c..edb1885 --- a/app/modules/meta/views/section_detail.php +++ b/app/modules/meta/views/section_detail.php @@ -4,8 +4,8 @@ >

        - -
        " method="post"> + +" method="post" onsubmit="window.edit_wysiwyg.toggle()">
        Add Data
        @@ -21,56 +21,22 @@
        - - +

        Data

        - $d): ?> $v): ?> - ") !== FALSE) ? 'multiline' : 'pair' ?> + ") !== FALSE || strpos($v, "
        ") !== FALSE) ? 'multiline' : 'pair' ?>
        -
        - +
        -
        - \ No newline at end of file diff --git a/app/modules/setup/controllers/setup.php b/app/modules/setup/controllers/setup.php deleted file mode 100644 index 7c26231..0000000 --- a/app/modules/setup/controllers/setup.php +++ /dev/null @@ -1,33 +0,0 @@ -load_view('theme_footer'); ?> +load_view('theme_footer', ['queries' => $this->queries], TRUE); ?> diff --git a/app/views/header.php b/app/views/header.php old mode 100644 new mode 100755 index fe0bc51..8e685b1 --- a/app/views/header.php +++ b/app/views/header.php @@ -1,12 +1,13 @@ +<?= $title ?> + -<?= $title ?> > -load_view('theme_header'); ?> \ No newline at end of file +load_view('theme_header', [], TRUE); ?> \ No newline at end of file diff --git a/app/views/message.php b/app/views/message.php old mode 100644 new mode 100755 diff --git a/app/views/theme_footer.php b/app/views/theme_footer.php old mode 100644 new mode 100755 index 3cc71a2..2ba76a2 --- a/app/views/theme_footer.php +++ b/app/views/theme_footer.php @@ -1,2 +1,7 @@
        -
        \ No newline at end of file +
        +
        Queries:
        + + +

        + \ No newline at end of file diff --git a/app/views/theme_header.php b/app/views/theme_header.php old mode 100644 new mode 100755 index a621046..15d1d37 --- a/app/views/theme_header.php +++ b/app/views/theme_header.php @@ -1,6 +1,6 @@

        Meta

        [Data Outline] \ No newline at end of file diff --git a/assets/config/css_groups.php b/assets/config/css_groups.php old mode 100644 new mode 100755 index 2113b50..78203ca --- a/assets/config/css_groups.php +++ b/assets/config/css_groups.php @@ -24,7 +24,8 @@ return array( 'normalize.css', 'message.css', 'theme.css', - 'tinyeditor.css' + 'tinyeditor.css', + 'prism.css' ) ); // End of css_groups.php \ No newline at end of file diff --git a/assets/config/js_groups.php b/assets/config/js_groups.php index 3928c8b..dba478b 100755 --- a/assets/config/js_groups.php +++ b/assets/config/js_groups.php @@ -27,6 +27,7 @@ return array( */ 'js' => array( + 'prism.js', 'kis-lite-dom.js', 'meta.js' ), diff --git a/assets/css/message.css b/assets/css/message.css old mode 100644 new mode 100755 diff --git a/assets/css/normalize.css b/assets/css/normalize.css old mode 100644 new mode 100755 diff --git a/assets/css/prism.css b/assets/css/prism.css new file mode 100755 index 0000000..d67726d --- /dev/null +++ b/assets/css/prism.css @@ -0,0 +1,127 @@ +/** + * prism.js default theme for JavaScript, CSS and HTML + * Based on dabblet (http://dabblet.com) + * @author Lea Verou + */ + +code[class*="language-"], +pre[class*="language-"], +.token { + color: black; + text-shadow: 0 1px white; + font-family: 'Anonymous Pro', Consolas, Monaco, 'Andale Mono', monospace; + direction: ltr; + text-align: left; + white-space: pre; + word-spacing: normal; + word-break: normal; + + + -moz-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; + + -webkit-hyphens: none; + -moz-hyphens: none; + -ms-hyphens: none; + hyphens: none; +} + +pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, +code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { + text-shadow: none; + background: #b3d4fc; +} + +pre[class*="language-"]::selection, pre[class*="language-"] ::selection, +code[class*="language-"]::selection, code[class*="language-"] ::selection { + text-shadow: none; + background: #b3d4fc; +} + +@media print { + code[class*="language-"], + pre[class*="language-"] { + text-shadow: none; + } +} + +/* Code blocks */ +pre[class*="language-"] { + padding: 1em; + margin: .5em 0; + overflow: auto; +} + +:not(pre) > code[class*="language-"], +pre[class*="language-"] { + background: #f5f2f0; +} + +/* Inline code */ +:not(pre) > code[class*="language-"] { + padding: .1em; + border-radius: .3em; +} + +.token.comment, +.token.prolog, +.token.doctype, +.token.cdata { + color: slategray; +} + +.token.punctuation { + color: #999; +} + +.namespace { + opacity: .7; +} + +.token.property, +.token.tag, +.token.boolean, +.token.number, +.token.constant, +.token.symbol { + color: #905; +} + +.token.selector, +.token.attr-name, +.token.string, +.token.builtin { + color: #690; +} + +.token.operator, +.token.entity, +.token.url, +.language-css .token.string, +.style .token.string, +.token.variable { + color: #a67f59; + background: hsla(0,0%,100%,.5); +} + +.token.atrule, +.token.attr-value, +.token.keyword { + color: #07a; +} + + +.token.regex, +.token.important { + color: #e90; +} + +.token.important { + font-weight: bold; +} + +.token.entity { + cursor: help; +} + diff --git a/assets/css/theme.css b/assets/css/theme.css old mode 100644 new mode 100755 index c95bdad..c77bf2c --- a/assets/css/theme.css +++ b/assets/css/theme.css @@ -217,7 +217,7 @@ dl.outline dd:last-child { list-style:square inside; } -.list li { +.list > li { list-style:none; } @@ -231,6 +231,10 @@ dl.multiline, dl.pair { border-bottom:1px dotted #312; } + li dl.multiline:last-of-type { + border-bottom:0; + } + dl.multiline dt { font-weight:bold; line-height:1.5; diff --git a/assets/js/kis-lite-dom.js b/assets/js/kis-lite-dom.js old mode 100755 new mode 100644 index 29205a1..662d7fa --- a/assets/js/kis-lite-dom.js +++ b/assets/js/kis-lite-dom.js @@ -2,24 +2,19 @@ Kis JS Keep It Simple JS Library Copyright Timothy J. Warren License Public Domain - Version 0.6.0 + Version 0.9.0 */ -(function (){ +(function (undefined){ "use strict"; - // Most functions rely on a string selector - // which returns html elements. This requires - // document.querySelectorAll or a custom - // selector engine. I choose to just use the - // browser feature, since it is present in - // IE 8+, and all other major browsers - if (typeof document.querySelector === "undefined") - { - return; - } - - var $_, $, dcopy, sel; + /** + * Current selector object + * + * @memberOf $_ + * @name el + */ + var sel = document.documentElement; /** @@ -27,31 +22,32 @@ * * Constructor function * - * @constuctor - * @namespace - * @param string selector - * @return object + * @constructor + * @namespace $_ + * @param {string} selector - The dom selector string + * @param {Object} [context] - Context of the dom selector string + * @return {Object} */ - $_ = function(s) + var $_ = function(s, context) { // Have documentElement be default selector, just in case - if (typeof s === "undefined") + if (s === undefined || s === null) { // Defines a "global" selector for that instance - sel = (typeof $_.el !== "undefined") + sel = ($_.el !== undefined && $_.el !== null) ? $_.el : document.documentElement; } else { - sel = (typeof s !== "object") ? $(s) : s; + sel = $(s, context); } // Add the selector to the prototype $_.prototype.el = sel; // Use the $_ object as it's own prototype - var self = dcopy($_); + var self = Object.create($_); // Give sel to each extension. for(var i in self) @@ -71,81 +67,43 @@ * Simple DOM selector function * * @memberOf $_ - * @param string selector - * @param object context - * @return object - * @type object + * @param {string} selector + * @param {Object} [context] + * @return {Object} */ - $ = function (a, context) + var $ = function (selector, context) { - var x, c; + var elements; - if (typeof a != "string" || typeof a === "undefined"){ return a;} + if (typeof selector != "string" || selector === undefined){ return selector;} //Check for a context of a specific element, otherwise, just run on the document - c = (context != null && context.nodeType === 1) + context = (context != null && context.nodeType === 1) ? context : document; //Pick the quickest method for each kind of selector - if (a.match(/^#([\w\-]+$)/)) + if (selector.match(/^#([\w\-]+$)/)) { - return document.getElementById(a.split('#')[1]); + return document.getElementById(selector.split('#')[1]); } else { - x = c.querySelectorAll(a); + elements = context.querySelectorAll(selector); } //Return the single object if applicable - return (x.length === 1) ? x[0] : x; - }; - - /** - * Deep copy/prototypical constructor function - * - * @param object obj - * @private - * @return object - * @type object - */ - dcopy = function(obj) - { - var type, F; - - if(typeof obj === "undefined") - { - return; - } - - if(typeof Object.create !== "undefined") - { - return Object.create(obj); - } - - type = typeof obj; - - if(type !== "object" && type !== "function") - { - return; - } - - /** - * @private - */ - F = function(){}; - - F.prototype = obj; - - return new F(); - + return (elements.length === 1) ? elements[0] : elements; }; /** * Adds the property `obj` to the $_ object, calling it `name` * - * @param string name - * @param object obj + * @memberOf $_ + * @function ext + * @example $_.ext('foo', {}); + * @param {string} name - name of the module + * @param {object} obj - the object to add */ $_.ext = function(name, obj) { @@ -156,35 +114,16 @@ /** * Iterates over a $_ object, applying a callback to each item * - * @name $_.each - * @function - * @param function callback + * @memberOf $_ + * @function each + * @example $_('form input').each(function(item) { alert(item) }); + * @param {function} callback - iteration callback */ - $_.ext('each', function (callback) + $_.ext('each', function(callback) { - if(typeof sel.length !== "undefined" && sel !== window) + if(sel.length !== undefined && sel !== window) { - // Use the native method, if it exists - if(typeof Array.prototype.forEach !== 'undefined') - { - [].forEach.call(sel, callback); - return; - } - - // Otherwise, fall back to a for loop - var len = sel.length; - - if (len === 0) - { - return; - } - - var selx; - for (var x = 0; x < len; x++) - { - selx = (sel.item(x)) ? sel.item(x) : sel[x]; - callback.call(selx, selx); - } + [].forEach.call(sel, callback); } else { @@ -195,11 +134,13 @@ /** * Retrieves the type of the passed variable * - * @param mixed obj - * @return string - * @type string + * @memberOf $_ + * @function type + * @example $_.type([]); // Returns 'array' + * @param {*} obj + * @return {string} */ - $_.type = function(obj) + var type = function(obj) { if((function() {return obj && (obj !== this)}).call(obj)) { @@ -214,60 +155,12 @@ //Set global variables $_ = window.$_ = window.$_ || $_; $_.$ = $; - + $_.type = type; }()); // -------------------------------------------------------------------------- -/** - * A module of various browser polyfills - * @file polyfill.js - */ -/** - * String trim function polyfill - */ -if(typeof String.prototype.trim === "undefined") -{ - /** - * @private - */ - String.prototype.trim = function() - { - return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, ""); - }; -} - -// -------------------------------------------------------------------------- - -/** - * event.preventDefault/e.stopPropagation polyfill - * @private - */ -if(typeof Event.preventDefault === "undefined" && typeof window.event !== "undefined") -{ - Event.prototype.preventDefault = function() - { - window.event.returnValue = false; - }, - Event.prototype.stopPropagation = function() - { - window.event.cancelBubble = true; - } -} - -// -------------------------------------------------------------------------- - -/** - * Array.isArray polyfill - */ -if (typeof Array.isArray === "undefined") -{ - Array.isArray = function(v) - { - return Object.prototype.toString.apply(v) === '[object Array]'; - } -} // -------------------------------------------------------------------------- @@ -276,23 +169,17 @@ if (typeof Array.isArray === "undefined") * * Module for making ajax requests */ -(function (){ +(function (undefined){ "use strict"; - // Don't bother even defining the object if the XMLHttpRequest isn't available - if(typeof window.XMLHttpRequest === "undefined") - { - return; - } - var ajax = { - _do: function (url, data, success_callback, error_callback, isPost) + _do: function (url, data, success_callback, error_callback, type) { var type, request = new XMLHttpRequest(); - if (typeof success_callback === "undefined") + if (success_callback === undefined) { /** * @private @@ -300,9 +187,12 @@ if (typeof Array.isArray === "undefined") success_callback = function (){}; } - type = (isPost) ? "POST" : "GET"; - - url += (type === "GET") ? "?" + this._serialize(data) : ''; + if (type === "GET") + { + url += (url.match(/\?/)) + ? this._serialize(data) + : "?" + this._serialize(data); + } request.open(type, url); @@ -316,7 +206,7 @@ if (typeof Array.isArray === "undefined") } else { - if (typeof error_callback !== 'undefined') + if (error_callback !== undefined) { error_callback.call(request.status, request.status); } @@ -325,7 +215,7 @@ if (typeof Array.isArray === "undefined") } }; - if (type === "POST") + if (type !== "GET") { request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.send(this._serialize(data)); @@ -335,6 +225,13 @@ if (typeof Array.isArray === "undefined") request.send(null); } }, + /** + * Url encoding for non-get requests + * + * @param data + * @returns {string} + * @private + */ _serialize: function (data) { var name, @@ -343,11 +240,7 @@ if (typeof Array.isArray === "undefined") for (name in data) { - if (!data.hasOwnProperty(name)) - { - continue; - } - if (typeof data[name] === "function") + if ( ! data.hasOwnProperty(name) || $_.type(data[name]) === "function") { continue; } @@ -367,60 +260,61 @@ if (typeof Array.isArray === "undefined") /** * Sends a GET type ajax request * - * @name get - * @function + * @function get * @memberOf $_ - * @param string url - * @param object data - * @param function success_callback - * @param function error_callback + * @param {string} url - The url to retrieve + * @param {Object} data - get parameters to send + * @param {function} success_callback - callback called on success + * @param {function} [error_callback] - callback called if there is an error */ $_.ext('get', function (url, data, success_callback, error_callback){ - ajax._do(url, data, success_callback, error_callback, false); + ajax._do(url, data, success_callback, error_callback, 'GET'); }); /** * Sends a POST type ajax request * - * @name post - * @function + * @function post * @memberOf $_ - * @param string url - * @param object data - * @param function success_callback - * @param function error_callback + * @param {string} url - The url to post to + * @param {Object} data - post parameters to send + * @param {function} success_callback - callback called on success + * @param {function} [error_callback] - callback called if there is an error */ $_.ext('post', function (url, data, success_callback, error_callback){ - ajax._do(url, data, success_callback, error_callback, true); + ajax._do(url, data, success_callback, error_callback, 'POST'); }); /** - * Watches for server-sent events and applies a callback on message + * Sends a PUT type ajax request * - * @name sse - * @function + * @function put * @memberOf $_ - * @param string url - * @param function callback + * @param {string} url - The url to post to + * @param {Object} data - PUT parameters to send + * @param {function} success_callback - callback called on success + * @param {function} [error_callback] - callback called if there is an error */ - $_.ext('sse', function(url, callback, poll_rate){ - - var source; - - // Check for server-sent event support - if (typeof EventSource !== 'undefined') - { - source = new EventSource(url); - - // Apply the callback - source.onmessage = function(event){ - callback.call(event.data, event.data); - }; - } + $_.ext('put', function (url, data, success_callback, error_callback){ + ajax._do(url, data, success_callback, error_callback, 'PUT'); }); + /** + * Sends a DELETE type ajax request + * + * @function delete + * @memberOf $_ + * @param {string} url - The url to post to + * @param {Object} data - delete parameters to send + * @param {function} success_callback - callback called on success + * @param {function} [error_callback] - callback called if there is an error + */ + $_.ext('delete', function (url, data, success_callback, error_callback){ + ajax._do(url, data, success_callback, error_callback, 'DELETE'); + }); }()); + // -------------------------------------------------------------------------- /** @@ -429,110 +323,16 @@ if (typeof Array.isArray === "undefined") * Event api wrapper * @todo Add method for triggering events */ -(function (){ +(function (undefined){ "use strict"; - // Property name for expandos on DOM objects - var kis_expando = "KIS_0_6_0"; - - var _attach, _remove, _add_remove, e, _attach_delegate; - - // Define the proper _attach and _remove functions - // based on browser support - if(typeof document.addEventListener !== "undefined") - { - /** - * @private - */ - _attach = function (sel, event, callback) - { - if(typeof sel.addEventListener !== "undefined") - { - // Duplicated events are dropped, per the specification - sel.addEventListener(event, callback, false); - } - }; - /** - * @private - */ - _remove = function (sel, event, callback) - { - if(typeof sel.removeEventListener !== "undefined") - { - sel.removeEventListener(event, callback, false); - } - }; - } - // typeof function doesn't work in IE where attachEvent is available: brute force it - else if(typeof document.attachEvent !== "undefined") - { - /** - * @private - */ - _attach = function (sel, event, callback) - { - function _listener () { - // Internet Explorer fails to correctly set the 'this' object - // for event listeners, so we need to set it ourselves. - callback.apply(arguments[0]); - } - - if (typeof sel.attachEvent !== "undefined") - { - _remove(event, callback); // Make sure we don't have duplicate listeners - - sel.attachEvent("on" + event, _listener); - // Store our listener so we can remove it later - var expando = sel[kis_expando] = sel[kis_expando] || {}; - expando.listeners = expando.listeners || {}; - expando.listeners[event] = expando.listeners[event] || []; - expando.listeners[event].push({ - callback: callback, - _listener: _listener - }); - } - }; - /** - * @private - */ - _remove = function (sel, event, callback) - { - if(typeof sel.detachEvent !== "undefined") - { - var expando = sel[kis_expando]; - if (expando && expando.listeners - && expando.listeners[event]) - { - var listeners = expando.listeners[event]; - var len = listeners.length; - for (var i=0; i 1 && typeof value === "undefined") + if (sel.length > 1 && value === undefined) { return null; } - else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though + else if (sel.length > 1 && value !== undefined) //You can set a bunch, though { $_.each(function (e){ return _attr(e, name, value); @@ -1087,29 +691,22 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" * @name text * @memberOf $_.dom * @function - * @param [string] value - * @return string - * @type string + * @param {?string} [value] + * @return {?string} */ text: function (value) { - var oldValue, set, type, sel; + var oldValue, set, sel; sel = this.el; - set = (typeof value !== "undefined") ? true : false; + set = (value !== undefined) ? true : false; - type = (typeof sel.textContent !== "undefined") - ? "textContent" - : (typeof sel.innerText !== "undefined") - ? "innerText" - : "innerHTML"; - - oldValue = sel[type]; + oldValue = sel.textContent; if(set) { - sel[type] = value; + sel.textContent = value; return value; } else @@ -1122,20 +719,35 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" * specified by the current selector. If a value is * passed, it will set that value on the current element, * otherwise it will return the value of the css property - * on the current element + * on the current element. * + * Accepts either key/value arguments, or an object with + * multiple key/value pairs. + * + * @example $_('#foo').dom.css('border', 0); + * @example $_('#foo').dom.css({background:'#000', color:'#fff'}); * @name css * @memberOf $_.dom * @function - * @param string property - * @param [string] value - * @return string - * @type string + * @param {(string|Object)} property + * @param {?string} [value] + * @return {?string} */ css: function (prop, val) { + var prop_key = null; + + // If passed an object, recurse! + if($_.type(prop) === 'object') + { + Object.keys(prop).forEach(function(prop_key) { + $_.each(function (e){ + _css(e, prop_key, prop[prop_key]); + }); + }); + } //Return the current value if a value is not set - if(typeof val === "undefined") + else if(val === undefined && $_.type(prop) !== 'object') { return _css(this.el, prop); } @@ -1147,41 +759,28 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" /** * Adds to the innerHTML of the current element, after the last child. * - * @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element + * @example $_("ul").dom.append("
      • "); // Adds an li element to the end of the selected ul element * @name append * @memberOf $_.dom * @function - * @param string htm + * @param {string} htm */ append: function(htm) { - if(typeof document.insertAdjacentHTML !== "undefined") - { - this.el.insertAdjacentHTML('beforeend', htm); - } - else - { - this.el.innerHTML += htm; - } + this.el.insertAdjacentHTML('beforeend', htm); }, /** * Adds to the innerHTML of the selected element, before the current children * + * @example $_("ul").dom.append("
      • "); // Adds an li element to the beginning of the selected ul element * @name prepend * @memberOf $_.dom * @function - * @param string htm + * @param {string} htm */ prepend: function(htm) { - if(typeof document.insertAdjacentHTML !== "undefined") - { - this.el.insertAdjacentHTML('afterbegin', htm); - } - else - { - this.el.innerHTML = htm + this.el.innerHTML; - } + this.el.insertAdjacentHTML('afterbegin', htm); }, /** * Sets or gets the innerHTML propery of the element(s) passed @@ -1189,14 +788,13 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" * @name html * @memberOf $_.dom * @function - * @param [string] htm - * @return string - * @type string + * @param {?string} [htm] + * @return {?string} */ html: function(htm) { - if(typeof htm !== "undefined") + if(htm !== undefined) { this.el.innerHTML = htm; } @@ -1208,4 +806,4 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" $_.ext('dom', d); -}()); \ No newline at end of file +}()); diff --git a/assets/js/meta.js b/assets/js/meta.js old mode 100644 new mode 100755 index e8b1c48..2aeef71 --- a/assets/js/meta.js +++ b/assets/js/meta.js @@ -27,39 +27,71 @@ $_.ext('center', function (sel){ sel.style.left = left + "px"; }); -(function() { +(function(w, $_) { - "use strict"; + "use strict"; - var TINY = window.TINY || {}; - var $_ = window.$_ || {}; + var TINY = w.TINY || {}; + var $_ = w.$_ || {}; + + var parent_map = { + "data":"section", + "section":"category", + "category":"genre", + "genre":"genre" + }; // ! Show/hide forms based on use $_("fieldset dl").dom.hide(); $_("fieldset legend").event.add('click', function(e){ - var form = $_("fieldset dl").dom; - - (form.css('display').trim() == 'none') - ? form.show() - : form.hide(); + ($_("fieldset dl").dom.css('display').trim() == 'none') + ? $_("fieldset dl").dom.show() + : $_("fieldset dl").dom.hide(); }); var meta = {}; - window.meta = meta; + w.meta = meta; + + /** + * Create the WYSIWYG editor box + */ + meta.initTINY = function(id) { + // WYSIWYG + new TINY.editor.edit('edit_wysiwyg', + { + id:id, + width:450, + height:175, + cssclass:'te', + controlclass:'tecontrol', + rowclass:'teheader', + dividerclass:'tedivider', + controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|', + 'orderedlist','unorderedlist','|','leftalign', + 'centeralign','rightalign','blockjustify','|','unformat','n','undo','redo','|', + 'image','hr','link','unlink','|'], + footer:true, + fonts:['Verdana','Arial','Georgia','Trebuchet MS'], + xhtml:true, + cssfile:ASSET_URL+'css.php/g/css', + bodyid:'editor', + footerclass:'tefooter', + toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'}, + resize:{cssclass:'resize'} + }); + }, /** * Deletes a genre/category/section/data item * based on the current page context */ meta.delete_item = function(e) { - var item_id, id, type; + var id, type, parent_id; // Get the type/id of the item - item_id = this.parentNode.id; - item_id = item_id.split('_'); - - id = item_id[1]; - type = item_id[0]; + id = this.parentNode.dataset['id']; + type = this.parentNode.dataset.type; + parent_id = this.parentNode.dataset.parent; // Confirm deletion var confirm_string = "Are you sure you want to delete this "+type+"? Deleting this item will delete all items under it. There is no undo."; @@ -70,34 +102,25 @@ $_.ext('center', function (sel){ if (do_delete) { - // Call the appropriate deletion method - switch(type) - { - case "genre": - case "category": - case "section": - case "data": - $_.post(APP_URL+'delete', {'id':id, 'type':type}, function(res){ - if (res == 1) - { - // Reload the page - window.location = window.location; - } - else - { - $_.get(APP_URL+'message', { - type: 'error', - message: 'There was an error deleting that item' - }, function(h) { - $_('body').dom.prepend(h); - }); - } + $_.post(APP_URL+'delete', {'id':id, 'type':type}, function(res){ + if (res == 1) + { + // Redirect to previous page + var redir_url = APP_URL+parent_map[type]+'/detail/'+parent_id; + w.location = (type !== 'genre') + ? redir_url + : APP_URL; + } + else + { + $_.get(APP_URL+'message', { + type: 'error', + message: 'There was an error deleting that item' + }, function(h) { + $_('body').dom.prepend(h); }); - break; - - default: - break; - } + } + }); } }; @@ -106,14 +129,10 @@ $_.ext('center', function (sel){ * being edited */ meta.get_edit_form = function(e) { - var item_id, id, type; + var id, type; - // Get the type/id of the item - item_id = this.parentNode.id; - item_id = item_id.split('_'); - - id = item_id[1]; - type = item_id[0]; + id = this.parentNode.dataset['id']; + type = this.parentNode.dataset.type; $_('#overlay_bg, #overlay').dom.show(); @@ -126,29 +145,7 @@ $_.ext('center', function (sel){ if (type == 'data') { - // WYSIWYG - new TINY.editor.edit('edit_wysiwyg', - { - id:'val', - width:450, - height:175, - cssclass:'te', - controlclass:'tecontrol', - rowclass:'teheader', - dividerclass:'tedivider', - controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|', - 'orderedlist','unorderedlist','|','leftalign', - 'centeralign','rightalign','blockjustify','|','unformat','n','undo','redo','|', - 'image','hr','link','unlink','|'], - footer:true, - fonts:['Verdana','Arial','Georgia','Trebuchet MS'], - xhtml:true, - cssfile:ASSET_URL+'css.php/g/css', - bodyid:'editor', - footerclass:'tefooter', - toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'}, - resize:{cssclass:'resize'} - }); + meta.initTINY('val'); //Do it again, so it's correct this time! $_('#overlay').center(); @@ -190,7 +187,7 @@ $_.ext('center', function (sel){ if (res == 1) { // Reload the page - window.location = window.location; + w.location = w.location; } else { @@ -217,12 +214,17 @@ $_.ext('center', function (sel){ // Overlay close $_("#overlay_bg").event.add('click', function(e) { - $_('#overlay_bg').dom.css('display', ''); + $_('#overlay_bg').dom.css('display', 'none'); $_('#overlay').dom.html(''); $_('#overlay').dom.hide(); }); // Edit form submission $_.event.live('#edit_form', 'submit', meta.update_item); - -}()); \ No newline at end of file + + // WYSIWYG on section/data pages + if (document.getElementById('textarea') != null) + { + meta.initTINY('textarea'); + } +}(window, $_)); \ No newline at end of file diff --git a/assets/js/prism.js b/assets/js/prism.js new file mode 100755 index 0000000..1968f7f --- /dev/null +++ b/assets/js/prism.js @@ -0,0 +1,12 @@ +/** + * Prism: Lightweight, robust, elegant syntax highlighting + * MIT license http://www.opensource.org/licenses/mit-license.php/ + * @author Lea Verou http://lea.verou.me + */(function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,s;s=r[i++];)t.highlightElement(s,e===!0,n)},highlightElement:function(r,i,s){var o,u,a=r;while(a&&!e.test(a.className))a=a.parentNode;if(a){o=(a.className.match(e)||[,""])[1];u=t.languages[o]}if(!u)return;r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+o;a=r.parentNode;/pre/i.test(a.nodeName)&&(a.className=a.className.replace(e,"").replace(/\s+/g," ")+" language-"+o);var f=r.textContent;if(!f)return;f=f.replace(/&/g,"&").replace(/e.length)break e;if(p instanceof i)continue;a.lastIndex=0;var d=a.exec(p);if(d){l&&(c=d[1].length);var v=d.index-1+c,d=d[0].slice(c),m=d.length,g=v+m,y=p.slice(0,v+1),b=p.slice(g+1),w=[h,1];y&&w.push(y);var E=new i(u,f?t.tokenize(d,f):d);w.push(E);b&&w.push(b);Array.prototype.splice.apply(s,w)}}}return s},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[];r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(!r||!r.length)return;for(var i=0,s;s=r[i++];)s(n)}}},n=t.Token=function(e,t){this.type=e;this.content=t};n.stringify=function(e,r,i){if(typeof e=="string")return e;if(Object.prototype.toString.call(e)=="[object Array]")return e.map(function(t){return n.stringify(t,r,e)}).join("");var s={type:e.type,content:n.stringify(e.content,r,i),tag:"span",classes:["token",e.type],attributes:{},language:r,parent:i};s.type=="comment"&&(s.attributes.spellcheck="true");t.hooks.run("wrap",s);var o="";for(var u in s.attributes)o+=u+'="'+(s.attributes[u]||"")+'"';return"<"+s.tag+' class="'+s.classes.join(" ")+'" '+o+">"+s.content+""};if(!self.document){self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,i=n.code;self.postMessage(JSON.stringify(t.tokenize(i,t.languages[r])));self.close()},!1);return}var r=document.getElementsByTagName("script");r=r[r.length-1];if(r){t.filename=r.src;document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)}})();; +Prism.languages.markup={comment:/<!--[\w\W]*?-->/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]*?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*\/?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(e){e.type==="entity"&&(e.attributes.title=e.content.replace(/&/,"&"))});; +Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*{))/gi,inside:{punctuation:/[;:]/g}},url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\};]*(?=\s*\{)/g,property:/(\b|\B)[\w-]+(?=\s*:)/ig,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/ig,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});; +Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/ig,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,"function":{pattern:/[a-z0-9_]+\(/ig,inside:{punctuation:/\(/}}, number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,operator:/[-+]{1,2}|!|<=?|>=?|={1,3}|(&){1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g}; +; +Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|throw|catch|finally|null|break|continue)\b/g,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g});Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,lookbehind:!0}});Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/(<|<)script[\w\W]*?(>|>)[\w\W]*?(<|<)\/script(>|>)/ig,inside:{tag:{pattern:/(<|<)script[\w\W]*?(>|>)|(<|<)\/script(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}}); +; +Prism.languages.sql={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|((--)|(\/\/)).*?(\r?\n|$))/g,lookbehind:!0},string: /("|')(\\?.)*?\1/g,keyword:/\b(ACTION|ADD|AFTER|ALGORITHM|ALTER|ANALYZE|APPLY|AS|AS|ASC|AUTHORIZATION|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADE|CASCADED|CASE|CHAIN|CHAR VARYING|CHARACTER VARYING|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLUMN|COLUMNS|COMMENT|COMMIT|COMMITTED|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATA|DATABASE|DATABASES|DATETIME|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DOUBLE PRECISION|DROP|DUMMY|DUMP|DUMPFILE|DUPLICATE KEY|ELSE|ENABLE|ENCLOSED BY|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPE|ESCAPED BY|EXCEPT|EXEC|EXECUTE|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR|FOR EACH ROW|FORCE|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GEOMETRY|GEOMETRYCOLLECTION|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|IDENTITY|IDENTITY_INSERT|IDENTITYCOL|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTO|INVOKER|ISOLATION LEVEL|JOIN|KEY|KEYS|KILL|LANGUAGE SQL|LAST|LEFT|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONGBLOB|LONGTEXT|MATCH|MATCHED|MEDIUMBLOB|MEDIUMINT|MEDIUMTEXT|MERGE|MIDDLEINT|MODIFIES SQL DATA|MODIFY|MULTILINESTRING|MULTIPOINT|MULTIPOLYGON|NATIONAL|NATIONAL CHAR VARYING|NATIONAL CHARACTER|NATIONAL CHARACTER VARYING|NATIONAL VARCHAR|NATURAL|NCHAR|NCHAR VARCHAR|NEXT|NO|NO SQL|NOCHECK|NOCYCLE|NONCLUSTERED|NULLIF|NUMERIC|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPTIMIZE|OPTION|OPTIONALLY|ORDER|OUT|OUTER|OUTFILE|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREV|PRIMARY|PRINT|PRIVILEGES|PROC|PROCEDURE|PUBLIC|PURGE|QUICK|RAISERROR|READ|READS SQL DATA|READTEXT|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEATABLE|REPLICATION|REQUIRE|RESTORE|RESTRICT|RETURN|RETURNS|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROWCOUNT|ROWGUIDCOL|ROWS?|RTREE|RULE|SAVE|SAVEPOINT|SCHEMA|SELECT|SERIAL|SERIALIZABLE|SESSION|SESSION_USER|SET|SETUSER|SHARE MODE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|START|STARTING BY|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLE|TABLES|TABLESPACE|TEMPORARY|TEMPTABLE|TERMINATED BY|TEXT|TEXTSIZE|THEN|TIMESTAMP|TINYBLOB|TINYINT|TINYTEXT|TO|TOP|TRAN|TRANSACTION|TRANSACTIONS|TRIGGER|TRUNCATE|TSEQUAL|TYPE|TYPES|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNPIVOT|UPDATE|UPDATETEXT|USAGE|USE|USER|USING|VALUE|VALUES|VARBINARY|VARCHAR|VARCHARACTER|VARYING|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH|WITH ROLLUP|WITHIN|WORK|WRITE|WRITETEXT)\b/gi,boolean:/\b(TRUE|FALSE|NULL)\b/gi,number:/\b-?(0x)?\d*\.?[\da-f]+\b/g,operator:/\b(ALL|AND|ANY|BETWEEN|EXISTS|IN|LIKE|NOT|OR|IS|UNIQUE|CHARACTER SET|COLLATE|DIV|OFFSET|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b|[-+]{1}|!|=?<|=?>|={1}|(&){1,2}|\|?\||\?|\*|\//gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[;[\]()`,.]/g};; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0e0233d --- /dev/null +++ b/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "aura/router": "2.0.*@dev" + } +} \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ef91b772a26ac861a667cffce4af593c5263547d GIT binary patch literal 1150 zcmeH`F$w}P6hxn3BQ}eLpp~Up@J3$2ai6YZ z_t)2d)hAD^%*^hUw0yBLy0mH~?mFLR{Jc- . - tests - assets - app/config - app/views - sys/db + app/modules/ tests/* assets/* + vendor/* sys/db/* app/config/* app/views/* diff --git a/sys/common.php b/sys/common.php old mode 100644 new mode 100755 index 4f4f412..97b6598 --- a/sys/common.php +++ b/sys/common.php @@ -21,6 +21,7 @@ */ namespace miniMVC; +use \Aura\Router\RouterFactory; // -------------------------------------------------------------------------- // ! Autoloading @@ -59,9 +60,6 @@ function autoload($name) } } -// Start the autoloader -spl_autoload_register('miniMVC\autoload'); - // -------------------------------------------------------------------------- // ! Error handling / messages // -------------------------------------------------------------------------- @@ -362,107 +360,50 @@ function get_segments() */ function route() { + $router_factory = new RouterFactory; + $router = $router_factory->newInstance(); - // Get the path info - $pi = $_SERVER['PATH_INFO']; - $ru = $_SERVER['REQUEST_URI']; - $sn = $_SERVER['SCRIPT_NAME']; - $qs = $_SERVER['QUERY_STRING']; + // Load the routes config file to add additional routes + $routes = []; + require_once(MM_APP_PATH . 'config/routes.php'); - // Make sure the home page works when in a sub_directory - if (strlen($sn) > strlen($ru)) - { - $pi = '/'; - } + // get the incoming request URL path + $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); - // Load the routes config file - $routes = require_once(MM_APP_PATH . 'config/routes.php'); + // get the route based on the path and server + $route = $router->match($path, $_SERVER); - // Set the default route - $module = $routes['default_module']; + // Set default controller/function $controller = $routes['default_controller']; - $func = "index"; - $route_set = FALSE; + $action = 'index'; - // If it isn't the index page - if ( ! empty($pi) && $pi !== "/") + // 404 Condition + if (empty($route)) { - //Remove trailing slash and begining slash - $pi = trim($pi, '/'); - $segments = explode("/", $pi); + show_404(); + return; + } - // URL matches the route exactly? Cool, that was easy - if (isset($routes[$pi])) + // Home + if (isset($route->name) && $route->name === 'home') + { + run($controller, $action); + return; + } + + // Gather route parts + foreach(array('controller', 'action', 'id') as $param) + { + if (isset($route->params[$param])) { - list($module, $controller, $func) = explode("/", $routes[$pi]); - run($module, $controller, $func); - return; - } - else - { - $custom_routes = $routes; - - // Skip required routes - unset($custom_routes['default_module']); - unset($custom_routes['default_controller']); - unset($custom_routes['404_handler']); - - foreach($custom_routes as $uri => $map) - { - if (preg_match("`{$uri}`i", $pi)) - { - list($module, $controller, $func) = explode("/", $map); - run($module, $controller, $func); - return; - } - } - } - - // Doesn't match a predefined route? - // Match on module/controller/method, module/controller, controller/method, or method - if ( ! $route_set) - { - $num_segments = 0; - - if (strpos($pi, '/') === FALSE && ! empty($pi)) - { - $num_segments = 1; - } - else - { - $segments = explode('/', $pi); - $num_segments = count($segments); - } - - // Determine route based on uri segments - if ($num_segments === 1) - { - $func = $pi; - } - elseif ($num_segments === 2) - { - - list($module, $controller) = $segments; - - // If it's just controller/function - if ($controller == 'index') - { - $controller = $module; - $module = $routes['default_module']; - $func = 'index'; - } - - } - else - { - list($module, $controller, $func) = $segments; - } + $$param = $route->params[$param]; } } - run($module, $controller, $func); + if ( ! isset($id)) $id = array(); - return; + // Dispatch to the appropriate controller + run($controller, $action, array($id)); } // -------------------------------------------------------------------------- @@ -470,14 +411,14 @@ function route() /** * Instantiate the appropriate controller * - * @param string - * @param string - * @param string - * @param array + * @param string $controller + * @param string $func + * @param array $args + * @return void */ -function run($module, $controller, $func, $args = array()) +function run($controller, $func, $args = array()) { - $path = MM_MOD_PATH . "{$module}/controllers/{$controller}.php"; + $path = MM_MOD_PATH . "meta/controllers/{$controller}.php"; if (is_file($path)) { @@ -492,7 +433,7 @@ function run($module, $controller, $func, $args = array()) // Define the name of the current module for file loading if ( ! defined('MM_MOD')) { - define('MM_MOD', $module); + define('MM_MOD', 'meta'); } if (class_exists($controller)) @@ -500,11 +441,9 @@ function run($module, $controller, $func, $args = array()) $class = new $controller(); } - //show_error(to_string(get_declared_classes())); - return call_user_func_array(array($class, $func), $args); + call_user_func_array(array($class, $func), $args); + return; } - - show_404(); } // Function doesn't exist...404 diff --git a/sys/core/Controller.php b/sys/core/Controller.php old mode 100644 new mode 100755 index bcae718..1d77fcb --- a/sys/core/Controller.php +++ b/sys/core/Controller.php @@ -92,6 +92,21 @@ class Controller { { return $this->page->load_view($file, $data, $return); } + + // -------------------------------------------------------------------------- + + /** + * Automate loading of header and footer + * + * @param string $file + * @param array $data + * @param bool $return + * @return mixed + */ + public function render($file, array $data=array(), $return=FALSE) + { + return $this->page->render($file, $data, $return); + } } // End of controller.php \ No newline at end of file diff --git a/sys/core/Model.php b/sys/core/Model.php old mode 100644 new mode 100755 diff --git a/sys/core/Page.php b/sys/core/Page.php old mode 100644 new mode 100755 index bc1c287..a3eec42 --- a/sys/core/Page.php +++ b/sys/core/Page.php @@ -166,12 +166,6 @@ class Page { { ob_end_flush(); } - - - } - else - { - echo 'No content'; } } @@ -452,7 +446,7 @@ class Page { $this->_headers($html5); //Output Header - $this->load_view('header', $data); + $this->append_output($this->load_view('header', $data, TRUE)); return $this; } @@ -468,7 +462,7 @@ class Page { $data['foot_js'] = ($this->foot_js != "") ? $this->foot_js : ''; - $this->load_view('footer', $data); + $this->append_output($this->load_view('footer', $data, TRUE)); } // -------------------------------------------------------------------------- @@ -543,6 +537,7 @@ class Page { { $this->build_header(); $this->load_view($view, $data); + $this->set_foot_js_group('js'); $this->build_footer(); } diff --git a/sys/core/db.php b/sys/core/db.php old mode 100644 new mode 100755 index 7cc281a..aeff8e9 --- a/sys/core/db.php +++ b/sys/core/db.php @@ -21,7 +21,7 @@ namespace miniMVC; * @package miniMVC * @subpackage System */ -class db extends \Query_Builder { +class db extends \Query\Query_Builder { /** * DB connection instances @@ -56,7 +56,7 @@ class db extends \Query_Builder { } //echo 'Creating new instance of db class.'; - self::$instance[$dbname] = new DB($db_conf[$dbname]); + self::$instance[$dbname] = Query($db_conf[$dbname]); } return self::$instance[$dbname]; @@ -81,10 +81,8 @@ class db extends \Query_Builder { { $error = $this->errorInfo(); } - - $code = $error[0]; - $driver_code = $error[1]; - $message = $error[2]; + + list($code, $driver_code, $message) = $error; // Contain the content for buffering ob_start(); diff --git a/sys/db b/sys/db deleted file mode 160000 index 2731850..0000000 --- a/sys/db +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 27318506d05a1ce0d7e7c8b891a23ab558b512a5 diff --git a/sys/db b/sys/db new file mode 120000 index 0000000..945333d --- /dev/null +++ b/sys/db @@ -0,0 +1 @@ +/var/www/htdocs/dev.timshomepage.net/github/Query/ \ No newline at end of file diff --git a/sys/libraries/Bcrypt.php b/sys/libraries/Bcrypt.php deleted file mode 100644 index db87d0e..0000000 --- a/sys/libraries/Bcrypt.php +++ /dev/null @@ -1,201 +0,0 @@ -rounds = $rounds; - } - - // -------------------------------------------------------------------------- - - /** - * Returns a has for the input string - * - * @param string - * @return string - */ - public function hash($input) - { - $hash = crypt($input, $this->getSalt()); - - if (strlen($hash) > 13) - return $hash; - - return false; - } - - // -------------------------------------------------------------------------- - - /** - * Check if a password hash is valid - * - * @param string - * @param string - * @return bool - */ - public function verify($input, $existingHash) - { - $hash = crypt($input, $existingHash); - - return $hash === $existingHash; - } - - // -------------------------------------------------------------------------- - - /** - * Private function to generate the random salt - * - * @return string - */ - private function getSalt() - { - $salt = sprintf('$2a$%02d$', $this->rounds); - - $bytes = $this->getRandomBytes(16); - - $salt .= $this->encodeBytes($bytes); - - return $salt; - } - - // -------------------------------------------------------------------------- - - /** - * Private method to generate random characters for salt - * - * @param int - * @return string - */ - private function getRandomBytes($count) - { - $bytes = ''; - - if (function_exists('openssl_random_pseudo_bytes') && (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) // OpenSSL slow on Win - { - $bytes = openssl_random_pseudo_bytes($count); - } - - if ($bytes === '' && is_readable('/dev/urandom') && ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) - { - $bytes = fread($hRand, $count); - fclose($hRand); - } - - if (strlen($bytes) < $count) - { - $bytes = ''; - - if ($this->randomState === null) - { - $this->randomState = microtime(); - if (function_exists('getmypid')) - { - $this->randomState .= getmypid(); - } - } - - for ($i = 0; $i < $count; $i += 16) - { - $this->randomState = md5(microtime() . $this->randomState); - - if (PHP_VERSION >= '5') - { - $bytes .= md5($this->randomState, true); - } - else - { - $bytes .= pack('H*', md5($this->randomState)); - } - } - - $bytes = substr($bytes, 0, $count); - } - - return $bytes; - } - - // -------------------------------------------------------------------------- - - /** - * Further randomizes salt? - * - * @param string - * @return string - */ - private function encodeBytes($input) - { - // The following is code from the PHP Password Hashing Framework - $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - - $output = ''; - $i = 0; - do - { - $c1 = ord($input[$i++]); - $output .= $itoa64[$c1 >> 2]; - $c1 = ($c1 & 0x03) << 4; - if ($i >= 16) - { - $output .= $itoa64[$c1]; - break; - } - - $c2 = ord($input[$i++]); - $c1 |= $c2 >> 4; - $output .= $itoa64[$c1]; - $c1 = ($c2 & 0x0f) << 2; - - $c2 = ord($input[$i++]); - $c1 |= $c2 >> 6; - $output .= $itoa64[$c1]; - $output .= $itoa64[$c2 & 0x3f]; - } while (1); - - return $output; - } -} \ No newline at end of file diff --git a/sys/libraries/Data_Store.php b/sys/libraries/Data_Store.php deleted file mode 100644 index d873e80..0000000 --- a/sys/libraries/Data_Store.php +++ /dev/null @@ -1,153 +0,0 @@ -value data store - * - * @package miniMVC - * @subpackage Libraries - */ -class Data_Store { - - /** - * Settings object represented by the currently loaded JSON file - */ - private $current; - - /** - * Singleton instance - */ - private static $instance; - - /** - * Create and/or load json file - */ - protected function __construct() - { - $path = MM_APP_PATH .'config/data_store.json'; - - if ( ! is_file($path)) - { - touch($path); - $this->current = (object)[]; - } - else - { - // Load the file - $json = file_get_contents($path); - - // Load the object into the class - $this->current = json_decode($json); - } - } - - // -------------------------------------------------------------------------- - - /** - * Output the data on destruct - */ - public function __destruct() - { - $file_string = json_encode($this->current, JSON_PRETTY_PRINT); - - file_put_contents(MM_APP_PATH . 'config/data_store.json', $file_string); - } - - // -------------------------------------------------------------------------- - - /** - * Magic function called when cloning an object - */ - public function __clone() - { - trigger_error('Clone is not allowed.', E_USER_ERROR); - } - - // -------------------------------------------------------------------------- - - /** - * Magic method to simplify isset checking for config options - * - * @param string $key - * @return mixed - */ - public function __get($key) - { - return (isset($this->current->{$key})) - ? $this->current->{$key} - : NULL; - } - - // -------------------------------------------------------------------------- - - /** - * Magic method to simplify setting config options - * - * @param string $key - * @param mixed - */ - public function __set($key, $val) - { - return $this->current->{$key} = $val; - } - - // -------------------------------------------------------------------------- - - /** - * Static method to retreive current instance - * of the singleton - * - * @return self - */ - public static function &get_instance() - { - if( ! isset(self::$instance)) - { - $name = __CLASS__; - self::$instance = new $name(); - } - - return self::$instance; - } - - // -------------------------------------------------------------------------- - - /** - * Removes a key from the data store - * - * @param string $key - * @return void - */ - public function del($key) - { - unset($this->current->{$key}); - } - - // -------------------------------------------------------------------------- - - /** - * Return the entire data store object - * - * @return object - */ - public function get_all() - { - return $this->current; - } -} - -// End of data store.php \ No newline at end of file diff --git a/sys/libraries/Session.php b/sys/libraries/Session.php deleted file mode 100644 index 8210e5a..0000000 --- a/sys/libraries/Session.php +++ /dev/null @@ -1,124 +0,0 @@ -sess =& $_SESSION[$session_id]; - } - - // -------------------------------------------------------------------------- - - /** - * Set a session value - * - * @param string $key - * @param mixed $val - * @return void - */ - public function __set($key, $val) - { - $this->sess[$key] = $val; - } - - // -------------------------------------------------------------------------- - - /** - * Retreive a session value - * - * @param string $key - * @return mixed - */ - public function __get($key) - { - return $this->sess[$key]; - } - - // -------------------------------------------------------------------------- - - /** - * Destroy a session - * - * @return void - */ - public function destroy() - { - sess_destroy(); - } - - // -------------------------------------------------------------------------- - - /** - * Singleton getter function - * - * @return self - */ - public static function &get_instance() - { - if ( ! isset(self::$instance)) - { - $class = __CLASS__; - - self::$instance = new $class; - } - - return self::$instance; - } - - // -------------------------------------------------------------------------- - - /** - * Magic function called when cloning an object - */ - public function __clone() - { - trigger_error('Clone is not allowed.', E_USER_ERROR); - } -} - -// End of session.php \ No newline at end of file