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