<?php

/* who liked this post shortcode */
add_shortcode('fans', 'wp_superlike_shortcode_fans');
function wp_superlike_shortcode_fans($atts) {
	global $post, $wp_superlike;

	/* make sure it has likes */
	if (!$wp_superlike->post_has_likes_loggedin($post->ID))
		return;

	/* show list */
	$display = null;
	$users = $wp_superlike->users_who_liked($post->ID);
	
	/* must have users */
	if (isset($users) && is_array($users) && count($users) > 0) {
	
	$display .= '<div class="wp-superlike-fans">';
	$display .= '<h5 class="wp-superlike-fans-h5">'.__('Users who liked this','wp_superlike').'</h5>';
	$display .= '<ul class="wp-superlike-fans-list">';
			
			foreach($users as $user) {
				if ((int)$user) {
			
					$display .= '<li>';
					$display .= '<div class="wp-superlike-pic">'.get_avatar( $user, 24).'</div>';
					$display .= '<div class="wp-superlike-user">'.get_the_author_meta('display_name', $user).'</div><div class="clear"></div>';
					$display .= '</li>';
			
				}
			}
			
	$display .= '</ul>';
	$display .= '</div>';
		
	return $display;
	
	}

}


/* done */

add_shortcode('superlike', 'wp_superlike_shortcode');
add_action('init', 'wp_superlike_add_button');

	/**
	* The shortcode function
	*/
	function wp_superlike_shortcode($atts) {
		
		extract(shortcode_atts(array(
			'post_id' => null,
			'layout' => null,
			'position' => null,
			'size' => null,
			'like_text' => null,
			'format' => null,
			'count' => null
		), $atts));
		
		if ($post_id) $args['post_id'] = $post_id;
		if ($layout) $args['layout'] = $layout;
		if ($position) $args['position'] = $position;
		if ($size) $args['size'] = $size;
		if ($like_text) $args['like_text'] = $like_text;
		if ($format) $args['format'] = $format;
		if ($count) $args['count'] = $count;

		return wp_superlike( $args );

	}

	/* display the button */
	function wp_superlike_add_button() {
	   if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') )
	   {
		add_filter('mce_external_plugins', 'wp_superlike_add_plugin');
		add_filter('mce_buttons', 'wp_superlike_register_button');
	   }
	}

	/* Register button */
	function wp_superlike_register_button($buttons) {
	   array_push($buttons, 'superlike');
	   return $buttons;
	}

	/* Register plugin */
	function wp_superlike_add_plugin($plugin_array) {  
		$plugin_array['superlike'] = get_template_directory_uri() . '/includes/plugins/wp-superlike/admin/js/shortcode.js';  
		return $plugin_array;
	}

?>