Beispiel #1
0
 /**
  * Settings
  *
  * @access     public
  * @param      array
  * @return     array
  */
 public function settings()
 {
     // -------------------------------------------
     // Get member groups with access to CP
     // -------------------------------------------
     $query = ee()->db->select('group_id, group_title')->from('member_groups')->where('can_access_cp', 'y')->order_by('group_title')->get();
     $groups = low_flatten_results($query->result_array(), 'group_title', 'group_id');
     // -------------------------------------------
     // Return list of groups
     // -------------------------------------------
     return array('can_create_sets' => array('ms', $groups, $this->default_settings['can_create_sets']));
 }
 /**
  * Display input field for regular user
  *
  * @access     public
  * @param      int       $var_id        The id of the variable
  * @param      string    $var_data      The value of the variable
  * @param      array     $var_settings  The settings of the variable
  * @return     string
  */
 function display_input($var_id, $var_data, $var_settings)
 {
     // Keep track of all LR Sets
     static $sets;
     // Get them if not existing
     if (!$sets) {
         $query = $this->EE->db->select('set_id, set_label')->from('low_reorder_sets')->where('site_id', $this->EE->config->item('site_id'))->order_by('set_label', 'asc')->get();
         $sets = low_flatten_results($query->result_array(), 'set_label', 'set_id');
     }
     // Prepend empty option
     $options = array('' => '--') + $sets;
     // Return select element
     return form_dropdown("var[{$var_id}]", $options, $var_data);
 }
Beispiel #3
0
 /**
  * Allows for category groups filtering: (1|2|3) && (4|5|6)
  *
  * @access     public
  * @return     void
  */
 public function filter($entry_ids)
 {
     // --------------------------------------
     // See if there are groups present, with correct values
     // --------------------------------------
     $groups = array_filter($this->params->get_prefixed('category:'), 'low_param_is_numeric');
     // --------------------------------------
     // Bail out if there are no groups
     // --------------------------------------
     if (empty($groups)) {
         return $entry_ids;
     }
     // --------------------------------------
     // Log it
     // --------------------------------------
     $this->_log('Applying ' . __CLASS__);
     // --------------------------------------
     // Loop through groups, compose SQL
     // --------------------------------------
     foreach ($groups as $key => $val) {
         // Prep the value
         $val = $this->params->prep($key, $val);
         // Get the parameter
         list($ids, $in) = low_explode_param($val);
         // Match all?
         $all = (bool) strpos($val, '&');
         // One query per group
         ee()->db->select('entry_id')->from('category_posts')->{$in ? 'where_in' : 'where_not_in'}('cat_id', $ids);
         // Limit by already existing ids
         if ($entry_ids) {
             ee()->db->where_in('entry_id', $entry_ids);
         }
         // Do the having-trick to account for *all* given entry ids
         if ($in && $all) {
             ee()->db->select('COUNT(*) AS num')->group_by('entry_id')->having('num', count($ids));
         }
         // Execute query
         $query = ee()->db->get();
         // And get the entry ids
         $entry_ids = low_flatten_results($query->result_array(), 'entry_id');
         $entry_ids = array_unique($entry_ids);
         // Bail out if there aren't any matches
         if (is_array($entry_ids) && empty($entry_ids)) {
             break;
         }
     }
     return $entry_ids;
 }
 /**
  * Display settings sub-form for this variable type
  *
  * @param	mixed	$var_id			The id of the variable: 'new' or numeric
  * @param	array	$var_settings	The settings of the variable
  * @return	array
  */
 function display_settings($var_id, $var_settings)
 {
     // -------------------------------------
     //  Init return value
     // -------------------------------------
     $r = array();
     // -------------------------------------
     //  Check current value from settings
     // -------------------------------------
     $folders = $this->get_setting('folders', $var_settings);
     // -------------------------------------
     //  Get all folders
     // -------------------------------------
     $all_folders = low_flatten_results($this->_get_upload_preferences(), 'name', 'id');
     // -------------------------------------
     //  Build options setting
     // -------------------------------------
     $r[] = array($this->setting_label(lang('file_folders')), form_multiselect($this->input_name('folders', TRUE), $all_folders, $folders));
     // -------------------------------------
     //  Build setting: Allow uploads?
     // -------------------------------------
     $upload_folders = array('0' => lang('no_uploads')) + $all_folders;
     $upload = $this->get_setting('upload', $var_settings);
     $overwrite = $this->get_setting('overwrite', $var_settings) == 'y';
     $r[] = array($this->setting_label(lang('upload_folder'), lang('upload_folder_help')), form_dropdown($this->input_name('upload'), $upload_folders, $upload, 'id="low-select-upload-folder"') . '<label class="low-checkbox low-inline" id="low-overwrite-files">' . form_checkbox($this->input_name('overwrite'), 'y', $overwrite) . lang('overwrite_existing_files_label') . '</label>');
     // -------------------------------------
     //  Build setting: multiple?
     // -------------------------------------
     $multiple = $this->get_setting('multiple', $var_settings) == 'y';
     $r[] = array($this->setting_label(lang('allow_multiple_files')), '<label class="low-checkbox">' . form_checkbox($this->input_name('multiple'), 'y', $multiple, 'class="low-allow-multiple"') . lang('allow_multiple_files_label') . '</label>');
     // -------------------------------------
     //  Build setting: separator
     // -------------------------------------
     $separator = $this->get_setting('separator', $var_settings);
     $r[] = array($this->setting_label(lang('separator_character')), $this->separator_select($separator));
     // -------------------------------------
     //  Build setting: multi interface
     // -------------------------------------
     $multi_interface = $this->get_setting('multi_interface', $var_settings);
     $r[] = array($this->setting_label(lang('multi_interface')), $this->interface_select($multi_interface, array('drag-list-thumbs' => lang('drag-list-thumbs'))));
     // -------------------------------------
     //  Return output
     // -------------------------------------
     return $r;
 }
