Version Description
- 7 February 2018 =
- Slider: Add playsinline for Video backgrounds for iOS.
- Repeater field: Trigger change events for repeater when adding, removing or duplicating items.
- TinyMCE field: Removed special handling for TinyMCE fields when retrieving data. Just use field value directly.
- Fixed build overwriting some CSS files.
Download this release
Release Info
Developer | gpriday |
Plugin | ![]() |
Version | 1.11.4 |
Comparing to | |
See all releases |
Code changes from version 1.11.3 to 1.11.4
- admin/tpl/admin.php +130 -130
- base/base.php +254 -254
- base/inc/fields/checkbox.class.php +26 -26
- base/inc/fields/js/tinymce-field.js +112 -112
- base/inc/fields/slider.class.php +49 -49
- base/inc/fields/tinymce.class.php +525 -525
- base/inc/post-selector.php +134 -134
- base/inc/widget-manager.class.php +167 -167
- base/inc/widgets/base-slider.class.php +341 -341
- base/js/admin.js +1292 -1303
- base/js/admin.min.js +1 -1
- compat/beaver-builder/beaver-builder.php +97 -97
- compat/compat.php +55 -55
- js/sow.google.map.js +473 -473
- lang/so-widgets-bundle.pot +436 -432
- readme.txt +8 -2
- so-widgets-bundle.php +795 -795
- widgets/accordion/js/accordion.js +111 -111
- widgets/accordion/styles/default.less +105 -105
- widgets/accordion/tpl/default.php +41 -41
- widgets/button/button.php +382 -382
- widgets/button/css/style.css +1 -45
- widgets/button/styles/atom.less +59 -59
- widgets/button/styles/flat.less +59 -59
- widgets/button/styles/wire.less +56 -56
- widgets/contact/contact.php +1283 -1283
- widgets/contact/js/contact.js +63 -63
- widgets/contact/styles/default.less +231 -231
- widgets/contact/tpl/default.php +58 -58
- widgets/cta/css/style.css +1 -42
- widgets/cta/cta.php +139 -131
- widgets/cta/styles/default.less +66 -66
- widgets/features/css/style.css +1 -58
- widgets/features/features.php +315 -315
- widgets/features/styles/default.less +187 -187
- widgets/google-map/css/style.css +1 -11
- widgets/google-map/google-map.php +694 -694
- widgets/hero/hero.php +447 -447
- widgets/hero/styles/default.less +119 -119
- widgets/image-grid/css/image-grid.css +1 -11
- widgets/post-carousel/css/style.css +1 -160
- widgets/social-media-buttons/social-media-buttons.php +306 -306
- widgets/social-media-buttons/styles/widget-mixins.less +46 -46
- widgets/tabs/js/tabs.js +82 -82
- widgets/tabs/styles/default.less +120 -120
- widgets/testimonial/css/style.css +1 -56
- widgets/testimonial/styles/default.less +188 -188
- widgets/testimonial/testimonial.php +369 -361
- widgets/testimonial/tpl/default.php +72 -72
- widgets/video/css/html-player-responsive.css +1 -5
- widgets/video/css/skin.css +1 -154
admin/tpl/admin.php
CHANGED
@@ -1,130 +1,130 @@
|
|
1 |
-
<div class="wrap" id="sow-widgets-page">
|
2 |
-
<div class="page-banner">
|
3 |
-
|
4 |
-
<span class="icon">
|
5 |
-
<img src="<?php echo siteorigin_widgets_url( 'admin/images/icon-back.png' )?>" class="icon-back" width="50" height="43">
|
6 |
-
<img src="<?php echo siteorigin_widgets_url( 'admin/images/icon-gear.png' ) ?>" class="icon-gear" width="26" height="26">
|
7 |
-
<img src="<?php echo siteorigin_widgets_url( 'admin/images/icon-front.png' ) ?>" class="icon-front" width="50" height="43">
|
8 |
-
</span>
|
9 |
-
<h1><?php _e('SiteOrigin Widgets Bundle', 'so-widgets-bundle') ?></h1>
|
10 |
-
|
11 |
-
<div id="sow-widget-search">
|
12 |
-
<input type="search" placeholder="<?php esc_attr_e('Filter Widgets', 'so-widgets-bundle') ?>" />
|
13 |
-
</div>
|
14 |
-
</div>
|
15 |
-
|
16 |
-
<ul class="page-nav">
|
17 |
-
<li class="active"><a href="#all"><?php _e('All', 'so-widgets-bundle') ?></a></li>
|
18 |
-
<li><a href="#enabled"><?php _e('Enabled', 'so-widgets-bundle') ?></a></li>
|
19 |
-
<li><a href="#disabled"><?php _e('Disabled', 'so-widgets-bundle') ?></a></li>
|
20 |
-
</ul>
|
21 |
-
|
22 |
-
|
23 |
-
<div id="widgets-list">
|
24 |
-
|
25 |
-
<?php
|
26 |
-
foreach( $widgets as $file => $widget ):
|
27 |
-
$file = wp_normalize_path( $file );
|
28 |
-
?>
|
29 |
-
<div class="so-widget-wrap">
|
30 |
-
<div class="so-widget so-widget-is-<?php echo $widget['Active'] ? 'active' : 'inactive' ?>" data-id="<?php echo esc_attr( $widget['ID'] ) ?>">
|
31 |
-
|
32 |
-
<?php
|
33 |
-
$banner = '';
|
34 |
-
$widget_dir = dirname( $file );
|
35 |
-
if( file_exists( $widget_dir . '/assets/banner.svg' ) ) {
|
36 |
-
$banner = str_replace( wp_normalize_path( WP_CONTENT_DIR ), content_url(), $widget_dir ) . '/assets/banner.svg';
|
37 |
-
}
|
38 |
-
$banner = apply_filters('siteorigin_widgets_widget_banner', $banner, $widget);
|
39 |
-
?>
|
40 |
-
<div class="so-widget-banner" data-seed="<?php echo esc_attr( substr( md5($widget['ID']), 0, 6 ) ) ?>">
|
41 |
-
<?php if( !empty( $banner ) ) : ?>
|
42 |
-
<img src="<?php echo esc_url($banner) ?>" />
|
43 |
-
<?php endif; ?>
|
44 |
-
</div>
|
45 |
-
|
46 |
-
<div class="so-widget-text">
|
47 |
-
|
48 |
-
<div class="so-widget-active-indicator"><?php _e('Active', 'so-widgets-bundle') ?></div>
|
49 |
-
|
50 |
-
<h3><?php echo esc_html( $widget['Name'] ); ?></h3>
|
51 |
-
|
52 |
-
<div class="so-widget-description">
|
53 |
-
<?php echo esc_html( $widget['Description'] ) ?>
|
54 |
-
</div>
|
55 |
-
|
56 |
-
<?php if( !empty( $widget['Author'] ) ) : ?>
|
57 |
-
<div class="so-widget-byline">
|
58 |
-
By
|
59 |
-
<strong>
|
60 |
-
<?php
|
61 |
-
if( !empty($widget['AuthorURI']) ) echo '<a href="' . esc_url( $widget['AuthorURI'] ) . '" target="_blank" rel="noopener noreferrer">';
|
62 |
-
echo esc_html( $widget['Author'] );
|
63 |
-
if( !empty($widget['AuthorURI']) ) echo '</a>';
|
64 |
-
?>
|
65 |
-
</strong>
|
66 |
-
</div>
|
67 |
-
<?php endif; ?>
|
68 |
-
|
69 |
-
<div class="so-widget-toggle-active">
|
70 |
-
<button class="button-secondary so-widget-activate" data-status="1"><?php esc_html_e( 'Activate', 'so-widgets-bundle' ) ?></button>
|
71 |
-
<button class="button-secondary so-widget-deactivate" data-status="0"><?php esc_html_e( 'Deactivate', 'so-widgets-bundle' ) ?></button>
|
72 |
-
</div>
|
73 |
-
|
74 |
-
<?php
|
75 |
-
/** @var SiteOrigin_Widget $widget_object */
|
76 |
-
$widget_object = !empty( $widget_objects[ $file ] ) ? $widget_objects[ $file ] : false;
|
77 |
-
if( !empty( $widget_object ) && $widget_object->has_form( 'settings' ) ) {
|
78 |
-
$rel_path = str_replace( wp_normalize_path( WP_CONTENT_DIR ), '', $file );
|
79 |
-
|
80 |
-
$form_url = add_query_arg( array(
|
81 |
-
'id' => $rel_path,
|
82 |
-
'action' => 'so_widgets_setting_form',
|
83 |
-
),
|
84 |
-
admin_url( 'admin-ajax.php' )
|
85 |
-
);
|
86 |
-
$form_url = wp_nonce_url( $form_url, 'display-widget-form' );
|
87 |
-
|
88 |
-
?>
|
89 |
-
<button class="button-secondary so-widget-settings" data-form-url="<?php echo esc_url( $form_url ) ?>">
|
90 |
-
<?php esc_html_e( 'Settings', 'so-widgets-bundle' ) ?>
|
91 |
-
</button>
|
92 |
-
<?php
|
93 |
-
}
|
94 |
-
?>
|
95 |
-
</div>
|
96 |
-
|
97 |
-
</div>
|
98 |
-
</div>
|
99 |
-
<?php endforeach; ?>
|
100 |
-
|
101 |
-
</div>
|
102 |
-
|
103 |
-
<div class="developers-link">
|
104 |
-
<?php _e('Developers - create your own widgets for the Widgets Bundle.', 'so-widgets-bundle') ?>
|
105 |
-
<a href="https://siteorigin.com/docs/widgets-bundle/" target="_blank" rel="noopener noreferrer"><?php _e('Read More', 'so-widgets-bundle') ?></a>.
|
106 |
-
</div>
|
107 |
-
|
108 |
-
<div id="sow-settings-dialog">
|
109 |
-
<div class="so-overlay"></div>
|
110 |
-
|
111 |
-
<div class="so-title-bar">
|
112 |
-
<h3 class="so-title"><?php _e( 'Widget Settings', 'so-widgets-bundle' ) ?></h3>
|
113 |
-
<a class="so-close">
|
114 |
-
<span class="so-dialog-icon"></span>
|
115 |
-
</a>
|
116 |
-
</div>
|
117 |
-
|
118 |
-
<div class="so-content so-loading">
|
119 |
-
</div>
|
120 |
-
|
121 |
-
<div class="so-toolbar">
|
122 |
-
<div class="so-buttons">
|
123 |
-
<button class="button-primary so-save"><?php _e( 'Save', 'so-widgets-bundle' ) ?></button>
|
124 |
-
</div>
|
125 |
-
</div>
|
126 |
-
</div>
|
127 |
-
|
128 |
-
<iframe id="so-widget-settings-save" name="so-widget-settings-save"></iframe>
|
129 |
-
|
130 |
-
</div>
|
1 |
+
<div class="wrap" id="sow-widgets-page">
|
2 |
+
<div class="page-banner">
|
3 |
+
|
4 |
+
<span class="icon">
|
5 |
+
<img src="<?php echo siteorigin_widgets_url( 'admin/images/icon-back.png' )?>" class="icon-back" width="50" height="43">
|
6 |
+
<img src="<?php echo siteorigin_widgets_url( 'admin/images/icon-gear.png' ) ?>" class="icon-gear" width="26" height="26">
|
7 |
+
<img src="<?php echo siteorigin_widgets_url( 'admin/images/icon-front.png' ) ?>" class="icon-front" width="50" height="43">
|
8 |
+
</span>
|
9 |
+
<h1><?php _e('SiteOrigin Widgets Bundle', 'so-widgets-bundle') ?></h1>
|
10 |
+
|
11 |
+
<div id="sow-widget-search">
|
12 |
+
<input type="search" placeholder="<?php esc_attr_e('Filter Widgets', 'so-widgets-bundle') ?>" />
|
13 |
+
</div>
|
14 |
+
</div>
|
15 |
+
|
16 |
+
<ul class="page-nav">
|
17 |
+
<li class="active"><a href="#all"><?php _e('All', 'so-widgets-bundle') ?></a></li>
|
18 |
+
<li><a href="#enabled"><?php _e('Enabled', 'so-widgets-bundle') ?></a></li>
|
19 |
+
<li><a href="#disabled"><?php _e('Disabled', 'so-widgets-bundle') ?></a></li>
|
20 |
+
</ul>
|
21 |
+
|
22 |
+
|
23 |
+
<div id="widgets-list">
|
24 |
+
|
25 |
+
<?php
|
26 |
+
foreach( $widgets as $file => $widget ):
|
27 |
+
$file = wp_normalize_path( $file );
|
28 |
+
?>
|
29 |
+
<div class="so-widget-wrap">
|
30 |
+
<div class="so-widget so-widget-is-<?php echo $widget['Active'] ? 'active' : 'inactive' ?>" data-id="<?php echo esc_attr( $widget['ID'] ) ?>">
|
31 |
+
|
32 |
+
<?php
|
33 |
+
$banner = '';
|
34 |
+
$widget_dir = dirname( $file );
|
35 |
+
if( file_exists( $widget_dir . '/assets/banner.svg' ) ) {
|
36 |
+
$banner = str_replace( wp_normalize_path( WP_CONTENT_DIR ), content_url(), $widget_dir ) . '/assets/banner.svg';
|
37 |
+
}
|
38 |
+
$banner = apply_filters('siteorigin_widgets_widget_banner', $banner, $widget);
|
39 |
+
?>
|
40 |
+
<div class="so-widget-banner" data-seed="<?php echo esc_attr( substr( md5($widget['ID']), 0, 6 ) ) ?>">
|
41 |
+
<?php if( !empty( $banner ) ) : ?>
|
42 |
+
<img src="<?php echo esc_url($banner) ?>" />
|
43 |
+
<?php endif; ?>
|
44 |
+
</div>
|
45 |
+
|
46 |
+
<div class="so-widget-text">
|
47 |
+
|
48 |
+
<div class="so-widget-active-indicator"><?php _e('Active', 'so-widgets-bundle') ?></div>
|
49 |
+
|
50 |
+
<h3><?php echo esc_html( $widget['Name'] ); ?></h3>
|
51 |
+
|
52 |
+
<div class="so-widget-description">
|
53 |
+
<?php echo esc_html( $widget['Description'] ) ?>
|
54 |
+
</div>
|
55 |
+
|
56 |
+
<?php if( !empty( $widget['Author'] ) ) : ?>
|
57 |
+
<div class="so-widget-byline">
|
58 |
+
By
|
59 |
+
<strong>
|
60 |
+
<?php
|
61 |
+
if( !empty($widget['AuthorURI']) ) echo '<a href="' . esc_url( $widget['AuthorURI'] ) . '" target="_blank" rel="noopener noreferrer">';
|
62 |
+
echo esc_html( $widget['Author'] );
|
63 |
+
if( !empty($widget['AuthorURI']) ) echo '</a>';
|
64 |
+
?>
|
65 |
+
</strong>
|
66 |
+
</div>
|
67 |
+
<?php endif; ?>
|
68 |
+
|
69 |
+
<div class="so-widget-toggle-active">
|
70 |
+
<button class="button-secondary so-widget-activate" data-status="1"><?php esc_html_e( 'Activate', 'so-widgets-bundle' ) ?></button>
|
71 |
+
<button class="button-secondary so-widget-deactivate" data-status="0"><?php esc_html_e( 'Deactivate', 'so-widgets-bundle' ) ?></button>
|
72 |
+
</div>
|
73 |
+
|
74 |
+
<?php
|
75 |
+
/** @var SiteOrigin_Widget $widget_object */
|
76 |
+
$widget_object = !empty( $widget_objects[ $file ] ) ? $widget_objects[ $file ] : false;
|
77 |
+
if( !empty( $widget_object ) && $widget_object->has_form( 'settings' ) ) {
|
78 |
+
$rel_path = str_replace( wp_normalize_path( WP_CONTENT_DIR ), '', $file );
|
79 |
+
|
80 |
+
$form_url = add_query_arg( array(
|
81 |
+
'id' => $rel_path,
|
82 |
+
'action' => 'so_widgets_setting_form',
|
83 |
+
),
|
84 |
+
admin_url( 'admin-ajax.php' )
|
85 |
+
);
|
86 |
+
$form_url = wp_nonce_url( $form_url, 'display-widget-form' );
|
87 |
+
|
88 |
+
?>
|
89 |
+
<button class="button-secondary so-widget-settings" data-form-url="<?php echo esc_url( $form_url ) ?>">
|
90 |
+
<?php esc_html_e( 'Settings', 'so-widgets-bundle' ) ?>
|
91 |
+
</button>
|
92 |
+
<?php
|
93 |
+
}
|
94 |
+
?>
|
95 |
+
</div>
|
96 |
+
|
97 |
+
</div>
|
98 |
+
</div>
|
99 |
+
<?php endforeach; ?>
|
100 |
+
|
101 |
+
</div>
|
102 |
+
|
103 |
+
<div class="developers-link">
|
104 |
+
<?php _e('Developers - create your own widgets for the Widgets Bundle.', 'so-widgets-bundle') ?>
|
105 |
+
<a href="https://siteorigin.com/docs/widgets-bundle/" target="_blank" rel="noopener noreferrer"><?php _e('Read More', 'so-widgets-bundle') ?></a>.
|
106 |
+
</div>
|
107 |
+
|
108 |
+
<div id="sow-settings-dialog">
|
109 |
+
<div class="so-overlay"></div>
|
110 |
+
|
111 |
+
<div class="so-title-bar">
|
112 |
+
<h3 class="so-title"><?php _e( 'Widget Settings', 'so-widgets-bundle' ) ?></h3>
|
113 |
+
<a class="so-close">
|
114 |
+
<span class="so-dialog-icon"></span>
|
115 |
+
</a>
|
116 |
+
</div>
|
117 |
+
|
118 |
+
<div class="so-content so-loading">
|
119 |
+
</div>
|
120 |
+
|
121 |
+
<div class="so-toolbar">
|
122 |
+
<div class="so-buttons">
|
123 |
+
<button class="button-primary so-save"><?php _e( 'Save', 'so-widgets-bundle' ) ?></button>
|
124 |
+
</div>
|
125 |
+
</div>
|
126 |
+
</div>
|
127 |
+
|
128 |
+
<iframe id="so-widget-settings-save" name="so-widget-settings-save"></iframe>
|
129 |
+
|
130 |
+
</div>
|
base/base.php
CHANGED
@@ -1,254 +1,254 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
include plugin_dir_path(__FILE__).'inc/fields/siteorigin-widget-field-class-loader.class.php';
|
4 |
-
include plugin_dir_path(__FILE__).'siteorigin-widget.class.php';
|
5 |
-
|
6 |
-
include plugin_dir_path(__FILE__).'inc/widget-manager.class.php';
|
7 |
-
include plugin_dir_path(__FILE__).'inc/meta-box-manager.php';
|
8 |
-
include plugin_dir_path(__FILE__).'inc/post-selector.php';
|
9 |
-
include plugin_dir_path(__FILE__).'inc/string-utils.php';
|
10 |
-
include plugin_dir_path(__FILE__).'inc/array-utils.php';
|
11 |
-
include plugin_dir_path(__FILE__).'inc/attachments.php';
|
12 |
-
include plugin_dir_path(__FILE__).'inc/actions.php';
|
13 |
-
include plugin_dir_path(__FILE__).'inc/shortcode.php';
|
14 |
-
|
15 |
-
/**
|
16 |
-
* @param $css
|
17 |
-
*/
|
18 |
-
function siteorigin_widget_add_inline_css($css){
|
19 |
-
global $siteorigin_widgets_inline_styles;
|
20 |
-
if ( empty( $siteorigin_widgets_inline_styles ) ) {
|
21 |
-
$siteorigin_widgets_inline_styles = array();
|
22 |
-
}
|
23 |
-
|
24 |
-
$siteorigin_widgets_inline_styles[] = $css;
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Print any inline styles that have been added with siteorigin_widget_add_inline_css
|
29 |
-
*/
|
30 |
-
function siteorigin_widget_print_styles(){
|
31 |
-
global $siteorigin_widgets_inline_styles;
|
32 |
-
if ( ! empty( $siteorigin_widgets_inline_styles ) ) {
|
33 |
-
foreach ($siteorigin_widgets_inline_styles as $widget_css) {
|
34 |
-
?>
|
35 |
-
<style type="text/css"><?php echo($widget_css) ?></style><?php
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
$siteorigin_widgets_inline_styles = array();
|
40 |
-
}
|
41 |
-
add_action('wp_head', 'siteorigin_widget_print_styles');
|
42 |
-
add_action('wp_footer', 'siteorigin_widget_print_styles');
|
43 |
-
|
44 |
-
/**
|
45 |
-
* The ajax handler for getting a list of available icons.
|
46 |
-
*/
|
47 |
-
function siteorigin_widget_get_icon_list(){
|
48 |
-
if(empty($_GET['family'])) exit();
|
49 |
-
if ( empty( $_REQUEST['_widgets_nonce'] ) || !wp_verify_nonce( $_REQUEST['_widgets_nonce'], 'widgets_action' ) ) return;
|
50 |
-
|
51 |
-
$widget_icon_families = apply_filters('siteorigin_widgets_icon_families', array() );
|
52 |
-
|
53 |
-
header('content-type: application/json');
|
54 |
-
echo json_encode( !empty($widget_icon_families[$_GET['family']]) ? $widget_icon_families[$_GET['family']] : array() );
|
55 |
-
exit();
|
56 |
-
}
|
57 |
-
add_action('wp_ajax_siteorigin_widgets_get_icons', 'siteorigin_widget_get_icon_list');
|
58 |
-
|
59 |
-
/**
|
60 |
-
* @param $icon_value
|
61 |
-
* @param bool $icon_styles
|
62 |
-
*
|
63 |
-
* @return bool|string
|
64 |
-
*/
|
65 |
-
function siteorigin_widget_get_icon($icon_value, $icon_styles = false) {
|
66 |
-
if( empty( $icon_value ) ) return false;
|
67 |
-
list( $family, $icon ) = explode('-', $icon_value, 2);
|
68 |
-
if( empty( $family ) || empty( $icon ) ) return false;
|
69 |
-
|
70 |
-
static $widget_icon_families;
|
71 |
-
static $widget_icons_enqueued = array();
|
72 |
-
|
73 |
-
if( empty($widget_icon_families) ) $widget_icon_families = apply_filters('siteorigin_widgets_icon_families', array() );
|
74 |
-
if( empty($widget_icon_families[$family]) || empty($widget_icon_families[$family]['icons'][$icon]) ) return false;
|
75 |
-
|
76 |
-
if(empty($widget_icons_enqueued[$family]) && !empty($widget_icon_families[$family]['style_uri'])) {
|
77 |
-
if( !wp_style_is( 'siteorigin-widget-icon-font-'.$family ) ) {
|
78 |
-
wp_enqueue_style('siteorigin-widget-icon-font-'.$family, $widget_icon_families[$family]['style_uri'] );
|
79 |
-
}
|
80 |
-
return '<span class="sow-icon-' . esc_attr($family) . '" data-sow-icon="' . $widget_icon_families[$family]['icons'][$icon] . '" ' . ( !empty($icon_styles) ? 'style="'.implode('; ', $icon_styles).'"' : '' ) . '></span>';
|
81 |
-
}
|
82 |
-
else {
|
83 |
-
return false;
|
84 |
-
}
|
85 |
-
|
86 |
-
}
|
87 |
-
|
88 |
-
/**
|
89 |
-
* @param $font_value
|
90 |
-
*
|
91 |
-
* @return array
|
92 |
-
*/
|
93 |
-
function siteorigin_widget_get_font($font_value) {
|
94 |
-
|
95 |
-
$web_safe = array(
|
96 |
-
'Helvetica Neue' => 'Arial, Helvetica, Geneva, sans-serif',
|
97 |
-
'Lucida Grande' => 'Lucida, Verdana, sans-serif',
|
98 |
-
'Georgia' => '"Times New Roman", Times, serif',
|
99 |
-
'Courier New' => 'Courier, mono',
|
100 |
-
'default' => 'default',
|
101 |
-
);
|
102 |
-
|
103 |
-
$font = array();
|
104 |
-
if ( isset( $web_safe[ $font_value ] ) ) {
|
105 |
-
$font['family'] = $web_safe[ $font_value ];
|
106 |
-
}
|
107 |
-
else if( siteorigin_widgets_is_google_webfont( $font_value ) ) {
|
108 |
-
$font_parts = explode( ':', $font_value );
|
109 |
-
$font['family'] = $font_parts[0];
|
110 |
-
$font_url_param = urlencode( $font_parts[0] );
|
111 |
-
if ( count( $font_parts ) > 1 ) {
|
112 |
-
$font['weight'] = $font_parts[1];
|
113 |
-
$font_url_param .= ':' . $font_parts[1];
|
114 |
-
}
|
115 |
-
$font['css_import'] = '@import url(https://fonts.googleapis.com/css?family=' . $font_url_param . ');';
|
116 |
-
}
|
117 |
-
else {
|
118 |
-
$font['family'] = $font_value;
|
119 |
-
$font = apply_filters( 'siteorigin_widget_get_custom_font_family', $font );
|
120 |
-
}
|
121 |
-
|
122 |
-
return $font;
|
123 |
-
}
|
124 |
-
|
125 |
-
/**
|
126 |
-
* Compatibility with Page Builder, add the groups and icons.
|
127 |
-
*
|
128 |
-
* @param $widgets
|
129 |
-
*
|
130 |
-
* @return mixed
|
131 |
-
*/
|
132 |
-
function siteorigin_widget_add_bundle_groups($widgets){
|
133 |
-
foreach( $widgets as $class => &$widget ) {
|
134 |
-
if( preg_match('/SiteOrigin_Widgets?_(.*)_Widget/i', $class, $matches) ) {
|
135 |
-
$widget['icon'] = 'so-widget-icon so-widget-icon-'.strtolower($matches[1]);
|
136 |
-
$widget['groups'] = array('so-widgets-bundle');
|
137 |
-
}
|
138 |
-
}
|
139 |
-
|
140 |
-
return $widgets;
|
141 |
-
}
|
142 |
-
add_filter('siteorigin_panels_widgets', 'siteorigin_widget_add_bundle_groups', 11);
|
143 |
-
|
144 |
-
/**
|
145 |
-
* Escape a URL
|
146 |
-
*
|
147 |
-
* @param $url
|
148 |
-
*
|
149 |
-
* @return string
|
150 |
-
*/
|
151 |
-
function sow_esc_url( $url ) {
|
152 |
-
if( preg_match('/^post: *([0-9]+)/', $url, $matches) ) {
|
153 |
-
// Convert the special post URL into a permalink
|
154 |
-
$url = get_the_permalink( intval($matches[1]) );
|
155 |
-
if( empty($url) ) return '';
|
156 |
-
}
|
157 |
-
|
158 |
-
$protocols = wp_allowed_protocols();
|
159 |
-
$protocols[] = 'skype';
|
160 |
-
return esc_url( $url, $protocols );
|
161 |
-
}
|
162 |
-
|
163 |
-
/**
|
164 |
-
* A special URL escaping function that handles additional protocols
|
165 |
-
*
|
166 |
-
* @param $url
|
167 |
-
*
|
168 |
-
* @return string
|
169 |
-
*/
|
170 |
-
function sow_esc_url_raw( $url ) {
|
171 |
-
if( preg_match('/^post: *([0-9]+)/', $url, $matches) ) {
|
172 |
-
// Convert the special post URL into a permalink
|
173 |
-
$url = get_the_permalink( intval($matches[1]) );
|
174 |
-
}
|
175 |
-
|
176 |
-
$protocols = wp_allowed_protocols();
|
177 |
-
$protocols[] = 'skype';
|
178 |
-
return esc_url_raw( $url, $protocols );
|
179 |
-
}
|
180 |
-
|
181 |
-
/**
|
182 |
-
* Get all the Google Web Fonts.
|
183 |
-
*
|
184 |
-
* @return mixed|void
|
185 |
-
*/
|
186 |
-
function siteorigin_widgets_fonts_google_webfonts( ) {
|
187 |
-
$fonts = include plugin_dir_path( __FILE__ ) . 'inc/fonts.php';
|
188 |
-
$fonts = apply_filters( 'siteorigin_widgets_google_webfonts', $fonts );
|
189 |
-
return !empty( $fonts ) ? $fonts : array();
|
190 |
-
}
|
191 |
-
|
192 |
-
function siteorigin_widgets_is_google_webfont( $font_value ) {
|
193 |
-
$google_webfonts = siteorigin_widgets_fonts_google_webfonts();
|
194 |
-
|
195 |
-
$font_family = explode( ':', $font_value );
|
196 |
-
$font_family = $font_family[0];
|
197 |
-
|
198 |
-
return isset( $google_webfonts[$font_family] );
|
199 |
-
}
|
200 |
-
|
201 |
-
function siteorigin_widgets_font_families( ){
|
202 |
-
// Add the default fonts
|
203 |
-
$font_families = array(
|
204 |
-
'Helvetica Neue' => 'Helvetica Neue',
|
205 |
-
'Lucida Grande' => 'Lucida Grande',
|
206 |
-
'Georgia' => 'Georgia',
|
207 |
-
'Courier New' => 'Courier New',
|
208 |
-
);
|
209 |
-
|
210 |
-
// Add in all the Google font families
|
211 |
-
foreach ( siteorigin_widgets_fonts_google_webfonts() as $font => $variants ) {
|
212 |
-
foreach ( $variants as $variant ) {
|
213 |
-
if ( $variant == 'regular' || $variant == 400 ) {
|
214 |
-
$font_families[ $font ] = $font;
|
215 |
-
}
|
216 |
-
else {
|
217 |
-
$font_families[ $font . ':' . $variant ] = $font . ' (' . $variant . ')';
|
218 |
-
}
|
219 |
-
}
|
220 |
-
}
|
221 |
-
|
222 |
-
return apply_filters('siteorigin_widgets_font_families', $font_families);
|
223 |
-
}
|
224 |
-
|
225 |
-
function siteorigin_widgets_tinymce_admin_print_styles() {
|
226 |
-
wp_enqueue_style( 'editor-buttons' );
|
227 |
-
}
|
228 |
-
add_action( 'admin_print_styles', 'siteorigin_widgets_tinymce_admin_print_styles' );
|
229 |
-
|
230 |
-
/**
|
231 |
-
* Get list of supported measurements
|
232 |
-
*
|
233 |
-
* @return array
|
234 |
-
*/
|
235 |
-
function siteorigin_widgets_get_measurements_list() {
|
236 |
-
$measurements = array(
|
237 |
-
'px', '%', 'in', 'cm', 'mm', 'em', 'rem', 'pt', 'pc', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax',
|
238 |
-
);
|
239 |
-
|
240 |
-
// Allow themes and plugins to trim or enhance the list.
|
241 |
-
return apply_filters('siteorigin_widgets_get_measurements_list', $measurements);
|
242 |
-
}
|
243 |
-
|
244 |
-
|
245 |
-
/**
|
246 |
-
* Returns the base URL of our widget with `$path` appended.
|
247 |
-
*
|
248 |
-
* @param string $path Extra path to append to the end of the URL.
|
249 |
-
*
|
250 |
-
* @return string Base URL of the widget, with $path appended.
|
251 |
-
*/
|
252 |
-
function siteorigin_widgets_url( $path = '' ) {
|
253 |
-
return plugins_url( 'so-widgets-bundle/' . $path );
|
254 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
include plugin_dir_path(__FILE__).'inc/fields/siteorigin-widget-field-class-loader.class.php';
|
4 |
+
include plugin_dir_path(__FILE__).'siteorigin-widget.class.php';
|
5 |
+
|
6 |
+
include plugin_dir_path(__FILE__).'inc/widget-manager.class.php';
|
7 |
+
include plugin_dir_path(__FILE__).'inc/meta-box-manager.php';
|
8 |
+
include plugin_dir_path(__FILE__).'inc/post-selector.php';
|
9 |
+
include plugin_dir_path(__FILE__).'inc/string-utils.php';
|
10 |
+
include plugin_dir_path(__FILE__).'inc/array-utils.php';
|
11 |
+
include plugin_dir_path(__FILE__).'inc/attachments.php';
|
12 |
+
include plugin_dir_path(__FILE__).'inc/actions.php';
|
13 |
+
include plugin_dir_path(__FILE__).'inc/shortcode.php';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @param $css
|
17 |
+
*/
|
18 |
+
function siteorigin_widget_add_inline_css($css){
|
19 |
+
global $siteorigin_widgets_inline_styles;
|
20 |
+
if ( empty( $siteorigin_widgets_inline_styles ) ) {
|
21 |
+
$siteorigin_widgets_inline_styles = array();
|
22 |
+
}
|
23 |
+
|
24 |
+
$siteorigin_widgets_inline_styles[] = $css;
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Print any inline styles that have been added with siteorigin_widget_add_inline_css
|
29 |
+
*/
|
30 |
+
function siteorigin_widget_print_styles(){
|
31 |
+
global $siteorigin_widgets_inline_styles;
|
32 |
+
if ( ! empty( $siteorigin_widgets_inline_styles ) ) {
|
33 |
+
foreach ($siteorigin_widgets_inline_styles as $widget_css) {
|
34 |
+
?>
|
35 |
+
<style type="text/css"><?php echo($widget_css) ?></style><?php
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
$siteorigin_widgets_inline_styles = array();
|
40 |
+
}
|
41 |
+
add_action('wp_head', 'siteorigin_widget_print_styles');
|
42 |
+
add_action('wp_footer', 'siteorigin_widget_print_styles');
|
43 |
+
|
44 |
+
/**
|
45 |
+
* The ajax handler for getting a list of available icons.
|
46 |
+
*/
|
47 |
+
function siteorigin_widget_get_icon_list(){
|
48 |
+
if(empty($_GET['family'])) exit();
|
49 |
+
if ( empty( $_REQUEST['_widgets_nonce'] ) || !wp_verify_nonce( $_REQUEST['_widgets_nonce'], 'widgets_action' ) ) return;
|
50 |
+
|
51 |
+
$widget_icon_families = apply_filters('siteorigin_widgets_icon_families', array() );
|
52 |
+
|
53 |
+
header('content-type: application/json');
|
54 |
+
echo json_encode( !empty($widget_icon_families[$_GET['family']]) ? $widget_icon_families[$_GET['family']] : array() );
|
55 |
+
exit();
|
56 |
+
}
|
57 |
+
add_action('wp_ajax_siteorigin_widgets_get_icons', 'siteorigin_widget_get_icon_list');
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @param $icon_value
|
61 |
+
* @param bool $icon_styles
|
62 |
+
*
|
63 |
+
* @return bool|string
|
64 |
+
*/
|
65 |
+
function siteorigin_widget_get_icon($icon_value, $icon_styles = false) {
|
66 |
+
if( empty( $icon_value ) ) return false;
|
67 |
+
list( $family, $icon ) = explode('-', $icon_value, 2);
|
68 |
+
if( empty( $family ) || empty( $icon ) ) return false;
|
69 |
+
|
70 |
+
static $widget_icon_families;
|
71 |
+
static $widget_icons_enqueued = array();
|
72 |
+
|
73 |
+
if( empty($widget_icon_families) ) $widget_icon_families = apply_filters('siteorigin_widgets_icon_families', array() );
|
74 |
+
if( empty($widget_icon_families[$family]) || empty($widget_icon_families[$family]['icons'][$icon]) ) return false;
|
75 |
+
|
76 |
+
if(empty($widget_icons_enqueued[$family]) && !empty($widget_icon_families[$family]['style_uri'])) {
|
77 |
+
if( !wp_style_is( 'siteorigin-widget-icon-font-'.$family ) ) {
|
78 |
+
wp_enqueue_style('siteorigin-widget-icon-font-'.$family, $widget_icon_families[$family]['style_uri'] );
|
79 |
+
}
|
80 |
+
return '<span class="sow-icon-' . esc_attr($family) . '" data-sow-icon="' . $widget_icon_families[$family]['icons'][$icon] . '" ' . ( !empty($icon_styles) ? 'style="'.implode('; ', $icon_styles).'"' : '' ) . '></span>';
|
81 |
+
}
|
82 |
+
else {
|
83 |
+
return false;
|
84 |
+
}
|
85 |
+
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* @param $font_value
|
90 |
+
*
|
91 |
+
* @return array
|
92 |
+
*/
|
93 |
+
function siteorigin_widget_get_font($font_value) {
|
94 |
+
|
95 |
+
$web_safe = array(
|
96 |
+
'Helvetica Neue' => 'Arial, Helvetica, Geneva, sans-serif',
|
97 |
+
'Lucida Grande' => 'Lucida, Verdana, sans-serif',
|
98 |
+
'Georgia' => '"Times New Roman", Times, serif',
|
99 |
+
'Courier New' => 'Courier, mono',
|
100 |
+
'default' => 'default',
|
101 |
+
);
|
102 |
+
|
103 |
+
$font = array();
|
104 |
+
if ( isset( $web_safe[ $font_value ] ) ) {
|
105 |
+
$font['family'] = $web_safe[ $font_value ];
|
106 |
+
}
|
107 |
+
else if( siteorigin_widgets_is_google_webfont( $font_value ) ) {
|
108 |
+
$font_parts = explode( ':', $font_value );
|
109 |
+
$font['family'] = $font_parts[0];
|
110 |
+
$font_url_param = urlencode( $font_parts[0] );
|
111 |
+
if ( count( $font_parts ) > 1 ) {
|
112 |
+
$font['weight'] = $font_parts[1];
|
113 |
+
$font_url_param .= ':' . $font_parts[1];
|
114 |
+
}
|
115 |
+
$font['css_import'] = '@import url(https://fonts.googleapis.com/css?family=' . $font_url_param . ');';
|
116 |
+
}
|
117 |
+
else {
|
118 |
+
$font['family'] = $font_value;
|
119 |
+
$font = apply_filters( 'siteorigin_widget_get_custom_font_family', $font );
|
120 |
+
}
|
121 |
+
|
122 |
+
return $font;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* Compatibility with Page Builder, add the groups and icons.
|
127 |
+
*
|
128 |
+
* @param $widgets
|
129 |
+
*
|
130 |
+
* @return mixed
|
131 |
+
*/
|
132 |
+
function siteorigin_widget_add_bundle_groups($widgets){
|
133 |
+
foreach( $widgets as $class => &$widget ) {
|
134 |
+
if( preg_match('/SiteOrigin_Widgets?_(.*)_Widget/i', $class, $matches) ) {
|
135 |
+
$widget['icon'] = 'so-widget-icon so-widget-icon-'.strtolower($matches[1]);
|
136 |
+
$widget['groups'] = array('so-widgets-bundle');
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
return $widgets;
|
141 |
+
}
|
142 |
+
add_filter('siteorigin_panels_widgets', 'siteorigin_widget_add_bundle_groups', 11);
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Escape a URL
|
146 |
+
*
|
147 |
+
* @param $url
|
148 |
+
*
|
149 |
+
* @return string
|
150 |
+
*/
|
151 |
+
function sow_esc_url( $url ) {
|
152 |
+
if( preg_match('/^post: *([0-9]+)/', $url, $matches) ) {
|
153 |
+
// Convert the special post URL into a permalink
|
154 |
+
$url = get_the_permalink( intval($matches[1]) );
|
155 |
+
if( empty($url) ) return '';
|
156 |
+
}
|
157 |
+
|
158 |
+
$protocols = wp_allowed_protocols();
|
159 |
+
$protocols[] = 'skype';
|
160 |
+
return esc_url( $url, $protocols );
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* A special URL escaping function that handles additional protocols
|
165 |
+
*
|
166 |
+
* @param $url
|
167 |
+
*
|
168 |
+
* @return string
|
169 |
+
*/
|
170 |
+
function sow_esc_url_raw( $url ) {
|
171 |
+
if( preg_match('/^post: *([0-9]+)/', $url, $matches) ) {
|
172 |
+
// Convert the special post URL into a permalink
|
173 |
+
$url = get_the_permalink( intval($matches[1]) );
|
174 |
+
}
|
175 |
+
|
176 |
+
$protocols = wp_allowed_protocols();
|
177 |
+
$protocols[] = 'skype';
|
178 |
+
return esc_url_raw( $url, $protocols );
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Get all the Google Web Fonts.
|
183 |
+
*
|
184 |
+
* @return mixed|void
|
185 |
+
*/
|
186 |
+
function siteorigin_widgets_fonts_google_webfonts( ) {
|
187 |
+
$fonts = include plugin_dir_path( __FILE__ ) . 'inc/fonts.php';
|
188 |
+
$fonts = apply_filters( 'siteorigin_widgets_google_webfonts', $fonts );
|
189 |
+
return !empty( $fonts ) ? $fonts : array();
|
190 |
+
}
|
191 |
+
|
192 |
+
function siteorigin_widgets_is_google_webfont( $font_value ) {
|
193 |
+
$google_webfonts = siteorigin_widgets_fonts_google_webfonts();
|
194 |
+
|
195 |
+
$font_family = explode( ':', $font_value );
|
196 |
+
$font_family = $font_family[0];
|
197 |
+
|
198 |
+
return isset( $google_webfonts[$font_family] );
|
199 |
+
}
|
200 |
+
|
201 |
+
function siteorigin_widgets_font_families( ){
|
202 |
+
// Add the default fonts
|
203 |
+
$font_families = array(
|
204 |
+
'Helvetica Neue' => 'Helvetica Neue',
|
205 |
+
'Lucida Grande' => 'Lucida Grande',
|
206 |
+
'Georgia' => 'Georgia',
|
207 |
+
'Courier New' => 'Courier New',
|
208 |
+
);
|
209 |
+
|
210 |
+
// Add in all the Google font families
|
211 |
+
foreach ( siteorigin_widgets_fonts_google_webfonts() as $font => $variants ) {
|
212 |
+
foreach ( $variants as $variant ) {
|
213 |
+
if ( $variant == 'regular' || $variant == 400 ) {
|
214 |
+
$font_families[ $font ] = $font;
|
215 |
+
}
|
216 |
+
else {
|
217 |
+
$font_families[ $font . ':' . $variant ] = $font . ' (' . $variant . ')';
|
218 |
+
}
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
return apply_filters('siteorigin_widgets_font_families', $font_families);
|
223 |
+
}
|
224 |
+
|
225 |
+
function siteorigin_widgets_tinymce_admin_print_styles() {
|
226 |
+
wp_enqueue_style( 'editor-buttons' );
|
227 |
+
}
|
228 |
+
add_action( 'admin_print_styles', 'siteorigin_widgets_tinymce_admin_print_styles' );
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Get list of supported measurements
|
232 |
+
*
|
233 |
+
* @return array
|
234 |
+
*/
|
235 |
+
function siteorigin_widgets_get_measurements_list() {
|
236 |
+
$measurements = array(
|
237 |
+
'px', '%', 'in', 'cm', 'mm', 'em', 'rem', 'pt', 'pc', 'ex', 'ch', 'vw', 'vh', 'vmin', 'vmax',
|
238 |
+
);
|
239 |
+
|
240 |
+
// Allow themes and plugins to trim or enhance the list.
|
241 |
+
return apply_filters('siteorigin_widgets_get_measurements_list', $measurements);
|
242 |
+
}
|
243 |
+
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Returns the base URL of our widget with `$path` appended.
|
247 |
+
*
|
248 |
+
* @param string $path Extra path to append to the end of the URL.
|
249 |
+
*
|
250 |
+
* @return string Base URL of the widget, with $path appended.
|
251 |
+
*/
|
252 |
+
function siteorigin_widgets_url( $path = '' ) {
|
253 |
+
return plugins_url( 'so-widgets-bundle/' . $path );
|
254 |
+
}
|
base/inc/fields/checkbox.class.php
CHANGED
@@ -1,26 +1,26 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class SiteOrigin_Widget_Field_Checkbox
|
5 |
-
*/
|
6 |
-
class SiteOrigin_Widget_Field_Checkbox extends SiteOrigin_Widget_Field_Base {
|
7 |
-
|
8 |
-
protected function render_field( $value, $instance ) {
|
9 |
-
?>
|
10 |
-
<label for="<?php echo esc_attr( $this->element_id ) ?>" class="so-checkbox-label">
|
11 |
-
<input type="checkbox" name="<?php echo esc_attr( $this->element_name ) ?>" id="<?php echo esc_attr( $this->element_id ) ?>"
|
12 |
-
class="siteorigin-widget-input" <?php checked( !empty( $value ) ) ?> />
|
13 |
-
<?php echo esc_html( $this->label ) ?>
|
14 |
-
</label>
|
15 |
-
<?php
|
16 |
-
}
|
17 |
-
|
18 |
-
protected function render_field_label( $value, $instance ) {
|
19 |
-
// Empty override. This field renders it's own label in the render_field() function.
|
20 |
-
}
|
21 |
-
|
22 |
-
protected function sanitize_field_input( $value, $instance ) {
|
23 |
-
return ! empty( $value ) && ! ( is_string( $value ) && $value === 'false' );
|
24 |
-
}
|
25 |
-
|
26 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class SiteOrigin_Widget_Field_Checkbox
|
5 |
+
*/
|
6 |
+
class SiteOrigin_Widget_Field_Checkbox extends SiteOrigin_Widget_Field_Base {
|
7 |
+
|
8 |
+
protected function render_field( $value, $instance ) {
|
9 |
+
?>
|
10 |
+
<label for="<?php echo esc_attr( $this->element_id ) ?>" class="so-checkbox-label">
|
11 |
+
<input type="checkbox" name="<?php echo esc_attr( $this->element_name ) ?>" id="<?php echo esc_attr( $this->element_id ) ?>"
|
12 |
+
class="siteorigin-widget-input" <?php checked( !empty( $value ) ) ?> />
|
13 |
+
<?php echo esc_html( $this->label ) ?>
|
14 |
+
</label>
|
15 |
+
<?php
|
16 |
+
}
|
17 |
+
|
18 |
+
protected function render_field_label( $value, $instance ) {
|
19 |
+
// Empty override. This field renders it's own label in the render_field() function.
|
20 |
+
}
|
21 |
+
|
22 |
+
protected function sanitize_field_input( $value, $instance ) {
|
23 |
+
return ! empty( $value ) && ! ( is_string( $value ) && $value === 'false' );
|
24 |
+
}
|
25 |
+
|
26 |
+
}
|
base/inc/fields/js/tinymce-field.js
CHANGED
@@ -1,112 +1,112 @@
|
|
1 |
-
/* global tinymce, switchEditors */
|
2 |
-
|
3 |
-
(function ( $ ) {
|
4 |
-
var setup = function( $field ) {
|
5 |
-
|
6 |
-
if ( $field.data( 'initialized' ) ) {
|
7 |
-
return;
|
8 |
-
}
|
9 |
-
|
10 |
-
var $container = $field.find( '.siteorigin-widget-tinymce-container' );
|
11 |
-
var settings = $container.data( 'editorSettings' );
|
12 |
-
var $textarea = $container.find( 'textarea' );
|
13 |
-
var id = $textarea.attr( 'id' );
|
14 |
-
var setupEditor = function ( editor ) {
|
15 |
-
editor.on( 'change',
|
16 |
-
function () {
|
17 |
-
window.tinymce.get( id ).save();
|
18 |
-
$textarea.trigger( 'change' );
|
19 |
-
}
|
20 |
-
);
|
21 |
-
};
|
22 |
-
|
23 |
-
settings.tinymce = $.extend( {}, settings.tinymce, { selector: '#' + id, setup: setupEditor } );
|
24 |
-
$( document ).one( 'wp-before-tinymce-init', function ( event, init ) {
|
25 |
-
if ( init.selector === settings.tinymce.selector ) {
|
26 |
-
var mediaButtons = $container.data( 'mediaButtons' );
|
27 |
-
$field.find( '.wp-editor-tabs' ).before( mediaButtons.html );
|
28 |
-
}
|
29 |
-
} );
|
30 |
-
$( document ).one( 'tinymce-editor-setup', function () {
|
31 |
-
if ( ! $field.find( '.wp-editor-wrap' ).hasClass( settings.selectedEditor + '-active' ) ) {
|
32 |
-
setTimeout( function () {
|
33 |
-
window.switchEditors.go( id );
|
34 |
-
}, 10 );
|
35 |
-
}
|
36 |
-
} );
|
37 |
-
|
38 |
-
wp.editor.remove( id );
|
39 |
-
|
40 |
-
// Wait for textarea to be visible before initialization.
|
41 |
-
if ( $textarea.is( ':visible' ) ) {
|
42 |
-
wp.editor.initialize( id, settings );
|
43 |
-
}
|
44 |
-
else {
|
45 |
-
var intervalId = setInterval( function () {
|
46 |
-
if ( $textarea.is( ':visible' ) ) {
|
47 |
-
wp.editor.initialize( id, settings );
|
48 |
-
clearInterval( intervalId );
|
49 |
-
}
|
50 |
-
}, 500);
|
51 |
-
}
|
52 |
-
|
53 |
-
$field.on( 'click', function ( event ) {
|
54 |
-
var $target = $( event.target );
|
55 |
-
var mode = $target.hasClass( 'switch-tmce' ) ? 'tmce' : 'html';
|
56 |
-
if ( mode === 'tmce' ) {
|
57 |
-
var editor = window.tinymce.get( id );
|
58 |
-
// Quick bit of sanitization to prevent catastrophic backtracking in TinyMCE HTML parser regex
|
59 |
-
if ( $target.hasClass( 'wp-switch-editor' ) && editor !== null ) {
|
60 |
-
var content = $textarea.val();
|
61 |
-
if ( content.search( '<' ) !== -1 && content.search( '>' ) === -1) {
|
62 |
-
content = content.replace( /</g, '' );
|
63 |
-
$textarea.val( content );
|
64 |
-
}
|
65 |
-
editor.setContent(window.switchEditors.wpautop(content));
|
66 |
-
}
|
67 |
-
}
|
68 |
-
$field.find( '.siteorigin-widget-tinymce-selected-editor' ).val( mode );
|
69 |
-
} );
|
70 |
-
|
71 |
-
$field.data( 'initialized', true );
|
72 |
-
};
|
73 |
-
|
74 |
-
$( document ).on( 'sowsetupformfield', '.siteorigin-widget-field-type-tinymce', function () {
|
75 |
-
var $field = $( this );
|
76 |
-
var $parentRepeaterItem = $field.closest( '.siteorigin-widget-field-repeater-item-form' );
|
77 |
-
|
78 |
-
if ( $parentRepeaterItem.length > 0 ) {
|
79 |
-
if ( $parentRepeaterItem.is( ':visible' ) ) {
|
80 |
-
setup( $field );
|
81 |
-
}
|
82 |
-
else {
|
83 |
-
$parentRepeaterItem.on('slideToggleOpenComplete', function onSlideToggleComplete() {
|
84 |
-
if ( $parentRepeaterItem.is( ':visible' ) ) {
|
85 |
-
setup( $field );
|
86 |
-
$parentRepeaterItem.off( 'slideToggleOpenComplete' );
|
87 |
-
}
|
88 |
-
});
|
89 |
-
}
|
90 |
-
}
|
91 |
-
else {
|
92 |
-
setup( $field );
|
93 |
-
}
|
94 |
-
});
|
95 |
-
|
96 |
-
$( document ).on( 'sortstop', function ( event, ui ) {
|
97 |
-
var $form;
|
98 |
-
if ( ui.item.is( '.siteorigin-widget-field-repeater-item' ) ) {
|
99 |
-
$form = ui.item.find( '> .siteorigin-widget-field-repeater-item-form' );
|
100 |
-
}
|
101 |
-
else {
|
102 |
-
$form = ui.item.find('.siteorigin-widget-form');
|
103 |
-
}
|
104 |
-
|
105 |
-
$form.find( '.siteorigin-widget-field-type-tinymce' ).each( function () {
|
106 |
-
$( this ).data( 'initialized', null );
|
107 |
-
setup( $( this ) );
|
108 |
-
} );
|
109 |
-
|
110 |
-
});
|
111 |
-
|
112 |
-
})( jQuery );
|
1 |
+
/* global tinymce, switchEditors */
|
2 |
+
|
3 |
+
(function ( $ ) {
|
4 |
+
var setup = function( $field ) {
|
5 |
+
|
6 |
+
if ( $field.data( 'initialized' ) ) {
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
|
10 |
+
var $container = $field.find( '.siteorigin-widget-tinymce-container' );
|
11 |
+
var settings = $container.data( 'editorSettings' );
|
12 |
+
var $textarea = $container.find( 'textarea' );
|
13 |
+
var id = $textarea.attr( 'id' );
|
14 |
+
var setupEditor = function ( editor ) {
|
15 |
+
editor.on( 'change',
|
16 |
+
function () {
|
17 |
+
window.tinymce.get( id ).save();
|
18 |
+
$textarea.trigger( 'change' );
|
19 |
+
}
|
20 |
+
);
|
21 |
+
};
|
22 |
+
|
23 |
+
settings.tinymce = $.extend( {}, settings.tinymce, { selector: '#' + id, setup: setupEditor } );
|
24 |
+
$( document ).one( 'wp-before-tinymce-init', function ( event, init ) {
|
25 |
+
if ( init.selector === settings.tinymce.selector ) {
|
26 |
+
var mediaButtons = $container.data( 'mediaButtons' );
|
27 |
+
$field.find( '.wp-editor-tabs' ).before( mediaButtons.html );
|
28 |
+
}
|
29 |
+
} );
|
30 |
+
$( document ).one( 'tinymce-editor-setup', function () {
|
31 |
+
if ( ! $field.find( '.wp-editor-wrap' ).hasClass( settings.selectedEditor + '-active' ) ) {
|
32 |
+
setTimeout( function () {
|
33 |
+
window.switchEditors.go( id );
|
34 |
+
}, 10 );
|
35 |
+
}
|
36 |
+
} );
|
37 |
+
|
38 |
+
wp.editor.remove( id );
|
39 |
+
|
40 |
+
// Wait for textarea to be visible before initialization.
|
41 |
+
if ( $textarea.is( ':visible' ) ) {
|
42 |
+
wp.editor.initialize( id, settings );
|
43 |
+
}
|
44 |
+
else {
|
45 |
+
var intervalId = setInterval( function () {
|
46 |
+
if ( $textarea.is( ':visible' ) ) {
|
47 |
+
wp.editor.initialize( id, settings );
|
48 |
+
clearInterval( intervalId );
|
49 |
+
}
|
50 |
+
}, 500);
|
51 |
+
}
|
52 |
+
|
53 |
+
$field.on( 'click', function ( event ) {
|
54 |
+
var $target = $( event.target );
|
55 |
+
var mode = $target.hasClass( 'switch-tmce' ) ? 'tmce' : 'html';
|
56 |
+
if ( mode === 'tmce' ) {
|
57 |
+
var editor = window.tinymce.get( id );
|
58 |
+
// Quick bit of sanitization to prevent catastrophic backtracking in TinyMCE HTML parser regex
|
59 |
+
if ( $target.hasClass( 'wp-switch-editor' ) && editor !== null ) {
|
60 |
+
var content = $textarea.val();
|
61 |
+
if ( content.search( '<' ) !== -1 && content.search( '>' ) === -1) {
|
62 |
+
content = content.replace( /</g, '' );
|
63 |
+
$textarea.val( content );
|
64 |
+
}
|
65 |
+
editor.setContent(window.switchEditors.wpautop(content));
|
66 |
+
}
|
67 |
+
}
|
68 |
+
$field.find( '.siteorigin-widget-tinymce-selected-editor' ).val( mode );
|
69 |
+
} );
|
70 |
+
|
71 |
+
$field.data( 'initialized', true );
|
72 |
+
};
|
73 |
+
|
74 |
+
$( document ).on( 'sowsetupformfield', '.siteorigin-widget-field-type-tinymce', function () {
|
75 |
+
var $field = $( this );
|
76 |
+
var $parentRepeaterItem = $field.closest( '.siteorigin-widget-field-repeater-item-form' );
|
77 |
+
|
78 |
+
if ( $parentRepeaterItem.length > 0 ) {
|
79 |
+
if ( $parentRepeaterItem.is( ':visible' ) ) {
|
80 |
+
setup( $field );
|
81 |
+
}
|
82 |
+
else {
|
83 |
+
$parentRepeaterItem.on('slideToggleOpenComplete', function onSlideToggleComplete() {
|
84 |
+
if ( $parentRepeaterItem.is( ':visible' ) ) {
|
85 |
+
setup( $field );
|
86 |
+
$parentRepeaterItem.off( 'slideToggleOpenComplete' );
|
87 |
+
}
|
88 |
+
});
|
89 |
+
}
|
90 |
+
}
|
91 |
+
else {
|
92 |
+
setup( $field );
|
93 |
+
}
|
94 |
+
});
|
95 |
+
|
96 |
+
$( document ).on( 'sortstop', function ( event, ui ) {
|
97 |
+
var $form;
|
98 |
+
if ( ui.item.is( '.siteorigin-widget-field-repeater-item' ) ) {
|
99 |
+
$form = ui.item.find( '> .siteorigin-widget-field-repeater-item-form' );
|
100 |
+
}
|
101 |
+
else {
|
102 |
+
$form = ui.item.find('.siteorigin-widget-form');
|
103 |
+
}
|
104 |
+
|
105 |
+
$form.find( '.siteorigin-widget-field-type-tinymce' ).each( function () {
|
106 |
+
$( this ).data( 'initialized', null );
|
107 |
+
setup( $( this ) );
|
108 |
+
} );
|
109 |
+
|
110 |
+
});
|
111 |
+
|
112 |
+
})( jQuery );
|
base/inc/fields/slider.class.php
CHANGED
@@ -1,50 +1,50 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Class SiteOrigin_Widget_Field_Slider
|
5 |
-
*/
|
6 |
-
class SiteOrigin_Widget_Field_Slider extends SiteOrigin_Widget_Field_Base {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* The minimum value of the allowed range.
|
10 |
-
*
|
11 |
-
* @access protected
|
12 |
-
* @var float
|
13 |
-
*/
|
14 |
-
protected $min;
|
15 |
-
|
16 |
-
/**
|
17 |
-
* The maximum value of the allowed range.
|
18 |
-
*
|
19 |
-
* @access protected
|
20 |
-
* @var float
|
21 |
-
*/
|
22 |
-
protected $max;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* The step size when moving in the range.
|
26 |
-
*
|
27 |
-
* @access protected
|
28 |
-
* @var float
|
29 |
-
*/
|
30 |
-
protected $step;
|
31 |
-
|
32 |
-
protected function render_field( $value, $instance ) {
|
33 |
-
?>
|
34 |
-
<div class="siteorigin-widget-slider-value"><?php echo ! empty( $value ) ? esc_html( $value ) : 0 ?></div>
|
35 |
-
<div class="siteorigin-widget-slider-wrapper">
|
36 |
-
<div class="siteorigin-widget-value-slider"></div>
|
37 |
-
</div>
|
38 |
-
<input type="number" class="siteorigin-widget-input" name="<?php echo esc_attr( $this->element_name ) ?>" id="<?php echo esc_attr( $this->element_id ) ?>"
|
39 |
-
value="<?php echo !empty( $value ) ? esc_attr( $value ) : 0 ?>"
|
40 |
-
min="<?php echo isset( $this->min ) ? floatval( $this->min ) : 0 ?>"
|
41 |
-
max="<?php echo isset( $this->max ) ? floatval( $this->max ) : 100 ?>"
|
42 |
-
step="<?php echo isset( $this->step ) ? floatval( $this->step ) : 1 ?>"/>
|
43 |
-
<?php
|
44 |
-
}
|
45 |
-
|
46 |
-
protected function sanitize_field_input( $value, $instance ) {
|
47 |
-
return (float) $value;
|
48 |
-
}
|
49 |
-
|
50 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Class SiteOrigin_Widget_Field_Slider
|
5 |
+
*/
|
6 |
+
class SiteOrigin_Widget_Field_Slider extends SiteOrigin_Widget_Field_Base {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* The minimum value of the allowed range.
|
10 |
+
*
|
11 |
+
* @access protected
|
12 |
+
* @var float
|
13 |
+
*/
|
14 |
+
protected $min;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* The maximum value of the allowed range.
|
18 |
+
*
|
19 |
+
* @access protected
|
20 |
+
* @var float
|
21 |
+
*/
|
22 |
+
protected $max;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The step size when moving in the range.
|
26 |
+
*
|
27 |
+
* @access protected
|
28 |
+
* @var float
|
29 |
+
*/
|
30 |
+
protected $step;
|
31 |
+
|
32 |
+
protected function render_field( $value, $instance ) {
|
33 |
+
?>
|
34 |
+
<div class="siteorigin-widget-slider-value"><?php echo ! empty( $value ) ? esc_html( $value ) : 0 ?></div>
|
35 |
+
<div class="siteorigin-widget-slider-wrapper">
|
36 |
+
<div class="siteorigin-widget-value-slider"></div>
|
37 |
+
</div>
|
38 |
+
<input type="number" class="siteorigin-widget-input" name="<?php echo esc_attr( $this->element_name ) ?>" id="<?php echo esc_attr( $this->element_id ) ?>"
|
39 |
+
value="<?php echo !empty( $value ) ? esc_attr( $value ) : 0 ?>"
|
40 |
+
min="<?php echo isset( $this->min ) ? floatval( $this->min ) : 0 ?>"
|
41 |
+
max="<?php echo isset( $this->max ) ? floatval( $this->max ) : 100 ?>"
|
42 |
+
step="<?php echo isset( $this->step ) ? floatval( $this->step ) : 1 ?>"/>
|
43 |
+
<?php
|
44 |
+
}
|
45 |
+
|
46 |
+
protected function sanitize_field_input( $value, $instance ) {
|
47 |
+
return (float) $value;
|
48 |
+
}
|
49 |
+
|
50 |
}
|
base/inc/fields/tinymce.class.php
CHANGED
@@ -1,525 +1,525 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class SiteOrigin_Widget_Field_TinyMCE extends SiteOrigin_Widget_Field_Text_Input_Base {
|
4 |
-
/**
|
5 |
-
* The number of visible rows in the textarea.
|
6 |
-
*
|
7 |
-
* @access protected
|
8 |
-
* @var int
|
9 |
-
*/
|
10 |
-
protected $rows = 10;
|
11 |
-
/**
|
12 |
-
* The editor initial height. Overrides rows if it is set.
|
13 |
-
*
|
14 |
-
* @access protected
|
15 |
-
* @var int
|
16 |
-
*/
|
17 |
-
protected $editor_height;
|
18 |
-
/**
|
19 |
-
* The editor to be displayed initially.
|
20 |
-
*
|
21 |
-
* @access protected
|
22 |
-
* @var string
|
23 |
-
*/
|
24 |
-
protected $default_editor = 'tinymce';
|
25 |
-
/**
|
26 |
-
* The last editor selected by the user.
|
27 |
-
*
|
28 |
-
* @access protected
|
29 |
-
* @var string
|
30 |
-
*/
|
31 |
-
protected $selected_editor;
|
32 |
-
/**
|
33 |
-
* An array of the buttons which will be rendered for the first toolbar of the TinyMCE editor.
|
34 |
-
*
|
35 |
-
* @access protected
|
36 |
-
* @var array
|
37 |
-
*/
|
38 |
-
protected $mce_buttons;
|
39 |
-
/**
|
40 |
-
* An array of the buttons which will be rendered for the second toolbar of the TinyMCE editor.
|
41 |
-
*
|
42 |
-
* @access protected
|
43 |
-
* @var array
|
44 |
-
*/
|
45 |
-
protected $mce_buttons_2;
|
46 |
-
/**
|
47 |
-
* An array of the buttons which will be rendered for the third toolbar of the TinyMCE editor.
|
48 |
-
*
|
49 |
-
* @access protected
|
50 |
-
* @var array
|
51 |
-
*/
|
52 |
-
protected $mce_buttons_3;
|
53 |
-
/**
|
54 |
-
* An array of the buttons which will be rendered for the fourth toolbar of the TinyMCE editor.
|
55 |
-
*
|
56 |
-
* @access protected
|
57 |
-
* @var array
|
58 |
-
*/
|
59 |
-
protected $mce_buttons_4;
|
60 |
-
/**
|
61 |
-
* An array of the buttons which will be rendered for the QuickTags editor.
|
62 |
-
*
|
63 |
-
* @access protected
|
64 |
-
* @var array
|
65 |
-
*/
|
66 |
-
protected $quicktags_buttons;
|
67 |
-
/**
|
68 |
-
* An array of filter callbacks to apply to the set of buttons which will be rendered for the editor.
|
69 |
-
*
|
70 |
-
* @access protected
|
71 |
-
* @var array
|
72 |
-
*/
|
73 |
-
protected $button_filters;
|
74 |
-
/**
|
75 |
-
* An array of the included plugins to enable for the TinyMCE editor.
|
76 |
-
*
|
77 |
-
* @access protected
|
78 |
-
* @var array
|
79 |
-
*/
|
80 |
-
protected $mce_plugins;
|
81 |
-
/**
|
82 |
-
* An array of external plugins for the TinyMCE editor.
|
83 |
-
*
|
84 |
-
* @access protected
|
85 |
-
* @var array
|
86 |
-
*/
|
87 |
-
protected $mce_external_plugins;
|
88 |
-
/**
|
89 |
-
* Updated Editor JS API was introduced in WP 4.8 so need to check for compatibility with older versions.
|
90 |
-
*
|
91 |
-
* @access private
|
92 |
-
* @var bool
|
93 |
-
*/
|
94 |
-
private $wp_version_lt_4_8;
|
95 |
-
|
96 |
-
protected function get_default_options() {
|
97 |
-
return array(
|
98 |
-
'mce_buttons' => array(
|
99 |
-
'formatselect',
|
100 |
-
'bold',
|
101 |
-
'italic',
|
102 |
-
'bullist',
|
103 |
-
'numlist',
|
104 |
-
'blockquote',
|
105 |
-
'alignleft',
|
106 |
-
'aligncenter',
|
107 |
-
'alignright',
|
108 |
-
'link',
|
109 |
-
'unlink',
|
110 |
-
'wp_more',
|
111 |
-
'wp_adv',
|
112 |
-
),
|
113 |
-
'mce_buttons_2' => array(
|
114 |
-
'strikethrough',
|
115 |
-
'hr',
|
116 |
-
'forecolor',
|
117 |
-
'pastetext',
|
118 |
-
'removeformat',
|
119 |
-
'charmap',
|
120 |
-
'outdent',
|
121 |
-
'indent',
|
122 |
-
'undo',
|
123 |
-
'redo',
|
124 |
-
'wp_help',
|
125 |
-
),
|
126 |
-
'quicktags_buttons' => array(
|
127 |
-
'strong',
|
128 |
-
'em',
|
129 |
-
'link',
|
130 |
-
'block',
|
131 |
-
'del',
|
132 |
-
'ins',
|
133 |
-
'img',
|
134 |
-
'ul',
|
135 |
-
'ol',
|
136 |
-
'li',
|
137 |
-
'code',
|
138 |
-
'more',
|
139 |
-
'close',
|
140 |
-
),
|
141 |
-
'mce_plugins' => array(
|
142 |
-
'charmap',
|
143 |
-
'colorpicker',
|
144 |
-
'hr',
|
145 |
-
'lists',
|
146 |
-
'media',
|
147 |
-
'paste',
|
148 |
-
'tabfocus',
|
149 |
-
'textcolor',
|
150 |
-
'fullscreen',
|
151 |
-
'wordpress',
|
152 |
-
'wpautoresize',
|
153 |
-
'wpeditimage',
|
154 |
-
'wpemoji',
|
155 |
-
'wpgallery',
|
156 |
-
'wplink',
|
157 |
-
'wpdialogs',
|
158 |
-
'wptextpattern',
|
159 |
-
'wpview',
|
160 |
-
),
|
161 |
-
'mce_external_plugins' => array(),
|
162 |
-
);
|
163 |
-
}
|
164 |
-
|
165 |
-
protected function initialize() {
|
166 |
-
if ( ! is_admin() ) {
|
167 |
-
return;
|
168 |
-
}
|
169 |
-
|
170 |
-
global $wp_version;
|
171 |
-
$this->wp_version_lt_4_8 = version_compare( $wp_version, '4.8', '<' );
|
172 |
-
|
173 |
-
if ( ! empty( $this->wp_version_lt_4_8 ) ) {
|
174 |
-
add_filter( 'mce_buttons', array( $this, 'mce_buttons_filter' ), 10, 2 );
|
175 |
-
add_filter( 'quicktags_settings', array( $this, 'quicktags_settings' ), 10, 2 );
|
176 |
-
}
|
177 |
-
|
178 |
-
if ( ! empty( $this->button_filters ) ) {
|
179 |
-
foreach ( $this->button_filters as $filter_name => $filter ) {
|
180 |
-
$is_valid_filter = preg_match(
|
181 |
-
'/mce_buttons(?:_[1-4])?|quicktags_settings/', $filter_name
|
182 |
-
) && ! empty( $filter ) && is_callable( $filter );
|
183 |
-
if ( $is_valid_filter ) {
|
184 |
-
add_filter( $filter_name, array( $this, $filter_name ), 10, 2 );
|
185 |
-
}
|
186 |
-
}
|
187 |
-
}
|
188 |
-
|
189 |
-
if( class_exists( 'WC_Shortcodes_TinyMCE_Buttons' ) ) {
|
190 |
-
if ( ! empty( $this->wp_version_lt_4_8 ) ) {
|
191 |
-
$screen = get_current_screen();
|
192 |
-
if( ! is_null( $screen ) && $screen->id != 'widgets' ) {
|
193 |
-
add_filter( 'mce_external_plugins', array( $this, 'add_wpc_shortcodes_plugin' ), 15 );
|
194 |
-
add_filter( 'mce_buttons', array( $this, 'register_wpc_shortcodes_button' ), 15 );
|
195 |
-
}
|
196 |
-
} else {
|
197 |
-
$this->mce_external_plugins = $this->add_wpc_shortcodes_plugin( $this->mce_external_plugins );
|
198 |
-
$this->mce_buttons = $this->register_wpc_shortcodes_button( $this->mce_buttons );
|
199 |
-
}
|
200 |
-
}
|
201 |
-
|
202 |
-
if( class_exists( 'WC_Shortcodes_Admin' ) ) {
|
203 |
-
if ( ! empty( $this->wp_version_lt_4_8 ) ) {
|
204 |
-
|
205 |
-
$screen = get_current_screen();
|
206 |
-
if( ! is_null( $screen ) && $screen->id != 'widgets' ) {
|
207 |
-
add_filter( 'mce_external_plugins', array( $this, 'add_wc_shortcodes_plugin' ), 15 );
|
208 |
-
add_filter( 'mce_buttons', array( $this, 'register_wc_shortcodes_button' ), 15 );
|
209 |
-
}
|
210 |
-
} else {
|
211 |
-
$this->mce_external_plugins = $this->add_wc_shortcodes_plugin( $this->mce_external_plugins );
|
212 |
-
$this->mce_buttons = $this->register_wc_shortcodes_button( $this->mce_buttons );
|
213 |
-
}
|
214 |
-
}
|
215 |
-
}
|
216 |
-
|
217 |
-
function add_wc_shortcodes_plugin( $plugins ) {
|
218 |
-
if( isset( $plugins['woocommerce_shortcodes'] ) ) {
|
219 |
-
return $plugins;
|
220 |
-
}
|
221 |
-
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
222 |
-
$editor_path = 'woocommerce-shortcodes/assets/js/editor' . $suffix . '.js';
|
223 |
-
if( file_exists( WP_PLUGIN_DIR . '/' . $editor_path ) ) {
|
224 |
-
$plugins['woocommerce_shortcodes'] = plugins_url( $editor_path );
|
225 |
-
}
|
226 |
-
return $plugins;
|
227 |
-
}
|
228 |
-
|
229 |
-
function register_wc_shortcodes_button( $buttons ) {
|
230 |
-
if( ! in_array( 'woocommerce_shortcodes', $buttons ) ) {
|
231 |
-
array_push( $buttons, '|', 'woocommerce_shortcodes' );
|
232 |
-
}
|
233 |
-
return $buttons;
|
234 |
-
}
|
235 |
-
|
236 |
-
function add_wpc_shortcodes_plugin( $plugins ) {
|
237 |
-
if( ! isset( $plugins['wpc_shortcodes'] ) ) {
|
238 |
-
$shortcodes_path = 'wc-shortcodes/includes/mce/js/shortcodes-tinymce-4.js';
|
239 |
-
if ( file_exists( WP_PLUGIN_DIR . '/' . $shortcodes_path ) ) {
|
240 |
-
$plugins['wpc_shortcodes'] = plugins_url( $shortcodes_path . '?ver=' . WC_SHORTCODES_VERSION );
|
241 |
-
}
|
242 |
-
}
|
243 |
-
|
244 |
-
if( ! isset( $plugins['wpc_font_awesome'] ) ) {
|
245 |
-
$fontawesome_path = 'wc-shortcodes/includes/mce/js/font-awesome-tinymce-4.js';
|
246 |
-
if ( file_exists( WP_PLUGIN_DIR . '/' . $fontawesome_path ) ) {
|
247 |
-
$plugins['wpc_font_awesome'] = plugins_url( $fontawesome_path . '?ver=' . WC_SHORTCODES_VERSION );
|
248 |
-
}
|
249 |
-
}
|
250 |
-
|
251 |
-
return $plugins;
|
252 |
-
}
|
253 |
-
|
254 |
-
function register_wpc_shortcodes_button( $buttons ) {
|
255 |
-
if( ! in_array( 'wpc_shortcodes_button', $buttons ) ) {
|
256 |
-
array_push( $buttons, 'wpc_shortcodes_button' );
|
257 |
-
}
|
258 |
-
if( ! in_array( 'wpcfontAwesomeGlyphSelect', $buttons ) ) {
|
259 |
-
array_push( $buttons, 'wpcfontAwesomeGlyphSelect' );
|
260 |
-
}
|
261 |
-
|
262 |
-
return $buttons;
|
263 |
-
}
|
264 |
-
|
265 |
-
/**
|
266 |
-
* @param $name
|
267 |
-
* @param $arguments
|
268 |
-
* @return array|mixed
|
269 |
-
*/
|
270 |
-
function __call( $name, $arguments ) {
|
271 |
-
if ( preg_match( '/mce_buttons(?:_[1-4])?|quicktags_settings/', $name ) && !empty( $this->button_filters[$name] ) ) {
|
272 |
-
$filter = $this->button_filters[$name];
|
273 |
-
if ( !empty( $filter[0] ) && is_a( $filter[0], 'SiteOrigin_Widget' ) ) {
|
274 |
-
$widget = $filter[0];
|
275 |
-
$settings = !empty($arguments[0]) ? $arguments[0] : array();
|
276 |
-
$editor_id = !empty($arguments[1]) ? $arguments[1] : '';
|
277 |
-
if ( preg_match( '/widget-' . $widget->id_base . '-.*-' . $this->base_name . '/', $editor_id ) ) {
|
278 |
-
return call_user_func( $filter, $settings, $editor_id );
|
279 |
-
}
|
280 |
-
else {
|
281 |
-
return $settings;
|
282 |
-
}
|
283 |
-
}
|
284 |
-
}
|
285 |
-
}
|
286 |
-
|
287 |
-
public function mce_buttons_filter( $buttons, $editor_id ) {
|
288 |
-
if (($key = array_search('fullscreen', $buttons)) !== false) {
|
289 |
-
unset($buttons[$key]);
|
290 |
-
}
|
291 |
-
return $buttons;
|
292 |
-
}
|
293 |
-
|
294 |
-
public function quicktags_settings( $settings, $editor_id ) {
|
295 |
-
$settings['buttons'] = preg_replace( '/,fullscreen/', '', $settings['buttons'] );
|
296 |
-
$settings['buttons'] = preg_replace( '/,dfw/', '', $settings['buttons'] );
|
297 |
-
return $settings;
|
298 |
-
}
|
299 |
-
|
300 |
-
protected function get_input_classes() {
|
301 |
-
$classes = parent::get_input_classes();
|
302 |
-
$classes[] = 'wp-editor-area';
|
303 |
-
return $classes;
|
304 |
-
}
|
305 |
-
|
306 |
-
protected function render_before_field( $value, $instance ) {
|
307 |
-
$selected_editor_name = $this->get_selected_editor_field_name( $this->base_name );
|
308 |
-
if( ! empty( $instance[ $selected_editor_name ] ) ) {
|
309 |
-
$this->selected_editor = $instance[ $selected_editor_name ];
|
310 |
-
}
|
311 |
-
else {
|
312 |
-
$this->selected_editor = $this->default_editor;
|
313 |
-
}
|
314 |
-
parent::render_before_field( $value, $instance );
|
315 |
-
}
|
316 |
-
|
317 |
-
protected function render_field( $value, $instance ) {
|
318 |
-
|
319 |
-
if ( $this->wp_version_lt_4_8 ) {
|
320 |
-
$this->render_field_pre48( $value, $instance );
|
321 |
-
return;
|
322 |
-
}
|
323 |
-
|
324 |
-
$selected_editor = in_array( $this->selected_editor, array( 'tinymce', 'tmce' ) ) ? 'tmce' : 'html';
|
325 |
-
|
326 |
-
$tmce_settings = array(
|
327 |
-
'toolbar1' => apply_filters( 'mce_buttons', $this->mce_buttons, $this->element_id ),
|
328 |
-
'toolbar2' => apply_filters( 'mce_buttons_2', $this->mce_buttons_2, $this->element_id ),
|
329 |
-
'toolbar3' => apply_filters( 'mce_buttons_3',$this->mce_buttons_3, $this->element_id ),
|
330 |
-
'toolbar4' => apply_filters( 'mce_buttons_4',$this->mce_buttons_4, $this->element_id ),
|
331 |
-
'plugins' => array_unique( apply_filters( 'tiny_mce_plugins', $this->mce_plugins ) ),
|
332 |
-
);
|
333 |
-
|
334 |
-
foreach ( $tmce_settings as $name => $setting ) {
|
335 |
-
$tmce_settings[ $name ] = is_array( $setting ) ? implode( ',', $setting ) : '';
|
336 |
-
}
|
337 |
-
|
338 |
-
$tmce_settings['external_plugins'] = array_unique( apply_filters( 'mce_external_plugins', $this->mce_external_plugins ) );
|
339 |
-
|
340 |
-
$suffix = SCRIPT_DEBUG ? '' : '.min';
|
341 |
-
$version = 'ver=' . get_bloginfo( 'version' );
|
342 |
-
// Default stylesheets
|
343 |
-
$mce_css = includes_url( "css/dashicons$suffix.css?$version" ) . ',' .
|
344 |
-
includes_url( "js/tinymce/skins/wordpress/wp-content.css?$version" );
|
345 |
-
|
346 |
-
$editor_styles = get_editor_stylesheets();
|
347 |
-
|
348 |
-
if ( ! empty( $editor_styles ) ) {
|
349 |
-
// Force urlencoding of commas.
|
350 |
-
foreach ( $editor_styles as $key => $url ) {
|
351 |
-
if ( strpos( $url, ',' ) !== false ) {
|
352 |
-
$editor_styles[ $key ] = str_replace( ',', '%2C', $url );
|
353 |
-
}
|
354 |
-
}
|
355 |
-
|
356 |
-
$mce_css .= ',' . implode( ',', $editor_styles );
|
357 |
-
}
|
358 |
-
$mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
|
359 |
-
$tmce_settings['content_css'] = $mce_css;
|
360 |
-
|
361 |
-
$qt_settings = apply_filters(
|
362 |
-
'quicktags_settings',
|
363 |
-
array( 'buttons' => $this->quicktags_buttons ),
|
364 |
-
$this->element_id
|
365 |
-
);
|
366 |
-
|
367 |
-
$qt_settings['buttons'] = ! empty( $qt_settings['buttons'] ) ? $qt_settings['buttons'] : array();
|
368 |
-
$qt_settings['buttons'] = is_array( $qt_settings['buttons'] ) ? implode( ',', $qt_settings['buttons'] ) : '';
|
369 |
-
|
370 |
-
$settings = array(
|
371 |
-
'selectedEditor' => $selected_editor,
|
372 |
-
'tinymce' => array(
|
373 |
-
'wp_skip_init' => strpos( $this->element_id, '__i__' ) != false ||
|
374 |
-
strpos( $this->element_id, '_id_' ) != false,
|
375 |
-
'wpautop' => true,
|
376 |
-
),
|
377 |
-
'quicktags' => array(
|
378 |
-
'buttons' => $qt_settings['buttons'],
|
379 |
-
),
|
380 |
-
);
|
381 |
-
|
382 |
-
$tmce_settings = apply_filters( 'tiny_mce_before_init', $tmce_settings, $this->element_id );
|
383 |
-
|
384 |
-
foreach ( $tmce_settings as $name => $setting ) {
|
385 |
-
unset( $jdec );
|
386 |
-
if ( ! empty( $tmce_settings[ $name ] ) ) {
|
387 |
-
// Attempt to decode setting as JSON. For back compat with filters used by WP editor.
|
388 |
-
if ( is_string( $setting ) ) {
|
389 |
-
$jdec = json_decode( $setting, true );
|
390 |
-
}
|
391 |
-
$settings['tinymce'][ $name ] = empty( $jdec ) ? $setting : $jdec;
|
392 |
-
}
|
393 |
-
}
|
394 |
-
|
395 |
-
$value = apply_filters( 'the_editor_content', $value, $this->selected_editor );
|
396 |
-
|
397 |
-
if ( false !== stripos( $value, 'textarea' ) ) {
|
398 |
-
$value = preg_replace( '%</textarea%i', '</textarea', $value );
|
399 |
-
}
|
400 |
-
|
401 |
-
|
402 |
-
$media_buttons = $this->render_media_buttons( $this->element_id );
|
403 |
-
|
404 |
-
?><div class="siteorigin-widget-tinymce-container"
|
405 |
-
data-editor-settings="<?php echo esc_attr( json_encode( $settings ) ) ?>"
|
406 |
-
data-media-buttons="<?php echo esc_attr( json_encode( array( 'html' => $media_buttons ) ) ) ?>">
|
407 |
-
<textarea id="<?php echo esc_attr( $this->element_id ) ?>"
|
408 |
-
name="<?php echo esc_attr( $this->element_name ) ?>"
|
409 |
-
<?php if ( isset( $this->editor_height ) ) : ?>
|
410 |
-
style="height: <?php echo intval( $this->editor_height ) ?>px"
|
411 |
-
<?php else : ?>
|
412 |
-
rows="<?php echo esc_attr( $this->rows ) ?>"
|
413 |
-
<?php endif; ?>
|
414 |
-
<?php $this->render_data_attributes( $this->get_input_data_attributes() ) ?>
|
415 |
-
<?php $this->render_CSS_classes( $this->get_input_classes() ) ?>
|
416 |
-
<?php if ( ! empty( $this->placeholder ) ) echo 'placeholder="' . esc_attr( $this->placeholder ) . '"' ?>
|
417 |
-
<?php if( ! empty( $this->readonly ) ) echo 'readonly' ?>><?php echo htmlentities( $value, ENT_QUOTES, 'UTF-8' ) ?></textarea>
|
418 |
-
</div>
|
419 |
-
<input type="hidden"
|
420 |
-
name="<?php echo esc_attr( $this->for_widget->so_get_field_name( $this->base_name . '_selected_editor', $this->parent_container) ) ?>"
|
421 |
-
class="siteorigin-widget-input siteorigin-widget-tinymce-selected-editor"
|
422 |
-
value="<?php echo esc_attr( $this->selected_editor ) ?>"/>
|
423 |
-
<?php
|
424 |
-
|
425 |
-
}
|
426 |
-
|
427 |
-
private function render_field_pre48( $value, $instance ) {
|
428 |
-
|
429 |
-
$settings = array(
|
430 |
-
'textarea_name' => esc_attr( $this->element_name ),
|
431 |
-
'default_editor' => $this->selected_editor,
|
432 |
-
'textarea_rows' => $this->rows,
|
433 |
-
'editor_class' => 'siteorigin-widget-input',
|
434 |
-
'tinymce' => array(
|
435 |
-
'wp_skip_init' => strpos( $this->element_id, '__i__' ) != false || strpos( $this->element_id, '_id_' ) != false
|
436 |
-
)
|
437 |
-
);
|
438 |
-
if( isset( $this->editor_height ) ) $settings['editor_height'] = $this->editor_height;
|
439 |
-
preg_match( '/widget-(.+?)\[/', $this->element_name, $id_base_matches );
|
440 |
-
$widget_id_base = empty($id_base_matches) || count($id_base_matches) < 2 ? '' : $id_base_matches[1];
|
441 |
-
?>
|
442 |
-
<div class="siteorigin-widget-tinymce-container"
|
443 |
-
data-mce-settings="<?php echo esc_attr( json_encode( $settings['tinymce'] ) ) ?>"
|
444 |
-
data-qt-settings="<?php echo esc_attr( json_encode( array() ) ) ?>"
|
445 |
-
data-widget-id-base="<?php echo esc_attr( $widget_id_base ) ?>"
|
446 |
-
>
|
447 |
-
<?php
|
448 |
-
wp_editor( $value, esc_attr( $this->element_id ), $settings )
|
449 |
-
?>
|
450 |
-
</div>
|
451 |
-
<input type="hidden"
|
452 |
-
name="<?php echo esc_attr( $this->for_widget->so_get_field_name( $this->base_name . '_selected_editor', $this->parent_container) ) ?>"
|
453 |
-
class="siteorigin-widget-input siteorigin-widget-tinymce-selected-editor"
|
454 |
-
value="<?php echo esc_attr( $this->selected_editor ) ?>"/>
|
455 |
-
<?php
|
456 |
-
|
457 |
-
if( $this->selected_editor == 'html' ) {
|
458 |
-
remove_filter( 'the_editor_content', 'wp_htmledit_pre' );
|
459 |
-
}
|
460 |
-
if( $this->selected_editor == 'tinymce' ) {
|
461 |
-
remove_filter( 'the_editor_content', 'wp_richedit_pre' );
|
462 |
-
}
|
463 |
-
}
|
464 |
-
|
465 |
-
public function enqueue_scripts() {
|
466 |
-
|
467 |
-
if ( $this->wp_version_lt_4_8 ) {
|
468 |
-
$src = plugin_dir_url( __FILE__ ) . 'js/tinymce-field-pre48' . SOW_BUNDLE_JS_SUFFIX . '.js';
|
469 |
-
$deps = array( 'jquery', 'editor', 'quicktags' );
|
470 |
-
} else {
|
471 |
-
wp_enqueue_editor();
|
472 |
-
$src = plugin_dir_url( __FILE__ ) . 'js/tinymce-field' . SOW_BUNDLE_JS_SUFFIX . '.js';
|
473 |
-
$deps = array( 'jquery' );
|
474 |
-
}
|
475 |
-
|
476 |
-
wp_enqueue_script( 'so-tinymce-field', $src, $deps, SOW_BUNDLE_VERSION );
|
477 |
-
wp_enqueue_style(
|
478 |
-
'so-tinymce-field', plugin_dir_url( __FILE__ ) . 'css/tinymce-field.css', array(), SOW_BUNDLE_VERSION
|
479 |
-
);
|
480 |
-
}
|
481 |
-
|
482 |
-
protected function sanitize_field_input( $value, $instance ) {
|
483 |
-
if( current_user_can( 'unfiltered_html' ) ) {
|
484 |
-
$sanitized_value = $value;
|
485 |
-
} else {
|
486 |
-
$sanitized_value = wp_kses_post( $value );
|
487 |
-
}
|
488 |
-
$sanitized_value = balanceTags( $sanitized_value , true );
|
489 |
-
return $sanitized_value;
|
490 |
-
}
|
491 |
-
|
492 |
-
public function sanitize_instance( $instance ) {
|
493 |
-
$selected_editor_name = $this->get_selected_editor_field_name( $this->base_name );
|
494 |
-
if( ! empty( $instance[ $selected_editor_name ] ) ) {
|
495 |
-
$selected_editor = $instance[ $selected_editor_name ];
|
496 |
-
$instance[ $selected_editor_name ] = in_array( $selected_editor, array( 'tinymce', 'tmce', 'quicktags', 'html' ) ) ? $selected_editor : $this->default_editor;
|
497 |
-
}
|
498 |
-
return $instance;
|
499 |
-
}
|
500 |
-
|
501 |
-
public function get_selected_editor_field_name( $base_name ) {
|
502 |
-
$v_name = $base_name;
|
503 |
-
if( strpos($v_name, '][') !== false ) {
|
504 |
-
// Remove this splitter
|
505 |
-
$v_name = substr( $v_name, strrpos($v_name, '][') + 2 );
|
506 |
-
}
|
507 |
-
return $v_name . '_selected_editor';
|
508 |
-
}
|
509 |
-
|
510 |
-
private function render_media_buttons( $editor_id ) {
|
511 |
-
|
512 |
-
ob_start();
|
513 |
-
if ( ! function_exists( 'media_buttons' ) ) {
|
514 |
-
include( ABSPATH . 'wp-admin/includes/media.php' );
|
515 |
-
}
|
516 |
-
|
517 |
-
echo '<div id="wp-' . esc_attr( $editor_id ) . '-media-buttons" class="wp-media-buttons">';
|
518 |
-
|
519 |
-
do_action( 'media_buttons', $editor_id );
|
520 |
-
|
521 |
-
echo "</div>\n";
|
522 |
-
|
523 |
-
return ob_get_clean();
|
524 |
-
}
|
525 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class SiteOrigin_Widget_Field_TinyMCE extends SiteOrigin_Widget_Field_Text_Input_Base {
|
4 |
+
/**
|
5 |
+
* The number of visible rows in the textarea.
|
6 |
+
*
|
7 |
+
* @access protected
|
8 |
+
* @var int
|
9 |
+
*/
|
10 |
+
protected $rows = 10;
|
11 |
+
/**
|
12 |
+
* The editor initial height. Overrides rows if it is set.
|
13 |
+
*
|
14 |
+
* @access protected
|
15 |
+
* @var int
|
16 |
+
*/
|
17 |
+
protected $editor_height;
|
18 |
+
/**
|
19 |
+
* The editor to be displayed initially.
|
20 |
+
*
|
21 |
+
* @access protected
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
protected $default_editor = 'tinymce';
|
25 |
+
/**
|
26 |
+
* The last editor selected by the user.
|
27 |
+
*
|
28 |
+
* @access protected
|
29 |
+
* @var string
|
30 |
+
*/
|
31 |
+
protected $selected_editor;
|
32 |
+
/**
|
33 |
+
* An array of the buttons which will be rendered for the first toolbar of the TinyMCE editor.
|
34 |
+
*
|
35 |
+
* @access protected
|
36 |
+
* @var array
|
37 |
+
*/
|
38 |
+
protected $mce_buttons;
|
39 |
+
/**
|
40 |
+
* An array of the buttons which will be rendered for the second toolbar of the TinyMCE editor.
|
41 |
+
*
|
42 |
+
* @access protected
|
43 |
+
* @var array
|
44 |
+
*/
|
45 |
+
protected $mce_buttons_2;
|
46 |
+
/**
|
47 |
+
* An array of the buttons which will be rendered for the third toolbar of the TinyMCE editor.
|
48 |
+
*
|
49 |
+
* @access protected
|
50 |
+
* @var array
|
51 |
+
*/
|
52 |
+
protected $mce_buttons_3;
|
53 |
+
/**
|
54 |
+
* An array of the buttons which will be rendered for the fourth toolbar of the TinyMCE editor.
|
55 |
+
*
|
56 |
+
* @access protected
|
57 |
+
* @var array
|
58 |
+
*/
|
59 |
+
protected $mce_buttons_4;
|
60 |
+
/**
|
61 |
+
* An array of the buttons which will be rendered for the QuickTags editor.
|
62 |
+
*
|
63 |
+
* @access protected
|
64 |
+
* @var array
|
65 |
+
*/
|
66 |
+
protected $quicktags_buttons;
|
67 |
+
/**
|
68 |
+
* An array of filter callbacks to apply to the set of buttons which will be rendered for the editor.
|
69 |
+
*
|
70 |
+
* @access protected
|
71 |
+
* @var array
|
72 |
+
*/
|
73 |
+
protected $button_filters;
|
74 |
+
/**
|
75 |
+
* An array of the included plugins to enable for the TinyMCE editor.
|
76 |
+
*
|
77 |
+
* @access protected
|
78 |
+
* @var array
|
79 |
+
*/
|
80 |
+
protected $mce_plugins;
|
81 |
+
/**
|
82 |
+
* An array of external plugins for the TinyMCE editor.
|
83 |
+
*
|
84 |
+
* @access protected
|
85 |
+
* @var array
|
86 |
+
*/
|
87 |
+
protected $mce_external_plugins;
|
88 |
+
/**
|
89 |
+
* Updated Editor JS API was introduced in WP 4.8 so need to check for compatibility with older versions.
|
90 |
+
*
|
91 |
+
* @access private
|
92 |
+
* @var bool
|
93 |
+
*/
|
94 |
+
private $wp_version_lt_4_8;
|
95 |
+
|
96 |
+
protected function get_default_options() {
|
97 |
+
return array(
|
98 |
+
'mce_buttons' => array(
|
99 |
+
'formatselect',
|
100 |
+
'bold',
|
101 |
+
'italic',
|
102 |
+
'bullist',
|
103 |
+
'numlist',
|
104 |
+
'blockquote',
|
105 |
+
'alignleft',
|
106 |
+
'aligncenter',
|
107 |
+
'alignright',
|
108 |
+
'link',
|
109 |
+
'unlink',
|
110 |
+
'wp_more',
|
111 |
+
'wp_adv',
|
112 |
+
),
|
113 |
+
'mce_buttons_2' => array(
|
114 |
+
'strikethrough',
|
115 |
+
'hr',
|
116 |
+
'forecolor',
|
117 |
+
'pastetext',
|
118 |
+
'removeformat',
|
119 |
+
'charmap',
|
120 |
+
'outdent',
|
121 |
+
'indent',
|
122 |
+
'undo',
|
123 |
+
'redo',
|
124 |
+
'wp_help',
|
125 |
+
),
|
126 |
+
'quicktags_buttons' => array(
|
127 |
+
'strong',
|
128 |
+
'em',
|
129 |
+
'link',
|
130 |
+
'block',
|
131 |
+
'del',
|
132 |
+
'ins',
|
133 |
+
'img',
|
134 |
+
'ul',
|
135 |
+
'ol',
|
136 |
+
'li',
|
137 |
+
'code',
|
138 |
+
'more',
|
139 |
+
'close',
|
140 |
+
),
|
141 |
+
'mce_plugins' => array(
|
142 |
+
'charmap',
|
143 |
+
'colorpicker',
|
144 |
+
'hr',
|
145 |
+
'lists',
|
146 |
+
'media',
|
147 |
+
'paste',
|
148 |
+
'tabfocus',
|
149 |
+
'textcolor',
|
150 |
+
'fullscreen',
|
151 |
+
'wordpress',
|
152 |
+
'wpautoresize',
|
153 |
+
'wpeditimage',
|
154 |
+
'wpemoji',
|
155 |
+
'wpgallery',
|
156 |
+
'wplink',
|
157 |
+
'wpdialogs',
|
158 |
+
'wptextpattern',
|
159 |
+
'wpview',
|
160 |
+
),
|
161 |
+
'mce_external_plugins' => array(),
|
162 |
+
);
|
163 |
+
}
|
164 |
+
|
165 |
+
protected function initialize() {
|
166 |
+
if ( ! is_admin() ) {
|
167 |
+
return;
|
168 |
+
}
|
169 |
+
|
170 |
+
global $wp_version;
|
171 |
+
$this->wp_version_lt_4_8 = version_compare( $wp_version, '4.8', '<' );
|
172 |
+
|
173 |
+
if ( ! empty( $this->wp_version_lt_4_8 ) ) {
|
174 |
+
add_filter( 'mce_buttons', array( $this, 'mce_buttons_filter' ), 10, 2 );
|
175 |
+
add_filter( 'quicktags_settings', array( $this, 'quicktags_settings' ), 10, 2 );
|
176 |
+
}
|
177 |
+
|
178 |
+
if ( ! empty( $this->button_filters ) ) {
|
179 |
+
foreach ( $this->button_filters as $filter_name => $filter ) {
|
180 |
+
$is_valid_filter = preg_match(
|
181 |
+
'/mce_buttons(?:_[1-4])?|quicktags_settings/', $filter_name
|
182 |
+
) && ! empty( $filter ) && is_callable( $filter );
|
183 |
+
if ( $is_valid_filter ) {
|
184 |
+
add_filter( $filter_name, array( $this, $filter_name ), 10, 2 );
|
185 |
+
}
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
if( class_exists( 'WC_Shortcodes_TinyMCE_Buttons' ) ) {
|
190 |
+
if ( ! empty( $this->wp_version_lt_4_8 ) ) {
|
191 |
+
$screen = get_current_screen();
|
192 |
+
if( ! is_null( $screen ) && $screen->id != 'widgets' ) {
|
193 |
+
add_filter( 'mce_external_plugins', array( $this, 'add_wpc_shortcodes_plugin' ), 15 );
|
194 |
+
add_filter( 'mce_buttons', array( $this, 'register_wpc_shortcodes_button' ), 15 );
|
195 |
+
}
|
196 |
+
} else {
|
197 |
+
$this->mce_external_plugins = $this->add_wpc_shortcodes_plugin( $this->mce_external_plugins );
|
198 |
+
$this->mce_buttons = $this->register_wpc_shortcodes_button( $this->mce_buttons );
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
if( class_exists( 'WC_Shortcodes_Admin' ) ) {
|
203 |
+
if ( ! empty( $this->wp_version_lt_4_8 ) ) {
|
204 |
+
|
205 |
+
$screen = get_current_screen();
|
206 |
+
if( ! is_null( $screen ) && $screen->id != 'widgets' ) {
|
207 |
+
add_filter( 'mce_external_plugins', array( $this, 'add_wc_shortcodes_plugin' ), 15 );
|
208 |
+
add_filter( 'mce_buttons', array( $this, 'register_wc_shortcodes_button' ), 15 );
|
209 |
+
}
|
210 |
+
} else {
|
211 |
+
$this->mce_external_plugins = $this->add_wc_shortcodes_plugin( $this->mce_external_plugins );
|
212 |
+
$this->mce_buttons = $this->register_wc_shortcodes_button( $this->mce_buttons );
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
function add_wc_shortcodes_plugin( $plugins ) {
|
218 |
+
if( isset( $plugins['woocommerce_shortcodes'] ) ) {
|
219 |
+
return $plugins;
|
220 |
+
}
|
221 |
+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
222 |
+
$editor_path = 'woocommerce-shortcodes/assets/js/editor' . $suffix . '.js';
|
223 |
+
if( file_exists( WP_PLUGIN_DIR . '/' . $editor_path ) ) {
|
224 |
+
$plugins['woocommerce_shortcodes'] = plugins_url( $editor_path );
|
225 |
+
}
|
226 |
+
return $plugins;
|
227 |
+
}
|
228 |
+
|
229 |
+
function register_wc_shortcodes_button( $buttons ) {
|
230 |
+
if( ! in_array( 'woocommerce_shortcodes', $buttons ) ) {
|
231 |
+
array_push( $buttons, '|', 'woocommerce_shortcodes' );
|
232 |
+
}
|
233 |
+
return $buttons;
|
234 |
+
}
|
235 |
+
|
236 |
+
function add_wpc_shortcodes_plugin( $plugins ) {
|
237 |
+
if( ! isset( $plugins['wpc_shortcodes'] ) ) {
|
238 |
+
$shortcodes_path = 'wc-shortcodes/includes/mce/js/shortcodes-tinymce-4.js';
|
239 |
+
if ( file_exists( WP_PLUGIN_DIR . '/' . $shortcodes_path ) ) {
|
240 |
+
$plugins['wpc_shortcodes'] = plugins_url( $shortcodes_path . '?ver=' . WC_SHORTCODES_VERSION );
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
if( ! isset( $plugins['wpc_font_awesome'] ) ) {
|
245 |
+
$fontawesome_path = 'wc-shortcodes/includes/mce/js/font-awesome-tinymce-4.js';
|
246 |
+
if ( file_exists( WP_PLUGIN_DIR . '/' . $fontawesome_path ) ) {
|
247 |
+
$plugins['wpc_font_awesome'] = plugins_url( $fontawesome_path . '?ver=' . WC_SHORTCODES_VERSION );
|
248 |
+
}
|
249 |
+
}
|
250 |
+
|
251 |
+
return $plugins;
|
252 |
+
}
|
253 |
+
|
254 |
+
function register_wpc_shortcodes_button( $buttons ) {
|
255 |
+
if( ! in_array( 'wpc_shortcodes_button', $buttons ) ) {
|
256 |
+
array_push( $buttons, 'wpc_shortcodes_button' );
|
257 |
+
}
|
258 |
+
if( ! in_array( 'wpcfontAwesomeGlyphSelect', $buttons ) ) {
|
259 |
+
array_push( $buttons, 'wpcfontAwesomeGlyphSelect' );
|
260 |
+
}
|
261 |
+
|
262 |
+
return $buttons;
|
263 |
+
}
|
264 |
+
|
265 |
+
/**
|
266 |
+
* @param $name
|
267 |
+
* @param $arguments
|
268 |
+
* @return array|mixed
|
269 |
+
*/
|
270 |
+
function __call( $name, $arguments ) {
|
271 |
+
if ( preg_match( '/mce_buttons(?:_[1-4])?|quicktags_settings/', $name ) && !empty( $this->button_filters[$name] ) ) {
|
272 |
+
$filter = $this->button_filters[$name];
|
273 |
+
if ( !empty( $filter[0] ) && is_a( $filter[0], 'SiteOrigin_Widget' ) ) {
|
274 |
+
$widget = $filter[0];
|
275 |
+
$settings = !empty($arguments[0]) ? $arguments[0] : array();
|
276 |
+
$editor_id = !empty($arguments[1]) ? $arguments[1] : '';
|
277 |
+
if ( preg_match( '/widget-' . $widget->id_base . '-.*-' . $this->base_name . '/', $editor_id ) ) {
|
278 |
+
return call_user_func( $filter, $settings, $editor_id );
|
279 |
+
}
|
280 |
+
else {
|
281 |
+
return $settings;
|
282 |
+
}
|
283 |
+
}
|
284 |
+
}
|
285 |
+
}
|
286 |
+
|
287 |
+
public function mce_buttons_filter( $buttons, $editor_id ) {
|
288 |
+
if (($key = array_search('fullscreen', $buttons)) !== false) {
|
289 |
+
unset($buttons[$key]);
|
290 |
+
}
|
291 |
+
return $buttons;
|
292 |
+
}
|
293 |
+
|
294 |
+
public function quicktags_settings( $settings, $editor_id ) {
|
295 |
+
$settings['buttons'] = preg_replace( '/,fullscreen/', '', $settings['buttons'] );
|
296 |
+
$settings['buttons'] = preg_replace( '/,dfw/', '', $settings['buttons'] );
|
297 |
+
return $settings;
|
298 |
+
}
|
299 |
+
|
300 |
+
protected function get_input_classes() {
|
301 |
+
$classes = parent::get_input_classes();
|
302 |
+
$classes[] = 'wp-editor-area';
|
303 |
+
return $classes;
|
304 |
+
}
|
305 |
+
|
306 |
+
protected function render_before_field( $value, $instance ) {
|
307 |
+
$selected_editor_name = $this->get_selected_editor_field_name( $this->base_name );
|
308 |
+
if( ! empty( $instance[ $selected_editor_name ] ) ) {
|
309 |
+
$this->selected_editor = $instance[ $selected_editor_name ];
|
310 |
+
}
|
311 |
+
else {
|
312 |
+
$this->selected_editor = $this->default_editor;
|
313 |
+
}
|
314 |
+
parent::render_before_field( $value, $instance );
|
315 |
+
}
|
316 |
+
|
317 |
+
protected function render_field( $value, $instance ) {
|
318 |
+
|
319 |
+
if ( $this->wp_version_lt_4_8 ) {
|
320 |
+
$this->render_field_pre48( $value, $instance );
|
321 |
+
return;
|
322 |
+
}
|
323 |
+
|
324 |
+
$selected_editor = in_array( $this->selected_editor, array( 'tinymce', 'tmce' ) ) ? 'tmce' : 'html';
|
325 |
+
|
326 |
+
$tmce_settings = array(
|
327 |
+
'toolbar1' => apply_filters( 'mce_buttons', $this->mce_buttons, $this->element_id ),
|
328 |
+
'toolbar2' => apply_filters( 'mce_buttons_2', $this->mce_buttons_2, $this->element_id ),
|
329 |
+
'toolbar3' => apply_filters( 'mce_buttons_3',$this->mce_buttons_3, $this->element_id ),
|
330 |
+
'toolbar4' => apply_filters( 'mce_buttons_4',$this->mce_buttons_4, $this->element_id ),
|
331 |
+
'plugins' => array_unique( apply_filters( 'tiny_mce_plugins', $this->mce_plugins ) ),
|
332 |
+
);
|
333 |
+
|
334 |
+
foreach ( $tmce_settings as $name => $setting ) {
|
335 |
+
$tmce_settings[ $name ] = is_array( $setting ) ? implode( ',', $setting ) : '';
|
336 |
+
}
|
337 |
+
|
338 |
+
$tmce_settings['external_plugins'] = array_unique( apply_filters( 'mce_external_plugins', $this->mce_external_plugins ) );
|
339 |
+
|
340 |
+
$suffix = SCRIPT_DEBUG ? '' : '.min';
|
341 |
+
$version = 'ver=' . get_bloginfo( 'version' );
|
342 |
+
// Default stylesheets
|
343 |
+
$mce_css = includes_url( "css/dashicons$suffix.css?$version" ) . ',' .
|
344 |
+
includes_url( "js/tinymce/skins/wordpress/wp-content.css?$version" );
|
345 |
+
|
346 |
+
$editor_styles = get_editor_stylesheets();
|
347 |
+
|
348 |
+
if ( ! empty( $editor_styles ) ) {
|
349 |
+
// Force urlencoding of commas.
|
350 |
+
foreach ( $editor_styles as $key => $url ) {
|
351 |
+
if ( strpos( $url, ',' ) !== false ) {
|
352 |
+
$editor_styles[ $key ] = str_replace( ',', '%2C', $url );
|
353 |
+
}
|
354 |
+
}
|
355 |
+
|
356 |
+
$mce_css .= ',' . implode( ',', $editor_styles );
|
357 |
+
}
|
358 |
+
$mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
|
359 |
+
$tmce_settings['content_css'] = $mce_css;
|
360 |
+
|
361 |
+
$qt_settings = apply_filters(
|
362 |
+
'quicktags_settings',
|
363 |
+
array( 'buttons' => $this->quicktags_buttons ),
|
364 |
+
$this->element_id
|
365 |
+
);
|
366 |
+
|
367 |
+
$qt_settings['buttons'] = ! empty( $qt_settings['buttons'] ) ? $qt_settings['buttons'] : array();
|
368 |
+
$qt_settings['buttons'] = is_array( $qt_settings['buttons'] ) ? implode( ',', $qt_settings['buttons'] ) : '';
|
369 |
+
|
370 |
+
$settings = array(
|
371 |
+
'selectedEditor' => $selected_editor,
|
372 |
+
'tinymce' => array(
|
373 |
+
'wp_skip_init' => strpos( $this->element_id, '__i__' ) != false ||
|
374 |
+
strpos( $this->element_id, '_id_' ) != false,
|
375 |
+
'wpautop' => true,
|
376 |
+
),
|
377 |
+
'quicktags' => array(
|
378 |
+
'buttons' => $qt_settings['buttons'],
|
379 |
+
),
|
380 |
+
);
|
381 |
+
|
382 |
+
$tmce_settings = apply_filters( 'tiny_mce_before_init', $tmce_settings, $this->element_id );
|
383 |
+
|
384 |
+
foreach ( $tmce_settings as $name => $setting ) {
|
385 |
+
unset( $jdec );
|
386 |
+
if ( ! empty( $tmce_settings[ $name ] ) ) {
|
387 |
+
// Attempt to decode setting as JSON. For back compat with filters used by WP editor.
|
388 |
+
if ( is_string( $setting ) ) {
|
389 |
+
$jdec = json_decode( $setting, true );
|
390 |
+
}
|
391 |
+
$settings['tinymce'][ $name ] = empty( $jdec ) ? $setting : $jdec;
|
392 |
+
}
|
393 |
+
}
|
394 |
+
|
395 |
+
$value = apply_filters( 'the_editor_content', $value, $this->selected_editor );
|
396 |
+
|
397 |
+
if ( false !== stripos( $value, 'textarea' ) ) {
|
398 |
+
$value = preg_replace( '%</textarea%i', '</textarea', $value );
|
399 |
+
}
|
400 |
+
|
401 |
+
|
402 |
+
$media_buttons = $this->render_media_buttons( $this->element_id );
|
403 |
+
|
404 |
+
?><div class="siteorigin-widget-tinymce-container"
|
405 |
+
data-editor-settings="<?php echo esc_attr( json_encode( $settings ) ) ?>"
|
406 |
+
data-media-buttons="<?php echo esc_attr( json_encode( array( 'html' => $media_buttons ) ) ) ?>">
|
407 |
+
<textarea id="<?php echo esc_attr( $this->element_id ) ?>"
|
408 |
+
name="<?php echo esc_attr( $this->element_name ) ?>"
|
409 |
+
<?php if ( isset( $this->editor_height ) ) : ?>
|
410 |
+
style="height: <?php echo intval( $this->editor_height ) ?>px"
|
411 |
+
<?php else : ?>
|
412 |
+
rows="<?php echo esc_attr( $this->rows ) ?>"
|
413 |
+
<?php endif; ?>
|
414 |
+
<?php $this->render_data_attributes( $this->get_input_data_attributes() ) ?>
|
415 |
+
<?php $this->render_CSS_classes( $this->get_input_classes() ) ?>
|
416 |
+
<?php if ( ! empty( $this->placeholder ) ) echo 'placeholder="' . esc_attr( $this->placeholder ) . '"' ?>
|
417 |
+
<?php if( ! empty( $this->readonly ) ) echo 'readonly' ?>><?php echo htmlentities( $value, ENT_QUOTES, 'UTF-8' ) ?></textarea>
|
418 |
+
</div>
|
419 |
+
<input type="hidden"
|
420 |
+
name="<?php echo esc_attr( $this->for_widget->so_get_field_name( $this->base_name . '_selected_editor', $this->parent_container) ) ?>"
|
421 |
+
class="siteorigin-widget-input siteorigin-widget-tinymce-selected-editor"
|
422 |
+
value="<?php echo esc_attr( $this->selected_editor ) ?>"/>
|
423 |
+
<?php
|
424 |
+
|
425 |
+
}
|
426 |
+
|
427 |
+
private function render_field_pre48( $value, $instance ) {
|
428 |
+
|
429 |
+
$settings = array(
|
430 |
+
'textarea_name' => esc_attr( $this->element_name ),
|
431 |
+
'default_editor' => $this->selected_editor,
|
432 |
+
'textarea_rows' => $this->rows,
|
433 |
+
'editor_class' => 'siteorigin-widget-input',
|
434 |
+
'tinymce' => array(
|
435 |
+
'wp_skip_init' => strpos( $this->element_id, '__i__' ) != false || strpos( $this->element_id, '_id_' ) != false
|
436 |
+
)
|
437 |
+
);
|
438 |
+
if( isset( $this->editor_height ) ) $settings['editor_height'] = $this->editor_height;
|
439 |
+
preg_match( '/widget-(.+?)\[/', $this->element_name, $id_base_matches );
|
440 |
+
$widget_id_base = empty($id_base_matches) || count($id_base_matches) < 2 ? '' : $id_base_matches[1];
|
441 |
+
?>
|
442 |
+
<div class="siteorigin-widget-tinymce-container"
|
443 |
+
data-mce-settings="<?php echo esc_attr( json_encode( $settings['tinymce'] ) ) ?>"
|
444 |
+
data-qt-settings="<?php echo esc_attr( json_encode( array() ) ) ?>"
|
445 |
+
data-widget-id-base="<?php echo esc_attr( $widget_id_base ) ?>"
|
446 |
+
>
|
447 |
+
<?php
|
448 |
+
wp_editor( $value, esc_attr( $this->element_id ), $settings )
|
449 |
+
?>
|
450 |
+
</div>
|
451 |
+
<input type="hidden"
|
452 |
+
name="<?php echo esc_attr( $this->for_widget->so_get_field_name( $this->base_name . '_selected_editor', $this->parent_container) ) ?>"
|
453 |
+
class="siteorigin-widget-input siteorigin-widget-tinymce-selected-editor"
|
454 |
+
value="<?php echo esc_attr( $this->selected_editor ) ?>"/>
|
455 |
+
<?php
|
456 |
+
|
457 |
+
if( $this->selected_editor == 'html' ) {
|
458 |
+
remove_filter( 'the_editor_content', 'wp_htmledit_pre' );
|
459 |
+
}
|
460 |
+
if( $this->selected_editor == 'tinymce' ) {
|
461 |
+
remove_filter( 'the_editor_content', 'wp_richedit_pre' );
|
462 |
+
}
|
463 |
+
}
|
464 |
+
|
465 |
+
public function enqueue_scripts() {
|
466 |
+
|
467 |
+
if ( $this->wp_version_lt_4_8 ) {
|
468 |
+
$src = plugin_dir_url( __FILE__ ) . 'js/tinymce-field-pre48' . SOW_BUNDLE_JS_SUFFIX . '.js';
|
469 |
+
$deps = array( 'jquery', 'editor', 'quicktags' );
|
470 |
+
} else {
|
471 |
+
wp_enqueue_editor();
|
472 |
+
$src = plugin_dir_url( __FILE__ ) . 'js/tinymce-field' . SOW_BUNDLE_JS_SUFFIX . '.js';
|
473 |
+
$deps = array( 'jquery' );
|
474 |
+
}
|
475 |
+
|
476 |
+
wp_enqueue_script( 'so-tinymce-field', $src, $deps, SOW_BUNDLE_VERSION );
|
477 |
+
wp_enqueue_style(
|
478 |
+
'so-tinymce-field', plugin_dir_url( __FILE__ ) . 'css/tinymce-field.css', array(), SOW_BUNDLE_VERSION
|
479 |
+
);
|
480 |
+
}
|
481 |
+
|
482 |
+
protected function sanitize_field_input( $value, $instance ) {
|
483 |
+
if( current_user_can( 'unfiltered_html' ) ) {
|
484 |
+
$sanitized_value = $value;
|
485 |
+
} else {
|
486 |
+
$sanitized_value = wp_kses_post( $value );
|
487 |
+
}
|
488 |
+
$sanitized_value = balanceTags( $sanitized_value , true );
|
489 |
+
return $sanitized_value;
|
490 |
+
}
|
491 |
+
|
492 |
+
public function sanitize_instance( $instance ) {
|
493 |
+
$selected_editor_name = $this->get_selected_editor_field_name( $this->base_name );
|
494 |
+
if( ! empty( $instance[ $selected_editor_name ] ) ) {
|
495 |
+
$selected_editor = $instance[ $selected_editor_name ];
|
496 |
+
$instance[ $selected_editor_name ] = in_array( $selected_editor, array( 'tinymce', 'tmce', 'quicktags', 'html' ) ) ? $selected_editor : $this->default_editor;
|
497 |
+
}
|
498 |
+
return $instance;
|
499 |
+
}
|
500 |
+
|
501 |
+
public function get_selected_editor_field_name( $base_name ) {
|
502 |
+
$v_name = $base_name;
|
503 |
+
if( strpos($v_name, '][') !== false ) {
|
504 |
+
// Remove this splitter
|
505 |
+
$v_name = substr( $v_name, strrpos($v_name, '][') + 2 );
|
506 |
+
}
|
507 |
+
return $v_name . '_selected_editor';
|
508 |
+
}
|
509 |
+
|
510 |
+
private function render_media_buttons( $editor_id ) {
|
511 |
+
|
512 |
+
ob_start();
|
513 |
+
if ( ! function_exists( 'media_buttons' ) ) {
|
514 |
+
include( ABSPATH . 'wp-admin/includes/media.php' );
|
515 |
+
}
|
516 |
+
|
517 |
+
echo '<div id="wp-' . esc_attr( $editor_id ) . '-media-buttons" class="wp-media-buttons">';
|
518 |
+
|
519 |
+
do_action( 'media_buttons', $editor_id );
|
520 |
+
|
521 |
+
echo "</div>\n";
|
522 |
+
|
523 |
+
return ob_get_clean();
|
524 |
+
}
|
525 |
+
}
|
base/inc/post-selector.php
CHANGED
@@ -1,134 +1,134 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Filter a query created from the post selector field into an array that will work properly with get_posts
|
5 |
-
*
|
6 |
-
* @param $query
|
7 |
-
*
|
8 |
-
* @return mixed
|
9 |
-
*/
|
10 |
-
function siteorigin_widget_post_selector_process_query( $query ){
|
11 |
-
$query = wp_parse_args($query,
|
12 |
-
array(
|
13 |
-
'post_status' => 'publish',
|
14 |
-
'posts_per_page' => 10,
|
15 |
-
)
|
16 |
-
);
|
17 |
-
|
18 |
-
if( !empty( $query['post_type'] ) ) {
|
19 |
-
if($query['post_type'] == '_all') $query['post_type'] = siteorigin_widget_post_selector_all_post_types();
|
20 |
-
$query['post_type'] = strpos( $query['post_type'], ',' ) !== false ? explode( ',', $query['post_type'] ) : $query['post_type'];
|
21 |
-
}
|
22 |
-
if( !empty( $query['post_type'] ) && $query['post_type'] == 'attachment' && $query['post_status'] == 'publish' ) {
|
23 |
-
$query['post_status'] = 'inherit';
|
24 |
-
}
|
25 |
-
|
26 |
-
|
27 |
-
if(!empty($query['post__in'])) {
|
28 |
-
$query['post__in'] = explode(',', $query['post__in']);
|
29 |
-
$query['post__in'] = array_map('intval', $query['post__in']);
|
30 |
-
}
|
31 |
-
|
32 |
-
if(!empty($query['tax_query'])) {
|
33 |
-
$tax_queries = explode(',', $query['tax_query']);
|
34 |
-
|
35 |
-
$query['tax_query'] = array();
|
36 |
-
$query['tax_query']['relation'] = 'OR';
|
37 |
-
foreach($tax_queries as $tq) {
|
38 |
-
list($tax, $term) = explode(':', $tq);
|
39 |
-
|
40 |
-
if( empty($tax) || empty($term) ) continue;
|
41 |
-
$query['tax_query'][] = array(
|
42 |
-
'taxonomy' => $tax,
|
43 |
-
'field' => 'slug',
|
44 |
-
'terms' => $term
|
45 |
-
);
|
46 |
-
}
|
47 |
-
}
|
48 |
-
|
49 |
-
if ( isset( $query['date_type'] ) && $query['date_type'] == 'relative' ) {
|
50 |
-
|
51 |
-
$date_query_rel = json_decode(
|
52 |
-
stripslashes( $query['date_query_relative'] ),
|
53 |
-
true
|
54 |
-
);
|
55 |
-
$value_after = new DateTime(
|
56 |
-
$date_query_rel['from']['value'] . ' ' . $date_query_rel['from']['unit'] . ' ago'
|
57 |
-
);
|
58 |
-
$value['after'] = $value_after->format( 'Y-m-d' );
|
59 |
-
$value_before = new DateTime(
|
60 |
-
$date_query_rel['to']['value'] . ' ' . $date_query_rel['to']['unit'] . ' ago'
|
61 |
-
);
|
62 |
-
$value['before'] = $value_before->format( 'Y-m-d' );
|
63 |
-
$query['date_query'] = $value;
|
64 |
-
unset( $query['date_type'] );
|
65 |
-
unset( $query['date_query_relative'] );
|
66 |
-
} else if ( ! empty( $query['date_query'] ) ) {
|
67 |
-
$query['date_query'] = json_decode( stripslashes( $query['date_query'] ), true );
|
68 |
-
}
|
69 |
-
|
70 |
-
if ( ! empty( $query['date_query'] ) ) {
|
71 |
-
$query['date_query']['inclusive'] = true;
|
72 |
-
}
|
73 |
-
|
74 |
-
if ( ! empty( $query['sticky'] ) ) {
|
75 |
-
switch($query['sticky']){
|
76 |
-
case 'ignore' :
|
77 |
-
$query['ignore_sticky_posts'] = 1;
|
78 |
-
break;
|
79 |
-
case 'only' :
|
80 |
-
$post_in = empty( $query['post__in'] ) ? array() : $query['post__in'];
|
81 |
-
$query['post__in'] = array_merge( $post_in, get_option( 'sticky_posts' ) );
|
82 |
-
break;
|
83 |
-
case 'exclude' :
|
84 |
-
$query['post__not_in'] = get_option( 'sticky_posts' );
|
85 |
-
break;
|
86 |
-
}
|
87 |
-
unset( $query['sticky'] );
|
88 |
-
}
|
89 |
-
|
90 |
-
// Exclude the current post (if applicable) to avoid any issues associated with showing the same post again
|
91 |
-
if( is_singular() && get_the_id() != false ){
|
92 |
-
$query['post__not_in'][] = get_the_id();
|
93 |
-
}
|
94 |
-
|
95 |
-
if ( ! empty( $query['additional'] ) ) {
|
96 |
-
$query = wp_parse_args( $query['additional'], $query );
|
97 |
-
unset( $query['additional'] );
|
98 |
-
|
99 |
-
// If post_not_in is set, we need to convert it to an array to avoid issues with the query.
|
100 |
-
if( !empty( $query['post__not_in'] ) && !is_array( $query['post__not_in'] ) ){
|
101 |
-
$query['post__not_in'] = explode( ',', $query['post__not_in'] );
|
102 |
-
$query['post__not_in'] = array_map( 'intval', $query['post__not_in'] );
|
103 |
-
}
|
104 |
-
}
|
105 |
-
|
106 |
-
return apply_filters( 'siteorigin_widgets_posts_selector_query', $query );
|
107 |
-
}
|
108 |
-
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Just return a comma separated list of all available post types.
|
112 |
-
*
|
113 |
-
* @return string
|
114 |
-
*/
|
115 |
-
function siteorigin_widget_post_selector_all_post_types(){
|
116 |
-
$post_types = array();
|
117 |
-
foreach( get_post_types( array( 'public' => true ), 'objects' ) as $id => $type ) {
|
118 |
-
$post_types[] = $id;
|
119 |
-
}
|
120 |
-
|
121 |
-
return implode(',', $post_types);
|
122 |
-
}
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Tells us how many posts this query has
|
126 |
-
*
|
127 |
-
* @param $query
|
128 |
-
* @return int
|
129 |
-
*/
|
130 |
-
function siteorigin_widget_post_selector_count_posts( $query ) {
|
131 |
-
$query = siteorigin_widget_post_selector_process_query( $query );
|
132 |
-
$posts = new WP_Query($query);
|
133 |
-
return $posts->found_posts;
|
134 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Filter a query created from the post selector field into an array that will work properly with get_posts
|
5 |
+
*
|
6 |
+
* @param $query
|
7 |
+
*
|
8 |
+
* @return mixed
|
9 |
+
*/
|
10 |
+
function siteorigin_widget_post_selector_process_query( $query ){
|
11 |
+
$query = wp_parse_args($query,
|
12 |
+
array(
|
13 |
+
'post_status' => 'publish',
|
14 |
+
'posts_per_page' => 10,
|
15 |
+
)
|
16 |
+
);
|
17 |
+
|
18 |
+
if( !empty( $query['post_type'] ) ) {
|
19 |
+
if($query['post_type'] == '_all') $query['post_type'] = siteorigin_widget_post_selector_all_post_types();
|
20 |
+
$query['post_type'] = strpos( $query['post_type'], ',' ) !== false ? explode( ',', $query['post_type'] ) : $query['post_type'];
|
21 |
+
}
|
22 |
+
if( !empty( $query['post_type'] ) && $query['post_type'] == 'attachment' && $query['post_status'] == 'publish' ) {
|
23 |
+
$query['post_status'] = 'inherit';
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
if(!empty($query['post__in'])) {
|
28 |
+
$query['post__in'] = explode(',', $query['post__in']);
|
29 |
+
$query['post__in'] = array_map('intval', $query['post__in']);
|
30 |
+
}
|
31 |
+
|
32 |
+
if(!empty($query['tax_query'])) {
|
33 |
+
$tax_queries = explode(',', $query['tax_query']);
|
34 |
+
|
35 |
+
$query['tax_query'] = array();
|
36 |
+
$query['tax_query']['relation'] = 'OR';
|
37 |
+
foreach($tax_queries as $tq) {
|
38 |
+
list($tax, $term) = explode(':', $tq);
|
39 |
+
|
40 |
+
if( empty($tax) || empty($term) ) continue;
|
41 |
+
$query['tax_query'][] = array(
|
42 |
+
'taxonomy' => $tax,
|
43 |
+
'field' => 'slug',
|
44 |
+
'terms' => $term
|
45 |
+
);
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( isset( $query['date_type'] ) && $query['date_type'] == 'relative' ) {
|
50 |
+
|
51 |
+
$date_query_rel = json_decode(
|
52 |
+
stripslashes( $query['date_query_relative'] ),
|
53 |
+
true
|
54 |
+
);
|
55 |
+
$value_after = new DateTime(
|
56 |
+
$date_query_rel['from']['value'] . ' ' . $date_query_rel['from']['unit'] . ' ago'
|
57 |
+
);
|
58 |
+
$value['after'] = $value_after->format( 'Y-m-d' );
|
59 |
+
$value_before = new DateTime(
|
60 |
+
$date_query_rel['to']['value'] . ' ' . $date_query_rel['to']['unit'] . ' ago'
|
61 |
+
);
|
62 |
+
$value['before'] = $value_before->format( 'Y-m-d' );
|
63 |
+
$query['date_query'] = $value;
|
64 |
+
unset( $query['date_type'] );
|
65 |
+
unset( $query['date_query_relative'] );
|
66 |
+
} else if ( ! empty( $query['date_query'] ) ) {
|
67 |
+
$query['date_query'] = json_decode( stripslashes( $query['date_query'] ), true );
|
68 |
+
}
|
69 |
+
|
70 |
+
if ( ! empty( $query['date_query'] ) ) {
|
71 |
+
$query['date_query']['inclusive'] = true;
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( ! empty( $query['sticky'] ) ) {
|
75 |
+
switch($query['sticky']){
|
76 |
+
case 'ignore' :
|
77 |
+
$query['ignore_sticky_posts'] = 1;
|
78 |
+
break;
|
79 |
+
case 'only' :
|
80 |
+
$post_in = empty( $query['post__in'] ) ? array() : $query['post__in'];
|
81 |
+
$query['post__in'] = array_merge( $post_in, get_option( 'sticky_posts' ) );
|
82 |
+
break;
|
83 |
+
case 'exclude' :
|
84 |
+
$query['post__not_in'] = get_option( 'sticky_posts' );
|
85 |
+
break;
|
86 |
+
}
|
87 |
+
unset( $query['sticky'] );
|
88 |
+
}
|
89 |
+
|
90 |
+
// Exclude the current post (if applicable) to avoid any issues associated with showing the same post again
|
91 |
+
if( is_singular() && get_the_id() != false ){
|
92 |
+
$query['post__not_in'][] = get_the_id();
|
93 |
+
}
|
94 |
+
|
95 |
+
if ( ! empty( $query['additional'] ) ) {
|
96 |
+
$query = wp_parse_args( $query['additional'], $query );
|
97 |
+
unset( $query['additional'] );
|
98 |
+
|
99 |
+
// If post_not_in is set, we need to convert it to an array to avoid issues with the query.
|
100 |
+
if( !empty( $query['post__not_in'] ) && !is_array( $query['post__not_in'] ) ){
|
101 |
+
$query['post__not_in'] = explode( ',', $query['post__not_in'] );
|
102 |
+
$query['post__not_in'] = array_map( 'intval', $query['post__not_in'] );
|
103 |
+
}
|
104 |
+
}
|
105 |
+
|
106 |
+
return apply_filters( 'siteorigin_widgets_posts_selector_query', $query );
|
107 |
+
}
|
108 |
+
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Just return a comma separated list of all available post types.
|
112 |
+
*
|
113 |
+
* @return string
|
114 |
+
*/
|
115 |
+
function siteorigin_widget_post_selector_all_post_types(){
|
116 |
+
$post_types = array();
|
117 |
+
foreach( get_post_types( array( 'public' => true ), 'objects' ) as $id => $type ) {
|
118 |
+
$post_types[] = $id;
|
119 |
+
}
|
120 |
+
|
121 |
+
return implode(',', $post_types);
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Tells us how many posts this query has
|
126 |
+
*
|
127 |
+
* @param $query
|
128 |
+
* @return int
|
129 |
+
*/
|
130 |
+
function siteorigin_widget_post_selector_count_posts( $query ) {
|
131 |
+
$query = siteorigin_widget_post_selector_process_query( $query );
|
132 |
+
$posts = new WP_Query($query);
|
133 |
+
return $posts->found_posts;
|
134 |
+
}
|
base/inc/widget-manager.class.php
CHANGED
@@ -1,167 +1,167 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Handles registering Widgets Bundle widgets.
|
5 |
-
*
|
6 |
-
* Class SiteOrigin_Widgets_Widget_Manager
|
7 |
-
*/
|
8 |
-
class SiteOrigin_Widgets_Widget_Manager {
|
9 |
-
/**
|
10 |
-
* Regsitered widgets
|
11 |
-
*
|
12 |
-
* @var
|
13 |
-
*/
|
14 |
-
private $registered;
|
15 |
-
|
16 |
-
function __construct(){
|
17 |
-
$this->registered = array();
|
18 |
-
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
|
19 |
-
}
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Get the single instance.
|
23 |
-
*
|
24 |
-
* @return SiteOrigin_Widgets_Widget_Manager
|
25 |
-
*/
|
26 |
-
static function single() {
|
27 |
-
static $single;
|
28 |
-
|
29 |
-
if( empty($single) ) {
|
30 |
-
$single = new self();
|
31 |
-
}
|
32 |
-
|
33 |
-
return $single;
|
34 |
-
}
|
35 |
-
|
36 |
-
/**
|
37 |
-
* @param $id
|
38 |
-
* @param $path
|
39 |
-
* @param bool|false $class
|
40 |
-
* @return mixed
|
41 |
-
*/
|
42 |
-
public function register( $id, $path, $class = false ){
|
43 |
-
$path = wp_normalize_path( $path );
|
44 |
-
if ( empty( $class ) ) {
|
45 |
-
$class = 'SiteOrigin_Widget_' . str_replace( ' ', '', ucwords( str_replace('-', ' ', $id) ) ) . '_Widget';
|
46 |
-
}
|
47 |
-
|
48 |
-
$this->registered[ $id ] = new stdClass();
|
49 |
-
$this->registered[ $id ]->path = $path;
|
50 |
-
$this->registered[ $id ]->class = $class;
|
51 |
-
$this->registered[ $id ]->registered = false;
|
52 |
-
|
53 |
-
return $this->registered[ $id ];
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Initialize all the widgets.
|
58 |
-
*/
|
59 |
-
public function widgets_init(){
|
60 |
-
foreach( $this->registered as $id => & $info ) {
|
61 |
-
if( $info->registered ) continue;
|
62 |
-
register_widget( $info->class );
|
63 |
-
$info->registered = true;
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Get the path of the widget
|
69 |
-
*
|
70 |
-
* @param $id
|
71 |
-
*
|
72 |
-
* @return bool
|
73 |
-
*/
|
74 |
-
public function get_plugin_path( $id ) {
|
75 |
-
if( empty( $this->registered[ $id ] ) ) {
|
76 |
-
// This call might be using the incorrect ID convention.
|
77 |
-
if( substr($id, 0, 4) == 'sow-' ) $id = substr($id, 4);
|
78 |
-
else $id = 'sow-' . $id;
|
79 |
-
}
|
80 |
-
|
81 |
-
return !empty($this->registered[$id]) ? $this->registered[$id]->path : false;
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* @param $id
|
86 |
-
*
|
87 |
-
* @return string
|
88 |
-
*
|
89 |
-
* @todo examine this when using a widget in a theme folder.
|
90 |
-
*/
|
91 |
-
function get_plugin_dir_path( $id ){
|
92 |
-
return plugin_dir_path( $this->get_plugin_path( $id ) );
|
93 |
-
}
|
94 |
-
|
95 |
-
function get_plugin_dir_url( $id ){
|
96 |
-
return plugin_dir_url( $this->get_plugin_path( $id ) );
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Get a widget ID from a file path
|
101 |
-
*
|
102 |
-
* @param string $path The file path.
|
103 |
-
*
|
104 |
-
* @return string The ID.
|
105 |
-
*/
|
106 |
-
function get_id_from_path( $path ){
|
107 |
-
foreach( $this->registered as $id => $r ) {
|
108 |
-
if( $r->path == $path ) return $id;
|
109 |
-
}
|
110 |
-
return false;
|
111 |
-
}
|
112 |
-
|
113 |
-
/**
|
114 |
-
* Get the class name of a widget from the
|
115 |
-
*
|
116 |
-
* @param $path
|
117 |
-
* @return mixed
|
118 |
-
*/
|
119 |
-
function get_class_from_path( $path ) {
|
120 |
-
foreach( $this->registered as $id => $r ) {
|
121 |
-
if( $r->path == $path ) return $r->class;
|
122 |
-
}
|
123 |
-
return false;
|
124 |
-
}
|
125 |
-
}
|
126 |
-
SiteOrigin_Widgets_Widget_Manager::single();
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Register a widget
|
130 |
-
*
|
131 |
-
* @param string $id The ID of the widget
|
132 |
-
* @param string $path The path of the widget
|
133 |
-
* @param bool|string $class The name of the class
|
134 |
-
*/
|
135 |
-
function siteorigin_widget_register( $id, $path, $class = false ){
|
136 |
-
SiteOrigin_Widgets_Widget_Manager::single()->register( $id, $path, $class );
|
137 |
-
}
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Get the base file of a widget plugin
|
141 |
-
*
|
142 |
-
* @param $name
|
143 |
-
* @return bool
|
144 |
-
*/
|
145 |
-
function siteorigin_widget_get_plugin_path($id){
|
146 |
-
return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_path( $id );
|
147 |
-
}
|
148 |
-
|
149 |
-
/**
|
150 |
-
* Get the base path folder of a widget plugin.
|
151 |
-
*
|
152 |
-
* @param $id
|
153 |
-
* @return string
|
154 |
-
*/
|
155 |
-
function siteorigin_widget_get_plugin_dir_path($id){
|
156 |
-
return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_dir_path( $id );
|
157 |
-
}
|
158 |
-
|
159 |
-
/**
|
160 |
-
* Get the base path URL of a widget plugin.
|
161 |
-
*
|
162 |
-
* @param $id
|
163 |
-
* @return string
|
164 |
-
*/
|
165 |
-
function siteorigin_widget_get_plugin_dir_url($id){
|
166 |
-
return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_dir_url( $id );
|
167 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Handles registering Widgets Bundle widgets.
|
5 |
+
*
|
6 |
+
* Class SiteOrigin_Widgets_Widget_Manager
|
7 |
+
*/
|
8 |
+
class SiteOrigin_Widgets_Widget_Manager {
|
9 |
+
/**
|
10 |
+
* Regsitered widgets
|
11 |
+
*
|
12 |
+
* @var
|
13 |
+
*/
|
14 |
+
private $registered;
|
15 |
+
|
16 |
+
function __construct(){
|
17 |
+
$this->registered = array();
|
18 |
+
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Get the single instance.
|
23 |
+
*
|
24 |
+
* @return SiteOrigin_Widgets_Widget_Manager
|
25 |
+
*/
|
26 |
+
static function single() {
|
27 |
+
static $single;
|
28 |
+
|
29 |
+
if( empty($single) ) {
|
30 |
+
$single = new self();
|
31 |
+
}
|
32 |
+
|
33 |
+
return $single;
|
34 |
+
}
|
35 |
+
|
36 |
+
/**
|
37 |
+
* @param $id
|
38 |
+
* @param $path
|
39 |
+
* @param bool|false $class
|
40 |
+
* @return mixed
|
41 |
+
*/
|
42 |
+
public function register( $id, $path, $class = false ){
|
43 |
+
$path = wp_normalize_path( $path );
|
44 |
+
if ( empty( $class ) ) {
|
45 |
+
$class = 'SiteOrigin_Widget_' . str_replace( ' ', '', ucwords( str_replace('-', ' ', $id) ) ) . '_Widget';
|
46 |
+
}
|
47 |
+
|
48 |
+
$this->registered[ $id ] = new stdClass();
|
49 |
+
$this->registered[ $id ]->path = $path;
|
50 |
+
$this->registered[ $id ]->class = $class;
|
51 |
+
$this->registered[ $id ]->registered = false;
|
52 |
+
|
53 |
+
return $this->registered[ $id ];
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Initialize all the widgets.
|
58 |
+
*/
|
59 |
+
public function widgets_init(){
|
60 |
+
foreach( $this->registered as $id => & $info ) {
|
61 |
+
if( $info->registered ) continue;
|
62 |
+
register_widget( $info->class );
|
63 |
+
$info->registered = true;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Get the path of the widget
|
69 |
+
*
|
70 |
+
* @param $id
|
71 |
+
*
|
72 |
+
* @return bool
|
73 |
+
*/
|
74 |
+
public function get_plugin_path( $id ) {
|
75 |
+
if( empty( $this->registered[ $id ] ) ) {
|
76 |
+
// This call might be using the incorrect ID convention.
|
77 |
+
if( substr($id, 0, 4) == 'sow-' ) $id = substr($id, 4);
|
78 |
+
else $id = 'sow-' . $id;
|
79 |
+
}
|
80 |
+
|
81 |
+
return !empty($this->registered[$id]) ? $this->registered[$id]->path : false;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* @param $id
|
86 |
+
*
|
87 |
+
* @return string
|
88 |
+
*
|
89 |
+
* @todo examine this when using a widget in a theme folder.
|
90 |
+
*/
|
91 |
+
function get_plugin_dir_path( $id ){
|
92 |
+
return plugin_dir_path( $this->get_plugin_path( $id ) );
|
93 |
+
}
|
94 |
+
|
95 |
+
function get_plugin_dir_url( $id ){
|
96 |
+
return plugin_dir_url( $this->get_plugin_path( $id ) );
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Get a widget ID from a file path
|
101 |
+
*
|
102 |
+
* @param string $path The file path.
|
103 |
+
*
|
104 |
+
* @return string The ID.
|
105 |
+
*/
|
106 |
+
function get_id_from_path( $path ){
|
107 |
+
foreach( $this->registered as $id => $r ) {
|
108 |
+
if( $r->path == $path ) return $id;
|
109 |
+
}
|
110 |
+
return false;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Get the class name of a widget from the
|
115 |
+
*
|
116 |
+
* @param $path
|
117 |
+
* @return mixed
|
118 |
+
*/
|
119 |
+
function get_class_from_path( $path ) {
|
120 |
+
foreach( $this->registered as $id => $r ) {
|
121 |
+
if( $r->path == $path ) return $r->class;
|
122 |
+
}
|
123 |
+
return false;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
SiteOrigin_Widgets_Widget_Manager::single();
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Register a widget
|
130 |
+
*
|
131 |
+
* @param string $id The ID of the widget
|
132 |
+
* @param string $path The path of the widget
|
133 |
+
* @param bool|string $class The name of the class
|
134 |
+
*/
|
135 |
+
function siteorigin_widget_register( $id, $path, $class = false ){
|
136 |
+
SiteOrigin_Widgets_Widget_Manager::single()->register( $id, $path, $class );
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Get the base file of a widget plugin
|
141 |
+
*
|
142 |
+
* @param $name
|
143 |
+
* @return bool
|
144 |
+
*/
|
145 |
+
function siteorigin_widget_get_plugin_path($id){
|
146 |
+
return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_path( $id );
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Get the base path folder of a widget plugin.
|
151 |
+
*
|
152 |
+
* @param $id
|
153 |
+
* @return string
|
154 |
+
*/
|
155 |
+
function siteorigin_widget_get_plugin_dir_path($id){
|
156 |
+
return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_dir_path( $id );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Get the base path URL of a widget plugin.
|
161 |
+
*
|
162 |
+
* @param $id
|
163 |
+
* @return string
|
164 |
+
*/
|
165 |
+
function siteorigin_widget_get_plugin_dir_url($id){
|
166 |
+
return SiteOrigin_Widgets_Widget_Manager::single()->get_plugin_dir_url( $id );
|
167 |
+
}
|
base/inc/widgets/base-slider.class.php
CHANGED
@@ -1,341 +1,341 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
abstract class SiteOrigin_Widget_Base_Slider extends SiteOrigin_Widget {
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Register all the frontend scripts and styles for the base slider.
|
7 |
-
*/
|
8 |
-
function initialize() {
|
9 |
-
|
10 |
-
$frontend_scripts = array();
|
11 |
-
$frontend_scripts[] = array(
|
12 |
-
'sow-slider-slider-cycle2',
|
13 |
-
plugin_dir_url( SOW_BUNDLE_BASE_FILE ) . 'js/jquery.cycle' . SOW_BUNDLE_JS_SUFFIX . '.js',
|
14 |
-
array( 'jquery' ),
|
15 |
-
SOW_BUNDLE_VERSION
|
16 |
-
);
|
17 |
-
if( function_exists('wp_is_mobile') && wp_is_mobile() ) {
|
18 |
-
$frontend_scripts[] = array(
|
19 |
-
'sow-slider-slider-cycle2-swipe',
|
20 |
-
plugin_dir_url( SOW_BUNDLE_BASE_FILE ) . 'js/jquery.cycle.swipe' . SOW_BUNDLE_JS_SUFFIX . '.js',
|
21 |
-
array( 'jquery' ),
|
22 |
-
SOW_BUNDLE_VERSION
|
23 |
-
);
|
24 |
-
}
|
25 |
-
$frontend_scripts[] = array(
|
26 |
-
'sow-slider-slider',
|
27 |
-
plugin_dir_url( SOW_BUNDLE_BASE_FILE ) . 'js/slider/jquery.slider' . SOW_BUNDLE_JS_SUFFIX . '.js',
|
28 |
-
array( 'jquery' ),
|
29 |
-
SOW_BUNDLE_VERSION
|
30 |
-
);
|
31 |
-
|
32 |
-
$this->register_frontend_scripts( $frontend_scripts );
|
33 |
-
$this->register_frontend_styles(
|
34 |
-
array(
|
35 |
-
array(
|
36 |
-
'sow-slider-slider',
|
37 |
-
plugin_dir_url( SOW_BUNDLE_BASE_FILE ) . 'css/slider/slider.css',
|
38 |
-
array(),
|
39 |
-
SOW_BUNDLE_VERSION
|
40 |
-
)
|
41 |
-
)
|
42 |
-
);
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* The control array required for the slider
|
47 |
-
*
|
48 |
-
* @return array
|
49 |
-
*/
|
50 |
-
function control_form_fields(){
|
51 |
-
return array(
|
52 |
-
'speed' => array(
|
53 |
-
'type' => 'number',
|
54 |
-
'label' => __('Animation speed', 'so-widgets-bundle'),
|
55 |
-
'description' => __('Animation speed in milliseconds.', 'so-widgets-bundle'),
|
56 |
-
'default' => 800,
|
57 |
-
),
|
58 |
-
|
59 |
-
'timeout' => array(
|
60 |
-
'type' => 'number',
|
61 |
-
'label' => __('Timeout', 'so-widgets-bundle'),
|
62 |
-
'description' => __('How long each frame is displayed for in milliseconds.', 'so-widgets-bundle'),
|
63 |
-
'default' => 8000,
|
64 |
-
),
|
65 |
-
|
66 |
-
'nav_color_hex' => array(
|
67 |
-
'type' => 'color',
|
68 |
-
'label' => __('Navigation color', 'so-widgets-bundle'),
|
69 |
-
'default' => '#FFFFFF',
|
70 |
-
),
|
71 |
-
|
72 |
-
'nav_style' => array(
|
73 |
-
'type' => 'select',
|
74 |
-
'label' => __('Navigation style', 'so-widgets-bundle'),
|
75 |
-
'default' => 'thin',
|
76 |
-
'options' => array(
|
77 |
-
'ultra-thin' => __('Ultra thin', 'so-widgets-bundle'),
|
78 |
-
'thin' => __('Thin', 'so-widgets-bundle'),
|
79 |
-
'medium' => __('Medium', 'so-widgets-bundle'),
|
80 |
-
'thick' => __('Thick', 'so-widgets-bundle'),
|
81 |
-
'ultra-thin-rounded' => __('Rounded ultra thin', 'so-widgets-bundle'),
|
82 |
-
'thin-rounded' => __('Rounded thin', 'so-widgets-bundle'),
|
83 |
-
'medium-rounded' => __('Rounded medium', 'so-widgets-bundle'),
|
84 |
-
'thick-rounded' => __('Rounded thick', 'so-widgets-bundle'),
|
85 |
-
)
|
86 |
-
),
|
87 |
-
|
88 |
-
'nav_size' => array(
|
89 |
-
'type' => 'number',
|
90 |
-
'label' => __('Navigation size', 'so-widgets-bundle'),
|
91 |
-
'default' => '25',
|
92 |
-
),
|
93 |
-
|
94 |
-
'swipe' => array(
|
95 |
-
'type' => 'checkbox',
|
96 |
-
'label' => __( 'Swipe Control', 'so-widgets-bundle' ),
|
97 |
-
'description' => __( 'Allow users to swipe through frames on mobile devices.', 'so-widgets-bundle' ),
|
98 |
-
'default' => true,
|
99 |
-
)
|
100 |
-
);
|
101 |
-
}
|
102 |
-
|
103 |
-
function video_form_fields(){
|
104 |
-
return array(
|
105 |
-
'file' => array(
|
106 |
-
'type' => 'media',
|
107 |
-
'library' => 'video',
|
108 |
-
'label' => __('Video file', 'so-widgets-bundle'),
|
109 |
-
),
|
110 |
-
|
111 |
-
'url' => array(
|
112 |
-
'type' => 'text',
|
113 |
-
'sanitize' => 'url',
|
114 |
-
'label' => __('Video URL', 'so-widgets-bundle'),
|
115 |
-
'optional' => 'true',
|
116 |
-
'description' => __('An external URL of the video. Overrides video file.', 'so-widgets-bundle')
|
117 |
-
),
|
118 |
-
|
119 |
-
'format' => array(
|
120 |
-
'type' => 'select',
|
121 |
-
'label' => __('Video format', 'so-widgets-bundle'),
|
122 |
-
'options' => array(
|
123 |
-
'video/mp4' => 'MP4',
|
124 |
-
'video/webm' => 'WebM',
|
125 |
-
'video/ogg' => 'Ogg',
|
126 |
-
),
|
127 |
-
),
|
128 |
-
|
129 |
-
'height' => array(
|
130 |
-
'type' => 'number',
|
131 |
-
'label' => __( 'Maximum height', 'so-widgets-bundle' )
|
132 |
-
),
|
133 |
-
|
134 |
-
);
|
135 |
-
}
|
136 |
-
|
137 |
-
function slider_settings( $controls ){
|
138 |
-
return array(
|
139 |
-
'pagination' => true,
|
140 |
-
'speed' => empty( $controls['speed'] ) ? 1 : $controls['speed'],
|
141 |
-
'timeout' => $controls['timeout'],
|
142 |
-
'swipe' => $controls['swipe'],
|
143 |
-
);
|
144 |
-
}
|
145 |
-
|
146 |
-
function render_template( $controls, $frames ){
|
147 |
-
$this->render_template_part('before_slider', $controls, $frames);
|
148 |
-
$this->render_template_part('before_slides', $controls, $frames);
|
149 |
-
|
150 |
-
foreach( $frames as $i => $frame ) {
|
151 |
-
$this->render_frame( $i, $frame );
|
152 |
-
}
|
153 |
-
|
154 |
-
$this->render_template_part('after_slides', $controls, $frames);
|
155 |
-
$this->render_template_part('navigation', $controls, $frames);
|
156 |
-
$this->render_template_part('after_slider', $controls, $frames);
|
157 |
-
}
|
158 |
-
|
159 |
-
function render_template_part( $part, $controls, $frames ) {
|
160 |
-
switch( $part ) {
|
161 |
-
case 'before_slider':
|
162 |
-
?><div class="sow-slider-base <?php if( wp_is_mobile() ) echo 'sow-slider-is-mobile' ?>" style="display: none"><?php
|
163 |
-
break;
|
164 |
-
case 'before_slides':
|
165 |
-
$settings = $this->slider_settings( $controls );
|
166 |
-
?><ul class="sow-slider-images" data-settings="<?php echo esc_attr( json_encode($settings) ) ?>"><?php
|
167 |
-
break;
|
168 |
-
case 'after_slides':
|
169 |
-
?></ul><?php
|
170 |
-
break;
|
171 |
-
case 'navigation':
|
172 |
-
?>
|
173 |
-
<ol class="sow-slider-pagination">
|
174 |
-
<?php foreach($frames as $i => $frame) : ?>
|
175 |
-
<li><a href="#" data-goto="<?php echo $i ?>"><?php echo $i+1 ?></a></li>
|
176 |
-
<?php endforeach; ?>
|
177 |
-
</ol>
|
178 |
-
|
179 |
-
<div class="sow-slide-nav sow-slide-nav-next">
|
180 |
-
<a href="#" data-goto="next" data-action="next">
|
181 |
-
<em class="sow-sld-icon-<?php echo sanitize_html_class( $controls['nav_style'] ) ?>-right"></em>
|
182 |
-
</a>
|
183 |
-
</div>
|
184 |
-
|
185 |
-
<div class="sow-slide-nav sow-slide-nav-prev">
|
186 |
-
<a href="#" data-goto="previous" data-action="prev">
|
187 |
-
<em class="sow-sld-icon-<?php echo sanitize_html_class( $controls['nav_style'] ) ?>-left"></em>
|
188 |
-
</a>
|
189 |
-
</div>
|
190 |
-
<?php
|
191 |
-
break;
|
192 |
-
case 'after_slider':
|
193 |
-
|