Exemplo n.º 1
0
 /**
  * Get field id for given field short name
  *
  * @access      protected
  * @param       string
  * @param       array
  * @return      int
  */
 protected function _get_field_id($str, $fields = array())
 {
     // --------------------------------------
     // Get custom channel fields from cache
     // --------------------------------------
     if (empty($fields) && !($fields = low_get_cache('channel', 'custom_channel_fields'))) {
         // If not present, get them from the API
         // Takes some effort, but its reusable for others this way
         $this->_log('Getting channel field info from API');
         ee()->load->library('api');
         ee()->api->instantiate('channel_fields');
         $fields = ee()->api_channel_fields->fetch_custom_channel_fields();
         foreach ($fields as $key => $val) {
             low_set_cache('channel', $key, $val);
         }
         $fields = $fields['custom_channel_fields'];
     }
     // --------------------------------------
     // To be somewhat compatible with MSM,
     // get the first ID that matches,
     // not just for current site, but all given.
     // --------------------------------------
     // Initiate ID
     $it = 0;
     // Check active site IDs, return first match encountered
     foreach (ee()->low_search_params->site_ids() as $site_id) {
         if (isset($fields[$site_id][$str])) {
             $it = $fields[$site_id][$str];
             break;
         }
     }
     // Please
     return $it;
 }
 /**
  * Prep variable data for saving
  *
  * @param	int		$var_id			The id of the variable
  * @param	mixed	$var_data		The value of the variable, array or string
  * @param	array	$var_settings	The settings of the variable
  * @return	string
  */
 function save_input($var_id, $var_data, $var_settings)
 {
     // Include upload library
     $this->EE->load->library('upload');
     // Get upload setting
     $upload = $this->get_setting('upload', $var_settings);
     // -------------------------------------
     //  Is there a valid upload for this var id?
     // -------------------------------------
     if ($upload && isset($_FILES['newfile']['name'][$var_id]) && !empty($_FILES['newfile']['name'][$var_id])) {
         // -------------------------------------
         //  Fetch upload folder from cache or DB
         // -------------------------------------
         $upload_cache = low_get_cache(LOW_VAR_PACKAGE, 'uploads');
         if (isset($upload_cache[$upload])) {
             $folder = $upload_cache[$upload];
         } else {
             // Fetch record from DB
             if ($folder = $this->_get_upload_preferences(NULL, $upload)) {
                 // get folder and register to session cache
                 $upload_cache[$upload] = $folder;
                 low_set_cache(LOW_VAR_PACKAGE, 'uploads', $upload_cache);
             } else {
                 // -------------------------------------
                 //  Bail out if folder wasn't found
                 // -------------------------------------
                 $this->error_msg = 'folder_not_found';
                 return FALSE;
             }
         }
         unset($upload_cache);
         // -------------------------------------
         //  Reset and fill $_FILES['userfile']
         // -------------------------------------
         $_FILES['userfile'] = array();
         // Get uploaded files details from $_FILES
         foreach ($_FILES['newfile'] as $key => $val) {
             if (isset($val[$var_id])) {
                 $_FILES['userfile'][$key] = $val[$var_id];
             }
         }
         // -------------------------------------
         //  Set parameters according to folder prefs
         // -------------------------------------
         $config = array('upload_path' => $folder['server_path'], 'allowed_types' => $folder['allowed_types'] == 'img' ? 'gif|jpg|jpeg|png|jpe' : '*', 'max_size' => $folder['max_size'], 'max_width' => $folder['max_width'], 'max_height' => $folder['max_height']);
         $this->EE->upload->initialize($config);
         // -------------------------------------
         //  Upload the file
         // -------------------------------------
         if (!$this->EE->upload->do_upload()) {
             // Set error msg and bail if unsuccessful
             $this->error_msg = $this->EE->upload->error_msg;
             return FALSE;
         }
         // get the new file's full path; the data we're going to save
         $newfile = $folder['url'] . $this->EE->upload->file_name;
         if (is_array($var_data)) {
             // add it to the selected files
             $var_data[] = $newfile;
         } else {
             // or replace single value
             $var_data = $newfile;
         }
         // Create thumbnail for this
         $this->EE->load->library('filemanager');
         $this->EE->load->model('file_model');
         $folder['file_name'] = $this->EE->upload->file_name;
         $folder['dimensions'] = NULL;
         $this->EE->filemanager->create_thumb($folder['server_path'] . $this->EE->upload->file_name, $folder);
         // Add to native DB table
         $this->EE->file_model->save_file(array('site_id' => $this->site_id, 'title' => $this->EE->upload->file_name, 'upload_location_id' => $upload, 'rel_path' => $this->EE->upload->upload_path, 'mime_type' => $this->EE->upload->file_type, 'file_name' => $this->EE->upload->file_name, 'file_size' => $this->EE->upload->file_size, 'uploaded_by_member_id' => $this->EE->session->userdata['member_id'], 'upload_date' => $this->EE->localize->now));
     }
     // END if upload?
     // Return new value
     return is_array($var_data) ? implode($this->separators[$this->get_setting('separator', $var_settings)], $var_data) : $var_data;
 }
 /**
  * Get settings
  *
  * @access     protected
  * @param      array
  * @return     array
  */
 protected function get_settings($settings = array())
 {
     if (!$settings) {
         // Check cache
         if (($this->settings = low_get_cache($this->package, 'settings')) === FALSE) {
             // Not in cache? Get from DB and add to cache
             $query = $this->EE->db->select('settings')->from('extensions')->where('class', $this->package . '_ext')->limit(1)->get();
             $this->settings = (array) @unserialize($query->row('settings'));
             // Add to cache
             low_set_cache($this->package, 'settings', $this->settings);
         }
     } else {
         $this->settings = $settings;
     }
     // Always fallback to default settings
     $this->settings = array_merge($this->default_settings, $this->settings);
     return $this->settings;
 }
