/** Activate the plugin, mock all the things */
 public function setUp()
 {
     parent::setUp();
     /* Activate GravityForms */
     require_once WP_PLUGIN_DIR . '/gravityforms/gravityforms.php';
     require_once WP_PLUGIN_DIR . '/gravityforms/export.php';
     /* Something happened in newer versions, and we can't get the lead cache to initialize
     			properly, we need to do this manually */
     global $_gform_lead_meta;
     if ($_gform_lead_meta === null) {
         $_gform_lead_meta = array();
     }
     GFForms::setup();
     GFCache::flush();
     /* Import some ready-made forms */
     $this->assertEquals(GFExport::import_file(dirname(__FILE__) . '/forms.xml'), 2);
     /* Add a faster turnaround schedule */
     add_filter('cron_schedules', function ($s) {
         $s['minute'] = array('interval' => 60, 'display' => 'Minutely');
         return $s;
     });
     /* Get an instance of our plugin */
     $this->digest = new GFDigestNotifications();
 }
Пример #2
0
 /**
  * Given an entry and a form field id, calculate the entry value for that field.
  *
  * @access public
  * @param array $entry
  * @param integer $field
  * @return null|string
  */
 public static function field_value($entry, $field_settings, $format = 'html')
 {
     if (empty($entry['form_id']) || empty($field_settings['id'])) {
         return NULL;
     }
     $gravityview_view = GravityView_View::getInstance();
     if (class_exists('GFCache')) {
         /**
          * Gravity Forms' GFCache function was thrashing the database, causing double the amount of time for the field_value() method to run.
          *
          * The reason is that the cache was checking against a field value stored in a transient every time `GFFormsModel::get_lead_field_value()` is called.
          *
          * What we're doing here is telling the GFCache that it's already checked the transient and the value is false, forcing it to just use the non-cached data, which is actually faster.
          *
          * @hack
          * @since  1.3
          * @param  string $cache_key Field Value transient key used by Gravity Forms
          * @param mixed false Setting the value of the cache to false so that it's not used by Gravity Forms' GFFormsModel::get_lead_field_value() method
          * @param boolean false Tell Gravity Forms not to store this as a transient
          * @param  int 0 Time to store the value. 0 is maximum amount of time possible.
          */
         GFCache::set("GFFormsModel::get_lead_field_value_" . $entry["id"] . "_" . $field_settings["id"], false, false, 0);
     }
     $field_id = $field_settings['id'];
     $form = $gravityview_view->getForm();
     $field = gravityview_get_field($form, $field_id);
     $field_type = RGFormsModel::get_input_type($field);
     if ($field_type) {
         $field_type = $field['type'];
         $value = RGFormsModel::get_lead_field_value($entry, $field);
     } else {
         // For non-integer field types (`id`, `date_created`, etc.)
         $field_type = $field_id;
         $field['type'] = $field_id;
         $value = isset($entry[$field_type]) ? $entry[$field_type] : NULL;
     }
     // Prevent any PHP warnings that may be generated
     ob_start();
     $display_value = GFCommon::get_lead_field_display($field, $value, $entry["currency"], false, $format);
     if ($errors = ob_get_clean()) {
         do_action('gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors);
     }
     $display_value = apply_filters("gform_entry_field_value", $display_value, $field, $entry, $form);
     // prevent the use of merge_tags for non-admin fields
     if (!empty($field['adminOnly'])) {
         $display_value = self::replace_variables($display_value, $form, $entry);
     }
     // Check whether the field exists in /includes/fields/{$field_type}.php
     // This can be overridden by user template files.
     $field_exists = $gravityview_view->locate_template("fields/{$field_type}.php");
     // Set the field data to be available in the templates
     $gravityview_view->setCurrentField(array('form' => $form, 'field_id' => $field_id, 'field' => $field, 'field_settings' => $field_settings, 'value' => $value, 'display_value' => $display_value, 'format' => $format, 'entry' => $entry, 'field_type' => $field_type));
     if ($field_exists) {
         do_action('gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_exists));
         ob_start();
         load_template($field_exists, false);
         $output = ob_get_clean();
     } else {
         // Backup; the field template doesn't exist.
         $output = $display_value;
     }
     $field_settings = $gravityview_view->getCurrentField('field_settings');
     /**
      * Link to the single entry by wrapping the output in an anchor tag
      *
      * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
      *
      */
     if (!empty($field_settings['show_as_link'])) {
         $output = self::entry_link_html($entry, $output, array(), $field_settings);
     }
     /**
      * @filter `gravityview_field_entry_value_{$field_type}` Modify the field value output for a field type. Example: `gravityview_field_entry_value_number`
      * @since 1.6
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      */
     $output = apply_filters('gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     /**
      * @filter `gravityview_field_entry_value` Modify the field value output for all field types
      * @param string $output HTML value output
      * @param array  $entry The GF entry array
      * @param  array $field_settings Settings for the particular GV field
      * @param array $field_data  {@since 1.6}
      */
     $output = apply_filters('gravityview_field_entry_value', $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     return $output;
 }
Пример #3
0
 /**
  * Performs Gravity Forms deactivation tasks.
  * @access public
  * @static
  * @see GFCache
  */
 public static function deactivation_hook()
 {
     GFCache::flush(true);
     delete_option('gravityforms_rewrite_rules_flushed');
     flush_rewrite_rules();
 }
 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;
 }
Пример #5
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;
 }
Пример #6
0
 public static function flush($flush_persistent = false)
 {
     global $wpdb;
     self::$_cache = array();
     if (false === $flush_persistent) {
         return true;
     }
     if (is_multisite()) {
         $sql = "\r\n                 DELETE FROM {$wpdb->sitemeta}\r\n                 WHERE meta_key LIKE '_site_transient_timeout_GFCache_%' OR\r\n                 meta_key LIKE '_site_transient_GFCache_%'\r\n                ";
     } else {
         $sql = "\r\n                 DELETE FROM {$wpdb->options}\r\n                 WHERE option_name LIKE '_transient_timeout_GFCache_%' OR\r\n                 option_name LIKE '_transient_GFCache_%'\r\n                ";
     }
     $rows_deleted = $wpdb->query($sql);
     $success = $rows_deleted !== false ? true : false;
     return $success;
 }
        public function inbox_page($args = array())
        {
            $defaults = array('display_empty_fields' => true, 'check_permissions' => true, 'show_header' => true, 'timeline' => true);
            $args = array_merge($defaults, $args);
            if (rgget('view') == 'entry') {
                $entry_id = absint(rgget('lid'));
                $entry = GFAPI::get_entry($entry_id);
                if (is_wp_error($entry)) {
                    esc_html_e('Oops! We could not locate your entry.', 'gravityflow');
                    return;
                }
                $form_id = $entry['form_id'];
                $form = GFAPI::get_form($form_id);
                require_once $this->get_base_path() . '/includes/pages/class-entry-detail.php';
                $step = $this->get_current_step($form, $entry);
                if ($step) {
                    $token = $this->decode_access_token();
                    if (isset($token['scopes']['action'])) {
                        if ($token['scopes']['action'] === 'cancel_workflow') {
                            $entry_id = rgars($token, 'scopes/entry_id');
                            if (empty($entry_id) || $entry_id != $entry['id']) {
                                esc_html_e('Error: incorrect entry.', 'gravityflow');
                                return;
                            }
                            $api = new Gravity_Flow_API($form_id);
                            $result = $api->cancel_workflow($entry);
                            if ($result) {
                                esc_html_e('Workflow Cancelled', 'gravityflow');
                            }
                            return;
                        }
                        $feedback = $step->maybe_process_token_action($token['scopes']['action'], $token, $form, $entry);
                        if (empty($feedback)) {
                            esc_html_e('Error: This URL is no longer valid.', 'gravityflow');
                            return;
                        }
                        if (is_wp_error($feedback)) {
                            echo $feedback->get_error_message();
                            return;
                        }
                        $this->process_workflow($form, $entry_id);
                        echo $feedback;
                        return;
                    }
                }
                $feedback = $this->maybe_process_admin_action($form, $entry);
                if (empty($feedback) && $step) {
                    $feedback = $step->maybe_process_status_update($form, $entry);
                    if ($feedback && !is_wp_error($feedback)) {
                        $this->process_workflow($form, $entry_id);
                    }
                }
                if (is_wp_error($feedback)) {
                    $error_data = $feedback->get_error_data();
                    if (!empty($error_data['form'])) {
                        $form = $error_data['form'];
                    }
                    ?>
					<div class="notice error is-dismissible gravityflow_validation_error" style="padding:6px;">
						<?php 
                    esc_html_e($feedback->get_error_message());
                    ?>
					</div>
					<?php 
                } elseif ($feedback) {
                    GFCache::flush();
                    $entry = GFAPI::get_entry($entry_id);
                    // refresh entry
                    ?>
					<div class="updated notice notice-success is-dismissible" style="padding:6px;">
						<?php 
                    esc_html_e($feedback);
                    ?>
					</div>
					<?php 
                    $next_step = $this->get_current_step($form, $entry);
                    $current_user_assignee_key = $this->get_current_user_assignee_key();
                    if ($next_step && $next_step->is_assignee($current_user_assignee_key) || $args['check_permissions'] == false || $this->current_user_can_any('gravityflow_view_all')) {
                        $step = $next_step;
                    } else {
                        $args['display_instructions'] = false;
                    }
                    $args['check_permissions'] = false;
                }
                Gravity_Flow_Entry_Detail::entry_detail($form, $entry, $step, $args);
                return;
            } else {
                ?>
				<div class="wrap gf_entry_wrap gravityflow_workflow_wrap gravityflow_workflow_detail">
					<?php 
                if ($args['show_header']) {
                    ?>
						<h2 class="gf_admin_page_title">
							<img width="45" height="22" src="<?php 
                    echo $this->get_base_url();
                    ?>
/images/gravityflow-icon-blue-grad.svg" style="margin-right:5px;"/>
							<span><?php 
                    esc_html_e('Workflow Inbox', 'gravityflow');
                    ?>
</span>
						</h2>
					<?php 
                    $this->toolbar();
                }
                require_once $this->get_base_path() . '/includes/pages/class-inbox.php';
                Gravity_Flow_Inbox::display($args);
                ?>
				</div>
			<?php 
            }
        }
 /**
  * Set RGFormsModel::$lead for use in hooks where $lead is not explicitly passed.
  *
  * @param mixed $lead
  */
 public static function set_current_lead($lead)
 {
     GFCache::flush();
     self::$_current_lead = $lead;
 }
Пример #9
0
 public static function deactivation_hook()
 {
     /**
      * This code was added on Jan. 13, 2016.
      *
      * @author Wes
      */
     add_action('update_option_active_plugins', array('GFForms', 'aria_deactivate_plugins'));
     do_action('update_option_active_plugins');
     // gravity forms source code..
     GFCache::flush(true);
 }
 /**
  * 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;
 }
 public function maybe_process_status_update($form, $entry)
 {
     $feedback = false;
     $form_id = $form['id'];
     if (isset($_POST['gforms_save_entry']) && check_admin_referer('gforms_save_entry', 'gforms_save_entry')) {
         $new_status = rgpost('gravityflow_status');
         if (!in_array($new_status, array('in_progress', 'complete'))) {
             return false;
         }
         // Loading files that have been uploaded to temp folder
         $files = GFCommon::json_decode(stripslashes(RGForms::post('gform_uploaded_files')));
         if (!is_array($files)) {
             $files = array();
         }
         GFFormsModel::$uploaded_files[$form_id] = $files;
         $validation = $this->validate_status_update($new_status, $form);
         if (is_wp_error($validation)) {
             return $validation;
         }
         $editable_fields = $this->get_editable_fields();
         $previous_assignees = $this->get_assignees();
         $this->save_entry($form, $entry, $editable_fields);
         remove_action('gform_after_update_entry', array(gravity_flow(), 'filter_after_update_entry'));
         do_action('gform_after_update_entry', $form, $entry['id']);
         do_action("gform_after_update_entry_{$form['id']}", $form, $entry['id']);
         $entry = GFFormsModel::get_lead($entry['id']);
         $entry = GFFormsModel::set_entry_meta($entry, $form);
         $this->refresh_entry();
         GFCache::flush();
         $this->maybe_adjust_assignment($previous_assignees);
         if ($token = gravity_flow()->decode_access_token()) {
             $assignee_key = sanitize_text_field($token['sub']);
         } else {
             $user = wp_get_current_user();
             $assignee_key = 'user_id|' . $user->ID;
         }
         $assignee = new Gravity_Flow_Assignee($assignee_key, $this);
         $feedback = $this->process_assignee_status($assignee, $new_status, $form);
     }
     return $feedback;
 }
 /**
  * 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;
 }
Пример #14
0
 public static function clear_field_value_cache($form)
 {
     if (!class_exists('GFCache')) {
         return;
     }
     foreach ($form['fields'] as &$field) {
         if (GFFormsModel::get_input_type($field) == 'total') {
             GFCache::delete('GFFormsModel::get_lead_field_value__' . $field['id']);
         }
     }
 }
Пример #15
0
 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;
 }
Пример #16
0
 /**
  * Get form object and insert review page, if necessary.
  *
  * @param array $form The current Form object
  * @return mixed The form meta array or false
  */
 public static function maybe_add_review_page($form)
 {
     /* Setup default review page parameters. */
     $review_page = array('content' => '', 'is_enabled' => false, 'nextButton' => array('type' => 'text', 'text' => __('Review Form', 'gravityforms'), 'imageUrl' => '', 'imageAlt' => ''), 'previousButton' => array('type' => 'text', 'text' => __('Previous', 'gravityforms'), 'imageUrl' => '', 'imageAlt' => ''));
     if (has_filter('gform_review_page') || has_filter("gform_review_page_{$form['id']}")) {
         // Prepare partial entry for review page.
         $partial_entry = GFFormsModel::get_current_lead();
         /**
          * GFFormsModel::create_lead() caches the field value and conditional logic visibility which can create
          * issues when 3rd parties use hooks later in the process to modify the form. Let's flush the cache avoid
          * any weirdness.
          */
         GFCache::flush();
         /**
          * A filter for setting up the review page
          *
          * @param array $review_page The review page parameters
          * @param array $form The current form object
          * @param array|false $partial_entry The partial entry for the form or false on initial form display.
          */
         $review_page = gf_apply_filters(array('gform_review_page', $form['id']), $review_page, $form, $partial_entry);
         if (!rgempty('button_text', $review_page)) {
             $review_page['nextButton']['text'] = $review_page['button_text'];
         }
     }
     if (rgar($review_page, 'is_enabled')) {
         $form = self::insert_review_page($form, $review_page);
     }
     return $form;
 }
 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];
 }
Пример #18
0
 public static function deactivation_hook()
 {
     GFCache::flush(true);
 }
 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;
 }