Beispiel #5
0
 /**
  * Update routines for version 2.0b1
  *
  * @access      private
  * @return      void
  */
 private function _v20b1()
 {
     // --------------------------------------
     // Install new tables
     // --------------------------------------
     ee()->low_reorder_set_model->install();
     ee()->low_reorder_order_model->install();
     // --------------------------------------
     // Get all current records from settings
     // --------------------------------------
     $query = ee()->db->get('low_reorder_settings');
     $rows = $query->result_array();
     // Return if no settings exist
     if (!empty($rows)) {
         // Upgrading from EE1
         if (!isset($rows[0]['channel_id'])) {
             foreach ($rows as &$r) {
                 $r['channel_id'] = $r['weblog_id'];
             }
         }
         // --------------------------------------
         // Get Field, Channel and Status details
         // --------------------------------------
         // Fields
         $query = ee()->db->select('field_id, site_id, field_name, field_label, field_instructions')->from('channel_fields')->where_in('field_id', low_flatten_results($rows, 'field_id'))->get();
         $fields = low_associate_results($query->result_array(), 'field_id');
         // Channels
         $query = ee()->db->select('channel_id, channel_name, channel_title, cat_group')->from('channels')->where_in('channel_id', low_flatten_results($rows, 'channel_id'))->get();
         $channels = low_associate_results($query->result_array(), 'channel_id');
         // Statuses
         $query = ee()->db->select('status_id, status')->from('statuses')->get();
         $statuses = low_flatten_results($query->result_array(), 'status', 'status_id');
         // --------------------------------------
         // Loop through rows and populate new table
         // --------------------------------------
         foreach ($rows as $row) {
             // Skip non-existent channels or fields
             if (!(isset($channels[$row['channel_id']]) && isset($fields[$row['field_id']]))) {
                 continue;
             }
             // Shortcut to related channel and field
             $channel = $channels[$row['channel_id']];
             $field = $fields[$row['field_id']];
             // Decode the settings
             $settings = decode_reorder_settings($row['settings']);
             // Initiate parameter array
             $params = array();
             // --------------------------------------
             // Set Channel parameter
             // --------------------------------------
             $params['channel'] = $channels[$row['channel_id']]['channel_name'];
             // --------------------------------------
             // Set Category parameter
             // --------------------------------------
             if (!empty($settings['categories'])) {
                 $params['category'] = implode('|', array_filter($settings['categories']));
             }
             // --------------------------------------
             // Set Status parameter
             // --------------------------------------
             if (!empty($settings['statuses'])) {
                 $tmp = array();
                 foreach ($settings['statuses'] as $status_id) {
                     $tmp[] = $statuses[$status_id];
                 }
                 $params['status'] = implode('|', array_unique($tmp));
                 unset($tmp);
             }
             // --------------------------------------
             // Set Show Expired parameter
             // --------------------------------------
             if (!empty($settings['show_expired']) && ($settings['show_expired'] == 'y' or $settings['show_expired'] === TRUE)) {
                 $params['show_expired'] = 'yes';
             }
             // --------------------------------------
             // Set Show Future Entries parameter
             // --------------------------------------
             if (!empty($settings['show_future']) && ($settings['show_future'] == 'y' or $settings['show_future'] === TRUE)) {
                 $params['show_future_entries'] = 'yes';
             }
             // --------------------------------------
             // Get permissions from settings
             // --------------------------------------
             $permissions = !empty($settings['permissions']) ? low_array_encode($settings['permissions']) : '';
             // --------------------------------------
             // Set Category Option value
             // --------------------------------------
             $cat_option = $settings['category_options'];
             // --------------------------------------
             // Set Category Groups value, if option is 'one'
             // --------------------------------------
             if ($cat_option == 'one' && $channel['cat_group']) {
                 $cat_groups = low_linearize(explode('|', $channel['cat_group']));
             } else {
                 $cat_groups = '';
             }
             // --------------------------------------
             // Set clear_cache value
             // --------------------------------------
             $clear_cache = !empty($settings['clear_cache']) && $settings['clear_cache'] == 'n' ? 'n' : 'y';
             // --------------------------------------
             // Sort order setting
             // --------------------------------------
             $reverse = @$settings['sort_order'] == 'desc';
             // --------------------------------------
             // Insert new row
             // --------------------------------------
             $set_id = ee()->low_reorder_set_model->insert(array('site_id' => $field['site_id'], 'set_label' => $channel['channel_title'] . ', ' . $field['field_label'], 'set_notes' => $field['field_instructions'], 'new_entries' => $reverse ? 'prepend' : 'append', 'clear_cache' => $clear_cache, 'channels' => low_linearize(array($row['channel_id'])), 'cat_option' => $cat_option, 'cat_groups' => $cat_groups, 'parameters' => low_array_encode($params), 'permissions' => $permissions));
             // --------------------------------------
             // Get current values
             // --------------------------------------
             ee()->db->select("GROUP_CONCAT(DISTINCT d.entry_id ORDER BY d.field_id_{$field['field_id']} ASC SEPARATOR '|') AS entries", FALSE)->from('channel_data d')->where('d.channel_id', $channel['channel_id'])->where("d.field_id_{$field['field_id']} !=", '');
             if ($cat_option != 'one') {
                 ee()->db->select("'0' AS cat_id", FALSE);
             } else {
                 ee()->db->select('cp.cat_id')->from('category_posts cp')->where('d.entry_id = cp.entry_id')->group_by('cat_id');
             }
             $query = ee()->db->get();
             foreach ($query->result() as $row) {
                 $entries = low_delinearize($row->entries);
                 if ($reverse) {
                     $entries = array_reverse($entries);
                 }
                 ee()->low_reorder_order_model->insert(array('set_id' => $set_id, 'cat_id' => $row->cat_id, 'sort_order' => low_linearize($entries)));
             }
         }
     }
     // end if $rows
     // --------------------------------------
     // Change low_reorder fieldtype to text
     // --------------------------------------
     ee()->db->where('field_type', $this->package);
     ee()->db->update('channel_fields', array('field_type' => 'text', 'field_settings' => low_array_encode(array('field_content_type' => 'text'))));
     // --------------------------------------
     // Remove low_reorder fieldtype
     // --------------------------------------
     ee()->db->where('name', $this->package);
     ee()->db->delete('fieldtypes');
     // --------------------------------------
     // Drop old table
     // --------------------------------------
     ee()->db->query("DROP TABLE IF EXISTS `exp_low_reorder_settings`");
     // --------------------------------------
     // Enable extension
     // --------------------------------------
     foreach ($this->hooks as $hook) {
         $this->_add_hook($hook);
     }
 }
 /**
  * Display input field for regular user
  *
  * @param	int		$var_id			The id of the variable
  * @param	string	$var_data		The value of the variable
  * @param	array	$var_settings	The settings of the variable
  * @return	string
  */
 public function display_input($var_id, $var_data, $var_settings)
 {
     // -------------------------------------
     //  Prep options
     // -------------------------------------
     $settings = array();
     foreach ($this->default_settings as $key => $val) {
         $settings[$key] = $this->get_setting($key, $var_settings);
     }
     // -------------------------------------
     //  Prep current data
     // -------------------------------------
     $current = explode($this->separators[$settings['separator']], $var_data);
     $now = ee()->localize->now;
     // -------------------------------------
     //  Get entries
     // -------------------------------------
     ee()->db->select(array('t.entry_id', 't.title'))->from('channel_titles AS t');
     // Filter out future entries
     if ($settings['show_future'] != 'y') {
         ee()->db->where('t.entry_date <=', $now);
     }
     // Filter out expired entries
     if ($settings['show_expired'] != 'y') {
         ee()->db->where("(t.expiration_date > {$now} OR t.expiration_date = 0)");
     }
     // Filter by channel
     if ($filtered_channels = array_filter((array) $settings['channels'])) {
         ee()->db->where_in('t.channel_id', $filtered_channels);
     }
     // Filter by category
     if ($filtered_categories = array_filter((array) $settings['categories'])) {
         ee()->db->join('category_posts AS cp', 't.entry_id = cp.entry_id');
         ee()->db->where_in('cp.cat_id', $filtered_categories);
     }
     // Filter by status
     if ($filtered_statuses = array_filter((array) $settings['statuses'])) {
         ee()->db->where_in('t.status', $filtered_statuses);
     }
     // Order by custom order
     ee()->db->order_by($settings['orderby'], $settings['sort']);
     // Limit entries
     if ($settings['limit']) {
         ee()->db->limit($settings['limit']);
     }
     $query = ee()->db->get();
     $entries = low_flatten_results($query->result_array(), 'title', 'entry_id');
     // -------------------------------------
     //  Create interface
     // -------------------------------------
     if ($settings['multiple'] == 'y' && $settings['multi_interface'] == 'drag-list') {
         $r = $this->drag_lists($var_id, $entries, $current);
     } else {
         $r = $this->select_element($var_id, $entries, $current, $settings['multiple'] == 'y');
     }
     // -------------------------------------
     //  Return select element
     // -------------------------------------
     return $r;
 }
