<?php 
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;

$fb_app_id = isset($campoal_options['conikal_fb_id_field']) ? $campoal_options['conikal_fb_id_field'] : '';
$fb_login = isset($campoal_options['conikal_fb_login_field']) ? $campoal_options['conikal_fb_login_field'] : 0;
$primary_share_button = isset($campoal_options['conikal_primary_share_button_field']) ? $campoal_options['conikal_primary_share_button_field'] : 'facebook';

$post_type = get_post_type($post->ID);
if ($post_type != 'petition' && $post_type != 'give_forms') {
    $petition_id = get_post_meta($post->ID, $post_type . '_post_id', true);
} else {
    $petition_id = $post->ID;
}

// Get social meta
$social_meta = conikal_social_meta();

// Get social button data
$social_buttons = conikal_social_buttons_data($social_meta, ($fb_login && !empty($fb_app_id) ? $fb_app_id : false));

// Get primary button data
$primary_button = $social_buttons[$primary_share_button];

// Mail sharing content
$mail_sharing_subject   = conikal_user_email_sharing($social_meta->id, 'subject');
$mail_sharing_content   = conikal_user_email_sharing($social_meta->id, 'message');
$mail_sharing_custom    = conikal_user_email_sharing($social_meta->id, 'custom');
?>

<a href="<?php echo esc_attr($primary_button['onclick'] ? $primary_button['link'] : $primary_button['link']) ?>" 
    id="<?php echo esc_attr($primary_share_button . '-primary-button') . esc_attr($petition_id) ?>"
    class="ui fluid <?php echo esc_attr($primary_share_button) ?> big button primary-share-button <?php echo esc_attr(in_array($primary_share_button, array('facebook', 'messenger')) ? '' : 'share-button-counter ') ?><?php echo esc_attr($primary_button['classes']) ?>" 
    <?php if ($primary_button['onclick']) : ?>
    onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=<?php echo esc_attr($primary_button['popup']['height']) ?>,width=<?php echo esc_attr($primary_button['popup']['width']) ?>');return false;"
    <?php endif; ?>
    data-id="<?php echo esc_attr($petition_id) ?>" 
    data-social="<?php echo esc_attr($primary_share_button) ?>" 
    data-heading="<?php echo esc_attr(urlencode($social_meta->title)) ?>" 
    data-link="<?php echo esc_attr($social_meta->link) ?>" 
    <?php if ($primary_share_button == 'mail' || $primary_share_button == 'gmail') : ?>
    data-subject="<?php echo esc_attr($mail_sharing_subject) ?>" 
    data-mail="<?php echo esc_attr($mail_sharing_content) ?>" 
    data-custom="<?php echo esc_attr($mail_sharing_custom) ?>" 
    <?php endif; ?>>
        <i class="<?php echo esc_attr($primary_button['icon']) ?>"></i>
        <?php echo esc_html($primary_button['label']) ?>
</a>