bIsMobile = (bool) $bIsMobile; add_action( 'wp_footer', function () { // Setup $this->setup(); // Share buttons $this->share_btns(); // Generate $this->generate(); // Output $this->output(); } ); add_action( 'wp_print_styles', array( &$this, 'siteLoadStyles' ) ); } /** * Buttonizer setup */ private function setup() { // Timezone date_default_timezone_set( ( get_option( 'timezone_string' ) != '' ? get_option( 'timezone_string' ) : "Europe/Amsterdam" ) ); // Get options $this->aButtons = (array) get_option( 'buttonizer_buttons' ); $this->aPageSettings = (array) get_option( 'buttonizer_page_categories' ); $this->aOpeningData = (array) get_option( 'buttonizer_opening_settings' ); $this->aSettings = (array) get_option( 'buttonizer_general_settings' ); // Current page data $this->sCurrentPageId = get_the_ID(); $this->sCurrentPageUrl = urlencode( get_permalink() ); $this->sCurrentPageTitle = get_the_title(); $this->sCurrentPageDescription = str_replace( " ", "+", get_the_content( 'Read more' ) ); // Is store opened $this->bIsOpened = $this->isOpened(); } public function siteLoadStyles() { wp_enqueue_style( 'buttonizer', plugins_url( '/css/buttonizer.css?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) ); wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css' ); } // Generate private function generate() { $aButtons = ( isset( $this->aButtons['buttonorder'] ) && is_array( $this->aButtons['buttonorder'] ) ? $this->aButtons['buttonorder'] : [] ); foreach ( $aButtons as $sKey => $iId ) { if ( '-1' == $iId ) { continue; } $sButton = $this->generateB( $iId ); if ( 'continue' == $sButton ) { continue; } else { $this->sOutput = $sButton . $this->sOutput; } $this->iAmountOfButtons++; } } /** * Button generator * * @param $bNmbr * @return string */ private function generateB( $bNmbr ) { // Check if this one must be showed when the company is open: if ( isset( $this->aButtons['button_' . $bNmbr . '_show_when_opened'] ) && !$this->bIsOpened ) { return 'continue'; } // Check if this one must be showed when the company is open: if ( isset( $this->aButtons['button_' . $bNmbr . '_show_not_when_opened'] ) && $this->bIsOpened ) { return 'continue'; } // Do we need to show the button? if ( !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) { // Skipping because not showing on desktop AND phone return 'continue'; } else { // Is the button visble on mobile phones?: if ( $this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_phone'] ) ) { // Skipping because this is a mobile return 'continue'; } // Is the button visible on desktop?: if ( !$this->bIsMobile && !isset( $this->aButtons['button_' . $bNmbr . '_show_on_desktop'] ) ) { // Skipping because this is desktop and it musn't get shown here return 'continue'; } } /* * Page categories selected or not * Check on what pages the button must be shown */ $buttonShowOnPages = ( isset( $this->aButtons['button_' . $bNmbr . '_show_on_pages'] ) ? $this->aButtons['button_' . $bNmbr . '_show_on_pages'] : 'all' ); $buttonPagesData = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages] ) ? $this->aPageSettings['category_' . $buttonShowOnPages] : 'all' ); $sCategoryType = ( isset( $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] ) ? $this->aPageSettings['category_' . $buttonShowOnPages . '_type'] : 'include' ); if ( $buttonShowOnPages != 'all' && $buttonShowOnPages != -5 && $buttonPagesData != 'all' && ($sCategoryType == 'include' && !in_array( $this->sCurrentPageId, $buttonPagesData ) || $sCategoryType == 'exclude' && in_array( $this->sCurrentPageId, $buttonPagesData )) ) { return 'continue'; } /* * All button info */ $buttonText = ( isset( $this->aButtons['button_' . $bNmbr . '_text'] ) ? $this->aButtons['button_' . $bNmbr . '_text'] : 'Button ' . $bNmbr ); $buttonTitle = ( isset( $this->aButtons['button_' . $bNmbr . '_title'] ) ? $this->aButtons['button_' . $bNmbr . '_title'] : 'Button ' . $bNmbr ); $buttonIsPhone = ( isset( $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] ) ? $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] : '' ); $linkNewTab = ( isset( $this->aButtons['button_' . $bNmbr . '_url_newtab'] ) ? 'target="_blank"' : '' ); $hideLabel = ( isset( $this->aButtons['button_' . $bNmbr . '_hide_label'] ) ? $this->aButtons['button_' . $bNmbr . '_hide_label'] : '' ); $sButtonAction = ( isset( $this->aButtons['button_' . $bNmbr . '_action'] ) ? $this->aButtons['button_' . $bNmbr . '_action'] : '' ); $sButtonActionLink = ( isset( $this->aButtons['button_' . $bNmbr . '_url'] ) ? $this->aButtons['button_' . $bNmbr . '_url'] : '' ); if ( 'phone' == $sButtonAction || $buttonIsPhone ) { $sButtonActionLink = 'tel:' . str_replace( [ ' ', '+', '?', '#' ], '', $sButtonActionLink ); } else { if ( 'mail' == $sButtonAction ) { $sButtonActionLink = 'mailto:' . $sButtonActionLink; } } // Has image if ( !isset( $this->aButtons['button_' . $bNmbr . '_image'] ) || empty($this->aButtons['button_' . $bNmbr . '_image']) ) { $sButtonIcon = ''; } else { $sButtonIcon = ''; } $sButtonClasses = 'is_extra bt_' . $this->iAmountOfButtons; // Show label on hover if ( isset( $this->aButtons['button_' . $bNmbr . '_show_label_on_hover'] ) && $this->aButtons['button_' . $bNmbr . '_show_label_on_hover'] == '1' ) { $sButtonClasses .= ' show_on_hover'; } // Custom classes $sButtonClasses .= ' ' . $this->getCustomClass( $bNmbr ); // Custom colors? if ( isset( $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] ) && $this->aButtons['button_' . $bNmbr . '_using_custom_colors'] == '1' ) { $this->sButtonCss .= ' .buttonizer-button .buttonizer_' . $bNmbr . ' { background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_button'] . '; } .buttonizer-button .buttonizer_' . $bNmbr . ':hover,.buttonizer_' . $bNmbr . ':active { background-color: ' . $this->aButtons['button_' . $bNmbr . '_colors_pushed'] . '; } .buttonizer-button .buttonizer_' . $bNmbr . ' i { color: ' . $this->aButtons['button_' . $bNmbr . '_colors_icon'] . '; } '; } return '' . (( $buttonText != "" ? '
' . $buttonText . '
' : '' )) . $sButtonIcon . '
'; // Thanks, end } /** * Show on timeout * * @return float|int|string */ private function showOnTimeout() { return '0'; } /** * Show on scroll * * @return string|int */ private function showOnScroll() { return '0'; } /** * Exit intent * * @return string */ private function enableExitIntent() { return '0'; } /** * Exit intent * * @return mixed|string */ private function enableExitIntentText() { return ''; } /** * Custom class * * @param $iButtonId * @return string */ private function getCustomClass( $iButtonId ) { return ''; } /** * Is the store opened right now? * * @return bool */ private function isOpened() { $sDayOfWeek = $this->getDay( date( 'N' ) ); // Result $bTodayOpened = ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened'] : '' ); // If result == 1 => Opened if ( $bTodayOpened != "1" ) { $bIsOpened = false; } else { // Get the time right now $sCurentHour = date( "G" ); $sCurrentMinute = date( "i" ); // Get the opening and closing time from today. $hourOpening = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_opened_from'] : '10:00' ) ); $hourClosing = explode( ':', ( isset( $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] ) ? $this->aOpeningData['buttonizer_' . $sDayOfWeek . '_closing_on'] : '17:00' ) ); // Check if the company is opened/closed if ( $sCurentHour < $hourOpening[0] || $sCurentHour == $hourOpening[0] && $sCurrentMinute < $hourOpening[1] || $sCurentHour > $hourClosing[0] || $sCurentHour == $hourClosing[0] && $sCurrentMinute > $hourClosing[1] - 1 ) { $bIsOpened = false; } else { $bIsOpened = true; } } return $bIsOpened; } /** * Day-number to text * * @param $sDay * @return string */ private function getDay( $sDay ) { switch ( $sDay ) { case '1': return 'monday'; break; case '2': return 'tuesday'; break; case '3': return 'wednesday'; break; case '4': return 'thursday'; break; case '5': return 'friday'; break; case '6': return 'saturday'; break; case '7': return 'sunday'; break; default: return 'sunday'; break; } } /** * Share buttons */ private function share_btns() { if ( isset( $this->aSettings["share_facebook"] ) && '1' == $this->aSettings["share_facebook"] ) { $buttonText = ( isset( $this->aSettings['share_facebook_text'] ) && $this->aSettings['share_facebook_text'] != '' ? $this->aSettings['share_facebook_text'] : 'Share this on Facebok' ); $this->sOutput = '' . (( $buttonText != "" ? '
' . $buttonText . '
' : '' )) . '
' . $this->sOutput; $this->iAmountOfShareButtons++; } if ( isset( $this->aSettings["share_twitter"] ) && '1' == $this->aSettings["share_twitter"] ) { $buttonText = ( isset( $this->aSettings['share_twitter_text'] ) && $this->aSettings['share_twitter_text'] != '' ? $this->aSettings['share_twitter_text'] : 'Share this on Twitter' ); $this->sOutput = '' . (( $buttonText != "" ? '
' . $buttonText . '
' : '' )) . '
' . $this->sOutput; $this->iAmountOfShareButtons++; } if ( isset( $this->aSettings["share_linkedin"] ) && '1' == $this->aSettings["share_linkedin"] ) { $buttonText = ( isset( $this->aSettings['share_linkedin_text'] ) && $this->aSettings['share_linkedin_text'] != '' ? $this->aSettings['share_linkedin_text'] : 'Share this on LinkedIn' ); $this->sOutput = '' . (( $buttonText != "" ? '
' . $buttonText . '
' : '' )) . '
' . $this->sOutput; $this->iAmountOfShareButtons++; } } /** * Get the positioning of the buttons * @param string $sPositioning * @return string */ public function buttonPositioning( $sPositioning = '' ) { $sPositioning .= (( isset( $this->aSettings['buttons_placing'] ) && $this->aSettings['buttons_placing'] == 'left' ? 'left' : 'right' )) . ': ' . (( isset( $this->aSettings['position_horizontal'] ) ? $this->aSettings['position_horizontal'] : (( isset( $this->aSettings['position_right'] ) ? $this->aSettings['position_right'] : '5' )) )) . '%;'; $sPositioning .= 'bottom: ' . (( isset( $this->aSettings['position_bottom'] ) ? $this->aSettings['position_bottom'] : '5' )) . '%;'; return $sPositioning; } /** * Output of the button */ public function output() { $showAfterTimeout = $this->showOnTimeout(); $showOnScroll = $this->showOnScroll(); // Main button image or icon $sImage = ( isset( $this->aSettings['custom_icon'] ) ? $this->aSettings['custom_icon'] : '' ); if ( $sImage != '' ) { $sIcon = ''; } else { $sIcon = ( !empty($this->aSettings['icon_icon']) && $this->aSettings['icon_icon'] != '+' ? '' : '+' ); } if ( $this->iAmountOfButtons == 1 && $this->iAmountOfShareButtons == 0 ) { $output = str_replace( "is_extra bt_0", "buttonizer_head onlyone", $this->sOutput ); } else { if ( $this->iAmountOfButtons > 1 || $this->iAmountOfShareButtons > 0 ) { $output = '' . (( !empty($this->aSettings['icon_label']) ? '
' . $this->aSettings['icon_label'] . '
' : '' )) . $sIcon . '
' . $this->sOutput; } else { $output = ''; } } // Google analytics toevoegen if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != "" ) { $output .= ""; } if ( isset( $this->aSettings['buttons_animation'] ) && in_array( $this->aSettings['buttons_animation'], $this->aAnimationSettings ) ) { $sButtonAnimation = $this->aSettings['buttons_animation']; } else { $sButtonAnimation = 'default'; } if ( isset( $this->aSettings['attention_animation'] ) && in_array( $this->aSettings['attention_animation'], $this->aAttentionAnimationSettings ) ) { $sAttentionAnimation = $this->aSettings['attention_animation']; } else { $sAttentionAnimation = 'default'; } list( $sShadowColorRed, $sShadowColorGreen, $sShadowColorBlue ) = sscanf( $this->aSettings['button_unpushed'], "#%02x%02x%02x" ); echo '
' . $output . '
' ; echo ' ' ; } }