Пример #1
0
 /**
  * Given an entry and a form field id, calculate the entry value for that field.
  *
  * @access public
  * @param array $entry
  * @param array $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();
     $field_id = $field_settings['id'];
     $form = $gravityview_view->getForm();
     $field = gravityview_get_field($form, $field_id);
     if ($field && is_numeric($field_id)) {
         // Used as file name of field template in GV.
         // Don't use RGFormsModel::get_input_type( $field ); we don't care if it's a radio input; we want to know it's a 'quiz' field
         $field_type = $field->type;
         $value = RGFormsModel::get_lead_field_value($entry, $field);
     } else {
         $field = GravityView_Fields::get_associated_field($field_id);
         $field_type = $field_id;
         // Used as file name of field template in GV
     }
     // If a Gravity Forms Field is found, get the field display
     if ($field) {
         // 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);
         }
     } else {
         $value = $display_value = rgar($entry, $field_id);
         $display_value = $value;
     }
     // Check whether the field exists in /includes/fields/{$field_type}.php
     // This can be overridden by user template files.
     $field_path = $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, 'field_path' => $field_path));
     if (!empty($field_path)) {
         do_action('gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_path));
         ob_start();
         load_template($field_path, false);
         $output = ob_get_clean();
     } else {
         // Backup; the field template doesn't exist.
         $output = $display_value;
     }
     // Get the field settings again so that the field template can override the settings
     $field_settings = $gravityview_view->getCurrentField('field_settings');
     /**
      * @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link`
      * @since 1.16
      * @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 Field array, as fetched from GravityView_View::getCurrentField()
      */
     $output = apply_filters('gravityview_field_entry_value_' . $field_type . '_pre_link', $output, $entry, $field_settings, $gravityview_view->getCurrentField());
     /**
      * 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']) && !gv_empty($output, false, false)) {
         $link_atts = empty($field_settings['new_window']) ? array() : array('target' => '_blank');
         $output = self::entry_link_html($entry, $output, $link_atts, $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
      * @param array $field Current field being displayed
      */
     $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;
 }
Пример #2
0
 /**
  * Checks if the field type is a 'numeric' field type (e.g. to be used when sorting)
  * @param  int|array  $form  form ID or form array
  * @param  int|array  $field field key or field array
  * @return boolean
  */
 public static function is_field_numeric($form = null, $field = '')
 {
     if (!is_array($form) && !is_array($field)) {
         $form = self::get_form($form);
     }
     // If entry meta, it's a string. Otherwise, numeric
     if (!is_numeric($field) && is_string($field)) {
         $type = $field;
     } else {
         $type = self::get_field_type($form, $field);
     }
     /**
      * @filter `gravityview/common/numeric_types` What types of fields are numeric?
      * @since 1.5.2
      * @param array $numeric_types Fields that are numeric. Default: `[ number, time ]`
      */
     $numeric_types = apply_filters('gravityview/common/numeric_types', array('number', 'time'));
     // Defer to GravityView_Field setting, if the field type is registered and `is_numeric` is true
     if ($gv_field = GravityView_Fields::get($type)) {
         if (true === $gv_field->is_numeric) {
             $numeric_types[] = $gv_field->is_numeric;
         }
     }
     $return = in_array($type, $numeric_types);
     return $return;
 }
 /**
  * GravityView_Field constructor.
  */
 public function __construct()
 {
     // Modify the field options based on the name of the field type
     add_filter(sprintf('gravityview_template_%s_options', $this->name), array(&$this, 'field_options'), 10, 5);
     add_filter('gravityview/sortable/field_blacklist', array($this, '_filter_sortable_fields'), 1);
     if ($this->_custom_merge_tag) {
         add_filter('gform_custom_merge_tags', array($this, '_filter_gform_custom_merge_tags'), 10, 4);
         add_filter('gform_replace_merge_tags', array($this, '_filter_gform_replace_merge_tags'), 10, 7);
     }
     GravityView_Fields::register($this);
 }
 /**
  *
  * Fill-in the saved values into the form inputs
  *
  * @param string $field_content Always empty. Returning not-empty overrides the input.
  * @param GF_Field $field
  * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
  * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
  * @param int $form_id Form ID
  *
  * @return mixed
  */
 function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
 {
     $gv_field = GravityView_Fields::get_associated_field($field);
     // If the form has been submitted, then we don't need to pre-fill the values,
     // Except for fileupload type and when a field input is overridden- run always!!
     if ($this->is_edit_entry_submission() && !in_array($field->type, array('fileupload', 'post_image')) && false === ($gv_field && is_callable(array($gv_field, 'get_field_input'))) || !empty($field_content) || in_array($field->type, array('honeypot')) || GFCommon::is_product_field($field->type)) {
         return $field_content;
     }
     // Turn on Admin-style display for file upload fields only
     if ('fileupload' === $field->type) {
         $_GET['page'] = 'gf_entries';
     }
     // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
     $field->adminOnly = false;
     /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
     // add categories as choices for Post Category field
     if ('post_category' === $field->type) {
         $field = GFCommon::add_categories_as_choices($field, $value);
     }
     $field_value = $this->get_field_value($field);
     /**
      * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
      * @since 1.11
      * @param mixed $field_value field value used to populate the input
      * @param object $field Gravity Forms field object ( Class GF_Field )
      */
     $field_value = apply_filters('gravityview/edit_entry/field_value', $field_value, $field);
     /**
      * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
      * @since 1.17
      * @param mixed $field_value field value used to populate the input
      * @param GF_Field $field Gravity Forms field object
      */
     $field_value = apply_filters('gravityview/edit_entry/field_value_' . $field->type, $field_value, $field);
     // Prevent any PHP warnings, like undefined index
     ob_start();
     if ($gv_field && is_callable(array($gv_field, 'get_field_input'))) {
         /** @var GF_Field $gv_field */
         $return = $gv_field->get_field_input($this->form, $field_value, $this->entry, $field);
     } else {
         $return = $field->get_field_input($this->form, $field_value, $this->entry);
     }
     // If there was output, it's an error
     $warnings = ob_get_clean();
     if (!empty($warnings)) {
         do_action('gravityview_log_error', __METHOD__ . $warnings, $field_value);
     }
     /**
      * Unset hack $_GET['page'] = 'gf_entries'
      * We need the fileupload html field to render with the proper id
      *  ( <li id="field_80_16" ... > )
      */
     unset($_GET['page']);
     return $return;
 }