bIsMobile = (bool) $bIsMobile; add_action( 'wp_footer', function () { // Setup $this->setup(); // Generate $this->generate(); // Share buttons $this->share_btns(); // Output $this->output(); } ); add_action( 'wp_print_styles', array( &$this, 'siteLoadStyles' ) ); add_action( 'wp_print_scripts', array( &$this, 'siteLoadScripts' ) ); } 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' ); } public function siteLoadScripts() { wp_enqueue_script( 'buttonizer-js', plugins_url( '/js/buttonizer.js?v=' . md5( BUTTONIZER_VERSION ), BUTTONIZER_PLUGIN_DIR ) ); } // Generate private function generate() { $aButtons = ( isset( $this->aButtons['buttonorder'] ) && is_array( $this->aButtons['buttonorder'] ) ? $this->aButtons['buttonorder'] : array() ); foreach ( $aButtons as $sKey => $iId ) { if ( '-1' == $iId ) { continue; } $sButton = $this->generateB( $iId ); if ( 'continue' == $sButton ) { continue; } else { $this->sOutput .= $sButton; } $this->iAmountOfButtons++; } } 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 ); $buttonIcon = ( isset( $this->aButtons['button_' . $bNmbr . '_icon'] ) ? $this->aButtons['button_' . $bNmbr . '_icon'] : 'plus' ); $buttonIsPhone = ( isset( $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] ) ? $this->aButtons['button_' . $bNmbr . '_is_phonenumber'] : '' ); $link = ( isset( $this->aButtons['button_' . $bNmbr . '_url'] ) ? $this->aButtons['button_' . $bNmbr . '_url'] : '' ); $linkNewTab = ( isset( $this->aButtons['button_' . $bNmbr . '_url_newtab'] ) ? 'target="_blank"' : '' ); $hideLabel = ( isset( $this->aButtons['button_' . $bNmbr . '_hide_label'] ) ? $this->aButtons['button_' . $bNmbr . '_hide_label'] : '' ); if ( $link != '#' && $link != '' && strpos( 'javascript:', $link ) !== false ) { $linkInfo = parse_url( $link ); if ( !$buttonIsPhone && empty($linkInfo['scheme']) && substr( $link, 0, 1 ) != '/' ) { $link = 'http://' . $link; } } $sButtonClasses = 'is_extra bt_' . $this->iAmountOfButtons; return '' . (( $buttonText != '' ? '
' . $buttonText . '
' : '' )) . '
'; } // Show on timeout private function showOnTimeout() { return '0'; } // Show on scroll private function showOnScroll() { return '0'; } // Exit intent private function enableExitIntent() { return '0'; } // Exit intent private function enableExitIntentText() { return ''; } // Is the store opened right now? private function isOpened() { $sDayOfWeek = $this->getDay( date( 'N' ) ); $bIsOpened = true; // 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 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 'monday'; 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->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->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->iAmountOfShareButtons++; } } // Output public function output() { $bShowOnScroll = ( isset( $this->aSettings['show_on_scroll'] ) ? true : false ); $bShowOnProcent = ( isset( $this->aSettings['procent_to_scroll'] ) ? $this->aSettings['procent_to_scroll'] : '0' ); $sGoogleAnalyticsCode = ( isset( $this->aSettings['google_analytics'] ) ? $this->aSettings['google_analytics'] : false ); $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 = '' . $sIcon . '' . $this->sOutput; } else { $output = ''; } } // Google analytics toevoegen if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != '' ) { $output .= ''; } list($sShadowColorRed, $sShadowColorGreen, $sShadowColorBlue) = sscanf( $this->aSettings['button_unpushed'], '#%02x%02x%02x' ); echo '
' . $output . '
' ; } }