/**
  * Get countries
  *
  * @access	public
  * @return	mixed
  */
 public function get_countries()
 {
     $cache = new Freeform_cacher(func_get_args(), __FUNCTION__, __CLASS__);
     if ($cache->is_set()) {
         return $cache->get();
     }
     $output = array();
     // --------------------------------------------
     // Get countries from config
     // --------------------------------------------
     $countries_file = APPPATH . 'config/countries.php';
     if (is_file($countries_file)) {
         include $countries_file;
         if (!empty($countries)) {
             $output = $countries;
         }
     }
     return $cache->set($output);
 }
 /**
  * Clear
  *
  * Clear a data groups function, a data group or all cache data.
  * sending no params clears all cache data.
  *
  * @static
  * @access public
  * @param  string $data_group data group to clear
  * @param  string $func       function to clear
  * @return null
  */
 public static function clear($data_group = '', $func = '')
 {
     $data_group = strtolower($data_group);
     if ($data_group !== '' and $func !== '') {
         unset(self::$cache[$data_group][$func]);
     } else {
         if ($data_group !== '') {
             unset(self::$cache[$data_group]);
         } else {
             self::$cache = array();
         }
     }
 }
예제 #3
0
 /**
  * Freeform Fieldtype Installed
  *
  * Returns true if a fieldtype is installed, false if not
  * caches list of installed fieldtypes
  *
  * @access	public
  * @param	string 		$ft_name 	fieldtype name
  * @return	boolean
  */
 public function freeform_fieldtype_installed($ft_name)
 {
     //cache?
     $cache = new Freeform_cacher(func_get_args(), __FUNCTION__, __CLASS__);
     if ($cache->is_set()) {
         return $cache->get();
     }
     ee()->load->model('freeform_fieldtyle_model');
     $installed_fieldtypes = ee()->freeform_fieldtype_model->installed_fieldtypes();
     //set cache and return
     return $cache->set(array_key_exists($ft_name, $installed_fieldtypes));
 }
예제 #4
0
 /**
  * Delete Field
  *
  * checks field to see if its in any forms, then removes the field
  *
  * @access public
  * @param  mixed 	int/array of ints 	$field_id field id to delete
  * @return boolean	success
  */
 public function delete_field($field_ids)
 {
     if (!is_array($field_ids) and !$this->is_positive_intlike($field_ids)) {
         return FALSE;
     }
     if (!is_array($field_ids)) {
         $field_ids = array($field_ids);
     }
     $field_ids = array_filter($field_ids, array($this, 'is_positive_intlike'));
     ee()->load->library('freeform_forms');
     //go through each field and remove it from every form its in
     $remove_fields = array();
     foreach ($field_ids as $field_id) {
         $field_form_data = $this->data->get_form_info_by_field_id($field_id);
         if ($field_form_data !== FALSE) {
             foreach ($field_form_data as $form_id => $form_data) {
                 ee()->freeform_forms->remove_field_from_form($form_id, $field_id);
             }
         }
         $instance =& $this->get_field_instance($field_id);
         if (is_callable(array($instance, 'delete_field'))) {
             $instance->delete_field();
         }
         $remove_fields[] = $field_id;
     }
     if (empty($remove_fields)) {
         return FALSE;
     }
     //delete all fields
     ee()->freeform_field_model->where_in('field_id', $remove_fields)->delete();
     Freeform_cacher::clear(__CLASS__, 'get_field_instance');
     return TRUE;
 }
