| 1 |
<?php |
| 2 |
|
| 3 |
class ContactListAdminInlineScripts { |
| 4 |
public static function inline_scripts( $context = '' ) { |
| 5 |
$current_screen = get_current_screen(); |
| 6 |
$current_screen_id = ''; |
| 7 |
if ( isset( $current_screen->id ) ) { |
| 8 |
$current_screen_id = $current_screen->id; |
| 9 |
} |
| 10 |
$js = ''; |
| 11 |
if ( $context == 'mail-log' ) { |
| 12 |
$js .= "jQuery( document ).ready( function(\$) {\n\n \$('.contact-list-empty-mail-log-form').submit(function() {\n\n return confirm('" . esc_js( __( 'Are you sure that you want to empty the mail log?', 'contact-list' ) ) . ' ' . esc_js( __( 'This action is irreversible.', 'contact-list' ) ) . "');\n\n });\n\n });"; |
| 13 |
} elseif ( $context == 'search-log' ) { |
| 14 |
$js .= "jQuery( document ).ready( function(\$) {\n\n \$('.contact-list-empty-search-log-form').submit(function() {\n\n return confirm('" . esc_js( __( 'Are you sure that you want to empty the search log?', 'contact-list' ) ) . ' ' . esc_js( __( 'This action is irreversible.', 'contact-list' ) ) . "');\n\n });\n\n });"; |
| 15 |
} elseif ( $context == 'import-log' ) { |
| 16 |
$js .= "jQuery( document ).ready( function(\$) {\n\n \$('.contact-list-empty-import-log-form').submit(function() {\n\n return confirm('" . esc_js( __( 'Are you sure that you want to empty the import log?', 'contact-list' ) ) . ' ' . esc_js( __( 'This action is irreversible.', 'contact-list' ) ) . "');\n\n });\n\n });"; |
| 17 |
} elseif ( $current_screen_id === 'edit-contact' || $current_screen_id === 'edit-contact-group' ) { |
| 18 |
$is_premium = 0; |
| 19 |
$js .= "jQuery( document ).ready( function(\$) {"; |
| 20 |
if ( !$is_premium ) { |
| 21 |
if ( $current_screen_id === 'edit-contact' ) { |
| 22 |
$url = 'https://wordpress.org/support/plugin/contact-list/'; |
| 23 |
$support_html = sprintf( wp_kses( |
| 24 |
/* translators: %s: link to the support forum */ |
| 25 |
__( 'If you have any questions in mind, please contact the author at <a href="%s" target="_blank">the support forum</a>. The forum is actively monitored and any kind of feedback is welcome.', 'contact-list' ), |
| 26 |
array( |
| 27 |
'a' => array( |
| 28 |
'href' => array(), |
| 29 |
'target' => array(), |
| 30 |
), |
| 31 |
) |
| 32 |
), esc_url( $url ) ); |
| 33 |
$js .= "\n \$('.post-type-contact .page-title-action').after(function() {\n\n return '<div class=\"contact-list-admin-support-box\">" . $support_html . "</div>';\n\n });\n "; |
| 34 |
} |
| 35 |
$js .= "\n \$('.contact-list-copy-paid-only').tipso({\n content: '" . esc_js( __( 'This feature is available in the paid plans.', 'contact-list' ) ) . "',\n width: 280,\n background: '#2271b1',\n });\n "; |
| 36 |
$js .= "\n \$('.contact-list-request-update').tipso({\n content: '" . esc_js( __( 'This feature is available in the paid plans.', 'contact-list' ) ) . "',\n width: 280,\n background: '#2271b1',\n });\n "; |
| 37 |
$js .= "\n \$('.contact-list-request-update').on('click', function(e) {\n e.preventDefault();\n \$(this).prop( 'disabled', true );\n });\n "; |
| 38 |
} |
| 39 |
$js .= "});"; |
| 40 |
} |
| 41 |
return $js; |
| 42 |
} |
| 43 |
|
| 44 |
public static function box_inline_scripts( $context = '' ) { |
| 45 |
$current_screen = get_current_screen(); |
| 46 |
$current_screen_id = ''; |
| 47 |
if ( isset( $current_screen->id ) ) { |
| 48 |
$current_screen_id = $current_screen->id; |
| 49 |
} |
| 50 |
$js = ''; |
| 51 |
$is_premium = 0; |
| 52 |
$admin_pages = ContactListAdminToolbar::get_admin_pages(); |
| 53 |
if ( !$is_premium && in_array( $current_screen_id, $admin_pages ) ) { |
| 54 |
if ( $current_screen_id == 'settings_page_contact-list' ) { |
| 55 |
$js = "\n jQuery( document ).ready( function(\$) {\n \$( '.contact-list-admin-pro-features' ).appendTo( '.contact-list-admin-page-content-container' ).fadeIn(2000);\n });\n "; |
| 56 |
} else { |
| 57 |
$js = "\n jQuery( document ).ready( function(\$) {\n \$( '.contact-list-admin-pro-features' ).appendTo( '#wpbody-content .wrap' ).fadeIn(2000);\n });\n "; |
| 58 |
} |
| 59 |
} |
| 60 |
return $js; |
| 61 |
} |
| 62 |
|
| 63 |
public static function contact_edit_scripts() { |
| 64 |
$js = ''; |
| 65 |
$js .= "jQuery( document ).ready( function(\$) {\n \$('#post').submit(function() {\n if (\$('#_cl_last_name').val().length == 0) {\n alert('" . esc_js( __( 'Please insert at least last name first.', 'contact-list' ) ) . "');\n return false;\n }\n });\n });"; |
| 66 |
return $js; |
| 67 |
} |
| 68 |
|
| 69 |
public static function help_support_scripts() { |
| 70 |
$js = ''; |
| 71 |
$js .= "jQuery( document ).ready( function(\$) {\n \$('.contact-list-toggle-debug-info').on('click', function() {\n if (\$('.contact-list-debug-info-container').is(':hidden')) {\n \$('.contact-list-debug-info-container').show();\n \$(this).text('" . esc_js( __( 'Close', 'contact-list' ) ) . "');\n } else {\n \$('.contact-list-debug-info-container').hide();\n \$(this).text('" . esc_js( __( 'Open', 'contact-list' ) ) . "');\n }\n });\n });"; |
| 72 |
return $js; |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|