Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
The begining of installable modules #36
Browse files Browse the repository at this point in the history
Allow modules access to manipulate the cp menu.
Modules must now first be installed and activated before use.
Added a basic CRUD core model.
Add better error detection for error thrown by admin menu helper.
Added initial core modules.
  • Loading branch information
cosmomathieu committed Aug 27, 2016
1 parent bb3f748 commit 5567e3a
Show file tree
Hide file tree
Showing 15 changed files with 1,724 additions and 134 deletions.
2 changes: 1 addition & 1 deletion application/config/autoload.php
Expand Up @@ -64,7 +64,7 @@
| $autoload['helper'] = array('url', 'file');
*/

$autoload['helper'] = array('url', 'custom_functions', 'form', 'ssl', 'content/content', 'navigations/navigations');
$autoload['helper'] = array('url', 'custom_functions', 'form', 'ssl', 'content/content', 'navigations/navigations', 'addons/addons');


/*
Expand Down
40 changes: 25 additions & 15 deletions application/config/constants.php
Expand Up @@ -44,7 +44,7 @@
| Defines the version number for cms canvas
|
*/
define('CC_VERSION', '1.2.0');
define('CC_VERSION', '1.3.0');

/*
|--------------------------------------------------------------------------
Expand All @@ -64,6 +64,14 @@
*/
define('ADMIN_PATH', 'sitemin');

/*
|--------------------------------------------------------------------------
| System Path
|--------------------------------------------------------------------------
|
*/
define('SYSTEM_PATH', CMS_ROOT . 'system/');

/*
|--------------------------------------------------------------------------
| Theme Path
Expand Down Expand Up @@ -277,20 +285,22 @@
|
*/
$admin_access_options = array(
ADMIN_PATH . '/content/entries' => 'Content / Entries',
ADMIN_PATH . '/calendar' => 'Calendar',
ADMIN_PATH . '/calendar/entries' => 'Calendar / Entries',
ADMIN_PATH . '/navigations' => 'Content / Navigations',
ADMIN_PATH . '/galleries' => 'Content / Galleries',
ADMIN_PATH . '/users' => 'Users',
ADMIN_PATH . '/users/groups' => 'User Groups',
ADMIN_PATH . '/content/types' => 'Tools / Content Types',
ADMIN_PATH . '/content/snippets' => 'Tools / Code Snippets',
ADMIN_PATH . '/categories' => 'Tools / Categories',
ADMIN_PATH . '/settings/theme-editor' => 'Tools / Theme Editor',
ADMIN_PATH . '/settings/general-settings' => 'General Settings',
ADMIN_PATH . '/settings/clear-cache' => 'Settings / Clear Cache',
ADMIN_PATH . '/settings/server-info' => 'Settings / Server Info',
ADMIN_PATH . '/addons/admin-modules' => 'Addons / Modules',
ADMIN_PATH . '/addons/admin-plugins' => 'Addons / Plugins',
ADMIN_PATH . '/content/entries' => 'Content / Entries',
ADMIN_PATH . '/calendar' => 'Calendar',
ADMIN_PATH . '/calendar/entries' => 'Calendar / Entries',
ADMIN_PATH . '/galleries' => 'Content / Galleries',
ADMIN_PATH . '/navigations' => 'Content / Navigations',
ADMIN_PATH . '/categories' => 'Tools / Categories',
ADMIN_PATH . '/content/snippets' => 'Tools / Code Snippets',
ADMIN_PATH . '/content/types' => 'Tools / Content Types',
ADMIN_PATH . '/settings/theme-editor' => 'Tools / Theme Editor',
ADMIN_PATH . '/settings/clear-cache' => 'Settings / Clear Cache',
ADMIN_PATH . '/settings/general-settings' => 'Settings / General',
ADMIN_PATH . '/settings/server-info' => 'Settings / Server Info',
ADMIN_PATH . '/users' => 'Users',
ADMIN_PATH . '/users/groups' => 'User Groups',
);

