PluginProbe
MaxGalleria / 6.5.0
MaxGalleria v6.5.0
6.5.3 trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.2.2 2.3 2.4 2.5 2.6 2.6.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 All 135 releases
maxgalleria / maxgalleria.php

maxgalleria.php in MaxGalleria 6.5.0, at maxgalleria.php

1,935 lines 73.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: MaxGalleria
4 Plugin URI: https://maxgalleria.com
5 Description: The gallery platform for WordPress.
6 Version: 6.5.0
7 Author: Max Foundry
8 Author URI: https://maxfoundry.com
9
10 Copyright 2014-2022 Max Foundry, LLC (https://maxfoundry.com)
11 */
12
13 class MaxGalleria {
14 private $_addons;
15
16 public $admin;
17 public $common;
18 public $meta;
19 public $nextgen;
20 public $settings;
21 public $shortcode;
22 public $shortcode_thumb;
23 public $new_gallery;
24 public $image_gallery;
25 public $video_gallery;
26 public $gallery_widget;
27 public $gallery_thumb_widget;
28 //public $license_valid;
29
30 public function __construct() {
31 $this->_addons = array();
32
33 $this->set_global_constants();
34 $this->set_activation_hooks();
35 $this->add_thumb_sizes();
36 $this->setup_hooks();
37 }
38
39 function activate() {
40 update_option(MAXGALLERIA_VERSION_KEY, MAXGALLERIA_VERSION_NUM);
41
42 $this->copy_template();
43
44 $current_user_id = get_current_user_id();
45 $havemeta = get_user_meta( $current_user_id, MAXGALLERIA_REVIEW_NOTICE, true );
46 if ($havemeta === '') {
47 $review_date = date('Y-m-d', strtotime("+1 days"));
48 update_user_meta( $current_user_id, MAXGALLERIA_REVIEW_NOTICE, $review_date );
49 }
50
51 //if ( 'impossible_default_value_12143' === get_option( 'mg_check_presets', 'impossible_default_value_12143' ) ) {
52 $mg_hide_presets = get_option( 'mg_hide_presets', 'none' );
53 if($mg_hide_presets !== 'on' && $mg_hide_presets !== 'off') {
54 if($this->check_for_mg_posts())
55 update_option( "mg_hide_presets", "off", true );
56 else
57 update_option( "mg_hide_presets", "on", true );
58 //update_option( "mg_check_presets", "impossible_default_value_12143", true );
59 }
60
61 }
62
63 function copy_template() {
64
65 // Copy gallery post type template file to theme directory
66 $source = MAXGALLERIA_PLUGIN_DIR . '/single-maxgallery.php';
67 $destination = $this->get_theme_dir() . '/single-maxgallery.php';
68 if(!defined('PRESERVE_MAXGALLERIA_TEMPLATE')) {
69 copy($source, $destination);
70 }
71 else if(!file_exists($destination)) {
72 copy($source, $destination);
73 }
74 flush_rewrite_rules();
75 }
76
77 public function add_thumb_sizes() {
78 // In addition to the thumbnail support when registering the custom post type, we need to add theme support
79 // to properly handle the featured image for a gallery, just in case the theme itself doesn't have it.
80 add_theme_support('post-thumbnails');
81
82 // Additional sizes, cropped
83 add_image_size(MAXGALLERIA_META_IMAGE_THUMB_SMALL, 100, 100, true);
84 add_image_size(MAXGALLERIA_META_IMAGE_THUMB_MEDIUM, 150, 150, true);
85 add_image_size(MAXGALLERIA_META_IMAGE_THUMB_LARGE, 200, 200, true);
86 add_image_size(MAXGALLERIA_META_VIDEO_THUMB_SMALL, 150, 100, true);
87 add_image_size(MAXGALLERIA_META_VIDEO_THUMB_MEDIUM, 200, 133, true);
88 add_image_size(MAXGALLERIA_META_VIDEO_THUMB_LARGE, 250, 166, true);
89 }
90
91 public function admin_page_is_maxgallery_post_type($post_id = 0) {
92 global $post;
93 global $post_type;
94
95 if (isset($post_id) && $post_id > 0 && get_post_type($post_id) == MAXGALLERIA_POST_TYPE) {
96 return true;
97 }
98
99 if (isset($_GET['post']) && $_GET['post'] > 0 && get_post_type($_GET['post']) == MAXGALLERIA_POST_TYPE) {
100 return true;
101 }
102
103 if (isset($_GET['post_type']) && $_GET['post_type'] == MAXGALLERIA_POST_TYPE) {
104 return true;
105 }
106
107 if (isset($post_type) && $post_type == MAXGALLERIA_POST_TYPE) {
108 return true;
109 }
110
111 if (isset($post) && $post->post_type == MAXGALLERIA_POST_TYPE) {
112 return true;
113 }
114
115 return false;
116 }
117
118 public function admin_page_is_media_edit() {
119 if ($this->common->url_contains('wp-admin/media.php') && $this->common->url_contains('action=edit')) {
120 return true;
121 }
122
123 return false;
124 }
125
126 public function admin_page_is_post_edit() {
127 if ($this->common->url_contains('wp-admin/post.php') && $this->common->url_contains('action=edit')) {
128 return true;
129 }
130
131 return false;
132 }
133
134 public function call_function_for_each_site($function) {
135 global $wpdb;
136
137 // Hold this so we can switch back to it
138 $current_blog = $wpdb->blogid;
139
140 // Get all the blogs/sites in the network and invoke the function for each one
141 $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
142 foreach ($blog_ids as $blog_id) {
143 switch_to_blog($blog_id);
144 call_user_func($function);
145 }
146
147 // Now switch back to the root blog
148 switch_to_blog($current_blog);
149 }
150
151 public function create_gallery_columns($column) {
152 // The Title and Date columns are standard, so we don't have to explicitly provide output for them
153
154 global $post;
155 $maxgallery = new MaxGalleryOptions($post->ID);
156
157 // Get all the attachments (the -1 gets all of them)
158 $args = array('post_parent' => $post->ID, 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'asc', 'numberposts' => -1);
159 $attachments = get_posts($args);
160
161 // Rounded borders
162 $style = 'border-radius: 2px; -moz-border-radius: 2px; -webkit-border-radius: 2px;';
163
164 switch ($column) {
165 case 'type':
166 if ($maxgallery->is_image_gallery()) {
167 echo '<img src="' . MAXGALLERIA_PLUGIN_URL . '/images/image-32.png" alt="' . esc_html__('Image', 'maxgalleria') . '" title="' . esc_html__('Image', 'maxgalleria') . '" style="' . esc_attr($style) . '" />';
168 }
169
170 if ($maxgallery->is_video_gallery()) {
171 echo '<img src="' . MAXGALLERIA_PLUGIN_URL . '/images/video-32.png" alt="' . esc_html__('Video', 'maxgalleria') . '" title="' . esc_html__('Video', 'maxgalleria') . '" style="' . esc_attr($style) . '" />';
172 }
173
174 break;
175 case 'thumbnail':
176 if (has_post_thumbnail($post->ID)) {
177 echo get_the_post_thumbnail($post->ID, array(32, 32), array('style' => $style));
178 }
179 else {
180 // Show the first thumb
181 foreach ($attachments as $attachment) {
182 $no_media_icon = 0;
183 echo wp_get_attachment_image($attachment->ID, array(32, 32), $no_media_icon, array('style' => $style));
184 break;
185 }
186 }
187 break;
188 case 'template':
189 $template_key = $maxgallery->get_template();
190 echo esc_html($this->get_template_name($template_key));
191 break;
192 case 'number':
193 if ($maxgallery->is_image_gallery()) {
194 if (count($attachments) == 0) { esc_html_e('0 images', 'maxgalleria'); }
195 if (count($attachments) == 1) { esc_html_e('1 image', 'maxgalleria'); }
196 if (count($attachments) > 1) { printf(esc_html__('%d images', 'maxgalleria'), count($attachments)); }
197 }
198
199 if ($maxgallery->is_video_gallery()) {
200 if (count($attachments) == 0) { esc_html_e('0 videos', 'maxgalleria'); }
201 if (count($attachments) == 1) { esc_html_e('1 video', 'maxgalleria'); }
202 if (count($attachments) > 1) { printf(esc_html__('%d videos', 'maxgalleria'), count($attachments)); }
203 }
204
205 break;
206 case 'shortcode':
207 echo '[maxgallery id="' . esc_html($post->ID) . '"]';
208
209 if ($post->post_status == 'publish') {
210 echo '<br />';
211 echo '[maxgallery name="' . esc_html($post->post_name) . '"]';
212 }
213
214 break;
215 }
216 }
217
218 public function create_plugin_action_links($links, $file) {
219 static $this_plugin;
220
221 if (!$this_plugin) {
222 $this_plugin = plugin_basename(__FILE__);
223 }
224
225 if ($file == $this_plugin) {
226 $settings_link = '<a href="' . admin_url() . 'edit.php?post_type=' . MAXGALLERIA_POST_TYPE . '&page=maxgalleria-settings">' . esc_html__('Settings', 'maxgalleria') . '</a>';
227 array_unshift($links, $settings_link);
228
229 $galleries_link = '<a href="' . admin_url() . 'edit.php?post_type=' . MAXGALLERIA_POST_TYPE . '">' . esc_html__('Galleries', 'maxgalleria') . '</a>';
230 array_unshift($links, $galleries_link);
231 }
232
233 return $links;
234 }
235
236 public function create_sortable_gallery_columns($vars) {
237 if (isset($vars['orderby'])) {
238 switch ($vars['orderby']) {
239 case 'type':
240 $vars = array_merge($vars, array('meta_key' => 'maxgallery_type', 'orderby' => 'meta_value'));
241 break;
242 case 'template':
243 $vars = array_merge($vars, array('meta_key' => 'maxgallery_template', 'orderby' => 'meta_value'));
244 break;
245 }
246 }
247
248 return $vars;
249 }
250
251 function deactivate() {
252 delete_option(MAXGALLERIA_VERSION_KEY);
253
254 if(!defined('PRESERVE_MAXGALLERIA_TEMPLATE')) {
255 // Delete the gallery post type template file from the theme directory
256 $file = $this->get_theme_dir() . '/single-maxgallery.php';
257 unlink($file);
258 }
259
260 flush_rewrite_rules();
261 }
262
263 public function define_gallery_columns($columns) {
264 $columns = apply_filters(MAXGALLERIA_FILTER_GALLERY_COLUMNS, array(
265 'cb' => '<input type="checkbox" />',
266 'title' => esc_html__('Title', 'maxgalleria'),
267 'thumbnail' => esc_html__('Thumbnail', 'maxgalleria'),
268 'type' => esc_html__('Type', 'maxgalleria'),
269 'template' => esc_html__('Template', 'maxgalleria'),
270 'number' => esc_html__('Number of Media', 'maxgalleria'),
271 'shortcode' => esc_html__('Shortcode', 'maxgalleria'),
272 'date' => esc_html__('Date', 'maxgalleria')
273 ));
274
275 return $columns;
276 }
277
278 public function define_sortable_gallery_columns($columns) {
279 // Title and Date are sortable by default
280
281 $columns['type'] = 'type';
282 $columns['template'] = 'template';
283 $columns['number'] = 'number';
284
285 return $columns;
286 }
287
288 public function do_activation($network_wide) {
289 if ($network_wide) {
290 $this->call_function_for_each_site(array($this, 'activate'));
291 }
292 else {
293 $this->activate();
294 }
295 }
296
297 public function do_deactivation($network_wide) {
298 if ($network_wide) {
299 $this->call_function_for_each_site(array($this, 'deactivate'));
300 }
301 else {
302 $this->deactivate();
303 }
304 }
305
306 public function enqueue_admin_print_scripts() {
307 if ($this->admin_page_is_maxgallery_post_type()) {
308 wp_enqueue_script('jquery');
309 wp_enqueue_script('jquery-migrate', ABSPATH . WPINC . '/js/jquery/jquery-migrate.min.js', array('jquery'));
310 wp_enqueue_script('thickbox');
311 wp_enqueue_script('media-upload');
312
313 // For the media uploader
314 wp_enqueue_media();
315 wp_enqueue_script('maxgalleria-media-script', MAXGALLERIA_PLUGIN_URL . '/js/media.js', array('jquery'));
316 wp_enqueue_script('maxgalleria-media-script');
317 wp_localize_script('maxgalleria-media-script', 'mg_media',
318 array('nonce' => wp_create_nonce(MG_META_NONCE )
319 ));
320
321
322 // Other stuff
323 wp_enqueue_script('jquery-ui-core');
324 wp_enqueue_script('jquery-ui-tabs');
325
326 wp_enqueue_script('maxgalleria-topbox', MAXGALLERIA_PLUGIN_URL . '/libs/topbox/js/topbox.js', array('jquery'));
327 wp_enqueue_script('maxgalleria-colorpicker-js', MAXGALLERIA_PLUGIN_URL . '/js/colpick/colpick.js', array('jquery'), null );
328
329 wp_enqueue_style('fontawesome', MAXGALLERIA_PLUGIN_URL . '/libs/fontawesome-free-6.0.0-web/css/all.min.css');
330
331 $screen = get_current_screen();
332 if($screen->id == 'edit-maxgallery') {
333 $show_gallery_ad = get_option('show_gallery_ad', "on");
334 wp_enqueue_script('maxgalleria-promo', MAXGALLERIA_PLUGIN_URL . '/js/promo.js', array('jquery'));
335 wp_localize_script( 'maxgalleria-promo', 'mg_promo',
336 array( 'pluginurl' => MAXGALLERIA_PLUGIN_URL,
337 'show_promo' => $show_gallery_ad,
338 'nonce' => wp_create_nonce(MG_META_NONCE ),
339 'admin_url' => admin_url('admin-ajax.php'),
340 'addon_link' => MG_ADDON_PAGE_LINK,
341 'carousel_link' => MG_IMAGE_CAROUSEL_LINK,
342 'albums_link' => MG_ALBUMS_LINK,
343 'video_showcase_link' => MG_VIDEO_SHOWCASE_LINK,
344 'slick_slider_link' => MG_SLICK_SLIDER_LINK,
345 'masonry_link' => MG_MASONRY_LINK,
346 'image_showcase_link' => MG_IMAGE_SHOWCASE_LINK,
347 'image_slider_link' => MG_IMAGE_SLIDER_LINK,
348 'facebook_link' => MG_FACEBOOK_LINK,
349 'vimeo_link' => MG_VIMEO_LINK,
350 'instgram_link' => MG_INSTAGRAM_LINK,
351 'flickr_link' => MG_FLICKR_LINK,
352 'fwgrid_link' => MG_FWGRID_LINK,
353 'mg_md_link' => MG_MD_LINK,
354 'hero_link' => MG_HERO_LINK
355 ));
356 }
357 } else {
358 wp_enqueue_script('maxgalleria-promo', MAXGALLERIA_PLUGIN_URL . '/js/tm.js', array('jquery'));
359 if(defined('MAXGALLERIA_ALBUMS_PLUGIN_URL')) {
360 $albumsurls = MAXGALLERIA_ALBUMS_PLUGIN_URL;
361 } else {
362 $albumsurls = "";
363 }
364 wp_localize_script( 'maxgalleria-promo', 'mg_promo',
365 array( 'pluginurl' => MAXGALLERIA_PLUGIN_URL,
366 'albumsurl' => $albumsurls
367 ));
368
369 }
370 }
371
372 public function enqueue_admin_print_styles() {
373
374 $screen = get_current_screen();
375
376 if ($this->admin_page_is_maxgallery_post_type()) {
377 wp_enqueue_style('thickbox');
378 wp_enqueue_style('maxgalleria-jquery-ui', MAXGALLERIA_PLUGIN_URL . '/libs/jquery-ui/jquery-ui.css');
379 wp_enqueue_style('maxgalleria-topbox', MAXGALLERIA_PLUGIN_URL . '/libs/topbox/css/topbox.css');
380 wp_enqueue_style('maxgalleria', MAXGALLERIA_PLUGIN_URL . '/maxgalleria.css');
381 wp_enqueue_style('maxgalleria-colorpicker', MAXGALLERIA_PLUGIN_URL . '/js/colpick/css/colpick.css');
382 wp_enqueue_style('maxgalleria-md-css', MAXGALLERIA_PLUGIN_URL . '/admin/material-plugin.css');
383
384 }
385 wp_enqueue_style('mg-notice', MAXGALLERIA_PLUGIN_URL . '/admin/mg-notice.css');
386
387 if($screen->id == 'maxgallery_page_mg-upgrade-to-pro') {
388 wp_enqueue_style('mg-upgrade', MAXGALLERIA_PLUGIN_URL . '/admin/mg-upgrade-to-pro.css');
389
390 wp_enqueue_style('mg-foundation', MAXGALLERIA_PLUGIN_URL . '/libs/foundation/foundation-float.min.css');
391 }
392
393 }
394
395 public function get_all_addons() {
396 return $this->_addons;
397 }
398
399 public function get_media_source_addons() {
400 $media_source_addons = array();
401
402 foreach ($this->_addons as $addon) {
403 if ($addon['type'] == 'media_source') {
404 array_push($media_source_addons, $addon);
405 }
406 }
407
408 return $media_source_addons;
409 }
410
411 public function get_template_addons() {
412 $template_addons = array();
413
414 foreach ($this->_addons as $addon) {
415 if ($addon['type'] == 'template') {
416 array_push($template_addons, $addon);
417 }
418 }
419
420 return $template_addons;
421 }
422
423 public function get_template_name($template_key) {
424 $template_name = '';
425 $templates = $this->get_template_addons();
426
427 foreach ($templates as $template) {
428 if ($template['key'] == $template_key) {
429 $template_name = $template['name'];
430 break;
431 }
432 }
433
434 return $template_name;
435 }
436
437 public function get_theme_dir() {
438 if(is_child_theme())
439 return WP_CONTENT_DIR . '/themes/' . get_stylesheet();
440 else
441 return WP_CONTENT_DIR . '/themes/' . get_template();
442 }
443
444 public function hide_add_new() {
445 global $submenu;
446 unset($submenu['edit.php?post_type=' . MAXGALLERIA_POST_TYPE][10]);
447 }
448
449 public function bootstrap() {
450 $this->load_textdomain();
451 $this->initialize_properties();
452 $this->register_media_sources();
453 $this->register_templates();
454 }
455
456 public function initialize_properties() {
457 // The order doesn't really matter, except maxgallery-options.php must be included first so
458 // that the MaxGalleryOptions class can be created in other parts of the system as needed
459
460 require_once 'maxgallery-options.php';
461 require_once 'maxgalleria-admin.php';
462 require_once 'maxgalleria-common.php';
463 require_once 'maxgalleria-meta.php';
464 require_once 'maxgalleria-nextgen.php';
465 require_once 'maxgalleria-settings.php';
466 require_once 'maxgalleria-shortcode.php';
467 require_once 'maxgalleria-shortcode-thumb.php';
468 require_once 'maxgalleria-new-gallery.php';
469 require_once 'maxgalleria-image-gallery.php';
470 require_once 'maxgalleria-video-gallery.php';
471 require_once 'widgets/gallery-widget.php';
472 require_once 'widgets/gallery-thumb-widget.php';
473
474 $this->admin = new MaxGalleriaAdmin();
475 $this->common = new MaxGalleriaCommon();
476 $this->meta = new MaxGalleriaMeta();
477 $this->nextgen = new MaxGalleriaNextGen();
478 $this->settings = new MaxGalleriaSettings();
479 $this->shortcode = new MaxGalleriaShortcode();
480 $this->shortcode_thumb = new MaxGalleriaShortcodeThumb();
481 $this->new_gallery = new MaxGalleriaNewGallery();
482 $this->image_gallery = new MaxGalleriaImageGallery();
483 $this->video_gallery = new MaxGalleriaVideoGallery();
484 $this->gallery_widget = new MaxGalleriaGalleryWidget();
485 $this->gallery_thumb_widget = new MaxGalleriaGalleryThumbWidget();
486 }
487
488 public function load_textdomain() {
489 load_plugin_textdomain('maxgalleria', false, dirname(plugin_basename(__FILE__)) . '/languages/');
490 }
491
492 public function media_button() {
493 global $pagenow, $wp_version;
494 $output = '';
495
496 // Only run in post/page creation and edit screens
497 if (in_array($pagenow, array('post.php', 'page.php', 'post-new.php', 'post-edit.php'))) {
498 $title = esc_html__('MaxGalleria Gallery', 'maxgalleria');
499 $icon = MAXGALLERIA_PLUGIN_URL . '/images/maxgalleria-icon-16.png';
500 $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
501 $output = '<a href="#TB_inline?width=640&inlineId=select-maxgallery-container" class="thickbox button" title="' . $title . '" style="padding-left: .4em;">' . $img . ' ' . $title . '</a>';
502 }
503
504 echo wp_kses_post($output);
505 }
506
507 public function media_button_admin_footer() {
508 require_once 'maxgalleria-media-button.php';
509 }
510
511 public function register_gallery_post_type() {
512 $slug = $this->settings->get_rewrite_slug();
513 $exclude_from_search = $this->settings->get_exclude_galleries_from_search();
514 $exclude_from_search = $exclude_from_search == 'on' ? true : false;
515
516 $labels = apply_filters(MAXGALLERIA_FILTER_GALLERY_POST_TYPE_LABELS, array(
517 'name' => esc_html__('MaxGalleria', 'maxgalleria'),
518 'singular_name' => esc_html__('Gallery', 'maxgalleria'),
519 'add_new' => esc_html__('Add New', 'maxgalleria'),
520 'add_new_item' => esc_html__('Add New Gallery', 'maxgalleria'),
521 'edit_item' => esc_html__('Edit Gallery', 'maxgalleria'),
522 'new_item' => esc_html__('New Gallery', 'maxgalleria'),
523 'view_item' => esc_html__('View Gallery', 'maxgalleria'),
524 'search_items' => esc_html__('Search Galleries', 'maxgalleria'),
525 'not_found' => esc_html__('No galleries found', 'maxgalleria'),
526 'not_found_in_trash' => esc_html__('No galleries found in trash', 'maxgalleria'),
527 'parent_item_colon' => ''
528 ));
529
530 $args = apply_filters(MAXGALLERIA_FILTER_GALLERY_POST_TYPE_ARGS, array(
531 'labels' => $labels,
532 'public' => true,
533 'publicly_queryable' => true,
534 'show_ui' => true,
535 'show_in_menu' => true,
536 'query_var' => true,
537 'menu_icon' => MAXGALLERIA_PLUGIN_URL . '/images/maxgalleria-icon-16.png',
538 'rewrite' => array('slug' => $slug),
539 'capability_type' => 'post',
540 'hierarchical' => false,
541 'supports' => array('title', 'thumbnail'),
542 'taxonomies' => array('category', 'post_tag'),
543 'exclude_from_search' => $exclude_from_search
544 ));
545
546 register_post_type(MAXGALLERIA_POST_TYPE, $args);
547 }
548
549 public function register_addon($addon) {
550 array_push($this->_addons, $addon);
551 }
552
553 public function register_media_sources() {
554 // YouTube
555 require_once MAXGALLERIA_PLUGIN_DIR . '/addons/media-sources/youtube/youtube.php';
556 $youtube = new MaxGalleriaYouTube();
557 $youtube_addon = array(
558 'key' => $youtube->addon_key,
559 'name' => $youtube->addon_name,
560 'type' => $youtube->addon_type,
561 'subtype' => $youtube->addon_subtype,
562 'settings' => $youtube->addon_settings
563 );
564 $this->register_addon($youtube_addon);
565 }
566
567 public function register_templates() {
568 // Image Tiles template
569 require_once MAXGALLERIA_PLUGIN_DIR . '/addons/templates/image-tiles/image-tiles.php';
570 $image_tiles = new MaxGalleriaImageTiles();
571 $image_tiles_addon = array(
572 'key' => $image_tiles->addon_key,
573 'name' => $image_tiles->addon_name,
574 'type' => $image_tiles->addon_type,
575 'subtype' => $image_tiles->addon_subtype,
576 'settings' => $image_tiles->addon_settings,
577 'image' => $image_tiles->addon_image,
578 'output' => $image_tiles->addon_output
579 );
580 $this->register_addon($image_tiles_addon);
581
582 // Video Tiles template
583 require_once MAXGALLERIA_PLUGIN_DIR . '/addons/templates/video-tiles/video-tiles.php';
584 $video_tiles = new MaxGalleriaVideoTiles();
585 $video_tiles_addon = array(
586 'key' => $video_tiles->addon_key,
587 'name' => $video_tiles->addon_name,
588 'type' => $video_tiles->addon_type,
589 'subtype' => $video_tiles->addon_subtype,
590 'settings' => $video_tiles->addon_settings,
591 'image' => $video_tiles->addon_image,
592 'output' => $video_tiles->addon_output
593 );
594 $this->register_addon($video_tiles_addon);
595 }
596
597 public function register_widgets() {
598 register_widget('MaxGalleriaGalleryWidget');
599 register_widget('MaxGalleriaGalleryThumbWidget');
600 }
601
602 public function set_activation_hooks() {
603 register_activation_hook(__FILE__, array($this, 'do_activation'));
604 register_deactivation_hook(__FILE__, array($this, 'do_deactivation'));
605 }
606
607 public function set_global_constants() {
608 define('MAXGALLERIA_VERSION_KEY', 'maxgalleria_version');
609 define('MAXGALLERIA_VERSION_NUM', '6.5.0');
610 define('MAXGALLERIA_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
611 define('MAXGALLERIA_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . MAXGALLERIA_PLUGIN_NAME);
612 define('MAXGALLERIA_PLUGIN_URL', rtrim(plugin_dir_url(__FILE__), '/'));
613 define('MAXGALLERIA_POST_TYPE', 'maxgallery');
614 define('MAXGALLERIA_SETTINGS', admin_url() . 'edit.php?post_type=' . MAXGALLERIA_POST_TYPE . '&page=maxgalleria-settings');
615 define('MAXGALLERIA_META_IMAGE_THUMB_SMALL', 'maxgallery-meta-image-thumb-small');
616 define('MAXGALLERIA_META_IMAGE_THUMB_MEDIUM', 'maxgallery-meta-image-thumb-medium');
617 define('MAXGALLERIA_META_IMAGE_THUMB_LARGE', 'maxgallery-meta-image-thumb-large');
618 define('MAXGALLERIA_META_VIDEO_THUMB_SMALL', 'maxgallery-meta-video-thumb-small');
619 define('MAXGALLERIA_META_VIDEO_THUMB_MEDIUM', 'maxgallery-meta-video-thumb-medium');
620 define('MAXGALLERIA_META_VIDEO_THUMB_LARGE', 'maxgallery-meta-video-thumb-large');
621 define('MAXGALLERIA_THUMB_SHAPE_LANDSCAPE', 'landscape');
622 define('MAXGALLERIA_THUMB_SHAPE_PORTRAIT', 'portrait');
623 define('MAXGALLERIA_THUMB_SHAPE_SQUARE', 'square');
624 define('MAXGALLERIA_SETTING_REWRITE_SLUG', 'maxgalleria_setting_rewrite_slug');
625 define('MAXGALLERIA_SETTING_EXCLUDE_GALLERIES_FROM_SEARCH', 'maxgalleria_setting_exlude_galleries_from_search');
626 define('MAXGALLERIA_SETTING_DEFAULT_IMAGE_GALLERY_TEMPLATE', 'maxgalleria_setting_default_image_gallery_template');
627 define('MAXGALLERIA_SETTING_DEFAULT_VIDEO_GALLERY_TEMPLATE', 'maxgalleria_setting_default_video_gallery_template');
628 define('MAXGALLERIA_ADMIN_NOTICE', 'maxgalleria_admin_notice-2');
629 define('MAXGALLERIA_REVIEW_NOTICE', 'maxgalleria_review_notice');
630 define('MG_META_NONCE', 'maxgalleria_meta_nonce');
631 define('MG_WP_CONTENT_FOLDER_NAME', basename(WP_CONTENT_DIR));
632
633 define('MG_EDD_SHOP_URL', 'https://maxgalleria.com/');
634 define('MAXGALLERIA_SETTING_SHOW_ADDON_PAGE', 'maxgalleria_setting_default_show_addons_page');
635
636 if(!defined('MAXGALLERIA_MEDIA_LIBRARY_SRC_FIX'))
637 define("MAXGALLERIA_MEDIA_LIBRARY_SRC_FIX", "mgmlp_src_fix");
638
639 define('MG_ADDON_PAGE_LINK',
640 'https://maxgalleria.com/addons/?utm_source=MGGetAddon&utm_medium=tout&utm_campaign=tout');
641 define('MG_IMAGE_CAROUSEL_LINK',
642 'https://maxgalleria.com/downloads/maxgalleria-image-carousel/?utm_source=MGGetAddon&amp;utm_medium=image-carousel&amp;utm_campaign=image-carousel');
643 define('MG_ALBUMS_LINK',
644 'https://maxgalleria.com/downloads/maxgalleria-albums/?utm_source=MGGetAddon&amp;utm_medium=albums&amp;utm_campaign=albums' );
645 define('MG_VIDEO_SHOWCASE_LINK',
646 'https://maxgalleria.com/downloads/maxgalleria-video-showcase/?utm_source=MGGetAddon&utm_medium=videoshowcase&utm_campaign=videoshowcase');
647 define('MG_SLICK_SLIDER_LINK',
648 'https://maxgalleria.com/downloads/slick-slider-for-wordpress/?utm_source=MGGetAddon&utm_medium=slick&utm_campaign=slick' );
649 define('MG_MASONRY_LINK',
650 'https://maxgalleria.com/downloads/masonry-pinterest-like-layout/?utm_source=MGGetAddon&utm_medium=masonry&utm_campaign=masonry');
651 define('MG_IMAGE_SHOWCASE_LINK',
652 'https://maxgalleria.com/downloads/maxgalleria-image-showcase/?utm_source=MGGetAddon&utm_medium=imageshowcase&utm_campaign=imageshowcase');
653 define ('MG_IMAGE_SLIDER_LINK',
654 'https://maxgalleria.com/downloads/maxgalleria-image-slider/?utm_source=MGGetAddon&utm_medium=imageslider&utm_campaign=imageslider');
655 define('MG_FACEBOOK_LINK',
656 'https://maxgalleria.com/downloads/maxgalleria-facebook/?utm_source=MGGetAddon&utm_medium=facebook&utm_campaign=facebook');
657 define('MG_VIMEO_LINK',
658 'https://maxgalleria.com/downloads/maxgalleria-vimeo/?utm_source=MGGetAddon&utm_medium=vimeo&utm_campaign=vimeo');
659 define('MG_INSTAGRAM_LINK',
660 'https://maxgalleria.com/downloads/maxgalleria-instagram/?utm_source=MGGetAddon&utm_medium=instagram&utm_campaign=instagram');
661 define('MG_FLICKR_LINK',
662 'https://maxgalleria.com/downloads/maxgalleria-flickr/?utm_source=MGGetAddon&utm_medium=flickr&utm_campaign=flickr');
663 define('MLPP_LINK', 'https://maxgalleria.com/downloads/media-library-plus-pro/?utm_source=MGGetAddon ');
664 define('MG_FWGRID_LINK',
665 'https://maxgalleria.com/downloads/full-width-grid/?utm_source=MGGetAddon&utm_medium=fwgrid&utm_campaign=slick' );
666 define('MG_MD_LINK',
667 'https://maxgalleria.com/downloads/material-deisgn/?utm_source=MGGetAddon&utm_medium=material-deisgn&utm_campaign=slick' );
668 define('MG_HERO_LINK',
669 'https://www.maxgalleria.com/hero-slider-wordpress/?utm_source=MGGetAddon&utm_medium=hero-slider&utm_campaign=hero' );
670
671
672 // Bring in all the actions and filters
673 require_once 'maxgalleria-hooks.php';
674 }
675
676 public function set_icon_edit_image() {
677 if ($this->admin_page_is_maxgallery_post_type()) {
678 echo '<style>';
679 echo '#icon-edit { background: url("'. MAXGALLERIA_PLUGIN_URL . '/images/maxgalleria-icon-32.png' . '") no-repeat transparent; }';
680 echo '</style>';
681 }
682 }
683
684 public function setup_hooks() {
685 add_action('init', array($this, 'bootstrap'), 0);
686 add_action('init', array($this, 'register_gallery_post_type'));
687 add_action('init', array($this, 'display_mg_admin_notice'));
688 add_filter('plugin_action_links', array($this, 'create_plugin_action_links'), 10, 2);
689 add_action('admin_print_scripts', array($this, 'enqueue_admin_print_scripts'));
690 add_action('admin_print_styles', array($this, 'enqueue_admin_print_styles'));
691 add_action('admin_head', array($this, 'set_icon_edit_image'));
692 add_action('admin_menu', array($this, 'hide_add_new'));
693 add_filter('manage_edit-' . MAXGALLERIA_POST_TYPE . '_columns', array($this, 'define_gallery_columns'));
694 add_filter('manage_edit-' . MAXGALLERIA_POST_TYPE . '_sortable_columns', array($this, 'define_sortable_gallery_columns'));
695 add_action('manage_posts_custom_column', array($this, 'create_gallery_columns'));
696 add_filter('request', array($this, 'create_sortable_gallery_columns'));
697 add_filter('media_upload_tabs', array($this, 'set_media_upload_tabs'), 50, 1);
698 add_filter('media_view_strings', array($this, 'set_media_view_strings'), 50, 1);
699 add_filter('post_mime_types', array($this, 'set_post_mime_types'), 50, 1);
700 add_filter('upload_mimes', array($this, 'set_upload_mimes'), 50, 1);
701 add_action('media_buttons', array($this, 'media_button'));
702 add_action('admin_footer', array($this, 'media_button_admin_footer'));
703 add_action('widgets_init', array($this, 'register_widgets'));
704 add_action('after_switch_theme', array($this, 'copy_template'));
705
706 if(!defined('ATTACHMENT_QUERY_OFF') && !class_exists('eml') && !function_exists( 'wpuxss_get_eml_slug' ) )
707 add_action( 'pre_get_posts', array($this, 'modify_attachments'));
708
709 //add_action( 'pre_get_posts', array($this, 'limit_contributor_access'));
710
711 add_action( 'admin_menu', array($this, 'limit_contributor_access'));
712
713 //add_action( 'admin_bar_menu', array($this, 'current_maxgalleria_gallery'), 999 );
714
715
716 // this is not working yet:
717 // check daily for the template in the theme folder; copy and update permalinks if missing.
718 // if ( ! wp_next_scheduled( 'mg_task_hook' ) ) {
719 // wp_schedule_event( time(), 'daily', 'mg_task_hook' );
720 // }
721 //
722 // add_action( 'mg_task_hook', array($this, 'mg_daily_check') );
723
724 add_action('admin_head', array($this, 'admin_head_hook'), 1);
725
726 //add_filter('mce_buttons', array($this, 'tinymce_button'));
727 //add_filter('mce_external_plugins', array($this, 'add_tinymce_button'));
728
729 add_action('enqueue_block_editor_assets', array($this, 'load_mg_block'));
730
731 add_filter('query_vars', array($this, 'mg_query_vars'));
732
733 add_action('wp_ajax_nopriv_mg_get_image_info', array($this, 'mg_get_image_info'));
734 add_action('wp_ajax_mg_get_image_info', array($this, 'mg_get_image_info'));
735
736 add_action('wp_ajax_nopriv_mg_save_image_info', array($this, 'mg_save_image_info'));
737 add_action('wp_ajax_mg_save_image_info', array($this, 'mg_save_image_info'));
738
739 add_action('wp_ajax_nopriv_mg_display_bulk_edit', array($this, 'mg_display_bulk_edit'));
740 add_action('wp_ajax_mg_display_bulk_edit', array($this, 'mg_display_bulk_edit'));
741
742 add_action('wp_ajax_nopriv_mg_save_bulk_info', array($this, 'mg_save_bulk_info'));
743 add_action('wp_ajax_mg_save_bulk_info', array($this, 'mg_save_bulk_info'));
744
745 add_action('wp_ajax_nopriv_mg_get_video_info', array($this, 'mg_get_video_info'));
746 add_action('wp_ajax_mg_get_video_info', array($this, 'mg_get_video_info'));
747
748 add_action('wp_ajax_nopriv_mg_save_video_info', array($this, 'mg_save_video_info'));
749 add_action('wp_ajax_mg_save_video_info', array($this, 'mg_save_video_info'));
750
751 add_action('wp_ajax_nopriv_mg_display_bulk_video', array($this, 'mg_display_bulk_video'));
752 add_action('wp_ajax_mg_display_bulk_video', array($this, 'mg_display_bulk_video'));
753
754 add_action('wp_ajax_nopriv_mg_save_bulk_video', array($this, 'mg_save_bulk_video'));
755 add_action('wp_ajax_mg_save_bulk_video', array($this, 'mg_save_bulk_video'));
756
757 add_action('wp_ajax_nopriv_mg_add_videos', array($this, 'mg_add_videos'));
758 add_action('wp_ajax_mg_add_videos', array($this, 'mg_add_videos'));
759
760 // added 'display' to the list of accepted styles used in wp_kses_post()
761 add_filter( 'safe_style_css', function( $styles ) {
762 $styles[] = 'display';
763 return $styles;
764 } );
765
766 }
767
768 public function load_mg_block() {
769
770 global $wpdb;
771
772 wp_register_script(
773 'mg-block', MAXGALLERIA_PLUGIN_URL . '/block/index.js',
774 array('wp-blocks','wp-editor','wp-i18n'),
775 true
776 );
777
778 $sql = "SELECT ID, post_title from {$wpdb->prefix}posts where post_type = 'maxgallery' and post_status = 'publish' order by post_title";
779
780 $gallery_list = array();
781
782 $rows = $wpdb->get_results($sql);
783
784 if($rows) {
785 foreach($rows as $row) {
786 $gallery_list[] = array(
787 'id' => strval($row->ID),
788 'name' => $row->post_title
789 );
790 }
791 }
792
793 // keep as array, not casting as an object
794 wp_localize_script( 'mg-block', 'mg_block_info',
795 array( 'galleries' => $gallery_list));
796
797 wp_enqueue_script('mg-block');
798
799 }
800
801 function limit_contributor_access() {
802 if( !current_user_can( 'publish_posts' ) ):
803 remove_menu_page( 'edit.php?post_type=maxgallery' );
804 endif;
805 }
806
807 public function modify_attachments( $query ) {
808
809 if ( is_admin() && strpos( $_SERVER[ 'REQUEST_URI' ], 'admin-ajax.php' ) !== false && $_REQUEST['action'] === 'query-attachments' ) {
810 add_filter( 'posts_groupby', array($this, 'group_attachments') );
811 }
812 return $query;
813 }
814
815 public function group_attachments($groupby) {
816 if ($groupby != '') {
817 $groupby .= " , guid";
818 } else {
819 $groupby .= " guid";
820 }
821 return $groupby;
822 }
823
824 public function set_media_upload_tabs($tabs) {
825 // Remove the "From URL", "Gallery", and "NextGEN" tabs from the media library popup.
826 // Only the tabs "From Computer" and "Media Library" should be shown.
827
828 if ($this->admin_page_is_maxgallery_post_type()) {
829 unset($tabs['type_url']); // From URL tab
830 unset($tabs['gallery']); // Gallery tab
831 unset($tabs['nextgen']); // NextGEN tab
832 }
833
834 return $tabs;
835 }
836
837 public function set_media_view_strings($strings) {
838 if ($this->admin_page_is_maxgallery_post_type()) {
839 // Remove these
840 unset($strings['insertFromUrlTitle']);
841 unset($strings['setFeaturedImageTitle']);
842 unset($strings['createGalleryTitle']);
843 unset($strings['createPlaylistTitle']);
844 unset($strings['createVideoPlaylistTitle']);
845
846 // Change these for better context in MaxGalleria galleries
847 $strings['insertMediaTitle'] = esc_html__('Add Images', 'maxgalleria');
848 $strings['insertIntoPost'] = esc_html__('Add to Gallery', 'maxgalleria');
849 $strings['uploadedToThisPost'] = esc_html__('Added to this gallery', 'maxgalleria');
850 }
851
852 return $strings;
853 }
854
855 public function set_post_mime_types($mime_types) {
856 // Remove the video and audio types
857
858 if ($this->admin_page_is_maxgallery_post_type()) {
859 unset($mime_types['video']);
860 unset($mime_types['audio']);
861 }
862
863 return $mime_types;
864 }
865
866 public function set_upload_mimes($mime_types) {
867 // Only allow image file type uploads. The complete list allowed by WordPress is
868 // located in the get_allowed_mime_types() function in wp-includes/functions.php.
869
870 if ($this->admin_page_is_maxgallery_post_type()) {
871 $mime_types = array(
872 'jpg|jpeg|jpe' => 'image/jpeg',
873 'gif' => 'image/gif',
874 'png' => 'image/png',
875 'bmp' => 'image/bmp',
876 'webp' => 'image/webp',
877 'avif' => 'image/avif',
878 'tif/tiff' => 'image/tiff'
879 );
880 }
881
882 return $mime_types;
883 }
884
885 public function thickbox_l10n_fix() {
886 // When combining scripts, localization is lost for thickbox.js, so we call this
887 // function to fix it. See https://wordpress.org/support/topic/plugin-affecting-photo-galleriessliders
888 // for more details.
889 echo '<script type="text/javascript">';
890 echo "var thickboxL10n = " . json_encode(array(
891 'next' => esc_html__('Next >'),
892 'prev' => esc_html__('< Prev'),
893 'image' => esc_html__('Image'),
894 'of' => esc_html__('of'),
895 'close' => esc_html__('Close'),
896 'noiframes' => esc_html__('This feature requires inline frames. You have iframes disabled or your browser does not support them.'),
897 'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'),
898 'closeImage' => includes_url('js/thickbox/tb-close.png')));
899 echo '</script>';
900 }
901
902 public function display_mg_admin_notice () {
903
904 $current_user_id = get_current_user_id();
905
906 $notice = get_user_meta( $current_user_id, MAXGALLERIA_ADMIN_NOTICE, true );
907 $review = get_user_meta( $current_user_id, MAXGALLERIA_REVIEW_NOTICE, true );
908
909 //if( $notice !== 'off' )
910 // add_action( 'admin_notices', array($this, 'mg_admin_notice' ));
911
912 if( $review !== 'off') {
913 if($review === false)
914 add_action( 'admin_notices', array($this, 'mg_review_notice' ));
915 else {
916 $now = date("Y-m-d");
917 $review_time = strtotime($review);
918 $now_time = strtotime($now);
919 if($now_time > $review_time)
920 add_action( 'admin_notices', array($this, 'mg_review_notice' ));
921 }
922 }
923 }
924
925 // public function mg_admin_notice() {
926 // if( current_user_can( 'manage_options' ) ) { ? >
927 // <div class="updated notice">
928 // </div>
929 // < ?php
930 // }
931 // }
932
933 public function mg_review_notice() {
934 if( current_user_can( 'manage_options' ) ) { ?>
935 <div class="updated notice maxgalleria-notice">
936 <div id='maxgallery_logo'></div>
937 <div id='maxgalleria-notice-3'><p id='mg-notice-title'><?php esc_html_e( 'Rate us Please!', 'maxgalleria' ); ?></p>
938 <p><?php esc_html_e( 'Your rating is the simplest way to support MaxGalleria. We really appreciate it!', 'maxgalleria' ); ?></p>
939
940 <ul id="review-notice-links">
941 <li> <span class="dashicons dashicons-smiley"></span><a href="<?php echo admin_url(); ?>edit.php?post_type=maxgallery&page=mg-review-notice"><?php esc_html_e( "I've already left a review", "maxgalleria" ); ?></a></li>
942 <li><span class="dashicons dashicons-calendar-alt"></span><a href="<?php echo admin_url(); ?>edit.php?post_type=maxgallery&page=mg-review-later"><?php esc_html_e( "Maybe Later", "maxgalleria" ); ?></a></li>
943 <li><span class="dashicons dashicons-external"></span><a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/maxgalleria?filter=5"><?php esc_html_e( "Sure! I'd love to!", "maxgalleria" ); ?></a></li>
944 </ul>
945 </div>
946 <a class="dashicons dashicons-dismiss close-mg-notice" href="<?php echo admin_url(); ?>edit.php?post_type=maxgallery&page=mg-review-notice"></a>
947
948 </div>
949 <?php
950 }
951 }
952
953 private function mg_daily_check() {
954
955 $source = MAXGALLERIA_PLUGIN_DIR . '/single-maxgallery.php';
956 $destination = $this->get_theme_dir() . '/single-maxgallery.php';
957
958 if(!file_exists($destination)) {
959 copy($source, $destination);
960 flush_rewrite_rules();
961 }
962
963 }
964
965 public function mg_get_attachment_url($attachment, $uploads) {
966 $url = "";
967 if ( $file = get_post_meta( $attachment->ID, '_wp_attached_file', true) ) {
968 if ( 0 === strpos( $file, $uploads['basedir'] ) ) {
969 // Replace file location with url location.
970 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
971 } elseif ( false !== strpos($file, MG_WP_CONTENT_FOLDER_NAME . '/uploads') ) {
972 $url = $uploads['baseurl'] . substr( $file, strpos($file, MG_WP_CONTENT_FOLDER_NAME . '/uploads') + 18 );
973 } else {
974 // It's a newly-uploaded file, therefore $file is relative to the basedir.
975 $url = $uploads['baseurl'] . "/$file";
976 }
977 } else {
978 $url = $attachment->guid;
979 }
980
981 // On SSL front-end, URLs should be HTTPS.
982 if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $GLOBALS['pagenow'] ) {
983 $url = set_url_scheme( $url );
984 }
985
986 $url = apply_filters( 'wp_get_attachment_url', $url, $attachment->ID );
987
988 return $url;
989 }
990
991 // check if MG is already running on the site
992 private function check_for_mg_posts() {
993 global $wpdb;
994
995 $sql = "SELECT ID from {$wpdb->prefix}posts where post_type = 'maxgallery' limit 0, 1";
996
997 if($wpdb->get_row($sql))
998 return true;
999 else
1000 return false;
1001
1002 }
1003
1004 public function current_maxgalleria_gallery( $wp_admin_bar ) {
1005
1006 global $wpdb;
1007
1008 if(current_user_can( 'manage_options')) {
1009
1010 $sql = "select option_value from {$wpdb->prefix}options where option_name = 'mg_current_gallery'";
1011
1012 $gallery_id = $wpdb->get_var($sql);
1013
1014 if($gallery_id != null) {
1015
1016 $args = array(
1017 'id' => 'mg_current_gallery',
1018 'title' => 'Current Gallery',
1019 'href' => admin_url() . "post.php?post={$gallery_id}&action=edit",
1020 );
1021
1022 $wp_admin_bar->add_node( $args );
1023 }
1024 }
1025 }
1026
1027 public function admin_head_hook() {
1028 global $wp_query;
1029 if(isset($wp_query->post->ID)) {
1030 if(MAXGALLERIA_POST_TYPE == get_post_type($wp_query->post->ID)) {
1031 add_filter( 'admin_body_class', array($this, 'mg_body_class'));
1032 }
1033 }
1034 }
1035
1036 public function mg_body_class($classes) {
1037 $mg_class = "maxgalery-pt";
1038 if(is_array($classes))
1039 $classes[] = $mg_class;
1040 else
1041 $classes .= " " . $mg_class;
1042 return $classes;
1043 }
1044
1045 public function tinymce_button($buttons){
1046 array_push($buttons, "maxgalleria_tinymce");
1047 return $buttons;
1048 }
1049
1050 public function add_tinymce_button($plugin_array){
1051 $js_url = trailingslashit(MAXGALLERIA_PLUGIN_URL . '/js/');
1052 $plugin_array['maxgalleria_tinymce'] = $js_url . 'maxgalleria_tinymce.js' ;
1053 return $plugin_array;
1054 }
1055
1056 // function by stever, https://www.php.net/strip%20tags
1057 public function stripUnwantedTagsAndAttrs($html_str){
1058 $content = mb_convert_encoding($html_str, 'HTML-ENTITIES', 'UTF-8');
1059 $xml = new DOMDocument('utf8');
1060 //$xml->encoding = 'utf8';
1061 //Suppress warnings: proper error handling is beyond scope of example
1062 libxml_use_internal_errors(true);
1063 //List the tags you want to allow here, NOTE you MUST allow html and body otherwise entire string will be cleared
1064 $allowed_tags = array("b", "br", "em", "hr", "i", "li", "ol", "p", "s", "span", "table", "tr", "td", "u", "ul", "strong");
1065 //List the attributes you want to allow here
1066 $allowed_attrs = array ("class", "id", "style");
1067 if (!strlen($content)){return false;}
1068 if ($xml->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)){
1069 foreach ($xml->getElementsByTagName("*") as $tag){
1070 if (!in_array($tag->tagName, $allowed_tags)){
1071 $tag->parentNode->removeChild($tag);
1072 }else{
1073 foreach ($tag->attributes as $attr){
1074 if (!in_array($attr->nodeName, $allowed_attrs)){
1075 $tag->removeAttribute($attr->nodeName);
1076 }
1077 }
1078 }
1079 }
1080 }
1081 return $xml->saveHTML();
1082 }
1083
1084 // removes unneeded <p></p> tags from HTML string
1085 // used to allow HTML in image captions
1086 public function remove_ptags($html_string) {
1087 $begin_pg_tag = strpos($html_string, '<p>');
1088 if($begin_pg_tag > -1) {
1089 $html_string = substr($html_string, $begin_pg_tag+3);
1090 $end_pg_tag = strrpos($html_string, '</p>');
1091 $updated_string = substr($html_string, 0 , $end_pg_tag);
1092 } else {
1093 $updated_string = $html_string;
1094 }
1095 return $updated_string;
1096 }
1097
1098 // determines is the license has expired
1099 public function is_valid_license($license_expires_option, $license_status_option) {
1100
1101 $expriation_date = get_option($license_expires_option);
1102 $license_status = get_option($license_status_option, 'inactive');
1103
1104 if($license_status == 'inactive');
1105 return $license_status;
1106
1107 $expire_time = strtotime($expriation_date);
1108
1109 $currnet_date_time = date('Y-m-d H:i:s');
1110 $today_time = strtotime($currnet_date_time);
1111 if($expire_time < $today_time || $license_status != 'valid') {
1112 $valid = 'expired';
1113 } else {
1114 $valid = 'valid';
1115 }
1116 return $valid;
1117 }
1118
1119 public function mg_query_vars( $vars ) {
1120 $vars[] = 'mg_page';
1121 return $vars;
1122 }
1123
1124 public function mg_get_image_info() {
1125
1126 if (isset($_POST) && check_admin_referer($this->image_gallery->nonce_image_edit['action'], $this->image_gallery->nonce_image_edit['name'])) {
1127
1128 if ((isset($_POST['image_id'])) && (strlen(trim($_POST['image_id'])) > 0))
1129 $image_id = trim(sanitize_text_field($_POST['image_id']));
1130 else
1131 $image_id = 0;
1132
1133 if($image_id) {
1134 $image = get_post($image_id);
1135
1136 $post_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
1137
1138 $image_link = get_post_meta($image->ID, 'maxgallery_attachment_image_link', true);
1139
1140 $action_link_text = get_post_meta($image->ID, 'maxgallery_attachment_action_link_text', true);
1141
1142 $image_html = wp_get_attachment_image($image->ID, MAXGALLERIA_META_IMAGE_THUMB_LARGE);
1143
1144 $data = array ('post_title' => esc_html($image->post_title), 'post_alt' => esc_attr($post_alt), 'caption' => wp_kses_post($image->post_excerpt), 'image_link' => esc_url($image_link), 'action_link_text' => wp_kses_post($action_link_text), 'image_html' => $image_html);
1145 echo json_encode($data);
1146
1147 }
1148
1149 }
1150 die();
1151
1152 }
1153
1154 public function mg_save_image_info() {
1155
1156 if (isset($_POST) && check_admin_referer($this->image_gallery->nonce_image_edit['action'], $this->image_gallery->nonce_image_edit['name'])) {
1157
1158 if ((isset($_POST['image_id'])) && (strlen(trim($_POST['image_id'])) > 0))
1159 $image_id = trim(sanitize_text_field($_POST['image_id']));
1160 else
1161 $image_id = 0;
1162
1163 if ((isset($_POST['post_title'])) && (strlen(trim($_POST['post_title'])) > 0))
1164 $post_title = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($_POST['post_title']));
1165 else
1166 $post_title = '';
1167
1168 if ((isset($_POST['caption'])) && (strlen(trim($_POST['caption'])) > 0))
1169 $post_excerpt = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($_POST['caption']));
1170 else
1171 $post_excerpt = '';
1172
1173 if ((isset($_POST['post_alt'])) && (strlen(trim($_POST['post_alt'])) > 0))
1174 $post_alt = stripslashes(sanitize_text_field($_POST['post_alt']));
1175 else
1176 $post_alt = '';
1177
1178 if ((isset($_POST['image_link'])) && (strlen(trim($_POST['image_link'])) > 0)) {
1179 $image_link = sanitize_url($_POST['image_link']);
1180 if ($image_link != '' && !$this->common->string_starts_with($image_link, 'http://') && !$this->common->string_starts_with($image_link, 'https://') ) {
1181 $image_link = 'http://' . $image_link;
1182 }
1183 } else
1184 $image_link = '';
1185
1186 if ((isset($_POST['action_link_text'])) && (strlen(trim($_POST['action_link_text'])) > 0))
1187 $action_link_text = stripslashes(sanitize_text_field($_POST['action_link_text']));
1188 else
1189 $action_link_text = '';
1190
1191 if ((isset($_POST['template'])) && (strlen(trim($_POST['template'])) > 0))
1192 $template = stripslashes(sanitize_text_field($_POST['template']));
1193 else
1194 $template = '';
1195
1196
1197 if($image_id != 0) {
1198
1199 $temp = array();
1200 $temp['ID'] = $image_id;
1201 $temp['post_title'] = $this->remove_ptags($post_title);
1202 $temp['post_excerpt'] = $this->remove_ptags($post_excerpt);
1203 wp_update_post($temp);
1204
1205 update_post_meta($image_id, '_wp_attachment_image_alt', $post_alt);
1206
1207 update_post_meta($image_id, 'maxgallery_attachment_image_link', stripslashes($image_link));
1208
1209 if($template === 'material-design') {
1210 update_post_meta($image_id, 'maxgallery_attachment_action_link_text', $action_link_text);
1211 }
1212
1213 }
1214
1215 }
1216
1217 die();
1218 }
1219
1220 public function mg_display_bulk_edit() {
1221
1222 $html = '';
1223
1224 if (isset($_POST) && check_admin_referer($this->image_gallery->nonce_image_edit['action'], $this->image_gallery->nonce_image_edit['name'])) {
1225
1226 if ((isset($_POST['image_ids'])) && (strlen(trim($_POST['image_ids'])) > 0))
1227 $image_ids = trim(sanitize_text_field($_POST['image_ids']));
1228 else
1229 $image_ids = '';
1230
1231 if (isset($image_ids)) {
1232 $image_ids_array = explode(',', $image_ids);
1233
1234 $html .= '<table id="bulk-edit-table" cellpadding="0" cellspacing="0">' . PHP_EOL;
1235 foreach ($image_ids_array as $image_id) {
1236 if (isset($image_id)) {
1237 $image = get_post($image_id);
1238 if (isset($image)) {
1239 $html .= ' <tr>' . PHP_EOL;
1240 $html .= ' <td class="thumb">' . PHP_EOL;
1241 $html .= wp_get_attachment_image($image->ID, MAXGALLERIA_META_IMAGE_THUMB_SMALL) . PHP_EOL;
1242 $html .= ' <input type="hidden" name="image-edit-id[]" value="' . esc_attr($image->ID) . '" />' . PHP_EOL;
1243 $html .= ' </td>' . PHP_EOL;
1244 $html .= ' <td>' . PHP_EOL;
1245 $html .= ' <div class="fields">' . PHP_EOL;
1246 $html .= ' <div class="field">' . PHP_EOL;
1247 $html .= ' <div class="field-label">' . esc_html__('Title', 'maxgalleria') . '</div>' . PHP_EOL;
1248 $html .= ' <div class="field-value">' . PHP_EOL;
1249 $html .= ' <input type="text" name="image-edit-title[]" value="' . esc_html($image->post_title) .'" />' . PHP_EOL;
1250 $html .= ' </div>' . PHP_EOL;
1251 $html .= ' </div>' . PHP_EOL;
1252 $html .= ' <div class="clear"></div>' . PHP_EOL;
1253
1254 $html .= ' <div class="field">' . PHP_EOL;
1255 $html .= ' <div class="field-label">' . esc_html__('Alt Text', 'maxgalleria') . '</div>' . PHP_EOL;
1256 $html .= ' <div class="field-value">' . PHP_EOL;
1257 $html .= ' <input type="text" name="image-edit-alt[]" value="' . esc_html(get_post_meta($image->ID, '_wp_attachment_image_alt', true)) . '" />' . PHP_EOL;
1258 $html .= ' </div>' . PHP_EOL;
1259 $html .= ' </div>' . PHP_EOL;
1260 $html .= ' <div class="clear"></div>' . PHP_EOL;
1261
1262 $html .= ' <div class="field">' . PHP_EOL;
1263 $html .= ' <div class="field-label">'. esc_html__('Caption', 'maxgalleria') . '</div>' . PHP_EOL;
1264 $html .= ' <div class="field-value">' . PHP_EOL;
1265 $html .= ' <input type="text" name="image-edit-caption[]" value="' . esc_html($image->post_excerpt) . '" />' . PHP_EOL;
1266 $html .= ' </div>' . PHP_EOL;
1267 $html .= ' </div>' . PHP_EOL;
1268 $html .= ' <div class="clear"></div>' . PHP_EOL;
1269
1270 $html .= ' <div class="field">' . PHP_EOL;
1271 $html .= ' <div class="field-label">' . esc_html__('Link', 'maxgalleria') . '</div>' . PHP_EOL;
1272 $html .= ' <div class="field-value last">' . PHP_EOL;
1273 $html .= ' <input type="text" name="image-edit-link[]" value="' . esc_url(get_post_meta($image->ID, 'maxgallery_attachment_image_link', true)) . '" />' . PHP_EOL;
1274 $html .= ' </div>' . PHP_EOL;
1275 $html .= ' </div>' . PHP_EOL;
1276 $html .= ' <div class="clear"></div>' . PHP_EOL;
1277 $html .= ' </div>' . PHP_EOL;
1278 $html .= ' </td>' . PHP_EOL;
1279 $html .= '</tr>' . PHP_EOL;
1280 }
1281 }
1282 }
1283 $html .= '<tr>' . PHP_EOL;
1284 $html .= ' <td>' . PHP_EOL;
1285 $html .= ' <a class="btn btn-primary" id="bulk-save-button">' . esc_html__('Save Changes', 'maxgalleria') . '</a>' . PHP_EOL;
1286 $html .= ' <input type="button" class="btn" id="bulk-cancel-button" value="' . esc_html__('Cancel', 'maxgalleria') . '" />' . PHP_EOL;
1287 $html .= ' </td>' . PHP_EOL;
1288 $html .= ' <td></td>' . PHP_EOL;
1289 $html .= '</tr>' . PHP_EOL;
1290
1291 $html .= '</table>' . PHP_EOL;
1292
1293 }
1294
1295 $html .= wp_nonce_field($this->image_gallery->nonce_image_edit_bulk['action'], $this->image_gallery->nonce_image_edit_bulk['name']);
1296
1297 $allowed_html = array(
1298 'a' => array(
1299 'href' => array(),
1300 'title' => array(),
1301 'class' => array(),
1302 'id' => array()
1303 ),
1304 'img' => array(
1305 'src' => array(),
1306 'alt' => array(),
1307 'class' => array(),
1308 'loading' => array(),
1309 'srcset' => array(),
1310 'srcset' => array(),
1311 'sizes' => array(),
1312 'width' => array(),
1313 'height' => array()
1314 ),
1315 'input' => array(
1316 'id' => array(),
1317 'class' => array(),
1318 'value' => array(),
1319 'name' => array(),
1320 'type' => array()
1321 ),
1322 'div' => array(
1323 'class' => array()
1324 ),
1325 'br' => array(),
1326 'em' => array(),
1327 'strong' => array(),
1328 'table' => array(
1329 'id' => array(),
1330 'cellpadding' => array(),
1331 'cellspacing' => array()
1332 ),
1333 'tr' => array(),
1334 'td' => array(
1335 'class' => array()
1336 )
1337 );
1338
1339 echo wp_kses($html, $allowed_html);
1340
1341 }
1342
1343 die();
1344
1345 }
1346
1347 public function mg_save_bulk_info() {
1348
1349 global $wpdb;
1350 $form_data = '';
1351
1352 if (isset($_POST) && check_admin_referer($this->image_gallery->nonce_image_edit_bulk['action'], $this->image_gallery->nonce_image_edit_bulk['name'])) {
1353
1354 if ((isset($_POST['template'])) && (strlen(trim($_POST['template'])) > 0))
1355 $template = trim(sanitize_text_field($_POST['template']));
1356 else
1357 $template = '';
1358
1359 if ((isset($_POST['form_data'])) && (strlen(trim($_POST['form_data'])) > 0)) {
1360 parse_str($_POST['form_data'], $form_data);
1361
1362 $i = 0;
1363 if(isset($form_data['image-edit-id'])) {
1364 foreach($form_data['image-edit-id'] as $image_edit_id) {
1365
1366 $temp = array();
1367 $temp['ID'] = sanitize_text_field($image_edit_id);
1368 $post_title = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($form_data['image-edit-title'][$i]));
1369 $post_excerpt = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($form_data['image-edit-caption'][$i]));
1370 $temp['post_title'] = $this->remove_ptags($post_title);
1371 $temp['post_excerpt'] = $this->remove_ptags($post_excerpt);
1372
1373 wp_update_post($temp);
1374
1375 // Determine if we need to prepend http:// to the link
1376 $link = esc_url_raw($form_data['image-edit-link'][$i]);
1377 if (isset($link) && $link != '') {
1378 if (!$this->common->string_starts_with($link, 'http://') && !$this->common->string_starts_with($link, 'https://')) {
1379 $link = 'http://' . $link;
1380 }
1381 }
1382
1383 // Now update the meta
1384 update_post_meta($image_edit_id, '_wp_attachment_image_alt', stripslashes(sanitize_text_field($form_data['image-edit-alt'][$i])));
1385 update_post_meta($image_edit_id, 'maxgallery_attachment_image_link', stripslashes($link));
1386
1387 if($template == 'material-design' && isset($form_data['image-edit-action-text'])) {
1388 $action_link_text = sanitize_text_field($form_data['image-edit-action-text'][$i]);
1389 update_post_meta($image->ID, 'maxgallery_attachment_action_link_text', stripslashes($action_link_text));
1390 }
1391
1392 $i++;
1393 }
1394
1395 }
1396 }
1397 }
1398 die();
1399 }
1400
1401 public function mg_get_video_info() {
1402
1403 if (isset($_POST) && check_admin_referer($this->video_gallery->nonce_video_edit['action'], $this->video_gallery->nonce_video_edit['name'])) {
1404
1405 if ((isset($_POST['video_id'])) && (strlen(trim($_POST['video_id'])) > 0))
1406 $video_id = trim(sanitize_text_field($_POST['video_id']));
1407 else
1408 $video_id = 0;
1409
1410 if($video_id != 0) {
1411
1412 $video = get_post($video_id);
1413
1414 $post_alt = get_post_meta($video_id, '_wp_attachment_image_alt', true);
1415
1416 $image_html = wp_get_attachment_image($video->ID, MAXGALLERIA_META_IMAGE_THUMB_LARGE);
1417
1418 $data = array ('post_title' => esc_html($video->post_title), 'post_alt' => esc_attr($post_alt), 'caption' => wp_kses_post($video->post_excerpt), 'image_html' => $image_html);
1419 echo json_encode($data);
1420
1421 }
1422
1423 }
1424
1425 die();
1426 }
1427
1428 public function mg_save_video_info() {
1429
1430
1431 if (isset($_POST) && check_admin_referer($this->video_gallery->nonce_video_edit['action'], $this->video_gallery->nonce_video_edit['name'])) {
1432
1433
1434 if ((isset($_POST['video_id'])) && (strlen(trim($_POST['video_id'])) > 0))
1435 $video_id = trim(sanitize_text_field($_POST['video_id']));
1436 else
1437 $video_id = 0;
1438
1439 if ((isset($_POST['post_title'])) && (strlen(trim($_POST['post_title'])) > 0))
1440 $post_title = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($_POST['post_title']));
1441 else
1442 $post_title = '';
1443
1444 if ((isset($_POST['caption'])) && (strlen(trim($_POST['caption'])) > 0))
1445 $post_excerpt = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($_POST['caption']));
1446 else
1447 $post_excerpt = '';
1448
1449 if ((isset($_POST['post_alt'])) && (strlen(trim($_POST['post_alt'])) > 0))
1450 $post_alt = stripslashes(sanitize_text_field($_POST['post_alt']));
1451 else
1452 $post_alt = '';
1453
1454 if($video_id != 0) {
1455
1456 $video = get_post($video_id);
1457
1458 // First update the post itself
1459 $temp = array();
1460 $temp['ID'] = $video->ID;
1461
1462 $temp['post_title'] = $this->remove_ptags($post_title);
1463 $temp['post_excerpt'] = $this->remove_ptags($post_excerpt);
1464
1465 wp_update_post($temp);
1466
1467 update_post_meta($video->ID, '_wp_attachment_image_alt', $post_alt);
1468
1469 update_post_meta($video->ID, 'maxgallery_attachment_video_enable_related_videos', 1);
1470
1471 update_post_meta($video->ID, 'maxgallery_attachment_video_enable_hd_playback', 1);
1472
1473 }
1474
1475 }
1476
1477 die();
1478
1479 }
1480
1481 public function mg_display_bulk_video() {
1482
1483 $html = '';
1484
1485 if (isset($_POST) && check_admin_referer($this->video_gallery->nonce_video_edit['action'], $this->video_gallery->nonce_video_edit['name'])) {
1486
1487 if ((isset($_POST['video_ids'])) && (strlen(trim($_POST['video_ids'])) > 0))
1488 $video_ids = trim(sanitize_text_field($_POST['video_ids']));
1489 else
1490 $video_ids = '';
1491
1492 if (isset($video_ids)) {
1493 $video_ids_array = explode(',', $video_ids);
1494
1495 $html .= '<table id="bulk-edit-table" cellpadding="0" cellspacing="0">' . PHP_EOL;
1496 foreach ($video_ids_array as $video_id) {
1497 if (isset($video_id)) {
1498 $video = get_post($video_id);
1499 if (isset($video)) {
1500
1501 $html .= ' <tr>' . PHP_EOL;
1502 $html .= ' <td class="thumb">' . PHP_EOL;
1503 $html .= wp_get_attachment_image($video->ID, MAXGALLERIA_META_VIDEO_THUMB_SMALL);
1504 $html .= ' <input type="hidden" name="video-edit-id[]" value="' . esc_attr($video->ID) . '" />' . PHP_EOL;
1505 $html .= ' </td>' . PHP_EOL;
1506 $html .= ' <td>' . PHP_EOL;
1507 $html .= ' <div class="fields">' . PHP_EOL;
1508 $html .= ' <div class="field">' . PHP_EOL;
1509 $html .= ' <div class="field-label">' . esc_html__('Title', 'maxgalleria') . '</div>' . PHP_EOL;
1510 $html .= ' <div class="field-value">' . PHP_EOL;
1511 $html .= ' <input type="text" name="video-edit-title[]" value="' . esc_html($video->post_title) . '" />' . PHP_EOL;
1512 $html .= ' </div>' . PHP_EOL;
1513 $html .= ' </div>' . PHP_EOL;
1514 $html .= ' <div class="clear"></div>' . PHP_EOL;
1515
1516 $html .= ' <div class="field">' . PHP_EOL;
1517 $html .= ' <div class="field-label">' . esc_html__('Alt Text', 'maxgalleria') . '</div>' . PHP_EOL;
1518 $html .= ' <div class="field-value">' . PHP_EOL;
1519 $html .= ' <input type="text" name="video-edit-alt[]" value="' . esc_html(get_post_meta($video->ID, '_wp_attachment_image_alt', true)) . '" />' . PHP_EOL;
1520 $html .= ' </div>' . PHP_EOL;
1521 $html .= ' </div>' . PHP_EOL;
1522 $html .= ' <div class="clear"></div>' . PHP_EOL;
1523
1524 $html .= ' <div class="field">' . PHP_EOL;
1525 $html .= ' <div class="field-label">' . esc_html__('Caption', 'maxgalleria') .'</div>' . PHP_EOL;
1526 $html .= ' <div class="field-value">' . PHP_EOL;
1527 $html .= ' <input type="text" name="video-edit-caption[]" value="' . esc_html($video->post_excerpt) . '" />' . PHP_EOL;
1528 $html .= ' </div>' . PHP_EOL;
1529 $html .= ' </div>' . PHP_EOL;
1530 $html .= ' <div class="clear"></div>' . PHP_EOL;
1531 $html .= ' </div>' . PHP_EOL;
1532 $html .= ' </td>' . PHP_EOL;
1533 $html .= ' </tr>' . PHP_EOL;
1534 }
1535 }
1536 }
1537 $html .= '<tr>' . PHP_EOL;
1538 $html .= ' <td></td>' . PHP_EOL;
1539 $html .= ' <td>' . PHP_EOL;
1540 $html .= ' <a class="btn btn-primary" id="bulk-save-button">' . esc_html__('Save Changes', 'maxgalleria') . '</a>' . PHP_EOL;
1541 $html .= ' <input type="button" class="btn" id="bulk-cancel-button" value="' . esc_html__('Cancel', 'maxgalleria') . '" />' . PHP_EOL;
1542 $html .= ' </td>' . PHP_EOL;
1543 $html .= ' <td></td>' . PHP_EOL;
1544 $html .= '</tr>' . PHP_EOL;
1545
1546 $html .= '</table>' . PHP_EOL;
1547
1548 }
1549
1550 $html .= wp_nonce_field($this->video_gallery->nonce_video_edit_bulk['action'], $this->video_gallery->nonce_video_edit_bulk['name']);
1551
1552 $allowed_html = array(
1553 'a' => array(
1554 'href' => array(),
1555 'title' => array(),
1556 'class' => array(),
1557 'id' => array()
1558 ),
1559 'img' => array(
1560 'src' => array(),
1561 'alt' => array(),
1562 'class' => array(),
1563 'loading' => array(),
1564 'srcset' => array(),
1565 'srcset' => array(),
1566 'sizes' => array(),
1567 'width' => array(),
1568 'height' => array()
1569 ),
1570 'input' => array(
1571 'id' => array(),
1572 'class' => array(),
1573 'value' => array(),
1574 'name' => array(),
1575 'type' => array()
1576 ),
1577 'div' => array(
1578 'class' => array()
1579 ),
1580 'br' => array(),
1581 'em' => array(),
1582 'strong' => array(),
1583 'table' => array(
1584 'id' => array(),
1585 'cellpadding' => array(),
1586 'cellspacing' => array()
1587 ),
1588 'tr' => array(),
1589 'td' => array(
1590 'class' => array()
1591 )
1592 );
1593
1594 echo wp_kses($html, $allowed_html);
1595
1596 }
1597
1598 die();
1599
1600 }
1601
1602 public function mg_save_bulk_video() {
1603
1604 global $wpdb;
1605 $form_data = '';
1606
1607 if (isset($_POST) && check_admin_referer($this->video_gallery->nonce_video_edit_bulk['action'], $this->video_gallery->nonce_video_edit_bulk['name'])) {
1608
1609 if ((isset($_POST['form_data'])) && (strlen(trim($_POST['form_data'])) > 0)) {
1610 parse_str($_POST['form_data'], $form_data);
1611
1612 if(isset($form_data['video-edit-id'])) {
1613
1614 $i = 0;
1615
1616 foreach ($form_data['video-edit-id'] as $video_edit_id) {
1617 // First update the post itself
1618 $temp = array();
1619 $temp['ID'] = sanitize_text_field($video_edit_id);
1620
1621 $post_title = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($form_data['video-edit-title'][$i]));
1622 $post_excerpt = $this->stripUnwantedTagsAndAttrs(wp_filter_post_kses($form_data['video-edit-caption'][$i]));
1623
1624 $temp['post_title'] = $this->remove_ptags($post_title);
1625 $temp['post_excerpt'] = $this->remove_ptags($post_excerpt);
1626
1627 wp_update_post($temp);
1628
1629 // Now update the image alt in the meta
1630 update_post_meta($video_edit_id, '_wp_attachment_image_alt', stripslashes(sanitize_text_field($form_data['video-edit-alt'][$i])));
1631
1632 // Increment the counter
1633 $i++;
1634 }
1635
1636 }
1637
1638 }
1639
1640 }
1641
1642 die();
1643
1644 }
1645
1646 private function check_for_mp4_video($gallery, $video_url, $uploads_dir) {
1647 global $wpdb;
1648 $updated = false;
1649
1650 $comma_position = strpos($video_url, ',');
1651 if($comma_position !== false) {
1652 $comma_position2 = strrpos($video_url, ',');
1653
1654 $video = esc_url_raw(substr($video_url, 0, $comma_position ));
1655 $thumb_url = esc_url_raw(substr($video_url, $comma_position+1, $comma_position2 - ($comma_position+1) ));
1656 $thumb_id = sanitize_text_field(substr($video_url, $comma_position2+1));
1657
1658 $video_path = str_replace( $uploads_dir['baseurl'], $uploads_dir['basedir'], $video );
1659 $thumbnail_path = str_replace( $uploads_dir['baseurl'], $uploads_dir['basedir'], $thumb_url );
1660
1661 require_once(ABSPATH . 'wp-admin/includes/media.php');
1662
1663 $filetype = wp_check_filetype(basename($thumbnail_path), null);
1664 $data = wp_read_video_metadata($video_path);
1665
1666 // Include image.php so we can call wp_generate_attachment_metadata()
1667 require_once(ABSPATH . 'wp-admin/includes/image.php');
1668
1669 // Insert the attachment
1670 $attachment_id = $thumb_id;
1671
1672 // update the partent of the post thumbnail record
1673 $menu_order = $this->common->get_next_menu_order($gallery->ID);
1674
1675 $post_table = $wpdb->prefix . "posts";
1676 $record = array('post_parent' => $gallery->ID, 'menu_order' => $menu_order );
1677 $where = array('ID' => $thumb_id);
1678 $wpdb->update( $post_table, $record, $where);
1679
1680 $data['id'] = $attachment_id;
1681 if(!isset($data['duration']) && isset($data['length']))
1682 $data['duration'] = $data['length'];
1683 if(!isset($data['title']))
1684 $data['title'] = preg_replace( '/\.[^.]+$/', '', basename($video_path));
1685
1686 // Save some of the data in the post meta of the attachment
1687 do_action(MAXGALLERIA_ACTION_VIDEO_ATTACHMENT_POST_META, $attachment_id, $video, $thumb_url, $data);
1688 $updated = true;
1689 }
1690 return $updated;
1691 }
1692
1693 public function mg_add_videos() {
1694
1695 global $wpdb;
1696 //global $maxgalleria;
1697 //$video_gallery = $this->video_gallery;
1698
1699 if (isset($_POST) && check_admin_referer($this->video_gallery->nonce_video_add['action'], $this->video_gallery->nonce_video_add['name'])) {
1700
1701 // lines could contain mixed data, so too early to sanitize until it is parsed
1702 if ((isset($_POST['video_urls'])) && (strlen(trim($_POST['video_urls'])) > 0)) {
1703 $video_urls = explode("\n", $_POST['video_urls']);
1704 foreach($video_urls as $video_url) {
1705 $video_url = sanitize_url($video_url);
1706 }
1707 } else
1708 $video_urls = '';
1709
1710 if ((isset($_POST['post_id'])) && (strlen(trim($_POST['post_id'])) > 0))
1711 $post_id = sanitize_text_field($_POST['post_id']);
1712 else
1713 $post_id = 0;
1714
1715 if(is_numeric($post_id) && $post_id != 0) {
1716
1717 $gallery = get_post($post_id);
1718
1719 do_action(MAXGALLERIA_ACTION_BEFORE_ADD_VIDEOS_TO_GALLERY, $video_urls);
1720
1721 if(class_exists('MaxGalleriaVideo'))
1722 global $maxgalleria_video;
1723
1724 $site_url = site_url();
1725 $uploads_dir = wp_upload_dir();
1726
1727 foreach ($video_urls as $video_url) {
1728
1729 // Use rtrim to remove the \n on the end of the strings
1730 $video_url = rtrim($video_url);
1731
1732 if ($video_url != '') {
1733
1734 if(strpos($video_url, '.mp4') != false)
1735 $mp4 = true;
1736 else
1737 $mp4 = false;
1738
1739 if(class_exists('MaxGalleriaVideo') && class_exists("MaxGalleriaMediaLibProS3") && $mp4) {
1740
1741 global $maxgalleria_media_library_pro_s3;
1742
1743 if(strpos($video_url, $maxgalleria_media_library_pro_s3->bucket) != false) {
1744 $updated = $this->check_for_mp4_video($gallery, $video_url, $uploads_dir);
1745 }
1746 } else {
1747
1748 $updated = $this->check_for_mp4_video($gallery, $video_url, $uploads_dir);
1749
1750 $video_url = sanitize_url($video_url);
1751 // is this a vimeo url?
1752 if( strpos($video_url, "vimeo.com") === false) {
1753 $vimeo = false;
1754 if(strpos($video_url, "youtube.com") != false) {
1755 $page_link = strpos($video_url, "youtube.com/watch?v=");
1756
1757 // if an yourtube embedded url convert it to a page link
1758 if($page_link === false) {
1759 $video_pos = strrpos($video_url, '/');
1760 $video_url = "https://www.youtube.com/watch?v=" . substr($video_url, $video_pos+1);
1761 }
1762 }
1763 } else {
1764 $vimeo = true;
1765 }
1766
1767 // Get the data for the video; first initialize the API URL
1768 // and then pass it to the filter so it can get populated
1769 $api_url = '';
1770 $api_url = apply_filters(MAXGALLERIA_FILTER_VIDEO_API_URL, $api_url, $video_url);
1771
1772
1773 // Continue only if we have an API URL to call
1774 if ($api_url != '') {
1775 // Perform a remote GET to get the body of data from
1776 // the API URL and then decode it into JSON bits
1777 $response = wp_remote_get($api_url);
1778 $contents = wp_remote_retrieve_body($response);
1779 $data = json_decode($contents, true);
1780
1781
1782 // Get the URL of the video thumbnail; first initialize the thumb
1783 // URL and then pass it to the filter so it can get populated
1784 $thumb_url = '';
1785 $thumb_url = apply_filters(MAXGALLERIA_FILTER_VIDEO_THUMB_URL, $thumb_url, $video_url, $data);
1786
1787 // Now that we have the thumb URL, get its remote contents
1788 // so we can store it as an attachment for the gallery
1789 $response = wp_remote_get($thumb_url);
1790 $contents = wp_remote_retrieve_body($response);
1791
1792 // Upload and get file data
1793 $default_name = basename($thumb_url);
1794 $position = strrpos($default_name, '.');
1795
1796 if($vimeo)
1797 $new_file_name = $data[0]['title'];
1798 else
1799 $new_file_name = $data['items'][0]['snippet']['title'];
1800
1801 // remove illegal characters
1802 $new_file_name = preg_replace("[\\~#%&*{}/:<>?|\"-]", "", $new_file_name);
1803 // replace spaces
1804 $new_file_name = str_replace(' ', '-', $new_file_name);
1805 // remove extra dashes
1806 $new_file_name = preg_replace('/-+/', '-', $new_file_name);
1807 // limit to 30 characters
1808 $new_file_name = substr($new_file_name, 0, 30);
1809 // remove ending dashes
1810 $new_file_name = rtrim($new_file_name, '-');
1811 // add the extention
1812 $new_file_name = $new_file_name . substr($default_name, $position);
1813 //$upload = wp_upload_bits(basename($thumb_url), null, $contents);
1814
1815 if($vimeo) // add missing extention
1816 $new_file_name .= '.jpg';
1817
1818 $upload = wp_upload_bits($new_file_name, null, $contents);
1819
1820 $guid = $upload['url'];
1821 $file = $upload['file'];
1822 $file_type = wp_check_filetype(basename($file), null);
1823
1824 // Set up the video thumb as an attachment; first initialize the
1825 // attachment and then pass it to the filter so it can get populated
1826 $attachment = array();
1827 $attachment = apply_filters(MAXGALLERIA_FILTER_VIDEO_ATTACHMENT, $attachment, $video_url, $gallery->ID, $guid, $file_type['type'], $data);
1828
1829 // Include image.php so we can call wp_generate_attachment_metadata()
1830 require_once(ABSPATH . 'wp-admin/includes/image.php');
1831
1832 // Insert the attachment
1833 $attachment_id = wp_insert_attachment($attachment, $file, $gallery->ID);
1834 $attachment_data = wp_generate_attachment_metadata($attachment_id, $file);
1835 wp_update_attachment_metadata($attachment_id, $attachment_data);
1836
1837
1838 if(class_exists("MaxGalleriaMediaLibProS3")) {
1839
1840 global $maxgalleria_media_library_pro_s3;
1841
1842 $image_url = wp_get_attachment_url($attachment_id);
1843 $filename = get_attached_file($attachment_id);
1844
1845 // upload the image
1846 $post_type = 'attachment';
1847 $location = $maxgalleria_media_library_pro_s3->get_location($image_url, $maxgalleria_media_library_pro_s3->maxgalleria_media_library_pro->uploads_folder_name);
1848 $destination_location = $maxgalleria_media_library_pro_s3->get_destination_location($location);
1849 $destination_folder = $maxgalleria_media_library_pro_s3->get_destination_folder($destination_location, $maxgalleria_media_library_pro_s3->maxgalleria_media_library_pro->uploads_folder_name_length);
1850 $upload_result = $maxgalleria_media_library_pro_s3->upload_to_s3($post_type, $location, $filename, $attachment_id);
1851
1852 // upload thumbnails
1853 $metadata = wp_get_attachment_metadata($attachment_id);
1854
1855 foreach($metadata['sizes'] as $thumbnail) {
1856 $source_file = $maxgalleria_media_library_pro_s3->maxgalleria_media_library_pro->get_absolute_path($maxgalleria_media_library_pro_s3->uploadsurl . $destination_folder . $thumbnail['file']);
1857 $upload_result = $maxgalleria_media_library_pro_s3->upload_to_s3($post_type, $destination_location . '/' . $thumbnail['file'], $source_file, 0);
1858 }
1859
1860 // delete from local server
1861 if($maxgalleria_media_library_pro_s3->remove_from_local) {
1862 if($upload_result['statusCode'] == '200') {
1863 $maxgalleria_media_library_pro_s3->remove_media_file($filename);
1864 foreach($metadata['sizes'] as $thumbnail) {
1865 $source_file = $maxgalleria_media_library_pro_s3->maxgalleria_media_library_pro->get_absolute_path($maxgalleria_media_library_pro_s3->uploadsurl . $destination_folder . $thumbnail['file']);
1866 $maxgalleria_media_library_pro_s3->remove_media_file($source_file);
1867 }
1868 }
1869 }
1870 }
1871
1872 // Save some of the data in the post meta of the attachment
1873 do_action(MAXGALLERIA_ACTION_VIDEO_ATTACHMENT_POST_META, $attachment_id, $video_url, $thumb_url, $data);
1874 $updated = true;
1875 }
1876 }
1877 }
1878 }
1879
1880 do_action(MAXGALLERIA_ACTION_AFTER_ADD_VIDEOS_TO_GALLERY, $video_urls);
1881
1882 }
1883 echo 'ok';
1884
1885 }
1886
1887 die();
1888 }
1889
1890 public function has_double_slashes_except_protocol($str) {
1891 $protocol = '';
1892 if (strpos($str, 'http://') === 0) {
1893 $protocol = 'http://';
1894 $str = substr($str, 7);
1895 } elseif (strpos($str, 'https://') === 0) {
1896 $protocol = 'https://';
1897 $str = substr($str, 8);
1898 }
1899
1900 return strpos($str, '//') !== false && strpos($str, '//', strpos($str, '//') + 2) === false;
1901
1902 }
1903
1904 public function remove_double_slash_except_protocol($str) {
1905 $protocol = '';
1906 if (strpos($str, 'http://') === 0) {
1907 $protocol = 'http://';
1908 $str = substr($str, 7);
1909 } elseif (strpos($str, 'https://') === 0) {
1910 $protocol = 'https://';
1911 $str = substr($str, 8);
1912 }
1913
1914 while(strpos($str, '//') !== false) {
1915 $str = str_replace('//', '/', $str);
1916 }
1917
1918 return $protocol . $str;
1919 }
1920
1921
1922 public function remove_double_backslash($str) {
1923 while(strpos($str, '\\\\') !== false) {
1924 $str = str_replace('\\\\', '\\', $str);
1925 }
1926 return $str;
1927 }
1928
1929 }
1930
1931 // Let's get this party started
1932 $maxgalleria = new MaxGalleria();
1933
1934 ?>
1935