PluginProbe
Bazz CallBack widget / 2.1
Bazz CallBack widget v2.1
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 2.1, at bazz-callback-widget.php

244 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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: 2.1
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 //activation hook
35 register_activation_hook( __FILE__, 'bazz_install');
36 function bazz_install() {
37 $bazz_options_arr = array(
38 'email' => 'example@mail.com',
39 'work_time_start' => '9',
40 'work_time_end' => '21',
41 'time' => '48',
42 'day_text' => __('The loading is extremely high, we will call back to you in the nearest future. Thanks!','bazz-callback-widget'),
43 'night_text' => __('Unfortunately, we don\'t work for now. We will call back to you tomorrow! Thanks!','bazz-callback-widget'),
44 'bottom' => '68'
45 );
46 update_option('bazz_options', $bazz_options_arr);
47 }
48 //deactivation hook
49 register_deactivation_hook( __FILE__, 'bazz_deactivate');
50 function bazz_deactivate() {
51
52 }
53
54 //localize
55 function localize_load() {
56 load_plugin_textdomain('bazz-callback-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
57 }
58 add_action('plugins_loaded', 'localize_load');
59
60 //load styles and scripts
61 add_action('init', 'bazz_widget_styles');
62 function bazz_widget_styles() {
63 if(!is_admin()) {
64 wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget.css', __FILE__));
65 } else {
66 wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget-admin.css', __FILE__));
67 }
68 }
69
70 add_action('wp_enqueue_scripts', 'bazz_widget_scripts');
71 function bazz_widget_scripts() {
72 wp_enqueue_script('jquery');
73 wp_enqueue_script('bazz_maskedinput', plugins_url('js/jquery.maskedinput.min.js', __FILE__), 'jquery', null, true);
74 wp_enqueue_script('bazz_draggable', plugins_url('js/jquery.draggable.min.js', __FILE__), 'jquery', null, true);
75 wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget.js', __FILE__), 'jquery', null, true);
76 wp_localize_script('bazz_widget_script', 'currentLang', array(
77 'currentLang' => __('EN','bazz-callback-widget'))
78 );
79 }
80
81 add_action('admin_enqueue_scripts', 'bazz_widget_admin_scripts');
82 function bazz_widget_admin_scripts() {
83 wp_enqueue_script('jquery');
84 wp_enqueue_script('bazz_slider', plugins_url('js/jquery.ui-slider.js', __FILE__), 'jquery');
85 wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget-admin.js', __FILE__), 'bazz_slider');
86 }
87
88 add_action('wp_enqueue_scripts', 'myajax_data', 99);
89 function myajax_data(){
90 wp_localize_script('bazz_widget_script', 'myajax',
91 array(
92 'url' => admin_url('admin-ajax.php')
93 )
94 );
95 }
96
97 //AJAX
98 add_action('wp_ajax_bazz_widget_action', 'bazz_widget_send');
99 add_action('wp_ajax_nopriv_bazz_widget_action', 'bazz_widget_send');
100 function bazz_widget_send() {
101 if (isset($_POST['phone'])) {$phone = $_POST['phone'];}
102 if (isset($_POST['name'])) {$name = $_POST['name'];} else {$name = __("The client wasn't introduced",'bazz-callback-widget');}
103 $blog_url = get_home_url();
104 $bazz_options_arr = get_option('bazz_options');
105 $email = $bazz_options_arr['email'];
106 $current_time = current_time('G');
107 $work_time_start = $bazz_options_arr['work_time_start'];
108 $work_time_end = $bazz_options_arr['work_time_end'];
109 $text = $bazz_options_arr['day_text'];
110 if ($work_time_start > $current_time || $current_time >= $work_time_end) {
111 $text = $bazz_options_arr['night_text'];
112 }
113 $to = $email;
114 $headers = "Content-type: text/plain; charset =utf-8";
115 $subject = "$blog_url ". __('[FROM BAZZ WIDGET]','bazz-callback-widget');
116 $message = __('Phone','bazz-callback-widget') ." - $phone ".
117 __('Name','bazz-callback-widget') ." - $name";
118 $send = mail($to, $subject, $message, $headers);
119 if ($send == 'true'){
120 echo ('<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">'.$text.'</div>');
121 wp_die();
122 } else {
123 return false;
124 wp_die();
125 }
126 }
127
128 //HTML layout
129 add_action('wp_footer', 'bazz_layout');
130 function bazz_layout() { ?>
131 <?php $bazz_options_arr = get_option('bazz_options'); ?>
132 <style>
133 .bazz-widget {bottom: <?php echo($bazz_options_arr['bottom']); ?>px;}
134 </style>
135 <div class="bazz-widget">
136 <div class="bazz-widget-button">
137 <i></i>
138 <i><?php _e('CALL NOW', 'bazz-callback-widget'); ?></i>
139 </div>
140 <div class="bazz-widget-close">+</div>
141 <div class="bazz-widget-form">
142 <div class="bazz-widget-form-top">
143 <label>
144 <?php _e('We will call ','bazz-callback-widget');?>
145 <a href="#" class="bazz-widget-your-name"> <?php _e('you','bazz-callback-widget');?></a>
146 <?php _e('in','bazz-callback-widget');?><br>00:<span class="bazz_time"><?php echo($bazz_options_arr['time']); ?></span>
147 <?php _e('seconds!','bazz-callback-widget');?>
148 </label>
149 <input type="text" value="<?php echo plugins_url('', __FILE__); ?>" id="plugin-url" hidden />
150 <input id="bazz-widget-phone" name="bazz-widget-phone" value="" type="tel" placeholder="<?php _e('phone here','bazz-callback-widget');?>" />
151 <a href="#" class="bazz-widget-form-submit"><?php _e('Call me!', 'bazz-callback-widget'); ?></a>
152 </div>
153 <div class="bazz-widget-form-bottom">
154 <label><?php _e("Introduce youself, and we'll have been calling you by name", 'bazz-callback-widget'); ?></label>
155 <input id="bazz-widget-name" class="grey-placeholder" name="bazz-widget-name" value="" type="text" placeholder="<?php _e('name here','bazz-callback-widget');?>" />
156 <a href="#" class="bazz-widget-name-close"></a>
157 </div>
158 </div>
159 <div class="bazz-widget-inner-circle"></div>
160 <div class="bazz-widget-inner-border"></div>
161 </div>
162 <?php }
163 //menu
164 add_action('admin_menu','bazz_widget_menu');
165 function bazz_widget_menu() {
166 add_options_page('Bazz CallBack Widget settins page', 'Bazz CallBack Widget settings', 'manage_options', 'bazz_menu', 'bazz_menu_page');
167 add_action('admin_init', 'bazz_register_settings');
168 }
169 function bazz_register_settings() {
170 register_setting('bazz_settings_group', 'bazz_options', 'bazz_sanitize_options');
171 }
172 function bazz_sanitize_options($input) {
173 $input['email'] = sanitize_email($input['email']);
174 $input['work_time_start'] = sanitize_text_field($input['work_time_start']);
175 $input['work_time_end'] = sanitize_text_field($input['work_time_end']);
176 $input['time'] = sanitize_text_field($input['time']);
177 $input['button_text'] = sanitize_text_field($input['button_text']);
178 $input['send_text'] = sanitize_text_field($input['send_text']);
179 $input['day_text'] = sanitize_text_field($input['day_text']);
180 $input['night_text'] = sanitize_text_field($input['night_text']);
181 $input['bottom'] = sanitize_text_field($input['bottom']);
182 return $input;
183 }
184 function bazz_menu_page() { ?>
185 <h2><?php _e('Hi there! This is settings of the','bazz-callback-widget'); ?> Bazz CallBack Widget</h2>
186 <p><?php _e('Change the parameters to the your discretion.', 'bazz-callback-widget'); ?><br></p>
187 <form method="post" action="options.php" id="bazz-settings-form">
188 <?php settings_fields('bazz_settings_group'); ?>
189 <?php $bazz_options = get_option('bazz_options'); ?>
190 <div class="option-email">
191 <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>
192 </div>
193 <div class="option-work-time">
194 <input type="text" id="work-time-start" name="bazz_options[work_time_start]" value="<?php echo esc_attr($bazz_options['work_time_start']); ?>" />
195 <input type="text" id="work-time-end" name="bazz_options[work_time_end]" value="<?php echo esc_attr($bazz_options['work_time_end']); ?>" />
196 <label><?php _e('Specify working time:', 'bazz-callback-widget');?></label>
197 <div></div>
198
199 <script>
200 jQuery(document).ready(function(){
201 min_value = parseInt(jQuery("#work-time-start").val());
202 max_value = parseInt(jQuery("#work-time-end").val());
203 jQuery(".option-work-time > div").slider({
204 min: 0,
205 max: 24,
206 values: [min_value, max_value],
207 range: true,
208 slide: function( event, ui ) {
209 jQuery(".option-work-time label > strong:eq(0)").text(ui.values[ 0 ]);
210 jQuery(".option-work-time label > strong:eq(1)").text(ui.values[ 1 ]);
211 jQuery("#work-time-start").val(ui.values[ 0 ]);
212 jQuery("#work-time-end").val(ui.values[ 1 ]);
213 }
214 });
215 });
216 </script>
217
218 <label><?php _e('The working day with', 'bazz-callback-widget'); ?> <strong> <?php echo esc_attr($bazz_options['work_time_start']); ?> </strong>
219 <?php _e('h to', 'bazz-callback-widget'); ?> <strong> <?php echo esc_attr($bazz_options['work_time_end']); ?> </strong>
220 <?php _e('h', 'bazz-callback-widget'); ?></label><br>
221 <em><?php _e('*The time zone is using WordPress settings', 'bazz-callback-widget'); ?></em>
222 </div>
223 <div class="option-timer">
224 <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>
225 </div>
226 <div class="option-text3">
227 <label for=""><?php _e('The text in working hours (afternoon):','bazz-callback-widget');?></label>
228 <textarea name="bazz_options[day_text]"><?php echo($bazz_options['day_text']); ?></textarea>
229 </div>
230 <div class="option-text4">
231 <label for=""><?php _e('The text in NOT working hours (night):','bazz-callback-widget');?></label>
232 <textarea name="bazz_options[night_text]"><?php echo($bazz_options['night_text']); ?></textarea>
233 </div>
234 <div class="option-bottom">
235 <label for=""><?php _e('Distance from the window bottom','bazz-callback-widget');?>
236 <input type="text" name="bazz_options[bottom]" value="<?php echo esc_attr($bazz_options['bottom']); ?>" /> px.</label>
237 </div>
238 <div>
239 <input type="submit" value="<?php _e('Save','bazz-callback-widget');?>" />
240 </div>
241 </form>
242 <?php }
243
244 ?>