Beispiel #7
0
 /**
  * Allows for tag filtering: (1|2|3) && (4|5|6)
  *
  * @access     public
  * @return     void
  */
 public function filter($entry_ids)
 {
     // -------------------------------------------
     // Make sure addons-library is loaded
     // -------------------------------------------
     ee()->load->library('addons');
     // -------------------------------------------
     // Solspace Tag or DevDemon Tagger?
     // -------------------------------------------
     if (ee()->addons->is_package('tag')) {
         $tables = array('tag_tags', 'tag_entries');
     } elseif (ee()->addons->is_package('tagger')) {
         $tables = array('tagger', 'tagger_links');
     }
     // --------------------------------------
     // See if there are tag params present
     // --------------------------------------
     $tag_names = $this->params->get_prefixed('tag_name');
     $tag_ids = $this->params->get_prefixed('tag_id');
     // --------------------------------------
     // Bail out if there are no tags
     // --------------------------------------
     if (empty($tables) || empty($tag_names) && empty($tag_ids)) {
         return $entry_ids;
     }
     // --------------------------------------
     // Log it
     // --------------------------------------
     $this->_log('Applying ' . __CLASS__);
     // -------------------------------------------
     // Check tag names and convert to tag IDs
     // -------------------------------------------
     if ($tag_names) {
         $unique_tags = array();
         foreach ($tag_names as $key => $val) {
             // Get the tags
             list($tags, $in) = low_explode_param($val);
             $unique_tags = array_merge($unique_tags, $tags);
         }
         // Remove duplicates and convert
         $unique_tags = array_unique($unique_tags);
         $unique_tags = array_map(array($this, '_convert_tag'), $unique_tags);
         // Get IDs for unique tags
         $query = ee()->db->select('tag_id, tag_name')->from($tables[0])->where_in('site_id', $this->params->site_ids())->where_in('tag_name', $unique_tags)->get();
         // clean up
         unset($unique_tags);
         // Get tag map: [tag name] => tag_id
         $tag_map = low_flatten_results($query->result_array(), 'tag_id', 'tag_name');
         // Now, loop through original tags thing and convert to tag IDs
         foreach ($tag_names as $key => $val) {
             // Initiate tag ids
             $ids = array();
             // Read parameter value
             list($tags, $in) = low_explode_param($val);
             // Loop through tags and map them to IDs
             foreach ($tags as $tag) {
                 $tag = $this->_convert_tag($tag);
                 if (isset($tag_map[$tag])) {
                     $ids[] = $tag_map[$tag];
                 }
             }
             if ($ids) {
                 // Check separator and implode back to parameter
                 $sep = strpos($val, '&') === FALSE ? '|' : '&';
                 $str = implode($sep, $ids);
                 // Add negator back
                 if (!$in) {
                     $str = 'not ' . $ids;
                 }
                 // Add final parameter string to IDs
                 $tag_ids[$key] = $str;
             }
         }
     }
     // --------------------------------------
     // Get channel IDs before starting the query
     // --------------------------------------
     $channel_ids = ee()->low_search_collection_model->get_channel_ids($this->params->get('collection'));
     // --------------------------------------
     // Loop through groups, compose SQL
     // --------------------------------------
     foreach ($tag_ids as $key => $val) {
         // Prep the value
         $val = $this->params->prep($key, $val);
         // Get the parameter
         list($ids, $in) = low_explode_param($val);
         // Match all?
         $all = (bool) strpos($val, '&');
         // One query per group
         ee()->db->distinct()->select('entry_id')->from($tables[1])->where_in('site_id', $this->params->site_ids())->{$in ? 'where_in' : 'where_not_in'}('tag_id', $ids);
         // Limit by already existing ids
         if ($entry_ids) {
             ee()->db->where_in('entry_id', $entry_ids);
         }
         // Limit by channel ID
         if ($channel_ids) {
             ee()->db->where_in('channel_id', $channel_ids);
         }
         // Do the having-trick to account for *all* given entry ids
         if ($in && $all) {
             ee()->db->select('COUNT(*) AS num')->group_by('entry_id')->having('num', count($ids));
         }
         // Execute query
         $query = ee()->db->get();
         // And get the entry ids
         $entry_ids = low_flatten_results($query->result_array(), 'entry_id');
         // Bail out if there aren't any matches
         if (is_array($entry_ids) && empty($entry_ids)) {
             break;
         }
     }
     return $entry_ids;
 }
 /**
  * Get oldest index for given collection or all collections
  *
  * @access      public
  * @param       int
  * @param       array
  * @return      void
  */
 public function get_oldest_index($collection_id = FALSE)
 {
     ee()->db->select('collection_id, MIN(index_date) AS index_date')->from($this->table())->where('site_id', $this->site_id)->group_by('collection_id');
     // Limit by given collection
     if ($collection_id) {
         ee()->db->where('collection_id', $collection_id);
     }
     $query = ee()->db->get();
     // Return array of collection_id => index_date
     return low_flatten_results($query->result_array(), 'index_date', 'collection_id');
 }
Beispiel #9
0
 /**
  * Modify a row for a search result for this filter
  */
 public function results($rows)
 {
     // -------------------------------------------
     // Shortcut to prefix
     // -------------------------------------------
     $pfx = ee()->low_search_settings->prefix;
     // -------------------------------------------
     // Prep collection info
     // -------------------------------------------
     if (!$this->_collections && $this->_results) {
         $col_ids = low_flatten_results($this->_results, 'collection_id');
         $col_ids = array_unique($col_ids);
         $this->_collections = ee()->low_search_collection_model->get_by_id($col_ids);
     }
     // -------------------------------------------
     // Loop through results and do yer thing
     // -------------------------------------------
     foreach ($rows as &$row) {
         // Get score for this entry
         $row[$pfx . 'score'] = $this->_get_score($row['entry_id']);
         // Add collection info to row
         foreach ($this->_get_collection_info($row['entry_id']) as $key => $val) {
             $row[$pfx . $key] = $val;
         }
     }
     // -------------------------------------------
     // No excerpt var in tagdata? No need to proceed.
     // -------------------------------------------
     if (strpos(ee()->TMPL->tagdata, $pfx . 'excerpt') === FALSE) {
         return $rows;
     }
     // -------------------------------------------
     // Load typography lib
     // -------------------------------------------
     ee()->load->library('typography');
     // -------------------------------------------
     // Get all entry ids we're working with
     // -------------------------------------------
     $entry_ids = low_flatten_results($rows, 'entry_id');
     // -------------------------------------------
     // Loop through results and add the excerpt
     // -------------------------------------------
     foreach ($rows as &$row) {
         // Get excerpt ID, the field ID to use as excerpt; 0 for title
         $eid = $this->_get_excerpt_id($row);
         // Skip if no valid excerpt ID is found
         if ($eid === FALSE) {
             continue;
         }
         // Get string and format for excerpt
         $str = $eid == '0' || !isset($row['field_id_' . $eid]) ? $row['title'] : $row['field_id_' . $eid];
         $fmt = $eid == '0' || !isset($row['field_fmt_' . $eid]) ? 'xhtml' : $row['field_fmt_' . $eid];
         // -------------------------------------------
         // 'low_search_excerpt' hook
         // - change the excerpt for an entry
         // -------------------------------------------
         if (ee()->extensions->active_hook('low_search_excerpt') === TRUE) {
             $str = ee()->extensions->call('low_search_excerpt', $entry_ids, $row, $eid);
             // Check return value
             if (is_array($str) && count($str) == 2) {
                 // Set excerpt string to first item in array
                 list($str, $skip) = $str;
                 // If second item in return value, skip native creation of excerpt
                 if ($skip === TRUE) {
                     $row[$pfx . 'excerpt'] = $str;
                     continue;
                 }
             }
         }
         // Overwrite empty excerpt with formatted one
         $row[$pfx . 'excerpt'] = $this->_create_excerpt($str, $fmt);
         // Highlight keywords if we have 'em
         if ($this->_keywords) {
             $row[$pfx . 'excerpt'] = $this->_highlight($row[$pfx . 'excerpt']);
             if (ee()->low_search_settings->get('title_hilite') == 'y') {
                 $row['title'] = $this->_highlight($row['title']);
             }
         }
     }
     return $rows;
 }
Beispiel #10
0
 /**
  * Filter the set's entry ids according to parameters
  *
  * @access     private
  * @return     void
  */
 private function _filter_entry_ids()
 {
     // Set/Cat key
     $key = $this->set_id . '-' . $this->cat_id;
     // Get entries from cache
     $entries = array_filter((array) low_get_cache(LOW_REORDER_PACKAGE, 'entry_ids'));
     if (!isset($entries[$key])) {
         // Log to template
         $this->_log('Getting ordered entry_ids from database');
         // Add channel_id and entry_id as parameter
         $params = $this->set['parameters'];
         $params['channel_id'] = implode('|', $this->set['channels']);
         $params['entry_id'] = implode('|', $this->entry_ids);
         // Fetch from DB
         $filtered = low_flatten_results($this->get_entries($params, FALSE), 'entry_id');
         // Intersect to preserve the order
         $filtered = array_filter(array_intersect($this->entry_ids, $filtered));
         $filtered = array_values($filtered);
         // Add to cache
         $entries[$key] = $filtered;
         low_set_cache(LOW_REORDER_PACKAGE, 'entry_ids', $entries);
         // Clean up
         unset($filtered);
     } else {
         // Log to template
         $this->_log('Getting ordered entry_ids from cache');
     }
     // Set the working entry ids to the filtered ones
     $this->entry_ids = $entries[$key];
 }
 /**
  * Takes a DB result set, returns 'flat' array with key => val
  *
  * @param	array	$result_set		array with arrays (1 per result)
  * @param	string	$key			key value for flat array
  * @param	string	$val			value value for flat array
  * @return	array
  */
 protected function flatten_results($result_set, $key, $val)
 {
     return low_flatten_results($result_set, $val, $key);
 }
