/** * Change collections when a custom field is deleted */ public function custom_field_modify_data($ft, $method, $data) { // ------------------------------------------- // Get the latest version of $data // ------------------------------------------- if (ee()->extensions->last_call !== FALSE) { $data = ee()->extensions->last_call; } // ------------------------------------------- // Remove reference to field if found in collection settings // ------------------------------------------- if ($method == 'settings_modify_column') { $collections = ee()->low_search_collection_model->get_all(); foreach ($data as $row) { // Skip if not deleting if ($row['ee_action'] != 'delete') { continue; } foreach ($collections as $col_id => $col) { // Init update array $update = array(); // Is the field the excerpt? If so, fall back to title if ($row['field_id'] == $col['excerpt']) { $update['excerpt'] = 0; } // Is the field part of a collection's settings? // If so, remove it if (array_key_exists($row['field_id'], $col['settings'])) { unset($col['settings'][$row['field_id']]); $update['settings'] = low_search_encode($col['settings'], FALSE); // also update edit date to trigger 'rebuild index' message $update['edit_date'] = ee()->localize->now; } // If we need to update, do so if (!empty($update)) { ee()->low_search_collection_model->update($col_id, $update); } } } } // Return the data again return $data; }
/** * View search log * * @access public * @return string */ public function search_log() { // Keep track of this URL $log_url = $this->mcp_url('search_log'); $filtered = FALSE; // -------------------------------------- // Check if filter form was posted // -------------------------------------- if ($filter = ee()->input->post('filter')) { if ($filter = array_filter($filter, 'low_not_empty')) { $log_url .= AMP . 'filter=' . low_search_encode($filter); } // Go to same url with encoded filter in GET ee()->functions->redirect($log_url); } // -------------------------------------- // Check if there's a GET filter // -------------------------------------- if ($filter = ee()->input->get('filter')) { $log_url .= AMP . 'filter=' . $filter; $filter = low_search_decode($filter); $filtered = TRUE; } if (!is_array($filter)) { $filter = array(); } // Add site id to it $filter['site_id'] = $this->site_id; // -------------------------------------- // Populate filters // -------------------------------------- // Get all unique members $members = ee()->db->select('m.member_id, m.screen_name')->from('members m')->join('low_search_log l', 'm.member_id = l.member_id', '')->where('l.site_id', $this->site_id)->group_by('m.member_id')->order_by('m.screen_name', 'asc')->get()->result_array(); $members = low_flatten_results($members, 'screen_name', 'member_id'); $this->data['members'] = $members; // Get all days of searching $dates = ee()->db->select("DISTINCT(FROM_UNIXTIME(search_date, '%Y-%m-%d')) AS search_date", FALSE)->from('low_search_log')->where('site_id', $this->site_id)->order_by('search_date', 'desc')->get()->result_array(); $dates = low_flatten_results($dates, 'search_date'); $this->data['dates'] = $dates; // -------------------------------------- // Get total rows of log // -------------------------------------- $total = ee()->low_search_log_model->get_filtered_count($filter); // Prune now? if (($search_log_size = ee()->low_search_settings->get('search_log_size')) !== '0' and $total > $search_log_size) { ee()->low_search_log_model->prune($this->site_id, $search_log_size); $total = $search_log_size; } // -------------------------------------- // Get start row // -------------------------------------- if (($start = ee()->input->get('start')) === FALSE) { $start = 0; } // -------------------------------------- // Load pagination class, if necessary // -------------------------------------- if ($total > self::VIEW_LOG_LIMIT) { ee()->load->library('pagination'); // Pagination link template $pagi_link = '<img src="' . ee()->cp->cp_theme_url . 'images/pagination_%s_button.gif" width="13" height="13" alt="%s" />'; // Set pagination parameters ee()->pagination->initialize(array('base_url' => $log_url, 'total_rows' => $total, 'per_page' => self::VIEW_LOG_LIMIT, 'page_query_string' => TRUE, 'query_string_segment' => 'start', 'full_tag_open' => '<span>', 'full_tag_close' => '</span>', 'prev_link' => sprintf($pagi_link, 'prev', '←'), 'next_link' => sprintf($pagi_link, 'next', '→'), 'first_link' => sprintf($pagi_link, 'first', '&ldarr;'), 'last_link' => sprintf($pagi_link, 'last', '&rdarr;'))); // Create the links $this->data['pagination'] = ee()->pagination->create_links(); } else { $this->data['pagination'] = FALSE; } // -------------------------------------- // Get search log // -------------------------------------- // pagination ee()->db->order_by('search_date', 'desc'); ee()->db->limit(self::VIEW_LOG_LIMIT, $start); $log = ee()->low_search_log_model->get_filtered_rows($filter); if ($log) { // -------------------------------------- // Set pagination details // -------------------------------------- $this->data['viewing_rows'] = sprintf(lang('viewing_rows'), $start + 1, ($to = $start + self::VIEW_LOG_LIMIT) > $total ? $total : $to, $total); // -------------------------------------- // Shortcut URL // -------------------------------------- $shortcut_url = $this->mcp_url('edit_shortcut', 'shortcut_id=new&log_id=%s'); // -------------------------------------- // Modify rows // -------------------------------------- foreach ($log as &$row) { // Display a nice date $row['search_date'] = $this->_human_time($row['search_date']); // Account for guests $row['member_id'] = isset($members[$row['member_id']]) ? $members[$row['member_id']] : ''; // Parameters $row['parameters'] = low_search_decode($row['parameters'], FALSE); // Shortcut URL $row['shortcut_url'] = sprintf($shortcut_url, $row['log_id']); } } // -------------------------------------- // Add log to data array // -------------------------------------- $this->data['log'] = $log; $this->data['is_admin'] = $this->member_group == 1; $this->data['filter'] = $filter; $this->data['filtered'] = $filtered; // -------------------------------------- // Set title and breadcrumb and view page // -------------------------------------- $this->_set_cp_var('cp_page_title', lang('view_search_log')); ee()->cp->set_breadcrumb($this->mcp_url(), lang('low_search_module_name')); return $this->view('mcp_list_search_log'); }
/** * Validate given array * * @access public * @param array * @return mixed */ public function validate($data) { // Reset errors $this->_errors = array(); // -------------------------------------- // Trim input // -------------------------------------- $data = array_map('trim', $data); // -------------------------------------- // Validate saved_id // -------------------------------------- if (empty($data['shortcut_id']) || !is_numeric($data['shortcut_id'])) { $data['shortcut_id'] = NULL; } // -------------------------------------- // Validate group_id // -------------------------------------- if (empty($data['group_id']) || !is_numeric($data['group_id'])) { $this->_errors['shortcut_invalid_group']; } // -------------------------------------- // Validate parameters // -------------------------------------- if (!empty($data['parameters'])) { // String, but not json if (is_string($data['parameters']) && substr($data['parameters'], 0, 1) != '{') { $data['parameters'] = low_search_decode($data['parameters']); } // Convert array to json if (is_array($data['parameters'])) { $data['parameters'] = low_search_encode($data['parameters'], FALSE); } // If something went wrong, skip it if (empty($data['parameters'])) { $this->_errors[] = 'shortcut_invalid_params'; } } else { $this->_errors[] = 'shortcut_no_params'; } // -------------------------------------- // Validate name // -------------------------------------- if (!empty($data['shortcut_name'])) { // shortcut_name should be url-safe if (preg_match('/^[\\w-]+$/', $data['shortcut_name'])) { // shortcut_name should be unique $query = ee()->db->from($this->table())->where('shortcut_name', $data['shortcut_name']); // Exclude this row if ($data['shortcut_id']) { ee()->db->where('shortcut_id !=', $data['shortcut_id']); } // Check it if ($query->count_all_results()) { $this->_errors[] = 'shortcut_name_not_available'; } } else { $this->_errors[] = 'shortcut_invalid_name'; } } else { $this->_errors[] = 'shortcut_no_name'; } // -------------------------------------- // Validate Label; fall back to name // -------------------------------------- if (empty($data['shortcut_label'])) { $data['shortcut_label'] = $data['shortcut_name']; } // -------------------------------------- // Return modified data if valid; FALSE if invalid // -------------------------------------- return empty($this->_errors) ? $data : FALSE; }
/** * Update routines for version 2.1.0 * * @access private * @return void */ private function _v210() { // Fields to add to the DB $fields = array('modifier' => 'decimal(2,1) unsigned NOT NULL default 1.0', 'excerpt' => 'int(6) unsigned NOT NULL default 0'); // Template query $tmpl = 'ALTER TABLE `%s` ADD `%s` %s AFTER `collection_label`'; $tbl = ee()->low_search_collection_model->table(); // Add fields foreach ($fields as $field => $properties) { ee()->db->query(sprintf($tmpl, $tbl, $field, $properties)); } // Get the collections and re-do the settings foreach (ee()->low_search_collection_model->get_all() as $row) { // Initiate data array $data = array(); // Decode the settings $settings = low_search_decode($row['settings'], FALSE); // Set new property values $data['modifier'] = (double) (isset($settings['modifier']) ? $settings['modifier'] : 1.0); $data['excerpt'] = (int) (isset($settings['excerpt']) ? $settings['excerpt'] : 0); // Remove these properties from settings unset($settings['modifier'], $settings['excerpt']); // filter it $settings = array_filter($settings); // Encode the new settings for DB usage $data['settings'] = low_search_encode($settings, FALSE); // Update row ee()->low_search_collection_model->update($row['collection_id'], $data); } }
/** * Transform {low_search:url} to {exp:low_search:url query=""} * * @access private * @param string * @return string */ private function _rewrite_url_vars($haystack) { $needle = LD . 'low_search:url'; $replace = LD . 'exp:low_search:url %s="%s"'; $param = $this->settings->get('encode_query') == 'y' ? 'query' : 'query_string'; if (strpos($haystack, $needle) !== FALSE) { // Make sure the query's an array $query = is_array($this->params->query) ? $this->params->query : array(); // For Form and Filters tag, add the tagparams to the query, too // The Results tag might have other params assigned or hard-coded // parameters, which needn't be added to the query if (ee()->TMPL->tagparts[1] != 'results' && is_array($this->params->tagparams)) { $query = array_merge($query, $this->params->tagparams); } // Encode it $query = empty($query) ? '' : low_search_encode($query); // And replace it in the template $haystack = str_replace($needle, sprintf($replace, $param, $query), $haystack); } return $haystack; }