<?php
/*
Plugin Name: Irontec - Achievements Widget
Plugin URI: http://www.irontec.com
Description: Añade un widget de achievements personalizado.
Version: 1.0
Author: Irontec
Author URI: http://www.irontec.com
*/
class Irontec_Achievements_Widget extends WP_Widget {
    /** constructor */
    function Irontec_Achievements_Widget() {
        parent::WP_Widget(false, $name = 'Irontec Achievements');
    }

    /** @see WP_Widget::widget */
    function widget($args, $instance) {
        global $bp, $current_user;;
        extract( $args );
        ?>       

    <?php
    // Add some CSS styling
    // You can move this to your theme's css if you hate inline styling
    echo "<style>
    .irontec-widget-padder { overflow: hidden; padding: 8px; }
    .irontec-widget-links-padder { overflow: hidden; padding: 6px 0px; }
    </style>";

    echo $args['before_widget'];

    $args['before_title'] = str_replace ('widgettitle','widgettitle achievements', $args['before_title']);
    echo $args['before_title'];
    echo '<a href="'. site_url() .'/achievements" title="'. __ ('Obtener m&aacute;s', 'buddypress') .'">';
    echo __('Hitos', 'buddypress');
    echo '</a>';
    echo $args['after_title'];

    echo '<div class="irontec-widget-links-padder">';
    /*if ($instance['display_showall'] == 1)*/
        echo '<a href="'. site_url() .'/achievements" title="'. __ ('Obtener m&aacute;s', 'buddypress') .'">';
        _e ('Obtener m&aacute;s', 'buddypress');
        echo '</a>';
    /*if ($instance['display_showall'] == 1 && $instance['display_create'] == 1)*/
        //echo '&nbsp;|&nbsp;';
    /*if ($instance['display_create'] == 1)*/
        if ( current_user_can('manage_options') ) {
            echo '&nbsp;&middot;&nbsp;';
            echo '<a id="fancybox-achievements" href="'. site_url() .'/achievements/create" title="' . __('Crear hito','buddypress') . '">';
            _e ('Crear hito','buddypress');
            echo '</a>';
        }
    echo '</div>';

    if ( dpa_has_achievements( array( 'user_id' => $current_user->ID, 'max' => 10, 'populate_extras' => false, 'search_terms' => '', 'type' => 'unlocked' ) ) ) :
        ?>
        <div class="irontec-widget-padder">
        <div class="irontec-achievements-avatar-block">
            <?php while ( dpa_achievements() ) : dpa_the_achievement(); ?>
                <div class="item-avatar">
                    <a href="<?php dpa_achievement_slug_permalink() ?>"><?php dpa_achievement_picture() ?></a>
                </div>
            <?php endwhile; ?>
        </div>
        </div>

    <?php else : ?>

        <p class="iron-widget-p" style="font-size: 10px; margin-bottom: 10px;">
            <span class="nodata">
            <?php _e ('Todav&iacute;a no has conseguido ning&uacute;n hito.', 'buddypress'); ?>
            </span>
        </p>

    <?php
    endif;

    echo $args['after_widget'];    
  }

}
add_action('widgets_init', create_function('', 'return register_widget("Irontec_Achievements_Widget");'));
/*
  function register(){
    register_sidebar_widget('Irontec Achievements Widget', array('Irontec_Achievements_Widget', 'widget'));
    register_widget_control('Irontec Achievements Widget', array('Irontec_Achievements_Widget', 'control'));
  }
*/
?>