public function get_payment_feed($entry, $form = false)
 {
     $submission_feed = GFCache::get('payment_feed');
     if (!$submission_feed) {
         if ($entry['id']) {
             $feeds = $this->get_feeds_by_entry($entry['id']);
             $submission_feed = $this->get_feed($feeds[0]);
         } else {
             if ($form) {
                 // getting all active feeds
                 $feeds = $this->get_feeds($form['id']);
                 foreach ($feeds as $feed) {
                     if ($this->is_feed_condition_met($feed, $form, $entry)) {
                         $submission_feed = $feed;
                         break;
                     }
                 }
             }
         }
         // if called without $form, there is assumption that cache has already been set; let's avoid issues where the cache has not been set and form was not provided
         // so that the cache will only be set when an $entry and $form object are provided
         if ($entry && $form) {
             GFCache::set('payment_feed', $submission_feed);
         }
     }
     return $submission_feed;
 }
 /**
  * @param $lead
  * @param $field GF_Field
  *
  * @return array|bool|mixed|string|void
  */
 public static function get_lead_field_value($lead, $field)
 {
     if (empty($lead)) {
         return;
     }
     $field_id = $field instanceof GF_Field ? $field->id : $field['id'];
     //returning cache entry if available
     $cache_key = 'GFFormsModel::get_lead_field_value_' . $lead['id'] . '_' . $field_id;
     $cache_value = GFCache::get($cache_key);
     if ($cache_value !== false) {
         return $cache_value;
     }
     $max_length = GFORMS_MAX_FIELD_LENGTH;
     $value = array();
     $inputs = $field instanceof GF_Field ? $field->get_entry_inputs() : rgar($field, 'inputs');
     if (is_array($inputs)) {
         //making sure values submitted are sent in the value even if
         //there isn't an input associated with it
         $lead_field_keys = array_keys($lead);
         natsort($lead_field_keys);
         foreach ($lead_field_keys as $input_id) {
             if (is_numeric($input_id) && absint($input_id) == absint($field->id)) {
                 $val = $lead[$input_id];
                 if (strlen($val) >= $max_length - 10) {
                     if (empty($form)) {
                         $form = RGFormsModel::get_form_meta($lead['form_id']);
                     }
                     $long_choice = self::get_field_value_long($lead, $input_id, $form);
                 } else {
                     $long_choice = $val;
                 }
                 $value[$input_id] = !empty($long_choice) ? $long_choice : $val;
             }
         }
     } else {
         $val = rgget($field_id, $lead);
         //To save a database call to get long text, only getting long text if regular field is 'somewhat' large (i.e. max - 50)
         if (strlen($val) >= $max_length - 50) {
             if (empty($form)) {
                 $form = RGFormsModel::get_form_meta($lead['form_id']);
             }
             $long_text = self::get_field_value_long($lead, $field_id, $form);
         }
         $value = !empty($long_text) ? $long_text : $val;
     }
     //filtering lead value
     $value = apply_filters('gform_get_field_value', $value, $lead, $field);
     //saving value in global variable to optimize performance
     GFCache::set($cache_key, $value);
     return $value;
 }
Esempio n. 3
0
 public static function is_section_empty($section_field, $form, $lead)
 {
     $cache_key = "GFCommon::is_section_empty_" . $form["id"] . "_" . $section_field["id"];
     $value = GFCache::get($cache_key);
     if ($value !== false) {
         return $value == true;
     }
     $fields = self::get_section_fields($form, $section_field["id"]);
     if (!is_array($fields)) {
         GFCache::set($cache_key, 1);
         return true;
     }
     foreach ($fields as $field) {
         $val = RGFormsModel::get_lead_field_value($lead, $field);
         $val = GFCommon::get_lead_field_display($field, $val, rgar($lead, 'currency'));
         if (!self::is_product_field($field["type"]) && !rgblank($val)) {
             GFCache::set($cache_key, 0);
             return false;
         }
     }
     GFCache::set($cache_key, 1);
     return true;
 }
