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->pageCategories = (array) get_option( 'buttonizer_page_categories' );
$this->aOpeningData = (array) get_option( 'buttonizer_opening_settings' );
$this->aSettings = (array) get_option( 'buttonizer_general_settings' );
$this->aVideo = (array) get_option( 'buttonizer_videos' );
// Current page data
$this->currentPageId = get_the_ID();
$this->currentCategoryId = get_the_category();
$this->currentBlogId = get_current_blog_id();
$this->currentPageTitle = strtolower( get_the_title() );
$this->sCurrentPageUrl = urlencode( get_permalink() );
$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'] : [] );
krsort( $aButtons );
foreach ( $aButtons as $sKey => $iId ) {
if ( '-1' == $iId ) {
continue;
}
$sButton = $this->generateB( $iId );
if ( 'continue' == $sButton ) {
continue;
} else {
$this->sOutput .= $sButton;
}
$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' );
if ( $this->checkPageCategories( $buttonShowOnPages ) ) {
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 = str_replace( '"', "'", ( isset( $this->aButtons['button_' . $bNmbr . '_url'] ) ? $this->aButtons['button_' . $bNmbr . '_url'] : '' ) );
$buttonStyle = "";
$buttonOnClick = "";
if ( 'phone' == $sButtonAction || $buttonIsPhone ) {
$sButtonActionLink = 'tel:' . str_replace( [
' ',
'+',
'?',
'#'
], '', $sButtonActionLink );
} else {
if ( 'mail' == $sButtonAction ) {
$sButtonActionLink = 'mailto:' . $sButtonActionLink;
} else {
if ( 'backtotop' == $sButtonAction ) {
$sButtonActionLink = "javascript: window.scroll({top: 0, left: 0, behavior: 'smooth' });";
} else {
if ( 'gobackpage' == $sButtonAction ) {
$sButtonActionLink = "javascript: window.history.back(); ";
} else {
if ( 'socialsharing' == $sButtonAction ) {
$socialData = ( isset( $this->aButtons['button_' . $bNmbr . '_social'] ) ? $this->aButtons['button_' . $bNmbr . '_social'] : 'twitter' );
$sButtonActionLink = "javascript:void(0)";
//Share options, action buttons
if ( 'whatsapp' == $socialData ) {
$buttonOnClick = "onButtonizerClickEvent('Whatsapp share click'); onButtonizerButtonWhatsapp()";
} else {
if ( 'mail' == $socialData ) {
$buttonOnClick = "onButtonizerClickEvent('Email share click'); onButtonizerButtonEmail()";
} else {
if ( 'linkedin' == $socialData ) {
$buttonOnClick = "onButtonizerClickEvent('Linkedin share click'); onButtonizerButtonLinkedin()";
} else {
if ( 'facebook' == $socialData ) {
$buttonOnClick = "onButtonizerClickEvent('Facebook share click'); onButtonizerButtonFacebook()";
} else {
if ( 'twitter' == $socialData ) {
$buttonOnClick = "onButtonizerClickEvent('Twitter share click'); onButtonizerButtonTwitter()";
}
}
}
}
}
}
}
}
}
}
// Has image
if ( !isset( $this->aButtons['button_' . $bNmbr . '_image'] ) || empty($this->aButtons['button_' . $bNmbr . '_image']) ) {
$sButtonIcon = '';
} else {
if ( isset( $this->aButtons['button_' . $bNmbr . '_image_background'] ) && $this->aButtons['button_' . $bNmbr . '_image_background'] == '1' ) {
$sButtonIcon = "";
$buttonStyle = "background-image: url('" . $this->aButtons['button_' . $bNmbr . '_image'] . "'); background-size: cover; background-position: center;";
} else {
$sButtonIcon = '';
}
}
$sButtonClasses = 'is_extra bt_' . $this->iAmountOfButtons;
// Show label on hover (per button)
$showOnHover = ( isset( $this->aButtons['button_' . $bNmbr . '_show_label_on_hover'] ) ? $this->aButtons['button_' . $bNmbr . '_show_label_on_hover'] : '' );
if ( $showOnHover == 'showOnHover' ) {
$sButtonClasses .= ' show_on_hover';
} else {
if ( $showOnHover == 'showOnHoverDesktop' ) {
if ( $this->bIsMobile == false ) {
$sButtonClasses .= ' show_on_hover';
}
} else {
if ( $showOnHover == 'showOnHoverMobile' ) {
if ( $this->bIsMobile == true ) {
$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 != "" ? '
';
} 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']) ? '