PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.1.1
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.1.1
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 / default / main.php

main.php in Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder 1.1.1, at classes/default/main.php

387 lines 19.2 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;
21
22 # No script kiddies
23 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
24 class Button
25 {
26 // Saved settings
27 private $aButtons ;
28 private $aPageSettings ;
29 private $aSettings ;
30 private $aOpeningData ;
31 // Default settings
32 private $bIsMobile = false ;
33 private $bIsOpened = true ;
34 // Current page
35 private $sCurrentPageId = 0 ;
36 private $sCurrentPageUrl = '' ;
37 private $sCurrentPageTitle = '' ;
38 private $sCurrentPageDescription = '' ;
39 private $aAnimationSettings = array( 'default', 'circle', 'fade-left-to-right' ) ;
40 private $aAttentionAnimationSettings = array( 'none', 'hello', 'bounce' ) ;
41 // Output string
42 private $iAmountOfButtons = 0 ;
43 private $iAmountOfShareButtons = 0 ;
44 private $sOutput = '' ;
45 // Custom button color
46 private $sButtonCss = '' ;
47 public function __construct( $bIsMobile )
48 {
49 // Set some data
50 $this->bIsMobile = (bool) $bIsMobile;
51 add_action( 'wp_footer', function () {
52 // Setup
53 $this->setup();
54 // Generate
55 $this->generate();
56 // Share buttons
57 $this->share_btns();
58 // Output
59 $this->output();
60 } );
61 add_action( 'wp_print_styles', array( &$this, 'siteLoadStyles' ) );
62 }
63
64 private function setup()
65 {
66 // Timezone
67 date_default_timezone_set( ( get_option( 'timezone_string' ) != '' ? get_option( 'timezone_string' ) : "Europe/Amsterdam" ) );
68 // Get options
69 $this->aButtons = (array) get_option( 'buttonizer_buttons' );
70 $this->aPageSettings = (array) get_option( 'buttonizer_page_categories' );
71 $this->aOpeningData = (array) get_option( 'buttonizer_opening_settings' );
72 $this->aSettings = (array) get_option( 'buttonizer_general_settings' );
73 // Current page data
74 $this->sCurrentPageId = get_the_ID();
75 $this->sCurrentPageUrl = urlencode( get_permalink() );
76 $this->sCurrentPageTitle = get_the_title();
77 $this->sCurrentPageDescription = str_replace( " ", "+", get_the_content( 'Read more' ) );
78 // Is store opened
79 $this->bIsOpened = $this->isOpened();
80 }
81
82 public function siteLoadStyles()
83 {
84 wp_enqueue_style( 'buttonizer', plugins_url( '/css/buttonizer.css?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) );
85 wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css' );
86 }
87
88 // Generate
89 private function generate()
90 {
91 $aButtons = ( isset( $this->aButtons['buttonorder'] ) && is_array( $this->aButtons['buttonorder'] ) ? $this->aButtons['buttonorder'] : [] );
92 foreach ( $aButtons as $sKey => $iId ) {
93 if ( '-1' == $iId ) {
94 continue;
95 }
96 $sButton = $this->generateB( $iId );
97
98 if ( 'continue' == $sButton ) {
99 continue;
100 } else {
101 $this->sOutput .= $sButton;
102 }
103
104 $this->iAmountOfButtons++;
105 }
106 }
107
108 private function generateB( $bNmbr )
109 {
110 // Check if this one must be showed when the company is open:
111 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_when_opened'] ) && !$this->bIsOpened ) {
112 return 'continue';
113 }
114 // Check if this one must be showed when the company is open:
115 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_not_when_opened'] ) && $this->bIsOpened ) {
116 return 'continue';
117 }
118 // Do we need to show the button?
119
120 if ( !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) {
121 // Skipping because not showing on desktop AND phone
122 return 'continue';
123 } else {
124 // Is the button visble on mobile phones?:
125 if ( $this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) ) {
126 // Skipping because this is a mobile
127 return 'continue';
128 }
129 // Is the button visible on desktop?:
130 if ( !$this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) {
131 // Skipping because this is desktop and it musn't get shown here
132 return 'continue';
133 }
134 }
135
136 /*
137 * Page categories selected or not
138 * Check on what pages the button must be shown
139 */
140 $buttonShowOnPages = ( isset( $this->aButtons['button_' . $bNmbr . '_show_on_pages'] ) ? $this->aButtons['button_' . $bNmbr . '_show_on_pages'] : 'all' );
141 $buttonPagesData = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages] ) ? $this->aPageSettings['category_' . $buttonShowOnPages] : 'all' );
142 $sCategoryType = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] ) ? $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] : 'include' );
143 if ( $buttonShowOnPages != 'all' && $buttonShowOnPages != -5 && $buttonPagesData != 'all' && ($sCategoryType == 'include' && !in_array( $this->sCurrentPageId, $buttonPagesData ) || $sCategoryType == 'exclude' && in_array( $this->sCurrentPageId, $buttonPagesData )) ) {
144 return 'continue';
145 }
146 /*
147 * All button info
148 */
149 $buttonText = ( isset( $this->aButtons['button_' . $bNmbr . '_text'] ) ? $this->aButtons['button_' . $bNmbr . '_text'] : 'Button ' . $bNmbr );
150 $buttonTitle = ( isset( $this->aButtons['button_' . $bNmbr . '_title'] ) ? $this->aButtons['button_' . $bNmbr . '_title'] : 'Button ' . $bNmbr );
151 $buttonIsPhone = ( isset( $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] ) ? $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] : '' );
152 $linkNewTab = ( isset( $this->aButtons['button_' . $bNmbr . '_url_newtab'] ) ? 'target="_blank"' : '' );
153 $hideLabel = ( isset( $this->aButtons['button_' . $bNmbr . '_hide_label'] ) ? $this->aButtons['button_' . $bNmbr . '_hide_label'] : '' );
154 $sButtonAction = ( isset( $this->aButtons['button_' . $bNmbr . '_action'] ) ? $this->aButtons['button_' . $bNmbr . '_action'] : '' );
155 $sButtonActionLink = ( isset( $this->aButtons['button_' . $bNmbr . '_url'] ) ? $this->aButtons['button_' . $bNmbr . '_url'] : '' );
156
157 if ( 'phone' == $sButtonAction || $buttonIsPhone ) {
158 $sButtonActionLink = 'tel:' . str_replace( [
159 ' ',
160 '+',
161 '?',
162 '#'
163 ], '', $sButtonActionLink );
164 } else {
165 if ( 'mail' == $sButtonAction ) {
166 $sButtonActionLink = 'mailto:' . $sButtonActionLink;
167 }
168 }
169
170 // Has image
171
172 if ( !isset( $this->aButtons['button_' . $bNmbr . '_image'] ) || empty($this->aButtons['button_' . $bNmbr . '_image']) ) {
173 $sButtonIcon = '<i class="fa ' . (( isset( $this->aButtons['button_' . $bNmbr . '_icon'] ) ? $this->aButtons['button_' . $bNmbr . '_icon'] : 'plus' )) . '"></i>';
174 } else {
175 $sButtonIcon = '<img src="' . $this->aButtons['button_' . $bNmbr . '_image'] . '" style="width: ' . (( count( $this->aButtons ) > 1 ? '25px' : '32px' )) . '; vertical-align: middle;" />';
176 }
177
178 $sButtonClasses = 'is_extra bt_' . $this->iAmountOfButtons;
179 // Show label on hover
180 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_label_on_hover'] ) && $this->aButtons['button_' . $bNmbr . '_show_label_on_hover'] == '1' ) {
181 $sButtonClasses .= ' show_on_hover';
182 }
183 // Custom classes
184 $sButtonClasses .= ' ' . $this->getCustomClass( $bNmbr );
185 // Custom colors?
186 if ( isset( $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] ) && $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] == '1' ) {
187 $this->sButtonCss .= '
188 .buttonizer-button .buttonizer_' . $bNmbr . ' {
189 background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_button'] . ';
190 }
191
192 .buttonizer-button .buttonizer_' . $bNmbr . ':hover,.buttonizer_' . $bNmbr . ':active {
193 background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_pushed'] . ';
194 }
195
196 .buttonizer-button .buttonizer_' . $bNmbr . ' i {
197 color: ' . $this->aButtons['button_' . $bNmbr . '_colors_icon'] . ';
198 } ';
199 }
200 return '<a href="' . $sButtonActionLink . '" class="' . $sButtonClasses . ' buttonizer_' . $bNmbr . '" ' . $linkNewTab . ' onclick="onButtonizerClickEvent(\'' . $buttonText . '\')">' . (( $buttonText != "" ? '<div class="text"' . (( $hideLabel == '1' ? 'style="display: none;"' : '' )) . '><div>' . $buttonText . '</div></div>' : '' )) . $sButtonIcon . '</a>';
201 // Thanks, end
202 }
203
204 // Show on timeout
205 private function showOnTimeout()
206 {
207 return '0';
208 }
209
210 // Show on scroll
211 private function showOnScroll()
212 {
213 return '0';
214 }
215
216 // Exit intent
217 private function enableExitIntent()
218 {
219 return '0';
220 }
221
222 // Exit intent
223 private function enableExitIntentText()
224 {
225 return '';
226 }
227
228 // Custom class
229 private function getCustomClass( $iButtonId )
230 {
231 return '';
232 }
233
234 // Is the store opened right now?
235 private function isOpened()
236 {
237 $sDayOfWeek = $this->getDay( date( 'N' ) );
238 $bIsOpened = true;
239 // Result
240 $bTodayOpened = ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] : '' );
241 // If result == 1 => Opened
242
243 if ( $bTodayOpened != "1" ) {
244 $bIsOpened = false;
245 } else {
246 // Get the time right now
247 $sCurentHour = date( "G" );
248 $sCurrentMinute = date( "i" );
249 // Get the opening and closing time from today.
250 $hourOpening = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] : '10:00' ) );
251 $hourClosing = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] : '17:00' ) );
252 // Check if the company is opened/closed
253
254 if ( $sCurentHour < $hourOpening[0] || $sCurentHour == $hourOpening[0] && $sCurrentMinute < $hourOpening[1] || $sCurentHour > $hourClosing[0] || $sCurentHour == $hourClosing[0] && $sCurrentMinute > $hourClosing[1] - 1 ) {
255 $bIsOpened = false;
256 } else {
257 $bIsOpened = true;
258 }
259
260 }
261
262 return $bIsOpened;
263 }
264
265 // Day-number to text
266 private function getDay( $sDay )
267 {
268 switch ( $sDay ) {
269 case '1':
270 return 'monday';
271 break;
272 case '2':
273 return 'tuesday';
274 break;
275 case '3':
276 return 'wednesday';
277 break;
278 case '4':
279 return 'thursday';
280 break;
281 case '5':
282 return 'friday';
283 break;
284 case '6':
285 return 'saturday';
286 break;
287 case '7':
288 return 'sunday';
289 break;
290 default:
291 return 'sunday';
292 break;
293 }
294 }
295
296 // Share buttons
297 private function share_btns()
298 {
299
300 if ( isset( $this->aSettings["share_facebook"] ) && '1' == $this->aSettings["share_facebook"] ) {
301 $buttonText = ( isset( $this->aSettings['share_facebook_text'] ) && $this->aSettings['share_facebook_text'] != '' ? $this->aSettings['share_facebook_text'] : 'Share this on Facebok' );
302 $this->sOutput .= '<a href="javascript:void(0)" onclick="onButtonizerClickEvent(\'Facebook share click\'); onButtonizerButtonFacebook();" class="is_extra share share_' . ($this->iAmountOfShareButtons + 1) . '">' . (( $buttonText != "" ? '<div class="text"><div>' . $buttonText . '</div></div>' : '' )) . '<i class="fa fa-facebook"></i></a>';
303 $this->iAmountOfShareButtons++;
304 }
305
306
307 if ( isset( $this->aSettings["share_twitter"] ) && '1' == $this->aSettings["share_twitter"] ) {
308 $buttonText = ( isset( $this->aSettings['share_twitter_text'] ) && $this->aSettings['share_twitter_text'] != '' ? $this->aSettings['share_twitter_text'] : 'Share this on Twitter' );
309 $this->sOutput .= '<a href="javascript:void(0)" onclick="onButtonizerClickEvent(\'Twitter share click\'); onButtonizerButtonTwitter();" class="is_extra share share_' . ($this->iAmountOfShareButtons + 1) . '">' . (( $buttonText != "" ? '<div class="text"><div>' . $buttonText . '</div></div>' : '' )) . '<i class="fa fa-twitter"></i></a>';
310 $this->iAmountOfShareButtons++;
311 }
312
313
314 if ( isset( $this->aSettings["share_linkedin"] ) && '1' == $this->aSettings["share_linkedin"] ) {
315 $buttonText = ( isset( $this->aSettings['share_linkedin_text'] ) && $this->aSettings['share_linkedin_text'] != '' ? $this->aSettings['share_linkedin_text'] : 'Share this on LinkedIn' );
316 $this->sOutput .= '<a href="javascript:void(0)" onclick="onButtonizerClickEvent(\'Linkedin share click\'); onButtonizerButtonLinkedin();" class="is_extra share share_' . ($this->iAmountOfShareButtons + 1) . '">' . (( $buttonText != "" ? '<div class="text"><div>' . $buttonText . '</div></div>' : '' )) . '<i class="fa fa-linkedin"></i></a>';
317 $this->iAmountOfShareButtons++;
318 }
319
320 }
321
322 // Output
323 public function output()
324 {
325 $bShowOnScroll = ( isset( $this->aSettings['show_on_scroll'] ) ? true : false );
326 $bShowOnProcent = ( isset( $this->aSettings['procent_to_scroll'] ) ? $this->aSettings['procent_to_scroll'] : '0' );
327 $sGoogleAnalyticsCode = ( isset( $this->aSettings['google_analytics'] ) ? $this->aSettings['google_analytics'] : false );
328 $showAfterTimeout = $this->showOnTimeout();
329 $showOnScroll = $this->showOnScroll();
330 // Main button image or icon
331 $sImage = ( isset( $this->aSettings['custom_icon'] ) ? $this->aSettings['custom_icon'] : '' );
332
333 if ( $sImage != '' ) {
334 $sIcon = '<img src="' . $sImage . '" style="width: 32px; vertical-align: middle;" />';
335 } else {
336 $sIcon = ( !empty($this->aSettings['icon_icon']) && $this->aSettings['icon_icon'] != '+' ? '<i class="isicon-fa fa ' . $this->aSettings['icon_icon'] . '"></i>' : '<i>+</i>' );
337 }
338
339
340 if ( $this->iAmountOfButtons == 1 && $this->iAmountOfShareButtons == 0 ) {
341 $output = str_replace( "is_extra bt_0", "buttonizer_head onlyone", $this->sOutput );
342 } else {
343
344 if ( $this->iAmountOfButtons > 1 || $this->iAmountOfShareButtons > 0 ) {
345 $output = '<a href="javascript:void(0)" class="buttonizer_head" onclick="onButtonizerClickEvent(\'Open/Close Buttonizer button\')">' . (( !empty($this->aSettings['icon_label']) ? '<div class="text noremove"><div>' . $this->aSettings['icon_label'] . '</div></div>' : '' )) . $sIcon . '</a>' . $this->sOutput;
346 } else {
347 $output = '';
348 }
349
350 }
351
352 // Google analytics toevoegen
353 if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != "" ) {
354 $output .= "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');ga('create', '" . $this->aSettings['google_analytics'] . "', 'auto');</script>";
355 }
356
357 if ( isset( $this->aSettings['buttons_animation'] ) && in_array( $this->aSettings['buttons_animation'], $this->aAnimationSettings ) ) {
358 $sButtonAnimation = $this->aSettings['buttons_animation'];
359 } else {
360 $sButtonAnimation = 'default';
361 }
362
363
364 if ( isset( $this->aSettings['attention_animation'] ) && in_array( $this->aSettings['attention_animation'], $this->aAttentionAnimationSettings ) ) {
365 $sAttentionAnimation = $this->aSettings['attention_animation'];
366 } else {
367 $sAttentionAnimation = 'default';
368 }
369
370 list( $sShadowColorRed, $sShadowColorGreen, $sShadowColorBlue ) = sscanf( $this->aSettings['button_unpushed'], "#%02x%02x%02x" );
371 echo '<style>.buttonizer-button a:hover, .buttonizer-button a:focus{ background:' . $this->aSettings['button_pushed'] . '; } .buttonizer-button a { background:' . $this->aSettings['button_unpushed'] . '; } .buttonizer-button a i { color: ' . $this->aSettings['icon_color'] . '; } ' . $this->sButtonCss . '</style>
372 <div class="buttonizer-button ' . (( $showOnScroll > 0 || $showAfterTimeout > 0 ? 'hide' : '' )) . ' ' . (( isset( $this->aSettings['buttons_label_show_on_hover'] ) && $this->aSettings['buttons_label_show_on_hover'] == '1' ? ' show_labels_on_hover' : '' )) . '" button-animation="' . $sButtonAnimation . '" attention-animation="' . $sAttentionAnimation . '" style=" right: ' . $this->aSettings['position_right'] . '%; bottom: ' . $this->aSettings['position_bottom'] . '%;" id="buttonizer-button"><div class="buttonizer_inner" id="buttonizer-sys">' . $output . '</div></div>' ;
373 echo '
374 <script defer type="text/javascript" src="' . plugins_url( '/js/buttonizer.js?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) . '"></script>
375 <script type="text/javascript">
376 document.addEventListener(\'DOMContentLoaded\', function(){
377 buttonizer.init({
378 scrollBarTop: ' . $showOnScroll . ',
379 showAfter: ' . $showAfterTimeout . ',
380 ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntent: ' . $this->enableExitIntent() . ',' : '' )) . '
381 ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntentText: "' . $this->enableExitIntentText() . '",' : '' )) . '
382 });
383 });
384 </script>' ;
385 }
386
387 }