Beispiel #12
0
 /**
  * Build collection index
  *
  * @access      protected
  * @return      array
  */
 public function build($collection_id = FALSE, $entry_ids = FALSE, $start = FALSE)
 {
     // --------------------------------------
     // Check for collection_id or entry_id
     // --------------------------------------
     $collection_id = $collection_id !== FALSE ? $collection_id : ee()->input->get_post('collection_id');
     $entry_ids = $entry_ids !== FALSE ? $entry_ids : ee()->input->get_post('entry_id');
     // --------------------------------------
     // Either collection_id or entry_id or both must be given
     // --------------------------------------
     if (!($collection_id || $entry_ids)) {
         show_error(ee()->lang->line('not_authorized'));
     }
     // --------------------------------------
     // Start building query to get collection details
     // --------------------------------------
     ee()->db->select('lsc.collection_id, lsc.channel_id, lsc.settings, lsc.site_id');
     ee()->db->from('low_search_collections lsc');
     // --------------------------------------
     // If there's a collection id, limit query by that one
     // --------------------------------------
     if ($collection_id) {
         ee()->db->where('lsc.collection_id', $collection_id);
     }
     // --------------------------------------
     // If there's an entry_id, limit query by those
     // --------------------------------------
     if ($entry_ids) {
         // Force array
         if (!is_array($entry_ids)) {
             $entry_ids = preg_split('/\\D+/', $entry_ids);
         }
         // Get collections for given entries
         ee()->db->select('GROUP_CONCAT(ct.entry_id) AS entries');
         ee()->db->join('channel_titles ct', 'lsc.channel_id = ct.channel_id');
         ee()->db->where_in('entry_id', $entry_ids);
         ee()->db->group_by('lsc.collection_id');
     }
     // --------------------------------------
     // Execute query and get results. Bail out if none
     // --------------------------------------
     if (!($collections = ee()->db->get()->result_array())) {
         return FALSE;
     }
     $collections = low_associate_results($collections, 'collection_id');
     $channel_ids = array_unique(low_flatten_results($collections, 'channel_id'));
     // --------------------------------------
     // Get batch size
     // --------------------------------------
     $batch_size = ee()->low_search_settings->get('batch_size');
     // --------------------------------------
     // Get total number of entries that need to be indexed
     // --------------------------------------
     if ($entry_ids) {
         $num_entries = count($entry_ids);
     } else {
         ee()->db->where_in('channel_id', $channel_ids);
         $num_entries = ee()->db->count_all_results('channel_titles');
     }
     // --------------------------------------
     // Get weighted field settings only, keep track of field ids
     // --------------------------------------
     $fields = array();
     $entries = array();
     foreach ($collections as &$col) {
         $col['settings'] = array_filter(low_search_decode($col['settings'], FALSE));
         // Add field ids to fields array
         $fields = array_merge($fields, array_keys($col['settings']));
         if (isset($col['entries'])) {
             foreach (explode(',', $col['entries']) as $eid) {
                 $entries[$eid][] = $col['collection_id'];
             }
         }
     }
     // Get rid of duplicate field ids
     $fields = array_unique($fields);
     sort($fields);
     // --------------------------------------
     // Let an extension take over?
     // --------------------------------------
     if (ee()->extensions->active_hook('low_search_get_index_entries') === TRUE) {
         $index_entries = ee()->extensions->call('low_search_get_index_entries', $fields, $channel_ids, $entry_ids, $start, $batch_size);
     } else {
         // --------------------------------------
         // Create select list
         // --------------------------------------
         $select = array('t.entry_id', 't.channel_id');
         foreach ($fields as $field_id) {
             // Skip non-numeric settings
             if (!is_numeric($field_id)) {
                 continue;
             }
             $select[] = $field_id == '0' ? 't.title AS field_id_0' : 'd.field_id_' . $field_id;
         }
         // --------------------------------------
         // Start building query
         // --------------------------------------
         ee()->db->select($select)->from('channel_titles t')->join('channel_data d', 't.entry_id = d.entry_id', 'inner')->where_in('t.channel_id', $channel_ids)->order_by('entry_id', 'asc');
         // --------------------------------------
         // Optional: Limit to given entries
         // --------------------------------------
         if ($entry_ids) {
             ee()->db->where_in('t.entry_id', $entry_ids);
         }
         // --------------------------------------
         // Optional: Limit entries by batch size
         // --------------------------------------
         if ($start !== FALSE && is_numeric($start)) {
             ee()->db->limit($batch_size, $start);
         }
         // --------------------------------------
         // Query it!
         // --------------------------------------
         $query = ee()->db->get();
         // Make sure the rows are keyed by their entry_id
         $index_entries = low_associate_results($query->result_array(), 'entry_id');
         // --------------------------------------
         // Get category info for these entries
         // --------------------------------------
         if ($entry_cats = $this->get_entry_categories(array_keys($index_entries))) {
             // add the categories to the index_entries rows
             foreach ($entry_cats as $entry_id => $cats) {
                 $index_entries[$entry_id] += $cats;
             }
         }
     }
     // --------------------------------------
     // Loop thru the entries to index
     // --------------------------------------
     foreach ($index_entries as $row) {
         // If it's a given entry, loop thru its collections and rebuild index
         if (isset($entries[$row['entry_id']])) {
             foreach ($entries[$row['entry_id']] as $col_id) {
                 // Collection details
                 $col = $collections[$col_id];
                 // Build index for this entry/collection combo
                 ee()->low_search_index_model->build($col, $row);
             }
         } else {
             foreach ($collections as $col_id => $col) {
                 if ($row['channel_id'] == $col['channel_id']) {
                     ee()->low_search_index_model->build($col, $row);
                 }
             }
         }
     }
     // Determine new start
     $new_start = $start + $batch_size;
     // Are we done?
     $done = $new_start >= $num_entries;
     // --------------------------------------
     // Prep response
     // --------------------------------------
     $response = array('status' => $done ? 'done' : 'building', 'start' => (int) $new_start, 'total_entries' => (int) $num_entries, 'processed' => count($index_entries));
     return $response;
 }
