本文整理匯總了PHP中GFCommon::is_empty_array方法的典型用法代碼示例。如果您正苦於以下問題:PHP GFCommon::is_empty_array方法的具體用法?PHP GFCommon::is_empty_array怎麽用?PHP GFCommon::is_empty_array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GFCommon
的用法示例。
在下文中一共展示了GFCommon::is_empty_array方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: default_if_empty
private static function default_if_empty($field, $value)
{
if (!GFCommon::is_empty_array($value)) {
return $value;
}
if (IS_ADMIN) {
$value = rgget("defaultValue", $field);
} else {
$value = rgar($field, "defaultValue");
if (!is_array($value)) {
$value = GFCommon::replace_variables_prepopulate(rgget("defaultValue", $field));
}
}
return $value;
}
示例2: prepare_date
public static function prepare_date($date_format, $value)
{
$format = empty($date_format) ? 'mdy' : $date_format;
$date_info = GFCommon::parse_date($value, $format);
if (!empty($date_info) && !GFCommon::is_empty_array($date_info)) {
$value = sprintf('%s-%02d-%02d', $date_info['year'], $date_info['month'], $date_info['day']);
} else {
$value = '';
}
return $value;
}
示例3: prepare_value
/**
* Prepare the value before saving it to the lead.
*
* @param mixed $form
* @param mixed $field
* @param mixed $value
* @param mixed $input_name
* @param mixed $lead_id the current lead ID, used for fields that are processed after other fields have been saved (ie Total, Calculations)
* @param mixed $lead passed by the RGFormsModel::create_lead() method, lead ID is not available for leads created by this function
*/
public static function prepare_value($form, $field, $value, $input_name, $lead_id, $lead = array())
{
$form_id = $form["id"];
$input_type = self::get_input_type($field);
switch ($input_type) {
case "total":
$lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
$value = GFCommon::get_order_total($form, $lead);
break;
case "calculation":
// ignore submitted value and recalculate price in backend
list(, , $input_id) = rgexplode("_", $input_name, 3);
if ($input_id == 2) {
require_once GFCommon::get_base_path() . '/currency.php';
$currency = new RGCurrency(GFCommon::get_currency());
$lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
$value = $currency->to_money(GFCommon::calculate($field, $form, $lead));
}
break;
case "phone":
if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
$value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
}
break;
case "time":
if (!is_array($value) && !empty($value)) {
preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
$value = array();
$value[0] = $matches[1];
$value[1] = $matches[2];
$value[2] = rgar($matches, 3);
}
$hour = empty($value[0]) ? "0" : strip_tags($value[0]);
$minute = empty($value[1]) ? "0" : strip_tags($value[1]);
$ampm = strip_tags(rgar($value, 2));
if (!empty($ampm)) {
$ampm = " {$ampm}";
}
if (!(empty($hour) && empty($minute))) {
$value = sprintf("%02d:%02d%s", $hour, $minute, $ampm);
} else {
$value = "";
}
break;
case "date":
$value = self::prepare_date($field["dateFormat"], $value);
break;
case "post_image":
$url = self::get_fileupload_value($form_id, $input_name);
$image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : "";
$image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : "";
$image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : "";
$value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : "";
break;
case "fileupload":
$value = self::get_fileupload_value($form_id, $input_name);
break;
case "number":
$lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
$value = GFCommon::has_field_calculation($field) ? GFCommon::round_number(GFCommon::calculate($field, $form, $lead), rgar($field, "calculationRounding")) : GFCommon::clean_number($value, rgar($field, "numberFormat"));
//return the value as a string when it is zero and a calc so that the "==" comparison done when checking if the field has changed isn't treated as false
if (GFCommon::has_field_calculation($field) && $value == 0) {
$value = "0";
}
break;
case "website":
if ($value == "http://") {
$value = "";
}
break;
case "list":
if (GFCommon::is_empty_array($value)) {
$value = "";
} else {
$value = self::create_list_array($field, $value);
$value = serialize($value);
}
break;
case "radio":
if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
$value = rgpost("input_{$field['id']}_other");
}
break;
case "multiselect":
$value = empty($value) ? "" : implode(",", $value);
break;
case "creditcard":
//saving last 4 digits of credit card
list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
if ($input_id == "1") {
//.........這裏部分代碼省略.........
示例4: get_value_default_if_empty
/**
* Returns the field default value if the field does not already have a value.
*
* @param array|string $value The field value.
*
* @return array|string
*/
public function get_value_default_if_empty($value)
{
if (!GFCommon::is_empty_array($value)) {
return $value;
}
return $this->get_value_default();
}
示例5: hide_empty_likert_field
/**
* Helper to determine if the empty field should be displayed when the lead detail grid is processed.
*
* @param array $form The Form object for the current Entry.
* @param string|array $value The field value.
*
* @return bool
*/
public function hide_empty_likert_field($form, $value)
{
$mode = empty($_POST['screen_mode']) ? 'view' : $_POST['screen_mode'];
$allow_display_empty_fields = $mode == 'view';
return GFCommon::is_empty_array($value) && !GFEntryDetail::maybe_display_empty_fields($allow_display_empty_fields, $form, false);
}
示例6: get_value_save_entry
public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead)
{
if ($this->adminOnly && $this->allowsPrepopulate) {
$value = json_decode($value);
}
if (GFCommon::is_empty_array($value)) {
$value = '';
} else {
$value = $this->create_list_array($value);
$value = serialize($value);
}
return $value;
}
示例7: process_feed
public static function process_feed($feed, $entry, $form)
{
$body = self::get_body($entry, $form);
$headers = array();
if (GFCommon::is_empty_array($body)) {
$headers['X-Hook-Test'] = 'true';
}
$json_body = json_encode($body);
if (empty($body)) {
self::log_debug('There is no field data to send to Zapier.');
return false;
}
self::log_debug('Posting to url: ' . $feed['url'] . ' data: ' . print_r($body, true));
$form_data = array('sslverify' => false, 'ssl' => true, 'body' => $json_body, 'headers' => $headers);
$response = wp_remote_post($feed['url'], $form_data);
if (is_wp_error($response)) {
self::log_error('The following error occurred: ' . print_r($response, true));
return false;
} else {
self::log_debug('Successful response from Zap: ' . print_r($response, true));
if (!empty($entry)) {
self::log_debug('Marking entry #' . $entry['id'] . ' as fulfilled.');
gform_update_meta($entry['id'], self::$slug . '_is_fulfilled', true);
}
return true;
}
}
示例8: prepare_value
//.........這裏部分代碼省略.........
$value = array_merge($value, $uploaded_files);
$value = json_encode($value);
} else {
$value = json_encode($uploaded_files);
}
} else {
$value = '';
}
$_gf_uploaded_files[$input_name] = $value;
}
} else {
$value = self::get_fileupload_value($form_id, $input_name);
}
break;
case "number":
$value = GFCommon::maybe_add_leading_zero($value);
$is_hidden = RGFormsModel::is_field_hidden($form, $field, array());
$lead = empty($lead) ? RGFormsModel::get_lead($lead_id) : $lead;
$value = GFCommon::has_field_calculation($field) ? GFCommon::round_number(GFCommon::calculate($field, $form, $lead), rgar($field, "calculationRounding")) : GFCommon::clean_number($value, rgar($field, "numberFormat"));
//return the value as a string when it is zero and a calc so that the "==" comparison done when checking if the field has changed isn't treated as false
if (GFCommon::has_field_calculation($field) && $value == 0) {
$value = "0";
}
break;
case "website":
if ($value == "http://") {
$value = "";
}
break;
case "list":
if (rgar($field, "adminOnly") && rgar($field, "allowsPrepopulate")) {
$value = json_decode($value);
}
if (GFCommon::is_empty_array($value)) {
$value = "";
} else {
foreach ($value as &$val) {
$val = self::sanitize_entry_value($field, $val, $input_type, $form_id);
}
$value = self::create_list_array($field, $value);
$value = serialize($value);
}
break;
case "radio":
if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
$value = rgpost("input_{$field['id']}_other");
}
$value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
break;
case "multiselect":
$value = empty($value) ? "" : is_array($value) ? implode(",", $value) : $value;
$value = self::sanitize_entry_value($field, $value, $input_type, $form_id);
break;
case "creditcard":
//saving last 4 digits of credit card
list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
if ($input_id == "1") {
$value = str_replace(" ", "", $value);
$card_number_length = strlen($value);
$value = substr($value, -4, 4);
$value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT);
} else {
if ($input_id == '4') {
$value = rgpost("input_{$field_id_token}_4");
if (!$value) {
$card_number = rgpost("input_{$field_id_token}_1");
示例9: prepare_value
private static function prepare_value($form, $field, $value, $input_name, $lead_id)
{
$form_id = $form["id"];
$input_type = self::get_input_type($field);
switch ($input_type) {
case "total":
$lead = RGFormsModel::get_lead($lead_id);
$value = GFCommon::get_order_total($form, $lead);
break;
case "post_category":
$cat = get_category($value);
$value = !empty($cat) ? $cat->name . ":" . $value : "";
break;
case "phone":
if ($field["phoneFormat"] == "standard" && preg_match('/^\\D?(\\d{3})\\D?\\D?(\\d{3})\\D?(\\d{4})$/', $value, $matches)) {
$value = sprintf("(%s)%s-%s", $matches[1], $matches[2], $matches[3]);
}
break;
case "time":
if (!is_array($value) && !empty($value)) {
preg_match('/^(\\d*):(\\d*) ?(.*)$/', $value, $matches);
$value = array();
$value[0] = $matches[1];
$value[1] = $matches[2];
$value[2] = rgar($matches, 3);
}
$hour = empty($value[0]) ? "0" : strip_tags($value[0]);
$minute = empty($value[1]) ? "0" : strip_tags($value[1]);
$ampm = strip_tags(rgar($value, 2));
if (!empty($ampm)) {
$ampm = " {$ampm}";
}
if (!(empty($hour) && empty($minute))) {
$value = sprintf("%02d:%02d%s", $hour, $minute, $ampm);
} else {
$value = "";
}
break;
case "date":
$format = empty($field["dateFormat"]) ? "mdy" : $field["dateFormat"];
$date_info = GFCommon::parse_date($value, $format);
if (!empty($date_info)) {
$value = sprintf("%d-%02d-%02d", $date_info["year"], $date_info["month"], $date_info["day"]);
} else {
$value = "";
}
break;
case "post_image":
$url = self::get_fileupload_value($form_id, $input_name);
$image_title = isset($_POST["{$input_name}_1"]) ? strip_tags($_POST["{$input_name}_1"]) : "";
$image_caption = isset($_POST["{$input_name}_4"]) ? strip_tags($_POST["{$input_name}_4"]) : "";
$image_description = isset($_POST["{$input_name}_7"]) ? strip_tags($_POST["{$input_name}_7"]) : "";
$value = !empty($url) ? $url . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : "";
break;
case "fileupload":
$value = self::get_fileupload_value($form_id, $input_name);
break;
case "number":
$value = GFCommon::clean_number($value, rgar($field, "numberFormat"));
break;
case "website":
if ($value == "http://") {
$value = "";
}
break;
case "list":
if (GFCommon::is_empty_array($value)) {
$value = "";
} else {
$value = self::create_list_array($field, $value);
$value = serialize($value);
}
break;
case "radio":
if (rgar($field, 'enableOtherChoice') && $value == 'gf_other_choice') {
$value = rgpost("input_{$field['id']}_other");
}
break;
case "multiselect":
$value = empty($value) ? "" : implode(",", $value);
break;
case "creditcard":
//saving last 4 digits of credit card
list($input_token, $field_id_token, $input_id) = rgexplode("_", $input_name, 3);
if ($input_id == "1") {
$value = str_replace(" ", "", $value);
$card_number_length = strlen($value);
$value = substr($value, -4, 4);
$value = str_pad($value, $card_number_length, "X", STR_PAD_LEFT);
} else {
if ($input_id == "4") {
$card_number = rgpost("input_{$field_id_token}_1");
$card_type = GFCommon::get_card_type($card_number);
$value = $card_type ? $card_type["name"] : "";
} else {
$value = "";
}
}
break;
default:
//.........這裏部分代碼省略.........
示例10: send_form_data_to_zapier
public static function send_form_data_to_zapier($entry = null, $form)
{
//if there is an entry, then this is a form submission, get data out of entry to POST to Zapier
//otherwise this is a dummy setup to give Zapier the field data, get the form fields and POST to Zapier with empty data
if (empty($form) && empty($entry)) {
self::log_debug("No form or entry was provided to send data to Zapier.");
return false;
}
$body = self::get_body($entry, $form);
$headers = array();
if (GFCommon::is_empty_array($body)) {
$headers["X-Hook-Test"] = 'true';
}
$json_body = json_encode($body);
if (empty($body)) {
self::log_debug("There is no field data to send to Zapier.");
return false;
}
//get zaps for form
$form_id = $form["id"];
$zaps = GFZapierData::get_feed_by_form($form_id, true);
if (empty($zaps)) {
self::log_debug("There are no zaps configured for form id {$form_id}");
return false;
}
$is_entry = !empty($entry);
$is_entry ? self::log_debug("Gathering entry data to send submission.") : self::log_debug("Gathering field data to send dummy submission.");
$retval = true;
foreach ($zaps as $zap) {
//checking to see if a condition was specified, and if so, met, otherwise don't send to zapier
//only check this when there is an entry, simple form updates should go to zapier regardless of conditions existing
if (!$is_entry || $is_entry && self::conditions_met($form, $zap)) {
if ($is_entry) {
self::log_debug("No condition specified or a condition was specified and met, sending to Zapier");
}
$form_data = array("sslverify" => false, "ssl" => true, "body" => $json_body, "headers" => $headers);
self::log_debug("Posting to url: " . $zap["url"] . " data: " . print_r($body, true));
$response = wp_remote_post($zap["url"], $form_data);
if (is_wp_error($response)) {
self::log_error("The following error occurred: " . print_r($response, true));
$retval = false;
} else {
self::log_debug("Successful response from Zap: " . print_r($response, true));
}
} else {
self::log_debug("A condition was specified and not met, not sending to Zapier");
$retval = false;
}
}
return $retval;
}
示例11: send_form_data_to_zapier
public static function send_form_data_to_zapier($entry = null, $form)
{
//if there is an entry, then this is a form submission, get data out of entry to POST to Zapier
//otherwise this is a dummy setup to give Zapier the field data, get the form fields and POST to Zapier with empty data
if (empty($form) && empty($entry)) {
self::log_debug('No form or entry was provided to send data to Zapier.');
return false;
}
//get zaps for form
$form_id = $form['id'];
$zaps = GFZapierData::get_feed_by_form($form_id, true);
if (empty($zaps)) {
self::log_debug("There are no zaps configured for form id {$form_id}");
return false;
}
//see if there is a paypal feed and zapier is set to be delayed until payment is received
if (class_exists('GFPayPal')) {
$paypal_feeds = self::get_paypal_feeds($form['id']);
//loop through paypal feeds to get active one for this form submission, needed to see if add-on processing should be delayed
foreach ($paypal_feeds as $paypal_feed) {
if ($paypal_feed['is_active'] && self::is_feed_condition_met($paypal_feed, $form, $entry)) {
$active_paypal_feed = $paypal_feed;
break;
}
}
$is_fulfilled = rgar($entry, 'is_fulfilled');
if (!empty($active_paypal_feed) && self::is_delayed($active_paypal_feed) && self::has_paypal_payment($active_paypal_feed, $form, $entry) && !$is_fulfilled) {
self::log_debug('Zapier Feed processing is delayed pending payment, not processing feed for entry #' . $entry['id']);
return false;
}
}
//do not send spam entries to zapier
if (!empty($entry) && $entry['status'] == 'spam') {
self::log_debug('The entry is marked as spam, NOT sending to Zapier.');
return false;
}
$body = self::get_body($entry, $form);
$headers = array();
if (GFCommon::is_empty_array($body)) {
$headers['X-Hook-Test'] = 'true';
}
$json_body = json_encode($body);
if (empty($body)) {
self::log_debug('There is no field data to send to Zapier.');
return false;
}
$is_entry = !empty($entry);
$is_entry ? self::log_debug('Gathering entry data to send submission.') : self::log_debug('Gathering field data to send dummy submission.');
$retval = true;
foreach ($zaps as $zap) {
//checking to see if a condition was specified, and if so, met, otherwise don't send to zapier
//only check this when there is an entry, simple form updates should go to zapier regardless of conditions existing
if (!$is_entry || $is_entry && self::conditions_met($form, $zap, $entry)) {
if ($is_entry) {
self::log_debug('No condition specified or a condition was specified and met, sending to Zapier');
}
$form_data = array('sslverify' => false, 'ssl' => true, 'body' => $json_body, 'headers' => $headers);
self::log_debug('Posting to url: ' . $zap['url'] . ' data: ' . print_r($body, true));
$response = wp_remote_post($zap['url'], $form_data);
if (is_wp_error($response)) {
self::log_error('The following error occurred: ' . print_r($response, true));
$retval = false;
} else {
self::log_debug('Successful response from Zap: ' . print_r($response, true));
}
} else {
self::log_debug('A condition was specified and not met, not sending to Zapier');
$retval = false;
}
}
return $retval;
}