affiliatesexport.php
7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
/**
* affiliatesexport.php
*
* Copyright (c) 2011,2012 Antonio Blanco http://www.eggemplo.com
*
* This code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This header and all notices must be kept intact.
*
* @author Antonio Blanco
* @package affiliatesexport
* @since affiliatesexport 1.0.0
*
* Plugin Name: Affiliates Export
* Plugin URI: http://www.itthinx.com
* Description: Affiliates data exporter
* Version: 1.0
* Author: itthinx
* Author URI: http://www.itthinx.com
* License: GPLv3
*/
define( 'AFFILIATESEXPORT_DOMAIN', 'affiliatesexport' );
define( 'AFFILIATESEXPORT_FILE', __FILE__ );
define( 'AFFILIATESEXPORT_PLUGIN_URL', plugin_dir_url( AFFILIATESEXPORT_FILE ) );
include_once 'class-affiliatesexport.php';
class AffiliatesExport_Plugin {
private static $notices = array();
public static function init() {
load_plugin_textdomain( AFFILIATESEXPORT_DOMAIN, null, 'affiliatesexport/languages' );
register_activation_hook( AFFILIATESEXPORT_FILE, array( __CLASS__, 'activate' ) );
register_deactivation_hook( AFFILIATESEXPORT_FILE, array( __CLASS__, 'deactivate' ) );
add_action( 'init', array( __CLASS__, 'wp_init' ) );
add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) );
}
public static function wp_init() {
if ( !defined ( 'AFFILIATES_PLUGIN_DOMAIN' ) ) {
self::$notices[] = "<div class='error'>" . __( '<strong>AffiliatesExport</strong> plugin requires <a href="http://www.itthinx.com/plugins/affiliates" target="_blank">Affiliates</a> or <a href="http://www.itthinx.com/plugins/affiliates-pro" target="_blank">Affiliates Pro</a> or <a href="http://www.itthinx.com/plugins/affiliates-enterprise" target="_blank">Affiliates Enterprise</a>.', AFFILIATESEXPORT_DOMAIN ) . "</div>";
} else {
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ), 40 );
//call register settings function
add_action( 'admin_init', array( __CLASS__, 'register_affiliatesexport_settings' ) );
}
}
/**
* Register settings as groups-mailchimp-settings
*/
public static function register_affiliatesexport_settings() {
// load datepicker scripts for all
wp_enqueue_script( 'datepicker', AFFILIATESEXPORT_PLUGIN_URL . 'js/jquery.ui.datepicker.min.js', array( 'jquery', 'jquery-ui-core' ));
wp_enqueue_script( 'datepickers', AFFILIATESEXPORT_PLUGIN_URL . 'js/datepickers.js', array( 'jquery', 'jquery-ui-core', 'datepicker' ));
wp_register_style( 'smoothness', AFFILIATESEXPORT_PLUGIN_URL . 'css/smoothness/jquery-ui-1.8.16.custom.css', array());
//register our settings
register_setting( 'affiliatesexport-settings', 'affexp_status' );
}
public static function admin_notices() {
if ( !empty( self::$notices ) ) {
foreach ( self::$notices as $notice ) {
echo $notice;
}
}
}
/**
* Adds the admin section.
*/
public static function admin_menu() {
$admin_page = add_submenu_page(
'affiliates-admin',
__( 'Affiliates export' , AFFILIATESEXPORT_DOMAIN),
__( 'Affiliates export' , AFFILIATESEXPORT_DOMAIN),
'manage_options',
'affiliatesexport',
array( __CLASS__, 'affiliatesexport' )
);
add_action( 'admin_print_styles-' . $admin_page, array( __CLASS__,'admin_print_styles') );
}
function admin_print_styles() {
wp_enqueue_style( 'smoothness' );
}
/**
* Show Groups MailChimp setting page.
*/
public static function affiliatesexport () {
?>
<div class="wrap">
<h2><?php echo __( 'Affiliates Export', AFFILIATESEXPORT_DOMAIN ); ?></h2>
<?php
if ( isset( $_POST['submit'] ) ) {
add_option( 'affexp_status', $_POST['affexp_status'] );
update_option( 'affexp_status', $_POST['affexp_status'] );
add_option( 'affexp_from_date', $_POST['from_date'] );
update_option( 'affexp_from_date', $_POST['from_date'] );
add_option( 'affexp_thru_date', $_POST['thru_date'] );
update_option( 'affexp_thru_date', $_POST['thru_date'] );
} elseif ( isset( $_POST['generate'] ) ) {
AffiliatesExport::generate(
get_option( 'blog_charset' )
);
}
?>
<form method="post" action="">
<table class="form-table">
<tr valign="top">
<th scope="row">
<label class="referral-status-filter" for="referral_status"><?php echo __('Referral Status', AFFILIATES_PLUGIN_DOMAIN );?></label>
</th>
<td>
<?php
$status_old = get_option('affexp_status', null);
$status = array(
AFFILIATES_REFERRAL_STATUS_ACCEPTED => __( 'Accepted', AFFILIATES_PLUGIN_DOMAIN ),
AFFILIATES_REFERRAL_STATUS_CLOSED => __( 'Closed', AFFILIATES_PLUGIN_DOMAIN ),
AFFILIATES_REFERRAL_STATUS_PENDING => __( 'Pending', AFFILIATES_PLUGIN_DOMAIN ),
AFFILIATES_REFERRAL_STATUS_REJECTED => __( 'Rejected', AFFILIATES_PLUGIN_DOMAIN ), );
$output = '<select class="referral-status-filter" name="affexp_status">';
$output .= '<option value="-" ' . ( empty( $status_old ) ? ' selected="selected" ' : '' ) . '>All</option>';
foreach ( $status as $key => $value ) {
$selected = $key == $status_old ? ' selected="selected" ' : '';
$output .= '<option ' . $selected . ' value="' . esc_attr( $key ) . '">' . $value . '</option>';
}
$output .= '</select>';
echo $output;
?>
</td>
</tr>
</table>
<p>
<?php
$from_date = get_option('affexp_from_date', "");
$thru_date = get_option('affexp_thru_date', "");
$output = '<label class="from-date-filter" for="from_date">' . __( 'From', AFFILIATESEXPORT_DOMAIN ) . '</label>' .
'<input class="datefield from-date-filter" name="from_date" type="text" value="' . esc_attr( $from_date ) . '"/>'.
'<label class="thru-date-filter" for="thru_date">' . __( 'Until', AFFILIATESEXPORT_DOMAIN ) . '</label>' .
'<input class="datefield thru-date-filter" name="thru_date" type="text" value="' . esc_attr( $thru_date ) . '"/>';
echo $output;
?>
</p>
<?php
submit_button();
settings_fields( 'affiliatesexport-settings' ); ?>
</form>
<span class="description">File structure: affiliate_id | affiliate_email | num_referrals | amount | num_hits</span>
</br>
<span class="description">Fields separated by tabulator. Referrals separated by enter.</span>
</br>
<?php
$url = esc_url( AFFILIATESEXPORT_PLUGIN_URL . 'core/generate-file.php' );
?>
<a href="<?php echo $url;?>?action=generate_file" target="_blank" class="button"><?php echo __("Generate file", AFFILIATESEXPORT_DOMAIN);?></a>
</div>
<?php
}
/**
* Plugin activation work.
*
*/
public static function activate() {
}
/**
* Plugin deactivation work. Delete database table.
*
*/
public static function deactivate() {
}
}
AffiliatesExport_Plugin::init();