Completed
Push — staging ( db2286...a0e6e2 )
by
unknown
12:24
created

admin/partials/view-list.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if ( ! isset( $_REQUEST['list-id'] ) ) {
3
	wp_die( __( 'Oops, we can\'t determine what List to view. Please go back and try again.' ) );
4
}
5
6
$list_id       = sanitize_key( $_REQUEST['list-id'] );
7
$list_helper   = yikes_get_mc_api_manager()->get_list_handler();
8
$api_key       = yikes_get_mc_api_key();
9
$dash_position = strpos( $api_key, '-' );
10
11
12
$list_data = $list_helper->get_list( $list_id );
13 View Code Duplication
if ( is_wp_error( $list_data ) ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
	$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
15
	$error_logging->maybe_write_to_log(
16
		$list_data->get_error_code(),
17
		__( "Get Account Lists", 'yikes-inc-easy-mailchimp-extender' ),
18
		"View Lists Page"
19
	);
20
	$list_data = array();
21
}
22
23
$merge_fields = $list_helper->get_merge_fields( $list_id );
24
if ( is_wp_error( $merge_fields ) ) {
25
	$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
26
	$error_logging->maybe_write_to_log(
27
		$merge_fields->get_error_code(),
28
		__( "Get Merge Variables", 'yikes-inc-easy-mailchimp-extender' ),
29
		"View Lists Page"
30
	);
31
	$merge_fields = array();
32
}
33
34
// get the interest group data
35
$interest_groupings = $list_helper->get_interest_categories( $list_id );
36
if ( is_wp_error( $interest_groupings ) ) {
37
	$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
38
	$error_logging->maybe_write_to_log(
39
		$interest_groupings->get_error_code(),
40
		__( "Get Interest Groups", 'yikes-inc-easy-mailchimp-extender' ),
41
		"View Lists Page"
42
	);
43
	$interest_groupings = array();
44
}
45
46
$no_interest_groupings = '<p class="description">' . __( 'Interest groups are not enabled for this list.', 'yikes-inc-easy-mailchimp-extender' ) . '</p>';
47
$no_segments = __( 'No segments set up for this list.', 'yikes-inc-easy-mailchimp-extender' );
48
$segments = $list_helper->get_segments( $list_id );
49
50
// Get the full list of members.
51
$members = $list_helper->get_members( $list_id );
52
if ( is_wp_error( $members ) ) {
53
	$error_logging = new Yikes_Inc_Easy_Mailchimp_Error_Logging();
54
	$error_logging->maybe_write_to_log(
55
		$members->get_error_code(),
56
		__( "Get Subscriber Count", 'yikes-inc-easy-mailchimp-extender' ),
57
		"View Lists Page"
58
	);
59
	$members = array();
60
}
61
62
// setup pagination variables
63
$paged			= isset( $_REQUEST['paged'] ) ? filter_var( $_REQUEST['paged'], FILTER_SANITIZE_NUMBER_INT ) : 0;
64
$limit			= apply_filters( 'yikes_admin_list_subscriber_limit', 20 );
65
$page_offset	= (int) $paged * (int) $limit;
66
$sort_dir		= isset( $_REQUEST['sort'] ) ? $_REQUEST['sort'] : 'DESC';
67
68
if ( $sort_dir === 'DESC' ) {
69
	$opposite_sort_dir = 'ASC';
70
	$icon              = '<span class="dashicons dashicons-arrow-down"></span>';
71
	$sort_function     = 'krsort';
72
} else {
73
	$opposite_sort_dir = 'DESC';
74
	$icon              = '<span class="dashicons dashicons-arrow-up"></span>';
75
	$sort_function     = 'ksort';
76
}
77
78
// Sort the array based on the sort direction.
79
$sort_function( $members );
80
81
// Maybe split the array into pages
82
$total_pages = ceil( count( $members ) / $limit );
83
if ( (int) $total_pages === 0 ) {
84
	$total_pages = '1';
85
}
86
87
// Segment the members based on the page and limit
88
$subscribers_list = array_slice( $members, $page_offset, $limit );
89
90
?>
91
<div class="wrap">
92
	<!-- Freddie Logo -->
93
	<img src="<?php echo YIKES_MC_URL . 'includes/images/MailChimp_Assets/Freddie_60px.png'; ?>" alt="<?php __( 'Freddie - MailChimp Mascot' , 'yikes-inc-easy-mailchimp-extender' ); ?>" class="yikes-mc-freddie-logo" />
94
95
	<h1>YIKES Easy Forms for MailChimp | <?php echo $list_data['name']; ?></h1>