Beispiel #13
0
 /**
  * Allows for search:title="foo|bar" parameter
  *
  * @access     private
  * @return     void
  */
 public function filter($entry_ids)
 {
     // --------------------------------------
     // Check if search:title is there
     // --------------------------------------
     $params = $this->params->get_prefixed($this->_pfx, TRUE);
     // --------------------------------------
     // Don't do anything if nothing's there
     // --------------------------------------
     if (empty($params)) {
         return $entry_ids;
     }
     // --------------------------------------
     // Log it
     // --------------------------------------
     $this->_log('Applying ' . __CLASS__);
     // --------------------------------------
     // Set channel IDs
     // --------------------------------------
     $this->_channel_ids = ee()->low_search_collection_model->get_channel_ids($this->params->get('collection'));
     // --------------------------------------
     // Loop through search filters and prep queries accordingly
     // --------------------------------------
     $queries = array();
     foreach ($params as $key => $val) {
         // Make sure value is prepped correctly with exact/exclude/require_all values
         $val = $this->params->prep($this->_pfx . $key, $val);
         // Search channel title
         if ($key == 'title') {
             // Title search
             $queries['channel_titles'][] = $this->_get_where('title', $val);
         } elseif (strpos($key, ':')) {
             list($field_name, $col_name) = explode(':', $key, 2);
             // Skip invalid fields
             if (!($field_id = $this->_get_field_id($field_name))) {
                 continue;
             }
             $table = FALSE;
             // Make sure it's an omelette!
             if ($this->_is_grid_field($field_name) && ($col_id = $this->_get_grid_col_id($field_id, $col_name))) {
                 $table = 'channel_grid_field_' . $field_id;
                 $field = 'col_id_' . $col_id;
             } elseif ($this->_is_matrix_field($field_id) && ($col_id = $this->_get_matrix_col_id($field_id, $col_name))) {
                 $table = 'matrix_data';
                 $field = 'col_id_' . $col_id;
             }
             if ($table) {
                 $queries[$table][] = $this->_get_where($field, $val);
             }
         } elseif ($field_id = $this->_get_field_id($key)) {
             // Regular fields
             $queries['channel_data'][] = $this->_get_where('field_id_' . $field_id, $val);
         }
         // Don't set it
         $this->params->forget[] = $this->_pfx . $key;
     }
     // --------------------------------------
     // Where now contains a list of clauses
     // --------------------------------------
     if (empty($queries)) {
         return $entry_ids;
     }
     // --------------------------------------
     // Query the lot!
     // --------------------------------------
     foreach ($queries as $table => $wheres) {
         // Start this query
         ee()->db->distinct()->select('entry_id')->from($table);
         // Add wheres
         foreach ($wheres as $sql) {
             ee()->db->where($sql);
         }
         // Limit by given entry ids?
         if (!empty($entry_ids)) {
             ee()->db->where_in('entry_id', $entry_ids);
         }
         // Limit only for non-grid tables
         if (in_array($table, array('channel_titles', 'channel_data'))) {
             // Limit by channel
             if ($this->_channel_ids) {
                 ee()->db->where_in('channel_id', $this->_channel_ids);
             }
             // Limit by site
             if ($site_ids = $this->params->site_ids()) {
                 ee()->db->where_in('site_id', $site_ids);
             }
         }
         // Execute!
         $query = ee()->db->get();
         // Get entry IDs
         $entry_ids = low_flatten_results($query->result_array(), 'entry_id');
         $entry_ids = array_unique($entry_ids);
         // Return immediately when no results are there
         if (empty($entry_ids)) {
             break;
         }
     }
     return $entry_ids;
 }
Beispiel #14
0
 /**
  * Get array of column ids for given Grid or Matrix field
  *
  * @access      private
  * @param       int
  * @param       string
  * @return      array
  */
 private function _get_cols($id, $table = 'grid_columns')
 {
     static $cols = array();
     if (!isset($cols[$table][$id])) {
         $query = ee()->db->select('col_id')->from($table)->where('field_id', $id)->where('col_search', 'y')->get();
         $cols[$table][$id] = low_flatten_results($query->result_array(), 'col_id');
     }
     return $cols[$table][$id];
 }
Beispiel #15
0
 /**
  * Display field in publish form or Matrix cell
  *
  * @param	string	Current value for field
  * @return	string	HTML containing input field
  */
 private function _display_field($data = '', $cell = FALSE)
 {
     // -------------------------------------
     //  What's the field name?
     // -------------------------------------
     $field_name = $cell ? $this->cell_name : $this->field_name;
     // -------------------------------------
     //  We need groups!
     // -------------------------------------
     if (empty($this->settings['lv_ft_groups'])) {
         return lang('no_variable_group_selected');
     }
     // -------------------------------------
     //  Get all variable groups
     // -------------------------------------
     if (!($groups = low_get_cache($this->package, 'groups'))) {
         $query = ee()->db->select('group_id, group_label')->from('low_variable_groups')->where('site_id', ee()->config->item('site_id'))->order_by('group_order')->get();
         $groups = low_flatten_results($query->result_array(), 'group_label', 'group_id');
         if (!$groups) {
             $groups = array();
         }
         $groups += array('0' => lang('ungrouped'));
         low_set_cache($this->package, 'groups', $groups);
     }
     // -------------------------------------
     //  Get variables from groups
     // -------------------------------------
     $query = ee()->db->select('ee.variable_name, low.variable_label, low.group_id')->from('global_variables ee')->join('low_variables low', 'ee.variable_id = low.variable_id')->where('ee.site_id', ee()->config->item('site_id'))->where_in('low.group_id', $this->settings['lv_ft_groups'])->where('low.early_parsing', 'n')->where('low.is_hidden', 'n')->order_by('low.variable_order', 'asc')->get();
     // Initiate arrays to get vars by
     $unordered_vars = $vars = array();
     // Loop through found vars and group by group label
     foreach ($query->result_array() as $row) {
         $unordered_vars[$row['group_id']][$row['variable_name']] = $row['variable_label'];
     }
     // Loop through groups (which are in the right order)
     // and group the vars by group label to easily create optgroups and such
     foreach ($groups as $group_id => $group_label) {
         if (isset($unordered_vars[$group_id])) {
             $vars[$group_label] = $unordered_vars[$group_id];
         }
     }
     // Reduce to 1 dimensional array
     if (count($vars) === 1) {
         $vars = $vars[key($vars)];
     }
     // clean up
     unset($unordered_vars);
     // -------------------------------------
     //  Multiple?
     // -------------------------------------
     if (@$this->settings['lv_ft_multiple'] == 'y') {
         // Init arrays for checkboxes
         $boxes = array();
         $data = explode("\n", $data);
         // Loop thru vars and create checkbox in a label
         foreach ($vars as $key => $val) {
             if (is_array($val)) {
                 $boxes[] = "<div style=\"margin:1em 0 .5em\"><strong>{$key}</strong></div>";
                 foreach ($val as $k => $v) {
                     $boxes[] = $this->_box($field_name, $k, in_array($k, $data), $v);
                 }
             } else {
                 $boxes[] = $this->_box($field_name, $key, in_array($key, $data), $val);
             }
         }
         // return string of checkboxes
         return implode("\n", $boxes);
     } else {
         $vars = array('' => '--') + $vars;
         return form_dropdown($field_name, $vars, $data);
     }
 }
