/** * Return a Gravity Forms field array, whether using GF 1.9 or not * * @since 1.7 * * @param array|GF_Fields $field Gravity Forms field or array * @return array Array version of $field */ public static function get_field_array($field) { if (class_exists('GF_Fields')) { $field_object = GF_Fields::create($field); // Convert the field object in 1.9 to an array for backward compatibility $field_array = get_object_vars($field_object); } else { $field_array = $field; } return $field_array; }
public static function captcha_image() { $field_properties = array('type' => 'captcha', 'simpleCaptchaSize' => $_GET['size'], 'simpleCaptchaFontColor' => $_GET['fg'], 'simpleCaptchaBackgroundColor' => $_GET['bg']); /* @var GF_Field_CAPTCHA $field */ $field = GF_Fields::create($field_properties); if ($_GET['type'] == 'math') { $captcha = $field->get_math_captcha($_GET['pos']); } else { $captcha = $field->get_captcha(); } @ini_set('memory_limit', '256M'); $image = imagecreatefrompng($captcha['path']); include_once ABSPATH . 'wp-admin/includes/image-edit.php'; wp_stream_image($image, 'image/png', 0); imagedestroy($image); die; }
/** * @param GF_Field $field * @param int $input_id * @param bool $input_only * * @return string */ public static function get_label($field, $input_id = 0, $input_only = false, $allow_admin_label = true) { if (!$field instanceof GF_Field) { $field = GF_Fields::create($field); } $field_label = (IS_ADMIN || RG_CURRENT_PAGE == 'select_columns.php' || RG_CURRENT_PAGE == 'print-entry.php' || rgget('gf_page', $_GET) == 'select_columns' || rgget('gf_page', $_GET) == 'print-entry') && !empty($field->adminLabel) && $allow_admin_label ? $field->adminLabel : $field->label; $input = self::get_input($field, $input_id); if (self::get_input_type($field) == 'checkbox' && $input != null) { return $input['label']; } else { if ($input != null) { return $input_only ? $input['label'] : $field_label . ' (' . $input['label'] . ')'; } else { return $field_label; } } }
public static function refresh_field_preview() { check_ajax_referer('rg_refresh_field_preview', 'rg_refresh_field_preview'); $field_json = stripslashes_deep($_POST['field']); $field_properties = GFCommon::json_decode($field_json, true); $field = GF_Fields::create($field_properties); $form_id = absint($_POST['formId']); $form = GFFormsModel::get_form_meta($form_id); require_once GFCommon::get_base_path() . '/form_display.php'; $field_content = GFFormDisplay::get_field_content($field, '', true, $form_id, $form); $args['fieldString'] = $field_content; $args_json = json_encode($args); die($args_json); }
private static function get_honeypot_field($form) { $max_id = self::get_max_field_id($form); $labels = self::get_honeypot_labels(); $properties = array('type' => 'honeypot', 'label' => $labels[rand(0, 3)], 'id' => $max_id + 1, 'cssClass' => 'gform_validation_container', 'description' => __('This field is for validation purposes and should be left unchanged.', 'gravityforms')); $field = GF_Fields::create($properties); return $field; }
/** * Loop through the fields being edited and if they include Post fields, update the Entry's post object * * @param array $form Gravity Forms form * * @return void */ function maybe_update_post_fields($form) { $post_id = $this->entry['post_id']; // Security check if (false === GVCommon::has_cap('edit_post', $post_id)) { do_action('gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id); return; } $update_entry = false; $updated_post = $original_post = get_post($post_id); foreach ($this->entry as $field_id => $value) { //todo: only run through the edit entry configured fields $field = RGFormsModel::get_field($form, $field_id); if (class_exists('GF_Fields')) { $field = GF_Fields::create($field); } if (GFCommon::is_post_field($field)) { // Get the value of the field, including $_POSTed value $value = RGFormsModel::get_field_value($field); // Convert the field object in 1.9 to an array for backward compatibility $field_array = GVCommon::get_field_array($field); switch ($field_array['type']) { case 'post_title': case 'post_content': case 'post_excerpt': $updated_post->{$field_array['type']} = $value; break; case 'post_tags': wp_set_post_tags($post_id, $value, false); break; case 'post_category': $categories = is_array($value) ? array_values($value) : (array) $value; $categories = array_filter($categories); wp_set_post_categories($post_id, $categories, false); // prepare value to be saved in the entry $field = GFCommon::add_categories_as_choices($field, ''); // if post_category is type checkbox, then value is an array of inputs if (isset($value[strval($field_id)])) { foreach ($value as $input_id => $val) { $input_name = 'input_' . str_replace('.', '_', $input_id); $this->entry[strval($input_id)] = RGFormsModel::prepare_value($form, $field, $val, $input_name, $this->entry['id']); } } else { $input_name = 'input_' . str_replace('.', '_', $field_id); $this->entry[strval($field_id)] = RGFormsModel::prepare_value($form, $field, $value, $input_name, $this->entry['id']); } break; case 'post_custom_field': $input_type = RGFormsModel::get_input_type($field); $custom_field_name = $field_array['postCustomFieldName']; // Only certain custom field types are supported if (!in_array($input_type, array('list', 'fileupload'))) { update_post_meta($post_id, $custom_field_name, $value); } break; case 'post_image': $value = ''; break; } //ignore fields that have not changed if ($value === rgget((string) $field_id, $this->entry)) { continue; } // update entry if ('post_category' !== $field->type) { $this->entry[strval($field_id)] = $value; } $update_entry = true; } } if ($update_entry) { $return_entry = GFAPI::update_entry($this->entry); if (is_wp_error($return_entry)) { do_action('gravityview_log_error', 'Updating the entry post fields failed', $return_entry); } else { do_action('gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded'); } } $return_post = wp_update_post($updated_post, true); if (is_wp_error($return_post)) { do_action('gravityview_log_error', 'Updating the post content failed', $return_post); } else { do_action('gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded'); } }
/** * @param GF_Field $field * @param $value * @param string $currency * @param bool $use_text * @param string $format * @param string $media * * @return array|mixed|string */ public static function get_lead_field_display($field, $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') { if (!$field instanceof GF_Field) { $field = GF_Fields::create($field); } if ($field->type == 'post_category') { $value = self::prepare_post_category_value($value, $field); } return $field->get_value_entry_detail($value, $currency, $use_text, $format, $media); }
public static function replace_field_variable($text, $form, $lead, $url_encode, $esc_html, $nl2br, $format, $input_id, $match, $esc_attr = false) { $field = RGFormsModel::get_field($form, $input_id); if (!$field instanceof GF_Field) { $field = GF_Fields::create($field); } $value = RGFormsModel::get_lead_field_value($lead, $field); $raw_value = $value; if (is_array($value)) { $value = rgar($value, $input_id); } $value = self::format_variable_value($value, $url_encode, $esc_html, $format, $nl2br); // modifier will be at index 4 unless used in a conditional shortcode in which case it would be at index 5 $i = $match[0][0] == '{' ? 4 : 5; $modifier = strtolower(rgar($match, $i)); $value = $field->get_value_merge_tag($value, $input_id, $lead, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br); if (!in_array($field->type, array('html', 'section', 'signature'))) { $value = self::encode_shortcodes($value); } if ($esc_attr) { $value = esc_attr($value); } if ($modifier == 'label') { $value = empty($value) ? '' : $field->label; } else { if ($modifier == 'qty' && $field->type == 'product') { //getting quantity associated with product field $products = self::get_product_fields($form, $lead, false, false); $value = 0; foreach ($products['products'] as $product_id => $product) { if ($product_id == $field->id) { $value = $product['quantity']; } } } } //Encoding left curly bracket so that merge tags entered in the front end are displayed as is and not parsed $value = self::encode_merge_tag($value); //filter can change merge tag value $value = apply_filters('gform_merge_tag_filter', $value, $input_id, $modifier, $field, $raw_value); if ($value === false) { $value = ''; } if ($match[0][0] != '{') { // replace the merge tag in the conditional shortcode merge_tag attr $value = str_replace($match[1], $value, $match[0]); } $text = str_replace($match[0], $value, $text); return $text; }
public function render($form, $ajax) { if (!class_exists('GFFormDisplay') || self::isDisabled()) { return $form; } self::enqueueScripts($form, $ajax); self::updateRenderedCount(); $next = GFFormDisplay::get_max_field_id($form) + 1; $template = sprintf($this->template, get_option('rg_gforms_captcha_public_key')); $opts = array('type' => 'section', '_is_entry_detail' => NULL, 'id' => $next, 'label' => '', 'adminLabel' => '', 'isRequired' => false, 'size' => 'medium', 'errorMessage' => '', 'inputs' => NULL, 'displayOnly' => true, 'labelPlacement' => '', 'content' => '', 'formId' => $form['id'], 'pageNumber' => GFFormDisplay::get_current_page($form['id']), 'conditionalLogic' => '', 'cssClass' => $this->buCAPTCHAIdentifier . '_section'); $form['fields'][] = GF_Fields::create($opts); $captcha_opts = array('type' => 'html', 'id' => $next + 1, 'content' => apply_filters('bu_gravityforms_global_recaptcha_div', $template), 'cssClass' => $this->buCAPTCHAIdentifier); $form['fields'][] = GF_Fields::create(array_merge($opts, $captcha_opts)); return $form; }
/** * init_attachment_process * * Called by WP Ajax Action: prso_gforms_youtube_upload_init * * Kicks off the whole video upload process * Decodes attachments, entry and form data and passes it to method * to process the uploads * * Note: attempts to increase php max execution time to allow for the * aysyncornous upload process to complete. This may not work on all * server environments so some people may have problems with large files :( * * @access public * @author Ben Moody */ public function init_attachment_process() { //Init vars $wp_attachment_data = array(); $entry = array(); $form = array(); if (!$this->curl_check_nonce($_POST['nonce_key'], 'adv-video-nonce')) { die; } $this->plugin_error_log('exec function: init_attachment_process'); //Try and force script to continue once curl coneection has ended ignore_user_abort(TRUE); set_time_limit(600); //Try to increase php max execution time ini_set('max_execution_time', 600); //Try to increase mysql timeout ini_set('mysql.connect_timeout', 600); //Get post vars if (isset($_POST['api'], $_POST['wp_attachment_data'], $_POST['entry'], $_POST['form'])) { //Cache selected api $this->selected_api = $_POST['api']; //Unserialize wp attachment data array $wp_attachment_data = maybe_unserialize($_POST['wp_attachment_data']); //Cache entry id and form id passed from gravity forms $entry = urldecode($_POST['entry']); $entry = json_decode($entry, TRUE); //Decode form array from gravity forms $form = urldecode($_POST['form']); $form = json_decode($form, TRUE); //Call method to process attachments $this->process_wp_attachments($wp_attachment_data, $entry, $form); //Convert the fields array back into an object as the video uploader changes it into an array if (isset($form['fields'])) { foreach ($form['fields'] as $key => $field) { $form['fields'][$key] = GF_Fields::create($field); } } do_action('prso_gform_pluploader_videos_uploads_end', $entry, $form, $wp_attachment_data); } die; }
/** * @param GF_Field $field * @param string $value * @param int $lead_id * @param int $form_id * @param null $form * * @return mixed|string|void */ public static function get_field_input($field, $value = '', $lead_id = 0, $form_id = 0, $form = null) { if (!$field instanceof GF_Field) { $field = GF_Fields::create($field); } $field->adminOnly = false; $id = intval($field->id); $field_id = 'input_' . $form_id . "_{$id}"; $entry = RGFormsModel::get_lead($lead_id); $post_id = $entry['post_id']; $post_link = ''; if (is_numeric($post_id) && GFCommon::is_post_field($field)) { $post_link = "<div>You can <a href='post.php?action=edit&post={$post_id}'>edit this post</a> from the post page.</div>"; } $field_input = apply_filters('gform_field_input', '', $field, $value, $lead_id, $form_id); if ($field_input) { return $field_input; } // add categories as choices for Post Category field if ($field->type == 'post_category') { $field = GFCommon::add_categories_as_choices($field, $value); } $type = RGFormsModel::get_input_type($field); switch ($type) { case 'honeypot': $autocomplete = RGFormsModel::is_html5_enabled() ? "autocomplete='off'" : ''; return "<div class='ginput_container'><input name='input_{$id}' id='{$field_id}' type='text' value='' {$autocomplete}/></div>"; break; case 'adminonly_hidden': if (!is_array($field->inputs)) { if (is_array($value)) { $value = json_encode($value); } return sprintf("<input name='input_%d' id='%s' class='gform_hidden' type='hidden' value='%s'/>", $id, $field_id, esc_attr($value)); } $fields = ''; foreach ($field->inputs as $input) { $fields .= sprintf("<input name='input_%s' class='gform_hidden' type='hidden' value='%s'/>", $input['id'], esc_attr(rgar($value, strval($input['id'])))); } return $fields; break; default: if (!empty($post_link)) { return $post_link; } if (!isset($entry)) { $entry = null; } return $field->get_field_input($form, $value, $entry); break; } }