class-affiliates-export.php 7.35 KB
<?php
 class Affiliates_Export { private $charset = 'UTF-8'; public function __construct() { $this->charset = get_option( 'blog_charset' ); } public function __set( $name, $IXAP87 ) { switch( $name ) { case 'charset' : $this->charset = $IXAP87; break; } } public function __get( $name ) { $IXAP15 = null; switch( $name ) { case 'charset' : $IXAP15 = $this->charset; break; } return $IXAP15; } public function request() { $IXAP56 = date( 'Y-m-d-H-i-s', time() ); header( 'Content-Description: File Transfer' ); if ( !empty( $this->charset ) ) { header( 'Content-Type: text/tab-separated-values; charset=' . $this->charset ); } else { header( 'Content-Type: text/tab-separated-values' ); } header( "Content-Disposition: attachment; filename=\"affiliates-export-$IXAP56.tsv\"" ); $this->entries(); echo "\n"; } private function entries() { global $wpdb, $affiliates_db, $affiliates_options; $IXAP47 = $affiliates_db->get_tablename( 'affiliates' ); $IXAP48 = $affiliates_db->get_tablename( 'affiliates_users' ); $IXAP25 = $affiliates_db->get_tablename( 'affiliates_attributes' ); $IXAP101 = date( 'Y-m-d', time() ); $IXAP76 = array( 'affiliate_id' => __( 'Id', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'name' => __( 'Affiliate', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'email' => __( 'Email', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'user_login' => __( 'Username', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'from_date' => __( 'From', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'thru_date' => __( 'Until', AFFILIATES_PRO_PLUGIN_DOMAIN ), 'links' => __( 'Links', AFFILIATES_PRO_PLUGIN_DOMAIN ), ); $IXAP76 = $IXAP76 + Affiliates_Attributes::get_keys(); $IXAP358 = array(); foreach( array_keys( $IXAP76 ) as $IXAP78 ) { $IXAP78 = preg_replace( '/(\.|\-)/', '_', $IXAP78 ); switch( $IXAP78 ) { case 'name' : case 'email' : case 'user_login' : $IXAP358[$IXAP78] = true; break; default : $IXAP358[$IXAP78] = false; } } $IXAP359 = $IXAP358; foreach( $affiliates_options->get_option( 'affiliates_overview_columns', array() ) as $IXAP78 => $IXAP87 ) { $IXAP359[$IXAP78] = $IXAP87; } $IXAP466 = array(); foreach( $IXAP76 as $IXAP78 => $IXAP133 ) { $IXAP362 = preg_replace( '/(\.|\-)/', '_', $IXAP78 ); if ( isset( $IXAP359[$IXAP362] ) && $IXAP359[$IXAP362] ) { $IXAP466[] = $IXAP133; } } require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings.php'; require_once AFFILIATES_CORE_LIB . '/class-affiliates-settings-registration.php'; $IXAP357 = Affiliates_Settings_Registration::get_fields(); foreach( Affiliates_Registration::get_skip_meta_fields() as $IXAP78 ) { unset( $IXAP357[$IXAP78] ); } if ( !empty( $IXAP357 ) ) { foreach( $IXAP357 as $name => $IXAP212 ) { if ( isset( $IXAP359[$name] ) && $IXAP359[$name] && $IXAP212['enabled'] ) { $IXAP466[] = stripslashes( $IXAP212['label'] ); } } } $IXAP30 = count( $IXAP466 ); for ( $IXAP80 = 0; $IXAP80 < $IXAP30; $IXAP80++ ) { echo $IXAP466[$IXAP80]; if ( $IXAP80 < $IXAP30 - 1 ) { echo "\t"; } } echo "\n"; $IXAP36 = $affiliates_options->get_option( 'affiliates_from_date', null ); $IXAP37 = null; $IXAP38 = $affiliates_options->get_option( 'affiliates_thru_date', null ); $IXAP39 = null; $IXAP24 = $affiliates_options->get_option( 'affiliates_affiliate_id', null ); $IXAP43 = $affiliates_options->get_option( 'affiliates_affiliate_name', null ); $IXAP354 = $affiliates_options->get_option( 'affiliates_affiliate_email', null ); $IXAP44 = $affiliates_options->get_option( 'affiliates_affiliate_user_login', null ); $IXAP289 = $affiliates_options->get_option( 'affiliates_show_deleted', false ); $IXAP290 = $affiliates_options->get_option( 'affiliates_show_inoperative', false ); $IXAP228 = $affiliates_options->get_option( 'affiliates_show_totals', true ); $IXAP51 = array( " 1=%d " ); $IXAP52 = array( 1 ); if ( $IXAP24 ) { $IXAP51[] = " $IXAP47.affiliate_id = %d "; $IXAP52[] = $IXAP24; } if ( $IXAP43 ) { $IXAP51[] = " $IXAP47.name LIKE '%%%s%%' "; $IXAP52[] = $IXAP43; } if ( $IXAP354 ) { $IXAP51[] = " $IXAP47.email LIKE '%%%s%%' "; $IXAP52[] = $IXAP354; } if ( $IXAP44 ) { $IXAP51[] = " $wpdb->users.user_login LIKE '%%%s%%' "; $IXAP52[] = $IXAP44; } if ( !$IXAP289 ) { $IXAP51[] = " $IXAP47.status = %s "; $IXAP52[] = 'active'; } if ( !$IXAP290 ) { $IXAP51[] = " $IXAP47.from_date <= %s AND ( $IXAP47.thru_date IS NULL OR $IXAP47.thru_date >= %s ) "; $IXAP52[] = $IXAP101; $IXAP52[] = $IXAP101; } if ( $IXAP37 && $IXAP39 ) { $IXAP51[] = " $IXAP47.from_date >= %s AND ( $IXAP47.thru_date IS NULL OR $IXAP47.thru_date < %s ) "; $IXAP52[] = $IXAP37; $IXAP52[] = $IXAP39; } else if ( $IXAP37 ) { $IXAP51[] = " $IXAP47.from_date >= %s "; $IXAP52[] = $IXAP37; } else if ( $IXAP39 ) { $IXAP51[] = " $IXAP47.thru_date < %s "; $IXAP52[] = $IXAP39; } if ( !empty( $IXAP51 ) ) { $IXAP51 = " WHERE " . implode( " AND ", $IXAP51 ); } else { $IXAP51 = ''; } $IXAP98 = $wpdb->prepare( "SELECT $IXAP47.*, $wpdb->users.* " . "FROM $IXAP47 " . "LEFT JOIN $IXAP48 ON $IXAP47.affiliate_id = $IXAP48.affiliate_id " . "LEFT JOIN $wpdb->users on $IXAP48.user_id = $wpdb->users.ID " . "LEFT JOIN $IXAP25 ON $IXAP47.affiliate_id = $IXAP25.affiliate_id " . "$IXAP51 " , $IXAP52 ); $IXAP55 = $wpdb->get_results( $IXAP98, OBJECT ); foreach( $IXAP55 as $IXAP15 ) { $IXAP90 = array(); if ( isset( $IXAP359['affiliate_id'] ) && $IXAP359['affiliate_id'] ) { $IXAP90[] = $IXAP15->affiliate_id; } if ( isset( $IXAP359['name'] ) && $IXAP359['name'] ) { $IXAP90[] = stripslashes( wp_filter_nohtml_kses( $IXAP15->name ) ); } if ( isset( $IXAP359['email'] ) && $IXAP359['email'] ) { $IXAP90[] = $IXAP15->email; } if ( isset( $IXAP359['user_login'] ) && $IXAP359['user_login'] ) { $IXAP90[] = $IXAP15->user_login; } if ( isset( $IXAP359['from_date'] ) && $IXAP359['from_date'] ) { $IXAP90[] = $IXAP15->from_date; } if ( isset( $IXAP359['thru_date'] ) && $IXAP359['thru_date'] ) { $IXAP90[] = $IXAP15->thru_date; } if ( isset( $IXAP359['links'] ) && $IXAP359['links'] ) { $IXAP90[] = Affiliates_Url_Renderer::get_affiliate_url( get_bloginfo( 'url' ), $IXAP15->affiliate_id ); } foreach( Affiliates_Attributes::get_keys() as $IXAP365 => $IXAP366 ) { $IXAP367 = $IXAP365; $IXAP365 = preg_replace( '/(\.|\-)/', '_', $IXAP365 ); if ( isset( $IXAP359[$IXAP365] ) && $IXAP359[$IXAP365] ) { $IXAP368 = $affiliates_db->get_value( "SELECT attr_value FROM $IXAP25 WHERE affiliate_id = %d AND attr_key = %s", $IXAP15->affiliate_id, $IXAP367 ); $IXAP90[] = wp_filter_nohtml_kses( $IXAP368 ); } } if ( !empty( $IXAP357 ) ) { foreach( $IXAP357 as $name => $IXAP212 ) { if ( isset( $IXAP359[$name] ) && $IXAP359[$name] && $IXAP212['enabled'] ) { $IXAP252 = isset( $IXAP212['type'] ) ? $IXAP212['type'] : 'text'; $IXAP87 = ''; switch( $name ) { case 'user_login' : $IXAP87 = $IXAP95->user_login; break; case 'user_email' : $IXAP87 = $IXAP95->user_email; break; case 'user_url' : $IXAP87 = $IXAP95->user_url; break; case 'password' : $IXAP87 = ''; break; default : $IXAP87 = get_user_meta( $IXAP15->ID, $name , true ); } $IXAP90[] = stripslashes( $IXAP87 ); } } } $IXAP30 = count( $IXAP90 ); for ( $IXAP80 = 0; $IXAP80 < $IXAP30; $IXAP80++ ) { echo $IXAP90[$IXAP80]; echo "\t"; } echo "\n"; } } public static function init() { add_action( 'init', array(__CLASS__,'wp_init' ) ); } public static function wp_init() { if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'export' && wp_verify_nonce( $_REQUEST['export-nonce'], 'export-affiliates' ) ) { if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) { wp_die( __( 'Access denied.', AFFILIATES_PRO_PLUGIN_DOMAIN ) ); } $IXAP467 = new Affiliates_Export(); $IXAP467->request(); die; } } } Affiliates_Export::init();