96
97
	<!-- Settings Page Description -->
98
	<p class="yikes-easy-mc-about-text about-text"><?php _e( 'View all subscribers below. View additional subscriber info, or add additional fields to this list.' , 'yikes-inc-easy-mailchimp-extender' ); ?></p>
99
	<!-- <p class="add-new-subscriber-button"><a href="#" onclick="jQuery(this).parent().next().slideToggle();" class="add-new-h2"><?php _e( 'New Subscriber' , 'yikes-inc-easy-mailchimp-extender' ); ?></a></p> -->
100
101
	<?php
102
		/* Display our admin notices here */
103
		// Unsubscribe user confirmation message
104 View Code Duplication
		if( isset( $_REQUEST['user-unsubscribed'] ) && $_REQUEST['user-unsubscribed'] == 'true' ) {
105
			?>
106
			<div class="updated manage-form-admin-notice">
107
				<p><?php _e( 'User successfully unsubscribed.', 'yikes-inc-easy-mailchimp-extender' ); ?></p>
108
			</div>
109
			<?php
110
		}
111 View Code Duplication
		if( isset( $_REQUEST['user-unsubscribed'] ) && $_REQUEST['user-unsubscribed'] == 'false' ) {
112
			?>
113
			<div class="error manage-form-admin-notice">
114
				<p><?php _e( "We've encountered an error trying to remove the subscriber. Please try again. If the error persists please get in contact with the YIKES Inc. support staff.", 'yikes-inc-easy-mailchimp-extender' ); ?></p>
115
			</div>
116
			<?php
117
		}
118
	?>
119
120
	<section class="add-new-subscriber-form-container">
121
		<h4><?php _e( 'Add New Subscriber' , 'yikes-inc-easy-mailchimp-extender' ); ?></h4>
122
		<form id="add-new-subcscriber">
123
			<input type="text" class="regular-text" placeholder="<?php _e( 'User Email Address' , 'yikes-inc-easy-mailchimp-extender' ); ?>" /></p>
124
			<p><?php submit_button( 'Add Subscriber' ); ?></p>
125
		</form>
126
	</section>
127
128
	<!-- entire body content -->
129
		<div id="poststuff">
130
131
			<div id="post-body" class="metabox-holder columns-2">
132
133
				<!-- main content -->
134
				<div id="post-body-content">
135
136
					<div class="meta-box-sortables ui-sortable">
137
138
						<div class="postbox yikes-easy-mc-postbox">
139
140
								<table class="wp-list-table widefat fixed posts" cellspacing="0" id="yikes-easy-mc-manage-forms-table">
141
142
									<!-- TABLE HEAD -->
143
									<thead>
144
										<tr>
145
											<th id="user-email columnname" class="manage-column column-columnname" scope="col"><a id="user-email-sort" href="<?php echo esc_url_raw( add_query_arg( array( 'column' => 'email' , 'sort' => $opposite_sort_dir ) ) ); ?>"><?php _e( 'User Email' , 'yikes-inc-easy-mailchimp-extender' ); echo $icon;?></a></th>
