/** * @todo Need to test object fully rather than stopping at the exception */ public function testFactory() { try { KMS::instance('content'); } catch (Exception $e) { $this->assertInstanceOf('KMS_Exception', $e); return; } $this->fail(); }
/** * Loads up a specific list table ORM instance * @param string name of the list to load * @return Model_List */ public function load($list_name) { $list = KMS::instance('site')->lists->where('name', '=', $list_name)->find(); if (!$list->loaded()) { throw new KMS_Exception('Unable to load list `:list:`', array(':list:' => $list_name)); } $this->_table_name = 'list_' . KMS::instance('site')->id . '_' . strtolower($list->name); parent::__construct($this->_passed_id); return $this; }
/** * Validation callback to verify that the entered username * does not already exist in the site database * @param Validate Validation object * @param string data field to validate against * @return void */ public function check_username(Validate $validate, $field) { if (!isset($this->_changed['username'])) { return; } $username_exists = KMS::instance('site')->users->where('username', '=', $validate[$field])->find(); if ($username_exists->loaded()) { $validate->error($field, 'already_exists', array($validate[$field])); } }
/** * Overrides ORM get magic method to allow for enabled * @param string name of column/relationship to return * @return mixed */ public function __get($column) { if ($column != 'enabled') { return parent::__get($column); } else { if ($this->_enabled === NULL) { $this->_enabled = ORM::factory('site_snippet')->where('site_id', '=', KMS::instance('site')->id)->where('snippet_id', '=', $this->id)->order_by('snippet_id', 'ASC')->find()->enabled; } return $this->_enabled; } }
/** * Removes a site template from the site. Does not remove it from * the KMS system. * @param int template id to remove * @return Model_Site_Template */ public function delete($id = NULL) { if ($id === NULL) { // Use the the primary key value $id = $this->pk(); } if (!empty($id) or $id === '0') { // Delete the object DB::delete($this->_table_name)->where($this->_primary_key, '=', $id)->where('site_id', '=', KMS::instance('site')->id)->execute($this->_db); } return $this; }
/** * Sets up the template and loads the site */ public function before() { parent::before(); $this->_site = KMS::instance('site'); $this->_user = KMS::Session()->get('user'); if ($this->_user === NULL) { Request::$current->redirect(Route::url('kms-admin', array('action' => 'login'))); } $this->template->site = KMS::instance('site'); $this->template->title = ucwords(strtolower(Request::instance()->action)); $this->template->sidebar = Request::factory('kms-admin/sidebar')->execute()->response; }
/** * Loads the site content */ protected function _load() { $this->_response = $this->_content->body; $active_template = KMS::instance('site')->site_templates->where('enabled', '=', TRUE)->find()->template_id; $template = KMS::instance('site')->templates->find($active_template); $this->_variables['title'] = $this->_content->title; if ($template->loaded() && $this->_content->mime_type == 'text/html') { $this->_variables['content'] = $this->_content->body; $this->_variables['meta_keywords'] = $this->_content->meta_keywords; $this->_variables['meta_description'] = $this->_content->meta_description; $this->_response = $template->body; } }
/** * Sets up module actions * @param Request Request that created the controller */ public function __construct($request) { // default menu items $this->_menu[10] = array('title' => 'Dashboard', 'params' => array('action' => 'dashboard')); $this->_menu[15] = array('title' => 'Profile', 'params' => array('action' => 'profile')); $this->_menu[999] = array('route' => 'kms-action', 'title' => 'Logout', 'params' => array('action' => 'logout')); // TEMPLATES if (KMS::instance('privilege')->has_any(array('template_activate', 'template_add', 'template_delete', 'template_edit'))) { $this->_menu[20] = array('title' => 'Templates', 'params' => array('action' => 'templates'), 'submenu' => array(10 => array('title' => 'Overview', 'params' => array('section' => 'overview')))); if (KMS::instance('privilege')->has('template_add')) { $this->_menu[20]['submenu'][20] = array('title' => 'Add New', 'params' => array('section' => 'add')); } } // CONTENT if (KMS::instance('privilege')->has_any(array('content_add', 'content_delete', 'content_edit'))) { $this->_menu[30] = array('title' => 'Content', 'params' => array('action' => 'content'), 'submenu' => array(10 => array('title' => 'Overview', 'params' => array('section' => 'overview')))); if (KMS::instance('privilege')->has('content_add')) { $this->_menu[30]['submenu'][20] = array('title' => 'Add New', 'params' => array('section' => 'add')); } } // LISTS if (KMS::instance('privilege')->has_any(array('list_add', 'list_delete', 'list_view_add', 'list_view_delete', 'list_view_edit'))) { $this->_menu[40] = array('title' => 'Lists', 'params' => array('action' => 'lists', 'section' => 'overview'), 'submenu' => array()); $submenu = array(20 => array('title' => 'Show All Lists', 'params' => array('section' => 'overview'))); if (KMS::instance('privilege')->has('list_add')) { $submenu[10] = array('title' => 'Add New List', 'params' => array('section' => 'add')); } $this->_menu[40]['submenu'] = KMS::instance('site')->lists->menu($submenu); } // RESOURCES if (KMS::instance('privilege')->has_any(array('resource_enable', 'resource_disable'))) { $this->_menu[50] = array('title' => 'Resources', 'params' => array('action' => 'resources'), 'submenu' => array(10 => array('title' => 'Snippets', 'params' => array('section' => 'snippets')), 20 => array('title' => 'Chunks', 'params' => array('section' => 'chunks')), 30 => array('title' => 'Variables', 'params' => array('section' => 'variables')))); } // ADMINISTRATION if (KMS::instance('privilege')->has_any(array('user_add', 'user_edit'))) { $this->_menu[80] = array('title' => 'Administration', 'params' => array('action' => 'admin'), 'submenu' => array()); if (KMS::instance('privilege')->has_any(array('user_add', 'user_edit'))) { $this->_menu[80]['submenu'][10] = array('title' => 'Users', 'params' => array('section' => 'users')); } } parent::__construct($request); }
/** * Tests that the KMS class can create a singleton instance of a KMS classes */ public function testInstance() { $this->assertInstanceOf('KMS_Site', KMS::instance('site', 1)); }
?> </td> <td><?php echo $item->role->find()->name; ?> </td> <td> <?php if ($item->id != KMS::Session()->get('user')->id) { if (KMS::instance('privilege')->has('user_edit')) { echo html::anchor(Route::url('kms-admin', array('action' => 'admin', 'section' => 'user-edit', 'id' => $item->id)), html::image(trim(Route::url('kms-asset', array('type' => 'images', 'file' => 'icons/pencil.png')), '/'), array('alt' => 'Edit User'))); } ?> <?php if (KMS::instance('privilege')->has('user_delete')) { echo html::anchor(Route::url('kms-admin', array('action' => 'admin', 'section' => 'user-delete', 'id' => $item->id)), html::image(trim(Route::url('kms-asset', array('type' => 'images', 'file' => 'icons/cross.png')), '/'), array('alt' => 'Remove User'))); } } ?> </td> </tr> <?php } ?> </tbody> </table> </div><!-- End .tab-content --> </div><!-- End .content-box-content -->
/** * Edits a site variable */ public function action_variable_edit() { $id = arr::get($this->_data, 'id'); unset($this->_data['id']); $this->_redirect = Route::url('kms-admin', array('action' => 'resources', 'section' => 'variables', 'id' => $id)); $resource = KMS::instance('site')->variables->find($id); if (!$resource->loaded()) { KMS::stop('Unable to load resource'); } $resource->values($this->_data); $this->_store = $resource->check(); if ($this->_store) { try { $resource->save(); $this->_message("The site variable <strong>{$resource->name}</strong> was successfully updated"); $this->_details = "The variable `{$resource->name}` was edited"; $this->_identifier = "site_variables.{$resource->id}"; } catch (Exception $e) { $this->_message('The variable name (' . arr::get($this->_data, 'name') . ') is already in use. Please enter a unique variable name.', 'error'); $this->_store = FALSE; } } else { $msg = 'ERROR: The following errors occurred:<br />'; foreach ($resource->validate()->errors('validate') as $error) { $msg .= ' - ' . ucfirst($error) . '<br />'; } $this->_message($msg, 'error'); } }
<?php defined('SYSPATH') or die('No direct access allowed.'); /* * KMS Constants */ define('KMS_DATABASE', 'kms'); define('KMS_VERSION', '0.2'); /* * KMS Routes */ Route::set('kms-super-admin', 'kms-admin/super(/<action>(/<section>(/<id>(/<subid>))))')->defaults(array('controller' => 'kms_superadmin', 'action' => 'index')); Route::set('kms-admin', 'kms-admin(/<action>(/<section>(/<id>(/<subid>))))', array('action' => '(?!sidebar|logout)[^/]*'))->defaults(array('controller' => 'kms_admin', 'action' => 'login')); Route::set('kms-admin-modules', 'kms-admin(/<action>)', array('action' => '(?!logout).*'))->defaults(array('controller' => 'kms_module')); Route::set('kms-action', 'kms-action(/<action>(/<id>))')->defaults(array('controller' => 'kms_action')); Route::set('kms-asset', 'kms-asset(/<type>(/<file>))', array('file' => '.*'))->defaults(array('controller' => 'kms_asset', 'action' => 'load')); /* * KMS Startup */ if (!defined('SUPPRESS_REQUEST')) { KMS::instance('site'); }
/** * Loads template pages */ public function action_templates() { switch (Request::$current->param('section')) { case 'overview': $this->template->title = 'Site Templates'; $template = KMS::instance('site')->templates->find_all(); $this->template->content = View::factory('kms/template-overview', compact('template')); break; case 'add': $this->template->title = 'Adding Template'; $template = array(); if (KMS::Session()->path('ua.status') === 'failed') { $template = KMS::Session()->path('ua.fields'); } $this->template->content = View::factory('kms/template-add', compact('template')); break; case 'edit': $this->template->title = 'Editing Template'; $template = KMS::instance('site')->templates->find(Request::$current->param('id')); if (!$template->loaded()) { KMS::stop('The requested template was not found'); } if (KMS::Session()->path('ua.status') === 'failed') { $template->values(KMS::Session()->path('ua.fields')); } $template = $template->as_array(); $this->template->content = View::factory('kms/template-edit', compact('template')); break; case 'delete': $template = KMS::instance('site')->templates->find(Request::$current->param('id')); if (!$template->loaded()) { KMS::stop('The requested template was not found'); } $template = $template->as_array(); $this->template->title = 'Delete Template'; $this->template->content = View::factory('kms/template-delete', compact('template')); break; default: Request::$current->redirect(Route::url('kms-admin', array('action' => 'templates', 'section' => 'overview'))); } }