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 / default / main.php

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

375 lines 18.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;
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 // Custom colors?
180 if ( isset( $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] ) && $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] == '1' ) {
181 $this->sButtonCss .= '
182 .buttonizer-button .buttonizer_' . $bNmbr . ' {
183 background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_button'] . ';
184 }
185
186 .buttonizer-button .buttonizer_' . $bNmbr . ':hover,.buttonizer_' . $bNmbr . ':active {
187 background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_pushed'] . ';
188 }
189
190 .buttonizer-button .buttonizer_' . $bNmbr . ' i {
191 color: ' . $this->aButtons['button_' . $bNmbr . '_colors_icon'] . ';
192 } ';
193 }
194 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>';
195 // Thanks, end
196 }
197
198 // Show on timeout
199 private function showOnTimeout()
200 {
201 return '0';
202 }
203
204 // Show on scroll
205 private function showOnScroll()
206 {
207 return '0';
208 }
209
210 // Exit intent
211 private function enableExitIntent()
212 {
213 return '0';
214 }
215
216 // Exit intent
217 private function enableExitIntentText()
218 {
219 return '';
220 }
221
222 // Is the store opened right now?
223 private function isOpened()
224 {
225 $sDayOfWeek = $this->getDay( date( 'N' ) );
226 $bIsOpened = true;
227 // Result
228 $bTodayOpened = ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] : '' );
229 // If result == 1 => Opened
230
231 if ( $bTodayOpened != "1" ) {
232 $bIsOpened = false;
233 } else {
234 // Get the time right now
235 $sCurentHour = date( "G" );
236 $sCurrentMinute = date( "i" );
237 // Get the opening and closing time from today.
238 $hourOpening = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] : '10:00' ) );
239 $hourClosing = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] : '17:00' ) );
240 // Check if the company is opened/closed
241
242 if ( $sCurentHour < $hourOpening[0] || $sCurentHour == $hourOpening[0] && $sCurrentMinute < $hourOpening[1] || $sCurentHour > $hourClosing[0] || $sCurentHour == $hourClosing[0] && $sCurrentMinute > $hourClosing[1] - 1 ) {
243 $bIsOpened = false;
244 } else {
245 $bIsOpened = true;
246 }
247
248 }
249
250 return $bIsOpened;
251 }
252
253 // Day-number to text
254 private function getDay( $sDay )
255 {
256 switch ( $sDay ) {
257 case '1':
258 return 'monday';
259 break;
260 case '2':
261 return 'tuesday';
262 break;
263 case '3':
264 return 'wednesday';
265 break;
266 case '4':
267 return 'thursday';
268 break;
269 case '5':
270 return 'friday';
271 break;
272 case '6':
273 return 'saturday';
274 break;
275 case '7':
276 return 'monday';
277 break;
278 default:
279 return 'sunday';
280 break;
281 }
282 }
283
284 // Share buttons
285 private function share_btns()
286 {
287
288 if ( isset( $this->aSettings["share_facebook"] ) && '1' == $this->aSettings["share_facebook"] ) {
289 $buttonText = ( isset( $this->aSettings['share_facebook_text'] ) && $this->aSettings['share_facebook_text'] != '' ? $this->aSettings['share_facebook_text'] : 'Share this on Facebok' );
290 $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>';
291 $this->iAmountOfShareButtons++;
292 }
293
294
295 if ( isset( $this->aSettings["share_twitter"] ) && '1' == $this->aSettings["share_twitter"] ) {
296 $buttonText = ( isset( $this->aSettings['share_twitter_text'] ) && $this->aSettings['share_twitter_text'] != '' ? $this->aSettings['share_twitter_text'] : 'Share this on Twitter' );
297 $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>';
298 $this->iAmountOfShareButtons++;
299 }
300
301
302 if ( isset( $this->aSettings["share_linkedin"] ) && '1' == $this->aSettings["share_linkedin"] ) {
303 $buttonText = ( isset( $this->aSettings['share_linkedin_text'] ) && $this->aSettings['share_linkedin_text'] != '' ? $this->aSettings['share_linkedin_text'] : 'Share this on LinkedIn' );
304 $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>';
305 $this->iAmountOfShareButtons++;
306 }
307
308 }
309
310 // Output
311 public function output()
312 {
313 $bShowOnScroll = ( isset( $this->aSettings['show_on_scroll'] ) ? true : false );
314 $bShowOnProcent = ( isset( $this->aSettings['procent_to_scroll'] ) ? $this->aSettings['procent_to_scroll'] : '0' );
315 $sGoogleAnalyticsCode = ( isset( $this->aSettings['google_analytics'] ) ? $this->aSettings['google_analytics'] : false );
316 $showAfterTimeout = $this->showOnTimeout();
317 $showOnScroll = $this->showOnScroll();
318 // Main button image or icon
319 $sImage = ( isset( $this->aSettings['custom_icon'] ) ? $this->aSettings['custom_icon'] : '' );
320
321 if ( $sImage != '' ) {
322 $sIcon = '<img src="' . $sImage . '" style="width: 32px; vertical-align: middle;" />';
323 } else {
324 $sIcon = ( !empty($this->aSettings['icon_icon']) && $this->aSettings['icon_icon'] != '+' ? '<i class="isicon-fa fa ' . $this->aSettings['icon_icon'] . '"></i>' : '<i>+</i>' );
325 }
326
327
328 if ( $this->iAmountOfButtons == 1 && $this->iAmountOfShareButtons == 0 ) {
329 $output = str_replace( "is_extra bt_0", "buttonizer_head onlyone", $this->sOutput );
330 } else {
331
332 if ( $this->iAmountOfButtons > 1 || $this->iAmountOfShareButtons > 0 ) {
333 $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;
334 } else {
335 $output = '';
336 }
337
338 }
339
340 // Google analytics toevoegen
341 if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != "" ) {
342 $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>";
343 }
344
345 if ( isset( $this->aSettings['buttons_animation'] ) && in_array( $this->aSettings['buttons_animation'], $this->aAnimationSettings ) ) {
346 $sButtonAnimation = $this->aSettings['buttons_animation'];
347 } else {
348 $sButtonAnimation = 'default';
349 }
350
351
352 if ( isset( $this->aSettings['attention_animation'] ) && in_array( $this->aSettings['attention_animation'], $this->aAttentionAnimationSettings ) ) {
353 $sAttentionAnimation = $this->aSettings['attention_animation'];
354 } else {
355 $sAttentionAnimation = 'default';
356 }
357
358 list( $sShadowColorRed, $sShadowColorGreen, $sShadowColorBlue ) = sscanf( $this->aSettings['button_unpushed'], "#%02x%02x%02x" );
359 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>
360 <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>' ;
361 echo '
362 <script defer type="text/javascript" src="' . plugins_url( '/js/buttonizer.js?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) . '"></script>
363 <script type="text/javascript">
364 document.addEventListener(\'DOMContentLoaded\', function(){
365 buttonizer.init({
366 scrollBarTop: ' . $showOnScroll . ',
367 showAfter: ' . $showAfterTimeout . ',
368 ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntent: ' . $this->enableExitIntent() . ',' : '' )) . '
369 ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntentText: "' . $this->enableExitIntentText() . '",' : '' )) . '
370 });
371 });
372 </script>' ;
373 }
374
375 }