Esempio n. 4
0
 public function is_locked($object_id)
 {
     if (!($user_id = GFCache::get(self::PREFIX_EDIT_LOCK . $this->_object_type . '_' . $object_id))) {
         return false;
     }
     if ($user_id != get_current_user_id()) {
         return true;
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Check whether a field is hidden via conditional logic.
  *
  * @param array    $form         Form object.
  * @param GF_Field $field        Field object.
  * @param array    $field_values Default field values for this form. Used when form has not yet been submitted. Pass an array if no default field values are available/required.
  * @param array    $lead         Optional, default is null. If lead object is available, pass the lead.
  *
  * @return mixed
  */
 public static function is_field_hidden($form, $field, $field_values, $lead = null)
 {
     if (empty($field)) {
         return false;
     }
     $cache_key = 'GFFormsModel::is_field_hidden_' . $form['id'] . '_' . $field->id;
     $display = GFCache::get($cache_key);
     if ($display !== false) {
         return $display;
     }
     $section = self::get_section($form, $field->id);
     $section_display = self::get_field_display($form, $section, $field_values, $lead);
     //if section is hidden, hide field no matter what. if section is visible, see if field is supposed to be visible
     if ($section_display == 'hide') {
         $display = 'hide';
     } else {
         if (self::is_page_hidden($form, $field->pageNumber, $field_values, $lead)) {
             $display = 'hide';
         } else {
             $display = self::get_field_display($form, $field, $field_values, $lead);
             return $display == 'hide';
         }
     }
     GFCache::set($cache_key, $display);
     return $display == 'hide';
 }
 public static function is_section_empty($section_field, $form, $entry)
 {
     $cache_key = "GFCommon::is_section_empty_{$form['id']}_{$section_field['id']}";
     $value = GFCache::get($cache_key);
     if ($value !== false) {
         return $value == true;
     }
     $fields = self::get_section_fields($form, $section_field['id']);
     if (!is_array($fields)) {
         GFCache::set($cache_key, 1);
         return true;
     }
     foreach ($fields as $field) {
         $value = GFFormsModel::get_lead_field_value($entry, $field);
         $value = GFCommon::get_lead_field_display($field, $value, rgar($entry, 'currency'));
         if (rgblank($value)) {
             continue;
         }
         // most fields are displayed in the section by default, exceptions are handled below
         $is_field_displayed_in_section = true;
         // by default, product fields are not displayed in their containing section (displayed in a product summary table)
         // if the filter is used to disable this, product fields are displayed in the section like other fields
         if (self::is_product_field($field['type'])) {
             $display_product_summary = apply_filters('gform_display_product_summary', true, $field, $form, $entry);
             $is_field_displayed_in_section = !$display_product_summary;
         }
         if ($is_field_displayed_in_section) {
             GFCache::set($cache_key, 0);
             return false;
         }
     }
     GFCache::set($cache_key, 1);
     return true;
 }
 public function get_feeds($form_id = null)
 {
     global $wpdb;
     $cache_key = implode('_', array_filter(array($this->_slug, 'get_feeds', $form_id)));
     $feeds = GFCache::get($cache_key);
     if (is_array($feeds)) {
         return $feeds;
     }
     $form_filter = is_numeric($form_id) ? $wpdb->prepare("AND form_id=%d", absint($form_id)) : "";
     $sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}gf_addon_feed\n                               WHERE addon_slug=%s {$form_filter}", $this->_slug);
     $results = $wpdb->get_results($sql, ARRAY_A);
     foreach ($results as &$result) {
         $result["meta"] = json_decode($result["meta"], true);
     }
     GFCache::set($cache_key, $results);
     return $results;
 }
 public function get_group_setting_key($grouping_id, $group_name)
 {
     $plugin_settings = GFCache::get('mailchimp_plugin_settings');
     if (empty($plugin_settings)) {
         $plugin_settings = $this->get_plugin_settings();
         GFCache::set('mailchimp_plugin_settings', $plugin_settings);
     }
     $key = 'group_key_' . $grouping_id . '_' . str_replace('%', '', sanitize_title_with_dashes($group_name));
     if (!isset($plugin_settings[$key])) {
         $group_key = 'mc_group_' . uniqid();
         $plugin_settings[$key] = $group_key;
         $this->update_plugin_settings($plugin_settings);
         GFCache::set('mailchimp_plugin_settings', $plugin_settings);
     }
     return $plugin_settings[$key];
 }
 /**
  * Returns the results in an array of HTML formatted data.
  *
  * @param int $formid The form ID.
  * @param string $display_field
  * @param string $style
  * @param bool $show_percentages
  * @param bool $show_counts
  * @param array $lead
  *
  * @return array
  */
 public function gpoll_get_results($formid, $display_field = '0', $style = 'green', $show_percentages = true, $show_counts = true, $lead = array())
 {
     $gpoll_output = array();
     $gpoll_data = array();
     // each bar will receive this HTML formatting
     $bar_html = "<div class='gpoll_wrapper {$style}'><div class='gpoll_ratio_box'><div class='gpoll_ratio_label'>%s</div></div><div class='gpoll_bar'>";
     $bar_html .= "<span class='gpoll_bar_juice' data-origwidth='%s' style='width: %s%%'><span class='gpoll_bar_count'>%s</span></span></div></div>";
     // if data is cached then pull the data out of the cache
     if (false === ($gpoll_data = GFCache::get('gpoll_data_' . $formid))) {
         // cache has timed out so get the data again and cache it again
         $gpoll_data = $this->update_cache($formid);
     }
     // build HTML output
     $gpoll_output['summary'] = "<div class='gpoll_container'>";
     $field_counter = 0;
     // loop through polls data field by field
     foreach ($gpoll_data['fields'] as $field) {
         $fieldid = $field['field_id'];
         // only build html for the field(s) specified in the parameter. 0 = all fields
         if (is_array($display_field)) {
             if (false === in_array($fieldid, $display_field)) {
                 continue;
             }
         } elseif ($display_field != '0' && $fieldid != $display_field) {
             continue;
         }
         // build 2 sections: summary and individual fields
         $field_number = $field_counter + 1;
         $gpoll_output['summary'] .= "<div class='gpoll_field'>";
         $gpoll_output['summary'] .= "<div class='gpoll_field_label_container'>";
         $gpoll_output['summary'] .= "<div class='gpoll_field_label'>";
         $gpoll_output['summary'] .= $field['field_label'] . '</div></div>';
         // the individual fields HTML was used in the past but not used now.
         // it was used to display results 'inline' with the form (i.e. form input then the bar below)
         // I've left it because it may be useful either to designers or for a future use
         $gpoll_output['fields'][$field_counter]['field_id'] = $field['field_id'];
         $gpoll_output['fields'][$field_counter]['type'] = $field['type'];
         $selected_values = array();
         // if the lead object is passed then prepare to highlight the selected choices
         if (!empty($lead)) {
             $form_meta = RGFormsModel::get_form_meta($formid);
             // collect all the responses in the lead for this field
             $selected_values = $this->get_selected_values($form_meta, $fieldid, $lead);
             //collect all the choices that are currently possible in the field
             $possible_choices = $this->get_possible_choices($form_meta, $fieldid);
             $form_meta_field = RGFormsModel::get_field($form_meta, $fieldid);
             // if the 'other' option is selected for this field
             // add the psuedo-value 'gpoll_other' if responses are found that are not in the list of possible choices
             if ($form_meta_field->enableOtherChoice) {
                 foreach ($selected_values as $selected_value) {
                     if (!in_array($selected_value, $possible_choices)) {
                         array_push($selected_values, 'gpoll_other');
                     }
                 }
             }
         }
         // loop through all the inputs in this field (poll data field not form object field) and build the HTML for the bar
         $input_counter = 0;
         foreach ($field['inputs'] as $input) {
             //highlight the selected value by adding a class to the label
             $selected_class = '';
             if (in_array(rgar($input, 'value'), $selected_values)) {
                 $selected_class .= ' gpoll_value_selected';
             }
             //build the bar and add it to the summary
             $gpoll_output['summary'] .= sprintf("<div class='gpoll_choice_label%s'>%s</div>", $selected_class, rgar($input, 'label'));
             $ratio = rgar($input, 'ratio');
             $count = $show_counts === true ? rgar($input, 'total_entries') : '';
             $percentage_label = $show_percentages === true ? $ratio . '%' : '';
             $input_html = sprintf($bar_html, $percentage_label, $ratio, $ratio, $count);
             $gpoll_output['summary'] .= $input_html;
             //add the bar HTML to the fields array ready to output alongside the summary
             $input_data = array('input_id' => rgar($input, 'input_id'), 'label' => rgar($input, 'label'), 'total_entries' => $input['total_entries'], 'ratio' => $input['ratio'], 'bar_html' => $input_html);
             $gpoll_output['fields'][$field_counter]['inputs'][$input_counter] = $input_data;
             $input_counter += 1;
         }
         $gpoll_output['summary'] .= '</div>';
         $field_counter += 1;
     }
     $gpoll_output['summary'] .= '</div>';
     return $gpoll_output;
 }
 public function get_payment_feed($entry, $form)
 {
     $submission_feed = GFCache::get("payment_feed");
     if (!$submission_feed) {
         if (!empty($entry["id"])) {
             $feeds = $this->get_processed_feeds($entry["id"]);
             $submission_feed = $this->get_feed($feeds[0]);
         } else {
             // getting all active feeds
             $feeds = $this->get_feeds($form['id']);
             foreach ($feeds as $feed) {
                 if ($this->is_feed_condition_met($feed, $form, $entry)) {
                     $submission_feed = $feed;
                     break;
                 }
             }
         }
         GFCache::set("payment_feed", $submission_feed);
     }
     return $submission_feed;
 }
 /**
  * Return the clients.
  *
  * @return mixed
  */
 private function get_clients()
 {
     $clients = GFCache::get('campaignmonitor_clients');
     if (!$clients) {
         $this->include_api();
         $api = new CS_REST_General($this->get_key());
         //getting all clients
         $response = $api->get_clients();
         if ($response->http_status_code == 200) {
             $clients = $response->response;
             GFCache::set('campaignmonitor_clients', $clients);
         }
     }
     return $clients;
 }
Esempio n. 12
0
    public static function get_lead_field_value($lead, $field){

        if(empty($lead))
            return;

        //returning cache entry if available
        $cache_key = "GFFormsModel::get_lead_field_value_" . $lead["id"] . "_" . $field["id"];

        $cache_value = GFCache::get($cache_key);
        if($cache_value !== false)
            return $cache_value;

        $max_length = GFORMS_MAX_FIELD_LENGTH;
        $value = array();
        if(is_array(rgar($field, "inputs"))){
            //making sure values submitted are sent in the value even if
            //there isn't an input associated with it
            $lead_field_keys = array_keys($lead);
            foreach($lead_field_keys as $input_id){
                if(is_numeric($input_id) && absint($input_id) == absint($field["id"])){
                    $val = $lead[$input_id];
                    if(strlen($val) >= ($max_length-10)) {
                        if(empty($form))
                            $form = RGFormsModel::get_form_meta($lead["form_id"]);

                        $long_choice = self::get_field_value_long($lead, $input_id, $form);
                    }
                    else{
                        $long_choice = $val;
                    }

                     $value[$input_id] = !empty($long_choice) ? $long_choice : $val;
                }
            }
        }
        else{
            $val = rgget($field["id"], $lead);

            //To save a database call to get long text, only getting long text if regular field is "somewhat" large (i.e. max - 50)
            if(strlen($val) >= ($max_length - 50)){
                if(empty($form))
                    $form = RGFormsModel::get_form_meta($lead["form_id"]);

                $long_text = self::get_field_value_long($lead, $field["id"], $form);
            }

            $value = !empty($long_text) ? $long_text : $val;
        }

        //filtering lead value
        $value = apply_filters("gform_get_field_value", $value, $lead, $field);

        //saving value in global variable to optimize performance
        GFCache::set($cache_key, $value);

        return $value;
    }
 public function get_freshbooks_items()
 {
     //non persistent cache
     $fb_items = GFCache::get('freshbooks_items');
     if (empty($fb_items)) {
         $this->init_api();
         $items = new FreshBooks_Item();
         $result = array();
         $result_info = array();
         $current_page = 1;
         $fb_items = array();
         do {
             $items->listing($result, $result_info, $current_page, 100);
             $pages = $result_info['pages'];
             foreach ($result as $line_item) {
                 $fb_items[] = array('value' => $line_item->itemId, 'label' => $line_item->name);
             }
             $current_page++;
         } while ($current_page <= $pages);
         GFCache::set('freshbooks_items', $fb_items);
     }
     return $fb_items;
 }