| 1 |
<?php |
| 2 |
/** |
| 3 |
* class-groups-admin-bitcoin.php |
| 4 |
* |
| 5 |
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com |
| 6 |
* |
| 7 |
* This code is released under the GNU General Public License. |
| 8 |
* See COPYRIGHT.txt and LICENSE.txt. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* This header and all notices must be kept intact. |
| 16 |
* |
| 17 |
* @author itthinx |
| 18 |
* @package groups |
| 19 |
* @since 4.0.0 |
| 20 |
*/ |
| 21 |
|
| 22 |
if ( !defined( 'ABSPATH' ) ) { |
| 23 |
exit; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Bitcoin |
| 28 |
*/ |
| 29 |
class Groups_Admin_Bitcoin { |
| 30 |
|
| 31 |
/** |
| 32 |
* Provide the Bitcoin box markup. |
| 33 |
* |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
public static function get_groups_bitcoin_box( $params = null ) { |
| 37 |
$type = ''; |
| 38 |
$where = ''; |
| 39 |
if ( is_array( $params ) ) { |
| 40 |
if ( isset( $params['type'] ) ) { |
| 41 |
switch ( $params['type'] ) { |
| 42 |
case 'vertical': |
| 43 |
case 'horizontal': |
| 44 |
$type = $params['type']; |
| 45 |
break; |
| 46 |
} |
| 47 |
} |
| 48 |
if ( isset( $params['where'] ) ) { |
| 49 |
switch ( $params['where'] ) { |
| 50 |
case 'options': |
| 51 |
case 'add-ons': |
| 52 |
$where = $params['where']; |
| 53 |
break; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
$bitcoin_address = 'bc1q7klf9ge8gvtl4h4qlh6c73tgk0cdehfv5vcq0g'; |
| 58 |
$bitcoin_box = sprintf( '<div id="groups-bitcoin-box" class="groups-bitcoin-box %s %s">', esc_attr( $type ), esc_attr( $where ) ); |
| 59 |
$bitcoin_box .= '<div class="groups-bitcoin-box-inside">'; |
| 60 |
$bitcoin_box .= '<div class="groups-bitcoin-cta">'; |
| 61 |
$bitcoin_box .= esc_html__( 'Contribute Bitcoin to Groups', 'groups' ); |
| 62 |
$bitcoin_box .= '</div>'; // .groups-bitcoin-cta |
| 63 |
$bitcoin_box .= '<div class="groups-bitcoin-image">'; |
| 64 |
$bitcoin_box .= sprintf( '<img class="groups-bitcoin-address-image" src="%s"/>', esc_url( GROUPS_PLUGIN_URL .'images/groups-bitcoin.png' ) ); |
| 65 |
$bitcoin_box .= '</div>'; // .groups-bitcoin-image |
| 66 |
$bitcoin_box .= '<div class="groups-bitcoin-description">'; |
| 67 |
$bitcoin_box .= sprintf( |
| 68 |
/* translators: HTML */ |
| 69 |
esc_html__( 'Support the developers and contribute Bitcoin to %s', 'groups' ), |
| 70 |
'<span class="groups-bitcoin-address">' . esc_html( $bitcoin_address ) . '</span>' . |
| 71 |
' ' . |
| 72 |
'<span class="dashicons dashicons-admin-page pseudo-copy-icon" style="display:none"></span>' |
| 73 |
); |
| 74 |
$bitcoin_box .= '</div>'; // .groups-bitcoin-description |
| 75 |
$bitcoin_box .= '</div>'; // .groups-bitcoin-box-inside |
| 76 |
$bitcoin_box .= '</div>'; // .groups-bitcoin-box |
| 77 |
$bitcoin_box .= '<script type="text/javascript">'; |
| 78 |
$bitcoin_box .= 'if ( typeof groups_bitcoin_box_address === "undefined" ) {'; |
| 79 |
$bitcoin_box .= 'function groups_bitcoin_box_address( event ) {'; |
| 80 |
$bitcoin_box .= 'if ( navigator.clipboard && window.isSecureContext ) {'; |
| 81 |
$bitcoin_box .= 'try {'; |
| 82 |
$bitcoin_box .= 'navigator.clipboard.writeText("' . esc_html( $bitcoin_address ) .'");'; |
| 83 |
$bitcoin_box .= 'jQuery( event.target ).closest( ".groups-bitcoin-box-inside" ).fadeOut( 100 ).fadeIn( 100 );'; |
| 84 |
$bitcoin_box .= '} catch (error) {'; |
| 85 |
$bitcoin_box .= '}'; |
| 86 |
$bitcoin_box .= '} else if ( document.queryCommandEnabled && document.queryCommandEnabled( "copy" ) ) {'; |
| 87 |
$bitcoin_box .= 'let tmp = document.createElement("textarea");'; |
| 88 |
$bitcoin_box .= sprintf( 'tmp.value="%s";', $bitcoin_address ); |
| 89 |
$bitcoin_box .= 'tmp.setAttribute("style","display:none");'; |
| 90 |
$bitcoin_box .= 'tmp.select();'; |
| 91 |
$bitcoin_box .= 'try {'; |
| 92 |
$bitcoin_box .= 'document.execCommand( "copy" );'; |
| 93 |
$bitcoin_box .= 'jQuery( event.target ).closest( ".groups-bitcoin-box-inside" ).fadeOut( 100 ).fadeIn( 100 );'; |
| 94 |
$bitcoin_box .= '} catch ( error ) {'; |
| 95 |
$bitcoin_box .= '} finally {'; |
| 96 |
$bitcoin_box .= 'tmp.remove();'; |
| 97 |
$bitcoin_box .= '}'; |
| 98 |
$bitcoin_box .= '}'; |
| 99 |
$bitcoin_box .= '}'; |
| 100 |
$bitcoin_box .= 'document.addEventListener( "DOMContentLoaded", function() {'; |
| 101 |
$bitcoin_box .= 'if ( typeof jQuery !== "undefined" ) {'; |
| 102 |
$bitcoin_box .= 'if ( navigator.clipboard && window.isSecureContext || document.queryCommandEnabled && document.queryCommandEnabled( "copy" ) ) {'; |
| 103 |
$bitcoin_box .= 'jQuery( ".groups-bitcoin-box" ).click( groups_bitcoin_box_address );'; |
| 104 |
$bitcoin_box .= 'jQuery( ".groups-bitcoin-box" ).css( "cursor", "pointer" );'; |
| 105 |
$bitcoin_box .= 'jQuery( ".groups-bitcoin-box .pseudo-copy-icon" ).css( "display", "inline" );'; |
| 106 |
$bitcoin_box .= '} else {'; |
| 107 |
$bitcoin_box .= 'jQuery( ".groups-bitcoin-box .dashicons.dashicons-admin-page" ).remove();'; |
| 108 |
$bitcoin_box .= '}'; |
| 109 |
$bitcoin_box .= '}'; |
| 110 |
$bitcoin_box .= '} );'; // DOMContentLoaded |
| 111 |
$bitcoin_box .= '}'; // typeof |
| 112 |
$bitcoin_box .= '</script>'; |
| 113 |
return $bitcoin_box; |
| 114 |
} |
| 115 |
} |
| 116 |
|