예제 #5
0
 /**
  * Clear class cache
  *
  * @access public
  * @param  string $func function to clear on, else clears entire class
  * @return object       returns $this for chaining
  */
 public function clear_cache($func = '')
 {
     if (trim($func) !== '') {
         Freeform_cacher::clear($this->class, $func);
     } else {
         Freeform_cacher::clear($this->class);
     }
     return $this;
 }
 /**
  * Subscribe to lists
  *
  * @access	private
  * @param	array 	emails to be subscribed
  * @param	array 	lists to be joined
  */
 private function subscribe_to_lists($data = array(), $emails = array())
 {
     if (empty($data) or !is_array($data)) {
         return FALSE;
     }
     // -------------------------------------
     //	Cache
     // -------------------------------------
     $cache = new Freeform_cacher(array($emails, $data), __FUNCTION__, __CLASS__);
     if ($cache->is_set()) {
         return $cache->get();
     }
     // -------------------------------------
     //	Get lists
     // -------------------------------------
     $this->lists = $this->get_lists();
     // -------------------------------------
     //	Clean
     // -------------------------------------
     $subscribe = array();
     $unsubscribe = array();
     foreach ($data as $key => $val) {
         if (!is_numeric($key) or !isset($this->lists[$key])) {
             continue;
         }
         if ($val == 'n') {
             $unsubscribe[] = $key;
         } else {
             $subscribe[] = $key;
         }
         $data = $subscribe;
     }
     // -------------------------------------
     //	Instantiate module
     // -------------------------------------
     if (class_exists('Mailinglist') === FALSE) {
         require PATH_MOD . '/mailinglist/mod.mailinglist' . EXT;
     }
     $mailinglist = new Mailinglist();
     // -------------------------------------
     //	Get current subscriptions
     // -------------------------------------
     $current_subscriptions = array();
     if (!empty($emails)) {
         $query = ee()->db->query("SELECT email, list_id\n\t\t\t\t FROM exp_mailing_list\n\t\t\t\t WHERE email\n\t\t\t\t IN ('" . implode("','", $emails) . "')\n\t\t\t\t AND list_id\n\t\t\t\t IN (" . implode(',', array_keys($this->lists)) . ")");
         foreach ($query->result_array() as $row) {
             $current_subscriptions[$row['email']][$row['list_id']] = $row['list_id'];
         }
     }
     // -------------------------------------
     //	Loop for email
     // -------------------------------------
     foreach ($emails as $email) {
         // Kill duplicate emails from authorization queue.  This prevents an error if a user
         // signs up but never activates their email, then signs up again.  Note- check for list_id
         // as they may be signing up for two different lists
         $sql = "DELETE FROM exp_mailing_list_queue\n\t\t\t\t\t\tWHERE email = '" . ee()->db->escape_str($email) . "'";
         if (!empty($subscribe)) {
             $sqla[] = " list_id IN ('" . implode("','", $subscribe) . "')";
         }
         if (!empty($unsubscribe)) {
             $sqla[] = " list_id IN ('" . implode("','", $unsubscribe) . "')";
         }
         if (!empty($sqla)) {
             $sql .= " AND (" . implode(" OR ", $sqla) . ")";
         }
         ee()->db->query($sql);
         // -------------------------------------
         //	Subscribe
         // -------------------------------------
         $code = ee()->functions->random('alnum', 10);
         foreach ($subscribe as $list_id) {
             if (isset($current_subscriptions[$email][$list_id])) {
                 continue;
             }
             if (empty($this->settings['send_email_confirmation']) or $this->settings['send_email_confirmation'] != 'y') {
                 ee()->db->query("INSERT INTO exp_mailing_list (list_id, authcode, email, ip_address)\n\t\t\t\t\t\t\t\t\t\t  VALUES ('" . ee()->db->escape_str($list_id) . "', '" . $code . "', '" . ee()->db->escape_str($email) . "', '" . ee()->db->escape_str(ee()->input->ip_address()) . "')");
             } else {
                 ee()->db->query("INSERT INTO exp_mailing_list_queue (email, list_id, authcode, date) VALUES ('" . ee()->db->escape_str($email) . "', '" . ee()->db->escape_str($list_id) . "', '" . $code . "', '" . time() . "')");
                 $mailinglist->send_email_confirmation($email, $code, $list_id);
             }
         }
         // -------------------------------------
         //	Unsubscribe
         // -------------------------------------
         if (!empty($current_subscriptions[$email]) and !empty($unsubscribe)) {
             $uns = array_intersect($current_subscriptions[$email], $unsubscribe);
         }
         if (!empty($uns)) {
             $sql = "DELETE FROM exp_mailing_list WHERE email = '" . ee()->db->escape_str($email) . "' AND list_id IN (" . implode(',', $uns) . ")";
             ee()->db->query($sql);
             $sql = "DELETE FROM exp_mailing_list_queue WHERE email = '" . ee()->db->escape_str($email) . "' AND list_id IN (" . implode(',', $uns) . ")";
             ee()->db->query($sql);
         }
     }
     // -------------------------------------
     //	return
     // -------------------------------------
     return $cache->set($data);
 }
