PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.0.10
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.0.10
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
buttonizer-multifunctional-button / classes / admin / Buttons.php

Buttons.php in Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder 1.0.10, at classes/admin/Buttons.php

447 lines 21.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 Copyright 2017 Buttonizer
19 */
20 namespace Buttonizer\Admin;
21
22 # No script kiddies
23 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
24 class Buttons
25 {
26 private $aSavedData = array() ;
27 private $aPageCategories = array() ;
28 private $aFontAwesome = array() ;
29 private $oIconManager = array() ;
30 private $aSystemSettings = array() ;
31 public function __construct( $aFontAwesome, $oIconManager )
32 {
33 $this->aFontAwesome = $aFontAwesome;
34 $this->oIconManager = $oIconManager;
35 $this->loadData();
36 $this->loadButtons();
37 }
38
39 private function loadData()
40 {
41 $this->aSavedData = (array) get_option( 'buttonizer_buttons' );
42 $this->aPageCategories = (array) get_option( 'buttonizer_page_categories' );
43 $this->aSystemSettings = (array) get_option( 'buttonizer_general_settings' );
44 }
45
46 private function loadButtons()
47 {
48 // Get buttons
49 $aButtons = ( isset( $this->aSavedData['buttonorder'] ) && is_array( $this->aSavedData['buttonorder'] ) ? $this->aSavedData['buttonorder'] : [
50 0 => -1,
51 ] );
52 if ( $aButtons[0] != '-1' ) {
53 $aButtons[-1] = '-1';
54 }
55 echo '<ul id="button-rows">' ;
56 $iButtonCount = 0;
57 foreach ( $aButtons as $sButtonKey => $iButtonId ) {
58 $this->loadIndividialButtonRow( $sButtonKey, $iButtonId, ( isset( $bDisabled ) ? true : false ) );
59 $iButtonCount++;
60 }
61 echo '</ul>' ;
62 echo '<img src="' . plugins_url( '/assets/no-buttons.jpg', BUTTONIZER_PLUGIN_DIR ) . '" style="' . (( 0 == $iButtonCount - 1 ? 'display: block;' : 'display: none;' )) . '" class="buttonizer-no-buttons" />' ;
63 }
64
65 private function loadIndividialButtonRow( $sButtonKey, $iButtonId, $bDisabled )
66 {
67 $sButtonTitle = ( isset( $this->aSavedData['button_' . $iButtonId . '_title'] ) ? $this->aSavedData['button_' . $iButtonId . '_title'] : 'Button ' . ($iButtonId + 1) );
68 $onMobile = ( isset( $this->aSavedData['button_' . $iButtonId . '_show_on_phone'] ) ? $this->aSavedData['button_' . $iButtonId . '_show_on_phone'] : '' );
69 $onDesktop = ( isset( $this->aSavedData['button_' . $iButtonId . '_show_on_desktop'] ) ? $this->aSavedData['button_' . $iButtonId . '_show_on_desktop'] : '' );
70 ?>
71 <li>
72 <div class="button-row" id="btn_row_<?php
73 echo $iButtonId ;
74 ?>" button-id="<?php
75 echo $iButtonId ;
76 ?>" data-button-action="<?php
77 echo ( isset( $this->aSavedData['button_' . $iButtonId . '_type'] ) ? $this->aSavedData['button_' . $iButtonId . '_type'] : 'url' ) ;
78 ?>" <?php
79 if ( $iButtonId == -1 ) {
80 echo ' style="display: none"' ;
81 }
82 ?>>
83 <input type="checkbox" name="buttonizer_buttons[buttonorder][]" value="<?php
84 echo $iButtonId ;
85 ?>" checked="checked" style="display: none;" />
86
87 <div class="row-info drag-handle">
88 <div class="mover"></div>
89 <span><i class="fa <?php
90 echo $this->buttonOutputIcon( $iButtonId ) ;
91 ?> button-icon"></i> <span class="row-title"><?php
92 echo ( $iButtonId == -1 ? 'New button' : $sButtonTitle ) ;
93 ?></span> <i class="fa fa-pencil pencil-edit"></i></span>
94
95 <a href="javascript:buttonizer.removeRow(<?php
96 echo $iButtonId ;
97 ?>)" class="delete-button">Delete <i class="fa fa-trash-o"></i></a>
98
99 <a href="javascript:buttonizer.toggleMobile(<?php
100 echo $iButtonId ;
101 ?>)" class="mobiledesktop mobile-button <?php
102 echo ( $onMobile == "" ? 'selected' : '' ) ;
103 ?>"><i class="fa fa-mobile"></i></a>
104 <a href="javascript:buttonizer.toggleDesktop(<?php
105 echo $iButtonId ;
106 ?>)" class="mobiledesktop desktop-button <?php
107 echo ( $onDesktop == "" ? 'selected' : '' ) ;
108 ?>"><i class="fa fa-desktop"></i></a>
109
110 <a href="javascript:void(0)" class="is-live-button" style="<?php
111 echo ( $onMobile != "" || $onDesktop != "" ? '' : 'display: none;' ) ;
112 ?>"><i class="fa fa-circle"></i> Live</a>
113
114 <button type="submit" class="must-save-button savebutton " style="display: none;"><i class="fa fa-floppy-o"></i> Save changes</button>
115 </div>
116
117 <div class="button-data">
118 <table>
119 <tr style="display: none;">
120 <td></td>
121 <td></td>
122 </tr>
123 <tr>
124 <td width="50%">
125 <label for="button_text" class="label-top">
126 <span class="info-class"><i class="fa fa-info-circle"></i> <span>This is for internal use only.<br /><br />When using Google Analytics, this will be the title of the event when clicking this button.</span></span>
127 Button name:
128 </label>
129 <input type="text" name="buttonizer_buttons[button_<?php
130 echo $iButtonId ;
131 ?>_title]" value="<?php
132 echo $sButtonTitle ;
133 ?>" class="button_title" />
134 </td>
135 <td class="button-pdr">
136 <label for="button_icon" class="label-top">
137 <span class="info-class"><i class="fa fa-info-circle"></i> <span>This will be the icon of the button. You can choose from the build-in Font Awesome icons.<br /><br />When you want to use your own icon or image, you can click the 'or upload an image' link to use your own icon.</span></span>
138 Button icon/image:
139 </label>
140 <?php
141 echo $this->buttonGetIcon( $iButtonId ) ;
142 ?>
143 </td>
144 </tr>
145
146 <tr>
147 <td>&nbsp;</td>
148 <td></td>
149 </tr>
150
151 <tr>
152 <td>
153 <label for="button_text" class="label-top">
154 <span class="info-class"><i class="fa fa-info-circle"></i> <span>This is the label what the guest on your website will see. Something like 'Contact me!', or 'Like us on Facebook'</span></span>
155 Button label:
156 </label>
157 <?php
158 echo $this->buttonGetText( $iButtonId ) ;
159 ?>
160 </td>
161 <td>
162 <label for="button_category" class="label-top">
163 <span class="info-class"><i class="fa fa-info-circle"></i> <span>Select a page category. You can add more page rules at the 'Page categories' tab.</span></span>
164 Button page category:
165 </label>
166 <?php
167 echo $this->buttonGetShowOnPages( $iButtonId ) ;
168 ?>
169 </td>
170 </tr>
171
172 <tr>
173 <td>&nbsp;</td>
174 <td></td>
175 </tr>
176
177 <tr class="settings-row button-action">
178 <td colspan="2">
179 <i class="fa fa-globe setting-icon"></i> Button action
180 <span class="info-class"><i class="fa fa-info-circle"></i> <span>This is the click-action of your button. When you choose for a phone number, it will be a direct click-to-call action.</span></span>
181
182 <table width="100%" class="settings-row-type">
183 <tr>
184 <td width="200"><?php
185 echo $this->buttonGetType( $iButtonId ) ;
186 ?></td>
187 <td>
188 <?php
189 echo $this->buttonGetUrl( $iButtonId ) ;
190 ?>
191
192 <div class="input_error" style="display: none;"></div>
193
194 <div class="extra_info" data-button-type="phone">
195
196 </div>
197 </td>
198 </tr>
199 </table>
200 </td>
201 </tr>
202
203 <tr class="settings-row setting-new-tab">
204 <td>
205 <i class="fa fa-external-link setting-icon"></i> Open in new tab
206 </td>
207 <td><?php
208 echo $this->buttonGetNewTab( $iButtonId ) ;
209 ?><label for="button_<?php
210 echo $iButtonId ;
211 ?>_url_newtab"> Yes</label></td>
212 </tr>
213
214 <tr class="settings-row">
215 <td>
216 <i class="fa fa-paint-brush setting-icon"></i> Button colors
217 <span class="info-class"><i class="fa fa-info-circle"></i> <span>You can change the colors of this button, like the default background, the background on hover or the icon color. You can undo them too. Click the palet for changing the colors.</span></span>
218 </td>
219 <td><?php
220 echo $this->buttonColors( $iButtonId ) ;
221 ?></td>
222 </tr>
223
224 <tr>
225 <td>&nbsp;</td>
226 <td></td>
227 </tr>
228
229 <tr class="settings-row show-mobile-btn">
230 <td>
231 <i class="fa fa-mobile setting-icon"></i> Show on mobile
232 </td>
233 <td><?php
234 echo $this->buttonGetShowPhone( $iButtonId ) ;
235 ?><label for="button_<?php
236 echo $iButtonId ;
237 ?>_show_on_phone"> Yes</label></td>
238 </tr>
239
240 <tr class="settings-row show-desktop-btn">
241 <td>
242 <i class="fa fa-desktop setting-icon"></i> Show on desktop
243 </td>
244 <td><?php
245 echo $this->buttonGetShowDesktop( $iButtonId ) ;
246 ?><label for="button_<?php
247 echo $iButtonId ;
248 ?>_show_on_desktop"> Yes</label></td>
249 </tr>
250
251 <tr class="settings-row">
252 <td>
253 <i class="fa fa-tag setting-icon"></i> Hide label
254
255 <span class="info-class">
256 <i class="fa fa-info-circle"></i>
257 <span>
258 This is the label what the guest on your website will see. Something like 'Contact me!', or 'Like us on Facebook'
259 </span>
260 </span>
261 </td>
262 <td><?php
263 echo $this->buttonGetHideLabel( $iButtonId ) ;
264 ?><label for="button_<?php
265 echo $iButtonId ;
266 ?>_hide_label"> Yes</label></td>
267 </tr>
268
269 <tr>
270 <td>&nbsp;</td>
271 <td></td>
272 </tr>
273
274 <?php
275 ?>
276 <tr class="settings-row">
277 <td>
278 <i class="fa fa-clock-o setting-icon"></i> Show <b>only</b> on opening hours
279 </td>
280 <td><input type="checkbox" class="buttonizer-click-to-pro" readonly=""> <label> Yes</label> <span class="buttonizer-pro-feature">PRO</span></td> <td></td>
281 </tr>
282
283 <tr class="settings-row">
284 <td>
285 <i class="fa fa-times-circle-o setting-icon"></i> Show <b>only outside</b> opening hours
286 </td>
287 <td><input type="checkbox" class="buttonizer-click-to-pro" readonly=""> <label> Yes</label> <span class="buttonizer-pro-feature">PRO</span></td>
288 </tr>
289 <?php
290 ?>
291 </table>
292 </div>
293 </div>
294 </li>
295 <?php
296 }
297
298 /*
299 * Form functions
300 */
301 // Get the text of the button
302 function buttonGetText( $iButtonId = 0 )
303 {
304 $fieldName = 'button_' . $iButtonId . '_text';
305 $fieldValue = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : 'New button' );
306 return '<input type="text" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="' . $fieldValue . '" class="button_textfield" placeholder="Button text" />';
307 }
308
309 // Get button icon
310 function buttonGetIcon( $iButtonId = 0 )
311 {
312 return $this->oIconManager->generator( [
313 'icon' => ( isset( $this->aSavedData['button_' . $iButtonId . '_icon'] ) ? $this->aSavedData['button_' . $iButtonId . '_icon'] : '' ),
314 'icon_fieldname' => 'buttonizer_buttons[button_' . $iButtonId . '_icon]',
315 'image' => ( isset( $this->aSavedData['button_' . $iButtonId . '_image'] ) ? $this->aSavedData['button_' . $iButtonId . '_image'] : '' ),
316 'image_fieldname' => 'buttonizer_buttons[button_' . $iButtonId . '_image]',
317 'choose_type' => true,
318 ] );
319 }
320
321 // Get button icon
322 function buttonOutputIcon( $iButtonId = 0 )
323 {
324 $fieldName = 'button_' . $iButtonId . '_icon';
325 return ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : 'fa-info' );
326 }
327
328 // Only show this button on phone?
329 function buttonGetShowPhone( $iButtonId = 0 )
330 {
331 $fieldName = 'button_' . $iButtonId . '_show_on_phone';
332 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
333 return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showonphone" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />';
334 }
335
336 // buttonGetShowOnPages
337 function buttonGetShowOnPages( $iButtonId = 0 )
338 {
339 $fieldName = 'button_' . $iButtonId . '_show_on_pages';
340 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
341 $pageOrders = ( isset( $this->aPageCategories['categorieOrder'] ) ? $this->aPageCategories['categorieOrder'] : [] );
342 /*
343 * Generate <select>
344 */
345 $html = '<select name="buttonizer_buttons[' . $fieldName . ']" id="button_category"><option value="-5">Show on every page</option><option value="-4">Hide everywhere</option>';
346 foreach ( $pageOrders as $arrayKey => $pageKey ) {
347 if ( $pageKey == -1 ) {
348 continue;
349 }
350 $html .= '<option value="' . $pageKey . '"' . (( $pageKey == $is_selected ? 'selected="selected"' : '' )) . '>' . $this->aPageCategories['category_' . $pageKey . '_title'] . '</option>';
351 }
352 return $html . '</select>';
353 }
354
355 // Only show this button on desktop?
356 function buttonGetShowDesktop( $iButtonId = 0 )
357 {
358 $fieldName = 'button_' . $iButtonId . '_show_on_desktop';
359 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
360 return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showondesktop" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />';
361 }
362
363 // Only show when company is open?
364 function buttonGetShowWenOpen( $iButtonId = 0 )
365 {
366 $fieldName = 'button_' . $iButtonId . '_show_when_opened';
367 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
368 return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showwhenopened" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />';
369 }
370
371 // Only show when company is open?
372 function buttonGetShowNotWenOpen( $iButtonId = 0 )
373 {
374 $fieldName = 'button_' . $iButtonId . '_show_not_when_opened';
375 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
376 return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_showwhenopened" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />';
377 }
378
379 function buttonGetHideLabel( $iButtonId = 0 )
380 {
381 $fieldName = 'button_' . $iButtonId . '_hide_label';
382 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
383 return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_hidelabel" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />';
384 }
385
386 function buttonGetType( $iButtonId = 0 )
387 {
388 $aTypes = [
389 'url' => 'Website URL',
390 'phone' => 'Phone number',
391 'mail' => 'E-mail',
392 ];
393 $aTypes = array_merge( $aTypes, [
394 'disabled_whatsapp' => 'Open whatsapp (phone number) - PRO ONLY',
395 'disabled_javascript' => 'Javascript function - PRO ONLY',
396 ] );
397 $fieldName = 'button_' . $iButtonId . '_action';
398 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : 'url' );
399 $html = '<select name="buttonizer_buttons[' . $fieldName . ']" id="button_type" class="button_action">';
400 foreach ( $aTypes as $sType => $sTitle ) {
401 $html .= '<option value="' . str_replace( 'disabled_', '', $sType ) . '"' . (( $sType == $is_selected ? 'selected="selected"' : '' )) . ' ' . (( strpos( $sType, 'disabled_' ) !== false > 0 ? 'disabled' : '' )) . '>' . $sTitle . '</option>';
402 }
403 return $html . '</select>';
404 }
405
406 function buttonGetUrl( $iButtonId = 0 )
407 {
408 $fieldName = 'button_' . $iButtonId . '_url';
409 $fieldValue = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
410 return '<input type="text" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="' . $fieldValue . '" class="button_input" placeholder="URL/Phone number" />';
411 }
412
413 // Only show this button on phone?
414 function buttonGetNewTab( $iButtonId = 0 )
415 {
416 $fieldName = 'button_' . $iButtonId . '_url_newtab';
417 $is_selected = ( isset( $this->aSavedData[$fieldName] ) ? $this->aSavedData[$fieldName] : '' );
418 return '<input type="checkbox" name="buttonizer_buttons[' . $fieldName . ']" id="' . $fieldName . '" value="1" class="button_isnewtab" ' . (( $is_selected == '1' ? 'checked="checked"' : '' )) . ' />';
419 }
420
421 function buttonColors( $iButtonId = 0 )
422 {
423 // Default button colors
424 $sDefaultColor1 = ( isset( $this->aSystemSettings['button_unpushed'] ) ? $this->aSystemSettings['button_unpushed'] : '#48A4DC' );
425 $sDefaultColor2 = ( isset( $this->aSystemSettings['button_pushed'] ) ? $this->aSystemSettings['button_pushed'] : '#1D9BDB' );
426 $sDefaultColor3 = ( isset( $this->aSystemSettings['icon_color'] ) ? $this->aSystemSettings['icon_color'] : '#fffff' );
427 // Using custom colors?
428 $bCustomColors = ( isset( $this->aSavedData['button_' . $iButtonId . '_using_custom_colors'] ) && $this->aSavedData['button_' . $iButtonId . '_using_custom_colors'] == '1' ? true : false );
429 // Get button colors
430 $sColor1 = ( $bCustomColors && isset( $this->aSavedData['button_' . $iButtonId . '_colors_button'] ) && !empty($this->aSavedData['button_' . $iButtonId . '_colors_button']) ? $this->aSavedData['button_' . $iButtonId . '_colors_button'] : $sDefaultColor1 );
431 $sColor2 = ( $bCustomColors && isset( $this->aSavedData['button_' . $iButtonId . '_colors_pushed'] ) && !empty($this->aSavedData['button_' . $iButtonId . '_colors_pushed']) ? $this->aSavedData['button_' . $iButtonId . '_colors_pushed'] : $sDefaultColor2 );
432 $sColor3 = ( $bCustomColors && isset( $this->aSavedData['button_' . $iButtonId . '_colors_icon'] ) && !empty($this->aSavedData['button_' . $iButtonId . '_colors_icon']) ? $this->aSavedData['button_' . $iButtonId . '_colors_icon'] : $sDefaultColor3 );
433 $sColorPalet = '<div class="button-color-palet" data-btnid="' . $iButtonId . '">';
434 $sColorPalet .= '<div class="color default" style="background-color: ' . $sColor1 . ';" data-default="' . $sDefaultColor1 . '"></div>';
435 $sColorPalet .= '<div class="color pushed" style="background-color: ' . $sColor2 . ';" data-default="' . $sDefaultColor2 . '"></div>';
436 $sColorPalet .= '<div class="color icon" style="background-color: ' . $sColor3 . ';" data-default="' . $sDefaultColor3 . '"></div>';
437 $sColorPalet .= '<div class="text">' . (( $sColor1 != $sDefaultColor1 || $sColor2 != $sDefaultColor2 || $sColor3 != $sDefaultColor3 ? 'Custom colors' : 'Default colors' )) . '</div>';
438 $sColorPalet .= '<input type="hidden" name="buttonizer_buttons[button_' . $iButtonId . '_using_custom_colors]" class="custom" value="' . (( $bCustomColors ? '1' : '0' )) . '" />';
439 $sColorPalet .= '<input type="hidden" name="buttonizer_buttons[button_' . $iButtonId . '_colors_button]" class="default" value="' . $sColor1 . '" />';
440 $sColorPalet .= '<input type="hidden" name="buttonizer_buttons[button_' . $iButtonId . '_colors_pushed]" class="pushed" value="' . $sColor2 . '" />';
441 $sColorPalet .= '<input type="hidden" name="buttonizer_buttons[button_' . $iButtonId . '_colors_icon]" class="icon" value="' . $sColor3 . '" />';
442 $sColorPalet .= '</div>';
443 $sColorPalet .= '<a href="javascript:void(0)" id="reset_colors_' . $iButtonId . '" style="' . (( !$bCustomColors ? 'display: none' : '' )) . '" class="button color_default_btn">Back to default</a>';
444 return $sColorPalet;
445 }
446
447 }