| 1 |
<?php |
| 2 |
|
| 3 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/admin-functions.php'; |
| 4 |
|
| 5 |
add_action( 'admin_menu', 'flamingo_admin_menu', 8 ); |
| 6 |
|
| 7 |
function flamingo_admin_menu() { |
| 8 |
global $_wp_last_object_menu; |
| 9 |
|
| 10 |
$_wp_last_object_menu++; |
| 11 |
|
| 12 |
add_menu_page( |
| 13 |
__( 'Flamingo Address Book', 'flamingo' ), |
| 14 |
__( 'Flamingo', 'flamingo' ), |
| 15 |
'flamingo_edit_contacts', 'flamingo', |
| 16 |
'flamingo_contact_admin_page', 'dashicons-feedback', |
| 17 |
$_wp_last_object_menu ); |
| 18 |
|
| 19 |
$contact_admin = add_submenu_page( 'flamingo', |
| 20 |
__( 'Flamingo Address Book', 'flamingo' ), |
| 21 |
__( 'Address Book', 'flamingo' ), |
| 22 |
'flamingo_edit_contacts', 'flamingo', |
| 23 |
'flamingo_contact_admin_page' ); |
| 24 |
|
| 25 |
add_action( 'load-' . $contact_admin, 'flamingo_load_contact_admin' ); |
| 26 |
|
| 27 |
$inbound_admin = add_submenu_page( 'flamingo', |
| 28 |
__( 'Flamingo Inbound Messages', 'flamingo' ), |
| 29 |
__( 'Inbound Messages', 'flamingo' ), |
| 30 |
'flamingo_edit_inbound_messages', 'flamingo_inbound', |
| 31 |
'flamingo_inbound_admin_page' ); |
| 32 |
|
| 33 |
add_action( 'load-' . $inbound_admin, 'flamingo_load_inbound_admin' ); |
| 34 |
} |
| 35 |
|
| 36 |
add_filter( 'set-screen-option', 'flamingo_set_screen_options', 10, 3 ); |
| 37 |
|
| 38 |
function flamingo_set_screen_options( $result, $option, $value ) { |
| 39 |
$flamingo_screens = array( |
| 40 |
'toplevel_page_flamingo_per_page', |
| 41 |
'flamingo_page_flamingo_inbound_per_page' ); |
| 42 |
|
| 43 |
if ( in_array( $option, $flamingo_screens ) ) |
| 44 |
$result = $value; |
| 45 |
|
| 46 |
return $result; |
| 47 |
} |
| 48 |
|
| 49 |
add_action( 'admin_enqueue_scripts', 'flamingo_admin_enqueue_scripts' ); |
| 50 |
|
| 51 |
function flamingo_admin_enqueue_scripts( $hook_suffix ) { |
| 52 |
if ( false === strpos( $hook_suffix, 'flamingo' ) ) |
| 53 |
return; |
| 54 |
|
| 55 |
wp_enqueue_style( 'flamingo-admin', |
| 56 |
flamingo_plugin_url( 'admin/style.css' ), |
| 57 |
array(), FLAMINGO_VERSION, 'all' ); |
| 58 |
|
| 59 |
wp_enqueue_script( 'flamingo-admin', |
| 60 |
flamingo_plugin_url( 'admin/script.js' ), |
| 61 |
array( 'postbox' ), FLAMINGO_VERSION, true ); |
| 62 |
|
| 63 |
$current_screen = get_current_screen(); |
| 64 |
|
| 65 |
wp_localize_script( 'flamingo-admin', '_flamingo', array( |
| 66 |
'screenId' => $current_screen->id ) ); |
| 67 |
} |
| 68 |
|
| 69 |
/* Updated Message */ |
| 70 |
|
| 71 |
add_action( 'flamingo_admin_updated_message', 'flamingo_admin_updated_message' ); |
| 72 |
|
| 73 |
function flamingo_admin_updated_message() { |
| 74 |
if ( ! empty( $_REQUEST['message'] ) ) { |
| 75 |
if ( 'contactupdated' == $_REQUEST['message'] ) |
| 76 |
$updated_message = esc_html( __( 'Contact updated.', 'flamingo' ) ); |
| 77 |
elseif ( 'contactdeleted' == $_REQUEST['message'] ) |
| 78 |
$updated_message = esc_html( __( 'Contact deleted.', 'flamingo' ) ); |
| 79 |
elseif ( 'inboundtrashed' == $_REQUEST['message'] ) |
| 80 |
$updated_message = esc_html( __( 'Messages trashed.', 'flamingo' ) ); |
| 81 |
elseif ( 'inbounduntrashed' == $_REQUEST['message'] ) |
| 82 |
$updated_message = esc_html( __( 'Messages restored.', 'flamingo' ) ); |
| 83 |
elseif ( 'inbounddeleted' == $_REQUEST['message'] ) |
| 84 |
$updated_message = esc_html( __( 'Messages deleted.', 'flamingo' ) ); |
| 85 |
elseif ( 'inboundspammed' == $_REQUEST['message'] ) |
| 86 |
$updated_message = esc_html( __( 'Messages got marked as spam.', 'flamingo' ) ); |
| 87 |
elseif ( 'inboundunspammed' == $_REQUEST['message'] ) |
| 88 |
$updated_message = esc_html( __( 'Messages got marked as not spam.', 'flamingo' ) ); |
| 89 |
elseif ( 'outboundupdated' == $_REQUEST['message'] ) |
| 90 |
$updated_message = esc_html( __( 'Messages updated.', 'flamingo' ) ); |
| 91 |
else |
| 92 |
return; |
| 93 |
} else { |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
if ( empty( $updated_message ) ) |
| 98 |
return; |
| 99 |
|
| 100 |
?> |
| 101 |
<div id="message" class="updated"><p><?php echo $updated_message; ?></p></div> |
| 102 |
<?php |
| 103 |
} |
| 104 |
|
| 105 |
/* Contact */ |
| 106 |
|
| 107 |
function flamingo_load_contact_admin() { |
| 108 |
$action = flamingo_current_action(); |
| 109 |
|
| 110 |
$redirect_to = admin_url( 'admin.php?page=flamingo' ); |
| 111 |
|
| 112 |
if ( 'save' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 113 |
$post = new Flamingo_Contact( $_REQUEST['post'] ); |
| 114 |
|
| 115 |
if ( ! empty( $post ) ) { |
| 116 |
if ( ! current_user_can( 'flamingo_edit_contact', $post->id ) ) |
| 117 |
wp_die( __( 'You are not allowed to edit this item.', 'flamingo' ) ); |
| 118 |
|
| 119 |
check_admin_referer( 'flamingo-update-contact_' . $post->id ); |
| 120 |
|
| 121 |
$post->props = (array) $_POST['contact']; |
| 122 |
|
| 123 |
$post->name = trim( $_POST['contact']['name'] ); |
| 124 |
|
| 125 |
$post->tags = ! empty( $_POST['tax_input'][Flamingo_Contact::contact_tag_taxonomy] ) |
| 126 |
? explode( ',', $_POST['tax_input'][Flamingo_Contact::contact_tag_taxonomy] ) |
| 127 |
: array(); |
| 128 |
|
| 129 |
$post->save(); |
| 130 |
|
| 131 |
$redirect_to = add_query_arg( array( |
| 132 |
'action' => 'edit', |
| 133 |
'post' => $post->id, |
| 134 |
'message' => 'contactupdated' ), $redirect_to ); |
| 135 |
} |
| 136 |
|
| 137 |
wp_safe_redirect( $redirect_to ); |
| 138 |
exit(); |
| 139 |
} |
| 140 |
|
| 141 |
if ( 'delete' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 142 |
if ( ! is_array( $_REQUEST['post'] ) ) |
| 143 |
check_admin_referer( 'flamingo-delete-contact_' . $_REQUEST['post'] ); |
| 144 |
else |
| 145 |
check_admin_referer( 'bulk-posts' ); |
| 146 |
|
| 147 |
$deleted = 0; |
| 148 |
|
| 149 |
foreach ( (array) $_REQUEST['post'] as $post ) { |
| 150 |
$post = new Flamingo_Contact( $post ); |
| 151 |
|
| 152 |
if ( empty( $post ) ) |
| 153 |
continue; |
| 154 |
|
| 155 |
if ( ! current_user_can( 'flamingo_delete_contact', $post->id ) ) |
| 156 |
wp_die( __( 'You are not allowed to delete this item.', 'flamingo' ) ); |
| 157 |
|
| 158 |
if ( ! $post->delete() ) |
| 159 |
wp_die( __( 'Error in deleting.', 'flamingo' ) ); |
| 160 |
|
| 161 |
$deleted += 1; |
| 162 |
} |
| 163 |
|
| 164 |
if ( ! empty( $deleted ) ) |
| 165 |
$redirect_to = add_query_arg( array( 'message' => 'contactdeleted' ), $redirect_to ); |
| 166 |
|
| 167 |
wp_safe_redirect( $redirect_to ); |
| 168 |
exit(); |
| 169 |
} |
| 170 |
|
| 171 |
if ( ! empty( $_GET['export'] ) ) { |
| 172 |
check_admin_referer( 'bulk-posts' ); |
| 173 |
|
| 174 |
$sitename = sanitize_key( get_bloginfo( 'name' ) ); |
| 175 |
|
| 176 |
$filename = ( empty( $sitename ) ? '' : $sitename . '-' ) |
| 177 |
. sprintf( 'flamingo-contact-%s.csv', date( 'Y-m-d' ) ); |
| 178 |
|
| 179 |
header( 'Content-Description: File Transfer' ); |
| 180 |
header( "Content-Disposition: attachment; filename=$filename" ); |
| 181 |
header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ) ); |
| 182 |
|
| 183 |
$labels = array( |
| 184 |
__( 'Email', 'flamingo' ), __( 'Full name', 'flamingo' ), |
| 185 |
__( 'First name', 'flamingo' ), __( 'Last name', 'flamingo' ) ); |
| 186 |
|
| 187 |
echo flamingo_csv_row( $labels ); |
| 188 |
|
| 189 |
$args = array( |
| 190 |
'posts_per_page' => -1, |
| 191 |
'orderby' => 'meta_value', |
| 192 |
'order' => 'ASC', |
| 193 |
'meta_key' => '_email' ); |
| 194 |
|
| 195 |
if ( ! empty( $_GET['s'] ) ) |
| 196 |
$args['s'] = $_GET['s']; |
| 197 |
|
| 198 |
if ( ! empty( $_GET['orderby'] ) ) { |
| 199 |
if ( 'email' == $_GET['orderby'] ) |
| 200 |
$args['meta_key'] = '_email'; |
| 201 |
elseif ( 'name' == $_GET['orderby'] ) |
| 202 |
$args['meta_key'] = '_name'; |
| 203 |
} |
| 204 |
|
| 205 |
if ( ! empty( $_GET['order'] ) && 'asc' == strtolower( $_GET['order'] ) ) |
| 206 |
$args['order'] = 'ASC'; |
| 207 |
|
| 208 |
if ( ! empty( $_GET['contact_tag_id'] ) ) |
| 209 |
$args['contact_tag_id'] = explode( ',', $_GET['contact_tag_id'] ); |
| 210 |
|
| 211 |
$items = Flamingo_Contact::find( $args ); |
| 212 |
|
| 213 |
foreach ( $items as $item ) { |
| 214 |
$row = array( |
| 215 |
$item->email, |
| 216 |
$item->get_prop( 'name' ), |
| 217 |
$item->get_prop( 'first_name' ), |
| 218 |
$item->get_prop( 'last_name' ) ); |
| 219 |
|
| 220 |
echo "\r\n" . flamingo_csv_row( $row ); |
| 221 |
} |
| 222 |
|
| 223 |
exit(); |
| 224 |
} |
| 225 |
|
| 226 |
if ( ! empty( $_GET['sendmail'] ) && ! empty( $_REQUEST['contact_tag_id'] ) ) { |
| 227 |
$redirect_to = admin_url( 'admin.php?page=flamingo_outbound' ); |
| 228 |
|
| 229 |
$redirect_to = add_query_arg( array( |
| 230 |
'action' => 'new', |
| 231 |
'contact_tag_id' => absint( $_REQUEST['contact_tag_id'] ) |
| 232 |
), $redirect_to ); |
| 233 |
|
| 234 |
wp_safe_redirect( $redirect_to ); |
| 235 |
exit(); |
| 236 |
} |
| 237 |
|
| 238 |
$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : ''; |
| 239 |
|
| 240 |
if ( Flamingo_Contact::post_type == get_post_type( $post_id ) ) { |
| 241 |
add_meta_box( 'submitdiv', __( 'Save', 'flamingo' ), |
| 242 |
'flamingo_contact_submit_meta_box', null, 'side', 'core' ); |
| 243 |
|
| 244 |
add_meta_box( 'contacttagsdiv', __( 'Tags', 'flamingo' ), |
| 245 |
'flamingo_contact_tags_meta_box', null, 'side', 'core' ); |
| 246 |
|
| 247 |
add_meta_box( 'contactnamediv', __( 'Name', 'flamingo' ), |
| 248 |
'flamingo_contact_name_meta_box', null, 'normal', 'core' ); |
| 249 |
|
| 250 |
} else { |
| 251 |
if ( ! class_exists( 'Flamingo_Contacts_List_Table' ) ) |
| 252 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/class-contacts-list-table.php'; |
| 253 |
|
| 254 |
$current_screen = get_current_screen(); |
| 255 |
|
| 256 |
add_filter( 'manage_' . $current_screen->id . '_columns', |
| 257 |
array( 'Flamingo_Contacts_List_Table', 'define_columns' ) ); |
| 258 |
|
| 259 |
add_screen_option( 'per_page', array( |
| 260 |
'label' => __( 'Contacts', 'flamingo' ), |
| 261 |
'default' => 20 ) ); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
function flamingo_contact_admin_page() { |
| 266 |
$action = flamingo_current_action(); |
| 267 |
$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : ''; |
| 268 |
|
| 269 |
if ( 'edit' == $action && Flamingo_Contact::post_type == get_post_type( $post_id ) ) { |
| 270 |
flamingo_contact_edit_page(); |
| 271 |
return; |
| 272 |
} |
| 273 |
|
| 274 |
$list_table = new Flamingo_Contacts_List_Table(); |
| 275 |
$list_table->prepare_items(); |
| 276 |
|
| 277 |
?> |
| 278 |
<div class="wrap"> |
| 279 |
<?php screen_icon(); ?> |
| 280 |
|
| 281 |
<h1><?php |
| 282 |
echo esc_html( __( 'Flamingo Address Book', 'flamingo' ) ); |
| 283 |
|
| 284 |
if ( ! empty( $_REQUEST['s'] ) ) { |
| 285 |
echo sprintf( '<span class="subtitle">' |
| 286 |
. __( 'Search results for “%s”', 'flamingo' ) |
| 287 |
. '</span>', esc_html( $_REQUEST['s'] ) ); |
| 288 |
} |
| 289 |
?></h1> |
| 290 |
|
| 291 |
<?php do_action( 'flamingo_admin_updated_message' ); ?> |
| 292 |
|
| 293 |
<form method="get" action=""> |
| 294 |
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" /> |
| 295 |
<?php $list_table->search_box( __( 'Search Contacts', 'flamingo' ), 'flamingo-contact' ); ?> |
| 296 |
<?php $list_table->display(); ?> |
| 297 |
</form> |
| 298 |
|
| 299 |
</div> |
| 300 |
<?php |
| 301 |
} |
| 302 |
|
| 303 |
function flamingo_contact_edit_page() { |
| 304 |
$post = new Flamingo_Contact( $_REQUEST['post'] ); |
| 305 |
|
| 306 |
if ( empty( $post ) ) |
| 307 |
return; |
| 308 |
|
| 309 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/meta-boxes.php'; |
| 310 |
|
| 311 |
include FLAMINGO_PLUGIN_DIR . '/admin/edit-contact-form.php'; |
| 312 |
} |
| 313 |
|
| 314 |
/* Inbound Messages */ |
| 315 |
|
| 316 |
function flamingo_load_inbound_admin() { |
| 317 |
$action = flamingo_current_action(); |
| 318 |
|
| 319 |
$redirect_to = admin_url( 'admin.php?page=flamingo_inbound' ); |
| 320 |
|
| 321 |
if ( 'trash' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 322 |
if ( ! is_array( $_REQUEST['post'] ) ) |
| 323 |
check_admin_referer( 'flamingo-trash-inbound-message_' . $_REQUEST['post'] ); |
| 324 |
else |
| 325 |
check_admin_referer( 'bulk-posts' ); |
| 326 |
|
| 327 |
$trashed = 0; |
| 328 |
|
| 329 |
foreach ( (array) $_REQUEST['post'] as $post ) { |
| 330 |
$post = new Flamingo_Inbound_Message( $post ); |
| 331 |
|
| 332 |
if ( empty( $post ) ) |
| 333 |
continue; |
| 334 |
|
| 335 |
if ( ! current_user_can( 'flamingo_delete_inbound_message', $post->id ) ) |
| 336 |
wp_die( __( 'You are not allowed to move this item to the Trash.', 'flamingo' ) ); |
| 337 |
|
| 338 |
if ( ! $post->trash() ) |
| 339 |
wp_die( __( 'Error in moving to Trash.', 'flamingo' ) ); |
| 340 |
|
| 341 |
$trashed += 1; |
| 342 |
} |
| 343 |
|
| 344 |
if ( ! empty( $trashed ) ) |
| 345 |
$redirect_to = add_query_arg( array( 'message' => 'inboundtrashed' ), $redirect_to ); |
| 346 |
|
| 347 |
wp_safe_redirect( $redirect_to ); |
| 348 |
exit(); |
| 349 |
} |
| 350 |
|
| 351 |
if ( 'untrash' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 352 |
if ( ! is_array( $_REQUEST['post'] ) ) |
| 353 |
check_admin_referer( 'flamingo-untrash-inbound-message_' . $_REQUEST['post'] ); |
| 354 |
else |
| 355 |
check_admin_referer( 'bulk-posts' ); |
| 356 |
|
| 357 |
$untrashed = 0; |
| 358 |
|
| 359 |
foreach ( (array) $_REQUEST['post'] as $post ) { |
| 360 |
$post = new Flamingo_Inbound_Message( $post ); |
| 361 |
|
| 362 |
if ( empty( $post ) ) |
| 363 |
continue; |
| 364 |
|
| 365 |
if ( ! current_user_can( 'flamingo_delete_inbound_message', $post->id ) ) |
| 366 |
wp_die( __( 'You are not allowed to restore this item from the Trash.', 'flamingo' ) ); |
| 367 |
|
| 368 |
if ( ! $post->untrash() ) |
| 369 |
wp_die( __( 'Error in restoring from Trash.', 'flamingo' ) ); |
| 370 |
|
| 371 |
$untrashed += 1; |
| 372 |
} |
| 373 |
|
| 374 |
if ( ! empty( $untrashed ) ) |
| 375 |
$redirect_to = add_query_arg( array( 'message' => 'inbounduntrashed' ), $redirect_to ); |
| 376 |
|
| 377 |
wp_safe_redirect( $redirect_to ); |
| 378 |
exit(); |
| 379 |
} |
| 380 |
|
| 381 |
if ( 'delete_all' == $action ) { |
| 382 |
check_admin_referer( 'bulk-posts' ); |
| 383 |
|
| 384 |
$_REQUEST['post'] = flamingo_get_all_ids_in_trash( |
| 385 |
Flamingo_Inbound_Message::post_type ); |
| 386 |
|
| 387 |
$action = 'delete'; |
| 388 |
} |
| 389 |
|
| 390 |
if ( 'delete' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 391 |
if ( ! is_array( $_REQUEST['post'] ) ) |
| 392 |
check_admin_referer( 'flamingo-delete-inbound-message_' . $_REQUEST['post'] ); |
| 393 |
else |
| 394 |
check_admin_referer( 'bulk-posts' ); |
| 395 |
|
| 396 |
$deleted = 0; |
| 397 |
|
| 398 |
foreach ( (array) $_REQUEST['post'] as $post ) { |
| 399 |
$post = new Flamingo_Inbound_Message( $post ); |
| 400 |
|
| 401 |
if ( empty( $post ) ) |
| 402 |
continue; |
| 403 |
|
| 404 |
if ( ! current_user_can( 'flamingo_delete_inbound_message', $post->id ) ) |
| 405 |
wp_die( __( 'You are not allowed to delete this item.', 'flamingo' ) ); |
| 406 |
|
| 407 |
if ( ! $post->delete() ) |
| 408 |
wp_die( __( 'Error in deleting.', 'flamingo' ) ); |
| 409 |
|
| 410 |
$deleted += 1; |
| 411 |
} |
| 412 |
|
| 413 |
if ( ! empty( $deleted ) ) |
| 414 |
$redirect_to = add_query_arg( array( 'message' => 'inbounddeleted' ), $redirect_to ); |
| 415 |
|
| 416 |
wp_safe_redirect( $redirect_to ); |
| 417 |
exit(); |
| 418 |
} |
| 419 |
|
| 420 |
if ( 'spam' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 421 |
if ( ! is_array( $_REQUEST['post'] ) ) |
| 422 |
check_admin_referer( 'flamingo-spam-inbound-message_' . $_REQUEST['post'] ); |
| 423 |
else |
| 424 |
check_admin_referer( 'bulk-posts' ); |
| 425 |
|
| 426 |
$submitted = 0; |
| 427 |
|
| 428 |
foreach ( (array) $_REQUEST['post'] as $post ) { |
| 429 |
$post = new Flamingo_Inbound_Message( $post ); |
| 430 |
|
| 431 |
if ( empty( $post ) ) |
| 432 |
continue; |
| 433 |
|
| 434 |
if ( ! current_user_can( 'flamingo_spam_inbound_message', $post->id ) ) |
| 435 |
wp_die( __( 'You are not allowed to spam this item.', 'flamingo' ) ); |
| 436 |
|
| 437 |
if ( $post->spam() ) |
| 438 |
$submitted += 1; |
| 439 |
} |
| 440 |
|
| 441 |
if ( ! empty( $submitted ) ) |
| 442 |
$redirect_to = add_query_arg( array( 'message' => 'inboundspammed' ), $redirect_to ); |
| 443 |
|
| 444 |
wp_safe_redirect( $redirect_to ); |
| 445 |
exit(); |
| 446 |
} |
| 447 |
|
| 448 |
if ( 'unspam' == $action && ! empty( $_REQUEST['post'] ) ) { |
| 449 |
if ( ! is_array( $_REQUEST['post'] ) ) |
| 450 |
check_admin_referer( 'flamingo-unspam-inbound-message_' . $_REQUEST['post'] ); |
| 451 |
else |
| 452 |
check_admin_referer( 'bulk-posts' ); |
| 453 |
|
| 454 |
$submitted = 0; |
| 455 |
|
| 456 |
foreach ( (array) $_REQUEST['post'] as $post ) { |
| 457 |
$post = new Flamingo_Inbound_Message( $post ); |
| 458 |
|
| 459 |
if ( empty( $post ) ) |
| 460 |
continue; |
| 461 |
|
| 462 |
if ( ! current_user_can( 'flamingo_unspam_inbound_message', $post->id ) ) |
| 463 |
wp_die( __( 'You are not allowed to unspam this item.', 'flamingo' ) ); |
| 464 |
|
| 465 |
if ( $post->unspam() ) |
| 466 |
$submitted += 1; |
| 467 |
} |
| 468 |
|
| 469 |
if ( ! empty( $submitted ) ) |
| 470 |
$redirect_to = add_query_arg( array( 'message' => 'inboundunspammed' ), $redirect_to ); |
| 471 |
|
| 472 |
wp_safe_redirect( $redirect_to ); |
| 473 |
exit(); |
| 474 |
} |
| 475 |
|
| 476 |
if ( ! empty( $_GET['export'] ) ) { |
| 477 |
check_admin_referer( 'bulk-posts' ); |
| 478 |
|
| 479 |
$sitename = sanitize_key( get_bloginfo( 'name' ) ); |
| 480 |
|
| 481 |
$filename = ( empty( $sitename ) ? '' : $sitename . '-' ) |
| 482 |
. sprintf( 'flamingo-inbound-%s.csv', date( 'Y-m-d' ) ); |
| 483 |
|
| 484 |
header( 'Content-Description: File Transfer' ); |
| 485 |
header( "Content-Disposition: attachment; filename=$filename" ); |
| 486 |
header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ) ); |
| 487 |
|
| 488 |
$args = array( |
| 489 |
'posts_per_page' => -1, |
| 490 |
'orderby' => 'date', |
| 491 |
'order' => 'DESC' ); |
| 492 |
|
| 493 |
if ( ! empty( $_REQUEST['s'] ) ) { |
| 494 |
$args['s'] = $_REQUEST['s']; |
| 495 |
} |
| 496 |
|
| 497 |
if ( ! empty( $_REQUEST['orderby'] ) ) { |
| 498 |
if ( 'subject' == $_REQUEST['orderby'] ) { |
| 499 |
$args['meta_key'] = '_subject'; |
| 500 |
$args['orderby'] = 'meta_value'; |
| 501 |
} elseif ( 'from' == $_REQUEST['orderby'] ) { |
| 502 |
$args['meta_key'] = '_from'; |
| 503 |
$args['orderby'] = 'meta_value'; |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
if ( ! empty( $_REQUEST['order'] ) |
| 508 |
&& 'asc' == strtolower( $_REQUEST['order'] ) ) { |
| 509 |
$args['order'] = 'ASC'; |
| 510 |
} |
| 511 |
|
| 512 |
if ( ! empty( $_REQUEST['m'] ) ) { |
| 513 |
$args['m'] = $_REQUEST['m']; |
| 514 |
} |
| 515 |
|
| 516 |
if ( ! empty( $_REQUEST['channel_id'] ) ) { |
| 517 |
$args['channel_id'] = $_REQUEST['channel_id']; |
| 518 |
} |
| 519 |
|
| 520 |
if ( ! empty( $_REQUEST['channel'] ) ) { |
| 521 |
$args['channel'] = $_REQUEST['channel']; |
| 522 |
} |
| 523 |
|
| 524 |
$items = Flamingo_Inbound_Message::find( $args ); |
| 525 |
|
| 526 |
if ( empty( $items ) ) { |
| 527 |
exit(); |
| 528 |
} |
| 529 |
|
| 530 |
$labels = array_keys( $items[0]->fields ); |
| 531 |
$labels[] = __( 'Date', 'flamingo' ); |
| 532 |
echo flamingo_csv_row( $labels ); |
| 533 |
|
| 534 |
foreach ( $items as $item ) { |
| 535 |
$row = array(); |
| 536 |
|
| 537 |
foreach ( $labels as $label ) { |
| 538 |
$col = isset( $item->fields[$label] ) ? $item->fields[$label] : ''; |
| 539 |
|
| 540 |
if ( is_array( $col ) ) { |
| 541 |
$col = flamingo_array_flatten( $col ); |
| 542 |
$col = array_filter( array_map( 'trim', $col ) ); |
| 543 |
$col = implode( ', ', $col ); |
| 544 |
} |
| 545 |
|
| 546 |
$row[] = $col; |
| 547 |
} |
| 548 |
|
| 549 |
$row[] = get_post_time( 'c', true, $item->id ); |
| 550 |
|
| 551 |
echo "\r\n" . flamingo_csv_row( $row ); |
| 552 |
} |
| 553 |
|
| 554 |
exit(); |
| 555 |
} |
| 556 |
|
| 557 |
$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : ''; |
| 558 |
|
| 559 |
if ( Flamingo_Inbound_Message::post_type == get_post_type( $post_id ) ) { |
| 560 |
add_meta_box( 'submitdiv', __( 'Save', 'flamingo' ), |
| 561 |
'flamingo_inbound_submit_meta_box', null, 'side', 'core' ); |
| 562 |
|
| 563 |
add_meta_box( 'inboundfieldsdiv', __( 'Fields', 'flamingo' ), |
| 564 |
'flamingo_inbound_fields_meta_box', null, 'normal', 'core' ); |
| 565 |
|
| 566 |
add_meta_box( 'inboundmetadiv', __( 'Meta', 'flamingo' ), |
| 567 |
'flamingo_inbound_meta_meta_box', null, 'normal', 'core' ); |
| 568 |
|
| 569 |
} else { |
| 570 |
if ( ! class_exists( 'Flamingo_Inbound_Messages_List_Table' ) ) |
| 571 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/class-inbound-messages-list-table.php'; |
| 572 |
|
| 573 |
$current_screen = get_current_screen(); |
| 574 |
|
| 575 |
add_filter( 'manage_' . $current_screen->id . '_columns', |
| 576 |
array( 'Flamingo_Inbound_Messages_List_Table', 'define_columns' ) ); |
| 577 |
|
| 578 |
add_screen_option( 'per_page', array( |
| 579 |
'label' => __( 'Messages', 'flamingo' ), |
| 580 |
'default' => 20 ) ); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
function flamingo_inbound_admin_page() { |
| 585 |
$action = flamingo_current_action(); |
| 586 |
$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : ''; |
| 587 |
|
| 588 |
if ( 'edit' == $action && Flamingo_Inbound_Message::post_type == get_post_type( $post_id ) ) { |
| 589 |
flamingo_inbound_edit_page(); |
| 590 |
return; |
| 591 |
} |
| 592 |
|
| 593 |
$list_table = new Flamingo_Inbound_Messages_List_Table(); |
| 594 |
$list_table->prepare_items(); |
| 595 |
|
| 596 |
?> |
| 597 |
<div class="wrap"> |
| 598 |
<?php screen_icon(); ?> |
| 599 |
|
| 600 |
<h1><?php |
| 601 |
echo esc_html( __( 'Inbound Messages', 'flamingo' ) ); |
| 602 |
|
| 603 |
if ( ! empty( $_REQUEST['s'] ) ) { |
| 604 |
echo sprintf( '<span class="subtitle">' |
| 605 |
. __( 'Search results for “%s”', 'flamingo' ) |
| 606 |
. '</span>', esc_html( $_REQUEST['s'] ) ); |
| 607 |
} |
| 608 |
?></h1> |
| 609 |
|
| 610 |
<?php do_action( 'flamingo_admin_updated_message' ); ?> |
| 611 |
|
| 612 |
<?php $list_table->views(); ?> |
| 613 |
|
| 614 |
<form method="get" action=""> |
| 615 |
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" /> |
| 616 |
<?php $list_table->search_box( __( 'Search Messages', 'flamingo' ), 'flamingo-inbound' ); ?> |
| 617 |
<?php $list_table->display(); ?> |
| 618 |
</form> |
| 619 |
|
| 620 |
</div> |
| 621 |
<?php |
| 622 |
} |
| 623 |
|
| 624 |
function flamingo_inbound_edit_page() { |
| 625 |
$post = new Flamingo_Inbound_Message( $_REQUEST['post'] ); |
| 626 |
|
| 627 |
if ( empty( $post ) ) |
| 628 |
return; |
| 629 |
|
| 630 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/meta-boxes.php'; |
| 631 |
|
| 632 |
include FLAMINGO_PLUGIN_DIR . '/admin/edit-inbound-form.php'; |
| 633 |
|
| 634 |
} |
| 635 |
|
| 636 |
/* Outbound Messages */ |
| 637 |
|
| 638 |
function flamingo_load_outbound_admin() { |
| 639 |
$action = flamingo_current_action(); |
| 640 |
|
| 641 |
$redirect_to = admin_url( 'admin.php?page=flamingo_outbound' ); |
| 642 |
|
| 643 |
$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : ''; |
| 644 |
|
| 645 |
if ( 'save' == $action ) { |
| 646 |
if ( $post_id ) { |
| 647 |
check_admin_referer( 'flamingo-update-outbound_' . $post_id ); |
| 648 |
} else { |
| 649 |
check_admin_referer( 'flamingo-add-outbound' ); |
| 650 |
} |
| 651 |
|
| 652 |
if ( ! empty( $_REQUEST['send'] ) ) { |
| 653 |
// send mail |
| 654 |
} |
| 655 |
|
| 656 |
if ( $post_id ) { |
| 657 |
if ( ! current_user_can( 'flamingo_edit_outbound_message', $post_id ) ) { |
| 658 |
wp_die( __( 'You are not allowed to edit this item.', 'flamingo' ) ); |
| 659 |
} |
| 660 |
|
| 661 |
// $post = new Flamingo_Outbound_Message( $post_id ); |
| 662 |
} else { |
| 663 |
// $post = Flamingo_Outbound_Message::add(); |
| 664 |
} |
| 665 |
|
| 666 |
//$post->save(); |
| 667 |
|
| 668 |
$redirect_to = add_query_arg( array( |
| 669 |
'action' => 'edit', |
| 670 |
//'post' => $post->id, |
| 671 |
'message' => 'outboundupdated' ), $redirect_to ); |
| 672 |
|
| 673 |
wp_safe_redirect( $redirect_to ); |
| 674 |
exit(); |
| 675 |
} |
| 676 |
|
| 677 |
if ( 'new' == $action ) { |
| 678 |
add_meta_box( 'submitdiv', __( 'Send', 'flamingo' ), |
| 679 |
'flamingo_outbound_submit_meta_box', null, 'side', 'core' ); |
| 680 |
|
| 681 |
} else { |
| 682 |
if ( ! class_exists( 'Flamingo_Outbound_Messages_List_Table' ) ) |
| 683 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/class-outbound-messages-list-table.php'; |
| 684 |
|
| 685 |
$current_screen = get_current_screen(); |
| 686 |
|
| 687 |
add_filter( 'manage_' . $current_screen->id . '_columns', |
| 688 |
array( 'Flamingo_Outbound_Messages_List_Table', 'define_columns' ) ); |
| 689 |
|
| 690 |
add_screen_option( 'per_page', array( |
| 691 |
'label' => __( 'Messages', 'flamingo' ), |
| 692 |
'default' => 20 ) ); |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
function flamingo_outbound_admin_page() { |
| 697 |
$action = flamingo_current_action(); |
| 698 |
$post_id = ! empty( $_REQUEST['post'] ) ? $_REQUEST['post'] : ''; |
| 699 |
|
| 700 |
if ( 'new' == $action ) { |
| 701 |
flamingo_outbound_edit_page(); |
| 702 |
return; |
| 703 |
} |
| 704 |
|
| 705 |
$list_table = new Flamingo_Outbound_Messages_List_Table(); |
| 706 |
$list_table->prepare_items(); |
| 707 |
|
| 708 |
?> |
| 709 |
<div class="wrap"> |
| 710 |
<?php screen_icon(); ?> |
| 711 |
|
| 712 |
<h1><?php |
| 713 |
echo esc_html( __( 'Outbound Messages', 'flamingo' ) ); |
| 714 |
|
| 715 |
if ( ! empty( $_REQUEST['s'] ) ) { |
| 716 |
echo sprintf( '<span class="subtitle">' |
| 717 |
. __( 'Search results for “%s”', 'flamingo' ) |
| 718 |
. '</span>', esc_html( $_REQUEST['s'] ) ); |
| 719 |
} |
| 720 |
?></h1> |
| 721 |
|
| 722 |
<?php do_action( 'flamingo_admin_updated_message' ); ?> |
| 723 |
|
| 724 |
<?php $list_table->views(); ?> |
| 725 |
|
| 726 |
<form method="get" action=""> |
| 727 |
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" /> |
| 728 |
<?php $list_table->search_box( __( 'Search Messages', 'flamingo' ), 'flamingo-outbound' ); ?> |
| 729 |
<?php $list_table->display(); ?> |
| 730 |
</form> |
| 731 |
|
| 732 |
</div> |
| 733 |
<?php |
| 734 |
} |
| 735 |
|
| 736 |
function flamingo_outbound_edit_page() { |
| 737 |
$action = flamingo_current_action(); |
| 738 |
$post = null; |
| 739 |
|
| 740 |
if ( 'edit' == $action ) { |
| 741 |
$post = new Flamingo_Outbound_Message( $_REQUEST['post'] ); |
| 742 |
|
| 743 |
if ( empty( $post ) ) |
| 744 |
return; |
| 745 |
} else { // maybe 'new' == $action |
| 746 |
if ( ! empty( $_REQUEST['contact_tag_id'] ) ) { |
| 747 |
$tag_id = explode( ',', $_REQUEST['contact_tag_id'] ); |
| 748 |
|
| 749 |
$contact_tag = get_term( $tag_id[0], |
| 750 |
Flamingo_Contact::contact_tag_taxonomy ); |
| 751 |
|
| 752 |
if ( empty( $contact_tag ) || is_wp_error( $contact_tag ) ) |
| 753 |
$contact_tag = null; |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/meta-boxes.php'; |
| 758 |
include FLAMINGO_PLUGIN_DIR . '/admin/edit-outbound-form.php'; |
| 759 |
} |
| 760 |
|