/** * generate xml for a form from a table * * @param object $setup * @return string * @author Andy Bennett */ function get_form_xml($setup) { $file_name = $setup->form_name; $dir = DATAPATH . '/xml/forms/'; $path = $dir . $file_name . '.xml'; if (file_exists($path)) { return file_get_contents($path); } if (!isset($setup->model) || !is_object($setup->model)) { $config = Kohana::config('controls.controllers'); $name = Kohana::instance()->uri->segment(1); if (!isset($config->{$name})) { throw new Exception("No controller set up"); } $this->set_table($config->{$name}['table']); } else { $this->set_table($setup->model->get_table()); $name = $setup->form_name; } $field_data = $this->db->field_data($this->table); // print_r($field_data); $view = new View('xml/form'); $view->field_data = $field_data; $view->name = Kohana::instance()->uri->segment(1); $view->action = Kohana::instance()->uri->segment(2); $data = $view->render(); if (file_exists($dir)) { file_put_contents($path, $data); } return $data; }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { if (Kohana::$instance == NULL) { // Set the instance to the first controller loaded Kohana::$instance = $this; } }
public static function set_checkbox($field = '', $value = '', $default = FALSE) { if ($_POST) { if (!Kohana::instance()->input->post($field)) { if (count($_POST) === 0) { return ' checked="checked"'; } return ''; } $field = Kohana::instance()->input->post($field); if (is_array($field)) { if (!in_array($value, $field)) { return ''; } else { return ' checked="checked"'; } } else { if ($field == '' or $value == '' or $field != $value) { return ''; } else { return ' checked="checked"'; } } } elseif ($default) { return ' checked="checked"'; } }
/** * 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; }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { if (Kohana::$instance == NULL) { // Set the instance to the first controller loaded Kohana::$instance = $this; } // URI should always be available $this->uri = URI::instance(); // Input should always be available $this->input = Input::instance(); $this->db = new Database(); $this->user_model = ORM::factory('user'); $this->supplier_model = ORM::factory('supplier'); $this->category_model = ORM::factory('category'); $this->item_model = ORM::factory('item'); $this->item_stock_model = ORM::factory('item_stock'); $this->district_model = ORM::factory('district'); $this->office_model = ORM::factory('office'); $this->budget_model = ORM::factory('office_budget'); $this->purchase_model = ORM::factory('purchase'); $this->request_model = ORM::factory('request'); $this->transaction_model = ORM::factory('transaction'); $this->setting_model = ORM::factory('setting'); $this->log_model = ORM::factory('log'); $this->email_model = ORM::factory('email'); }
function error_404() { if (Kohana::$instance == NULL) { Kohana::$instance = new Errors_Controller(); } Kohana::show_404(null, 'common/error_404'); }
function error_404() { if (Kohana::$instance == NULL) { Kohana::$instance = new Errors_Controller(); } Kohana::log('error', 'Error 404 (steam.core.hooks): ' . URI::instance()->string()); Kohana::show_404(null, 'common/error_404'); }
public function get_upload_config() { // get the default upload config from appconf $uconf = Kohana::config('upload.upload'); $s = Kohana::instance()->uri->segment(1); if (!isset($uconf->multi->{$s})) { throw new Exception("No config item for " . $s); } return $uconf->multi->{$s}; }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { if (Kohana::$instance == NULL) { // Set the instance to the first controller loaded Kohana::$instance = $this; } // URI should always be available $this->uri = URI::instance(); // Input should always be available $this->input = Input::instance(); }
function get_pagination($limit, $total) { $pagination = new Pagination(); // pull the pagination config from the config/my_controller.php $config = Kohana::config('steam.pagination_config'); // set the base url $config['base_url'] = Kohana::instance()->uri->string(); $config['uri_segment'] = 'admin'; $config['total_items'] = $total; $config['items_per_page'] = $limit; $config['style'] = 'custom'; $pagination->initialize($config); return $pagination; }
/** * get the where query * * @param string $w * @return array * @author Andy Bennett */ function get_where($w = null) { $controller = Kohana::instance()->uri->segment(1); $where = array(); #$where = array('s.title' => $controller); if (!is_null($w)) { $where = array_merge($w, $where); } $t = parent::get_table(); if (!Acl::instance()->check(Steamauth::instance()->get_role(), 'gallery', 'moderate')) { $where[$t . '.status'] = '1'; } return $where; }
/** * return list * * @param object $lc * @return array * @author Andy Bennett */ public function get_list() { $data = array('action' => 'list', 'name' => $this->name, 'role' => User::instance()->get_role()); Event::run('steamcore.aclcheck', $data); $tdata = array(); $limit = 10; $page_num = $this->input->get('page', 1); $offset = ($page_num - 1) * $limit; $model = ORM::factory($this->setup['model'], null); $data['query'] = $model->where('role', URI::segment(1))->find_all($limit, $offset); $data['controller'] = Kohana::instance()->uri->segment(1); $data['pagination'] = Pagination::factory(array('style' => 'digg', 'items_per_page' => $limit, 'query_string' => 'page', 'total_items' => $model->count_last_query())); // merge any passed data and the data returned from the model $tdata = array_merge($tdata, $data); // return the result return $tdata; }
/** * This produces a form for editing the copy and headers in a page * * @return void * @author Dan Chadwick **/ function edit_inline() { // $d = array( // 'model' => steamcore::get_controls_model( 'pages' ), // 'form_name' => 'pages_edit', // 'form_data' => array(), // 'update' => ($r->count())?$r->current()->id:0 // ); // $setup = steamcore::array_object( $d ); // // /* Clear events */ // Event::clear('steamform_'.$setup->form_name.'.complete'); // Event::clear('steamform_'.$setup->form_name.'.show_form'); // // Event::add('steamform_'.$setup->form_name.'.complete', array('admin_helpers', 'response_complete_listener') ); // Event::add('steamform_'.$setup->form_name.'.show_form', array('admin_helpers', 'show_form_listener') ); // try { $p = Kohana::instance()->uri->segment(2, 'home'); $p = str_replace('.html', '', $p); $m = ORM::factory('page')->where('name', $p)->find(); $form = Xform::factory()->name('xpage_contents_edit'); // create the form $form->set_form_data('current', $m); $form->run(); // run the form // handle form completion if (!$form->complete) { return $form->render(); } else { $cols = array_keys($m->table_columns); foreach ($form->final_data as $k => $v) { if (!in_array($k, $cols)) { continue; } $m->{$k} = $v; } } } catch (Exception $e) { throw new Kohana_User_Exception('SteamCore Add Error', $e->getMessage()); } // Assets::instance()->add_javascript('/cache/js/steamform'); // Assets::instance()->add_javascript('/steamform/index/steamform'); return $e; }
/** * return list * * @param object $lc * @return array * @author Andy Bennett */ public function get_list() { $data = array('action' => 'list', 'name' => $this->name, 'role' => User::instance()->get_role()); Event::run('steamcore.aclcheck', $data); $tdata = array(); $limit = -1; $page_num = Input::instance()->get('page', 1); $offset = ($page_num - 1) * $limit; $model = ORM::factory($this->setup['model'], null); $data['query'] = $model->find_all(); $type = Input::instance()->get('type', false); $data['type'] = $type ? 'type=' . $type : ''; $data['controller'] = Kohana::instance()->uri->segment(1); $data['pagination'] = ''; $data['page'] = $page_num; // merge any passed data and the data returned from the model $tdata = array_merge($tdata, $data); // return the result return $tdata; }
public static function render($content, $container_id = false, $dir = "containers/", $additional = array()) { $container_id = $container_id ? $container_id : self::get_container(); $kohana = Kohana::instance(); $c = new Container($container_id); $view = new View($dir . $c->get_template()); $view->header = $content->header; $view->sub_header = $content->sub_header; $view->main_content = $content->copy; $view->section_nav = current(self::return_column($c, array('column' => 'nav'))); $view->left_column = self::return_column($c, array('column' => 'left-col')); $view->mid_column = self::return_column($c, array('column' => 'middle-col')); $view->right_column = self::return_column($c, array('column' => 'right-col')); if (is_array($additional)) { foreach ($additional as $a => $v) { $view->{$a} = $v; } } Display::instance()->display($view); }
/** * check an item is unique * * @param string $str * @param string $param * @return void * @author Andy Bennett */ public function check_unique($str, $param) { $table = $this->table; if (!is_string($param)) { $param = current($param); } // check that the item is unique $sql = $this->db->select('*')->from($table)->where(array('{param}' => strtolower($str)))->getsql(); $sql = str_replace('{param}', $param, $sql); $q = $this->db->query($sql); if ($q->count()) { $q->rewind(); $id = Kohana::instance()->input->post('form_id'); if (Kohana::instance()->input->post('form_action') && $id !== false && isset($q->current()->id)) { if ($id == $q->current()->id) { return true; } } return false; } else { return true; } }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { $session = Session::instance(); $site_config = yaml::parse($_SESSION['site_name'], 'site_config'); foreach ($site_config as $key => $value) { $this->{$key} = $value; } // --- Setup our required library instances --- // -------------------------------------------- # Auth Instance for editing site capability $this->client = new Auth($this->claimed); # Account Instance for user account tool. $this->account_user = new Account(); # assets instance to fetch datapath urls. $this->assets = Assets::instance($this->site_name, $this->theme); # URI should always be available $this->uri = URI::instance(); # Input should always be available $this->input = Input::instance(); if (Kohana::$instance == NULL) { # Set the instance to the first controller loaded Kohana::$instance = $this; } }
/** * Get data and display feed * * @param string $description - For top of feed * @return void * @author Dan Chadwick */ function index($description = null) { $model = steamcore::get_controls_model($this->uri->segment(2)); $tbl = $model->table_name; //Set limit $limit = uri::segment(3, Kohana::config('rss.limit')); //Limit the number of feed items by adding a third segment to the url if ($limit == -1) { $limit = null; } /* Set filter * Filters can be added to the rss string like so: ?filter_[filter_field_name]=[filter_value] */ $get = Kohana::instance()->input->get(); foreach ($get as $key => $filter_value) { if (strstr($key, 'filter_')) { $filter_column = substr($key, 7, strlen($key) - 7); $model->like($filter_column, $filter_value); } } $model->orderby(array('date_added' => 'desc')); $result = $model->find_all($limit); $v = Kohana::find_file('views', 'rss/' . $tbl) ? $tbl : 'feed-view'; // You can use a new rss view (named after the table) for specific tables if differnet fields are to be displayed $p = new View('rss/' . $v); header('Content-type: application/rss+xml'); $link = $tbl != 'pages' ? $tbl . '/' : ''; $p->set('description', $description); $p->set('link_data', 'page/' . $link); $p->set('feed_data', $result); try { $p->render(TRUE); } catch (Exception $ex) { throw new Kohana_Exception('debug', 'Rss error'); } }
/** * Change status complete * * @return void * @author Andy Bennett */ public static function status_complete_listener() { url::redirect(Kohana::instance()->input->post('current')); }
/** * get the data about the image * * @param integer $image (optional - if not passed, used uri segment 3) * @return object * @author Andy Bennett */ protected function get_image_row($image = false) { // use URI segment 3 if no id is passed if (!$image) { $image = end(URI::instance()->segment_array()); } // strip any file extensions (actually strip anything that isn't a number) $image = pathinfo(Kohana::instance()->uri->string(), PATHINFO_FILENAME); // make sure the id is numeric - if not exit if (!preg_match('/[0-9]+/i', $image)) { exit; } // get the ORM object $row = ORM::factory($this->setup['model'] . '_upload', $image); // make sure the object has been loaded properly and the parent model matches if (!$row->loaded) { Kohana::log('error', 'File model row error: ' . $image); throw new Kohana_404_Exception($image, 'common/error_404'); } if ($row->parent_model != $this->setup['model']) { Kohana::log('error', 'File model error: ' . $row->id); throw new Kohana_403_Exception($row->id, 'common/error_403'); } // make sure the object's status is true if (!$row->parent->status and !User::instance()->is_moderator()) { Kohana::log('error', 'File status: ' . $row->id); throw new Kohana_403_Exception($row->id, 'common/error_403'); } $data = array('action' => URI::instance()->segment(2), 'name' => $this->setup['name'], 'role' => User::instance()->get_role()); Event::run('acl.check', $data); // set up the image's path and error if the file doesn't exist $row->full_path = Kohana::config('upload.directory') . '/' . $row->file_name; if (!file_exists($row->full_path)) { Kohana::log('error', 'Invalid file path: ' . $row->full_path); throw new Kohana_404_Exception($row->orig_name, 'common/error_404'); } return $row; }
/** * check that the user has permission to view this row * * @return boolean * @author Andy Bennett */ public function check_auth() { // if there is an auth directive for the row and the user doesn't belong to that group, then continue return !isset($this->p->row->auth) || Kohana::instance()->ci_auth->belongsToGroup($this->p->row->auth, TRUE); }
/** * set a value * * @return void * @author Andy Bennett */ public function setvalue() { $data = array('action' => 'edit', 'name' => $this->name, 'role' => User::instance()->get_role()); Event::run('steamcore.aclcheck', $data); $value = Kohana::instance()->input->post('value'); $key = Kohana::instance()->input->post('key'); $id = Kohana::instance()->input->post('form_id'); $model = ORM::factory($this->setup['model'], $id); $model->{$key} = $value; $model->save(); Event::run('steamcore.item_value_set', $action = Input::instance()->post('current')); }
* @see http://docs.kohanaphp.com/bootstrap * * ---------------------------------------------------------------------------- */ // Define the name of the front controller index define('FCINDEX', basename(__FILE__)); // Define the absolute paths for configured directories define('DOCROOT', str_replace('\\', '/', realpath(getcwd())) . '/'); define('APPPATH', str_replace('\\', '/', realpath($application)) . '/'); define('MODPATH', str_replace('\\', '/', realpath($modules)) . '/'); define('SYSPATH', str_replace('\\', '/', realpath($system)) . '/'); // Clean up the configuration vars unset($application, $modules, $system); if (file_exists('install' . EXT)) { // Load the installation check return include 'install' . EXT; } // Load the main Kohana class require SYSPATH . 'classes/kohana' . EXT; // Enable auto-loading of classes spl_autoload_register(array('Kohana', 'auto_load')); // Enable the exception handler // set_exception_handler(array('Kohana', 'exception_handler')); // Enable the error-to-exception handler set_error_handler(array('Kohana', 'error_handler')); // Initialize the environment Kohana::init(); // Create the main instance Kohana::instance(); // Shutdown the environment Kohana::shutdown();
/** * undocumented function * * @param object $setup * @return void * @author Andy Bennett */ public static function get_form_xml($file_name, $model) { $dir = DATAPATH . '/xml/forms/'; $path = $dir . $file_name . '.xml'; if (file_exists($path)) { return file_get_contents($path); } $m = ORM::factory($model); $field_data = $m->field_data($file_name); // print_r($field_data); $view = new View('xform/form'); $view->form = $file_name; $view->field_data = $file_name; $view->name = Kohana::instance()->uri->segment(1); $view->action = Kohana::instance()->uri->segment(2); // $data = $view->render(); $data = $field_data; $f = fopen($path); fwrite($f, $field_data, 'w'); return $data; }
/** * return the page name of the current section * * @return string * @author Andy Bennett */ public function get_section($n = 0) { // get the current page $p = Kohana::instance()->uri->segment(2, 'home'); $t = Kohana::instance()->uri->segment(1, 'page'); // Check number of items in this section. If 1 (i.e. we're top-level) show all children $xpc = $this->sitemap->xpath('//item[@url="/' . $t . '/' . $p . '"]/ancestor-or-self::item'); if ($n < 0) { $n = count($xpc) + ($n - 1); } $n = min(count($xpc) - 1, $n); return basename($xpc[$n]['url']); }
public static function event_item_deleted() { Session::instance()->set_flash('user_message', 'User deleted successfully'); url::redirect(Kohana::instance()->uri->segment(1)); }
/** * replace {} placeholders in the form * * @return void * @author Andy Bennett */ protected function replace_placeholders() { // first convert the form object back to a string $f = $this->data->form_xml_string; // first replace placeholders matching {form_XXXX} with input post data if (preg_match_all('/{form_([a-zA-Z0-9_-]+)}/', $f, $matches)) { for ($i = 0; $i < count($matches[1]); $i++) { $m = $matches[1][$i]; $u = Kohana::instance()->input->post('form_' . $m); $v = $m !== false ? $u : ''; $f = str_replace($matches[0][$i], $v, $f); } } // replace placeholders matching {user_XXXX} with data about the current user if (preg_match_all('/{user_([a-z0-9_-]+)}/', $f, $matches)) { for ($i = 0; $i < count($matches[1]); $i++) { $m = $matches[1][$i]; $v = User::instance()->{$m}; $f = str_replace($matches[0][$i], $v, $f); } } // replace placeholders matching {user_XXXX} with data about the current user if (preg_match_all('/{session_([a-z0-9_-]+)}/', $f, $matches)) { for ($i = 0; $i < count($matches[1]); $i++) { $m = $matches[1][$i]; $v = Session::instance()->get($m); $f = str_replace($matches[0][$i], $v, $f); } } // replace placeholders matching {uri_X} with data from the URI string if (preg_match_all('/{uri_([0-9]+)}/', $f, $matches)) { for ($i = 0; $i < count($matches[1]); $i++) { $m = (int) $matches[1][$i]; $s = Kohana::instance()->uri->segment($m); $v = isset($s) ? $s : ''; $f = str_replace($matches[0][$i], $v, $f); } } if (!isset($this->form_data['controller'])) { $this->form_data['controller'] = URI::instance()->segment(1); } // finally replace any items from form_data foreach ($this->form_data as $k => $v) { if (is_string($v) || is_numeric($v)) { $f = str_replace('{' . $k . '}', $v, $f); } } // now convert the string back to a simplexml object $this->form = simplexml_load_string($f); }
/** * View an id * * @return void * @author Dan Chadwick */ public function view() { $id = Kohana::instance()->input->post('form_id'); parent::view($id); }
/** * event listener - send registration complete email * * @return void * @author Andy Bennett */ public static function register_complete_email() { $data = Event::$data; $data->data['users']['clear_credential'] = Kohana::instance()->input->post('form_credential'); $to = $data->data['users']['email']; $conf = Kohana::config('steamauth.steamauth'); $type = $conf->activation_method; if ($type == 'moderator') { self::register_complete_email_send('activation_link_email_' . $type, $data); self::register_complete_email_send('activation_pending_email', $data, $to); } else { self::register_complete_email_send('activation_link_email_' . $type, $data, $to); } }
} ?> <?php if (Acl::instance()->check(User::instance()->get_role(), null, 'edit')) { ?> <?php echo form::open('/' . $controller . '/edit', ''); ?> <?php echo form::hidden('form_id', $item->id); ?> <?php echo form::hidden('controller', $controller); ?> <?php echo form::hidden('current', Kohana::instance()->uri->string()); ?> <?php echo assets_helper::img_tag('/cache/img/admin/edit_icon.gif', array('alt' => 'Edit', 'name' => 'submit', 'title' => 'Edit this user'), true); ?> <?php echo form::close(); ?> <?php } ?> </td> </tr> <?php $i++; }