Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!function_exists('it_get_reactions')) {
- #html display of the reactions
- function it_get_reactions($postid) {
- $out = '';
- $buttons = '';
- $i = 0;
- #get all reactions from theme options
- $reactions = it_get_setting('reactions');
- $reactions_style = it_get_setting('reactions_style');
- $reactions_title = it_get_setting('reactions_title');
- $reactions_style = !empty($reactions_style) ? $reactions_style : 'both';
- $reactions_title = !empty($reactions_title) ? $reactions_title : __("What's your reaction?",IT_TEXTDOMAIN);
- if ( isset($reactions['keys']) && $reactions['keys'] != '#' ) {
- #get excluded reactions for this post
- $excluded_reactions = get_post_meta($postid, IT_META_REACTIONS, $single = true);
- if(unserialize($excluded_reactions)) $excluded_reactions = unserialize($excluded_reactions);
- $excluded_reactions = is_array($excluded_reactions) ? $excluded_reactions : array();
- #get total reactions for this post
- $total_reactions = get_post_meta($postid, IT_META_TOTAL_REACTIONS, $single = true);
- $total_reactions = !empty($total_reactions) ? $total_reactions : 0;
- $unlimitedreactions = it_get_setting('reaction_limit_disable') ? 1 : 0;
- $buttons .= '<div class="reactions-wrapper clearfix" data-postid="' . $postid . '" data-unlimitedreactions="' . $unlimitedreactions . '">';
- $buttons .= '<div class="reactions-inner">';
- $buttons .= '<div class="section-title">' . $reactions_title . '</div>';
- $reactions_keys = explode(',',$reactions['keys']);
- foreach ($reactions_keys as $rkey) {
- if ( $rkey != '#') {
- $reaction_name = ( !empty( $reactions[$rkey]['name'] ) ) ? $reactions[$rkey]['name'] : '#';
- $reaction_slug = ( !empty( $reactions[$rkey]['slug'] ) ) ? $reactions[$rkey]['slug'] : it_get_slug($reaction_name, $reaction_name);
- $reaction_icon = ( !empty( $reactions[$rkey]['icon'] ) ) ? $reactions[$rkey]['icon'] : '#';
- $reaction_preset = ( !empty( $reactions[$rkey]['preset'] ) ) ? $reactions[$rkey]['preset'] : '#';
- #check to see if this reaction is excluded for this post
- if(!empty($reaction_slug) && !in_array($reaction_slug,$excluded_reactions)) {
- $i++;
- #get current reaction number
- $number = get_post_meta($postid, '_'.$reaction_slug, $single = true);
- #$number = get_post_meta($postid, $reaction_slug, $single = true);
- $number = !empty($number) ? $number : 0;
- #calculate percentage
- $percentage = $total_reactions != 0 ? round(($number / $total_reactions) * 100, 0) : 0;
- $percentage .= '%';
- #determine if this reaction was already clicked by this user
- $ip = it_get_ip();
- $ips = get_post_meta($postid, '_'.$reaction_slug.'_ips', $single = true);
- #$ips = get_post_meta($postid, $reaction_slug.'_ips', $single = true);
- $pos = strpos($ips,$ip);
- $clickcss = ' clickable';
- if($pos !== false && !it_get_setting('reaction_limit_disable')) {
- $clickcss = ' selected';
- }
- #preset image or custom icon
- if($reaction_icon=='#') {
- $icon = '<span class="theme-icon-' . $reaction_preset . '"></span>';
- } else {
- $icon = '<img src="' . $reaction_icon . '" />';
- }
- #generate css reaction size class
- $reactioncss = is_numeric(str_replace('%','',$percentage)) ? round(str_replace('%','',$percentage) / 10) : '';
- $reactioncss = ' size' . $reactioncss;
- #html display of button
- $buttons .= '<div class="reaction add-active' . $clickcss. '" data-reaction="' . $reaction_slug . '">';
- $buttons .= '<span class="theme-icon-check"></span>';
- if($reactions_style!='text') $buttons .= '<div class="reaction-icon">' . $icon . '</div>';
- if($reactions_style!='icon') $buttons .= '<div class="reaction-text">' . $reaction_name . '</div>';
- $buttons .= '<div class="reaction-percentage ' . $reaction_slug . $reactioncss . '">' . $percentage . '</div>';
- $buttons .= '</div>';
- }
- }
- }
- $buttons .= '</div>';
- $buttons .= '</div>';
- }
- #at least one reaction exists and is not excluded for this post
- if($i > 0) $out = $buttons;
- return $out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement