Embedpress_Calendar.php
1 month ago
Embedpress_Document.php
1 month ago
Embedpress_Elementor.php
2 months ago
Embedpress_Pdf.php
1 month ago
Embedpress_Pdf_Gallery.php
2 months ago
Embedpress_Calendar.php
344 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 | // Localization is now handled by LocalizationManager |
| 65 | // This section is kept for backward compatibility but functionality has been moved |
| 66 | } |
| 67 | public function get_name() |
| 68 | { |
| 69 | return 'embedpress_calendar'; |
| 70 | } |
| 71 | |
| 72 | public function get_title() |
| 73 | { |
| 74 | return esc_html__( 'EmbedPress Google Calendar', 'embedpress' ); |
| 75 | } |
| 76 | |
| 77 | public function get_categories() |
| 78 | { |
| 79 | return ['embedpress']; |
| 80 | } |
| 81 | |
| 82 | public function get_custom_help_url() |
| 83 | { |
| 84 | return 'https://embedpress.com/docs/embed-google-calendar-in-wordpress/'; |
| 85 | } |
| 86 | |
| 87 | public function get_icon() |
| 88 | { |
| 89 | return 'eicon-calendar'; |
| 90 | } |
| 91 | |
| 92 | public function get_script_depends() { |
| 93 | return ['popper','tippy', 'my_moment', 'my_moment_timezone', 'fullcalendar', 'fullcalendar_moment', 'fullcalendar_moment_timezone', 'fullcalendar_daygrid', 'fullcalendar_timegrid', 'fullcalendar_list', 'fullcalendar_locales', 'epgc']; |
| 94 | } |
| 95 | |
| 96 | public function get_style_depends() { |
| 97 | return ['fullcalendar', 'fullcalendar_daygrid', 'fullcalendar_list','epgc', 'tippy_light']; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get widget keywords. |
| 102 | * |
| 103 | * Retrieve the list of keywords the widget belongs to. |
| 104 | * |
| 105 | * @return array Widget keywords. |
| 106 | * @since 2.5.5 |
| 107 | * @access public |
| 108 | * |
| 109 | */ |
| 110 | public function get_keywords() |
| 111 | { |
| 112 | return ['embedpress', 'calendar', 'google', 'google calendar', 'google-calendar', 'ics', 'event', 'embedpress calendar']; |
| 113 | } |
| 114 | |
| 115 | protected function register_controls() |
| 116 | { |
| 117 | $class = 'embedpress-pro-control not-active'; |
| 118 | $text = '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>'; |
| 119 | $this->pro_class = apply_filters('embedpress/pro_class', $class); |
| 120 | $this->pro_text = apply_filters('embedpress/pro_text', $text); |
| 121 | |
| 122 | /** |
| 123 | * EmbedPress Content Settings |
| 124 | */ |
| 125 | $this->start_controls_section( |
| 126 | 'embedpress_calendar_content_settings', |
| 127 | [ |
| 128 | 'label' => esc_html__( 'Content Settings', 'embedpress' ), |
| 129 | ] |
| 130 | ); |
| 131 | |
| 132 | $this->add_control( |
| 133 | 'embedpress_calendar_type', |
| 134 | [ |
| 135 | 'label' => __( 'Calendar Type', 'embedpress' ), |
| 136 | 'type' => Controls_Manager::SELECT, |
| 137 | 'default' => 'public', |
| 138 | 'options' => [ |
| 139 | 'private' => __( 'Private', 'embedpress' ), |
| 140 | 'public' => __( 'Public', 'embedpress' ) |
| 141 | ], |
| 142 | ] |
| 143 | ); |
| 144 | |
| 145 | |
| 146 | $this->add_control( |
| 147 | 'embedpress_public_cal_link', |
| 148 | [ |
| 149 | |
| 150 | 'label' => __( 'Public Calendar Link', 'embedpress' ), |
| 151 | 'type' => Controls_Manager::TEXT, |
| 152 | 'dynamic' => [ |
| 153 | 'active' => true, |
| 154 | ], |
| 155 | 'placeholder' => __( 'Enter public calendar link', 'embedpress' ), |
| 156 | 'label_block' => true, |
| 157 | 'condition' => [ |
| 158 | 'embedpress_calendar_type' => 'public' |
| 159 | ], |
| 160 | |
| 161 | ] |
| 162 | ); |
| 163 | |
| 164 | |
| 165 | |
| 166 | $this->add_responsive_control( |
| 167 | 'embedpress_elementor_calendar_width', |
| 168 | [ |
| 169 | 'label' => __( 'Width', 'embedpress' ), |
| 170 | 'type' => Controls_Manager::SLIDER, |
| 171 | 'separator' => 'before', |
| 172 | 'default' => [ |
| 173 | 'unit' => 'px', |
| 174 | 'size' => Helper::get_options_value('enableEmbedResizeWidth'), |
| 175 | ], |
| 176 | 'range' => [ |
| 177 | 'px' => [ |
| 178 | 'min' => 6, |
| 179 | 'max' => 1200, |
| 180 | ], |
| 181 | ], |
| 182 | 'selectors' => [ |
| 183 | '{{WRAPPER}} .embedpress-calendar-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%', |
| 184 | ], |
| 185 | 'render_type' => 'template', |
| 186 | ] |
| 187 | ); |
| 188 | |
| 189 | $this->add_responsive_control( |
| 190 | 'embedpress_elementor_calendar_height', |
| 191 | [ |
| 192 | 'label' => __( 'Height', 'embedpress' ), |
| 193 | 'type' => Controls_Manager::SLIDER, |
| 194 | 'default' => [ |
| 195 | 'unit' => 'px', |
| 196 | 'size' => Helper::get_options_value('enableEmbedResizeHeight'), |
| 197 | ], |
| 198 | 'range' => [ |
| 199 | 'px' => [ |
| 200 | 'min' => 6, |
| 201 | 'max' => 1000, |
| 202 | ], |
| 203 | ], |
| 204 | 'selectors' => [ |
| 205 | '{{WRAPPER}} .embedpress-calendar-embed iframe' => 'height: {{SIZE}}{{UNIT}};', |
| 206 | ], |
| 207 | 'render_type' => 'template', |
| 208 | |
| 209 | ] |
| 210 | ); |
| 211 | |
| 212 | $this->add_responsive_control( |
| 213 | 'embedpress_elementor_calendar_align', |
| 214 | [ |
| 215 | 'label' => __( 'Alignment', 'embedpress' ), |
| 216 | 'type' => Controls_Manager::CHOOSE, |
| 217 | 'options' => [ |
| 218 | 'left' => [ |
| 219 | 'title' => __( 'Left', 'embedpress' ), |
| 220 | 'icon' => 'eicon-text-align-left', |
| 221 | ], |
| 222 | 'center' => [ |
| 223 | 'title' => __( 'Center', 'embedpress' ), |
| 224 | 'icon' => 'eicon-text-align-center', |
| 225 | ], |
| 226 | 'right' => [ |
| 227 | 'title' => __( 'Right', 'embedpress' ), |
| 228 | 'icon' => 'eicon-text-align-right', |
| 229 | ] |
| 230 | ], |
| 231 | 'prefix_class' => 'elementor%s-align-', |
| 232 | 'default' => '', |
| 233 | ] |
| 234 | ); |
| 235 | |
| 236 | $this->add_control( |
| 237 | 'embedpress_calendar_powered_by', |
| 238 | [ |
| 239 | 'label' => __( 'Powered By', 'embedpress' ), |
| 240 | 'type' => Controls_Manager::SWITCHER, |
| 241 | 'label_on' => __( 'Show', 'embedpress' ), |
| 242 | 'label_off' => __( 'Hide', 'embedpress' ), |
| 243 | 'return_value' => 'yes', |
| 244 | 'default' => apply_filters( 'embedpress_calendar_powered_by_control', 'yes' ), |
| 245 | ] |
| 246 | ); |
| 247 | |
| 248 | $this->init_branding_controls( 'calendar'); |
| 249 | |
| 250 | // Get global lazy load setting |
| 251 | $g_settings = get_option(EMBEDPRESS_PLG_NAME, []); |
| 252 | $lazy_load_default = isset($g_settings['g_lazyload']) && $g_settings['g_lazyload'] == 1 ? 'yes' : ''; |
| 253 | |
| 254 | $this->add_control( |
| 255 | 'enable_lazy_load', |
| 256 | [ |
| 257 | 'label' => sprintf(__('Enable Lazy Loading %s', 'embedpress'), $this->pro_text), |
| 258 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 259 | 'label_on' => __('Yes', 'embedpress'), |
| 260 | 'label_off' => __('No', 'embedpress'), |
| 261 | 'return_value' => 'yes', |
| 262 | 'default' => $lazy_load_default, |
| 263 | 'separator' => 'before', |
| 264 | 'description' => __('Load iframe only when it enters the viewport for better performance', 'embedpress'), |
| 265 | 'classes' => $this->pro_class, |
| 266 | ] |
| 267 | ); |
| 268 | |
| 269 | $this->end_controls_section(); |
| 270 | |
| 271 | } |
| 272 | |
| 273 | public function isGoogleCalendar($url) { |
| 274 | // Allow http(s), optional `www.`, and the `u/<n>/` account segment that |
| 275 | // Google injects when copying the embed code while signed in. |
| 276 | $pattern = '~^https?://(?:www\.)?calendar\.google\.com/calendar/(?:u/\d+/)?embed\?.*$~i'; |
| 277 | return preg_match($pattern, $url); |
| 278 | } |
| 279 | |
| 280 | protected function render() |
| 281 | { |
| 282 | $settings = $this->get_settings(); |
| 283 | $id = 'embedpress-calendar-' .esc_attr( $this->get_id()); |
| 284 | $dimension = "width: " . esc_attr($settings['embedpress_elementor_calendar_width']['size']) . "px; height: " . esc_attr($settings['embedpress_elementor_calendar_height']['size']) . "px"; |
| 285 | |
| 286 | if(!empty($settings['embedpress_public_cal_link']) && !$this->isGoogleCalendar($settings['embedpress_public_cal_link'])) { |
| 287 | echo esc_html__('Invalid Calendar URL.'); |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | $this->add_render_attribute('embedpress-calendar-render', [ |
| 292 | 'class' => ['embedpress-embed-calendar-calendar', esc_attr($id)], |
| 293 | 'data-emid' => esc_attr($id) |
| 294 | ]); |
| 295 | $this->add_render_attribute('embedpress-calendar', [ |
| 296 | 'class' => ['embedpress-calendar-embed', 'ep-cal-' . md5($id), 'ose-calendar'] |
| 297 | ]); |
| 298 | $is_private_cal = (!empty($settings['embedpress_calendar_type']) && 'private' === $settings['embedpress_calendar_type']); |
| 299 | $is_editor_view = Plugin::$instance->editor->is_edit_mode(); |
| 300 | ?> |
| 301 | <div <?php echo $this->get_render_attribute_string('embedpress-calendar'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" data-embed-type="<?php echo esc_attr(Helper::get_provider_name($settings['embedpress_public_cal_link'])); ?>"> |
| 302 | <?php |
| 303 | do_action('embedpress_calendar_after_embed', $settings, $id, $this); |
| 304 | ?> |
| 305 | <div <?php echo $this->get_render_attribute_string('embedpress-calendar-render'); ?>> |
| 306 | <?php if (!empty($settings['embedpress_public_cal_link']) && !empty($settings['embedpress_calendar_type']) && 'public' === $settings['embedpress_calendar_type']) { |
| 307 | // Apply lazy loading if enabled (but not in editor mode) |
| 308 | if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !$is_editor_view) { ?> |
| 309 | <div class="ep-lazy-iframe-placeholder" |
| 310 | data-ep-lazy-src="<?php echo esc_attr($settings['embedpress_public_cal_link']); ?>" |
| 311 | data-ep-iframe-style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" |
| 312 | data-ep-iframe-frameborder="0" |
| 313 | style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block"></div> |
| 314 | <?php } else { ?> |
| 315 | <iframe title="" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" src="<?php echo esc_url($settings['embedpress_public_cal_link']); ?>" frameborder="0"></iframe> |
| 316 | <?php } |
| 317 | } else { |
| 318 | if ($is_editor_view && empty($settings['embedpress_public_cal_link']) && !$is_private_cal) { ?> |
| 319 | <p><?php esc_html_e('Please paste your public google calendar link.', 'embedpress'); ?></p> |
| 320 | <?php } |
| 321 | |
| 322 | if ($is_private_cal && !apply_filters('embedpress/is_allow_rander', false)) { ?> |
| 323 | <p><?php esc_html_e('You need EmbedPress Pro to display Private Calendar Data.', 'embedpress'); ?></p> |
| 324 | <?php } else { |
| 325 | // Render the private calendar in both the editor and the frontend. |
| 326 | // The AJAX endpoint backing this uses the epgc_cache_time transient, |
| 327 | // so repeat editor opens don't re-hit Google when caching is on. |
| 328 | do_action('embedpress_google_helper_shortcode', 10); |
| 329 | } |
| 330 | |
| 331 | } ?> |
| 332 | </div> |
| 333 | <?php |
| 334 | if ($settings['embedpress_calendar_powered_by'] === 'yes') { |
| 335 | printf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress')); |
| 336 | } |
| 337 | ?> |
| 338 | </div> |
| 339 | <?php |
| 340 | } |
| 341 | |
| 342 | |
| 343 | } |
| 344 |