예제 #7
0
 /**
  * Main Export function for returning or forcing a download of file
  *
  * @access public
  * @param  array  	$options various download options. Form_id and query required
  * @return string 	string of file contents or exit on array
  */
 public function export($options = array())
 {
     // -------------------------------------
     //	run defaults
     // -------------------------------------
     $defaults = array('method' => 'csv', 'form_id' => 0, 'form_name' => '', 'output' => 'string', 'rows' => array(), 'model' => NULL, 'fields' => '*', 'remove_entry_id' => FALSE, 'header_labels' => array(), 'total_entries' => 0);
     foreach ($defaults as $key => $value) {
         if (isset($options[$key])) {
             $defaults[$key] = $options[$key];
         }
     }
     extract($defaults);
     unset($defaults, $options);
     $chunk = FALSE;
     $chunk_start = FALSE;
     $chunk_end = FALSE;
     // -------------------------------------
     //	check prelim data
     // -------------------------------------
     if ((!is_array($rows) or empty($rows)) and !$model or !$this->is_positive_intlike($form_id)) {
         return FALSE;
     }
     // -------------------------------------
     //	cache clean
     // -------------------------------------
     $this->clean_file_cache();
     // -------------------------------------
     //	export
     // -------------------------------------
     $method = is_callable(array($this, $method)) ? $method : 'csv';
     //return a string to write somewhere?
     if ($output == 'string') {
         if (empty($rows) and $model) {
             $rows = $model->get();
         }
         return $this->{$method}(array('form_id' => $form_id, 'rows' => $rows, 'remove_entry_id' => $remove_entry_id, 'header_labels' => $header_labels, 'chunk' => $chunk, 'chunk_start' => $chunk_start, 'chunk_end' => $chunk_end));
     } else {
         $form_name = rtrim(trim($form_name), '_') . '_';
         $filename = ee()->security->sanitize_filename('freeform_' . $form_name . 'export_' . date('Ymd_Hi_s', ee()->localize->now) . '.' . $method);
         //do we need to chunk this?
         if (empty($rows) and $model and $total_entries > $this->export_chunk_size) {
             //Set the execution time to infinite.
             set_time_limit(0);
             //detect chunk size
             $chunk_size = ceil($total_entries / $this->export_chunk_size);
             // -------------------------------------
             //	get file path and check writability
             // -------------------------------------
             ee()->load->helper('file');
             $filepath = $this->cache_file_path($filename);
             //blank
             write_file($filepath, '');
             //chunk and write
             for ($i = 0; $i < $chunk_size; $i++) {
                 $model->limit($this->export_chunk_size, $i * $this->export_chunk_size);
                 $data = $this->{$method}(array('form_id' => $form_id, 'remove_entry_id' => $remove_entry_id, 'header_labels' => $header_labels, 'rows' => $model->get(array(), FALSE), 'chunk' => TRUE, 'chunk_start' => $i == 0, 'chunk_end' => $i == $chunk_size - 1));
                 write_file($filepath, $data, 'a+');
                 unset($data);
                 Freeform_cacher::clear();
             }
             // -------------------------------------
             //	send to user
             // -------------------------------------
             header('Content-disposition: attachment; filename=' . $filename);
             header('Content-type: ' . get_mime_by_extension($filename));
             readfile($filepath);
             exit;
         } else {
             if (empty($rows) and $model) {
                 $rows = $model->get();
             }
             $data = $this->{$method}(array('form_id' => $form_id, 'rows' => $rows, 'remove_entry_id' => $remove_entry_id, 'header_labels' => $header_labels, 'chunk' => $chunk, 'chunk_start' => $chunk_start, 'chunk_end' => $chunk_end));
             if ($data) {
                 ee()->load->helper('download');
                 force_download($filename, $data);
                 exit;
             }
         }
         //fail safe
         $this->actions()->full_stop(lang('error_creating_export'));
     }
 }