-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrypto-qr-code-wp.php
187 lines (162 loc) · 5.34 KB
/
crypto-qr-code-wp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/*
Plugin Name: Crypto QR Code WP
Plugin URI: https://www.dopethemes.com/downloads/crypto-qr-code-wp/
Description: Add cryptocurrencies QR code donate with tooltip.
Author: DopeThemes
Author URI: https://www.dopethemes.com/
Text Domain: crypto-qr-code-wp
Version: 1.0.2
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Domain Path: /lang
*/
/*
Copyright DopeThemes
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
if( ! class_exists( 'crypto_qr_code_wp' ) ) :
class crypto_qr_code_wp {
/*
* __construct
*
* A dummy constructor to ensure Crypto QR Code WP is only initialized once.
*
* @type function
* @date 03/24/19
* @since 1.0.0
*
* @param N/A
* @return N/A
*/
public function __construct() {
// Do nothing here.
}
/*
* initialize
*
* The real constructor to initialize Crypto QR Code WP.
*
* @type function
* @date 03/24/19
* @since 1.0.0
*
* @param N/A
* @return N/A
*/
public function initialize() {
// Parameters.
$this->settings = array(
'name' => esc_html__( 'Crypto QR Code WP', 'crypto-qr-code-wp' ),
'version' => '1.0.2',
'basename' => plugin_basename( __FILE__ ),
'path' => plugin_dir_path( __FILE__ ),
'dir' => plugin_dir_url( __FILE__ )
);
// Global Defines.
define( 'CRYPTO_QR_CODE_WP_UPLOAD', trailingslashit( WP_CONTENT_DIR ) . 'uploads/' );
define( 'CRYPTO_QR_CODE_WP_IMG_DIR', trailingslashit( WP_CONTENT_DIR ) . 'uploads/crypto-qr-codes/' );
define( 'CRYPTO_QR_CODE_WP_URL', trailingslashit( WP_CONTENT_URL ) );
// Resources.
add_action( 'init', array( $this, 'register_assets' ) );
add_action( 'admin_init', array( $this, 'create_file_resources' ) );
// Libraries.
include( 'includes/helpers.php' );
include( 'includes/shortcode.php' );
include( 'includes/widgets.php' );
// Vendor.
include( 'includes/vendor/phpqrcode/qrlib.php' );
}
/*
* register_assets
*
* @type function
* @date 03/26/19
* @since 1.0.0
*/
function register_assets() {
wp_register_script( 'crypto-qr-code-wp', plugin_dir_url( __FILE__ ) . 'assets/js/script.js', array( 'jquery' ), $this->settings['version'] );
wp_register_style( 'crypto-qr-code-wp', plugin_dir_url( __FILE__ ) . 'assets/css/style.css', array(), $this->settings['version'] );
// Call assets.
wp_enqueue_script( 'crypto-qr-code-wp' );
wp_enqueue_style( 'crypto-qr-code-wp' );
}
/*
* create_file_resources
*
* @type function
* @date 03/26/19
* @since 1.0.1
*/
function create_file_resources() {
// Check upload folder existence.
if( ! is_dir( CRYPTO_QR_CODE_WP_IMG_DIR ) && is_writable( CRYPTO_QR_CODE_WP_UPLOAD ) && current_user_can( 'manage_options' ) ) {
mkdir( CRYPTO_QR_CODE_WP_IMG_DIR , 0755 );
}
// HTAccess rules and secure folder.
$htaccess_file = CRYPTO_QR_CODE_WP_IMG_DIR . '.htaccess';
if( ( ! file_exists( $htaccess_file ) && is_writable( CRYPTO_QR_CODE_WP_UPLOAD ) ) && current_user_can( 'manage_options' ) ) {
// Set htaccess rules.
$rules = NULL;
settype( $rules, 'string' );
$rules = "Options -Indexes\n";
$rules .= "deny from all\n";
$rules .= "<FilesMatch '\.(svg)$'>\n";
$rules .= "Order Allow,Deny\n";
$rules .= "Allow from all\n";
$rules .= "</FilesMatch>";
$fp = fopen( $htaccess_file, "w" );
if ( ! $fp ) {
return false;
}
// File lock security.
flock( $fp, LOCK_EX );
// Start writing data.
fseek( $fp, 0 );
$data_bytes = fwrite( $fp, $rules );
if ( $data_bytes ) {
ftruncate( $fp, ftell( $fp ) );
}
fflush( $fp );
flock( $fp, LOCK_UN );
fclose( $fp );
}
}
}
/*
* crypto_qr_code_wp
*
* The main function responsible for returning the one true crypto_qr_code_wp Instance to functions everywhere.
* Use this function like you would a global variable, except without needing to declare the global.
*
* Example: <?php $crypto_qr_code_wp = crypto_qr_code_wp(); ?>
*
* @type function
* @date 03/24/19
* @since 1.0.0
*
* @param N/A
* @return (object)
*/
function crypto_qr_code_wp() {
global $crypto_qr_code_wp;
if( ! isset($crypto_qr_code_wp) ) {
$crypto_qr_code_wp = new crypto_qr_code_wp();
$crypto_qr_code_wp->initialize();
}
return $crypto_qr_code_wp;
}
// initialize.
crypto_qr_code_wp();
endif; // class_exists check.