<?php
/**
 * Include wordpress
 */
require_once dirname(__FILE__) .'/../../../../wp-load.php';

global $wpdb;
/**
 * Prevent non authenticated users from seing this
 */
if ( !is_user_logged_in() ) exit ();

/**
 * Get help id
 */
$id   = strip_tags($_GET['id']);
$comp = strip_tags($_GET['comp']);
$act  = strip_tags($_GET['act']);

/**
 * AYUDA MODAL
 */
if (is_numeric($id) && $act!='fav') {
    
    $table_name = $wpdb->prefix . "iron_ayudamodal";
    $results    = $wpdb->get_results("SELECT * FROM ".$table_name." WHERE id = ".$id." LIMIT 1");
    
    if (sizeof ($results[0])>0) {
        if ($_COOKIE['LANG'] == 'eu') {
            if ($results[0]->content_eu != '')
                echo $results[0]->content_eu;
            else
                echo "Ez da laguntzarik aurkitu!";
        } elseif ($_COOKIE['LANG'] == 'en') {
            if ($results[0]->content_en != '')
                echo $results[0]->content_en;
            else
                echo "No help text for this item!";
        } else {
            if ($results[0]->content != '')
                echo $results[0]->content;
            else
                echo "No se ha encontrado texto de ayuda";
        }
    } else {
        _e ('No se ha encontrado el texto de ayuda.','buddypress');
    }
} elseif ($act == 'fav') {
    
    /**
     * ME GUSTA
     */
    $table_name  = $wpdb->prefix . "users";
    $table_name2 = $wpdb->prefix . "usermeta";
    $results     = $wpdb->get_results("SELECT ID FROM " . $table_name);
    
    foreach ($results as $user) {
        
        $user_act = get_user_meta($user->ID, 'bp_favorite_activities');
        
        /**
         * SI EL ID ESTA EN EL ARRAY ES QUE ESTE USUARIO LO TIENE DE FAVORITO
         */
        if (sizeof($user_act[0])>0) {
            if ( in_array ($id, $user_act[0])) {
                $usernames .= (xprofile_get_field_data( 'Nombre', $user->ID)) . ', ';
                $userurl   .= bp_core_get_username($user->ID) . ', ';
            }
        }
    }
    
    $act_count = bp_activity_get_meta( $id, 'favorite_count' );
    
    if ($act_count>0) {
        
        printf(__('This content likes to %s user (s).','buddypress'),$act_count);
        
        $url         = substr ($userurl, 0, -2);
        $arr_nameUrl = explode(", ",$url);
        
        $name     = substr ($usernames, 0, -2);
        $arr_name = explode(", ",$name);
        
        for($i=0;$i<=(count($arr_name)-1);$i++) {
            echo ' <a href="' . home_url() . '/miembros/' . $arr_nameUrl[$i] . '" style="font-weight: bold;">'. $arr_name[$i] . '</a> ';
        }
        //echo ' (<a href="'.$name.'">' . $name .'</a>)';
    } else {
        echo __ ('This content does not like anyone yet.','buddypress');
    } 
}
?>