PluginProbe
Bazz CallBack widget / 1.3
Bazz CallBack widget v1.3
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 1.3, at bazz-callback-widget.php

232 lines 9.9 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 Description: This plugin makes a simple widget for callback on your website.
6 Author: Viktor Ievlev
7 Version: 1.3
8 Author URI: http://viktor-web.ru
9 */
10 /*
11 Copyright 2016 Viktor Ievlev (email: bazz@bk.ru)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27 //activation hook
28 register_activation_hook( __FILE__, 'bazz_install');
29 function bazz_install() {
30 $bazz_options_arr = array(
31 'email' => 'example@mail.com',
32 'work_time_start' => '9',
33 'work_time_end' => '21',
34 'time' => '48',
35 'button_text' => 'ПОЗВО-НИТЬ',
36 'send_text' => 'Жду звонка!',
37 'day_text' => 'Нагрузка крайне высокая, мы перезвоним Вам в ближайшее время. Спасибо!',
38 'night_text' => 'К сожалению, сейчас мы не работаем! Мы перезвоним Вам завтра! Спасибо!',
39 'bottom' => '68'
40 );
41 update_option('bazz_options', $bazz_options_arr);
42 }
43 //deactivation hook
44 register_deactivation_hook( __FILE__, 'bazz_deactivate');
45 function bazz_deactivate() {
46
47 }
48 //load styles and scripts
49 add_action('init', 'bazz_widget_styles');
50 function bazz_widget_styles() {
51 if(!is_admin()) {
52 wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget.css', __FILE__));
53 } else {
54 wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget-admin.css', __FILE__));
55 }
56 }
57
58 add_action('wp_enqueue_scripts', 'bazz_widget_scripts');
59 function bazz_widget_scripts() {
60 wp_enqueue_script('jquery');
61 wp_enqueue_script('bazz_maskedinput', plugins_url('js/jquery.maskedinput.min.js', __FILE__), 'jquery');
62 wp_enqueue_script('bazz_draggable', plugins_url('js/jquery.draggable.min.js', __FILE__), 'jquery');
63 wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget.js', __FILE__));
64 }
65
66 add_action('admin_enqueue_scripts', 'bazz_widget_admin_scripts');
67 function bazz_widget_admin_scripts() {
68 wp_enqueue_script('jquery');
69 wp_enqueue_script('bazz_slider', plugins_url('js/jquery.ui-slider.js', __FILE__), 'jquery');
70 wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget-admin.js', __FILE__), 'bazz_slider');
71 }
72
73 add_action('wp_enqueue_scripts', 'myajax_data', 99);
74 function myajax_data(){
75 wp_localize_script('bazz_widget_script', 'myajax',
76 array(
77 'url' => admin_url('admin-ajax.php')
78 )
79 );
80 }
81
82 //AJAX
83 add_action('wp_ajax_bazz_widget_action', 'bazz_widget_send');
84 add_action('wp_ajax_nopriv_bazz_widget_action', 'bazz_widget_send');
85 function bazz_widget_send() {
86 if (isset($_POST['phone'])) {$phone = $_POST['phone'];}
87 if (isset($_POST['name'])) {$name = $_POST['name'];} else {$name = 'Клиент не представился';}
88 $blog_url = get_home_url();
89 $bazz_options_arr = get_option('bazz_options');
90 $email = $bazz_options_arr['email'];
91 $current_time = current_time('G');
92 $work_time_start = $bazz_options_arr['work_time_start'];
93 $work_time_end = $bazz_options_arr['work_time_end'];
94 $text = $bazz_options_arr['day_text'];
95 if ($work_time_start > $current_time || $current_time >= $work_time_end) {
96 $text = $bazz_options_arr['night_text'];
97 }
98 $to = $email;
99 $headers = "Content-type: text/plain; charset =utf-8";
100 $subject = "$blog_url [ИЗ ВИДЖЕТА]";
101 $message = "Телефон - $phone
102 Имя - $name";
103 $send = mail($to, $subject, $message, $headers);
104 if ($send == 'true'){
105 echo ('<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">'.$text.'</div>');
106 wp_die();
107 } else {
108 return false;
109 wp_die();
110 }
111 }
112
113 //HTML layout
114 add_action('wp_footer', 'bazz_layout');
115 function bazz_layout() { ?>
116 <?php $bazz_options_arr = get_option('bazz_options'); ?>
117 <style>
118 .bazz-widget {bottom: <?php echo($bazz_options_arr['bottom']); ?>px;}
119 </style>
120 <div class="bazz-widget">
121 <div class="bazz-widget-button">
122 <i></i>
123 <i><?php echo($bazz_options_arr['button_text']); ?></i>
124 </div>
125 <div class="bazz-widget-close">+</div>
126 <div class="bazz-widget-form">
127 <div class="bazz-widget-form-top">
128 <label>Перезвоним <a href="#" class="bazz-widget-your-name">Вам</a> за<br>00:<span class="bazz_time"><?php echo($bazz_options_arr['time']); ?></span> секунд!</label>
129 <input type="text" value="<?php echo plugins_url('', __FILE__); ?>" id="plugin-url" hidden />
130 <input id="bazz-widget-phone" name="bazz-widget-phone" value="" type="tel" placeholder="+7(___)___-__-__" />
131 <a href="#" class="bazz-widget-form-submit"><?php echo($bazz_options_arr['send_text']); ?></a>
132 </div>
133 <div class="bazz-widget-form-bottom">
134 <label>Пердставьтесь, и мы будем обращаться по имени</label>
135 <input id="bazz-widget-name" name="bazz-widget-name" value="" type="text" placeholder="Введите Ваше имя" />
136 <a href="#" class="bazz-widget-name-close"></a>
137 </div>
138 </div>
139 <div class="bazz-widget-inner-circle"></div>
140 <div class="bazz-widget-inner-border"></div>
141 </div>
142 <?php }
143 //menu
144 add_action('admin_menu','bazz_widget_menu');
145 function bazz_widget_menu() {
146 add_options_page('Bazz CallBack Widget settins page', 'Bazz CallBack Widget settings', 'manage_options', 'bazz_menu', 'bazz_menu_page');
147 add_action('admin_init', 'bazz_register_settings');
148 }
149 function bazz_register_settings() {
150 register_setting('bazz_settings_group', 'bazz_options', 'bazz_sanitize_options');
151 }
152 function bazz_sanitize_options($input) {
153 $input['email'] = sanitize_email($input['email']);
154 $input['work_time_start'] = sanitize_text_field($input['work_time_start']);
155 $input['work_time_end'] = sanitize_text_field($input['work_time_end']);
156 $input['time'] = sanitize_text_field($input['time']);
157 $input['button_text'] = sanitize_text_field($input['button_text']);
158 $input['send_text'] = sanitize_text_field($input['send_text']);
159 $input['day_text'] = sanitize_text_field($input['day_text']);
160 $input['night_text'] = sanitize_text_field($input['night_text']);
161 $input['bottom'] = sanitize_text_field($input['bottom']);
162 return $input;
163 }
164 function bazz_menu_page() { ?>
165 <h2>Привет! Это настройки плагина Bazz CallBack Widget</h2>
166 <p>Изменяем параметры на свое усмотрение.<br></p>
167 <form method="post" action="options.php" id="bazz-settings-form">
168 <?php settings_fields('bazz_settings_group'); ?>
169 <?php $bazz_options = get_option('bazz_options'); ?>
170 <div class="option-email">
171 <label for="">Отправлять письмо на:<input type="email" name="bazz_options[email]" value="<?php echo esc_attr($bazz_options['email']); ?>" /></label>
172 </div>
173
174 <div class="option-work-time">
175 <input type="text" id="work-time-start" name="bazz_options[work_time_start]" value="<?php echo esc_attr($bazz_options['work_time_start']); ?>" />
176 <input type="text" id="work-time-end" name="bazz_options[work_time_end]" value="<?php echo esc_attr($bazz_options['work_time_end']); ?>" />
177 <label>Укажите время работы:</label>
178 <div></div>
179
180 <script>
181 jQuery(document).ready(function(){
182 min_value = parseInt(jQuery("#work-time-start").val());
183 max_value = parseInt(jQuery("#work-time-end").val());
184 jQuery(".option-work-time > div").slider({
185 min: 0,
186 max: 24,
187 values: [min_value, max_value],
188 range: true,
189 slide: function( event, ui ) {
190 jQuery(".option-work-time label > strong:eq(0)").text(ui.values[ 0 ]);
191 jQuery(".option-work-time label > strong:eq(1)").text(ui.values[ 1 ]);
192 jQuery("#work-time-start").val(ui.values[ 0 ]);
193 jQuery("#work-time-end").val(ui.values[ 1 ]);
194 }
195 });
196 });
197 </script>
198
199 <label>Рабочий день с <strong><?php echo esc_attr($bazz_options['work_time_start']); ?></strong> ч. до <strong><?php echo esc_attr($bazz_options['work_time_end']); ?></strong> ч.</label><br>
200 <em>*Часовой пояс берется из настроек WordPress</em>
201 </div>
202 <div class="option-timer">
203 <label for="">Таймер обратного отсчета будет запущен на <input type="text" name="bazz_options[time]" value="<?php echo esc_attr($bazz_options['time']); ?>" /> секунд.</label>
204 </div>
205 <div class="option-text1">
206 <label for="">Текст на круглой синей кнопке:</label>
207 <input type="text" name="bazz_options[button_text]" value="<?php echo esc_attr($bazz_options['button_text']); ?>" />
208 </div>
209 <div class="option-text2">
210 <label for="">Текст на кнопке отправки формы:</label>
211 <input type="text" name="bazz_options[send_text]" value="<?php echo esc_attr($bazz_options['send_text']); ?>" />
212 </div>
213 <div class="option-text3">
214 <label for="">Текст-результат в рабочее время (днем):</label>
215 <textarea name="bazz_options[day_text]"><?php echo($bazz_options['day_text']); ?></textarea>
216 </div>
217 <div class="option-text4">
218 <label for="">Текст-результат в НЕ рабочее время (ночью):</label>
219 <textarea name="bazz_options[night_text]"><?php echo($bazz_options['night_text']); ?></textarea>
220 </div>
221 <div class="option-bottom">
222 <label for="">Расстояние от низа окна
223 <input type="text" name="bazz_options[bottom]" value="<?php echo esc_attr($bazz_options['bottom']); ?>" /> px.</label>
224 </div>
225 <div>
226 <input type="submit" value="Со�
227 ранить" />
228 </div>
229 </form>
230 <?php }
231
232 ?>