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 != '#' && 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 != '' ? '';
} 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 .= '';
}
echo '