Embedpress_Calendar.php
3 years ago
Embedpress_Document.php
2 years ago
Embedpress_Elementor.php
2 years ago
Embedpress_Pdf.php
2 years ago
Embedpress_Calendar.php
358 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Elementor\Widgets; |
| 4 | |
| 5 | |
| 6 | use \Elementor\Controls_Manager as Controls_Manager; |
| 7 | use \Elementor\Modules\DynamicTags\Module as TagsModule; |
| 8 | use \Elementor\Widget_Base as Widget_Base; |
| 9 | use \Elementor\Plugin; |
| 10 | use EmbedPress\Includes\Traits\Branding; |
| 11 | use Embedpress_Google_Helper; |
| 12 | use EmbedPress\Includes\Classes\Helper; |
| 13 | |
| 14 | ( defined( 'ABSPATH' ) ) or die( "No direct script access allowed." ); |
| 15 | |
| 16 | class Embedpress_Calendar extends Widget_Base |
| 17 | { |
| 18 | use Branding; |
| 19 | protected $pro_class = ''; |
| 20 | protected $pro_text = ''; |
| 21 | public function __construct($data = [], $args = null) { |
| 22 | parent::__construct($data, $args); |
| 23 | |
| 24 | wp_register_style('fullcalendar', EPGC_ASSET_URL . 'lib/fullcalendar4/core/main.min.css', null, EMBEDPRESS_VERSION); |
| 25 | wp_register_style('fullcalendar_daygrid', EPGC_ASSET_URL . 'lib/fullcalendar4/daygrid/main.min.css', ['fullcalendar'], EMBEDPRESS_VERSION); |
| 26 | wp_register_style('fullcalendar_timegrid', EPGC_ASSET_URL . 'lib/fullcalendar4/timegrid/main.min.css', ['fullcalendar_daygrid'], EMBEDPRESS_VERSION); |
| 27 | wp_register_style('fullcalendar_list', EPGC_ASSET_URL . 'lib/fullcalendar4/list/main.min.css', ['fullcalendar'], EMBEDPRESS_VERSION); |
| 28 | wp_register_style('epgc', EPGC_ASSET_URL . 'css/epgc.css', ['fullcalendar_timegrid'], EMBEDPRESS_VERSION); |
| 29 | wp_register_style('tippy_light', EPGC_ASSET_URL . 'lib/tippy/light-border.css', null, EMBEDPRESS_VERSION); |
| 30 | |
| 31 | //wp_enqueue_style( 'fullcalendar'); |
| 32 | //wp_enqueue_style( 'fullcalendar_daygrid'); |
| 33 | //wp_enqueue_style( 'fullcalendar_timegrid'); |
| 34 | //wp_enqueue_style( 'fullcalendar_list'); |
| 35 | //wp_enqueue_style( 'epgc'); |
| 36 | //wp_enqueue_style( 'tippy_light'); |
| 37 | |
| 38 | |
| 39 | wp_register_script('popper',EPGC_ASSET_URL . 'lib/popper.min.js', null, EMBEDPRESS_VERSION, true); |
| 40 | wp_register_script('tippy',EPGC_ASSET_URL . 'lib/tippy/tippy-bundle.umd.min.js', ['popper'], EMBEDPRESS_VERSION, true); |
| 41 | wp_register_script('my_moment',EPGC_ASSET_URL . 'lib/moment/moment-with-locales.min.js', null, EMBEDPRESS_VERSION, true); |
| 42 | wp_register_script('my_moment_timezone',EPGC_ASSET_URL . 'lib/moment/moment-timezone-with-data.min.js', ['my_moment'], EMBEDPRESS_VERSION, true); |
| 43 | wp_register_script('fullcalendar',EPGC_ASSET_URL . 'lib/fullcalendar4/core/main.min.js', ['my_moment_timezone'], EMBEDPRESS_VERSION, true); |
| 44 | wp_register_script('fullcalendar_moment',EPGC_ASSET_URL . 'lib/fullcalendar4/moment/main.min.js', ['fullcalendar'], EMBEDPRESS_VERSION, true); |
| 45 | wp_register_script('fullcalendar_moment_timezone',EPGC_ASSET_URL . 'lib/fullcalendar4/moment-timezone/main.min.js', ['fullcalendar_moment'], EMBEDPRESS_VERSION, true); |
| 46 | wp_register_script('fullcalendar_daygrid',EPGC_ASSET_URL . 'lib/fullcalendar4/daygrid/main.min.js', ['fullcalendar'], EMBEDPRESS_VERSION, true); |
| 47 | wp_register_script('fullcalendar_timegrid',EPGC_ASSET_URL . 'lib/fullcalendar4/timegrid/main.min.js', ['fullcalendar_daygrid'], EMBEDPRESS_VERSION, true); |
| 48 | wp_register_script('fullcalendar_list',EPGC_ASSET_URL . 'lib/fullcalendar4/list/main.min.js', ['fullcalendar'], EMBEDPRESS_VERSION, true); |
| 49 | wp_register_script('fullcalendar_locales',EPGC_ASSET_URL . 'lib/fullcalendar4/core/locales-all.min.js',['fullcalendar'], EMBEDPRESS_VERSION, true); |
| 50 | wp_register_script('epgc', EPGC_ASSET_URL . 'js/main.js',['fullcalendar'], EMBEDPRESS_VERSION, true); |
| 51 | |
| 52 | //wp_enqueue_script('popper'); |
| 53 | //wp_enqueue_script('my_moment'); |
| 54 | //wp_enqueue_script('my_moment_timezone'); |
| 55 | //wp_enqueue_script('fullcalendar'); |
| 56 | //wp_enqueue_script('fullcalendar_moment'); |
| 57 | //wp_enqueue_script('fullcalendar_moment_timezone'); |
| 58 | //wp_enqueue_script('fullcalendar_daygrid'); |
| 59 | //wp_enqueue_script('fullcalendar_timegrid'); |
| 60 | //wp_enqueue_script('fullcalendar_list'); |
| 61 | //wp_enqueue_script('fullcalendar_locales'); |
| 62 | //wp_enqueue_script('epgc'); |
| 63 | |
| 64 | $nonce = wp_create_nonce('epgc_nonce'); |
| 65 | wp_localize_script('epgc', 'epgc_object', [ |
| 66 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 67 | 'nonce' => $nonce, |
| 68 | 'trans' => [ |
| 69 | 'all_day' => __('All day', 'embedpress'), |
| 70 | 'created_by' => __('Created by', 'embedpress'), |
| 71 | 'go_to_event' => __('Go to event', 'embedpress'), |
| 72 | 'unknown_error' => __('Unknown error', 'embedpress'), |
| 73 | 'request_error' => __('Request error', 'embedpress'), |
| 74 | 'loading' => __('Loading', 'embedpress') |
| 75 | ] |
| 76 | ]); |
| 77 | } |
| 78 | public function get_name() |
| 79 | { |
| 80 | return 'embedpress_calendar'; |
| 81 | } |
| 82 | |
| 83 | public function get_title() |
| 84 | { |
| 85 | return esc_html__( 'EmbedPress Google Calendar', 'embedpress' ); |
| 86 | } |
| 87 | |
| 88 | public function get_categories() |
| 89 | { |
| 90 | return ['embedpress']; |
| 91 | } |
| 92 | |
| 93 | public function get_custom_help_url() |
| 94 | { |
| 95 | return 'https://embedpress.com/docs/embed-google-calendar-in-wordpress/'; |
| 96 | } |
| 97 | |
| 98 | public function get_icon() |
| 99 | { |
| 100 | return 'eicon-calendar'; |
| 101 | } |
| 102 | |
| 103 | public function get_script_depends() { |
| 104 | return ['popper','tippy', 'my_moment', 'my_moment_timezone', 'fullcalendar', 'fullcalendar_moment', 'fullcalendar_moment_timezone', 'fullcalendar_daygrid', 'fullcalendar_timegrid', 'fullcalendar_list', 'fullcalendar_locales', 'epgc']; |
| 105 | } |
| 106 | |
| 107 | public function get_style_depends() { |
| 108 | return ['fullcalendar', 'fullcalendar_daygrid', 'fullcalendar_list','epgc', 'tippy_light']; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get widget keywords. |
| 113 | * |
| 114 | * Retrieve the list of keywords the widget belongs to. |
| 115 | * |
| 116 | * @return array Widget keywords. |
| 117 | * @since 2.5.5 |
| 118 | * @access public |
| 119 | * |
| 120 | */ |
| 121 | public function get_keywords() |
| 122 | { |
| 123 | return ['embedpress', 'calendar', 'google', 'google calendar', 'google-calendar', 'ics', 'event', 'embedpress calendar']; |
| 124 | } |
| 125 | |
| 126 | protected function register_controls() |
| 127 | { |
| 128 | $this->pro_class = is_embedpress_pro_active() ? '': 'embedpress-pro-control not-active'; |
| 129 | $this->pro_text = is_embedpress_pro_active() ? '': '<sup class="embedpress-pro-label" style="color:red">'.__('Pro', 'embedpress').'</sup>'; |
| 130 | /** |
| 131 | * EmbedPress Content Settings |
| 132 | */ |
| 133 | $this->start_controls_section( |
| 134 | 'embedpress_calendar_content_settings', |
| 135 | [ |
| 136 | 'label' => esc_html__( 'Content Settings', 'embedpress' ), |
| 137 | ] |
| 138 | ); |
| 139 | |
| 140 | $this->add_control( |
| 141 | 'embedpress_calendar_type', |
| 142 | [ |
| 143 | 'label' => __( 'Calendar Type', 'embedpress' ), |
| 144 | 'type' => Controls_Manager::SELECT, |
| 145 | 'default' => 'public', |
| 146 | 'options' => [ |
| 147 | 'private' => __( 'Private', 'embedpress' ), |
| 148 | 'public' => __( 'Public', 'embedpress' ) |
| 149 | ], |
| 150 | ] |
| 151 | ); |
| 152 | |
| 153 | |
| 154 | $this->add_control( |
| 155 | 'embedpress_public_cal_link', |
| 156 | [ |
| 157 | |
| 158 | 'label' => __( 'Public Calendar Link', 'embedpress' ), |
| 159 | 'type' => Controls_Manager::TEXT, |
| 160 | 'dynamic' => [ |
| 161 | 'active' => true, |
| 162 | ], |
| 163 | 'placeholder' => __( 'Enter public calendar link', 'embedpress' ), |
| 164 | 'label_block' => true, |
| 165 | 'condition' => [ |
| 166 | 'embedpress_calendar_type' => 'public' |
| 167 | ], |
| 168 | |
| 169 | ] |
| 170 | ); |
| 171 | |
| 172 | |
| 173 | |
| 174 | $this->add_responsive_control( |
| 175 | 'embedpress_elementor_calendar_width', |
| 176 | [ |
| 177 | 'label' => __( 'Width', 'embedpress' ), |
| 178 | 'type' => Controls_Manager::SLIDER, |
| 179 | 'separator' => 'before', |
| 180 | 'default' => [ |
| 181 | 'unit' => 'px', |
| 182 | 'size' => 600, |
| 183 | ], |
| 184 | 'range' => [ |
| 185 | 'px' => [ |
| 186 | 'min' => 6, |
| 187 | 'max' => 1200, |
| 188 | ], |
| 189 | ], |
| 190 | 'selectors' => [ |
| 191 | '{{WRAPPER}} .embedpress-calendar-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%', |
| 192 | ], |
| 193 | 'render_type' => 'template', |
| 194 | ] |
| 195 | ); |
| 196 | |
| 197 | $this->add_responsive_control( |
| 198 | 'embedpress_elementor_calendar_height', |
| 199 | [ |
| 200 | 'label' => __( 'Height', 'embedpress' ), |
| 201 | 'type' => Controls_Manager::SLIDER, |
| 202 | 'default' => [ |
| 203 | 'unit' => 'px', |
| 204 | 'size' => 600, |
| 205 | ], |
| 206 | 'range' => [ |
| 207 | 'px' => [ |
| 208 | 'min' => 6, |
| 209 | 'max' => 1000, |
| 210 | ], |
| 211 | ], |
| 212 | 'selectors' => [ |
| 213 | '{{WRAPPER}} .embedpress-calendar-embed iframe' => 'height: {{SIZE}}{{UNIT}};', |
| 214 | ], |
| 215 | 'render_type' => 'template', |
| 216 | |
| 217 | ] |
| 218 | ); |
| 219 | |
| 220 | $this->add_responsive_control( |
| 221 | 'embedpress_elementor_calendar_align', |
| 222 | [ |
| 223 | 'label' => __( 'Alignment', 'embedpress' ), |
| 224 | 'type' => Controls_Manager::CHOOSE, |
| 225 | 'options' => [ |
| 226 | 'left' => [ |
| 227 | 'title' => __( 'Left', 'embedpress' ), |
| 228 | 'icon' => 'eicon-text-align-left', |
| 229 | ], |
| 230 | 'center' => [ |
| 231 | 'title' => __( 'Center', 'embedpress' ), |
| 232 | 'icon' => 'eicon-text-align-center', |
| 233 | ], |
| 234 | 'right' => [ |
| 235 | 'title' => __( 'Right', 'embedpress' ), |
| 236 | 'icon' => 'eicon-text-align-right', |
| 237 | ] |
| 238 | ], |
| 239 | 'prefix_class' => 'elementor%s-align-', |
| 240 | 'default' => '', |
| 241 | ] |
| 242 | ); |
| 243 | |
| 244 | $this->add_control( |
| 245 | 'embedpress_calendar_powered_by', |
| 246 | [ |
| 247 | 'label' => __( 'Powered By', 'embedpress' ), |
| 248 | 'type' => Controls_Manager::SWITCHER, |
| 249 | 'label_on' => __( 'Show', 'embedpress' ), |
| 250 | 'label_off' => __( 'Hide', 'embedpress' ), |
| 251 | 'return_value' => 'yes', |
| 252 | 'default' => apply_filters( 'embedpress_calendar_powered_by_control', 'yes' ), |
| 253 | ] |
| 254 | ); |
| 255 | |
| 256 | $this->init_branding_controls( 'calendar'); |
| 257 | |
| 258 | $this->end_controls_section(); |
| 259 | |
| 260 | if (! is_embedpress_pro_active()) { |
| 261 | $this->start_controls_section( |
| 262 | 'embedpress_pro_section', |
| 263 | [ |
| 264 | 'label' => __('Go Premium for More Features', 'embedpress'), |
| 265 | ] |
| 266 | ); |
| 267 | |
| 268 | $this->add_control( |
| 269 | 'embedpress_pro_cta', |
| 270 | [ |
| 271 | 'label' => __('Unlock more possibilities', 'embedpress'), |
| 272 | 'type' => Controls_Manager::CHOOSE, |
| 273 | 'options' => [ |
| 274 | '1' => [ |
| 275 | 'title' => '', |
| 276 | 'icon' => 'eicon-lock', |
| 277 | ], |
| 278 | ], |
| 279 | 'default' => '1', |
| 280 | 'description' => '<span class="pro-feature"> Get the <a href="https://wpdeveloper.com/in/upgrade-embedpress" target="_blank">Pro version</a> for more provider support and customization options.</span>', |
| 281 | ] |
| 282 | ); |
| 283 | |
| 284 | $this->end_controls_section(); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | |
| 289 | protected function render() |
| 290 | { |
| 291 | $settings = $this->get_settings(); |
| 292 | $id = 'embedpress-calendar-' . $this->get_id(); |
| 293 | $dimension = "width: {$settings['embedpress_elementor_calendar_width']['size']}px;height: {$settings['embedpress_elementor_calendar_height']['size']}px"; |
| 294 | |
| 295 | $this->add_render_attribute( 'embedpress-calendar-render', [ |
| 296 | 'class' => ['embedpress-embed-calendar-calendar', $id], |
| 297 | 'data-emid' => $id |
| 298 | ] ); |
| 299 | $this->add_render_attribute( 'embedpress-calendar', [ |
| 300 | 'class' => ['embedpress-calendar-embed', 'ep-cal-'.md5( $id), 'ose-calendar'] |
| 301 | ] ); |
| 302 | $is_private_cal = (!empty( $settings['embedpress_calendar_type']) && 'private' === $settings['embedpress_calendar_type']); |
| 303 | $is_editor_view = Plugin::$instance->editor->is_edit_mode(); |
| 304 | ?> |
| 305 | <div <?php echo $this->get_render_attribute_string( 'embedpress-calendar' ); ?> style="<?php echo esc_attr( $dimension); ?>; max-width:100%; display: inline-block"> |
| 306 | |
| 307 | |
| 308 | <?php |
| 309 | do_action( 'embedpress_calendar_after_embed', $settings, $id, $this); |
| 310 | ?> |
| 311 | <div <?php echo $this->get_render_attribute_string( 'embedpress-calendar-render' ); ?>> |
| 312 | <?php if ( !empty( $settings['embedpress_public_cal_link']) && !empty( $settings['embedpress_calendar_type']) && 'public' === $settings['embedpress_calendar_type'] ) { |
| 313 | ?> |
| 314 | <iframe title="" style="<?php echo esc_attr( $dimension); ?>; max-width:100%; display: inline-block" src="<?php echo esc_attr( $settings['embedpress_public_cal_link']); ?>" |
| 315 | frameborder="0"></iframe> |
| 316 | <?php |
| 317 | } else { |
| 318 | if ( $is_editor_view && empty( $settings['embedpress_public_cal_link']) && !$is_private_cal ) { |
| 319 | ?> |
| 320 | <p><?php esc_html_e( 'Please paste your public google calendar link.', 'embedpress'); ?></p> |
| 321 | <?php |
| 322 | } |
| 323 | // handle notice display |
| 324 | if ( $is_editor_view && $is_private_cal ) { |
| 325 | if ( !is_embedpress_pro_active()) { |
| 326 | ?> |
| 327 | <p><?php esc_html_e( 'You need EmbedPress Pro to display Private Calendar Data.', 'embedpress'); ?></p> |
| 328 | <?php |
| 329 | }else{ |
| 330 | ?> |
| 331 | <p><?php esc_html_e( 'Private Calendar Data will be displayed in the frontend', 'embedpress'); ?></p> |
| 332 | <?php |
| 333 | } |
| 334 | }else{ |
| 335 | // handle printing private calendar data |
| 336 | if ( is_embedpress_pro_active() ) { |
| 337 | echo Embedpress_Google_Helper::shortcode(); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | |
| 342 | } |
| 343 | ?> |
| 344 | </div> |
| 345 | <?php |
| 346 | if ( $settings[ 'embedpress_calendar_powered_by' ] === 'yes' ) { |
| 347 | printf( '<p class="embedpress-el-powered">%s</p>', __( 'Powered By EmbedPress', 'embedpress' ) ); |
| 348 | } |
| 349 | |
| 350 | ?> |
| 351 | </div> |
| 352 | |
| 353 | <?php |
| 354 | |
| 355 | } |
| 356 | |
| 357 | } |
| 358 |