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

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