/** * Loads the sidebar */ public function action_sidebar() { $this->action = Request::instance()->action; $user = (object) KMS::Session()->get('user'); $sidebar = $this; $this->request->response = View::factory('kms/admin-sidebar', compact('user', 'sidebar')); }
/** * Initializes the object and load in logged in user */ protected function __construct() { $user = KMS::Session()->get('user'); if ($user !== NULL) { $this->_default_user = $user; $this->user($user->id); } }
/** * 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])); } }
/** * 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; }
/** * @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(); }
/** * 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; } }
/** * 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; }
/** * 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; }
/** * Helper method to find mime_type * @param string name of the file * @param string extension of the file * @return string */ private function _get_mime_type($filename, $ext) { $mime_types = KMS::mime_types(); if (array_key_exists($ext, $mime_types)) { return $mime_types[$ext]; } elseif (function_exists('finfo_open')) { $finfo = finfo_open(FILEINFO_MIME); $mimetype = finfo_file($finfo, $filename); finfo_close($finfo); return $mimetype; } else { return 'application/octet-stream'; } }
echo form::hidden('site_list', $site_list->id); ?> <fieldset> <?php foreach ($columns as $id => $col) { if ($id == 'id') { continue; } ?> <p> <label><?php echo $col['column_name']; ?> </label> <?php echo KMS::input($col, $list->{$id}); ?> </p> <?php } ?> <p> <input class="button" type="submit" value="Add" /> </p> </fieldset> <div class="clear"></div><!-- End .clear --> </form> </div><!-- End .tab-content --> </div><!-- End .content-box-content -->
$link = @mysql_connect(arr::get(Session::instance()->get('kms-database'), 'dbhost'), arr::get(Session::instance()->get('kms-database'), 'uname'), arr::get(Session::instance()->get('kms-database'), 'pwd')); if (!$link) { KMS::stop('<strong>ERROR:</strong> Could not connect to MySQL database. Click back to verify your MySQL settings.<br /><br /><strong>MySQL Error:</strong> ' . mysql_error(), $_POST); } $db = mysql_select_db(arr::get(Session::instance()->get('kms-database'), 'dbname'), $link); if (!$db) { $error = mysql_error(); mysql_close($link); KMS::stop('<strong>ERROR:</strong> Could not connect to MySQL database. Click back to verify your MySQL settings.<br /><br /><strong>MySQL Error:</strong> ' . $error, $_POST); } foreach ($db_schema as $sql) { $response = @mysql_query($sql, $link); if (!$response) { $error = mysql_error(); mysql_close($link); KMS::stop('<strong>ERROR:</strong> Could not connect to MySQL database. Click back to verify your MySQL settings.<br /><br /><strong>MySQL Error:</strong> ' . $error); } } mysql_close($link); // add site and user data $site = ORM::factory('site'); $site->domain = arr::get(Session::instance()->get('kms-config'), 'domain'); $site->description = arr::get(Session::instance()->get('kms-config'), 'domain_description'); $site->save(); $site_id = $site->id; $user = ORM::factory('user'); $user->username = arr::get(Session::instance()->get('kms-config'), 'admin'); $user->password = sha1(arr::get(Session::instance()->get('kms-config'), 'admin_pwd')); $user->first_name = arr::get(Session::instance()->get('kms-config'), 'first_name'); $user->last_name = arr::get(Session::instance()->get('kms-config'), 'last_name'); $user->email = arr::get(Session::instance()->get('kms-config'), 'email');
/** * @dataProvider inputData */ public function testInput(array $column_data, $value = '', array $readonly_columns = array('id'), $result) { $this->assertEquals($result, KMS::input($column_data, $value, $readonly_columns)); }
/** * Creates a new instance of the class */ public function __construct() { $this->_data = Session::instance()->get(KMS::Config()->session_key, array()); Session::instance()->bind(KMS::Config()->session_key, $this->_data); }
<div class="content-box-content"> <div class="tab-content default-tab" id="tab1"> <?php if (KMS::Session()->path('ua.message.text') !== NULL) { ?> <div class="notification <?php echo KMS::Session()->path('ua.message.class'); ?> png_bg"> <a href="" class="close"><img src="/kms-asset/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a> <div> <?php echo KMS::Session()->path('ua.message.text'); ?> </div> </div> <?php } ?> <?php echo form::open(Route::url('kms-action', array('action' => 'profile_edit'))); ?> <fieldset> <p> <label>Username</label> <input class="text-input large-input" type="text" id="large-input" name="username" value="<?php echo arr::get($profile, 'username');
/** * Gets a singleton KMS object instance * @param type KMS class to get * @param mixed optional parameters * @return mixed */ public static function instance($class, $params = NULL) { $install_file = arr::get(kohana::modules(), 'kms') . 'config/.kms'; if (!file_exists($install_file) && !empty($_SERVER['REQUEST_URI']) && !preg_match('/kms-asset/', $_SERVER['REQUEST_URI'])) { require arr::get(kohana::modules(), 'kms') . 'install.php'; } if (empty(self::$_instance)) { self::$_instance = new KMS(); KMS::Session(); // start session } $kmsclass = 'kms_' . strtolower($class); if (empty(self::$_instances[$kmsclass])) { self::$_instances[$kmsclass] = self::factory($class, $params); } return self::$_instances[$kmsclass]; }
?> </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 -->
?> <fieldset> <p> <label>List Name</label> <input class="text-input large-input" type="text" name="name" value="<?php echo arr::get($site_list->as_array(), 'name'); ?> " /> </p> <p> <label>Columns</label> </p> </fieldset> <?php foreach (KMS::Session()->path('ua.fields.column_name', array('')) as $key => $value) { $column = array('name' => $value, 'type' => KMS::Session()->path('ua.fields.column_name.' . $key)); ?> <fieldset class="column-left"> <p> <label>Name</label> <input class="text-input medium-input" type="text" name="column_name[]" value="<?php echo arr::get($column, 'name'); ?> " /> </p> </fieldset> <fieldset class="column-right"> <p> <label>Type</label> <?php echo form::select('column_type[]', $column_types, arr::get($column, 'type'), array('class' => 'medium-input'));
/** * Loads KMS_Content */ public function action_index() { $this->request->response = KMS::factory('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'); } }
/** * Helper function for rendering site variables * @param string data to parse (chunk, snippet, variable) * @param string specifies what type of data is being passed in ([c]hunk, [s]nippet, [v]ariable, [list]) * @return boolean */ protected function _parse($data, $type) { $found = FALSE; foreach ($data as $key => $value) { $find = $key; if ($type != 'list') { $key = preg_quote($key, '/'); } $key = "/\\[\\[{$type}\\*{$key}\\]\\]/"; if (!preg_match($key, $this->_response, $matches)) { continue; } if ($type == 's') { $value = $this->_eval($find, $value); } else { if ($type == 'list') { $data = KMS::factory('list', $matches)->load(); $this->_render_vars += $data; } } $this->_response = preg_replace($key, $value, $this->_response); $found = TRUE; } return $found; }
<body id="login"> <div id="login-wrapper" class="png_bg"> <div id="login-top"> <h1>Kooshy (KMS)</h1> </div> <!-- End #logn-top --> <div id="login-content"> <div class="notification <?php echo KMS::Session()->path('ua.message.class', 'information'); ?> png_bg"> <a href="" class="close"><img src="/kms-asset/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a> <div> <?php echo KMS::Session()->path('ua.message.text', 'Please login by using the form below.'); ?> </div> </div> <?php echo form::open(Route::url('kms-action', array('action' => 'login'))); ?> <p> <?php echo form::label('ff_username', 'Username'); ?> <?php echo form::input('username', arr::path($ua, 'fields.username'), array('id' => 'ff_username', 'class' => 'text-input')); ?> </p> <div class="clear"></div>
<fieldset class="column-left"> <p> <label for="ff_uri">URI</label> <input class="text-input medium-input" type="text" id="ff_uri" name="uri" value="<?php echo arr::get($content, 'uri'); ?> " /> </p> </fieldset> <fieldset class="column-right"> <p> <label for="ff_mime_type">Mime Type</label> <?php echo form::select('mime_type', KMS::mime_types(FALSE), arr::get($content, 'mime_type', 'text/html'), array('class' => 'medium-input', 'id' => 'ff_mime_type')); ?> </p> </fieldset> <div class="clear"></div> <fieldset> <p> <label for="ff_meta_keywords">Meta Keywords [meta_keywords]</label> <input class="text-input large-input" type="text" id="ff_meta_keywords" name="meta_keywords" value="<?php echo arr::get($content, 'meta_keywords'); ?> " /> </p> <p> <label for="ff_meta_description">Meta Description [meta_description]</label>
/** * 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'))); } }
<?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'); }