Exemplo n.º 4
0
 /**
  * Check whether given field id is a playa field
  */
 private function _is_playa_field($id)
 {
     $it = FALSE;
     if ($fields = low_get_cache('channel', 'pair_custom_fields')) {
         $it = strpos($this->_get_field_id($id, $fields), 'playa') !== FALSE;
     }
     return $it;
 }
Exemplo n.º 5
0
 /**
  * Get category id from param, URI, DB or Cache
  *
  * @access      private
  * @param       array    limited by these category groups
  * @return      int
  */
 private function _get_cat_id($cat_groups = array())
 {
     // --------------------------------------
     // Check category parameter first
     // --------------------------------------
     if ($cat_id = ee()->TMPL->fetch_param('category')) {
         $this->_log("Retrieving cat_id from parameter");
         return $cat_id;
     }
     // --------------------------------------
     // Check URI for C123
     // --------------------------------------
     if (preg_match('#/?C(\\d+)(/|$)#', ee()->uri->uri_string(), $match)) {
         $this->_log("Retrieving cat_id from URI");
         return $match[1];
     }
     // --------------------------------------
     // Check URI for category keyword
     // --------------------------------------
     // Check if cat group is not empty and reserved category word is valid
     if ($cat_groups && ee()->config->item('use_category_name') == 'y' && ($cat_word = ee()->config->item('reserved_category_word')) != '') {
         // Check if reserved cat word is in URI and if there's a segment behind it
         if (($key = array_search($cat_word, ee()->uri->segment_array())) && ($cat_url_title = ee()->uri->segment($key + 1))) {
             // Get category cache
             $categories = (array) low_get_cache(LOW_REORDER_PACKAGE, 'categories');
             // Fetch cat_id from DB if not in cache
             if (!($cat_id = (int) array_search($cat_url_title, $categories))) {
                 $this->_log("Retrieving cat_id from database");
                 $query = ee()->db->select('cat_id, cat_url_title')->from('categories')->where('cat_url_title', $cat_url_title)->where_in('group_id', $cat_groups)->get();
                 $cat_id = $query->row('cat_id');
                 $categories[$cat_id] = $query->row('cat_url_title');
                 low_set_cache(LOW_REORDER_PACKAGE, 'categories', $categories);
             } else {
                 $this->_log("Retrieving cat_id from cache");
             }
             // Return the cat id
             return $cat_id;
         }
     }
     // Return 0 by default if all else fails
     return 0;
 }
