Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/Admin/CPT
File: DownloadAllSubmissions.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* This module utilizes deprecated code, which should eventually be replaced.
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
require_once Ninja_Forms::$dir . 'lib/StepProcessing/step-processing.php';
[6] Fix | Delete
[7] Fix | Delete
class NF_Admin_CPT_DownloadAllSubmissions extends NF_Step_Processing {
[8] Fix | Delete
[9] Fix | Delete
function __construct() {
[10] Fix | Delete
$this->action = 'download_all_subs';
[11] Fix | Delete
[12] Fix | Delete
parent::__construct();
[13] Fix | Delete
[14] Fix | Delete
add_action( 'admin_footer-edit.php', array( $this, 'bulk_admin_footer' ) );
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
protected function allowProcessing(): bool
[18] Fix | Delete
{
[19] Fix | Delete
if (
[20] Fix | Delete
!is_admin() ||
[21] Fix | Delete
!is_user_logged_in() ||
[22] Fix | Delete
!current_user_can(apply_filters('ninja_forms_api_allow_get_submissions', 'manage_options')) ||
[23] Fix | Delete
!isset($_REQUEST['args']) ||
[24] Fix | Delete
!isset($_REQUEST['args']['security']) ||
[25] Fix | Delete
!wp_verify_nonce($_REQUEST['args']['security'], 'ninja_forms_batch_nonce')
[26] Fix | Delete
) {
[27] Fix | Delete
return false;
[28] Fix | Delete
}else{
[29] Fix | Delete
return true;
[30] Fix | Delete
}
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
public function loading() {
[34] Fix | Delete
$subs_per_step = apply_filters( 'ninja_forms_export_subs_per_step', 10 );
[35] Fix | Delete
$form_id = isset( $this->args['form_id'] ) ? absint( $this->args['form_id'] ) : 0;
[36] Fix | Delete
[37] Fix | Delete
if ( empty( $form_id ) ) {
[38] Fix | Delete
[39] Fix | Delete
return array( 'complete' => true );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
$sub_count = $this->get_sub_count( $form_id );
[43] Fix | Delete
[44] Fix | Delete
if( empty( $this->total_steps ) || $this->total_steps <= 1 ) {
[45] Fix | Delete
$this->total_steps = round( ( $sub_count / $subs_per_step ), 0 ) + 2;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
$args = array(
[49] Fix | Delete
'total_steps' => $this->total_steps,
[50] Fix | Delete
);
[51] Fix | Delete
[52] Fix | Delete
$this->args['filename'] = $this->random_filename( 'all-subs' );
[53] Fix | Delete
update_user_option( get_current_user_id(), 'nf_download_all_subs_filename', $this->args['filename'] );
[54] Fix | Delete
$this->redirect = esc_url_raw( add_query_arg( array( 'download_all' => $this->args['filename'] ), $this->args['redirect'] ) );
[55] Fix | Delete
[56] Fix | Delete
$this->loaded = true;
[57] Fix | Delete
return $args;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
public function step() {
[61] Fix | Delete
if( ! is_numeric( $this->args[ 'form_id' ] ) ){
[62] Fix | Delete
wp_die( esc_html__( 'Invalid form id', 'ninja-forms' ) );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
$subs_per_step = apply_filters( 'ninja_forms_export_subs_per_step', 10 );
[66] Fix | Delete
[67] Fix | Delete
$this->args[ 'filename' ] = wp_kses_post( $this->args[ 'filename' ] );
[68] Fix | Delete
[69] Fix | Delete
$exported_subs = get_user_option( get_current_user_id(), 'nf_download_all_subs_ids' );
[70] Fix | Delete
if ( ! is_array( $exported_subs ) ) {
[71] Fix | Delete
$exported_subs = array();
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$previous_name = get_user_option( get_current_user_id(), 'nf_download_all_subs_filename' );
[75] Fix | Delete
if ( $previous_name ) {
[76] Fix | Delete
$this->args['filename'] = $previous_name;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
$args = array(
[80] Fix | Delete
'posts_per_page' => $subs_per_step,
[81] Fix | Delete
'paged' => $this->step,
[82] Fix | Delete
'post_type' => 'nf_sub',
[83] Fix | Delete
'meta_query' => array(
[84] Fix | Delete
array(
[85] Fix | Delete
'key' => '_form_id',
[86] Fix | Delete
'value' => $this->args['form_id'],
[87] Fix | Delete
),
[88] Fix | Delete
),
[89] Fix | Delete
);
[90] Fix | Delete
[91] Fix | Delete
$subs_results = get_posts( $args );
[92] Fix | Delete
[93] Fix | Delete
if ( is_array( $subs_results ) && ! empty( $subs_results ) ) {
[94] Fix | Delete
$upload_dir = wp_upload_dir();
[95] Fix | Delete
$file_path = trailingslashit( $upload_dir['path'] ) . $this->args['filename'] . '.csv';
[96] Fix | Delete
$myfile = fopen( $file_path, 'a' ) or die( 'Unable to open file!' );
[97] Fix | Delete
$x = 0;
[98] Fix | Delete
$export = '';
[99] Fix | Delete
[100] Fix | Delete
$sub_ids = array();
[101] Fix | Delete
foreach( $subs_results as $result ){
[102] Fix | Delete
$sub_ids[] = $result->ID;
[103] Fix | Delete
}
[104] Fix | Delete
$export .= NF_Database_Models_Submission::export( $this->args['form_id'], $sub_ids, TRUE );
[105] Fix | Delete
if( 1 < $this->step ) {
[106] Fix | Delete
$stack = explode( apply_filters( 'nf_sub_csv_terminator', "\n" ), $export );
[107] Fix | Delete
array_shift($stack);
[108] Fix | Delete
$stack = implode( apply_filters( 'nf_sub_csv_terminator', "\n" ), $stack );
[109] Fix | Delete
$export = $stack;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
fwrite( $myfile, $export );
[113] Fix | Delete
fclose( $myfile );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
update_user_option( get_current_user_id(), 'nf_download_all_subs_ids', $exported_subs );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
public function complete() {
[120] Fix | Delete
delete_user_option( get_current_user_id(), 'nf_download_all_subs_ids' );
[121] Fix | Delete
delete_user_option( get_current_user_id(), 'nf_download_all_subs_filename' );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
/**
[125] Fix | Delete
* Add an integar to the end of our filename to make sure it is unique
[126] Fix | Delete
*
[127] Fix | Delete
* @access public
[128] Fix | Delete
* @since 2.7.6
[129] Fix | Delete
* @return $filename
[130] Fix | Delete
*/
[131] Fix | Delete
public function random_filename( $filename ) {
[132] Fix | Delete
$upload_dir = wp_upload_dir();
[133] Fix | Delete
$file_path = trailingslashit( $upload_dir['path'] ) . $filename . '.csv';
[134] Fix | Delete
if ( file_exists ( $file_path ) ) {
[135] Fix | Delete
for ($x = 0; $x < 999 ; $x++) {
[136] Fix | Delete
$tmp_name = $filename . '-' . $x;
[137] Fix | Delete
$tmp_path = trailingslashit( $upload_dir['path'] );
[138] Fix | Delete
if ( file_exists( $tmp_path . $tmp_name . '.csv' ) ) {
[139] Fix | Delete
$this->random_filename( $tmp_name );
[140] Fix | Delete
break;
[141] Fix | Delete
} else {
[142] Fix | Delete
$this->filename = $tmp_name;
[143] Fix | Delete
break;
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
return $filename;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
public function bulk_admin_footer() {
[152] Fix | Delete
global $post_type;
[153] Fix | Delete
[154] Fix | Delete
if ( ! is_admin() )
[155] Fix | Delete
return false;
[156] Fix | Delete
[157] Fix | Delete
if( $post_type == 'nf_sub' && isset ( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'all' ) {
[158] Fix | Delete
?>
[159] Fix | Delete
<script type="text/javascript">
[160] Fix | Delete
jQuery(document).ready(function() {
[161] Fix | Delete
<?php
[162] Fix | Delete
if ( ( isset ( $_POST['action'] ) && $_POST['action'] == 'export' ) || ( isset ( $_POST['action2'] ) && $_POST['action2'] == 'export' ) ) {
[163] Fix | Delete
?>
[164] Fix | Delete
setInterval(function(){
[165] Fix | Delete
jQuery( "select[name='action'" ).val( '-1' );
[166] Fix | Delete
jQuery( "select[name='action2'" ).val( '-1' );
[167] Fix | Delete
jQuery( '#posts-filter' ).submit();
[168] Fix | Delete
},5000);
[169] Fix | Delete
<?php
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
if ( isset ( $_REQUEST['form_id'] ) && ! empty ( $_REQUEST['form_id'] ) ) {
[173] Fix | Delete
$redirect = urlencode( remove_query_arg( array( 'download_all', 'download_file' ) ) );
[174] Fix | Delete
$url = admin_url( 'admin.php?page=nf-processing&action=download_all_subs&form_id=' . absint( $_REQUEST['form_id'] ) . '&redirect=' . $redirect . '&security=' . wp_create_nonce( 'ninja_forms_batch_nonce' ) );
[175] Fix | Delete
$url = esc_url( apply_filters( 'ninja_forms_download_all_submissions_url', $url, absint( $_REQUEST['form_id'] ) ) );
[176] Fix | Delete
?>
[177] Fix | Delete
var button = '<a href="<?php echo $url; ?>" class="button-secondary nf-download-all"><?php echo esc_html__( 'Download All Submissions', 'ninja-forms' ); ?></a>';
[178] Fix | Delete
jQuery( '#doaction2' ).after( button );
[179] Fix | Delete
<?php
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
if ( isset ( $_REQUEST['download_all'] ) && $_REQUEST['download_all'] != '' ) {
[183] Fix | Delete
$redirect = esc_url_raw( add_query_arg( array( 'download_file' => esc_html( $_REQUEST['download_all'] ) ) ) );
[184] Fix | Delete
$redirect = remove_query_arg( array( 'download_all' ), $redirect );
[185] Fix | Delete
?>
[186] Fix | Delete
document.location.href = "<?php echo $redirect; ?>";
[187] Fix | Delete
<?php
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
?>
[191] Fix | Delete
});
[192] Fix | Delete
</script>
[193] Fix | Delete
<?php
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
function get_sub_count( $form_id, $post_status = 'publish' ) {
[198] Fix | Delete
global $wpdb;
[199] Fix | Delete
[200] Fix | Delete
$meta_key = '_form_id';
[201] Fix | Delete
$meta_value = $form_id;
[202] Fix | Delete
[203] Fix | Delete
$sql = "SELECT count(DISTINCT pm.post_id)
[204] Fix | Delete
FROM $wpdb->postmeta pm
[205] Fix | Delete
JOIN $wpdb->posts p ON (p.ID = pm.post_id)
[206] Fix | Delete
WHERE pm.meta_key = %s
[207] Fix | Delete
AND pm.meta_value = %s
[208] Fix | Delete
AND p.post_type = 'nf_sub'
[209] Fix | Delete
AND p.post_status = %s";
[210] Fix | Delete
[211] Fix | Delete
$count = $wpdb->get_var( $wpdb->prepare( $sql, $meta_key, $meta_value, $post_status ) );
[212] Fix | Delete
[213] Fix | Delete
return $count;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
}
[217] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function