PluginProbe
Groups – Memberships and Access Control / 4.7.1
Groups – Memberships and Access Control v4.7.1
4.7.1 4.7.0 4.6.0 4.5.0 4.4.0 4.3.0 trunk 1.0.0-beta-1 1.0.0-beta-2 1.0.0-beta-3 1.0.0-beta-3b 1.0.0-beta-3c 1.0.0-beta-3d 1.1.4 1.1.5 1.10.0 1.10.1 1.10.2 1.10.3 1.11.0 1.11.1 1.11.2 1.11.3 1.12.0 1.13.0 All 131 releases
groups / lib / admin / class-groups-admin-bitcoin.php

class-groups-admin-bitcoin.php in Groups – Memberships and Access Control 4.7.1, at lib/admin/class-groups-admin-bitcoin.php

116 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 '&ensp;' .
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