define('ADMIN_ACCESS_OPTIONS', serialize($admin_access_options));
Expand Down
30 changes: 27 additions & 3 deletions application/core/Admin_Controller.php
@@ -1,8 +1,27 @@
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* PageStudio
*
* A web application for managing website content. For use with PHP 5.4+
*
* This application is based on the on the CMS Canvas, the CodeIgniter
* application, http://cmscanvas.com/. It has been greatly altered to
* work for the purposes of our development team. Additional resources
* and concepts have been borrowed from PyroCMS http://pyrocms.com,
* for further improvement and reliability.
*
* @package PageStudio
* @author Cosmo Mathieu <cosmo@cosmointeractive.co>
* @copyright Copyright (c) 2015, CosmoInteractive, LLC
* @license MIT License
* @link http://pagestudiocms.com
*/

// ------------------------------------------------------------------------

class Admin_Controller extends MY_Controller
{
function __construct()
public function __construct()
{
parent::__construct();

Expand All @@ -13,9 +32,14 @@ function __construct()
->group_types(array(ADMINISTRATOR))
->unauthenticated_redirect(ADMIN_PATH . '/users/login')
->require_auth();

// -------------------------------------
// Build Admin Navigation
// -------------------------------------
$this->template->set('admin_menu_items', get_admin_module_menu_items());

// Load jQuery by default
$this->template->add_package(array('jquery', 'jquerytools', 'admin_jqueryui'));
$this->template->add_package(['jquery', 'jquerytools', 'admin_jqueryui']);
}

public function _remap($method, $params = array())
Expand Down
51 changes: 49 additions & 2 deletions application/core/MY_Controller.php
Expand Up @@ -2,9 +2,17 @@

class MY_Controller extends CI_Controller
{
function __construct()
/**
* @var The currently loaded module
*/
public $module;

public function __construct()
{
parent::__construct();

// Only allow access to installed modules
$this->module_install_check();

// Load in the admin helper functions if the current user is an administrator
if ($this->secure->group_types(array(ADMINISTRATOR))->is_auth())
Expand Down Expand Up @@ -37,12 +45,51 @@ function __construct()
}

$this->template->set_meta_title(ucwords($title) . " | " . $this->settings->site_name);

// Set Group
if ($this->session->userdata('user_session'))
{
$this->group_id = $this->session->userdata('user_session')->group_id;
$this->Group_session = $this->session->userdata('group_session');
}
}

// ---------------------------------------------------------------

/**
* Only allow access to registered/activate modules
*
* @return bool True or False
*/
public function module_install_check()
{
ci()->load->ext_model('addons_model', APPPATH . 'modules/addons/models');
$module_model = new Addons_model('modules');

$this->module = ci()->router->fetch_module();

// Load all modules (the Events library uses them all) and make their details widely available
ci()->enabled_modules = $module_model->get_modules(1);

if( ! $module_model->is_enabled($this->module))
{
// If module is not installed and is front controller show 404
if (is_a($this, 'Admin_Controller'))
{
}
show_error('The <b>' . ucfirst($this->module) . '</b> module has been deactivated or has yet to be installed, please refer to your system administrator.', 500);
}
}
}

/**
* Returns the CodeIgniter object.
*
* Example: ci()->db->get('table');
*
* @return \CI_Controller
*/
function ci()
{
return get_instance();
}
4 changes: 4 additions & 0 deletions application/core/MY_Loader.php
Expand Up @@ -42,6 +42,10 @@ public function ext_view($folder, $view, $vars = array(), $return = FALSE)
*/
public function ext_model($model, $path = NULL, $object_name = NULL, $connect = FALSE)
{
/** Hack! Load our core model if not already */
require_once SYSTEM_PATH ."core/Model.php";
require_once APPPATH ."core/MY_Model.php";

if(is_null($path)) {
show_error('The model path for "'.$model.'" cannot be left to EMPTY. Error triggered in '.APPPATH.'core/MY_Loader.php line 45');
}
Expand Down

1 comment on commit 5567e3a

@cosmomathieu
Copy link
Member Author

@cosmomathieu cosmomathieu commented on 5567e3a Aug 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Closes #37

Please sign in to comment.