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

global $campoal_options;
global $post;
global $current_user;

$default_accordion = isset($campoal_options['conikal_default_accordion_sign_field']) ? $campoal_options['conikal_default_accordion_sign_field'] : 'share';
$hashtag = isset($campoal_options['conikal_social_hastag_field']) ? $campoal_options['conikal_social_hastag_field'] : '';
$share_comment_box = isset($campoal_options['conikal_share_comment_box_field']) ? $campoal_options['conikal_share_comment_box_field'] : 0;

// Does the user want tag?
$enable_tag 	    = give_is_setting_enabled( give_get_option( 'tags', 'disabled' ) );

$give_prefix 		= '_give_';

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

$petition_id        = get_post_meta($form_id, $give_prefix . 'petition_id', true);

// get petition citation status
$title              = get_the_title($form_id);
$link               = get_permalink($form_id);
$heading            = $title;
$topics             = wp_get_post_terms($form_id, 'give_forms_tag');

// check user has purchases
$user_contribute    = conikal_user_purchased_donation($form_id);

$reveal_label       = get_post_meta($form_id, '_give_reveal_label', true);

// get fundraising mode setting
$fundraising_mode   = conikal_fundraising_mode_setting($petition_id);

// check user has purchases
$user_contribute    = conikal_user_purchased_donation($form_id);

// get topics hastag
$topics_hashtag = '';
if (!empty($topics) && $enable_tag) {
    foreach ($topics as $topic) {
        $topics_hashtag .= '#' . $topic->name . ',';
    }
    $hashtag = $topics_hashtag;
}

// get supporters
$sign = get_user_meta($current_user->ID, 'petition_sign', true);
$sign = $sign != '' ? $sign : array();

// get post thumbnail
$thumbnail 			= conikal_get_petition_thumbnail($form_id, 'thumbnail', false);
$lazy_placeholder   = conikal_lazy_load_placeholder('thumbnail-square');

$give_attrs['id']           = $form_id;
$give_attrs['show_goal']    = $fundraising_mode == 1 ? false : true;

// Get share counter 
$share_counter = conikal_get_share_counter($form_id);
?>

<div class="ui form">
    <div class="field">
        <div class="ui pointing below fluid basic large label">
            <?php if ($share_comment_box) : ?>
            <textarea name="sign-comment" id="sign-comment<?php echo esc_attr($form_id) ?>" class="sign-comment<?php echo esc_attr(wp_is_mobile() ? ' ui large input' : '') ?>" rows="3" placeholder="<?php esc_attr_e('Add a personal message', 'campoal') ?>" data-id="<?php echo esc_attr($form_id) ?>"></textarea>
            <div class="ui horizontal divider">
                <i class="share alternate icon"></i>
                <span id="share-number<?php echo esc_attr($form_id) ?>">
                    <?php echo esc_html( conikal_format_number('%!,0i', $share_counter['total'], true) ) ?>
                </span>
                <?php esc_html_e('Shares', 'campoal') ?>
            </div>
            <?php endif; ?>
            <div class="ui grid">
                <div class="four wide column">
                    <img class="ui fluid rounded image lazy" data-src="<?php echo esc_url($thumbnail) ?>" src="<?php echo esc_url($lazy_placeholder) ?>" alt="<?php echo esc_attr($title) ?>">
                </div>
                <div class="twelve wide column ui form">
                <?php if (get_the_author_meta('ID') == $current_user->ID || current_user_can('editor') || current_user_can('administrator')) { ?>
                    <h3 class="heading-sharing" id="heading-sharing<?php echo esc_attr($form_id) ?>" data-id="<?php echo esc_attr($form_id) ?>"><?php echo esc_html($heading != '' ? $heading : $title) ?></h3>
                    <div class="edit-heading field display none" id="edit-heading<?php echo esc_attr($form_id) ?>" data-id="<?php echo esc_attr($form_id) ?>">
                        <textarea class="custom-heading" id="custom-heading<?php echo esc_attr($form_id) ?>" data-id="<?php echo esc_attr($form_id) ?>" rows="3"><?php echo esc_textarea($heading != '' ? $heading : $title) ?></textarea>
                    </div>
                    <?php wp_nonce_field('custom_heading_ajax_nonce', 'securityHeading', true); ?>
                <?php } else { ?>
                    <h3><?php echo esc_html($heading != '' ? $heading : $title) ?></h3>
                <?php } ?>
                </div>
            </div>
        </div>
       <!-- PRIMARY SHARE BUTTON -->
       <?php get_template_part('templates/sign-share/share-button'); ?>
    </div>
    <input type="hidden" id="hashtag<?php echo esc_attr($form_id) ?>" name="hashtag" value="<?php echo esc_attr($hashtag) ?>">
</div>

<div class="ui hidden divider"></div>
<!-- SOCIAL SHARE BUTTON -->
<?php get_template_part('templates/social-buttons'); ?>

<!-- SHORT URL -->
<?php get_template_part('templates/sign-share/short-link'); ?>