Skip to content

Commit

Permalink
Update payping.php
Browse files Browse the repository at this point in the history
  • Loading branch information
HadiWP authored May 26, 2024
1 parent 79f0e03 commit 1f1752f
Showing 1 changed file with 17 additions and 253 deletions.
270 changes: 17 additions & 253 deletions payping.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ public static function uninstall() {
delete_option( "ppgf_payping_settings" );
delete_option( "ppgf_payping_configured" );
delete_option( "ppgf_payping_version" );
$plugin = basename( dirname( __FILE__ ) ) . "/payping-gravityforms.php";
deactivate_plugins( $plugin );

update_option( 'payping_gf_recently_activated', array( $plugin => time() ) + (array) get_option( 'payping_gf_recently_activated' ) );
}

Expand Down Expand Up @@ -372,34 +371,15 @@ public static function delay_addons( $is_delayed, $form, $entry, $slug ) {

// -------------------------------------------------
private static function redirect_confirmation( $url, $ajax ) {

if ( headers_sent() || $ajax ) {
// Enqueue the custom JavaScript inline
wp_enqueue_script( 'custom-redirect', '', array( 'jquery' ), '1.0.0', true );

$confirmation = "<script type=\"text/javascript\">" . apply_filters( 'gform_cdata_open', '' ) . "
jQuery(document).ready(function($) {
function gformRedirect(url) {
document.location.href = url;
}
gformRedirect('$url');
});
";

if ( ! $ajax ) {
$confirmation .= 'gformRedirect();';
}

$confirmation .= apply_filters( 'gform_cdata_close', '' ) . '</script>';
$confirmation = array( 'redirect' => $url );
} else {
$confirmation = array( 'redirect' => $url );
}

return $confirmation;
}


// -------------------------------------------------
public static function get_active_config( $form ) {

Expand Down Expand Up @@ -716,18 +696,19 @@ public static function get_order_total( $form, $entry ) {

// -------------------------------------------------
private static function get_mapped_field_list( $field_name, $selected_field, $fields ) {
$str = "<select name='$field_name' id='$field_name'><option value=''></option>";
if ( is_array( $fields ) ) {
foreach ( $fields as $field ) {
$str_escaped = "<select name='" . esc_attr($field_name) . "' id='" . esc_attr($field_name) . "'><option value=''></option>";
if (is_array($fields)) {
foreach ($fields as $field) {
$field_id = $field[0];
$field_label = esc_html( GFCommon::truncate_middle( $field[1], 40 ) );
$field_label = esc_html(GFCommon::truncate_middle($field[1], 40));
$selected = $field_id == $selected_field ? "selected='selected'" : "";
$str .= "<option value='" . esc_html($field_id) . "' " . esc_html($selected) . ">" . esc_html($field_label) . "</option>";
$str_escaped .= "<option value='" . esc_attr($field_id) . "' " . $selected . ">" . esc_html($field_label) . "</option>";
}
}
$str .= "</select>";
$str_escaped .= "</select>";

echo $str_escaped;

return $str;
}

// -------------------------------------------------
Expand Down Expand Up @@ -769,7 +750,7 @@ private static function get_customer_information_email( $form, $config = null )
private static function get_customer_information_mobile( $form, $config = null ) {
$form_fields = self::get_form_fields( $form );
$selected_field = ! empty( $config["meta"]["customer_fields_mobile"] ) ? $config["meta"]["customer_fields_mobile"] : '';

return self::get_mapped_field_list( 'payping_customer_field_mobile', $selected_field, $form_fields );
}
// ------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1138,34 +1119,7 @@ public static function settings_page() {

</form>

<form action="" method="post">
<?php

wp_nonce_field( "uninstall", "gf_payping_uninstall" );

if ( self::has_access( "gravityforms_payping_uninstall" ) ) {

?>
<div class="hr-divider"></div>
<div class="delete-alert alert_red">

<h3>
<i class="fa fa-exclamation-triangle gf_invalid"></i>
<?php esc_html_e( "غیر فعالسازی افزونه دروازه پرداخت پی‌پینگ", "payping-gravityforms" ); ?>
</h3>

<div
class="gf_delete_notice"><?php esc_html_e( "تذکر : بعد از غیرفعالسازی تمامی اطلاعات مربوط به پی‌پینگ حذف خواهد شد", "payping-gravityforms" ) ?></div>

<?php
echo '<input style="font-family:tahoma !important;" type="submit" name="uninstall" value="' . esc_html__( "غیر فعال سازی درگاه پی‌پینگ", "payping-gravityforms" ) . '" class="button" onclick="return confirm(\'' . esc_html__( "تذکر : بعد از غیرفعالسازی تمامی اطلاعات مربوط به پی‌پینگ حذف خواهد شد . آیا همچنان مایل به غیر فعالسازی میباشید؟", "payping-gravityforms" ) . '\');"/>';

?>

</div>

<?php } ?>
</form>

<?php
}

Expand Down Expand Up @@ -1496,7 +1450,7 @@ class="description"><?php esc_html_e( "شورت کد ها : {form_id} , {form_ti
<td class="payping_customer_fields_desc">
<?php
if ( ! empty( $form ) ) {
echo sprintf(self::get_customer_information_desc( $form, $config ));
self::get_customer_information_desc( $form, $config );
}
?>
</td>
Expand All @@ -1509,7 +1463,7 @@ class="description"><?php esc_html_e( "شورت کد ها : {form_id} , {form_ti
<td class="payping_customer_fields_email">
<?php
if ( ! empty( $form ) ) {
echo sprintf(self::get_customer_information_email( $form, $config ));
self::get_customer_information_email( $form, $config );
}
?>
</td>
Expand All @@ -1522,7 +1476,7 @@ class="description"><?php esc_html_e( "شورت کد ها : {form_id} , {form_ti
<td class="payping_customer_fields_mobile">
<?php
if ( ! empty( $form ) ) {
echo sprintf(self::get_customer_information_mobile( $form, $config ));
self::get_customer_information_mobile( $form, $config);
}
?>
</td>
Expand Down Expand Up @@ -1744,194 +1698,7 @@ class="description"><?php esc_html_e( 'برخی افزودنی های گرویت
}
</style>

<?php
function enqueue_my_custom_script() {
?>
<script type="text/javascript">
function GF_SwitchFid(fid) {
jQuery("#payping_wait").show();
document.location = "?page=gravityforms_payping&view=edit&fid=" + fid;
}

function GF_SwitchForm(id) {
if (id.length > 0) {
document.location = "?page=gravityforms_payping&view=edit&id=" + id;
}
}

var form = [];
form = <?php echo ! empty( $form ) ? GFCommon::json_encode( $form ) : GFCommon::json_encode( array() ) ?>;

jQuery(document).ready(function ($) {

var delete_link, selectedField, selectedValue, selectedOperator;

delete_link = $('.delete_this_condition');
if (delete_link.length === 1)
delete_link.hide();

$(document.body).on('change', '.gf_payping_conditional_field_id', function () {
var id = $(this).attr('id');
id = id.replace('gf_payping_', '').replace('__conditional_field_id', '');
var selectedOperator = $('#gf_payping_' + id + '__conditional_operator').val();
$('#gf_payping_' + id + '__conditional_value_container').html(GetConditionalFieldValues("gf_payping_" + id + "__conditional", jQuery(this).val(), selectedOperator, "", 20, id));
}).on('change', '.gf_payping_conditional_operator', function () {
var id = $(this).attr('id');
id = id.replace('gf_payping_', '').replace('__conditional_operator', '');
var selectedOperator = $(this).val();
var field_id = $('#gf_payping_' + id + '__conditional_field_id').val();
$('#gf_payping_' + id + '__conditional_value_container').html(GetConditionalFieldValues("gf_payping_" + id + "__conditional", field_id, selectedOperator, "", 20, id));
}).on('click', '.add_new_condition', function () {
var parent_div = $(this).parent('.gf_payping_conditional_div');
var counter = $('#gf_payping_conditional_counter');
var new_id = parseInt(counter.val()) + 1;
var content = parent_div[0].outerHTML
.replace(new RegExp('gf_payping_\\d+__', 'g'), ('gf_payping_' + new_id + '__'))
.replace(new RegExp('\\[\\d+\\]', 'g'), ('[' + new_id + ']'));
counter.val(new_id);
counter.before(content);
RefreshConditionRow("gf_payping_" + new_id + "__conditional", "", "is", "", new_id);
$('.delete_this_condition').show();
return false;
}).on('click', '.delete_this_condition', function () {
$(this).parent('.gf_payping_conditional_div').remove();
var delete_link = $('.delete_this_condition');
if (delete_link.length === 1)
delete_link.hide();
return false;
});

<?php foreach ( $condition_field_ids as $i => $field_id ) : ?>
selectedField = "<?php echo esc_html(str_replace( '"', '\"', $field_id )); ?>";
selectedValue = "<?php echo esc_html(str_replace( '"', '\"', $condition_values[ '' . $i . '' ] )); ?>";
selectedOperator = "<?php echo esc_html(str_replace( '"', '\"', $condition_operators[ '' . $i . '' ] )); ?>";
RefreshConditionRow("gf_payping_<?php echo esc_html(intval( $i ));?>__conditional", selectedField, selectedOperator, selectedValue, <?php echo esc_html(intval( $i ));?>);
<?php endforeach;?>
});

function RefreshConditionRow(input, selectedField, selectedOperator, selectedValue, index) {
var field_id = jQuery("#" + input + "_field_id");
field_id.html(GetSelectableFields(selectedField, 20));
var optinConditionField = field_id.val();
var checked = jQuery("#" + input + "_enabled").attr('checked');
if (optinConditionField) {
jQuery("#gf_no_conditional_message").hide();
jQuery("#" + input + "_div").show();
jQuery("#" + input + "_value_container").html(GetConditionalFieldValues("" + input + "", optinConditionField, selectedOperator, selectedValue, 20, index));
jQuery("#" + input + "_value").val(selectedValue);
jQuery("#" + input + "_operator").val(selectedOperator);
}
else {
jQuery("#gf_no_conditional_message").show();
jQuery("#" + input + "_div").hide();
}
if (!checked) jQuery("#" + input + "_container").hide();
}

function GetConditionalFieldValues(input, fieldId, selectedOperator, selectedValue, labelMaxCharacters, index) {
if (!fieldId)
return "";
var str = "";
var name = (input.replace(new RegExp('_\\d+__', 'g'), '_')) + "_value[" + index + "]";
var field = GetFieldById(fieldId);
if (!field)
return "";

var is_text = false;

if (selectedOperator == '' || selectedOperator == 'is' || selectedOperator == 'isnot') {
if (field["type"] == "post_category" && field["displayAllCategories"]) {
str += '<?php $dd = wp_dropdown_categories( array(
"class" => "condition_field_value",
"orderby" => "name",
"id" => "gf_dropdown_cat_id",
"name" => "gf_dropdown_cat_name",
"hierarchical" => true,
"hide_empty" => 0,
"echo" => false
) ); echo str_replace( "\n", "", str_replace( "'", "\\'", $dd ) ); ?>';
str = str.replace("gf_dropdown_cat_id", "" + input + "_value").replace("gf_dropdown_cat_name", name);
}
else if (field.choices) {
var isAnySelected = false;
str += "<select class='condition_field_value' id='" + input + "_value' name='" + name + "'>";
for (var i = 0; i < field.choices.length; i++) {
var fieldValue = field.choices[i].value ? field.choices[i].value : field.choices[i].text;
var isSelected = fieldValue == selectedValue;
var selected = isSelected ? "selected='selected'" : "";
if (isSelected)
isAnySelected = true;
str += "<option value='" + fieldValue.replace(/'/g, "&#039;") + "' " + selected + ">" + TruncateMiddle(field.choices[i].text, labelMaxCharacters) + "</option>";
}
if (!isAnySelected && selectedValue) {
str += "<option value='" + selectedValue.replace(/'/g, "&#039;") + "' selected='selected'>" + TruncateMiddle(selectedValue, labelMaxCharacters) + "</option>";
}
str += "</select>";
}
else {
is_text = true;
}
}
else {
is_text = true;
}

if (is_text) {
selectedValue = selectedValue ? selectedValue.replace(/'/g, "&#039;") : "";
str += "<input type='text' class='condition_field_value' style='padding:3px' placeholder='<?php esc_html_e( "یک مقدار وارد نمایید", "payping-gravityforms" ); ?>' id='" + input + "_value' name='" + name + "' value='" + selectedValue + "'>";
}
return str;
}

function GetSelectableFields(selectedFieldId, labelMaxCharacters) {
var str = "";
if (typeof form.fields !== "undefined") {
var inputType;
var fieldLabel;
for (var i = 0; i < form.fields.length; i++) {
fieldLabel = form.fields[i].adminLabel ? form.fields[i].adminLabel : form.fields[i].label;
inputType = form.fields[i].inputType ? form.fields[i].inputType : form.fields[i].type;
if (IsConditionalLogicField(form.fields[i])) {
var selected = form.fields[i].id == selectedFieldId ? "selected='selected'" : "";
str += "<option value='" + form.fields[i].id + "' " + selected + ">" + TruncateMiddle(fieldLabel, labelMaxCharacters) + "</option>";
}
}
}
return str;
}

function TruncateMiddle(text, maxCharacters) {
if (!text)
return "";
if (text.length <= maxCharacters)
return text;
var middle = parseInt(maxCharacters / 2);
return text.substr(0, middle) + "..." + text.substr(text.length - middle, middle);
}

function GetFieldById(fieldId) {
for (var i = 0; i < form.fields.length; i++) {
if (form.fields[i].id == fieldId)
return form.fields[i];
}
return null;
}

function IsConditionalLogicField(field) {
var inputType = field.inputType ? field.inputType : field.type;
var supported_fields = ["checkbox", "radio", "select", "text", "website", "textarea", "email", "hidden", "number", "phone", "multiselect", "post_title",
"post_tags", "post_custom_field", "post_content", "post_excerpt"];
var index = jQuery.inArray(inputType, supported_fields);
return index >= 0;
}
</script>
<?php
}

// Enqueue the script
wp_enqueue_script('my-custom-script', '', array('jquery'), null, true);
wp_add_inline_script('my-custom-script', 'jQuery(document).ready(function($) { ' . enqueue_my_custom_script() . ' });');
?>


<?php
}
Expand Down Expand Up @@ -2095,10 +1862,7 @@ public static function Request( $confirmation, $form, $entry, $ajax ) {
}
GFAPI::update_entry( $entry );
$entry = GFPersian_Payments::get_entry( $entry_id );


$ReturnPath = self::Return_URL( $form['id'], $entry_id );
//var_dump(self::$config); die();
$ResNumber = apply_filters( 'gf_payping_res_number', apply_filters( 'ppgf_gateway_res_number', $entry_id, $entry, $form ), $entry, $form );
} else {
$Amount = absint( 2000 );
Expand Down Expand Up @@ -2159,7 +1923,7 @@ public static function Request( $confirmation, $form, $entry, $ajax ) {

if (isset($response["code"]) && $response["code"] != '') {
$Payment_URL = sprintf('https://api.payping.ir/v1/pay/gotoipg/%s', $response["code"]);

if ($valid_checker) {
return true;
} else {
Expand Down

0 comments on commit 1f1752f

Please sign in to comment.