/** * get a list of pages * * @return void * @author Andy Bennett */ function get_pages_() { $name = 'application'; $dbe = new Database_Expression('(SELECT pid FROM pages WHERE name="' . $name . '")'); $root = ORM::factory('pages_position')->in('page_pid', $dbe)->find(); $sitemap_string = $root->render_descendants($name, false)->render(); $sitemap = simplexml_load_string($sitemap_string); $arr = array(); $arr[] = steamcore::array_object(array('id' => 'home', 'title' => '/')); //get sections $xpc = $sitemap->xpath('/root/items/item'); foreach ($xpc as $x) { $url = $x['url']; if (strpos($url, 'page') === false) { continue; } $arr[] = steamcore::array_object(array('id' => str_replace('/page/', '', $url), 'title' => (string) $x['url'])); } //get sub-pages $xpc = $sitemap->xpath('/root/items/item/item'); foreach ($xpc as $x) { $url = $x['url']; if (strpos($url, 'page') === false) { continue; } $arr[] = steamcore::array_object(array('id' => str_replace('/page/', '', $url), 'title' => (string) $x['url'])); } return $arr; }
/** * set up the joins * * @param string $db * @return void * @author Andy Bennett */ function get_joins() { $t = parent::get_table(); $joins = array(); $joins[] = steamcore::array_object(array('table' => 'uploads AS u', 'on' => $t . '.upload = u.id')); #$joins[] = steamcore::array_object( array('table' => 'galleries AS s', 'on' => $t.'.gallery = s.id') ); return $joins; }
/** * normalise the passed setup object (setting defaults, throwing errors on when required values are missing) * * @param string $setup * @return void * @author Andy Bennett */ public function normalise_setup($setup = false) { // throw exceptions if the correct parameters haven't been passed if (!is_object($setup)) { throw new Kohana_User_Exception('Form Setup Error', 'setup object required'); } if (!isset($setup->form_name) || !is_string($setup->form_name)) { throw new Kohana_User_Exception('Form Setup Error', 'form_name string is required'); } if (!isset($setup->model) || !is_object($setup->model)) { throw new Kohana_User_Exception('Form Setup Error', 'model object is required'); } // setup $d = array('db' => true, 'update' => false, 'exit_point' => false, 'form_data' => array()); $setup = steamcore::array_object($d, $setup); return $setup; }
public function get_pages() { $arr = array(); $arr[] = steamcore::array_object(array('id' => 'home', 'title' => '/')); // get sections $xpc = $this->sitemap->xpath('/root/items/item'); foreach ($xpc as $x) { $url = $x['url']; if (strpos($url, 'page') === false) { continue; } $arr[] = steamcore::array_object(array('id' => str_replace('/page/', '', $url), 'title' => (string) $x['url'])); } // get sub-pages $xpc = $xml->xpath('/root/items/item/item'); foreach ($xpc as $x) { $url = $x['url']; if (strpos($url, 'page') === false) { continue; } $arr[] = steamcore::array_object(array('id' => str_replace('/page/', '', $url), 'title' => (string) $x['url'])); } return $arr; }
/** * show the user their profile for editing * * @return void * @author Andy Bennett */ public function profile() { if (!$this->model->test_logged_in()) { throw new Exception('invalid user'); } $id = $this->model->get_user_data()->id; $setup = steamcore::array_object(array('update' => $id, 'form_name' => 'auth_profile', 'model' => $this->model)); // try running the form, throw exception on error (shouldn't happen) try { steamform_helper::run_form($setup); } catch (Exception $e) { throw new Kohana_User_Exception('SteamCore Edit Error', $e->getMessage()); } }
/** * return a list of the groups * * @return array * @author Andy Bennett */ public function get_groups() { $new = array(); $roles = Kohana::config('acl.roles'); foreach ($roles as $role => $val) { if ($role == 'superadmin') { continue; } if ($role == 'guest') { continue; } $new[] = steamcore::array_object(array('id' => $role, 'title' => $role)); } return $new; }
/** * build and run an XML form * * @param object $setup * @return void * @author Andy Bennett */ public static function run_form($setup = false) { try { $setup = SteamForm::normalise_setup($setup); $form = SteamForm::factory($setup); // does the form data validate $form->test_form(); // get the data submitted from the form $fc = steamcore::array_object(array('form' => $form->return_form())); // run the validated event Event::run('steamform_' . $setup->form_name . '.validated', $fc); if ($setup->exit_point === 'validated') { return; } // do the uploading foreach ($_FILES as $file => $file_data) { if ($file_data['error'] > 0) { unset($_POST[$file]); } else { // insert the upload into the uploads database $_POST[$file] = $setup->model->insert_upload(upload::get_upload_data($file, $file_data)); } } // run the uploaded event Event::run('steamform_' . $setup->form_name . '.uploaded', $fc); if ($setup->exit_point === 'uploaded') { return; } // if this is an update, get the current values, and pass them into the form if ($setup->update !== false) { $id = isset($setup->id) ? $setup->id : Kohana::instance()->input->post('form_id'); if (!$id || !preg_match('/^[0-9]+$/', $id)) { throw new Exception("No ID supplied"); } $fc->id = $id; // prepare the data for inserting $setup->model->prep_update_formdata($fc); Event::run('steamform_' . $setup->form_name . '.update_prepped', $fc); if ($setup->exit_point === 'prepped') { return $fc; } if ($setup->db) { // insert the data into the database $r = $setup->model->update_formdata($fc); // run the updated event Event::run('steamform_' . $setup->form_name . '.updated', $r); } } else { // prepare the data for inserting $setup->model->prep_insert_formdata($fc); Event::run('steamform_' . $setup->form_name . '.insert_prepped', $fc); if ($setup->exit_point === 'prepped') { return $fc; } if ($setup->db) { // insert the data into the database $r = $setup->model->insert_formdata($fc); // run the inserted event Event::run('steamform_' . $setup->form_name . '.inserted', $r); } } if ($setup->exit_point === 'inserted') { return; } if ($setup->exit_point === 'updated') { return; } // if there is a notify item in the form, run the notify event if (isset($fc->form->notify)) { Event::run('steamform.notify', steamcore::array_object(array('data' => $fc, 'notify' => $fc->form->notify))); } Event::run('audit.cache', steamcore::array_object(array('action' => $setup->update ? 'edit' : 'add', 'id' => $r, 'data' => $fc->data))); // run the inserted event Event::run('steamform_' . $setup->form_name . '.complete', steamcore::array_object(array('id' => $r, 'data' => $fc->data))); } catch (Exception $e) { // if this is an update, get the current values, and pass them into the form if ($setup->update !== false) { $current = steamform_helper::return_current_values($setup->model, $setup->update, $form); $form->set_form_data('current', $current); } if ($e->getCode() != -1) { Kohana::log('error', $e->getMessage()); $form->set_form_data('error', $e->getMessage()); } // generate the html and throw it $f = $form->render(); // run the show_form event Event::run('steamform_' . $setup->form_name . '.show_form', $f); } }
/** * join the tables as appropriate * * @param object $lc * @return object * @author Andy Bennett */ public function get_joins() { // get the primary table from the config file $p = $this->conf->tables['primary']; $joins = array(); // set the secondary if (isset($this->conf->tables['secondary']) && is_array($this->conf->tables['secondary'])) { foreach ($this->conf->tables['secondary'] as $t) { $t->type = isset($t->type) ? $t->type : 'left'; $joins[] = steamcore::array_object(array('table' => $t->table, 'on' => $t->table . '.' . $t->key . '=' . $p->table . '.' . $p->key, 'type' => 'left')); } } return $joins; }
<?php defined('SYSPATH') or die('No direct script access.'); $config['steamauth'] = new stdClass(); $config['steamauth']->identity_column = 'identity'; $config['steamauth']->credential_column = 'credential'; $config['steamauth']->tables = array('primary' => steamcore::array_object(array('table' => 'users', 'key' => 'id')), 'secondary' => array()); $config['steamauth']->registration_enabled = TRUE; $config['steamauth']->home_action = ''; $config['steamauth']->activation_method = 'user'; // credential SETTINGS $config['steamauth']->user_credential_min = 6; //min credential length $config['steamauth']->user_credential_max = 16; //max credential length $config['steamauth']->use_country = TRUE; $config['steamauth']->change_credential_email = 'change_credential_email'; $config['steamauth']->activation_email = 'activation_email'; //The location of the activation email $config['steamauth']->forgotten_credential_email = 'forgotten_credential_email'; // The location of the forgotten password email $config['steamauth']->forgotten_credential_reset_email = 'forgotten_credential_reset_email'; //The location of the forgotten password reset email $config['steamauth']->forgotten_identity_email = 'forgotten_identity_email'; // The location of the forgotten password email $config['steamauth']->user_activation_email = 'user_activation_email'; //The location of the activation email $config['steamauth']->moderator_activation_email = 'moderator_activation_email'; //The location of the activation email
/** * return list * * @param object $lc * @return array * @author Andy Bennett */ public function get_list() { $data = array('action' => 'list', 'name' => $this->name, 'role' => Steamauth::instance()->get_role()); Event::run('steamcore.aclcheck', $data); $tdata = array(); $limit = 10; $total = $this->model->get_total(); // query the model $pagination = pagination_helper::get_pagination($limit, $total); $l = steamcore::array_object(array('limit' => $limit, 'offset' => $pagination->sql_offset())); $o = $this->get_order(); $data['query'] = $this->model->get_list($w = null, $o, $l); $data['controller'] = Kohana::instance()->uri->segment(1); $data['pagination'] = $total <= $limit ? '' : $pagination->render(); // pass the order direction // $data['od'] = (!isset($lc->query_config->order_dir) || $lc->query_config->order_dir == 'DESC')?'ASC':'DESC'; // merge any passed data and the data returned from the model $tdata = array_merge($tdata, $data); // return the result return $tdata; }
/** * get the list of gallery items * * @param int $gid * @return array * @author Andy Bennett */ function get_list($gid) { $data = array('action' => 'list', 'name' => $this->name, 'role' => Steamauth::instance()->get_role()); Event::run('steamcore.aclcheck', $data); // which model are we using? one passed through or the default? $model = $this->model; $controller = Kohana::instance()->uri->segment(1); $tdata = array(); $limit = 10; $where = null; if ($this->uri->segment(3)) { $where = array('gallery' => $gid); } // query the model $pagination = pagination_helper::get_pagination($limit, $model->get_total($where)); $l = steamcore::array_object(array('limit' => $limit, 'offset' => $pagination->sql_offset())); $data['query'] = $model->get_list($where, $order = null, $limit = $l); $data['controller'] = $controller; $data['pagination'] = $pagination->render(); // pass the order direction // $data['od'] = (!isset($lc->query_config->order_dir) || $lc->query_config->order_dir == 'DESC')?'ASC':'DESC'; // merge any passed data and the data returned from the model $tdata = array_merge($tdata, $data); // return the result return $tdata; }