/**
  * 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);
 }
示例#2
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));
 }
示例#3
0
 /**
  * Freeform Fieldtype installable
  *
  * returns all of the installable fieldtypes with
  * install status, and versions
  *
  * @access	public
  * @param 	array  	filter array to only get what we need? (TODO)
  * @param 	boolean use cache?
  * @return	array 	installable fieldtypes, install status, and versions
  */
 public function get_installable_fieldtypes($filter = array(), $use_cache = TRUE)
 {
     $cache = new Freeform_cacher(func_get_args(), __FUNCTION__, __CLASS__);
     if ($use_cache and $cache->is_set()) {
         return $cache->get();
     }
     ee()->load->helper('directory');
     $fieldtypes = $this->get_default_fieldtypes();
     $installed_fieldtypes = ee()->freeform_fieldtype_model->installed_fieldtypes();
     $installed_updated = FALSE;
     //PHP 5.3 is a million times faster at this
     if (class_exists('DirectoryIterator')) {
         $third_party_fields = array();
         foreach (new DirectoryIterator(PATH_THIRD) as $fileInfo) {
             if ($fileInfo->isDir() && !$fileInfo->isDot()) {
                 $third_party_fields[$fileInfo->getFilename()] = array();
             }
         }
     } else {
         $third_party_fields = directory_map(PATH_THIRD);
     }
     //each item in the path third
     foreach ($third_party_fields as $name => $folder) {
         $file = 'freeform_ft.' . strtolower($name) . '.php';
         $pkg_path = PATH_THIRD . strtolower($name) . '/';
         if (is_array($folder) and $name !== 'freeform' and file_exists($pkg_path . $file)) {
             $ft_lower_name = strtolower($name);
             //$match[1];
             $ft_class_name = ucfirst($ft_lower_name . '_freeform_ft');
             //$pkg_path		= PATH_THIRD . strtolower($name) . '/';
             include_once $pkg_path . $file;
             //if we cannot even get a class, move on
             if (class_exists($ft_class_name)) {
                 ee()->load->add_package_path($pkg_path);
                 $this->lang_autoload($name);
                 //new instance? YEAAAH
                 $ft_temp = new $ft_class_name();
                 $installed = array_key_exists($ft_lower_name, $installed_fieldtypes);
                 //version, description required, dog
                 $fieldtypes[$ft_lower_name] = array('name' => $ft_temp->info['name'], 'version' => $ft_temp->info['version'], 'description' => $ft_temp->info['description'], 'installed' => $installed, 'default_type' => FALSE, 'class_name' => $ft_class_name);
                 //higher version number? run update
                 if ($fieldtypes[$ft_lower_name]['installed'] and $this->version_compare($fieldtypes[$ft_lower_name]['version'], '>', $installed_fieldtypes[$ft_lower_name]['version'])) {
                     $ft_temp->update();
                     //update version number
                     ee()->freeform_fieldtype_model->update(array('fieldtype_name' => $ft_lower_name), array('version' => $fieldtypes[$ft_lower_name]['version']));
                 }
                 //mem and crap
                 unset($ft_temp);
                 ee()->load->remove_package_path($pkg_path);
             }
         }
     }
     //END foreach ($third_party_fields as $name => $folder)
     ksort($fieldtypes);
     return $cache->set($fieldtypes);
 }
 /**
  * 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);
 }
示例#5
0
 /**
  * Freeform Fieldtype installable
  *
  * returns all of the installable fieldtypes with
  * install status, and versions
  *
  * @access	public
  * @param 	array  	filter array to only get what we need? (TODO)
  * @param 	boolean use cache?
  * @return	array 	installable fieldtypes, install status, and versions
  */
 public function get_installable_fieldtypes($filter = array(), $use_cache = TRUE)
 {
     $cache = new Freeform_cacher(func_get_args(), __FUNCTION__, __CLASS__);
     if ($use_cache and $cache->is_set()) {
         return $cache->get();
     }
     ee()->load->helper('directory');
     $fieldtypes = $this->get_default_fieldtypes();
     ksort($fieldtypes);
     return $cache->set($fieldtypes);
 }