PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.14.6
GiveWP – Donation Plugin and Fundraising Platform v4.14.6
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / ThirdPartySupport / Elementor / Widgets / V1 / GiveTotalsWidget.php
give / src / ThirdPartySupport / Elementor / Widgets / V1 Last commit date
resources 10 months ago DonationHistoryWidget.php 10 months ago DonationReceiptWidget.php 10 months ago GiveDonorWallWidget.php 10 months ago GiveFormGridWidget.php 9 months ago GiveFormWidget.php 10 months ago GiveGoalWidget.php 10 months ago GiveLoginWidget.php 10 months ago GiveMultiFormGoalWidget.php 10 months ago GiveProfileEditorWidget.php 10 months ago GiveRegisterWidget.php 10 months ago GiveSubscriptionsWidget.php 10 months ago GiveTotalsWidget.php 10 months ago
GiveTotalsWidget.php
281 lines
1 <?php
2
3 namespace Give\ThirdPartySupport\Elementor\Widgets\V1;
4
5 use Give\Framework\Database\DB;
6 use Elementor\Widget_Base;
7
8 /**
9 * Elementor Give Totals Widget.
10 *
11 * Elementor widget that inserts the GiveWP [give_totals] shortcode to output a form total with options.
12 *
13 * @since 4.7.0 migrated from givewp-elementor-widgets
14 */
15
16 class GiveTotalsWidget extends Widget_Base
17 {
18 /**
19 * Get widget name.
20 *
21 * Retrieve Give Totals widget name.
22 *
23 * @since 4.7.0 migrated from givewp-elementor-widgets
24 * @access public
25 *
26 * @return string Widget name.
27 */
28 public function get_name()
29 {
30 return 'Give Totals';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve Give Totals widget title.
37 *
38 * @since 4.7.0 migrated from givewp-elementor-widgets
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title()
44 {
45 return __('Give Totals (Legacy)', 'give');
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve Give Totals widget icon.
52 *
53 * @since 4.7.0 migrated from givewp-elementor-widgets
54 * @access public
55 *
56 * @return string Widget icon.
57 */
58 public function get_icon()
59 {
60 return 'give-icon';
61 }
62
63 /**
64 * Get widget categories.
65 *
66 * Retrieve the list of categories the Give Totals widget belongs to.
67 *
68 * @since 4.7.0 migrated from givewp-elementor-widgets
69 * @access public
70 *
71 * @return array Widget categories.
72 */
73 public function get_categories()
74 {
75 return ['givewp-category-legacy'];
76 }
77
78 /**
79 * Widget inner wrapper.
80 *
81 * Use optimized DOM structure, without the inner wrapper.
82 *
83 * @since 4.7.0 migrated from givewp-elementor-widgets
84 * @access public
85 */
86 public function has_widget_inner_wrapper(): bool
87 {
88 return false;
89 }
90
91 /**
92 * Register Give Totals widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 4.7.0 migrated from givewp-elementor-widgets
97 * @access protected
98 */
99 protected function register_controls()
100 {
101 $this->start_controls_section(
102 'give_totals_settings',
103 [
104 'label' => __('GiveWP Totals Widget', 'give'),
105 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
106 ]
107 );
108
109 $this->add_control(
110 'forms',
111 [
112 'label' => __('Forms', 'give'),
113 'type' => \Elementor\Controls_Manager::SELECT2,
114 'description' => __('Choose the forms you want to combine in this total.', 'give'),
115 'separator' => 'after',
116 'options' => $this->getDonationForms(),
117 'multiple' => true,
118 'default' => '',
119 ]
120 );
121
122 $this->add_control(
123 'total_goal',
124 [
125 'label' => __('Goal Amount', 'give'),
126 'type' => \Elementor\Controls_Manager::TEXT,
127 'description' => __('Designate a goal amount.', 'give'),
128 'default' => '10000'
129 ]
130 );
131
132 $this->add_control(
133 'message',
134 [
135 'label' => __('Message:', 'give'),
136 'type' => \Elementor\Controls_Manager::TEXTAREA,
137 'description' => __('(Optional) The total goal you want to reflect in your message.', 'give'),
138 'default' => __('Hey! We\'ve raised {total} of the {total_goal} we are trying to raise for this campaign!', 'give'),
139 ]
140 );
141
142 $this->add_control(
143 'link',
144 [
145 'label' => __('Link', 'give'),
146 'type' => \Elementor\Controls_Manager::URL,
147 'description' => __('The url of where you want to link donors to encourage them to donate toward the goal.', 'give'),
148 'show_external' => false,
149 'default' => [
150 'url' => 'https://example.org',
151 'is_external' => false,
152 'nofollow' => false,
153 ],
154 ]
155 );
156
157 $this->add_control(
158 'link_text',
159 [
160 'label' => __('Link Text', 'give'),
161 'type' => \Elementor\Controls_Manager::TEXTAREA,
162 'description' => __('The text you want to hyperlink with your link.', 'give'),
163 'default' => __('Donate Now', 'give'),
164 ]
165 );
166
167 $this->add_control(
168 'show_progress',
169 [
170 'label' => __('Show Progress', 'give'),
171 'type' => \Elementor\Controls_Manager::SWITCHER,
172 'description' => __('Show or hide a the progress bar.', 'give'),
173 'label_on' => __('Show', 'give'),
174 'label_off' => __('Hide', 'give'),
175 'default' => 'yes'
176 ]
177 );
178
179 $this->add_control(
180 'cats',
181 [
182 'label' => __('Categories', 'give'),
183 'type' => \Elementor\Controls_Manager::TEXT,
184 'description' => __('Comma separated list of GiveWP category IDs you want to combine into this total.', 'give'),
185 ]
186 );
187
188 $this->add_control(
189 'tags',
190 [
191 'label' => __('Tags', 'give'),
192 'type' => \Elementor\Controls_Manager::TEXT,
193 'description' => __('Comma separated list of GiveWP tag IDs you want to combine into this total.', 'give'),
194 ]
195 );
196
197 $this->add_control(
198 'give_totals_info',
199 [
200 'label' => '',
201 'type' => \Elementor\Controls_Manager::RAW_HTML,
202 'content_classes' => 'give-info',
203 'raw' => '
204 <div class="give">
205 <p class="info-head">
206 ' . __('GIVEWP TOTALS WIDGET', 'give') . '</p>
207 <p class="info-message">' . __('This is the GiveWP Totals widget. Use this to display a total of one or many forms.', 'give') . '</p>
208 <p class="give-docs-links">
209 <a href="https://givewp.com/documentation/core/shortcodes/give_totals/?utm_source=plugin_settings&utm_medium=referral&utm_campaign=Free_Addons&utm_content=givelementor" rel="noopener noreferrer" target="_blank"><i class="fa fa-book" aria-hidden="true"></i>' . __('Visit the GiveWP Docs for more info on the GiveWP Totals.', 'give') . '</a>
210 </p>
211 </div>'
212 ]
213 );
214
215 $this->end_controls_section();
216 }
217
218 /**
219 * Render the [give_totals] output on the frontend.
220 *
221 * Written in PHP and used to generate the final HTML.
222 *
223 * @since 4.7.0 migrated from givewp-elementor-widgets
224 * @access protected
225 */
226 protected function render()
227 {
228 $settings = $this->get_settings_for_display();
229
230 $goal = esc_html($settings['total_goal']);
231 $message = esc_html($settings['message']);
232 $link = esc_url($settings['link']['url']);
233 $linkText = esc_html($settings['link_text']);
234 $showProgress = ('yes' === $settings['show_progress'] ? 'progress_bar="true"' : 'progress_bar="false"');
235 $cats = esc_html($settings['cats']);
236 $tags = esc_html($settings['tags']);
237
238 $html = do_shortcode('
239 [give_totals
240 ids="' . implode(',', $settings['forms']) . '"
241 total_goal="' . $goal . '"
242 message="' . $message . '"
243 link_text="' . $linkText . '"
244 link="' . $link . '" '
245 . $showProgress . '
246 cats="' . $cats . '"
247 tags="' . $tags . '"]'
248 );
249
250 echo '<div class="givewp-elementor-widget give-totals-shortcode-wrap">';
251
252 echo $html;
253
254 echo '</div>';
255 }
256
257 /**
258 * Get donation forms
259 *
260 * @since 4.7.0 migrated from givewp-elementor-widgets
261 *
262 * @return array
263 */
264 private function getDonationForms()
265 {
266 $options = [];
267
268 $forms = DB::table('posts')
269 ->select('ID', 'post_title')
270 ->where('post_type', 'give_forms')
271 ->where('post_status', 'publish')
272 ->getAll();
273
274 foreach ($forms as $form) {
275 $options[$form->ID] = $form->post_title;
276 }
277
278 return $options;
279 }
280 }
281