146
											<th id="columnname" class="manage-column column-columnname num" scope="col"><?php _e( 'Email Client' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
147
										</tr>
148
									</thead>
149
									<!-- end header -->
150
151
									<!-- FOOTER -->
152
									<tfoot>
153
										<tr>
154
											<th class="manage-column column-columnname" scope="col"><?php _e( 'User Email' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
155
											<th class="manage-column column-columnname num" scope="col"><?php _e( 'Email Client' , 'yikes-inc-easy-mailchimp-extender' ); ?></th>
156
										</tr>
157
									</tfoot>
158
									<!-- end footer -->
159
160
									<!-- TABLE BODY -->
161
									<tbody>
162
										<?php if ( count( $subscribers_list ) > 0 ) {
163
											$i = 1;
164
											foreach ( $subscribers_list as $subscriber ) {
165
												$user_id           = $subscriber['id'];
166
												$path              = YIKES_MC_URL . "includes/images/na.png";
167
												$email_client_icon = "<img width='35' src='" . $path . "' alt='" . __( 'not set', 'yikes-inc-easy-mailchimp-extender' ) . "' title='" . __( 'not set', 'yikes-inc-easy-mailchimp-extender' ) . "'>";
168
169
												?>
170
												<tr class="<?php if ( $i % 2 == 0 ) { echo 'alternate'; } ?>">
171
													<td class="column-columnname">
172
														<a class="user-email row-title" href="mailto:<?php echo sanitize_email( $subscriber['email_address'] ); ?>">
173
															<?php echo sanitize_email( $subscriber['email_address'] ); ?>
174
														</a>
175
														<div class="row-actions">
176
															<?php $view_user_info_url = esc_url_raw( add_query_arg( array(
177
																'mailchimp-list' => $list_id,
178
																'email-id'       => $user_id,
179
															), admin_url() . 'admin.php?page=yikes-mailchimp-view-user' ) ); ?>
180
															<span><a href="<?php echo $view_user_info_url; ?>"><?php _e( 'View Info', 'yikes-inc-easy-mailchimp-extender' ); ?></a> |</span>
181
															<?php $url = esc_url_raw( add_query_arg( array(
182
																'action'         => 'yikes-easy-mc-unsubscribe-user',
183
																'mailchimp-list' => $list_id,
184
																'nonce'          => wp_create_nonce( 'unsubscribe-user-' . $user_id ),
185
																'email_id'       => $user_id,
186
															) ) ); ?>
187
															<span><a href="<?php echo $url; ?>" onclick="return confirm('<?php printf( __( "Are you sure you want to unsubscribe %s from this mailing list?", 'yikes-inc-easy-mailchimp-extender' ), sanitize_email( $subscriber['email_address'] ) ); ?>');" class="yikes-delete-subscriber"><?php _e( "Unsubscribe", 'yikes-inc-easy-mailchimp-extender' ); ?></a>
188
														</div>
189
													</td>
190
													<td class="column-columnname num"><?php echo $email_client_icon; ?></td>
191
												</tr>
192
												<?php
193
												$i ++;
194
											}
195
											} else { ?>
196
											<tr class="no-items">
197
												<td class="colspanchange no-current-subscriber-notice" colspan="2"><em><?php _e( 'No one is currently subscribed to this list.' , 'yikes-inc-easy-mailchimp-extender' ); ?></em></td>
198
											</tr>
199
										<?php } ?>
200
									</tbody>
201
								</table>
202
								<!-- end table -->
203
204
						</div> <!-- .postbox -->
205
206
						<!-- pagination -->
207
						<div class="tablenav">
208
							<div class="tablenav-pages">
209
								<a class='first-page <?php if( $paged == 0 ) { echo 'disabled'; } ?>' title='<?php _e( "Go to the first page" , 'yikes-inc-easy-mailchimp-extender' ); ?>' href='<?php echo esc_url_raw( add_query_arg( array( "paged" => 0 ) ) ); ?>'>&laquo;</a>
210
								<a class='prev-page <?php if( $paged == 0 ) { echo 'disabled'; } ?>' title='<?php _e( "Go to the previous page" , 'yikes-inc-easy-mailchimp-extender' ); ?>' href='<?php echo esc_url_raw( add_query_arg( array( "paged" => intval( $paged - 1 ) ) ) ); ?>'>&lsaquo;</a>
211
								<span class="paging-input"><input class='current-page' title='<?php _e( "Current page" , 'yikes-inc-easy-mailchimp-extender' ); ?>' type='text' name='paged' value='<?php if( $paged == 0 ) { echo '1'; } else { echo intval( $paged + 1 ); } ?>' size='1' /> <?php _e( 'of', 'yikes-inc-easy-mailchimp-extender' ); ?> <span class='total-pages'><?php echo $total_pages; ?></span></span>
212
								<a class='next-page <?php if( $paged == intval( $total_pages - 1 ) ) { echo 'disabled'; } ?>' title='<?php _e( "Go to the next page" , 'yikes-inc-easy-mailchimp-extender' ); ?>' href='<?php echo esc_url_raw( add_query_arg( array( "paged" => intval( $paged + 1 ) ) ) ); ?>'>&rsaquo;</a>
213
								<a class='last-page <?php if( $paged == intval( $total_pages - 1 ) ) { echo 'disabled'; } ?>' title='<?php _e( "Go to the last page" , 'yikes-inc-easy-mailchimp-extender' ); ?>' href='<?php echo esc_url_raw( add_query_arg( array( "paged" => intval( $total_pages - 1 ) ) ) ); ?>'>&raquo;</a>
214
							</div>
215
						</div>
216
217
					</div> <!-- .meta-box-sortables .ui-sortable -->
218
219
				</div> <!-- post-body-content -->
220
221
				<!-- sidebar -->
222
				<div id="postbox-container-1" class="postbox-container">
223
224
					<div class="meta-box-sortables">
225
226
						<div class="postbox yikes-easy-mc-postbox">
227
228
							<h3><?php _e( 'List Overview' , 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
229
230
							<?php
231
								// store list rating
232
								$list_rating = $list_data['list_rating'];
233
								if( $list_rating > 0 ) {
234
									$list_rating_explosion = explode( '.' , $list_rating );
235
									$star_array = array();
236
									$x = 1;
237
									while( $list_rating_explosion[0] >= $x ) {
238
										$star_array[] = '<span class="dashicons dashicons-star-filled list-rating-star"></span>';
239
										$x++;
240
									}
241
									if( $list_rating_explosion[1] == '5' ) {
242
										$star_array[] = '<span class="dashicons dashicons-star-half list-rating-star"></span>';
243
									}
244
								} else {
245
									$star_array = array( 'n/a' );
246
								}
247
							?>
248
							<table class="form-table">
249
								<tr valign="top">
250
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'List Rating' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
251
									<td><?php echo implode( ' ' , $star_array ); ?></td>
252
								</tr>
253
								<tr valign="top">
254
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'Average Subscribers' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
255
									<td><?php echo $list_data['stats']['avg_sub_rate']; ?><small> / <?php  _e( 'month' , 'yikes-inc-easy-mailchimp-extender' ); ?></small></td>
256
								</tr>
257
								<tr valign="top">
258
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'Subscriber Count' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
259
									<td><?php echo intval( $list_data['stats']['member_count'] ); ?></td>
260
								</tr>
261
								<tr valign="top">
262
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'New Since Last Campaign' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
263
									<td><?php echo intval( $list_data['stats']['member_count_since_send'] ); ?></td>
264
								</tr>
265
								<tr valign="top">
266
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'Created' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
267
									<td><?php echo date( get_option('date_format') , strtotime( $list_data['date_created'] ) ); ?></td>
268
								</tr>
269
								<tr valign="top">
270
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'List Fields' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
271
									<td><?php echo intval( $list_data['stats']['merge_field_count'] + 1 ); // add 1 for our email field.. ?></td>
272
								</tr>
273
								<tr valign="top">
274
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'Short Signup URL' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
275
									<td><input type="text" class="widefat view-list-sidebar-input" value="<?php echo esc_url_raw( $list_data['subscribe_url_short'] ); ?>" readonly onclick="jQuery(this).select();"></td>
276
								</tr>
277
								<tr valign="top">
278
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'Default From Email' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
279
									<td><input type="text" class="widefat view-list-sidebar-input" value="<?php echo sanitize_email( $list_data['campaign_defaults']['from_email'] ); ?>" readonly onclick="jQuery(this).select();"></td>
280
								</tr>
281
								<tr valign="top">
282
									<td scope="row"><label for="tablecell"><strong><?php  _e( 'Default From Name' , 'yikes-inc-easy-mailchimp-extender' ); ?></strong></label></td>
283
									<td><?php echo $list_data['campaign_defaults']['from_name']; ?></td>
284
								</tr>
285
							</table>
286
287
						</div> <!-- .postbox -->
288
289
290
						<!-- Merge Field Info -->
291
						<div class="postbox yikes-easy-mc-postbox">
292
293
							<h3><?php _e( 'Form Fields' , 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
294
							<?php
295
								if( count( $merge_fields['merge_fields'] ) >= 1 ) {
296
									?><ul class="merge-variable-ul"><?php
297
										echo '<li class="interest-group-count">' . sprintf( _n( '%d Field', '%d Fields', intval( count( $merge_fields['merge_fields'] ) ), 'yikes-inc-easy-mailchimp-extender' ), intval( count( $merge_fields['merge_fields'] ) ) ) . '</li>';
298
										foreach( $merge_fields['merge_fields'] as $merge_field ) {
299
											// new action hook @since 6.0.3.8
300
											echo '<li class="' . $merge_field['tag'] . '"><span class="dashicons dashicons-marker"></span>' . $merge_field['name'] . ' ' . do_action( 'yikes-mailchimp-list-field', $merge_field ) . '</li>';
301
										}
302
									?></ul><?php
303
								}
304
								/**
305
								*	Custom action hook for our add-ons to hook into
306
								*	@since 6.0.3.8
307
								*/
308
								do_action( 'yikes-mailchimp-list-form-fields-metabox' );
309
							?>
310
311
						</div>
312
313
						<!-- Interest Group Field Info -->
314
						<div class="postbox yikes-easy-mc-postbox">
315
316
317
							<h3><?php _e( 'Interest Groups Overview' , 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
318
							<?php
319
							if ( ! empty( $interest_groupings ) ) {
320
								?>
321
								<ul class="interest-group-ul"><?php
322
								echo '<li class="interest-group-count">' . sprintf( _n( '%d Interest Group', '%d Interest Groups', intval( count( $interest_groupings ) ), 'yikes-inc-easy-mailchimp-extender' ), intval( count( $interest_groupings ) ) ) . '</li>';
323
								foreach ( $interest_groupings as $interest_group ) {
324
									// Build up the total subscribers
325
									$count = array_sum( wp_list_pluck( $interest_group['items'], 'subscriber_count' ) );
326
									echo '<li><span class="dashicons dashicons-marker"></span>' . $interest_group['title'] . '<span class="interest-group-title"></span><small title="' . $count . ' ' . __( "subscribers assigned to this group", 'yikes-inc-easy-mailchimp-extender' ) . '">(' . $count . ')</small></li>';
327
								}
328
								?></ul><?php
329
							} else {
330
								?>
331
								<ul class="interest-group-ul">
332
									<li><?php echo $no_interest_groupings; ?></li>
333
								</ul>
334
								<?php
335
							}
336
							/**
337
							 *    Custom action hook for our add-ons to hook into
338
							 *
339
							 * @since 6.0.3.8
340
							 */
341
							do_action( 'yikes-mailchimp-list-interest-groups-metabox' );
342
							?>
343
344
						</div>
345
346
						<!-- Segments Info -->
347
						<div class="postbox yikes-easy-mc-postbox">
348
349
350
							<h3><?php _e( 'Segments Overview' , 'yikes-inc-easy-mailchimp-extender' ); ?></h3>
351
							<?php
352
								if( isset( $segments['saved'] ) && count( $segments['saved'] ) >= 1 ) {
353
									$i = 1;
354
									?><ul class="segment-ul"><?php
355
										echo '<li class="segment-group-count">' . sprintf( _n( '%d Segment', '%d Segments', intval( count( $segments['saved'] ) ), 'yikes-inc-easy-mailchimp-extender' ), intval( count( $segments['saved'] ) ) ) . '</li>';
356
									foreach( $segments['saved'] as $segment ) {
357
										echo '<li><span class="dashicons dashicons-arrow-right"></span>' . $segment['name'] . ' <small><a href="#" onclick="jQuery(this).parent().parent().next().slideToggle();jQuery(this).toggleText();return false;" data-alt-text="' . __( 'hide conditions' , 'yikes-inc-easy-mailchimp-extender' ) . '">' . __( "view conditions" , 'yikes-inc-easy-mailchimp-extender' ) . '</a></small></li>';
358
										?><div class="conditionals yikes-easy-mc-hidden"><?php
359
										foreach( $segment['segment_opts']['conditions'] as $condition ) {
360
											echo '<li><small>' . sprintf( __( 'condition #%s : If %s %s %s', 'yikes-inc-easy-mailchimp-extender' ), intval( $i ), $condition['field'],  $condition['op'], $condition['value'] ) . '</small></li>';
361
											$i++;
362
										}
363
										?></div><?php
364
									}
365
									?></ul><?php
366
								} else {
367
									?>
368
									<ul class="segment-ul">
369
										<li><?php echo $no_segments; ?></li>
370
									</ul>
371
									<?php
372
								}
373
							?>
374
							<!--
375
								<a class="edit-segments-button" href="#" onclick="return false;" class="button-primary"><?php _e( 'Edit Segments' , 'yikes-inc-easy-mailchimp-extender' ); ?></a>
376
							-->
377
							<p class="description edit-segment-description"><?php _e( 'To edit this lists segments, head over to' , 'yikes-inc-easy-mailchimp-extender' ); ?> <a href="http://www.MailChimp.com" target="_blank">MailChimp</a></p>
378
379
						</div>
380
381
382
					</div> <!-- .meta-box-sortables -->
383
384
				</div> <!-- #postbox-container-1 .postbox-container -->
385
386
			</div> <!-- #post-body .metabox-holder .columns-2 -->
387
388
			<br class="clear">
389
		</div> <!-- #poststuff -->
390
</div>
391
<!-- JS -->
392
<script type="text/javascript">
393
	 /* Toggle Text - Stats/Shortcode (manage-forms.php)*/
394
	jQuery.fn.toggleText = function() {
395
		var altText = this.data("alt-text");
396
		if (altText) {
397
			this.data("alt-text", this.html());
398
			this.html('<small>'+altText+'</small>');
399
		}
400
	};
401
</script>
402