Ejemplo n.º 1
0
 public function _remap($method, $params = array())
 {
     // First we see if this is a registered plugin.
     if (!CMS\Libraries\Plugins::is_registered($method)) {
         show_404();
     }
     // If there is no method we assume it is the index method.
     if (!isset($params[0])) {
         $params[0] = 'index';
     }
     // Get an instance of the class
     $instance = CMS\Libraries\Plugins::get($method);
     if (!$instance) {
         show_404();
     }
     // Setup args.
     $args = $params;
     unset($args[0]);
     // Hand the request of to another class / function.
     if (method_exists($instance, $params[0])) {
         // Do we want to include the CMS template.
         if (isset($instance->layout) && $instance->layout == false) {
             $output = call_user_func_array(array($instance, $params[0]), $args);
             $this->output->set_output($output);
             return true;
         }
         // We default to showing the CMS layout.
         $output = $this->load->view('cms/templates/app-header', $this->data, true);
         $output .= call_user_func_array(array($instance, $params[0]), $args);
         $output .= $this->load->view('cms/templates/app-footer', $this->data, true);
         $this->output->set_output($output);
     } else {
         show_404();
     }
 }
Ejemplo n.º 2
0
 function get()
 {
     $model = '';
     // Set which model we are going to get data from.
     switch ($this->input->get('type')) {
         case 'users':
             $this->load->model('cms_users_model');
             $model = 'cms_users_model';
             break;
         case 'blocks':
             $this->load->model('cms_blocks_model');
             $model = 'cms_blocks_model';
             break;
         case 'buckets':
             $this->load->model('cms_buckets_model');
             $model = 'cms_buckets_model';
             break;
         case 'bucket-reorder':
             $this->load->model('cms_buckets_model');
             $bucket = $this->cms_buckets_model->get_by_id($this->input->get('bucket'));
             $this->load->model('bucketdata_model');
             $this->bucketdata_model->set_table($bucket['CMS_BucketsTable']);
             $this->bucketdata_model->reorder($this->input->post('ids'));
             $this->_return_data(array());
             return;
             break;
         case 'bucket-next':
             $this->load->model('bucketdata_model');
             $this->load->model('cms_buckets_model');
             // Get bucket.
             if (!($bucket = $this->cms_buckets_model->get_by_id($this->input->get_post('bucket')))) {
                 die('Nothing to see here.');
             }
             // Set table.
             $table = $bucket['CMS_BucketsTable'];
             $id = $table . 'Id';
             $current = $this->input->get_post('current');
             $order = $table . 'Order';
             // Get the order of the current entry.
             $curr_entry = $this->db->query("SELECT {$order} AS Ord FROM {$table} WHERE {$id} = {$current}")->row_array();
             // Get next entry.
             $data = $this->db->query("SELECT * FROM {$table} WHERE {$order} > {$curr_entry['Ord']} ORDER BY {$order} LIMIT 1")->result_array();
             if (isset($data[0])) {
                 $this->_return_data(array('Id' => $data[0][$id]));
             } else {
                 $this->_return_data(array());
             }
             return;
             break;
         case 'bucket':
             // See if we have assigned a custom function to handle this data return.
             $cust = CMS\Libraries\Plugins::run_custom_api_call('get', $this->input->get_post('bucket'));
             if (!is_null($cust)) {
                 $this->_return_data($cust);
                 return;
             }
             // Default API return.
             $this->load->model('bucketdata_model');
             $this->load->model('cms_buckets_model');
             if (!($bucket = $this->cms_buckets_model->get_by_id($this->input->get_post('bucket')))) {
                 die('Nothing to see here.');
             }
             $this->bucketdata_model->set_table($bucket['CMS_BucketsTable']);
             // See if we have any relations to add.
             if (isset($bucket['CMS_BucketsListview']['joins']) && is_array($bucket['CMS_BucketsListview']['joins'])) {
                 foreach ($bucket['CMS_BucketsListview']['joins'] as $key => $row) {
                     $this->bucketdata_model->set_join($row['table'], $row['left'], $row['right'], $row['type']);
                 }
             }
             $model = 'bucketdata_model';
             break;
         case 'media':
             $this->load->model('cms_media_model');
             $model = 'cms_media_model';
             break;
         default:
             die('Nothing to see here.');
             break;
     }
     // Set order
     if ($this->input->get_post('order')) {
         if ($this->input->get_post('sort')) {
             $this->{$model}->set_order($this->input->get_post('order') . ' ' . $this->input->get_post('sort'));
         } else {
             $this->{$model}->set_order($this->input->get_post('order'));
         }
     }
     // Set limit / offset
     if ($this->input->get_post('limit')) {
         if ($this->input->get_post('offset')) {
             $this->{$model}->set_limit($this->input->get_post('limit'), $this->input->get_post('offset'));
         } else {
             $this->{$model}->set_limit($this->input->get_post('limit'));
         }
     }
     // Set search
     if ($this->input->get_post('search')) {
         $this->{$model}->set_search($this->input->get_post('search'));
     }
     // No expired
     if ($this->input->get_post('no_end_expired')) {
         $this->{$model}->set_no_end_expired();
     }
     // Only expired
     if ($this->input->get_post('only_end_expired')) {
         $this->{$model}->set_only_end_expired();
     }
     // Return data.
     $data = $this->{$model}->get();
     // Get a total count.
     if ($this->input->get_post('search')) {
         $this->{$model}->set_search($this->input->get_post('search'));
     }
     $d = $this->{$model}->get();
     $count = count($d);
     $this->_return_data($data, $count);
 }