| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Booking Calendar |
| 5 |
* @subpackage Files Loading |
| 6 |
* @category Bookings |
| 7 |
* |
| 8 |
* @author wpdevelop |
| 9 |
* @link https://wpbookingcalendar.com/ |
| 10 |
* @email info@wpbookingcalendar.com |
| 11 |
* |
| 12 |
* @modified 29.09.2015 |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 16 |
|
| 17 |
//FixIn: 9.9.0.15 |
| 18 |
|
| 19 |
class WPBC_TinyMCE_Buttons { |
| 20 |
|
| 21 |
// <editor-fold defaultstate="collapsed" desc=" I n i t + H o o k s" > |
| 22 |
private $settings = array(); |
| 23 |
|
| 24 |
function __construct( $params ) { |
| 25 |
|
| 26 |
$this->settings = array( |
| 27 |
'tiny_prefix' => 'wpbc_tiny' |
| 28 |
, 'tiny_icon_url' => WPBC_PLUGIN_URL . '/assets/img/bc_black-16x16.png' |
| 29 |
, 'tiny_js_plugin' => WPBC_PLUGIN_URL . '/js/wpbc_tinymce_btn.js' |
| 30 |
, 'tiny_js_function' => 'wpbc_init_tinymce_buttons' // This function NAME exist inside of this JS file: ['tiny_js_plugin'] |
| 31 |
, 'tiny_btn_row' => 1 |
| 32 |
, 'pages_where_insert' => array( 'post-new.php', 'page-new.php', 'post.php', 'page.php', 'widgets.php', 'customize.php' ) //FixIn: 8.8.2.12 |
| 33 |
, 'buttons' => array( |
| 34 |
'booking_insert' => array( |
| 35 |
'hint' => __('Insert booking calendar' ,'booking') |
| 36 |
, 'title' => __('Booking calendar' ,'booking') |
| 37 |
, 'img' => WPBC_PLUGIN_URL . '/assets/img/bc_black-16x16.png' |
| 38 |
, 'class' => 'bookig_buttons' |
| 39 |
, 'js_func_name_click' => 'wpbc_tiny_btn_click' |
| 40 |
, 'bookmark' => 'booking' |
| 41 |
, 'is_close_bookmark' => 0 |
| 42 |
) |
| 43 |
) |
| 44 |
); |
| 45 |
|
| 46 |
$this->settings = wp_parse_args( $params, $this->settings ); |
| 47 |
|
| 48 |
add_action( 'init', array( $this, 'define_init_hooks' ) ); // Define init hooks |
| 49 |
} |
| 50 |
|
| 51 |
/** Init all hooks for showing Button in Tiny Toolbar */ |
| 52 |
public function define_init_hooks() { |
| 53 |
|
| 54 |
if ( wpbc_can_i_load_on_this_page__shortcode_config() ) { |
| 55 |
|
| 56 |
// Load JS file - TinyMCE plugin |
| 57 |
add_filter( 'mce_external_plugins', array( $this, 'load_tiny_js_plugin' ) ); |
| 58 |
|
| 59 |
// Add the custom TinyMCE buttons |
| 60 |
if ( 1 === $this->settings['tiny_btn_row'] ) { |
| 61 |
add_filter( 'mce_buttons', array( $this, 'add_tiny_button' ) ); |
| 62 |
} else { |
| 63 |
add_filter( 'mce_buttons_' . $this->settings['tiny_btn_row'], array( $this, 'add_tiny_button' ) ); |
| 64 |
} |
| 65 |
|
| 66 |
// Add the old style button to the non-TinyMCE editor views //Fix: 8.4.2.10 - compatibility with Gutenberg 4.1- 4.3 ( or newer ) at edit post page. |
| 67 |
add_action( 'edit_page_form', array( $this, 'add_html_button' ) ); |
| 68 |
add_action( 'admin_head', array( $this, 'insert_button') ); // Tiny Button |
| 69 |
add_action( 'admin_footer', array( $this, 'modal_content' ) ); // Modal Content |
| 70 |
|
| 71 |
// JS & CSS |
| 72 |
wpbc_load_js__required_for_modals(); |
| 73 |
|
| 74 |
add_action( 'customize_controls_print_footer_scripts', array( $this, 'add_html_button' ) ); //FixIn: 8.8.2.12 |
| 75 |
add_action( 'customize_controls_print_footer_scripts', array( $this, 'insert_button' ) ); |
| 76 |
add_action( 'customize_controls_print_footer_scripts', array( $this, 'modal_content' ) ); // Modal Content |
| 77 |
} |
| 78 |
} |
| 79 |
// </editor-fold> |
| 80 |
|
| 81 |
|
| 82 |
// <editor-fold defaultstate="collapsed" desc=" TinyMCE - Add Button " > |
| 83 |
|
| 84 |
/** |
| 85 |
* Load JS file - TinyMCE plugin |
| 86 |
* |
| 87 |
* @param array $plugins |
| 88 |
* @return array |
| 89 |
*/ |
| 90 |
public function load_tiny_js_plugin( $plugins ){ |
| 91 |
|
| 92 |
$plugins[ $this->settings['tiny_prefix'] . '_quicktags'] = $this->settings['tiny_js_plugin']; |
| 93 |
|
| 94 |
return $plugins; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
/** |
| 99 |
* Add the custom TinyMCE buttons |
| 100 |
* |
| 101 |
* @param array $buttons |
| 102 |
* @return array |
| 103 |
*/ |
| 104 |
public function add_tiny_button( $buttons ) { |
| 105 |
|
| 106 |
array_push( $buttons, "separator" ); |
| 107 |
|
| 108 |
foreach ( $this->settings['buttons'] as $type => $strings ) { |
| 109 |
array_push( $buttons, $this->settings['tiny_prefix'] . '_' . $type ); |
| 110 |
} |
| 111 |
|
| 112 |
return $buttons; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
/** Add the old style button to the non-TinyMCE editor views */ |
| 117 |
public function add_html_button() { |
| 118 |
|
| 119 |
$buttonshtml = ''; |
| 120 |
$datajs=''; |
| 121 |
|
| 122 |
foreach ( $this->settings['buttons'] as $type => $props ) { |
| 123 |
|
| 124 |
$buttonshtml .= '<input type="button" class="ed_button button button-small" onclick="' |
| 125 |
.$props['js_func_name_click'].'(\'' . $type . '\')" title="' . $props['hint'] . '" value="' . $props['title'] . '" />'; |
| 126 |
|
| 127 |
$datajs.= " wpbc_tiny_btn_data['$type'] = {\n"; |
| 128 |
$datajs.= ' title: "' . esc_js( $props['title'] ) . '",' . "\n"; |
| 129 |
$datajs.= ' tag: "' . esc_js( $props['bookmark'] ) . '",' . "\n"; |
| 130 |
$datajs.= ' tag_close: "' . esc_js( $props['is_close_bookmark'] ) . '",' . "\n"; |
| 131 |
$datajs.= ' cal_count: "' . get_bk_option( 'booking_client_cal_count' ) . '"' . "\n"; |
| 132 |
$datajs.= "\n };\n"; |
| 133 |
} |
| 134 |
|
| 135 |
?><script type="text/javascript"> |
| 136 |
// <![CDATA[ |
| 137 |
|
| 138 |
function wpbc_add_html_button_to_toolbar(){ // Add buttons ( HTML view ) |
| 139 |
if ( jQuery( '#ed_toolbar' ).length == 0 ) |
| 140 |
setTimeout( 'wpbc_add_html_button_to_toolbar()' , 100 ); |
| 141 |
else |
| 142 |
jQuery("#ed_toolbar").append( '<?php echo wp_specialchars_decode( esc_js( $buttonshtml ), ENT_COMPAT ); ?>' ); |
| 143 |
} |
| 144 |
jQuery(document).ready(function(){ |
| 145 |
setTimeout( 'wpbc_add_html_button_to_toolbar()' , 100 ); |
| 146 |
}); |
| 147 |
|
| 148 |
var selected_booking_shortcode = 'bookingform'; |
| 149 |
var wpbc_tiny_btn_data={}; |
| 150 |
<?php echo $datajs; ?> |
| 151 |
|
| 152 |
// ]]> |
| 153 |
</script><?php |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
public function insert_button() { |
| 159 |
|
| 160 |
$script = ''; |
| 161 |
|
| 162 |
// calendar3-range https://icons.getbootstrap.com/icons/calendar3-range/ |
| 163 |
$svg_icon_integarted = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-calendar3-range" viewBox="-2 -1 20 20">' |
| 164 |
. '<path d="M14 0H2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2zM1 3.857C1 3.384 1.448 3 2 3h12c.552 0 1 .384 1 .857v10.286c0 .473-.448.857-1 .857H2c-.552 0-1-.384-1-.857V3.857z"/>' |
| 165 |
. '<path d="M7 10a1 1 0 0 0 0-2H1v2h6zm2-3h6V5H9a1 1 0 0 0 0 2z"/>' |
| 166 |
. '</svg>'; |
| 167 |
$mune_icon_url = sprintf( 'data:image/svg+xml;base64,%s', base64_encode( $svg_icon_integarted ) ); |
| 168 |
|
| 169 |
|
| 170 |
if ( ! empty( $this->settings['buttons'] ) ){ |
| 171 |
|
| 172 |
$script .= '<script type="text/javascript">'; |
| 173 |
|
| 174 |
$script .= ' function '. $this->settings['tiny_js_function'] . '(ed, url) {'; |
| 175 |
|
| 176 |
foreach ( $this->settings['buttons'] as $type => $props ) { |
| 177 |
|
| 178 |
$script .= " if ( typeof ".$props['js_func_name_click']." == 'undefined' ) return; "; |
| 179 |
$script .= " ed.addButton('". $this->settings['tiny_prefix'] . '_' . $type ."', {"; |
| 180 |
$script .= " title : '". $props['hint'] ."',"; |
| 181 |
//$script .= " image : '". $props['img'] ."',"; |
| 182 |
$script .= " image : '" . $mune_icon_url . "',"; |
| 183 |
$script .= " onclick : function() {"; |
| 184 |
$script .= " ". $props['js_func_name_click'] ."('". $type ."');"; |
| 185 |
$script .= " }"; |
| 186 |
$script .= " });"; |
| 187 |
} |
| 188 |
$script .= ' }'; |
| 189 |
|
| 190 |
$script .= '</script>'; |
| 191 |
|
| 192 |
echo $script; |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
// </editor-fold> |
| 197 |
|
| 198 |
|
| 199 |
// <editor-fold defaultstate="collapsed" desc=" M o d a l C o n t e n t " > |
| 200 |
public function modal_content() { |
| 201 |
|
| 202 |
?><span class="wpdevelop wpbc_page"><div class="visibility_container clearfix-height" style="display:block;"><?php |
| 203 |
?><div id="wpbc_tiny_modal" class="modal wpbc_popup_modal wpbc_tiny_modal" tabindex="-1" role="dialog"> |
| 204 |
<div class="modal-dialog modal-lg"> |
| 205 |
<div class="modal-content"> |
| 206 |
<div class="modal-header"> |
| 207 |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
| 208 |
<h4 class="modal-title"> |
| 209 |
<span>WP Booking Calendar</span> |
| 210 |
<span style="padding: 0 1em;"> / </span> |
| 211 |
<span> |
| 212 |
<?php |
| 213 |
_e( 'Shortcode Configuration', 'booking' ); |
| 214 |
?></span></h4> |
| 215 |
</div> |
| 216 |
<div class="modal-body"> |
| 217 |
|
| 218 |
<div class="wpbc_settings_flex_container"> |
| 219 |
|
| 220 |
<div class="wpbc_settings_flex_container_left" style="flex: 1 1 150px;"> |
| 221 |
<?php |
| 222 |
wpbc_shortcode_config__navigation_panel(); |
| 223 |
?> |
| 224 |
</div> |
| 225 |
<div class="wpbc_settings_flex_container_right"> |
| 226 |
<div class="wpbc_sc_container__all_shortcodes"> |
| 227 |
<input name="wpbc_shortcode_type" id="wpbc_shortcode_type" value="booking" autocomplete="off" type="hidden" /> |
| 228 |
<?php |
| 229 |
|
| 230 |
// [booking ... ] ------------------------------------------------------------------ |
| 231 |
wpbc_shortcode_config__content__booking(); |
| 232 |
|
| 233 |
// [bookingcalendar ... ] ---------------------------------------------------------- |
| 234 |
wpbc_shortcode_config__content__bookingcalendar(); |
| 235 |
|
| 236 |
// [bookingselect ... ] ------------------------------------------------------------ |
| 237 |
wpbc_shortcode_config__content__bookingselect(); |
| 238 |
|
| 239 |
// [bookingtimeline ... ] ---------------------------------------------------------- |
| 240 |
wpbc_shortcode_config__content__bookingtimeline(); |
| 241 |
|
| 242 |
// [bookingsearch searchresults='https://servcer.com/search-form/' searchresultstitle='{searchresults} Result(s) Found' noresultstitle='Nothing Found'] |
| 243 |
wpbc_shortcode_config__content__bookingsearch(); |
| 244 |
|
| 245 |
// [bookingform type=1 selected_dates='03.03.2024'] -------------------------------- |
| 246 |
wpbc_shortcode_config__content__bookingform(); |
| 247 |
|
| 248 |
// [bookingedit] , [bookingcustomerlisting] , [bookingresource type=6 show='capacity'] , [booking_confirm] |
| 249 |
wpbc_shortcode_config__content__bookingother(); |
| 250 |
|
| 251 |
// Booking Import of .ics feed shortcode |
| 252 |
wpbc_shortcode_config__content__booking_ics_import(); |
| 253 |
|
| 254 |
// Booking Listing of .ics feed shortcode |
| 255 |
wpbc_shortcode_config__content__booking_ics_listing(); |
| 256 |
|
| 257 |
?> |
| 258 |
</div> |
| 259 |
<div style="display: flex;flex-flow: row wrap;justify-content: flex-start;align-items: baseline;" for="wpbc_text_put_in_shortcode"> |
| 260 |
<input name="wpbc_text_put_in_shortcode" id="wpbc_text_put_in_shortcode" class="put-in" readonly="readonly" onfocus="this.select()" type="text" |
| 261 |
style="width: auto;flex: 1;" /> |
| 262 |
</div> |
| 263 |
<input name="wpbc_text_gettenberg_section_id" id="wpbc_text_gettenberg_section_id" type="text" style="display: none;" /> |
| 264 |
</div> |
| 265 |
</div> |
| 266 |
|
| 267 |
</div> |
| 268 |
<div class="modal-footer" style="text-align:center;"> |
| 269 |
<div class="wpbc_shortcode_config_content_toolbar__container"> |
| 270 |
<div class="wpbc_shortcode_config_content_toolbar__reset"> |
| 271 |
<a href="javascript:void(0)" class="button button-primary wpbc_tiny_button__reset_to_resource wpbc_ui_button_danger" |
| 272 |
onclick="javascript:wpbc_shortcode_config__reset( jQuery('#wpbc_shortcode_type').val().trim() );" ><?php _e( 'Reset' ); ?></a> |
| 273 |
</div> |
| 274 |
<div class="wpbc_shortcode_config_content_toolbar__insert"> |
| 275 |
<a href="javascript:void(0)" class="button button-primary wpbc_tiny_button__insert_to_editor" style="float:none;" |
| 276 |
onclick="javascript:wpbc_send_text_to_editor( jQuery('#wpbc_text_put_in_shortcode').val().trim() );wpbc_tiny_close();"><?php _e( 'Insert' ); ?></a> |
| 277 |
<a href="javascript:void(0)" class="button button-primary wpbc_tiny_button__insert_to_resource" style="float:none;display:none;" |
| 278 |
onclick="javascript:wpbc_send_text_to_resource( jQuery('#wpbc_text_put_in_shortcode').val().trim() );wpbc_tiny_close();" ><?php _e( 'Insert' ); ?></a> |
| 279 |
<!--a href="javascript:void(0)" class="button" style="float:none;" data-dismiss="modal"><?php _e('Close' ,'booking'); ?></a--> |
| 280 |
</div> |
| 281 |
</div> |
| 282 |
</div> |
| 283 |
</div><!-- /.modal-content --> |
| 284 |
</div><!-- /.modal-dialog --> |
| 285 |
</div><!-- /.modal --> |
| 286 |
<?php |
| 287 |
?></div></span><?php |
| 288 |
|
| 289 |
} |
| 290 |
// </editor-fold> |
| 291 |
|
| 292 |
|
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
$wpbc_pages_where_insert_btn = array( 'post-new.php', 'page-new.php', 'post.php', 'page.php', 'widgets.php', 'customize.php' ); //FixIn: 8.8.2.11 //FixIn: 8.8.2.12 |
| 297 |
|
| 298 |
if ( |
| 299 |
( in_array( basename( $_SERVER['PHP_SELF'] ), $wpbc_pages_where_insert_btn ) ) |
| 300 |
|| ( |
| 301 |
( isset( $_REQUEST['page'] ) |
| 302 |
&& ( $_REQUEST['page'] == 'wpbc-resources' ) ) // Check if this Booking > Resources page |
| 303 |
) |
| 304 |
){ |
| 305 |
new WPBC_TinyMCE_Buttons( |
| 306 |
array( |
| 307 |
'tiny_prefix' => 'wpbc_tiny' |
| 308 |
, 'tiny_icon_url' => WPBC_PLUGIN_URL . '/assets/img/bc_black-16x16.png' |
| 309 |
, 'tiny_js_plugin' => WPBC_PLUGIN_URL . '/js/wpbc_tinymce_btn.js' |
| 310 |
, 'tiny_js_function' => 'wpbc_init_tinymce_buttons' // This function NAME exist inside of this file: ['tiny_js_plugin'] |
| 311 |
, 'tiny_btn_row' => 1 |
| 312 |
, 'pages_where_insert' => $wpbc_pages_where_insert_btn |
| 313 |
, 'buttons' => array( |
| 314 |
'booking_insert' => array( |
| 315 |
'hint' => __('Insert WP Booking Calendar' ,'booking') |
| 316 |
, 'title' => __('Booking calendar' ,'booking') |
| 317 |
, 'img' => WPBC_PLUGIN_URL . '/assets/img/bc_black-16x16.png' |
| 318 |
, 'class' => 'bookig_buttons' |
| 319 |
, 'js_func_name_click' => 'wpbc_tiny_btn_click' |
| 320 |
, 'bookmark' => 'booking' |
| 321 |
, 'is_close_bookmark' => 0 |
| 322 |
) |
| 323 |
) |
| 324 |
) |
| 325 |
); |
| 326 |
} |