PluginProbe
MaxGalleria / 6.4.7
MaxGalleria v6.4.7
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.4.7, at maxgalleria.php

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