1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* All Legacy FooVideo Code lives in this class |
4
|
|
|
* Date: 19/05/2018 |
5
|
|
|
*/ |
6
|
|
|
if ( ! class_exists( 'FooGallery_Pro_Video_Legacy' ) ) { |
7
|
|
|
|
8
|
|
|
class FooGallery_Pro_Video_Legacy { |
|
|
|
|
9
|
|
|
|
10
|
|
|
function __construct() { |
|
|
|
|
11
|
|
|
add_filter( 'foogallery_is_attachment_video', array( $this, 'foogallery_is_attachment_video_legacy' ), 10, 2 ); |
12
|
|
|
|
13
|
|
|
add_filter( 'foogallery_clean_video_url', array( $this, 'foogallery_clean_video_url_legacy_filter' ) ); |
14
|
|
|
add_filter( 'foogallery_youtubekey', array( $this, 'foogallery_youtubekey_legacy_filter' ) ); |
15
|
|
|
|
16
|
|
|
//check if the old FooVideo is installed |
17
|
|
|
if ( is_admin() && class_exists('Foo_Video') ) { |
18
|
|
|
add_action( 'admin_notices', array( $this, 'display_foovideo_notice') ); |
19
|
|
|
add_action( 'admin_menu', array( $this, 'add_migration_menu' ) ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
// Ajax calls for migrating |
23
|
|
|
add_action( 'wp_ajax_foogallery_video_migration', array( $this, 'ajax_foogallery_video_migration' ) ); |
24
|
|
|
add_action( 'wp_ajax_foogallery_video_migration_reset', array( $this, 'ajax_foogallery_video_migration_reset' ) ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Legacy way of knowing if an attachment is a video |
29
|
|
|
* |
30
|
|
|
* @param $is_video |
31
|
|
|
* @param $foogallery_attachment |
32
|
|
|
* |
33
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
|
|
function foogallery_is_attachment_video_legacy( $is_video, $foogallery_attachment ) { |
|
|
|
|
36
|
|
|
$video_info = get_post_meta( $foogallery_attachment->ID, FOOGALLERY_VIDEO_POST_META, true ); |
37
|
|
|
|
38
|
|
|
return isset( $video_info ) && isset( $video_info['id'] ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Applies the legacy filter for backwards compatibility |
43
|
|
|
* @param $url |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
function foogallery_clean_video_url_legacy_filter( $url ) { |
|
|
|
|
48
|
|
|
return apply_filters( 'foogallery_foovideo_clean_video_url', $url ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function foogallery_build_class_attribute( $classes ) { |
52
|
|
|
global $current_foogallery_template; |
53
|
|
|
|
54
|
|
|
//first determine if the gallery has any videos |
55
|
|
|
|
56
|
|
|
//get the selected video icon |
57
|
|
|
$video_hover_icon = foogallery_gallery_template_setting( 'video_hover_icon', 'fg-video-default' ); |
58
|
|
|
|
59
|
|
|
//backwards compatible for the videoslider |
60
|
|
|
if ( 'videoslider' === $current_foogallery_template ) { |
61
|
|
|
switch ( $video_hover_icon ) { |
62
|
|
|
case 'video-icon-default': |
63
|
|
|
$video_hover_icon = 'rvs-flat-circle-play'; |
64
|
|
|
break; |
65
|
|
|
case 'video-icon-1': |
66
|
|
|
$video_hover_icon = 'rvs-plain-arrow-play'; |
67
|
|
|
break; |
68
|
|
|
case 'video-icon-2': |
69
|
|
|
$video_hover_icon = 'rvs-youtube-play'; |
70
|
|
|
break; |
71
|
|
|
case 'video-icon-3': |
72
|
|
|
$video_hover_icon = 'rvs-bordered-circle-play'; |
73
|
|
|
break; |
74
|
|
|
default: |
75
|
|
|
$video_hover_icon = ''; |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
switch ( $video_hover_icon ) { |
79
|
|
|
case 'video-icon-default': |
80
|
|
|
$video_hover_icon = 'fg-video-default'; |
81
|
|
|
break; |
82
|
|
|
case 'video-icon-1': |
83
|
|
|
$video_hover_icon = 'fg-video-1'; |
84
|
|
|
break; |
85
|
|
|
case 'video-icon-2': |
86
|
|
|
$video_hover_icon = 'fg-video-2'; |
87
|
|
|
break; |
88
|
|
|
case 'video-icon-3': |
89
|
|
|
$video_hover_icon = 'fg-video-3'; |
90
|
|
|
break; |
91
|
|
|
case 'video-icon-4': |
92
|
|
|
$video_hover_icon = 'fg-video-4'; |
93
|
|
|
break; |
94
|
|
|
default: |
95
|
|
|
$video_hover_icon = ''; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
//include the video icon class |
100
|
|
|
$classes[] = $video_hover_icon; |
101
|
|
|
//get the video icon sticky state |
102
|
|
|
$video_icon_sticky = foogallery_gallery_template_setting( 'foovideo_sticky_icon', '' ); |
103
|
|
|
if ( 'videoslider' === $current_foogallery_template && '' === $video_icon_sticky ) { |
104
|
|
|
$video_icon_sticky = 'rvs-show-play-on-hover'; |
105
|
|
|
} |
106
|
|
|
//include the video sticky class |
107
|
|
|
$classes[] = $video_icon_sticky; |
108
|
|
|
return $classes; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Display a message if the FooVideo extension is also installed |
113
|
|
|
*/ |
114
|
|
|
function display_foovideo_notice() { |
|
|
|
|
115
|
|
|
?> |
116
|
|
|
<div class="notice error"> |
117
|
|
|
<p> |
118
|
|
|
<strong><?php _e('FooVideo Extension Redundant!', 'foogallery'); ?></strong><br/> |
119
|
|
|
<?php _e('You have both FooGallery PRO and the legacy FooVideo extension activated. FooGallery PRO now includes all the video features that FooVideo had, plus more! Which means the FooVideo extension is now redundant.', 'foogallery'); ?> |
120
|
|
|
<br/> |
121
|
|
|
<?php _e('Your video galleries will continue to work, but we recommend you migrate them across to FooGallery PRO and then deactivate FooVideo.', 'foogallery'); ?> |
122
|
|
|
<br/> |
123
|
|
|
<br/> |
124
|
|
|
<a href="#" class="button button-primary button-large"><?php _e('Migrate Video Galleries', 'foogallery'); ?></a> |
125
|
|
|
<br/> |
126
|
|
|
<br/> |
127
|
|
|
</p> |
128
|
|
|
</div> |
129
|
|
|
<?php |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Outputs the video migration view |
134
|
|
|
*/ |
135
|
|
|
function render_video_migration_view() { |
|
|
|
|
136
|
|
|
require_once 'view-video-migration.php'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Add a new menu item for running the migration |
141
|
|
|
*/ |
142
|
|
|
function add_migration_menu() { |
|
|
|
|
143
|
|
|
foogallery_add_submenu_page( __( 'Video Migration', 'foogallery' ), 'manage_options', 'foogallery-video-migration', array( $this, 'render_video_migration_view', ) ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function ajax_foogallery_video_migration() { |
|
|
|
|
147
|
|
|
if ( check_admin_referer( 'foogallery_video_migration' ) ) { |
148
|
|
|
$helper = new FooGallery_Pro_Video_Migration_Helper(); |
149
|
|
|
$state = $helper->run_next_migration_step(); |
150
|
|
|
header( 'Content-type: application/json' ); |
151
|
|
|
echo json_encode( $state ); |
152
|
|
|
} |
153
|
|
|
die(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
function ajax_foogallery_video_migration_reset() { |
|
|
|
|
157
|
|
|
if ( check_admin_referer( 'foogallery_video_migration' ) ) { |
158
|
|
|
$helper = new FooGallery_Pro_Video_Migration_Helper(); |
159
|
|
|
$state = $helper->reset_state(); |
160
|
|
|
header( 'Content-type: application/json' ); |
161
|
|
|
echo json_encode( $state ); |
162
|
|
|
} |
163
|
|
|
die(); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.