<commit_before><?php

/**
 * @file Friends.php
 * This file is part of MOVIM.
 * 
 * @brief The Friends widget
 *
 * @author <NAME> <<EMAIL>>
 *
 * @version 1.0
 * @date 20 October 2010
 *
 * Copyright (C)2010 MOVIM project
 * 
 * See COPYING for licensing information.
 */

class Friends extends Widget
{
    
    function WidgetLoad()
    {
    	$this->addcss('friends.css');
    	$this->addjs('friends.js');
		$this->registerEvent('rosterreceived', 'onRosterReceived');
		$this->registerEvent('incomeonline', 'onIncomingOnline');
		$this->registerEvent('incomeoffline', 'onIncomingOffline');
		$this->registerEvent('incomednd', 'onIncomingDND');
		$this->registerEvent('incomeaway', 'onIncomingAway');
    }

    function onRosterReceived($roster)
    {
		$html = $this->prepareRoster($roster);
        MovimRPC::call('movim_fill', 'tinylist', MovimRPC::cdata($html));
    }
    
    function prepareRoster($roster) {
        $html = "<ul>";
    	$i = 0;
		foreach($roster["queryItemJid"] as $key => $value ) {
			if($value != "undefined") {
				if($roster["queryItemName"][$i] != NULL) {
					$html .= "<li id='".$value."' onclick='setChatUser(\"".$value."\")'>";
					$html .= "<a class='user_page' href='?q=friend&f=".$value."'></a>";
					$html .= $roster["queryItemName"][$i]." : ".$value."</li>";
				} else
					$html .= "<li id='".$value."' onclick='setChatUser(\"".$value."\")'>".$value."</li>";
			}
			$i++;
		}
		$html .= "</ul>";
		return $html;
    }
    
	function onIncomingOnline($data)
	{
		list($jid, $place) = explode("/",$data['from']);
	    MovimRPC::call('incomingOnline',
                      MovimRPC::cdata($jid));
	}
		
	function onIncomingOffline($data)
	{
		list($jid, $place) = explode("/",$data['from']);
		
	    MovimRPC::call('incomingOffline', MovimRPC::cdata($jid));
	}
	
	function onIncomingDND($data)
	{
		list($jid, $place) = explode("/",$data['from']);
		
	    MovimRPC::call('incomingDND', MovimRPC::cdata($jid));
	}
	
	function onIncomingAway($data)
	{
		list($jid, $place) = explode("/",$data['from']);
		
	    MovimRPC::call('incomingAway', MovimRPC::cdata($jid));
	}
	
	function ajaxRefreshRoster()
	{
		$user = new User();
		$xmpp = XMPPConnect::getInstance($user->getLogin());
		$xmpp->getRosterList();
	}

    function build()
    {
        ?>
        <div id="friends">
          <div class="config_button" onclick="<?php $this->callAjax('ajaxRefreshRoster');?>"></div><commit_msg>Corrected bug in widget Friends when PHP is in nazi mode (show warning and notices).<commit_after><?php

/**
 * @file Friends.php
 * This file is part of MOVIM.
 *
 * @brief The Friends widget
 *
 * @author <NAME> <<EMAIL>>
 *
 * @version 1.0
 * @date 20 October 2010
 *
 * Copyright (C)2010 MOVIM project
 *
 * See COPYING for licensing information.
 */

class Friends extends Widget
{

    function WidgetLoad()
    {
    	$this->addcss('friends.css');
    	$this->addjs('friends.js');
		$this->registerEvent('rosterreceived', 'onRosterReceived');
		$this->registerEvent('incomeonline', 'onIncomingOnline');
		$this->registerEvent('incomeoffline', 'onIncomingOffline');
		$this->registerEvent('incomednd', 'onIncomingDND');
		$this->registerEvent('incomeaway', 'onIncomingAway');
    }

    function onRosterReceived($roster)
    {
		$html = $this->prepareRoster($roster);
        MovimRPC::call('movim_fill', 'tinylist', MovimRPC::cdata($html));
    }

    function prepareRoster($roster) {
        $html = "<ul>";
    	$i = 0;

        // Is there anything in the roster?
        if(!is_array($roster) || count($roster) < 1) {
            $html .= "</ul>";
            return $html;
        }

		foreach($roster["queryItemJid"] as $key => $value ) {
			if($value != "undefined") {
				if($roster["queryItemName"][$i] != NULL) {
					$html .= "<li id='".$value."' onclick='setChatUser(\"".$value."\")'>";
					$html .= "<a class='user_page' href='?q=friend&f=".$value."'></a>";
					$html .= $roster["queryItemName"][$i]." : ".$value."</li>";
				} else
					$html .= "<li id='".$value."' onclick='setChatUser(\"".$value."\")'>".$value."</li>";
			}
			$i++;
		}
		$html .= "</ul>";
		return $html;
    }

	function onIncomingOnline($data)
	{
		list($jid, $place) = explode("/",$data['from']);
	    MovimRPC::call('incomingOnline',
                      MovimRPC::cdata($jid));
	}

	function onIncomingOffline($data)
	{
		list($jid, $place) = explode("/",$data['from']);

	    MovimRPC::call('incomingOffline', MovimRPC::cdata($jid));
	}

	function onIncomingDND($data)
	{
		list($jid, $place) = explode("/",$data['from']);

	    MovimRPC::call('incomingDND', MovimRPC::cdata($jid));
	}

	function onIncomingAway($data)
	{
		list($jid, $place) = explode("/",$data['from']);

	    MovimRPC::call('incomingAway', MovimRPC::cdata($jid));
	}

	function ajaxRefreshRoster()
	{
		$user = new User();
		$xmpp = XMPPConnect::getInstance($user->getLogin());
		$xmpp->getRosterList();
	}

    function build()
    {
        ?>
        <div id="friends">
          <div class="config_button" onclick="<?php $this->callAjax('ajaxRefreshRoster');?>"></div>
{'fraction_non_alphanumeric': 0.21716873400275644, 'fraction_numerical': 0.005316007088009451, 'mean_word_length': 3.5765765765765765, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5914249', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1786, 'n_words': 296}