PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 1.0.6
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v1.0.6
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.6, at classes/default/main.php

361 lines 17.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 // Output string
41 private $iAmountOfButtons = 0 ;
42 private $iAmountOfShareButtons = 0 ;
43 private $sOutput = '' ;
44 // Custom button color
45 private $sButtonCss = '' ;
46 public function __construct( $bIsMobile )
47 {
48 // Set some data
49 $this->bIsMobile = (bool) $bIsMobile;
50 add_action( 'wp_footer', function () {
51 // Setup
52 $this->setup();
53 // Generate
54 $this->generate();
55 // Share buttons
56 $this->share_btns();
57 // Output
58 $this->output();
59 } );
60 add_action( 'wp_print_styles', array( &$this, 'siteLoadStyles' ) );
61 add_action( 'wp_print_scripts', array( &$this, 'siteLoadScripts' ) );
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 public function siteLoadScripts()
89 {
90 wp_enqueue_script( 'buttonizer-js', plugins_url( '/js/buttonizer.js?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) );
91 }
92
93 // Generate
94 private function generate()
95 {
96 $aButtons = ( isset( $this->aButtons['buttonorder'] ) && is_array( $this->aButtons['buttonorder'] ) ? $this->aButtons['buttonorder'] : array() );
97 foreach ( $aButtons as $sKey => $iId ) {
98 if ( '-1' == $iId ) {
99 continue;
100 }
101 $sButton = $this->generateB( $iId );
102
103 if ( 'continue' == $sButton ) {
104 continue;
105 } else {
106 $this->sOutput .= $sButton;
107 }
108
109 $this->iAmountOfButtons++;
110 }
111 }
112
113 private function generateB( $bNmbr )
114 {
115 // Check if this one must be showed when the company is open:
116 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_when_opened'] ) && !$this->bIsOpened ) {
117 return 'continue';
118 }
119 // Check if this one must be showed when the company is open:
120 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_not_when_opened'] ) && $this->bIsOpened ) {
121 return 'continue';
122 }
123 // Do we need to show the button?
124
125 if ( !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) {
126 // Skipping because not showing on desktop AND phone
127 return 'continue';
128 } else {
129 // Is the button visble on mobile phones?:
130 if ( $this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) ) {
131 // Skipping because this is a mobile
132 return 'continue';
133 }
134 // Is the button visible on desktop?:
135 if ( !$this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) {
136 // Skipping because this is desktop and it musn't get shown here
137 return 'continue';
138 }
139 }
140
141 /*
142 * Page categories selected or not
143 * Check on what pages the button must be shown
144 */
145 $buttonShowOnPages = ( isset( $this->aButtons['button_' . $bNmbr . '_show_on_pages'] ) ? $this->aButtons['button_' . $bNmbr . '_show_on_pages'] : 'all' );
146 $buttonPagesData = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages] ) ? $this->aPageSettings['category_' . $buttonShowOnPages] : 'all' );
147 $sCategoryType = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] ) ? $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] : 'include' );
148 if ( $buttonShowOnPages != 'all' && $buttonShowOnPages != -5 && $buttonPagesData != 'all' && ($sCategoryType == 'include' && !in_array( $this->sCurrentPageId, $buttonPagesData ) || $sCategoryType == 'exclude' && in_array( $this->sCurrentPageId, $buttonPagesData )) ) {
149 return 'continue';
150 }
151 /*
152 * All button info
153 */
154 $buttonText = ( isset( $this->aButtons['button_' . $bNmbr . '_text'] ) ? $this->aButtons['button_' . $bNmbr . '_text'] : 'Button ' . $bNmbr );
155 $buttonTitle = ( isset( $this->aButtons['button_' . $bNmbr . '_title'] ) ? $this->aButtons['button_' . $bNmbr . '_title'] : 'Button ' . $bNmbr );
156 $buttonIsPhone = ( isset( $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] ) ? $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] : '' );
157 $link = ( isset( $this->aButtons['button_' . $bNmbr . '_url'] ) ? $this->aButtons['button_' . $bNmbr . '_url'] : '' );
158 $linkNewTab = ( isset( $this->aButtons['button_' . $bNmbr . '_url_newtab'] ) ? 'target="_blank"' : '' );
159 $hideLabel = ( isset( $this->aButtons['button_' . $bNmbr . '_hide_label'] ) ? $this->aButtons['button_' . $bNmbr . '_hide_label'] : '' );
160
161 if ( $link != '#' && $link != '' && strpos( 'javascript:', $link ) !== false ) {
162 $linkInfo = parse_url( $link );
163 if ( !$buttonIsPhone && empty($linkInfo['scheme']) && substr( $link, 0, 1 ) != '/' ) {
164 $link = 'http://' . $link;
165 }
166 }
167
168 // Has image
169
170 if ( !isset( $this->aButtons['button_' . $bNmbr . '_image'] ) || empty($this->aButtons['button_' . $bNmbr . '_image']) ) {
171 $sButtonIcon = '<i class="fa ' . (( isset( $this->aButtons['button_' . $bNmbr . '_icon'] ) ? $this->aButtons['button_' . $bNmbr . '_icon'] : 'plus' )) . '"></i>';
172 } else {
173 $sButtonIcon = '<img src="' . $this->aButtons['button_' . $bNmbr . '_image'] . '" style="width: ' . (( count( $this->aButtons ) > 1 ? '25px' : '32px' )) . '; vertical-align: middle;" />';
174 }
175
176 $sButtonClasses = 'is_extra bt_' . $this->iAmountOfButtons;
177 // Custom colors?
178 if ( isset( $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] ) && $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] == '1' ) {
179 $this->sButtonCss .= '
180 .buttonizer-button .buttonizer_' . $bNmbr . ' {
181 background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_button'] . ';
182 }
183
184 .buttonizer-button .buttonizer_' . $bNmbr . ':hover,.buttonizer_' . $bNmbr . ':active {
185 background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_pushed'] . ';
186 }
187
188 .buttonizer-button .buttonizer_' . $bNmbr . ' i {
189 color: ' . $this->aButtons['button_' . $bNmbr . '_colors_icon'] . ';
190 } ';
191 }
192 return '<a href="' . (( $buttonIsPhone ? 'tel:' . $link : $link )) . '" class="' . $sButtonClasses . ' buttonizer_' . $bNmbr . ' ' . $linkNewTab . ' onclick="onButtonizerClickEvent(\'' . $buttonText . '\')">' . (( $buttonText != '' ? '<div class="text"' . (( $hideLabel == '1' ? 'style="display: none;"' : '' )) . '><div>' . $buttonText . '</div></div>' : '' )) . $sButtonIcon . '</a>';
193 }
194
195 // Show on timeout
196 private function showOnTimeout()
197 {
198 return '0';
199 }
200
201 // Show on scroll
202 private function showOnScroll()
203 {
204 return '0';
205 }
206
207 // Exit intent
208 private function enableExitIntent()
209 {
210 return '0';
211 }
212
213 // Exit intent
214 private function enableExitIntentText()
215 {
216 return '';
217 }
218
219 // Is the store opened right now?
220 private function isOpened()
221 {
222 $sDayOfWeek = $this->getDay( date( 'N' ) );
223 $bIsOpened = true;
224 // Result
225 $bTodayOpened = ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] : '' );
226 // If result == 1 => Opened
227
228 if ( $bTodayOpened != '1' ) {
229 $bIsOpened = false;
230 } else {
231 // Get the time right now
232 $sCurentHour = date( 'G' );
233 $sCurrentMinute = date( 'i' );
234 // Get the opening and closing time from today.
235 $hourOpening = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] : '10:00' ) );
236 $hourClosing = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] : '17:00' ) );
237 // Check if the company is opened/closed
238
239 if ( $sCurentHour < $hourOpening[0] || $sCurentHour == $hourOpening[0] && $sCurrentMinute < $hourOpening[1] || $sCurentHour > $hourClosing[0] || $sCurentHour == $hourClosing[0] && $sCurrentMinute > $hourClosing[1] - 1 ) {
240 $bIsOpened = false;
241 } else {
242 $bIsOpened = true;
243 }
244
245 }
246
247 return $bIsOpened;
248 }
249
250 // Day-number to text
251 private function getDay( $sDay )
252 {
253 switch ( $sDay ) {
254 case '1':
255 return 'monday';
256 break;
257 case '2':
258 return 'tuesday';
259 break;
260 case '3':
261 return 'wednesday';
262 break;
263 case '4':
264 return 'thursday';
265 break;
266 case '5':
267 return 'friday';
268 break;
269 case '6':
270 return 'saturday';
271 break;
272 case '7':
273 return 'monday';
274 break;
275 default:
276 return 'sunday';
277 break;
278 }
279 }
280
281 // Share buttons
282 private function share_btns()
283 {
284
285 if ( isset( $this->aSettings['share_facebook'] ) && '1' == $this->aSettings['share_facebook'] ) {
286 $buttonText = ( isset( $this->aSettings['share_facebook_text'] ) && $this->aSettings['share_facebook_text'] != '' ? $this->aSettings['share_facebook_text'] : 'Share this on Facebok' );
287 $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>';
288 $this->iAmountOfShareButtons++;
289 }
290
291
292 if ( isset( $this->aSettings['share_twitter'] ) && '1' == $this->aSettings['share_twitter'] ) {
293 $buttonText = ( isset( $this->aSettings['share_twitter_text'] ) && $this->aSettings['share_twitter_text'] != '' ? $this->aSettings['share_twitter_text'] : 'Share this on Twitter' );
294 $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>';
295 $this->iAmountOfShareButtons++;
296 }
297
298
299 if ( isset( $this->aSettings['share_linkedin'] ) && '1' == $this->aSettings['share_linkedin'] ) {
300 $buttonText = ( isset( $this->aSettings['share_linkedin_text'] ) && $this->aSettings['share_linkedin_text'] != '' ? $this->aSettings['share_linkedin_text'] : 'Share this on LinkedIn' );
301 $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>';
302 $this->iAmountOfShareButtons++;
303 }
304
305 }
306
307 // Output
308 public function output()
309 {
310 $bShowOnScroll = ( isset( $this->aSettings['show_on_scroll'] ) ? true : false );
311 $bShowOnProcent = ( isset( $this->aSettings['procent_to_scroll'] ) ? $this->aSettings['procent_to_scroll'] : '0' );
312 $sGoogleAnalyticsCode = ( isset( $this->aSettings['google_analytics'] ) ? $this->aSettings['google_analytics'] : false );
313 $showAfterTimeout = $this->showOnTimeout();
314 $showOnScroll = $this->showOnScroll();
315 // Main button image or icon
316 $sImage = ( isset( $this->aSettings['custom_icon'] ) ? $this->aSettings['custom_icon'] : '' );
317
318 if ( $sImage != '' ) {
319 $sIcon = '<img src="' . $sImage . '" style="width: 32px; vertical-align: middle;" />';
320 } else {
321 $sIcon = ( !empty($this->aSettings['icon_icon']) && $this->aSettings['icon_icon'] != '+' ? '<i class="isicon-fa fa ' . $this->aSettings['icon_icon'] . '"></i>' : '<i>+</i>' );
322 }
323
324
325 if ( $this->iAmountOfButtons == 1 && $this->iAmountOfShareButtons == 0 ) {
326 $output = str_replace( 'is_extra bt_0', 'buttonizer_head onlyone', $this->sOutput );
327 } else {
328
329 if ( $this->iAmountOfButtons > 1 || $this->iAmountOfShareButtons > 0 ) {
330 $output = '<a href="javascript:void(0)" class="buttonizer_head" onclick="onButtonizerClickEvent(\'Open/Close Buttonizer button\')">' . $sIcon . '</a>' . $this->sOutput;
331 } else {
332 $output = '';
333 }
334
335 }
336
337 // Google analytics toevoegen
338 if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != '' ) {
339 $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>';
340 }
341
342 if ( isset( $this->aSettings['buttons_animation'] ) && in_array( $this->aSettings['buttons_animation'], $this->aAnimationSettings ) ) {
343 $sButtonAnimation = $this->aSettings['buttons_animation'];
344 } else {
345 $sButtonAnimation = 'default';
346 }
347
348 list($sShadowColorRed, $sShadowColorGreen, $sShadowColorBlue) = sscanf( $this->aSettings['button_unpushed'], '#%02x%02x%02x' );
349 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>
350 <div class="buttonizer-button ' . (( $showOnScroll > 0 || $showAfterTimeout > 0 ? 'hide' : '' )) . '" button-animation="' . $sButtonAnimation . '" style=" right: ' . $this->aSettings['position_right'] . '%; bottom: ' . $this->aSettings['position_bottom'] . '%;" id="buttonizer-button"><div class="buttonizer_inner" id="buttonizer-sys">' . $output . '</div></div>
351 <script type="text/javascript">
352 buttonizer.init({
353 scrollBarTop: ' . $showOnScroll . ',
354 showAfter: ' . $showAfterTimeout . ',
355 ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntent: ' . $this->enableExitIntent() . ',' : '' )) . '
356 ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntentText: "' . $this->enableExitIntentText() . '",' : '' )) . '
357 });
358 </script>' ;
359 }
360
361 }