# buttonizer-multifunctional-button/1.0.3/classes/default/main.php

Buttonizer – Floating Menus, Sticky Buttons, &amp; Popup Builder, version 1.0.3. 329 lines.

- Page: https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.3/code/classes/default/main.php
- Raw: https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.3/raw/classes/default/main.php
- Modified: 2017-09-01T12:26:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/buttonizer-multifunctional-button/1.0.3/code/classes/default/main.php#L10-L20`.

```php
<?php

/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Copyright 2017 Buttonizer
*/
namespace Buttonizer;

# No script kiddies
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Button
{
    // Saved settings
    private  $aButtons ;
    private  $aPageSettings ;
    private  $aSettings ;
    private  $aOpeningData ;
    // Default settings
    private  $bIsMobile = false ;
    private  $bIsOpened = true ;
    // Current page
    private  $sCurrentPageId = 0 ;
    private  $sCurrentPageUrl = '' ;
    private  $sCurrentPageTitle = '' ;
    private  $sCurrentPageDescription = '' ;
    // Output string
    private  $iAmountOfButtons = 0 ;
    private  $iAmountOfShareButtons = 0 ;
    private  $sOutput = '' ;
    public function __construct( $bIsMobile )
    {
        // Set some data
        $this->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 '<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>';
    }
    
    // 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 .= '<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>';
            $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 .= '<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>';
            $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 .= '<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>';
            $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 = '<img src="' . $sImage . '" style="width: 32px; vertical-align: middle;" />';
        } else {
            $sIcon = ( !empty($this->aSettings['icon_icon']) && $this->aSettings['icon_icon'] != '+' ? '<i class="isicon-fa fa ' . $this->aSettings['icon_icon'] . '"></i>' : '<i>+</i>' );
        }
        
        
        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 = '<a href="javascript:void(0)" class="buttonizer_head" onclick="onButtonizerClickEvent(\'Open/Close Buttonizer button\')">' . $sIcon . '</a>' . $this->sOutput;
            } else {
                $output = '';
            }
        
        }
        
        // Google analytics toevoegen
        if ( isset( $this->aSettings['google_analytics'] ) && $this->aSettings['google_analytics'] != '' ) {
            $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>';
        }
        list($sShadowColorRed, $sShadowColorGreen, $sShadowColorBlue) = sscanf( $this->aSettings['button_unpushed'], '#%02x%02x%02x' );
        echo  '<div class="buttonizer-button ' . (( $showOnScroll > 0 || $showAfterTimeout > 0 ? 'hide' : '' )) . '" id="buttonizer-button"><div class="buttonizer_inner" id="buttonizer-sys">' . $output . '</div></div>
        <script type="text/javascript">
        buttonizer.init({
            scrollBarTop: ' . $showOnScroll . ',
            showAfter: ' . $showAfterTimeout . ',
            ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntent: ' . $this->enableExitIntent() . ',' : '' )) . '
            ' . (( ButtonizerLicense()->is__premium_only() ? 'exitIntentText: "' . $this->enableExitIntentText() . '",' : '' )) . '
        });
        </script>
        <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>' ;
    }

}
```
