| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Bazz CallBack Widget |
| 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.10 |
| 10 |
Author URI: http://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' ) ) exit; |
| 33 |
|
| 34 |
//current version constant |
| 35 |
define( 'BAZZ_WIDGET_VERSION', '3.10' ); |
| 36 |
|
| 37 |
//activation hook |
| 38 |
register_activation_hook( __FILE__, 'bazz_install'); |
| 39 |
function bazz_install() { |
| 40 |
if (!get_option('bazz_options')) { |
| 41 |
$bazz_options_arr = array( |
| 42 |
'email' => 'example@mail.com', |
| 43 |
'work_time_start' => '9', |
| 44 |
'work_time_end' => '21', |
| 45 |
'time' => '48', |
| 46 |
'day_text' => __('The loading is extremely high, we will call back to you in the nearest future. Thanks!','bazz-callback-widget'), |
| 47 |
'night_text' => __('Unfortunately, we don\'t work for now. We will call back to you tomorrow! Thanks!','bazz-callback-widget'), |
| 48 |
'bottom' => '68' |
| 49 |
); |
| 50 |
update_option('bazz_options', $bazz_options_arr); |
| 51 |
} |
| 52 |
} |
| 53 |
//deactivation hook |
| 54 |
register_deactivation_hook( __FILE__, 'bazz_deactivate'); |
| 55 |
function bazz_deactivate() { |
| 56 |
|
| 57 |
} |
| 58 |
//uninstall hook |
| 59 |
register_uninstall_hook( __FILE__, 'bazz_uninstall'); |
| 60 |
function bazz_uninstall() { |
| 61 |
delete_option('bazz_options'); |
| 62 |
} |
| 63 |
|
| 64 |
//Add new options |
| 65 |
function bazz_new_option( $option_name, $option_value ) { |
| 66 |
$bazz_options_array = get_option('bazz_options'); |
| 67 |
if ( !array_key_exists( $option_name, $bazz_options_array ) ) { |
| 68 |
$bazz_options_array[$option_name] = $option_value; |
| 69 |
update_option('bazz_options', $bazz_options_array); |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
add_action( 'init', 'bazz_widget_add_new_options' ); |
| 74 |
function bazz_widget_add_new_options() { |
| 75 |
/*Добавляем сюда новые опции*/ |
| 76 |
|
| 77 |
//Added in 2.2 |
| 78 |
bazz_new_option('in_russia', '1'); |
| 79 |
|
| 80 |
//Added in 3.0 |
| 81 |
bazz_new_option('color_scheme', '#00AFF2'); |
| 82 |
bazz_new_option('left_right', 'right'); |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
//localize |
| 87 |
function localize_load() { |
| 88 |
load_plugin_textdomain('bazz-callback-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 89 |
} |
| 90 |
add_action('plugins_loaded', 'localize_load'); |
| 91 |
|
| 92 |
//load styles and scripts |
| 93 |
add_action('init', 'bazz_widget_styles'); |
| 94 |
function bazz_widget_styles() { |
| 95 |
if(!is_admin()) { |
| 96 |
wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget.css', __FILE__), array(), BAZZ_WIDGET_VERSION, 'all'); |
| 97 |
} else { |
| 98 |
wp_enqueue_style('bazz_widget_admin_style', plugins_url('css/bazz-widget-admin.css', __FILE__), array(), BAZZ_WIDGET_VERSION, 'all'); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
add_action('wp_footer', 'bazz_widget_scripts'); |
| 103 |
function bazz_widget_scripts() { |
| 104 |
wp_enqueue_script('jquery'); |
| 105 |
wp_enqueue_script('bazz_maskedinput', plugins_url('js/jquery.maskedinput.min.js', __FILE__), 'jquery', null, true); |
| 106 |
wp_enqueue_script('bazz_draggable', plugins_url('js/jquery.draggable.min.js', __FILE__), 'jquery', null, true); |
| 107 |
wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget.js', __FILE__), 'jquery', null, true); |
| 108 |
wp_localize_script('bazz_widget_script', 'bazz_ajax', |
| 109 |
array( |
| 110 |
'url' => admin_url('admin-ajax.php') |
| 111 |
) |
| 112 |
); |
| 113 |
$bazz_options = get_option('bazz_options'); |
| 114 |
wp_localize_script('bazz_widget_script', 'bazz_options', |
| 115 |
array( |
| 116 |
'currentLang' => __('EN','bazz-callback-widget'), |
| 117 |
'bazz_in_russia' => $bazz_options['in_russia'], |
| 118 |
'bazz_color_scheme' => $bazz_options['color_scheme'] |
| 119 |
) |
| 120 |
); |
| 121 |
} |
| 122 |
|
| 123 |
add_action('admin_enqueue_scripts', 'bazz_widget_admin_scripts'); |
| 124 |
function bazz_widget_admin_scripts() { |
| 125 |
wp_enqueue_script('jquery'); |
| 126 |
wp_enqueue_script('bazz_slider', plugins_url('js/jquery.ui-slider.js', __FILE__), 'jquery'); |
| 127 |
wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget-admin.js', __FILE__), 'bazz_slider'); |
| 128 |
} |
| 129 |
|
| 130 |
//AJAX |
| 131 |
add_action('wp_ajax_bazz_widget_action', 'bazz_widget_send'); |
| 132 |
add_action('wp_ajax_nopriv_bazz_widget_action', 'bazz_widget_send'); |
| 133 |
function bazz_widget_send() { |
| 134 |
if (isset($_POST['phone'])) {$phone = $_POST['phone'];} |
| 135 |
if (isset($_POST['name'])) {$name = $_POST['name'];} else {$name = __("The client wasn't introduced",'bazz-callback-widget');} |
| 136 |
$blog_url = get_home_url(); |
| 137 |
$admin_email = get_option('admin_email'); |
| 138 |
$bazz_options_arr = get_option('bazz_options'); |
| 139 |
$email = $bazz_options_arr['email']; |
| 140 |
$current_time = current_time('G'); |
| 141 |
$work_time_start = $bazz_options_arr['work_time_start']; |
| 142 |
$work_time_end = $bazz_options_arr['work_time_end']; |
| 143 |
$text = $bazz_options_arr['day_text']; |
| 144 |
if ($work_time_start > $current_time || $current_time >= $work_time_end) { |
| 145 |
$text = $bazz_options_arr['night_text']; |
| 146 |
} |
| 147 |
$to = $email; |
| 148 |
$headers = "Content-type: text/plain; charset=utf-8"; |
| 149 |
$subject = "$blog_url ". __('[FROM BAZZ WIDGET]','bazz-callback-widget'); |
| 150 |
$message = __('Phone','bazz-callback-widget') ." - $phone ". |
| 151 |
__('Name','bazz-callback-widget') ." - $name"; |
| 152 |
$send = wp_mail($to, $subject, $message, $headers); |
| 153 |
if ($send == 'true'){ |
| 154 |
echo ('<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">'.$text.'</div>'); |
| 155 |
wp_die(); |
| 156 |
} else { |
| 157 |
return false; |
| 158 |
wp_die(); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
//HTML layout |
| 163 |
add_action('wp_footer', 'bazz_layout'); |
| 164 |
function bazz_layout() { ?> |
| 165 |
<?php $bazz_options_arr = get_option('bazz_options'); ?> |
| 166 |
<?php if ( 'left' == $bazz_options_arr['left_right'] ) { |
| 167 |
$other_side = 'right'; |
| 168 |
} else { |
| 169 |
$other_side = 'left'; |
| 170 |
} ?> |
| 171 |
<style> |
| 172 |
.bazz-widget {bottom: <?php echo($bazz_options_arr['bottom']); ?>px; <?php echo($bazz_options_arr['left_right']); ?>: 75px; <?php echo $other_side; ?>: auto !important;} |
| 173 |
.bazz-widget, .bazz-widget-close, .bazz-widget-form-submit, .bazz-widget-button, .bazz-widget-name-close, .bazz-widget-inner-circle { background-color: <?php echo($bazz_options_arr['color_scheme']); ?>;} |
| 174 |
.bazz-widget-inner-border, .bazz-widget-form-submit, .bazz-widget-name-close {border-color: <?php echo($bazz_options_arr['color_scheme']); ?>;} |
| 175 |
</style> |
| 176 |
<div class="bazz-widget"> |
| 177 |
<div class="bazz-widget-button"> |
| 178 |
<i></i> |
| 179 |
<i><?php _e('CALL NOW', 'bazz-callback-widget'); ?></i> |
| 180 |
</div> |
| 181 |
<div class="bazz-widget-close">+</div> |
| 182 |
<div class="bazz-widget-form"> |
| 183 |
<div class="bazz-widget-form-top"> |
| 184 |
<label> |
| 185 |
<?php _e('We will call ','bazz-callback-widget');?> |
| 186 |
<a href="javascript:void(0);" class="bazz-widget-your-name"> <?php _e('you','bazz-callback-widget');?></a> |
| 187 |
<?php if ($bazz_options_arr['time'] == 0) { ?> |
| 188 |
<?php _e('back in the nearest future!','bazz-callback-widget');?> |
| 189 |
<?php } else { ?> |
| 190 |
<?php _e('in','bazz-callback-widget');?> 00:<span class="bazz_time"><?php echo($bazz_options_arr['time']); ?></span> |
| 191 |
<?php _e('seconds!','bazz-callback-widget');?> |
| 192 |
<?php } ?> |
| 193 |
</label> |
| 194 |
<input type="text" value="<?php echo plugins_url('', __FILE__); ?>" id="plugin-url" hidden /> |
| 195 |
<input id="bazz-widget-phone" name="bazz-widget-phone" value="" type="tel" placeholder="<?php _e('phone here','bazz-callback-widget');?>" /> |
| 196 |
<a href="javascript:void(0);" class="bazz-widget-form-submit"><?php _e('Call me!', 'bazz-callback-widget'); ?></a> |
| 197 |
<div class="bazz-widget-form-info"></div> |
| 198 |
</div> |
| 199 |
<div class="bazz-widget-form-bottom"> |
| 200 |
<label><?php _e("Introduce youself, and we'll have been calling you by name", 'bazz-callback-widget'); ?></label> |
| 201 |
<input id="bazz-widget-name" class="grey-placeholder" name="bazz-widget-name" value="" type="text" placeholder="<?php _e('name here','bazz-callback-widget');?>" /> |
| 202 |
<a href="javascript:void(0);" class="bazz-widget-name-close"></a> |
| 203 |
</div> |
| 204 |
</div> |
| 205 |
<div class="bazz-widget-inner-circle"></div> |
| 206 |
<div class="bazz-widget-inner-border"></div> |
| 207 |
</div> |
| 208 |
<?php } |
| 209 |
//menu |
| 210 |
$plugin_file = plugin_basename(__FILE__); |
| 211 |
add_filter("plugin_action_links_$plugin_file", 'plugin_settings_link' ); |
| 212 |
function plugin_settings_link($links) { |
| 213 |
$settings_link = '<a href="options-general.php?page=bazz_menu">' . __('Settings', 'bazz-callback-widget') . '</a>'; |
| 214 |
array_unshift( $links, $settings_link ); |
| 215 |
return $links; |
| 216 |
} |
| 217 |
|
| 218 |
add_action('admin_menu','bazz_widget_menu'); |
| 219 |
function bazz_widget_menu() { |
| 220 |
add_options_page('Bazz CallBack Widget settins page', 'Bazz CallBack Widget settings', 'manage_options', 'bazz_menu', 'bazz_menu_page'); |
| 221 |
add_action('admin_init', 'bazz_register_settings'); |
| 222 |
} |
| 223 |
function bazz_register_settings() { |
| 224 |
register_setting('bazz_settings_group', 'bazz_options', 'bazz_sanitize_options'); |
| 225 |
} |
| 226 |
function bazz_sanitize_options($input) { |
| 227 |
$input['email'] = sanitize_email($input['email']); |
| 228 |
$input['work_time_start'] = sanitize_text_field($input['work_time_start']); |
| 229 |
$input['work_time_end'] = sanitize_text_field($input['work_time_end']); |
| 230 |
$input['time'] = sanitize_text_field($input['time']); |
| 231 |
$input['button_text'] = sanitize_text_field($input['button_text']); |
| 232 |
$input['send_text'] = sanitize_text_field($input['send_text']); |
| 233 |
$input['day_text'] = sanitize_text_field($input['day_text']); |
| 234 |
$input['night_text'] = sanitize_text_field($input['night_text']); |
| 235 |
$input['bottom'] = sanitize_text_field($input['bottom']); |
| 236 |
$input['in_russia'] = sanitize_text_field($input['in_russia']); |
| 237 |
$input['color_scheme'] = sanitize_text_field($input['color_scheme']); |
| 238 |
return $input; |
| 239 |
} |
| 240 |
function bazz_menu_page() { ?> |
| 241 |
<h2><?php _e('Hi there! This is settings of the','bazz-callback-widget'); ?> Bazz CallBack Widget</h2> |
| 242 |
<p><?php _e('Change the parameters to the your discretion.', 'bazz-callback-widget'); ?><br></p> |
| 243 |
<form method="post" action="options.php" id="bazz-settings-form"> |
| 244 |
<?php settings_fields('bazz_settings_group'); ?> |
| 245 |
<?php $bazz_options = get_option('bazz_options'); ?> |
| 246 |
<div class="option-color-scheme"> |
| 247 |
<label for=""><?php _e('Color scheme:', 'bazz-callback-widget');?><input type="color" name="bazz_options[color_scheme]" value="<?php echo esc_attr($bazz_options['color_scheme']); ?>" /></label> |
| 248 |
</div> |
| 249 |
<div class="option-email"> |
| 250 |
<label for=""><?php _e('To send the message to:', 'bazz-callback-widget');?><input type="email" name="bazz_options[email]" value="<?php echo esc_attr($bazz_options['email']); ?>" /></label> |
| 251 |
</div> |
| 252 |
<div class="option-work-time"> |
| 253 |
<input type="text" id="work-time-start" name="bazz_options[work_time_start]" value="<?php echo esc_attr($bazz_options['work_time_start']); ?>" /> |
| 254 |
<input type="text" id="work-time-end" name="bazz_options[work_time_end]" value="<?php echo esc_attr($bazz_options['work_time_end']); ?>" /> |
| 255 |
<label><?php _e('Specify working time:', 'bazz-callback-widget');?></label> |
| 256 |
<div></div> |
| 257 |
|
| 258 |
<script> |
| 259 |
jQuery(document).ready(function(){ |
| 260 |
min_value = parseInt(jQuery("#work-time-start").val()); |
| 261 |
max_value = parseInt(jQuery("#work-time-end").val()); |
| 262 |
jQuery(".option-work-time > div").slider({ |
| 263 |
min: 0, |
| 264 |
max: 24, |
| 265 |
values: [min_value, max_value], |
| 266 |
range: true, |
| 267 |
slide: function( event, ui ) { |
| 268 |
jQuery(".option-work-time label > strong:eq(0)").text(ui.values[ 0 ]); |
| 269 |
jQuery(".option-work-time label > strong:eq(1)").text(ui.values[ 1 ]); |
| 270 |
jQuery("#work-time-start").val(ui.values[ 0 ]); |
| 271 |
jQuery("#work-time-end").val(ui.values[ 1 ]); |
| 272 |
} |
| 273 |
}); |
| 274 |
}); |
| 275 |
</script> |
| 276 |
|
| 277 |
<label><?php _e('The working day with', 'bazz-callback-widget'); ?> <strong> <?php echo esc_attr($bazz_options['work_time_start']); ?> </strong> |
| 278 |
<?php _e('h to', 'bazz-callback-widget'); ?> <strong> <?php echo esc_attr($bazz_options['work_time_end']); ?> </strong> |
| 279 |
<?php _e('h', 'bazz-callback-widget'); ?></label><br> |
| 280 |
<em><?php _e('*The time zone is using WordPress settings', 'bazz-callback-widget'); ?></em> |
| 281 |
</div> |
| 282 |
<div class="option-timer"> |
| 283 |
<label for=""><?php _e('The countdown will be started on','bazz-callback-widget');?> <input type="text" name="bazz_options[time]" value="<?php echo esc_attr($bazz_options['time']); ?>" /> <?php _e('seconds.','bazz-callback-widget');?></label> |
| 284 |
<em><?php _e('Set 0 and countdown functionality will be disabled', 'bazz-callback-widget'); ?></em> |
| 285 |
</div> |
| 286 |
<div class="option-text3"> |
| 287 |
<label for=""><?php _e('The text in working hours (afternoon):','bazz-callback-widget');?></label> |
| 288 |
<textarea name="bazz_options[day_text]"><?php echo($bazz_options['day_text']); ?></textarea> |
| 289 |
</div> |
| 290 |
<div class="option-text4"> |
| 291 |
<label for=""><?php _e('The text in NOT working hours (night):','bazz-callback-widget');?></label> |
| 292 |
<textarea name="bazz_options[night_text]"><?php echo($bazz_options['night_text']); ?></textarea> |
| 293 |
</div> |
| 294 |
<div class="option-in-russia"> |
| 295 |
<label for=""><?php _e('Your clients are from Russia?','bazz-callback-widget');?></label> |
| 296 |
<select name="bazz_options[in_russia]" id=""> |
| 297 |
<option value="1" <?php if ($bazz_options['in_russia'] == 1) echo ('selected'); ?>><?php _e('Yes','bazz-callback-widget'); ?></option> |
| 298 |
<option value="0" <?php if ($bazz_options['in_russia'] == 0) echo ('selected'); ?>><?php _e('No','bazz-callback-widget'); ?></option> |
| 299 |
</select> |
| 300 |
</div> |
| 301 |
<div class="option-bottom"> |
| 302 |
<label for=""><?php _e('Distance from the window bottom','bazz-callback-widget');?> |
| 303 |
<input type="text" name="bazz_options[bottom]" value="<?php echo esc_attr($bazz_options['bottom']); ?>" /> px.</label> |
| 304 |
</div> |
| 305 |
<div class="option-left-right"> |
| 306 |
<label for=""><?php _e('Show on the left/right side','bazz-callback-widget');?> |
| 307 |
<select name="bazz_options[left_right]" id=""> |
| 308 |
<option value="left" <?php if ($bazz_options['left_right'] == 'left') echo ('selected'); ?>><?php _e('Left','bazz-callback-widget');?></option> |
| 309 |
<option value="right" <?php if ($bazz_options['left_right'] == 'right') echo ('selected'); ?>><?php _e('Right','bazz-callback-widget');?></option> |
| 310 |
</select> |
| 311 |
</div> |
| 312 |
<div> |
| 313 |
<input type="submit" value="<?php _e('Save','bazz-callback-widget');?>" /> |
| 314 |
</div> |
| 315 |
</form> |
| 316 |
<?php } |
| 317 |
|
| 318 |
?> |