extension.class.php
6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* Slider Revolution
*
* @package Essential_Grid
* @author ThemePunch <info@themepunch.com>
* @link http://www.revolution.themepunch.com/
* @copyright 2015 ThemePunch
*/
/**
* @package RevSliderExtension
* @author ThemePunch <info@themepunch.com>
*/
if( !defined( 'ABSPATH') ) exit();
class RevSliderExtension {
public function __construct() {
$this->init_essential_grid_extensions();
}
/***************************
* Setup part for Revslider inclusion into Essential Grid
***************************/
/**
* Do all initializations for RevSlider integration
*/
public function init_essential_grid_extensions(){
if(!class_exists('Essential_Grid')) return false; //only add if Essential Grid is installed
add_filter('essgrid_set_ajax_source_order', array($this, 'add_slider_to_eg_ajax'));
add_filter('essgrid_handle_ajax_content', array($this, 'set_slider_values_to_eg_ajax'), 10, 4);
add_action('essgrid_add_meta_options', array($this, 'add_eg_additional_meta_field'));
add_action('essgrid_save_meta_options', array($this, 'save_eg_additional_meta_field'), 10, 2);
//only do on frontend
add_action('admin_head', array($this, 'add_eg_additional_inline_javascript'));
add_action('wp_head', array($this, 'add_eg_additional_inline_javascript'));
}
/**
* Add Slider to the List of choosable media
*/
public function add_slider_to_eg_ajax($media){
$media['revslider'] = array('name' => __('Slider Revolution', REVSLIDER_TEXTDOMAIN), 'type' => 'ccw');
return $media;
}
/**
* Add Slider to the List of choosable media
*/
public function set_slider_values_to_eg_ajax($handle, $media_sources, $post, $grid_id){
if($handle !== 'revslider') return false;
$slider_source = '';
$values = get_post_custom($post['ID']);
if(isset($values['eg_sources_revslider'])){
if(isset($values['eg_sources_revslider'][0]))
$slider_source = (isset($values['eg_sources_revslider'][0])) ? $values['eg_sources_revslider'][0] : '';
else
$slider_source = (isset($values['eg_sources_revslider'])) ? $values['eg_sources_revslider'] : '';
}
if($slider_source === ''){
return false;
}else{
return ' data-ajaxtype="'.$handle.'" data-ajaxsource="'.$slider_source.'"';
}
}
/**
* Adds custom meta field into the essential grid meta box for post/pages
*/
public function add_eg_additional_meta_field($values){
$sld = new RevSlider();
$sliders = $sld->getArrSliders();
$shortcodes = array();
if(!empty($sliders)){
$first = true;
foreach($sliders as $slider){
$name = $slider->getParam('shortcode','false');
if($name != 'false'){
$shortcodes[$slider->getID()] = $name;
$first = false;
}
}
}
$selected_slider = (isset($values['eg_sources_revslider'])) ? $values['eg_sources_revslider'] : '';
if($selected_slider == '') $selected_slider[0] = '';
?>
<p>
<strong style="font-size:14px"><?php _e('Choose Revolution Slider', REVSLIDER_TEXTDOMAIN); ?></strong>
</p>
<p>
<select name="eg_sources_revslider" id="eg_sources_revslider">
<option value=""<?php selected($selected_slider[0], ''); ?>><?php _e('--- Choose Slider ---', REVSLIDER_TEXTDOMAIN); ?></option>
<?php
if(!empty($shortcodes)){
foreach($shortcodes as $id => $name){
?>
<option value="<?php echo $id; ?>"<?php selected($selected_slider[0], $id); ?>><?php echo $name; ?></option>
<?php
}
}
?>
</select>
</p>
<?php
}
/**
* Adds custom meta field into the essential grid meta box for post/pages
*/
public function save_eg_additional_meta_field($metas, $post_id){
if(isset($metas['eg_sources_revslider']))
update_post_meta($post_id, 'eg_sources_revslider', $metas['eg_sources_revslider']);
}
/**
* Adds needed javascript to the DOM
*/
public function add_eg_additional_inline_javascript(){
?>
<script type="text/javascript">
jQuery(document).ready(function() {
// CUSTOM AJAX CONTENT LOADING FUNCTION
var ajaxRevslider = function(obj) {
// obj.type : Post Type
// obj.id : ID of Content to Load
// obj.aspectratio : The Aspect Ratio of the Container / Media
// obj.selector : The Container Selector where the Content of Ajax will be injected. It is done via the Essential Grid on Return of Content
var content = "";
data = {};
data.action = 'revslider_ajax_call_front';
data.client_action = 'get_slider_html';
data.token = '<?php echo wp_create_nonce("RevSlider_Front"); ?>';
data.type = obj.type;
data.id = obj.id;
data.aspectratio = obj.aspectratio;
// SYNC AJAX REQUEST
jQuery.ajax({
type:"post",
url:"<?php echo admin_url('admin-ajax.php'); ?>",
dataType: 'json',
data:data,
async:false,
success: function(ret, textStatus, XMLHttpRequest) {
if(ret.success == true)
content = ret.data;
},
error: function(e) {
console.log(e);
}
});
// FIRST RETURN THE CONTENT WHEN IT IS LOADED !!
return content;
};
// CUSTOM AJAX FUNCTION TO REMOVE THE SLIDER
var ajaxRemoveRevslider = function(obj) {
return jQuery(obj.selector+" .rev_slider").revkill();
};
// EXTEND THE AJAX CONTENT LOADING TYPES WITH TYPE AND FUNCTION
var extendessential = setInterval(function() {
if (jQuery.fn.tpessential != undefined) {
clearInterval(extendessential);
if(typeof(jQuery.fn.tpessential.defaults) !== 'undefined') {
jQuery.fn.tpessential.defaults.ajaxTypes.push({type:"revslider",func:ajaxRevslider,killfunc:ajaxRemoveRevslider,openAnimationSpeed:0.3});
// type: Name of the Post to load via Ajax into the Essential Grid Ajax Container
// func: the Function Name which is Called once the Item with the Post Type has been clicked
// killfunc: function to kill in case the Ajax Window going to be removed (before Remove function !
// openAnimationSpeed: how quick the Ajax Content window should be animated (default is 0.3)
}
}
},30);
});
</script>
<?php
}
}
?>