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

314 lines 15.5 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 // Output string
40 private $iAmountOfButtons = 0 ;
41 private $iAmountOfShareButtons = 0 ;
42 private $sOutput = '' ;
43 public function __construct( $bIsMobile )
44 {
45 // Set some data
46 $this->bIsMobile = (bool) $bIsMobile;
47 add_action( 'wp_footer', function () {
48 // Setup
49 $this->setup();
50 // Generate
51 $this->generate();
52 // Share buttons
53 $this->share_btns();
54 // Output
55 $this->output();
56 } );
57 add_action( 'wp_print_styles', array( &$this, 'siteLoadStyles' ) );
58 add_action( 'wp_print_scripts', array( &$this, 'siteLoadScripts' ) );
59 }
60
61 private function setup()
62 {
63 // Timezone
64 date_default_timezone_set( ( get_option( 'timezone_string' ) != '' ? get_option( 'timezone_string' ) : 'Europe/Amsterdam' ) );
65 // Get options
66 $this->aButtons = (array) get_option( 'buttonizer_buttons' );
67 $this->aPageSettings = (array) get_option( 'buttonizer_page_categories' );
68 $this->aOpeningData = (array) get_option( 'buttonizer_opening_settings' );
69 $this->aSettings = (array) get_option( 'buttonizer_general_settings' );
70 // Current page data
71 $this->sCurrentPageId = get_the_ID();
72 $this->sCurrentPageUrl = urlencode( get_permalink() );
73 $this->sCurrentPageTitle = get_the_title();
74 $this->sCurrentPageDescription = str_replace( ' ', '+', get_the_content( 'Read more' ) );
75 // Is store opened
76 $this->bIsOpened = $this->isOpened();
77 }
78
79 public function siteLoadStyles()
80 {
81 wp_enqueue_style( 'buttonizer', plugins_url( '/css/buttonizer.css?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) );
82 wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css' );
83 }
84
85 public function siteLoadScripts()
86 {
87 wp_enqueue_script( 'buttonizer-js', plugins_url( '/js/buttonizer.js?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) );
88 }
89
90 // Generate
91 private function generate()
92 {
93 $aButtons = ( isset( $this->aButtons['buttonorder'] ) && is_array( $this->aButtons['buttonorder'] ) ? $this->aButtons['buttonorder'] : array() );
94 foreach ( $aButtons as $sKey => $iId ) {
95 if ( '-1' == $iId ) {
96 continue;
97 }
98 $sButton = $this->generateB( $iId );
99
100 if ( 'continue' == $sButton ) {
101 continue;
102 } else {
103 $this->sOutput .= $sButton;
104 }
105
106 $this->iAmountOfButtons++;
107 }
108 }
109
110 private function generateB( $bNmbr )
111 {
112 // Check if this one must be showed when the company is open:
113 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_when_opened'] ) && !$this->bIsOpened ) {
114 return 'continue';
115 }
116 // Check if this one must be showed when the company is open:
117 if ( isset( $this->aButtons['button_' . $bNmbr . '_show_not_when_opened'] ) && $this->bIsOpened ) {
118 return 'continue';
119 }
120 // Do we need to show the button?
121
122 if ( !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) {
123 // Skipping because not showing on desktop AND phone
124 return 'continue';
125 } else {
126 // Is the button visble on mobile phones?:
127 if ( $this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) ) {
128 // Skipping because this is a mobile
129 return 'continue';
130 }
131 // Is the button visible on desktop?:
132 if ( !$this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) {
133 // Skipping because this is desktop and it musn't get shown here
134 return 'continue';
135 }
136 }
137
138 /*
139 * Page categories selected or not
140 * Check on what pages the button must be shown
141 */
142 $buttonShowOnPages = ( isset( $this->aButtons['button_' . $bNmbr . '_show_on_pages'] ) ? $this->aButtons['button_' . $bNmbr . '_show_on_pages'] : 'all' );
143 $buttonPagesData = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages] ) ? $this->aPageSettings['category_' . $buttonShowOnPages] : 'all' );
144 $sCategoryType = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] ) ? $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] : 'include' );
145 if ( $buttonShowOnPages != 'all' && $buttonShowOnPages != -5 && $buttonPagesData != 'all' && ($sCategoryType == 'include' && !in_array( $this->sCurrentPageId, $buttonPagesData ) || $sCategoryType == 'exclude' && in_array( $this->sCurrentPageId, $buttonPagesData )) ) {
146 return 'continue';
147 }
148 /*
149 * All button info
150 */
151 $buttonText = ( isset( $this->aButtons['button_' . $bNmbr . '_text'] ) ? $this->aButtons['button_' . $bNmbr . '_text'] : 'Button ' . $bNmbr );
152 $buttonTitle = ( isset( $this->aButtons['button_' . $bNmbr . '_title'] ) ? $this->aButtons['button_' . $bNmbr . '_title'] : 'Button ' . $bNmbr );
153 $buttonIcon = ( isset( $this->aButtons['button_' . $bNmbr . '_icon'] ) ? $this->aButtons['button_' . $bNmbr . '_icon'] : 'plus' );
154 $buttonIsPhone = ( isset( $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] ) ? $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] : '' );
155 $link = ( isset( $this->aButtons['button_' . $bNmbr . '_url'] ) ? $this->aButtons['button_' . $bNmbr . '_url'] : '' );
156 $linkNewTab = ( isset( $this->aButtons['button_' . $bNmbr . '_url_newtab'] ) ? 'target="_blank"' : '' );
157 $hideLabel = ( isset( $this->aButtons['button_' . $bNmbr . '_hide_label'] ) ? $this->aButtons['button_' . $bNmbr . '_hide_label'] : '' );
158
159 if ( $link != '#' && strpos( 'javascript:', $link ) !== false ) {
160 $linkInfo = parse_url( $link );
161 if ( !$buttonIsPhone && empty($linkInfo['scheme']) && substr( $link, 0, 1 ) != '/' ) {
162 $link = 'http://' . $link;
163 }
164 }
165
166 $sButtonClasses = 'is_extra bt_' . $this->iAmountOfButtons;
167 return '<a href="' . (( $buttonIsPhone ? 'tel:' . $link : $link )) . '" class="' . $sButtonClasses . '" ' . $linkNewTab . ' onclick="onButtonizerClickEvent(\'' . $buttonText . '\')">' . (( $buttonText != '' ? '<div class="text"' . (( $hideLabel == '1' ? 'style="display: none;"' : '' )) . '><div>' . $buttonText . '</div></div>' : '' )) . '<i class="fa ' . $buttonIcon . '"></i></a>';
168 }
169
170 // Show on timeout
171 private function showOnTimeout()
172 {
173 return '0';
174 }
175
176 // Show on scroll
177 private function showOnScroll()
178 {
179 return '0';
180 }
181
182 // Is the store opened right now?
183 private function isOpened()
184 {
185 $sDayOfWeek = $this->getDay( date( 'N' ) );
186 $bIsOpened = true;
187 // Result
188 $bTodayClosed = ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closed'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closed'] : '' );
189 // If result == 1 => Closed
190
191 if ( $bTodayClosed == '1' ) {
192 $bIsOpened = false;
193 } else {
194 // Get the time right now
195 $sCurentHour = date( 'G' );
196 $sCurrentMinute = date( 'i' );
197 // Get the opening and closing time from today.
198 $hourOpening = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] : '10:00' ) );
199 $hourClosing = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] : '17:00' ) );
200 // Check if the company is opened/closed
201
202 if ( $sCurentHour < $hourOpening[0] || $sCurentHour == $hourOpening[0] && $sCurrentMinute < $hourOpening[1] || $sCurentHour > $hourClosing[0] || $sCurentHour == $hourClosing[0] && $sCurrentMinute > $hourClosing[1] - 1 ) {
203 $bIsOpened = false;
204 } else {
205 $bIsOpened = true;
206 }
207
208 }
209
210 return $bIsOpened;
211 }
212
213 // Day-number to text
214 private function getDay( $sDay )
215 {
216 switch ( $sDay ) {
217 case '1':
218 return 'monday';
219 break;
220 case '2':
221 return 'tuesday';
222 break;
223 case '3':
224 return 'wednesday';
225 break;
226 case '4':
227 return 'thursday';
228 break;
229 case '5':
230 return 'friday';
231 break;
232 case '6':
233 return 'saturday';
234 break;
235 case '7':
236 return 'monday';
237 break;
238 default:
239 return 'sunday';
240 break;
241 }
242 }
243
244 // Share buttons
245 private function share_btns()
246 {
247
248 if ( isset( $this->aSettings['share_facebook'] ) && '1' == $this->aSettings['share_facebook'] ) {
249 $buttonText = ( isset( $this->aSettings['share_facebook_text'] ) && $this->aSettings['share_facebook_text'] != '' ? $this->aSettings['share_facebook_text'] : 'Share this on Facebok' );
250 $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>';
251 $this->iAmountOfShareButtons++;
252 }
253
254
255 if ( isset( $this->aSettings['share_twitter'] ) && '1' == $this->aSettings['share_twitter'] ) {
256 $buttonText = ( isset( $this->aSettings['share_twitter_text'] ) && $this->aSettings['share_twitter_text'] != '' ? $this->aSettings['share_twitter_text'] : 'Share this on Twitter' );
257 $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>';
258 $this->iAmountOfShareButtons++;
259 }
260
261
262 if ( isset( $this->aSettings['share_linkedin'] ) && '1' == $this->aSettings['share_linkedin'] ) {
263 $buttonText = ( isset( $this->aSettings['share_linkedin_text'] ) && $this->aSettings['share_linkedin_text'] != '' ? $this->aSettings['share_linkedin_text'] : 'Share this on LinkedIn' );
264 $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>';
265 $this->iAmountOfShareButtons++;
266 }
267
268 }
269
270 // Output
271 public function output()
272 {
273 $bShowOnScroll = ( isset( $this->aSettings['show_on_scroll'] ) ? true : false );
274 $bShowOnProcent = ( isset( $this->aSettings['procent_to_scroll'] ) ? $this->aSettings['procent_to_scroll'] : '0' );
275 $sGoogleAnalyticsCode = ( isset( $this->aSettings['google_analytics'] ) ? $this->aSettings['google_analytics'] : false );
276 $showAfterTimeout = $this->showOnTimeout();
277 $showOnScroll = $this->showOnScroll();
278 // Main button image or icon
279 $sImage = ( isset( $this->aSettings['custom_icon'] ) ? $this->aSettings['custom_icon'] : '' );
280
281 if ( $sImage != '' ) {
282 $sIcon = '<img src="' . $sImage . '" style="width: 32px; vertical-align: middle;" />';
283 } else {
284 $sIcon = ( !empty($this->aSettings['icon_icon']) && $this->aSettings['icon_icon'] != '+' ? '<i class="isicon-fa fa ' . $this->aSettings['icon_icon'] . '"></i>' : '<i>+</i>' );
285 }
286
287
288 if ( $this->iAmountOfButtons == 1 && $this->iAmountOfShareButtons == 0 ) {
289 $output = str_replace( 'is_extra bt_0', 'buttonizer_head onlyone', $this->sOutput );
290 } else {
291
292 if ( $this->iAmountOfButtons > 1 || $this->iAmountOfShareButtons > 0 ) {
293 $output = '<a href="javascript:void(0)" class="buttonizer_head" id="buttonizer-sys" onclick="onButtonizerClickEvent(\'Open/Close Buttonizer button\')">' . $sIcon . '</a>' . $this->sOutput;
294 } else {
295 $output = '';
296 }
297
298 }
299
300 // Google analytics toevoegen
301 if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != '' ) {
302 $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>';
303 }
304 echo '<div class="buttonizer-button ' . (( $showOnScroll > 0 || $showAfterTimeout > 0 ? 'hide' : '' )) . '" id="buttonizer-button"><div class="buttonizer_inner" id="buttonizer-sys">' . $output . '</div></div>
305 <script type="text/javascript">
306 buttonizer.init({
307 scrollBarTop: ' . $showOnScroll . ',
308 showAfter: ' . $showAfterTimeout . ',
309 });
310 </script>
311 <style>.buttonizer-button { right: ' . $this->aSettings['position_right'] . '%; bottom: ' . $this->aSettings['position_bottom'] . '%; } .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'] . '; }</style>' ;
312 }
313
314 }