Exemple #1
0
/**
 * Get the like output on site
 * @param array
 * @return string
 */
function GetWtiLikePost($arg = null)
{
    global $wpdb;
    $post_id = get_the_ID();
    $wti_like_post = "";
    // Get the posts ids where we do not need to show like functionality
    $allowed_posts = explode(",", get_option('wti_like_post_allowed_posts'));
    $excluded_posts = explode(",", get_option('wti_like_post_excluded_posts'));
    $excluded_categories = get_option('wti_like_post_excluded_categories');
    $excluded_sections = get_option('wti_like_post_excluded_sections');
    if (empty($excluded_categories)) {
        $excluded_categories = array();
    }
    if (empty($excluded_sections)) {
        $excluded_sections = array();
    }
    $title_text = get_option('wti_like_post_title_text');
    $category = get_the_category();
    $excluded = false;
    // Checking for excluded section. if yes, then dont show the like/dislike option
    if (in_array('home', $excluded_sections) && is_home() || in_array('archive', $excluded_sections) && is_archive()) {
        return;
    }
    // Checking for excluded categories
    foreach ($category as $cat) {
        if (in_array($cat->cat_ID, $excluded_categories) && !in_array($post_id, $allowed_posts)) {
            $excluded = true;
        }
    }
    // If excluded category, then dont show the like/dislike option
    if ($excluded) {
        return;
    }
    // Check for title text. if empty then have the default value
    if (empty($title_text)) {
        $title_text_like = __('Like', 'wti-like-post');
        $title_text_unlike = __('Unlike', 'wti-like-post');
    } else {
        $title_text = explode('/', get_option('wti_like_post_title_text'));
        $title_text_like = $title_text[0];
        $title_text_unlike = isset($title_text[1]) ? $title_text[1] : '';
    }
    // Checking for excluded posts
    if (!in_array($post_id, $excluded_posts)) {
        // Get the nonce for security purpose and create the like and unlike urls
        $nonce = wp_create_nonce("wti_like_post_vote_nonce");
        $ajax_like_link = admin_url('admin-ajax.php?action=wti_like_post_process_vote&task=like&post_id=' . $post_id . '&nonce=' . $nonce);
        $ajax_unlike_link = admin_url('admin-ajax.php?action=wti_like_post_process_vote&task=unlike&post_id=' . $post_id . '&nonce=' . $nonce);
        $like_count = GetWtiLikeCount($post_id);
        $unlike_count = GetWtiUnlikeCount($post_id);
        $msg = GetWtiVotedMessage($post_id);
        $alignment = "left" == get_option('wti_like_post_alignment') ? 'align-left' : 'align-right';
        $show_dislike = get_option('wti_like_post_show_dislike');
        $style = get_option('wti_like_post_voting_style') == "" ? 'style1' : get_option('wti_like_post_voting_style');
        $wti_like_post .= "<div class='watch-action'>";
        $wti_like_post .= "<div class='watch-position " . $alignment . "'>";
        $wti_like_post .= "<div class='action-like'>";
        $wti_like_post .= "<a class='lbg-" . $style . " like-" . $post_id . " jlk' href='javascript:void(0)' data-task='like' data-post_id='" . $post_id . "' data-nonce='" . $nonce . "' rel='nofollow'>";
        $wti_like_post .= "<img src='" . plugins_url('images/pixel.gif', __FILE__) . "' title='" . __($title_text_like, 'wti-like-post') . "' />";
        $wti_like_post .= "<span class='lc-" . $post_id . " lc'>" . $like_count . "</span>";
        $wti_like_post .= "</a></div>";
        if ($show_dislike) {
            $wti_like_post .= "<div class='action-unlike'>";
            $wti_like_post .= "<a class='unlbg-" . $style . " unlike-" . $post_id . " jlk' href='javascript:void(0)' data-task='unlike' data-post_id='" . $post_id . "' data-nonce='" . $nonce . "' rel='nofollow'>";
            $wti_like_post .= "<img src='" . plugins_url('images/pixel.gif', __FILE__) . "' title='" . __($title_text_unlike, 'wti-like-post') . "' />";
            $wti_like_post .= "<span class='unlc-" . $post_id . " unlc'>" . $unlike_count . "</span>";
            $wti_like_post .= "</a></div> ";
        }
        $wti_like_post .= "</div> ";
        $wti_like_post .= "<div class='status-" . $post_id . " status " . $alignment . "'>" . $msg . "</div>";
        $wti_like_post .= "</div><div class='wti-clear'></div>";
    }
    if ($arg == 'put') {
        return $wti_like_post;
    } else {
        echo $wti_like_post;
    }
}
                        <script type="text/javascript">var switchTo5x=false;</script>
                        <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
                        <script type="text/javascript">stLight.options({publisher: "37243fc6-d06b-449d-bdd3-a60613856c42", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>     
                        </span>
                    </div>
                    <?php 
}
?>
                    <div class="video-toolbar-item pull-right col-md-3 video-toolbar-item-like-bar">
                        <div class="wrap-toolbar-item">
                        <?php 
$main_color_2 = ot_get_option('main_color_2') ? ot_get_option('main_color_2') : '#4141a0';
$mes = '<style type="text/css">.action-like a:after{ color:' . $main_color_2 . ' !important}</style>';
$mes_un = '<style type="text/css">.action-unlike a:after{ color:' . $main_color_2 . ' !important}</style>';
if (function_exists('GetWtiVotedMessage')) {
    $msg = GetWtiVotedMessage(get_the_ID());
}
if (!$msg) {
    echo '<style type="text/css">
                              .video-toolbar-item.like-dislike .status{display:none !important;}
							  .video-toolbar-item.like-dislike:hover .status{display:none !important;}</style>';
}
$ip = '';
if (function_exists('WtiGetRealIpAddress')) {
    $ip = WtiGetRealIpAddress();
}
$tm_vote = TmAlreadyVoted(get_the_ID(), $ip);
// get setting data
$is_logged_in = is_user_logged_in();
$login_required = get_option('wti_like_post_login_required');
if ($login_required && !$is_logged_in) {
function GetWtiLikePost($arg = null)
{
    global $wpdb;
    $post_id = get_the_ID();
    $wti_like_post = "";
    //get the posts ids where we do not need to show like functionality
    $allowed_posts = explode(",", get_option('wti_like_post_allowed_posts'));
    $excluded_posts = explode(",", get_option('wti_like_post_excluded_posts'));
    $excluded_categories = get_option('wti_like_post_excluded_categories');
    $excluded_sections = get_option('wti_like_post_excluded_sections');
    if (empty($excluded_categories)) {
        $excluded_categories = array();
    }
    if (empty($excluded_sections)) {
        $excluded_sections = array();
    }
    $title_text = get_option('wti_like_post_title_text');
    $category = get_the_category();
    $excluded = false;
    //checking for excluded section. if yes, then dont show the like/dislike option
    if (in_array('home', $excluded_sections) && is_home() || in_array('archive', $excluded_sections) && is_archive()) {
        return;
    }
    //checking for excluded categories
    foreach ($category as $cat) {
        if (in_array($cat->cat_ID, $excluded_categories) && !in_array($post_id, $allowed_posts)) {
            $excluded = true;
        }
    }
    //if excluded category, then dont show the like/dislike option
    if ($excluded) {
        return;
    }
    //check for title text. if empty then have the default value
    if (empty($title_text)) {
        $title_text_like = __('Like', 'wti-like-post');
        $title_text_unlike = __('Unlike', 'wti-like-post');
    } else {
        $title_text = explode('/', get_option('wti_like_post_title_text'));
        $title_text_like = $title_text[0];
        $title_text_unlike = $title_text[1];
    }
    //checking for excluded posts
    if (!in_array($post_id, $excluded_posts)) {
        $like_count = GetWtiLikeCount($post_id);
        $unlike_count = GetWtiUnlikeCount($post_id);
        $msg = GetWtiVotedMessage($post_id);
        $alignment = "left" == get_option('wti_like_post_alignment') ? 'left' : 'right';
        $show_dislike = get_option('wti_like_post_show_dislike');
        $style = get_option('wti_like_post_voting_style') == "" ? 'style1' : get_option('wti_like_post_voting_style');
        $wti_like_post .= "<div id='watch_action'>";
        $wti_like_post .= "<div id='watch_position' style='float:" . $alignment . "; '>";
        $wti_like_post .= "<div id='action_like' >" . "<span class='like-" . $post_id . " like'><img title='" . __($title_text_like, 'wti-like-post') . "' id='like-" . $post_id . "' rel='like' class='lbg-{$style} jlk' src='" . WP_PLUGIN_URL . "/wti-like-post/images/pixel.gif'></span>" . "<span id='lc-" . $post_id . "' class='lc'>" . $like_count . "</span>" . "</div>";
        if ($show_dislike) {
            $wti_like_post .= "<div id='action_unlike' >" . "<span class='unlike-" . $post_id . " unlike'><img title='" . __($title_text_unlike, 'wti-like-post') . "' id='unlike-" . $post_id . "' rel='unlike' class='unlbg-{$style} jlk' src='" . WP_PLUGIN_URL . "/wti-like-post/images/pixel.gif'></span>" . "<span id='unlc-" . $post_id . "' class='unlc'>" . $unlike_count . "</span>" . "</div> ";
        }
        $wti_like_post .= "</div> ";
        $wti_like_post .= "<div id='status-" . $post_id . "' class='status' style='float:" . $alignment . "; '>&nbsp;&nbsp;" . $msg . "</div>";
        $wti_like_post .= "</div><div id='clear'></div>";
    }
    if ($arg == 'put') {
        return $wti_like_post;
    } else {
        echo $wti_like_post;
    }
}