Пример #1
0
 /**
  * Display shorts
  *
  * @access     public
  * @return     string
  */
 public function shortcuts()
 {
     // --------------------------------------
     // Fields to select, reused for ordering
     // --------------------------------------
     $select = array('shortcut_id', 'shortcut_name', 'shortcut_label', 'parameters', 'sort_order');
     // --------------------------------------
     // Start query
     // --------------------------------------
     ee()->db->select($select)->from(ee()->low_search_shortcut_model->table());
     // --------------------------------------
     // Filter by shortcut ID
     // --------------------------------------
     if ($shortcut_id = ee()->TMPL->fetch_param('shortcut_id')) {
         list($items, $in) = low_explode_param($shortcut_id);
         ee()->db->{$in ? 'where_in' : 'where_not_in'}('shortcut_id', $items);
     }
     // --------------------------------------
     // Filter by site
     // --------------------------------------
     if ($sites = array_values(ee()->TMPL->site_ids)) {
         ee()->db->where_in('site_id', $sites);
     }
     // --------------------------------------
     // Filter by group ID
     // --------------------------------------
     if ($group_id = ee()->TMPL->fetch_param('group_id')) {
         list($items, $in) = low_explode_param($group_id);
         ee()->db->{$in ? 'where_in' : 'where_not_in'}('group_id', $items);
     }
     // --------------------------------------
     // Filter by short name
     // --------------------------------------
     if ($shortcut_name = ee()->TMPL->fetch_param('shortcut_name')) {
         list($items, $in) = low_explode_param($shortcut_name);
         ee()->db->{$in ? 'where_in' : 'where_not_in'}('shortcut_name', $items);
     }
     // --------------------------------------
     // Order by
     // --------------------------------------
     if (($orderby = ee()->TMPL->fetch_param('orderby', 'sort_order')) && in_array($orderby, $select)) {
         $sort = strtolower(ee()->TMPL->fetch_param('sort', 'asc'));
         if (!in_array($sort, array('asc', 'desc'))) {
             $sort = 'asc';
         }
         ee()->db->order_by($orderby, $sort);
     }
     // --------------------------------------
     // Limit, offset
     // --------------------------------------
     if (($limit = ee()->TMPL->fetch_param('limit', 100)) && is_numeric($limit)) {
         $offset = (int) ee()->TMPL->fetch_param('offset', 0);
         ee()->db->limit($limit, $offset);
     }
     // --------------------------------------
     // Get the rows
     // --------------------------------------
     $rows = ee()->db->get()->result_array();
     // --------------------------------------
     // Nothing? No results
     // --------------------------------------
     if (empty($rows)) {
         $this->_log('No shortcuts found');
         return ee()->TMPL->no_results();
     }
     // --------------------------------------
     // Are there {shortcut_url result_page=""} vars?
     // --------------------------------------
     $urls = array();
     foreach (low_array_get_prefixed(ee()->TMPL->var_single, 'shortcut_url') as $var) {
         $urls[$var] = array();
         // Read out the parameters so we can override them
         if (preg_match_all("/([\\w\\-:]+)\\s*=\\s*('|\")(.+?)\\2/", $var, $matches)) {
             foreach ($matches[0] as $i => $val) {
                 $urls[$var][$matches[1][$i]] = $matches[3][$i];
             }
         }
     }
     // --------------------------------------
     // Modify the rows
     // --------------------------------------
     foreach ($rows as &$row) {
         $params = low_search_decode($row['parameters'], FALSE);
         foreach ($urls as $key => $val) {
             $row[$key] = $this->_create_url(array_merge($params, $val));
         }
         // Don't need the raw json
         unset($row['parameters']);
     }
     // --------------------------------------
     // Parse it, dawg
     // --------------------------------------
     $tagdata = ee()->TMPL->parse_variables(ee()->TMPL->tagdata, $rows);
     return $tagdata;
 }
Пример #2
0
 /**
  * Get prefixed parameters
  *
  * @access     public
  * @param      string
  * @return     array
  */
 public function get_prefixed($prefix = '', $strip = FALSE)
 {
     return low_array_get_prefixed($this->_params, $prefix, $strip);
 }