Beispiel #16
0
 /**
  * Search parameters for range:field params and return set of ids that match it
  *
  * @access      private
  * @return      void
  */
 public function filter($entry_ids)
 {
     // --------------------------------------
     // Get ranges params
     // --------------------------------------
     $params = array_filter(array_merge($this->params->get_prefixed('range:'), $this->params->get_prefixed('range-from:'), $this->params->get_prefixed('range-to:')), 'low_not_empty');
     // --------------------------------------
     // Don't do anything if nothing's there
     // --------------------------------------
     if (empty($params)) {
         return $entry_ids;
     }
     // --------------------------------------
     // Log it
     // --------------------------------------
     $this->_log('Applying ' . __CLASS__);
     // --------------------------------------
     // Validate params
     // --------------------------------------
     $ranges = array();
     foreach ($params as $key => $val) {
         // Split key
         list($prefix, $field) = explode(':', $key, 2);
         // Skip invalid fields
         if (!($field_name = $this->_get_field_name($field))) {
             continue;
         }
         // Init this range
         $from = $to = NULL;
         // Check prefix and get from/to values accordingly
         switch ($prefix) {
             case 'range':
                 // Fallback to ;
                 $char = strpos($val, ';') ? ';' : $this->_sep;
                 if (strpos($val, $char)) {
                     list($from, $to) = explode($char, $val, 2);
                 }
                 break;
             case 'range-from':
                 $from = $val;
                 break;
             case 'range-to':
                 $to = $val;
                 break;
         }
         // Make sure the values are numeric
         $from = $this->_validate_value($from, $field);
         $to = $this->_validate_value($to, $field);
         // If both are invalid, skip it
         if (is_null($from) && is_null($to)) {
             continue;
         }
         // Add from value to field
         if (!is_null($from)) {
             $ranges[$field]['from'] = $from;
         }
         // Add to value to field
         if (!is_null($to)) {
             $ranges[$field]['to'] = $to;
         }
         // Add sql field name to field
         $ranges[$field]['field'] = $field_name;
     }
     // --------------------------------------
     // No ranges, bail out
     // --------------------------------------
     if (empty($ranges)) {
         $this->_log('No valid ranges found');
         return $entry_ids;
     }
     // --------------------------------------
     // Get channel IDs before starting the query
     // --------------------------------------
     $channel_ids = ee()->low_search_collection_model->get_channel_ids($this->params->get('collection'));
     // --------------------------------------
     // Start query
     // --------------------------------------
     ee()->db->select('t.entry_id')->from('channel_titles t')->join('channel_data d', 't.entry_id = d.entry_id');
     // --------------------------------------
     // Limit by channel ids?
     // --------------------------------------
     if ($channel_ids) {
         ee()->db->where_in('t.channel_id', $channel_ids);
     }
     // --------------------------------------
     // Limit by site ids?
     // --------------------------------------
     if ($site_ids = $this->params->site_ids()) {
         ee()->db->where_in('t.site_id', $site_ids);
     }
     // --------------------------------------
     // Limit by given entry ids?
     // --------------------------------------
     if (!empty($entry_ids)) {
         ee()->db->where_in('t.entry_id', $entry_ids);
     }
     // --------------------------------------
     // And filter by the ranges
     // --------------------------------------
     foreach ($ranges as $field => $range) {
         // Exclude values from range?
         $exclude = $this->params->in_param("range:{$field}", 'exclude');
         // Prefix the field name
         $sql_field = ($this->_is_native_field($range['field']) ? 't.' : 'd.') . $range['field'];
         // Limit by Greater Than option
         if (isset($range['from'])) {
             $gt = $exclude || $this->params->in_param("range-from:{$field}", 'exclude') ? ' >' : ' >=';
             ee()->db->where($sql_field . $gt, $range['from']);
         }
         // Limit by Lesser Than option
         if (isset($range['to'])) {
             $lt = $exclude || $this->params->in_param("range-to:{$field}", 'exclude') ? ' <' : ' <=';
             ee()->db->where($sql_field . $lt, $range['to']);
         }
     }
     // --------------------------------------
     // Execute!
     // --------------------------------------
     $query = ee()->db->get();
     // --------------------------------------
     // And get the entry ids
     // --------------------------------------
     $entry_ids = low_flatten_results($query->result_array(), 'entry_id');
     $entry_ids = array_unique($entry_ids);
     return $entry_ids;
 }
 /**
  * Get the site id and cleaned var from a var="" parameter value
  *
  * @access     private
  * @return     array
  */
 private function _get_var_param()
 {
     // -------------------------------------
     //  Get the var parameter value
     // -------------------------------------
     $var = $this->EE->TMPL->fetch_param('var', FALSE);
     // -------------------------------------
     //  Default site id to current site id
     // -------------------------------------
     $site_id = $this->site_id;
     // -------------------------------------
     //  Get site id based on site_name:var_name value
     // -------------------------------------
     if (!empty($var) && ($pos = strpos($var, ':')) !== FALSE) {
         // Get the part before the :
         $prefix = substr($var, 0, $pos);
         // If MSM is enabled and if site name is not current site, fetch its id from cache or DB
         if ($this->EE->config->item('multiple_sites_enabled') == 'y') {
             // Check cache, if not set, execute query and register to cache
             if (($sites = low_get_cache($this->package, 'sites')) === FALSE) {
                 $query = $this->EE->db->query("SELECT site_id, site_name FROM exp_sites");
                 $sites = low_flatten_results($query->result_array(), 'site_id', 'site_name');
                 low_set_cache($this->package, 'sites', $sites);
             }
             // If the prefix is a site name, strip it from the var name
             // and use its id to return
             if (array_key_exists($prefix, $sites)) {
                 $var = substr($var, $pos + 1);
                 $site_id = $sites[$prefix];
                 $this->EE->TMPL->log_item("Low Variables: Found var {$var} in site {$prefix}");
             }
         }
     }
     // -------------------------------------
     //  Return the site id and cleaned var name
     // ------------------------------------
     return array($var, $site_id);
 }
 /**
  * Add early parsed variables to config->_global_vars() array
  *
  * @access     private
  * @return     void
  */
 private function _add_vars($session = FALSE)
 {
     // -------------------------------------
     //  Define static var to keep track of
     //  whether we've added vars already...
     // -------------------------------------
     static $added;
     // ...if so, just bail out
     if ($added) {
         return;
     }
     // -------------------------------------
     //  Initiate data array
     // -------------------------------------
     $early = array();
     // -------------------------------------
     //  Get global variables to parse early, ordered the way they're displayed in the CP
     // -------------------------------------
     $query = ee()->db->select(array('ee.variable_name', 'ee.variable_data'))->from('global_variables AS ee')->join('low_variables AS low', 'ee.variable_id = low.variable_id')->where('ee.site_id', $this->site_id)->where('low.early_parsing', 'y')->order_by('low.group_id')->order_by('low.variable_order')->get();
     $early = low_flatten_results($query->result_array(), 'variable_data', 'variable_name');
     // -------------------------------------
     //  Are we registering member data?
     // -------------------------------------
     if ($this->settings['register_member_data'] == 'y') {
         // Variables to set
         $keys = array('member_id', 'group_id', 'group_description', 'username', 'screen_name', 'email', 'ip_address', 'location', 'total_entries', 'total_comments', 'private_messages', 'total_forum_posts', 'total_forum_topics');
         // Add logged_in_... vars to early parsing arrat
         foreach ($keys as $key) {
             $early['logged_in_' . $key] = $session ? @$session->userdata[$key] : ee()->session->userdata($key);
         }
     }
     // -------------------------------------
     //  Look for existing language variable, set user language to it
     //  Disabled for now
     // -------------------------------------
     // if (isset(ee()->config->_global_vars['global:language']))
     // {
     // 	$SESS->userdata['language'] = ee()->config->_global_vars['global:language'];
     // }
     // -------------------------------------
     //  Add variables to early parsed global vars
     //  Option: make it a setting to switch order around?
     // -------------------------------------
     if ($early) {
         ee()->config->_global_vars = $this->settings['register_globals'] == 'y' ? array_merge($early, ee()->config->_global_vars) : array_merge(ee()->config->_global_vars, $early);
     }
     // Remember that we've added the vars so we don't do it again
     $added = TRUE;
 }
