1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Editor Blocks. |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2021 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Fundraising; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Blocks |
15
|
|
|
* |
16
|
|
|
* @author Reüel van der Steege |
17
|
|
|
* @since 2.2.6 |
18
|
|
|
* @version 2.1.7 |
19
|
|
|
*/ |
20
|
|
|
class Blocks { |
21
|
|
|
/** |
22
|
|
|
* Add-on plugin. |
23
|
|
|
* |
24
|
|
|
* @var Addon |
25
|
|
|
*/ |
26
|
|
|
private $plugin; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Constructor. |
30
|
|
|
* |
31
|
|
|
* @param Addon $plugin Add-on plugin. |
32
|
|
|
*/ |
33
|
|
|
public function __construct( Addon $plugin ) { |
34
|
|
|
$this->plugin = $plugin; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Setup. |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function setup() { |
43
|
|
|
// Initialize. |
44
|
|
|
add_action( 'init', array( $this, 'register_scripts' ) ); |
45
|
|
|
add_action( 'init', array( $this, 'register_styles' ) ); |
46
|
|
|
add_action( 'init', array( $this, 'register_block_types' ) ); |
47
|
|
|
|
48
|
|
|
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_styles' ) ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Register blocks. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function register_scripts() { |
57
|
|
|
$asset_file = include plugin_dir_path( $this->plugin->file ) . 'js/dist/index.asset.php'; |
58
|
|
|
|
59
|
|
|
wp_register_script( |
60
|
|
|
'pronamic-pay-fundraising-blocks', |
61
|
|
|
plugins_url( 'js/dist/index.js', $this->plugin->file ), |
62
|
|
|
$asset_file['dependencies'], |
63
|
|
|
$asset_file['version'], |
64
|
|
|
false |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
// Script translations. |
68
|
|
|
wp_set_script_translations( 'pronamic-pay-fundraising-blocks', 'pronamic-pay-fundraising', plugin_dir_path( $this->plugin->file ) . 'languages' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Register styles. |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function register_styles() { |
77
|
|
|
$min = SCRIPT_DEBUG ? '' : '.min'; |
78
|
|
|
|
79
|
|
|
wp_register_style( |
80
|
|
|
'pronamic-pay-fundraising', |
81
|
|
|
plugins_url( '/css/fundraising' . $min . '.css', $this->plugin->file ), |
82
|
|
|
array(), |
83
|
|
|
$this->plugin->version |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Register block types. |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
public function register_block_types() { |
93
|
|
|
// Blocks. |
94
|
|
|
$attributes = array( |
95
|
|
|
'raisedLabel' => array( |
96
|
|
|
'type' => 'string', |
97
|
|
|
), |
98
|
|
|
'raisedAmount' => array( |
99
|
|
|
'type' => 'string', |
100
|
|
|
'default' => '0', |
101
|
|
|
), |
102
|
|
|
'targetLabel' => array( |
103
|
|
|
'type' => 'string', |
104
|
|
|
), |
105
|
|
|
'targetAmount' => array( |
106
|
|
|
'type' => 'string', |
107
|
|
|
'default' => '0', |
108
|
|
|
), |
109
|
|
|
'contributionsLabel' => array( |
110
|
|
|
'type' => 'string', |
111
|
|
|
), |
112
|
|
|
'contributionsValue' => array( |
113
|
|
|
'type' => 'string', |
114
|
|
|
'default' => '0', |
115
|
|
|
), |
116
|
|
|
'currencyCode' => array( |
117
|
|
|
'type' => 'string', |
118
|
|
|
), |
119
|
|
|
'currencyDecimals' => array( |
120
|
|
|
'type' => 'string', |
121
|
|
|
'default' => '2', |
122
|
|
|
), |
123
|
|
|
'locale' => array( |
124
|
|
|
'type' => 'string', |
125
|
|
|
'default' => str_replace( '_', '-', \get_locale() ), |
126
|
|
|
), |
127
|
|
|
'color' => array( |
128
|
|
|
'type' => 'string', |
129
|
|
|
'default' => '#f9461c', |
130
|
|
|
), |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
$args = array( |
134
|
|
|
'editor_script' => 'pronamic-pay-fundraising-blocks', |
135
|
|
|
'style' => 'pronamic-pay-fundraising', |
136
|
|
|
'attributes' => $attributes, |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
// Fundraising Progress Circle block. |
140
|
|
|
$args['title'] = __( 'Fundraising Progress Circle', 'pronamic_ideal' ); |
141
|
|
|
|
142
|
|
|
$args['render_callback'] = function( $attributes, $content ) { |
143
|
|
|
ob_start(); |
144
|
|
|
|
145
|
|
|
include __DIR__ . '/../templates/block-fundraising-progress-circle.php'; |
146
|
|
|
|
147
|
|
|
return ob_get_clean(); |
148
|
|
|
}; |
149
|
|
|
|
150
|
|
|
register_block_type( 'pronamic-pay/fundraising-progress-circle', $args ); |
151
|
|
|
|
152
|
|
|
// Fundraising Progress Bar block. |
153
|
|
|
$args['title'] = __( 'Fundraising Progress Bar', 'pronamic_ideal' ); |
154
|
|
|
|
155
|
|
|
$args['render_callback'] = function( $attributes, $content ) { |
156
|
|
|
ob_start(); |
157
|
|
|
|
158
|
|
|
include __DIR__ . '/../templates/block-fundraising-progress-bar.php'; |
159
|
|
|
|
160
|
|
|
return ob_get_clean(); |
161
|
|
|
}; |
162
|
|
|
|
163
|
|
|
register_block_type( 'pronamic-pay/fundraising-progress-bar', $args ); |
164
|
|
|
|
165
|
|
|
// Fundraising Progress Text block. |
166
|
|
|
$args['title'] = __( 'Fundraising Progress', 'pronamic_ideal' ); |
167
|
|
|
|
168
|
|
|
$args['render_callback'] = function( $attributes, $content ) { |
169
|
|
|
ob_start(); |
170
|
|
|
|
171
|
|
|
include __DIR__ . '/../templates/block-fundraising-progress-text.php'; |
172
|
|
|
|
173
|
|
|
return ob_get_clean(); |
174
|
|
|
}; |
175
|
|
|
|
176
|
|
|
register_block_type( 'pronamic-pay/fundraising-progress-text', $args ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Enqueue styles. |
181
|
|
|
* |
182
|
|
|
* @return void |
183
|
|
|
*/ |
184
|
|
|
public function enqueue_styles() { |
185
|
|
|
\wp_enqueue_style( 'pronamic-pay-fundraising' ); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|