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 |