Beispiel #19
0
 /**
  * Search parameters for (parents|children):field params and return set of ids that match it
  *
  * @access      public
  * @return      void
  */
 public function filter($entry_ids)
 {
     // --------------------------------------
     // Check prefixed parameters needed
     // --------------------------------------
     $rels = array_filter(array_merge($this->params->get_prefixed('parent:'), $this->params->get_prefixed('child:')), 'low_param_is_numeric');
     // --------------------------------------
     // Don't do anything if nothing's there
     // --------------------------------------
     if (empty($rels)) {
         return $entry_ids;
     }
     // --------------------------------------
     // Log it
     // --------------------------------------
     $this->_log('Applying ' . __CLASS__);
     // --------------------------------------
     // Loop through relationships
     // --------------------------------------
     foreach ($rels as $key => $val) {
         // List out match
         list($type, $field) = explode(':', $key, 2);
         // Get the field id, skip if non-existent
         if (!($field_id = $this->_get_field_id($field))) {
             continue;
         }
         // Prep the value
         $val = $this->params->prep($key, $val);
         // Get the parameter
         list($ids, $in) = low_explode_param($val);
         // Match all?
         $all = (bool) strpos($val, '&');
         // Init vars
         $rel_ids = $table = FALSE;
         $get_children = $type == 'parent';
         // Native relationship field
         if ($this->_is_rel_field($field)) {
             // Account for new EE rels
             $prefix = version_compare(APP_VER, '2.6.0', '<') ? 'rel_' : '';
             // Set the table & attributes
             $table = 'relationships';
             $select = $get_children ? $prefix . 'child_id' : $prefix . 'parent_id';
             $where = $get_children ? $prefix . 'parent_id' : $prefix . 'child_id';
         } elseif ($this->_is_playa_field($field_id)) {
             // Set the table
             $table = 'playa_relationships';
             $select = $get_children ? 'child_entry_id' : 'parent_entry_id';
             $where = $get_children ? 'parent_entry_id' : 'child_entry_id';
             // Focus on specific field
             ee()->db->where('parent_field_id', $field_id);
         }
         // Execute query
         if ($table) {
             ee()->db->select($select . ' AS entry_id')->from($table)->{$in ? 'where_in' : 'where_not_in'}($where, $ids);
             // Limit by already existing ids
             if ($entry_ids) {
                 ee()->db->where_in($select, $entry_ids);
             }
             // Do the having-trick to account for *all* given entry ids
             if ($in && $all) {
                 ee()->db->select('COUNT(*) AS num')->group_by($select)->having('num', count($ids));
             }
             // Execute query
             $query = ee()->db->get();
             // And get the entry ids
             $entry_ids = low_flatten_results($query->result_array(), 'entry_id');
             $entry_ids = array_unique($entry_ids);
             // Bail out if there aren't any matches
             if (is_array($entry_ids) && empty($entry_ids)) {
                 break;
             }
         }
     }
     return $entry_ids;
 }
 /**
  * Sync EE vars and Low vars
  *
  * Deletes Low Variables that reference to non-existing EE Variables,
  * Creates default Low Variables that have no reference to existing EE Vars.
  *
  * @access     private
  * @return     void
  */
 private function _sync()
 {
     // -------------------------------------
     //  Get all native variable ids
     // -------------------------------------
     $query = ee()->db->select('variable_id')->from('global_variables')->get();
     $ee_ids = low_flatten_results($query->result_array(), 'variable_id');
     // -------------------------------------
     //  Sync based on ee ids
     // -------------------------------------
     if (!empty($ee_ids)) {
         // Delete references to non-existing native vars
         ee()->db->where_not_in('variable_id', $ee_ids)->delete('low_variables');
         // Get all Low Variables
         $query = ee()->db->select('variable_id')->from('low_variables')->get();
         $low_ids = low_flatten_results($query->result_array(), 'variable_id');
         // Get ids that do not exist in low_var but do exist in ee_var
         if ($diff = array_diff($ee_ids, $low_ids)) {
             foreach ($diff as $i => $var_id) {
                 ee()->db->insert('low_variables', array('variable_id' => $var_id, 'group_id' => '0', 'variable_label' => '', 'variable_notes' => '', 'variable_type' => LOW_VAR_DEFAULT_TYPE, 'variable_settings' => '', 'variable_order' => $i, 'edit_date' => time()));
             }
         }
     }
 }
 /**
  * Display input field for regular user
  *
  * @param	int		$var_id			The id of the variable
  * @param	string	$var_data		The value of the variable
  * @param	array	$var_settings	The settings of the variable
  * @return	string
  */
 function display_input($var_id, $var_data, $var_settings)
 {
     // -------------------------------------
     //  Prep options
     // -------------------------------------
     $category_groups = $this->get_setting('category_groups', $var_settings);
     $multiple = $this->get_setting('multiple', $var_settings);
     $separator = $this->get_setting('separator', $var_settings);
     $multi_interface = $this->get_setting('multi_interface', $var_settings);
     // -------------------------------------
     //  Prep current data
     // -------------------------------------
     $current = explode($this->separators[$separator], $var_data);
     // -------------------------------------
     //  No groups? Bail.
     // -------------------------------------
     if (empty($category_groups)) {
         return lang('no_category_groups_selected');
     }
     // -------------------------------------
     //  Load category API and fetch categories
     // -------------------------------------
     ee()->load->library('api');
     ee()->api->instantiate('channel_categories');
     $categories = ee()->api_channel_categories->category_tree($category_groups);
     // -------------------------------------
     //  Compose nested category array
     // -------------------------------------
     $cats = array();
     if ($multiple == 'y' && $multi_interface == 'drag-list') {
         // This will return a flat list of categories
         $cats = low_flatten_results($categories, '1', '0');
         // So we need to sort alphabetically again
         asort($cats);
         // Then assign to output
         $r = $this->drag_lists($var_id, $cats, $current);
     } else {
         // Loop thru tree and create nested array accordingly
         foreach ($categories as $row) {
             // Category name
             $cat = $row['1'];
             // Check indent level
             if ($row['5'] > 1) {
                 $cat = str_repeat('-', $row['5'] - 1) . ' ' . $cat;
             }
             $cats[$row['3']][$row['0']] = $cat;
         }
         // Sort if multiple groups
         if (count($cats) > 1) {
             ksort($cats);
         }
         // Assign regular select element to output
         $r = $this->select_element($var_id, $cats, $current, $multiple == 'y');
     }
     // -------------------------------------
     //  Return interface
     // -------------------------------------
     return $r;
 }
Beispiel #22
0
 /**
  * Update by category
  */
 private function _update_index_by_category($cat_ids)
 {
     if (empty($cat_ids)) {
         return $cat_ids;
     }
     // Get entries for this category
     $query = ee()->db->select('entry_id')->from('category_posts')->where_in('cat_id', $cat_ids)->get();
     $entry_ids = low_flatten_results($query->result_array(), 'entry_id');
     $entry_ids = array_unique($entry_ids);
     if ($entry_ids) {
         ee()->load->library('Low_search_index');
         ee()->low_search_index->build(FALSE, $entry_ids);
     }
 }
 /**
  * Do update to 1.3.4
  */
 private function _v134()
 {
     // Add group_id foreign key in table
     $this->EE->db->query("ALTER TABLE `exp_low_variables` ADD `is_hidden` CHAR(1) NOT NULL DEFAULT 'n'");
     // Set new attribute, only if settings are found
     if ($settings = low_get_cache(LOW_VAR_PACKAGE, 'settings')) {
         // Only update variables if prefix was filled in
         if ($prefix_length = strlen(@$settings['prefix'])) {
             $sql = "SELECT variable_id FROM `exp_global_variables` WHERE LEFT(variable_name, {$prefix_length}) = '" . $this->EE->db->escape_str($settings['prefix']) . "'";
             $query = $this->EE->db->query($sql);
             if ($ids = low_flatten_results($query->result_array(), 'variable_id')) {
                 // Hide wich vars
                 $sql_in = $settings['with_prefixed'] == 'show' ? 'NOT IN' : 'IN';
                 // Execute query
                 $this->EE->db->query("UPDATE `exp_low_variables` SET is_hidden = 'y' WHERE variable_id {$sql_in} (" . implode(',', $ids) . ")");
             }
         }
         // Update settings
         unset($settings['prefix'], $settings['with_prefixed'], $settings['ignore_prefixes']);
         $this->EE->db->query("UPDATE `exp_extensions` SET settings = '" . $this->EE->db->escape_str(serialize($settings)) . "' WHERE class = 'Low_variables_ext'");
     }
 }
