Advertisement
Guest User

Untitled

a guest
Jan 24th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (!function_exists('it_get_reactions')) {
  2.     #html display of the reactions
  3.     function it_get_reactions($postid) {
  4.         $out = '';
  5.         $buttons = '';
  6.         $i = 0;
  7.         #get all reactions from theme options
  8.         $reactions = it_get_setting('reactions');
  9.         $reactions_style = it_get_setting('reactions_style');
  10.         $reactions_title = it_get_setting('reactions_title');      
  11.         $reactions_style = !empty($reactions_style) ? $reactions_style : 'both';   
  12.         $reactions_title = !empty($reactions_title) ? $reactions_title : __("What's your reaction?",IT_TEXTDOMAIN);
  13.         if ( isset($reactions['keys']) && $reactions['keys'] != '#' ) {
  14.            
  15.             #get excluded reactions for this post
  16.             $excluded_reactions = get_post_meta($postid, IT_META_REACTIONS, $single = true);
  17.             if(unserialize($excluded_reactions)) $excluded_reactions = unserialize($excluded_reactions);
  18.             $excluded_reactions = is_array($excluded_reactions) ? $excluded_reactions : array();
  19.            
  20.             #get total reactions for this post
  21.             $total_reactions = get_post_meta($postid, IT_META_TOTAL_REACTIONS, $single = true);
  22.             $total_reactions = !empty($total_reactions) ? $total_reactions : 0;
  23.            
  24.             $unlimitedreactions = it_get_setting('reaction_limit_disable') ? 1 : 0;
  25.            
  26.             $buttons .= '<div class="reactions-wrapper clearfix" data-postid="' . $postid . '" data-unlimitedreactions="' . $unlimitedreactions . '">';
  27.                 $buttons .= '<div class="reactions-inner">';
  28.                     $buttons .= '<div class="section-title">' . $reactions_title . '</div>';
  29.                     $reactions_keys = explode(',',$reactions['keys']);
  30.                     foreach ($reactions_keys as $rkey) {
  31.                         if ( $rkey != '#') {
  32.                             $reaction_name = ( !empty( $reactions[$rkey]['name'] ) ) ? $reactions[$rkey]['name'] : '#';
  33.                             $reaction_slug = ( !empty( $reactions[$rkey]['slug'] ) ) ? $reactions[$rkey]['slug'] : it_get_slug($reaction_name, $reaction_name);
  34.                             $reaction_icon = ( !empty( $reactions[$rkey]['icon'] ) ) ? $reactions[$rkey]['icon'] : '#';
  35.                             $reaction_preset = ( !empty( $reactions[$rkey]['preset'] ) ) ? $reactions[$rkey]['preset'] : '#';
  36.                            
  37.                             #check to see if this reaction is excluded for this post
  38.                             if(!empty($reaction_slug) && !in_array($reaction_slug,$excluded_reactions)) {
  39.                                
  40.                                 $i++;
  41.                                
  42.                                 #get current reaction number
  43.                                 $number = get_post_meta($postid, '_'.$reaction_slug, $single = true);
  44.                                 #$number = get_post_meta($postid, $reaction_slug, $single = true);
  45.                                 $number = !empty($number) ? $number : 0;
  46.                                
  47.                                 #calculate percentage
  48.                                 $percentage = $total_reactions != 0 ? round(($number / $total_reactions) * 100, 0) : 0;
  49.                                 $percentage .= '%';
  50.                                
  51.                                 #determine if this reaction was already clicked by this user
  52.                                 $ip = it_get_ip();
  53.                                 $ips = get_post_meta($postid, '_'.$reaction_slug.'_ips', $single = true);
  54.                                 #$ips = get_post_meta($postid, $reaction_slug.'_ips', $single = true);
  55.                                 $pos = strpos($ips,$ip);
  56.                                 $clickcss = ' clickable';
  57.                                 if($pos !== false && !it_get_setting('reaction_limit_disable')) {
  58.                                     $clickcss = ' selected';
  59.                                 }
  60.                                
  61.                                 #preset image or custom icon
  62.                                 if($reaction_icon=='#') {
  63.                                     $icon = '<span class="theme-icon-' . $reaction_preset . '"></span>';
  64.                                 } else {
  65.                                     $icon = '<img src="' . $reaction_icon . '" />';
  66.                                 }
  67.                                
  68.                                 #generate css reaction size class
  69.                                 $reactioncss = is_numeric(str_replace('%','',$percentage)) ? round(str_replace('%','',$percentage) / 10) : '';
  70.                                 $reactioncss = ' size' . $reactioncss;                             
  71.                                
  72.                                 #html display of button
  73.                                 $buttons .= '<div class="reaction add-active' . $clickcss. '" data-reaction="' . $reaction_slug . '">';
  74.                                     $buttons .= '<span class="theme-icon-check"></span>';                                  
  75.                                     if($reactions_style!='text') $buttons .= '<div class="reaction-icon">' . $icon . '</div>';
  76.                                     if($reactions_style!='icon') $buttons .= '<div class="reaction-text">' . $reaction_name . '</div>';
  77.                                     $buttons .= '<div class="reaction-percentage ' . $reaction_slug . $reactioncss . '">' . $percentage . '</div>';
  78.                                 $buttons .= '</div>';  
  79.                                
  80.                             }
  81.                            
  82.                         }
  83.                     }
  84.                 $buttons .= '</div>';
  85.             $buttons .= '</div>';
  86.            
  87.         }
  88.         #at least one reaction exists and is not excluded for this post
  89.         if($i > 0) $out = $buttons;
  90.         return $out;
  91.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement