Esempio n. 1
0
 /**
  * Filters
  *
  * @access      public
  * @return      string
  */
 public function filters()
 {
     // --------------------------------------
     // Load up language file
     // --------------------------------------
     ee()->lang->loadfile($this->package);
     // --------------------------------------
     // Read parameters
     // --------------------------------------
     $this->params->set();
     // --------------------------------------
     // Overwrite with shortcut?
     // --------------------------------------
     $this->_get_shortcut();
     // --------------------------------------
     // Prep params for template variables
     // --------------------------------------
     $vars = array();
     foreach ($this->params->get() as $key => $val) {
         $vars[$this->settings->prefix . $key . ':raw'] = $val;
         $vars[$this->settings->prefix . $key] = low_format($val);
     }
     // --------------------------------------
     // Add shortcut data to vars
     // --------------------------------------
     if ($this->shortcut) {
         foreach (ee()->low_search_shortcut_model->get_template_attrs() as $key) {
             $vars[$this->settings->prefix . $key] = $this->shortcut[$key];
         }
     }
     // --------------------------------------
     // Get search collections for this site
     // --------------------------------------
     // Check to see whether we actually need to get collections
     $get_collections = FALSE;
     $collections = array();
     $active_collections = array();
     // Get them only if the var pair exists
     foreach (low_array_get_prefixed(ee()->TMPL->var_pair, 'collections') as $val) {
         $this->_log('Collections variable pair found');
         $get_collections = TRUE;
         // Is the 'show' parameter set?
         // If so, get the ids
         if (isset($val['show'])) {
             $get_collections = $val['show'];
         }
     }
     // Get the collections if necessary
     if ($get_collections !== FALSE) {
         $this->_log('Getting search collection details');
         // --------------------------------------
         // Possibly limit by ids
         // --------------------------------------
         $collections = array();
         $site_collections = ee()->low_search_collection_model->get_by_site(array_values(ee()->TMPL->site_ids));
         if ($get_collections !== TRUE) {
             list($show, $in) = low_explode_param($get_collections);
             $key = low_array_is_numeric($show) ? 'collection_id' : 'collection_name';
             $site_collections = low_associate_results($site_collections, $key);
             foreach ($site_collections as $id => $row) {
                 if ($in === in_array($id, $show)) {
                     $collections[] = $row;
                 }
             }
         } else {
             $collections = array_values($site_collections);
         }
         // --------------------------------------
         // Define collection meta data
         // --------------------------------------
         $meta = array('collection_count' => 0, 'total_collections' => count($collections));
         // --------------------------------------
         // Get array of active collections
         // --------------------------------------
         $col = $this->params->get('collection');
         if (!empty($col)) {
             if (is_string($col)) {
                 list($active_collections, $in) = low_explode_param($col);
             } elseif (is_array($col)) {
                 $active_collections = $col;
             }
         }
         // --------------------------------------
         // Loop thru collections, modify rows
         // --------------------------------------
         // Numeric collections?
         $attr = low_array_is_numeric($active_collections) ? 'collection_id' : 'collection_name';
         foreach ($collections as &$row) {
             // Forget some
             unset($row['site_id'], $row['settings']);
             // Make strings html-safe
             $row = array_map('htmlspecialchars', $row);
             // Is collection selected?
             $row['collection_is_active'] = in_array($row[$attr], $active_collections) ? 'y' : '';
             // Increment collection count
             $meta['collection_count']++;
             // Merge meta with row
             $row = array_merge($row, $meta);
         }
     }
     // --------------------------------------
     // Add collections to vars array
     // --------------------------------------
     $vars['collections'] = $vars[$this->settings->prefix . 'collections'] = $collections;
     // --------------------------------------
     // Handle error messages
     // --------------------------------------
     // Main error message
     $vars['error_message'] = ee()->session->flashdata('error_message');
     // Errors per field
     if (($errors = ee()->session->flashdata('errors')) && is_array($errors)) {
         foreach ($errors as $field) {
             $vars[$this->settings->prefix . $field . '_missing'] = TRUE;
         }
     }
     // --------------------------------------
     // Parse it now
     // --------------------------------------
     $tagdata = ee()->TMPL->parse_variables_row(ee()->TMPL->tagdata, $vars);
     $tagdata = $this->_post_parse($tagdata);
     // --------------------------------------
     // Return output
     // --------------------------------------
     return $tagdata;
 }
 /**
  * Get collection IDs by parameter on a site ID
  *
  * @access      public
  * @param       int      Site ID
  * @return      array
  */
 public function get_by_param($param)
 {
     list($ids, $in) = low_explode_param($param);
     $attr = low_array_is_numeric($ids) ? $this->pk() : 'collection_name';
     return $this->_get_by_attr($ids, $attr, $in);
 }
Esempio n. 3
0
 /**
  * Get site ids by parameter
  *
  * @access      private
  * @return      void
  */
 private function _set_site_ids()
 {
     // Reset
     $this->_site_ids = array();
     if (empty($this->_params['site'])) {
         // No site param? limit to current site only
         $this->_site_ids[] = ee()->config->item('site_id');
     } else {
         // Read sites from parameter
         list($sites, $in) = low_explode_param($this->_params['site']);
         // Shortcut to all sites
         $all_sites = ee()->TMPL->sites;
         // Numeric?
         $check = low_array_is_numeric($sites) ? 'key' : 'val';
         // Loop through all sites and add some of them
         foreach ($all_sites as $key => $val) {
             if ($in === in_array(${$check}, $sites)) {
                 $this->_site_ids[$val] = $key;
             }
         }
         // And set to global TMPL
         ee()->TMPL->site_ids = $this->_site_ids;
     }
 }