} //joindate and enddate $csvoutput .= "," . pmpro_enclose(date("Y-m-d", $theuser->joindate)) . ","; if ($theuser->membership_id) { if ($theuser->enddate) { $csvoutput .= pmpro_enclose(apply_filters("pmpro_memberslist_expires_column", date("Y-m-d", $theuser->enddate), $theuser)); } else { $csvoutput .= pmpro_enclose(apply_filters("pmpro_memberslist_expires_column", "Never", $theuser)); } } elseif ($l == "oldmembers" && $theuser->enddate) { $csvoutput .= pmpro_enclose(date("Y-m-d", $theuser->enddate)); } else { $csvoutput .= "N/A"; } //any extra columns if (!empty($extra_columns)) { foreach ($extra_columns as $heading => $callback) { $csvoutput .= "," . pmpro_enclose(call_user_func($callback, $theuser, $heading)); } } $csvoutput .= "\n"; //output echo $csvoutput; $csvoutput = ""; } } print $csvoutput; function pmpro_enclose($s) { return "\"" . str_replace("\"", "\\\"", $s) . "\""; }
} //only admins can get this if (!function_exists("current_user_can") || !current_user_can("manage_options") && !current_user_can("pmpro_affiliates_report_csv") && ($report != "all" && $current_user->user_login != $affiliate->affiliateuser)) { die(__("You do not have permissions to perform this action.", "pmpro")); } $sqlQuery = "SELECT a.code, o.affiliate_subid as subid, a.name, u.ID as user_id, u.user_login, u.display_name as display_name, UNIX_TIMESTAMP(o.timestamp) as timestamp, o.total FROM {$wpdb->pmpro_membership_orders} o LEFT JOIN {$wpdb->pmpro_affiliates} a ON o.affiliate_id = a.id LEFT JOIN {$wpdb->users} u ON o.user_id = u.ID WHERE o.affiliate_id <> '' "; if ($report != "all") { $sqlQuery .= " AND a.id = '" . esc_sql($report) . "' "; } $affiliate_orders = $wpdb->get_results($sqlQuery); //begin output header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=affiliates_report.csv"); //headings echo "code,sub-id,user_id,user_login,display_name,date,total\n"; if (!empty($affiliate_orders)) { global $pmpro_currency_symbol; foreach ($affiliate_orders as $order) { echo pmpro_enclose($order->code) . ","; echo pmpro_enclose($order->subid) . ","; echo pmpro_enclose($order->user_id) . ","; echo pmpro_enclose($order->user_login) . ","; echo pmpro_enclose($order->display_name) . ","; echo pmpro_enclose(date("Y-m-d", $order->timestamp)) . ","; echo pmpro_enclose($order->total) . "\n"; } } function pmpro_enclose($s) { return "\"" . str_replace("\"", "\\\"", $s) . "\""; }
if ($count > 1) { $csvoutput .= ","; } //checking $object->property. note the double $$ if (!empty($col[2]) && isset(${$col}[0]->{$col}[1]->{$col}[2])) { $csvoutput .= pmpro_enclose(${$col}[0]->{$col}[1]->{$col}[2]); } elseif (!empty(${$col}[0]->{$col}[1])) { $csvoutput .= pmpro_enclose(${$col}[0]->{$col}[1]); } //output the value } } //timestamp $csvoutput .= "," . pmpro_enclose(date(get_option("date_format"), $order->timestamp)); //any extra columns if (!empty($extra_columns)) { foreach ($extra_columns as $heading => $callback) { $csvoutput .= "," . pmpro_enclose(call_user_func($callback, $order)); } } $csvoutput .= "\n"; //output echo $csvoutput; $csvoutput = ""; } } print $csvoutput; function pmpro_enclose($s) { return "\"" . str_replace("\"", "\\\"", $s) . "\""; }
if ($theuser->enddate) { array_push($csvoutput, pmpro_enclose(apply_filters("pmpro_memberslist_expires_column", date($dateformat, $theuser->enddate), $theuser))); } else { array_push($csvoutput, pmpro_enclose(apply_filters("pmpro_memberslist_expires_column", "Never", $theuser))); } } elseif ($l == "oldmembers" && $theuser->enddate) { array_push($csvoutput, pmpro_enclose(date($dateformat, $theuser->enddate))); } else { array_push($csvoutput, "N/A"); } //any extra columns if (!empty($extra_columns)) { foreach ($extra_columns as $heading => $callback) { $val = call_user_func($callback, $theuser, $heading); $val = !empty($val) ? $val : null; array_push($csvoutput, pmpro_enclose($val)); } } //free memory for user records $metavalues = null; $discount_code = null; $theuser = null; // $csvoutput .= "\n"; $line = implode(',', $csvoutput) . "\n"; fprintf($csv_fh, "%s", $line); //reset $line = null; $csvoutput = null; } // end of foreach usr_data if (PMPRO_BENCHMARK) {