PluginProbe
Bazz CallBack widget / 3.24
Bazz CallBack widget v3.24
4.0 3.25 3.24 3.5 3.6 3.7 3.8 3.9 trunk 1.0 1.1 1.2 1.3 1.4 2.0 2.1 2.2 2.3 3.0 3.1 3.10 3.11 3.12 3.13 3.14 All 37 releases
bazz-callback-widget / bazz-callback-widget.php

bazz-callback-widget.php in Bazz CallBack widget 3.24, at bazz-callback-widget.php

428 lines 18.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Callback Widget – Bazz CallBack
4 Plugin URI: http://viktor-web.ru
5 Text Domain: bazz-callback-widget
6 Domain Path: /languages
7 Description: This plugin makes a simple widget for callback on your website.
8 Author: Viktor Ievlev
9 Version: 3.24
10 Author URI: https://viktor-web.ru
11 License: GPLv2
12 */
13 /*
14 Copyright 2016 Viktor Ievlev (email: bazz@bk.ru)
15
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 // Exit if accessed directly
32 if ( ! defined( 'ABSPATH' ) ) {
33 exit;
34 }
35
36 //current version constant
37 define( 'BAZZ_WIDGET_VERSION', '3.19' );
38
39 //activation hook
40 register_activation_hook( __FILE__, 'bazz_install' );
41 function bazz_install() {
42 if ( ! get_option( 'bazz_options' ) ) {
43 $bazz_options_arr = array(
44 'email' => 'example@mail.com',
45 'work_time_start' => '9',
46 'work_time_end' => '21',
47 'time' => '48',
48 'day_text' => __( 'The loading is extremely high, we will call you back in the near future. Thanks!', 'bazz-callback-widget' ),
49 'night_text' => __( 'Unfortunately, we don\'t work for now. We will call you back tomorrow! Thanks!', 'bazz-callback-widget' ),
50 'bottom' => '68'
51 );
52 update_option( 'bazz_options', $bazz_options_arr );
53 }
54 }
55
56 //deactivation hook
57 register_deactivation_hook( __FILE__, 'bazz_deactivate' );
58 function bazz_deactivate() {
59
60 }
61
62 //uninstall hook
63 register_uninstall_hook( __FILE__, 'bazz_uninstall' );
64 function bazz_uninstall() {
65 delete_option( 'bazz_options' );
66 }
67
68 //Add new options
69 function bazz_new_option( $option_name, $option_value ) {
70 $bazz_options_array = get_option( 'bazz_options' );
71 if ( ! array_key_exists( $option_name, $bazz_options_array ) ) {
72 $bazz_options_array[ $option_name ] = $option_value;
73 update_option( 'bazz_options', $bazz_options_array );
74 }
75
76 }
77
78 add_action( 'init', 'bazz_widget_add_new_options' );
79 function bazz_widget_add_new_options() {
80 /*Добавляем сюда новые опции*/
81
82 //Added in 2.2
83 bazz_new_option( 'in_russia', '1' );
84
85 //Added in 3.0
86 bazz_new_option( 'color_scheme', '#00AFF2' );
87 bazz_new_option( 'left_right', 'right' );
88
89 }
90
91 //localize
92 function localize_load() {
93 load_plugin_textdomain( 'bazz-callback-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
94 }
95
96 add_action( 'plugins_loaded', 'localize_load' );
97
98 //load styles and scripts
99 add_action( 'init', 'bazz_widget_styles' );
100 function bazz_widget_styles() {
101 if ( ! is_admin() ) {
102 wp_enqueue_style( 'bazz_widget_style', plugins_url( 'css/bazz-widget.css', __FILE__ ), array(), BAZZ_WIDGET_VERSION, 'all' );
103 } else {
104 wp_enqueue_style( 'bazz_widget_admin_style', plugins_url( 'css/bazz-widget-admin.css', __FILE__ ), array(), BAZZ_WIDGET_VERSION, 'all' );
105 }
106 }
107
108 add_action( 'wp_footer', 'bazz_widget_scripts' );
109 function bazz_widget_scripts() {
110 wp_enqueue_script( 'jquery' );
111 wp_enqueue_script( 'bazz_maskedinput', plugins_url( 'js/jquery.maskedinput.min.js', __FILE__ ), 'jquery', null, true );
112 wp_enqueue_script( 'bazz_draggable', plugins_url( 'js/jquery.draggable.min.js', __FILE__ ), 'jquery', null, true );
113 wp_enqueue_script( 'bazz_widget_script', plugins_url( 'js/bazz-widget.js', __FILE__ ), 'jquery', null, true );
114 wp_localize_script( 'bazz_widget_script', 'bazz_ajax',
115 array(
116 'url' => admin_url( 'admin-ajax.php' )
117 )
118 );
119 $bazz_options = get_option( 'bazz_options' );
120 $locale = get_locale();
121 if( 'ru_RU' == $locale ) {
122 $current_lang = 'RU';
123 } else {
124 $current_lang = 'EN';
125 }
126 wp_localize_script( 'bazz_widget_script', 'bazz_options',
127 array(
128 'currentLang' => $current_lang,
129 'bazz_in_russia' => $bazz_options['in_russia'],
130 'bazz_color_scheme' => $bazz_options['color_scheme']
131 )
132 );
133 }
134
135 function bazz_widget_admin_scripts() {
136 wp_enqueue_script( 'jquery' );
137 wp_enqueue_script( 'bazz_slider', plugins_url( 'js/jquery.ui-slider.js', __FILE__ ), 'jquery' );
138 wp_enqueue_script( 'bazz_slider_rtl', plugins_url( 'js/jquery.ui.slider-rtl.min.js', __FILE__ ), 'jquery' );
139 }
140
141 //AJAX
142 add_action( 'wp_ajax_bazz_widget_action', 'bazz_widget_send' );
143 add_action( 'wp_ajax_nopriv_bazz_widget_action', 'bazz_widget_send' );
144 function bazz_widget_send() {
145
146 // Protection
147 if( empty( $_POST ) || ! wp_verify_nonce( $_POST['nonce'], 'bazz_widget_nonce') || $_POST['check'] !== '' ) {
148 wp_send_json_error( '<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">Forbidden!</div>' );
149 }
150
151 $phone = isset( $_POST['phone'] ) ? $_POST['phone'] : '';
152 $name = ! empty( $_POST['name'] ) ? $_POST['name'] : __( "The client wasn't introduced", 'bazz-callback-widget' );
153 $callback_page = isset( $_POST['refferer'] ) ? $_POST['refferer'] : '';
154 $blog_url = get_home_url();
155 $admin_email = get_option( 'admin_email' );
156 $bazz_options_arr = get_option( 'bazz_options' );
157 $email = $bazz_options_arr['email'];
158 $current_time = current_time( 'G' );
159 $work_time_start = $bazz_options_arr['work_time_start'];
160 $work_time_end = $bazz_options_arr['work_time_end'];
161 $text = $bazz_options_arr['day_text'];
162 if ( $work_time_start > $current_time || $current_time >= $work_time_end ) {
163 $text = $bazz_options_arr['night_text'];
164 }
165 $to = $email;
166 $headers = "Content-type: text/plain; charset=utf-8\r\n";
167 $subject = "$blog_url " . __( '[FROM BAZZ WIDGET]', 'bazz-callback-widget' );
168 $message = __( 'Phone', 'bazz-callback-widget' ) . " - $phone\n" .
169 __( 'Name', 'bazz-callback-widget' ) . " - $name\n" .
170 __( 'From page', 'bazz-callback-widget' ) . " - " . $blog_url . $callback_page;
171 $send = wp_mail( $to, $subject, $message, $headers );
172 if ( $send ) {
173 wp_send_json_success( '<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">' . $text . '</div>' );
174 } else {
175 wp_send_json_error( '<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">Email sending error.</div>' );
176 }
177 }
178 //Change the name in the header FROM
179 add_filter( 'wp_mail_from_name', 'bazz_wp_mail_from_name' );
180 function bazz_wp_mail_from_name( $email_from ){
181 return get_option( 'blogname' );
182 }
183
184 //HTML layout
185 add_action( 'wp_footer', 'bazz_layout' );
186 function bazz_layout() { ?>
187 <?php $bazz_options_arr = get_option( 'bazz_options' ); ?>
188 <?php if ( 'left' == $bazz_options_arr['left_right'] ) {
189 $other_side = 'right';
190 } else {
191 $other_side = 'left';
192 } ?>
193 <style>
194 .bazz-widget {
195 bottom: <?php echo($bazz_options_arr['bottom']); ?>px;
196 <?php echo($bazz_options_arr['left_right']); ?>: 75px;
197 <?php echo $other_side; ?>: auto !important;
198 }
199
200 .bazz-widget, .bazz-widget-close, .bazz-widget-form-submit, .bazz-widget-button, .bazz-widget-name-close, .bazz-widget-inner-circle {
201 background-color: <?php echo($bazz_options_arr['color_scheme']); ?>;
202 }
203
204 .bazz-widget-inner-border, .bazz-widget-form-submit, .bazz-widget-name-close {
205 border-color: <?php echo($bazz_options_arr['color_scheme']); ?>;
206 }
207 .bazz-widget-form-top .countdown {
208 color: <?php echo($bazz_options_arr['color_scheme']); ?>;
209 }
210 <?php if ( is_rtl() ) : ?>
211 .bazz-widget-form-top,
212 .bazz-widget-form-bottom {
213 direction: RTL;
214 }
215 .bazz-widget-close {
216 left: auto;
217 right: -10px;
218 }
219 .bazz-widget-form label,
220 .bazz-widget-form input {
221 text-align: right;
222 }
223 <?php endif; ?>
224 </style>
225 <div class="bazz-widget">
226 <div class="bazz-widget-button">
227 <i></i>
228 <i><span><?php _e( 'CALL ME', 'bazz-callback-widget' ); ?></span></i>
229 </div>
230 <div class="bazz-widget-close">+</div>
231 <div class="bazz-widget-form">
232 <div class="bazz-widget-form-top">
233 <label>
234
235 <?php $you_hyperlink = '<a href="javascript:void(0);" class="bazz-widget-your-name">' . esc_html__( 'you', 'bazz-callback-widget' ) . '</a>'; ?>
236
237 <?php if ( $bazz_options_arr['time'] == 0 ) { ?>
238
239 <?php echo( sprintf( esc_html__( 'We will call %s back in the near future!', 'bazz-callback-widget' ), $you_hyperlink ) ); ?>
240
241 <?php } else { ?>
242
243 <?php
244 if ( (int) $bazz_options_arr['time'] < 10 ) {
245 $time_option = '0' . $bazz_options_arr['time'];
246 } else {
247 $time_option = $bazz_options_arr['time'];
248 }
249 ?>
250
251 <?php $time_option = '00:<span class="bazz_time">' . $time_option . '</span>'; ?>
252 <?php echo( sprintf( esc_html__( 'We will call %s back in %s seconds!', 'bazz-callback-widget' ), $you_hyperlink, $time_option ) ); ?>
253
254 <?php } ?>
255
256 </label>
257 <input type="text" value="" name="bazz-widget-check" id="bazz-widget-check" hidden/>
258 <?php wp_nonce_field( 'bazz_widget_nonce','bazz-widget-nonce', true ); ?>
259 <input id="bazz-widget-phone" name="bazz-widget-phone" value="" type="tel"
260 placeholder="<?php _e( 'Phone here', 'bazz-callback-widget' ); ?>"/>
261 <a href="javascript:void(0);"
262 class="bazz-widget-form-submit"><?php _e( 'Call me!', 'bazz-callback-widget' ); ?></a>
263 <div class="bazz-widget-form-info"></div>
264 </div>
265 <div class="bazz-widget-form-bottom">
266 <label><?php _e( "Introduce yourself, and we'll call you by name", 'bazz-callback-widget' ); ?></label>
267 <input id="bazz-widget-name" class="grey-placeholder" name="bazz-widget-name" value="" type="text"
268 placeholder="<?php _e( 'name here', 'bazz-callback-widget' ); ?>"/>
269 <a href="javascript:void(0);" class="bazz-widget-name-close"></a>
270 </div>
271 </div>
272 <div class="bazz-widget-inner-circle"></div>
273 <div class="bazz-widget-inner-border"></div>
274 </div>
275 <?php }
276
277 //menu
278 $plugin_file = plugin_basename( __FILE__ );
279 add_filter( "plugin_action_links_$plugin_file", 'plugin_settings_link' );
280 function plugin_settings_link( $links ) {
281 $settings_links = array(
282 '<a href="options-general.php?page=bazz_menu">' . __( 'Settings', 'bazz-callback-widget' ) . '</a>',
283 '<a href="https://codecanyon.net/item/bazz-callback-widget-pro/19946676" target="_blank" style="color:#a00">PRO version</a>'
284 );
285
286 foreach( $settings_links as $settings_link ) {
287 array_unshift( $links, $settings_link );
288 }
289
290 return $links;
291 }
292
293 add_action( 'admin_menu', 'bazz_widget_menu' );
294 function bazz_widget_menu() {
295 $page = add_options_page( 'Bazz CallBack Widget settins page', 'Bazz CallBack Widget settings', 'manage_options', 'bazz_menu', 'bazz_menu_page' );
296 add_action( 'admin_init', 'bazz_register_settings' );
297 add_action( 'load-' . $page, 'bazz_widget_admin_scripts' );
298 }
299
300 function bazz_register_settings() {
301 register_setting( 'bazz_settings_group', 'bazz_options', 'bazz_sanitize_options' );
302 }
303
304 function bazz_sanitize_options( $input ) {
305 $input['email'] = sanitize_email( $input['email'] );
306 $input['work_time_start'] = sanitize_text_field( $input['work_time_start'] );
307 $input['work_time_end'] = sanitize_text_field( $input['work_time_end'] );
308 $input['time'] = sanitize_text_field( $input['time'] );
309 $input['day_text'] = sanitize_text_field( $input['day_text'] );
310 $input['night_text'] = sanitize_text_field( $input['night_text'] );
311 $input['bottom'] = sanitize_text_field( $input['bottom'] );
312 $input['in_russia'] = sanitize_text_field( $input['in_russia'] );
313 $input['color_scheme'] = sanitize_text_field( $input['color_scheme'] );
314
315 return $input;
316 }
317
318 function bazz_menu_page() { ?>
319 <h2><?php _e( 'Hi there! This is settings of the', 'bazz-callback-widget' ); ?> Bazz CallBack Widget</h2>
320 <p><?php _e( 'Change the parameters to the your discretion.', 'bazz-callback-widget' ); ?><br></p>
321 <form method="post" action="options.php" id="bazz-settings-form">
322 <?php settings_fields( 'bazz_settings_group' ); ?>
323 <?php $bazz_options = get_option( 'bazz_options' ); ?>
324 <div class="option-color-scheme">
325 <label for=""><?php _e( 'Color scheme:', 'bazz-callback-widget' ); ?><input type="color"
326 name="bazz_options[color_scheme]"
327 value="<?php echo esc_attr( $bazz_options['color_scheme'] ); ?>"/></label>
328 </div>
329 <div class="option-email">
330 <label for=""><?php _e( 'To send the message to:', 'bazz-callback-widget' ); ?><input type="email"
331 name="bazz_options[email]"
332 value="<?php echo esc_attr( $bazz_options['email'] ); ?>"/></label>
333 </div>
334 <div class="option-work-time">
335 <input type="text" id="work-time-start" name="bazz_options[work_time_start]"
336 value="<?php echo esc_attr( $bazz_options['work_time_start'] ); ?>"/>
337 <input type="text" id="work-time-end" name="bazz_options[work_time_end]"
338 value="<?php echo esc_attr( $bazz_options['work_time_end'] ); ?>"/>
339 <label><?php _e( 'Specify working time:', 'bazz-callback-widget' ); ?></label>
340 <div></div>
341
342 <script>
343 jQuery(document).ready(function () {
344 var isRTL = false;
345 if ( jQuery('html').attr('dir') == 'rtl' ) {
346 isRTL = true;
347 }
348 var min_value = parseInt(jQuery("#work-time-start").val());
349 var max_value = parseInt(jQuery("#work-time-end").val());
350 jQuery(".option-work-time > div").slider({
351 isRTL: isRTL,
352 min: 0,
353 max: 24,
354 values: [min_value, max_value],
355 range: true,
356 slide: function (event, ui) {
357 jQuery(".option-work-time label > strong:eq(0)").text(ui.values[0]);
358 jQuery(".option-work-time label > strong:eq(1)").text(ui.values[1]);
359 jQuery("#work-time-start").val(ui.values[0]);
360 jQuery("#work-time-end").val(ui.values[1]);
361 }
362 });
363 });
364 </script>
365
366 <label>
367 <?php $from_time = '<strong>' . esc_attr( $bazz_options['work_time_start'] ) . '</strong>'; ?>
368 <?php $to_time = '<strong>' . esc_attr( $bazz_options['work_time_end'] ) . '</strong>'; ?>
369 <?php echo( sprintf( esc_html__( 'The working day with %s h to %s h', 'bazz-callback-widget' ), $from_time, $to_time ) ); ?>
370 </label>
371 <br>
372 <em>
373 <?php _e( '*The time zone is using WordPress settings.', 'bazz-callback-widget' ); ?>
374 <?php echo ( sprintf( esc_html__( 'For now is %s', 'bazz-callback-widget' ), current_time( 'H:i', 0 ) ) ); ?>
375 </em>
376 </div>
377 <div class="option-timer">
378 <label for=""><?php _e( 'The countdown will be started on', 'bazz-callback-widget' ); ?> <input type="text"
379 name="bazz_options[time]"
380 value="<?php echo esc_attr( $bazz_options['time'] ); ?>"/> <?php _e( 'seconds.', 'bazz-callback-widget' ); ?>
381 </label>
382 <em><?php _e( 'Set 0 and countdown functionality will be disabled', 'bazz-callback-widget' ); ?></em>
383 </div>
384 <div class="option-text3">
385 <label for=""><?php _e( 'The text after sending in working hours (afternoon):', 'bazz-callback-widget' ); ?></label>
386 <textarea name="bazz_options[day_text]"><?php echo( $bazz_options['day_text'] ); ?></textarea>
387 </div>
388 <div class="option-text4">
389 <label for=""><?php _e( 'The text after sending in NOT working hours (night):', 'bazz-callback-widget' ); ?></label>
390 <textarea name="bazz_options[night_text]"><?php echo( $bazz_options['night_text'] ); ?></textarea>
391 </div>
392 <?php if ( get_locale() == 'ru_RU' ) :?>
393 <div class="option-in-russia">
394 <label for=""><?php _e( 'Your clients are from Russia?', 'bazz-callback-widget' ); ?></label>
395 <select name="bazz_options[in_russia]" id="">
396 <option value="1" <?php if ( $bazz_options['in_russia'] == 1 ) {
397 echo( 'selected' );
398 } ?>><?php _e( 'Yes', 'bazz-callback-widget' ); ?></option>
399 <option value="0" <?php if ( $bazz_options['in_russia'] == 0 ) {
400 echo( 'selected' );
401 } ?>><?php _e( 'No', 'bazz-callback-widget' ); ?></option>
402 </select>
403 </div>
404 <?php endif; ?>
405 <div class="option-bottom">
406 <label for=""><?php _e( 'Distance from the window bottom', 'bazz-callback-widget' ); ?>
407 <input type="text" name="bazz_options[bottom]"
408 value="<?php echo esc_attr( $bazz_options['bottom'] ); ?>"/> px.</label>
409 </div>
410 <div class="option-left-right">
411 <label for=""><?php _e( 'Show on the left/right side', 'bazz-callback-widget' ); ?>
412 <select name="bazz_options[left_right]" id="">
413 <option value="left" <?php if ( $bazz_options['left_right'] == 'left' ) {
414 echo( 'selected' );
415 } ?>><?php _e( 'Left', 'bazz-callback-widget' ); ?></option>
416 <option value="right" <?php if ( $bazz_options['left_right'] == 'right' ) {
417 echo( 'selected' );
418 } ?>><?php _e( 'Right', 'bazz-callback-widget' ); ?></option>
419 </select>
420 </div>
421 <div>
422 <input type="submit" value="<?php _e( 'Save', 'bazz-callback-widget' ); ?>"/>
423 </div>
424 </form>
425 <?php }
426
427 ?>
428