Beispiel #24
0
 /**
  * Save set settings
  *
  * @access      public
  * @return      void
  */
 public function save_set()
 {
     // --------------------------------------
     // Get Set id
     // --------------------------------------
     if (!($set_id = ee()->input->post('set_id'))) {
         return $this->_show_error('invalid_request');
     }
     // --------------------------------------
     // Init data array
     // --------------------------------------
     $data = array();
     // --------------------------------------
     // Regular fields
     // --------------------------------------
     foreach (ee()->low_reorder_set_model->attributes() as $attr) {
         $data[$attr] = ee()->input->post($attr);
     }
     // Clean up params
     $data['parameters'] = array_filter($data['parameters']);
     // --------------------------------------
     // Validate some fields
     // --------------------------------------
     // Label shouldn't be empty
     if (empty($data['set_label'])) {
         show_error(lang('set_label_empty'));
     }
     // Set name should be valid
     if (!preg_match('/^[-_\\w]+$/i', $data['set_name'])) {
         show_error(lang('set_name_invalid'));
     }
     // Check if set name is unique for this site
     if (!ee()->low_reorder_set_model->name_is_unique($set_id, $data['set_name'], $this->site_id)) {
         show_error(lang('set_name_not_unique'));
     }
     // Channels shouldn't be empty
     if (empty($data['channels'])) {
         show_error(lang('channels_empty'));
     }
     // Default to status = open if none are given
     if (empty($data['parameters']['status'])) {
         $data['parameters']['status'][] = 'open';
     }
     // Cat groups are required for 'one'
     if ($data['cat_option'] == 'one') {
         if (empty($data['cat_groups'])) {
             show_error(lang('cat_groups_empty'));
         }
     } else {
         // If not set to 'one', set cat_groups to empty
         $data['cat_groups'] = '';
     }
     // Unset category parameter
     if ($data['cat_option'] != 'some') {
         unset($data['parameters']['category']);
     }
     // Set clear_cache to 'y' or 'n'
     $data['clear_cache'] = $data['clear_cache'] == 'yes' ? 'y' : 'n';
     // --------------------------------------
     // Set site id
     // --------------------------------------
     $data['site_id'] = $this->site_id;
     // --------------------------------------
     // Get parameters
     // --------------------------------------
     // Store channel_short_names in parameters
     if (!empty($data['channels'])) {
         $query = ee()->db->select('channel_name')->from('channels')->where_in('channel_id', $data['channels'])->get();
         $data['parameters']['channel'] = implode('|', low_flatten_results($query->result_array(), 'channel_name'));
     }
     // --------------------------------------
     // Add search filters to parameters
     // --------------------------------------
     if ($search = ee()->input->post('search')) {
         foreach ($search['fields'] as $i => $key) {
             $val = (string) @$search['values'][$i];
             if (strlen($key) && strlen($val)) {
                 $data['parameters']["search:{$key}"] = $val;
             }
         }
     }
     // --------------------------------------
     // Get parameters and permissions
     // --------------------------------------
     $data['parameters'] = ee()->low_reorder_set_model->get_params($data['parameters']);
     $data['permissions'] = (array) ee()->input->post('permissions');
     // Copy data to $sql_data
     $sql_data = $data;
     // --------------------------------------
     // Convert sql_data to strings
     // --------------------------------------
     $sql_data['parameters'] = json_encode($sql_data['parameters']);
     $sql_data['permissions'] = json_encode($sql_data['permissions']);
     foreach ($sql_data as &$val) {
         if (is_array($val)) {
             $val = count($val) ? low_linearize($val) : '';
         }
     }
     // --------------------------------------
     // Insert or Update
     // --------------------------------------
     if ($set_id == 'new') {
         $set_id = ee()->low_reorder_set_model->insert($sql_data);
     } else {
         ee()->low_reorder_set_model->update($set_id, $sql_data);
     }
     // --------------------------------------
     // Insert order
     // --------------------------------------
     // Prep params
     $params = $data['parameters'] + array('channel_id' => implode('|', $data['channels']));
     // Account for uncategorized entries
     if ($data['cat_option'] == 'none') {
         $params['uncategorized_entries'] = 'yes';
     }
     // Initiate orders for all categories
     if ($data['cat_option'] == 'one') {
         $query = ee()->db->select("c.cat_id, GROUP_CONCAT(t.entry_id ORDER BY t.entry_date DESC SEPARATOR '|') AS entry_ids", FALSE)->from('channel_titles t')->join('category_posts cp', 't.entry_id = cp.entry_id')->join('categories c', 'c.cat_id = cp.cat_id')->where_in('t.channel_id', $data['channels'])->where_in('t.status', explode('|', $data['parameters']['status']))->where_in('c.group_id', $data['cat_groups'])->group_by('c.cat_id')->get();
         foreach ($query->result() as $row) {
             ee()->low_reorder_order_model->insert_ignore(array('set_id' => $set_id, 'cat_id' => $row->cat_id, 'sort_order' => $row->entry_ids ? "|{$row->entry_ids}|" : ''));
         }
     } else {
         $entries = low_flatten_results($this->get_entries($params), 'entry_id');
         ee()->low_reorder_order_model->insert_ignore(array('set_id' => $set_id, 'cat_id' => 0, 'sort_order' => low_linearize($entries)));
     }
     // -------------------------------------
     // 'low_reorder_post_save_set' hook.
     //  - Do something after the (new) set has been saved
     // -------------------------------------
     if (ee()->extensions->active_hook('low_reorder_post_save_set') === TRUE) {
         // Use raw, non-encoded data to pass through
         ee()->extensions->call('low_reorder_post_save_set', $set_id, $data);
     }
     // --------------------------------------
     // Set feedback message
     // --------------------------------------
     ee()->session->set_flashdata('msg', lang('settings_saved'));
     // --------------------------------------
     // Go back to set or reoder page
     // --------------------------------------
     $method = ee()->input->post('reorder') ? 'reorder' : 'edit';
     ee()->functions->redirect($this->base_url . AMP . 'method=' . $method . AMP . 'set_id=' . $set_id);
 }
 /**
  * Get channel IDs by parameter
  */
 public function get_channel_ids($param)
 {
     $channel_ids = array();
     if ($param) {
         $cols = $this->get_by_param($param);
         $channel_ids = low_flatten_results($cols, 'channel_id');
         $channel_ids = array_unique($channel_ids);
     }
     return $channel_ids;
 }
Beispiel #26
0
 /**
  * Search parameters for distance: params
  *
  * @access      private
  * @return      void
  */
 public function filter($entry_ids)
 {
     // --------------------------------------
     // Reset
     // --------------------------------------
     $this->_results = array();
     // --------------------------------------
     // Get distance params
     // --------------------------------------
     $params = $this->params->get_prefixed('distance:', TRUE);
     $params = array_filter($params, 'low_not_empty');
     // --------------------------------------
     // Check required params
     // --------------------------------------
     foreach (array('from', 'to') as $key) {
         if (empty($params[$key])) {
             return $entry_ids;
         }
     }
     // --------------------------------------
     // Log it
     // --------------------------------------
     $this->_log('Applying ' . __CLASS__);
     // --------------------------------------
     // Get channel IDs before starting the query
     // --------------------------------------
     $channel_ids = ee()->low_search_collection_model->get_channel_ids($this->params->get('collection'));
     // --------------------------------------
     // Get from coords
     // --------------------------------------
     list($lat, $long) = preg_split('/[|,]/', $params['from'], 2, PREG_SPLIT_NO_EMPTY);
     // --------------------------------------
     // Unit
     // --------------------------------------
     if (empty($params['unit'])) {
         $params['unit'] = 'km';
     }
     // Radius of the earth
     switch ($params['unit']) {
         case 'mi':
             $R = 3959;
             break;
         default:
             $R = 6371;
     }
     // --------------------------------------
     // Get reference to fields from params
     // --------------------------------------
     list($lat_field, $long_field) = explode('|', $params['to'], 2);
     $lat_field_id = $this->_get_field_id($lat_field);
     $long_field_id = $this->_get_field_id($long_field);
     if (!($lat_field_id && $long_field_id)) {
         return $entry_ids;
     }
     $lat_field = 'field_id_' . $lat_field_id;
     $long_field = 'field_id_' . $long_field_id;
     // --------------------------------------
     // The distance SQL statement: Haversine formula
     // --------------------------------------
     $haversine = '(%d * acos(cos(radians(%2$f)) * cos(radians(%4$s)) * cos(radians(%5$s) - radians(%3$f))' . ' + sin(radians(%2$f)) * sin(radians(%4$s)))) AS distance';
     // Get entry IDs and their distances
     ee()->db->select('entry_id')->select(sprintf($haversine, $R, $lat, $long, $lat_field, $long_field), FALSE)->from('channel_data')->where("({$lat_field} OR {$long_field})")->order_by('distance', 'asc');
     // --------------------------------------
     // Limit by site ids?
     // --------------------------------------
     if ($site_ids = $this->params->site_ids()) {
         ee()->db->where_in('site_id', $site_ids);
     }
     // --------------------------------------
     // Limit by channel ids?
     // --------------------------------------
     if ($channel_ids) {
         ee()->db->where_in('channel_id', $channel_ids);
     }
     // --------------------------------------
     // Limit by entry ids?
     // --------------------------------------
     if ($entry_ids) {
         ee()->db->where_in('entry_id', $entry_ids);
     }
     // --------------------------------------
     // Limit by radius?
     // --------------------------------------
     if (!empty($params['radius'])) {
         ee()->db->having('distance <=', $params['radius']);
     }
     // --------------------------------------
     // Execute!
     // --------------------------------------
     $query = ee()->db->get();
     $this->_results = low_flatten_results($query->result_array(), 'distance', 'entry_id');
     return array_keys($this->_results);
 }
 /**
  * Get shortcuts for given group
  *
  * @access      public
  * @return      void
  */
 public function get_group_counts($site_id)
 {
     $query = ee()->db->select('group_id, COUNT(*) AS num')->from($this->table())->where('site_id', $site_id)->group_by('group_id')->get();
     return low_flatten_results($query->result_array(), 'num', 'group_id');
 }