Exemplo n.º 6
0
 /**
  * Add search score to channel entries
  *
  * @access      public
  * @param       object
  * @param       array
  * @return      array
  */
 public function channel_entries_query_result($obj, $query)
 {
     // -------------------------------------------
     // Get the latest version of $query
     // -------------------------------------------
     if (ee()->extensions->last_call !== FALSE) {
         $query = ee()->extensions->last_call;
     }
     // -------------------------------------------
     // Bail out if we're not Low Searching
     // -------------------------------------------
     if (ee()->TMPL->fetch_param('low_search') != 'yes') {
         return $query;
     }
     // -------------------------------------------
     // Get variables from parameters
     // -------------------------------------------
     $vars = ee()->low_search_params->get_vars(ee()->low_search_settings->prefix);
     // -------------------------------------------
     // Add shortcut data to vars
     // -------------------------------------------
     if ($row = low_get_cache(LOW_SEARCH_PACKAGE, 'shortcut')) {
         foreach (ee()->low_search_shortcut_model->get_template_attrs() as $key) {
             $vars[ee()->low_search_settings->prefix . $key] = $row[$key];
         }
     }
     // -------------------------------------------
     // Loop through entries and add items
     // -------------------------------------------
     foreach ($query as &$row) {
         // Add all search parameters to entry
         $row = array_merge($row, $vars);
     }
     // Check what the filters are doing
     $query = ee()->low_search_filters->results($query);
     return $query;
 }
 /**
  * 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'");
     }
 }
Exemplo n.º 8
0
 /**
  * Get channel fields from Cache or DB
  *
  * @access     private
  * @return     array
  */
 private function _get_channel_fields()
 {
     // --------------------------------------
     // Try and get channel field data from cache
     // --------------------------------------
     if (!($fields = low_get_cache('channel', 'custom_channel_fields'))) {
         // Load channel fields API
         ee()->load->library('api');
         ee()->api->instantiate('channel_fields');
         // Call API
         $fields = ee()->api_channel_fields->fetch_custom_channel_fields();
         // Register to cache
         foreach ($fields as $key => $val) {
             low_set_cache('channel', $key, $val);
         }
         // Shortcut
         $fields = $fields['custom_channel_fields'];
     }
     // --------------------------------------
     // Return the custom channel fields
     // --------------------------------------
     return $fields[$this->site_id];
 }
Exemplo n.º 9
0
 /**
  * Check whether given string is a grid field
  */
 private function _get_matrix_col_id($field_id, $col_name)
 {
     $matrix_cols = low_get_cache(LOW_SEARCH_PACKAGE, 'matrix_cols');
     if (!isset($matrix_cols[$field_id])) {
         $query = ee()->db->select('col_id, col_name')->from('matrix_cols')->where('field_id', $field_id)->get();
         foreach ($query->result() as $row) {
             $matrix_cols[$field_id][$row->col_id] = $row->col_name;
         }
         low_set_cache(LOW_SEARCH_PACKAGE, 'matrix_cols', $matrix_cols);
     }
     return array_search($col_name, $matrix_cols[$field_id]);
 }
Exemplo n.º 10
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);
     }
 }
Exemplo n.º 11
0
 /**
  * Check whether given string is a date field
  */
 private function _is_date_field($str)
 {
     $it = FALSE;
     if (in_array($str, $this->_native_dates)) {
         $it = TRUE;
     } elseif ($fields = low_get_cache('channel', 'date_fields')) {
         $it = (bool) $this->_get_field_id($str, $fields);
     }
     return $it;
 }
 /**
  * Get variables types from cache or settings
  *
  * @access     private
  * @return     array
  */
 private function _get_types()
 {
     if (($this->types = low_get_cache($this->package, 'types')) === FALSE) {
         $this->get_settings();
         $this->types = $this->get_types($this->settings['enabled_types']);
         low_set_cache($this->package, 'types', $this->types);
     }
     return $this->types;
 }
Exemplo n.º 13
0
 /**
  * Add reverse count to channel entries
  *
  * @access      public
  * @param       object
  * @param       array
  * @return      array
  */
 public function channel_entries_query_result($obj, $query)
 {
     // -------------------------------------------
     // Get the latest version of $query
     // -------------------------------------------
     if (ee()->extensions->last_call !== FALSE) {
         $query = ee()->extensions->last_call;
     }
     // -------------------------------------------
     // Fire for low_reorder only
     // -------------------------------------------
     if (ee()->TMPL->fetch_param('low_reorder') == 'yes') {
         // Get the set id
         $set_id = (int) low_get_cache($this->package, 'set_id');
         $cat_id = (int) low_get_cache($this->package, 'cat_id');
         $total_results = count($query);
         $reverse_count = ee()->TMPL->fetch_param('reverse_count', 'reverse_count');
         foreach ($query as &$row) {
             // Add set id & cat id
             $row['low_reorder_set_id'] = $set_id;
             $row['low_reorder_category_id'] = $cat_id;
             // Add reverse count
             if (!isset($row[$reverse_count])) {
                 $row[$reverse_count] = $total_results--;
             }
         }
     }
     // -------------------------------------------
     // Return (modified) query
     // -------------------------------------------
     return $query;
 }