Changeset 151


Ignore:
Timestamp:
01/18/08 15:17:58 (16 years ago)
Author:
niltonneto
Message:

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Location:
trunk/instant_messenger
Files:
600 added
150 deleted
36 edited

Legend:

Unmodified
Added
Removed
  • trunk/instant_messenger/controller.php

    r55 r151  
    11<?php 
    2         //      Explode action from cExecuteForm function 
    3         $cExecuteFormReturn = false; 
    4    $returnMode = $_REQUEST['returnMode']; 
    5         if($_POST['_action']) { 
    6                 if($_FILES) { 
    7                         $count_files = $_POST['countFiles']; 
    8                         $array_files = array(); 
    9                         for($idx = 1; $idx <= $count_files; $idx++) { 
    10                                 if($_FILES['file_'.$idx] && !$_FILES['file_'.$idx]['error']) 
    11                                         $array_files[] = $_FILES['file_'.$idx]; 
    12                         } 
    13                         $_POST['FILES'] = $array_files; 
    14                 } 
    15                 list($app,$class,$method) = explode('.',@$_POST['_action']); 
    16                 $cExecuteFormReturn = true; 
    17         } 
    18         //      Explode action from cExecute function 
    19         else if($_GET['action']) 
    20    { 
    21       unset($_GET['returnMode']); 
    22                 list($app,$class,$method) = explode('.',@$_GET['action']); 
    23    } 
    24         // NO ACTION 
    25         else 
    26                 return $_SESSION['response'] = 'false'; 
     2if ( !$_GET['act'] ) 
     3        echo "controller - #0 : invalid action"; 
     4else 
     5{ 
     6        #$header = getallheaders(); 
     7        #if ( !$header['ThreadId'] ) 
     8        #       echo "controller - #1 : invalid thread id"; 
     9        #else 
     10        #{ 
     11                #header('ThreadId: ' . $header['ThreadId']); 
     12                header('ThreadId: ' . $_GET['act']); 
     13                list($type, $file, $complement) = explode('.', $_GET['act']); 
     14                switch ( $type ) 
     15                { 
     16                        case '$this' : 
     17                        case '$class' : 
     18                        case '$obj' : 
     19                                factory($file, $complement); 
     20                                break; 
     21                        case '$file' : 
     22                        case '$xml' : 
     23                        case '$js' : 
     24                        case '$css' : 
     25                                shop(); 
     26                                break; 
     27                        default : echo "controller - #2 : invalid type"; 
     28                } 
     29        #} 
     30} 
    2731 
    28         // Load dinamically class file. 
    29         if($app == '$this') 
    30                 $filename = 'inc/class.'.$class.'.inc.php'; 
    31         else 
    32                 $filename = '../'.$app.'/inc/class.'.$class.'.inc.php'; 
     32exit(0); 
    3333 
    34         include_once($filename); 
     34function factory($class = false, $method = false) 
     35{ 
     36        if ( !$class || !$method ) 
     37        { 
     38                echo "controller - #3 : invalid class or method"; 
     39                return false; 
     40        } 
    3541 
    36         // Create new Object  (class loaded). 
     42        # Load dinamically class file. 
     43        $filename = 'inc/class.'.$class.'.inc.php'; 
     44        if ( !file_exists($filename) ) 
     45        { 
     46                echo "controller - #4 : class not exists"; 
     47                return false; 
     48        } 
     49        require_once $filename; 
     50 
     51        # Create new Object  (class loaded). 
    3752        $obj = new $class; 
    38  
    39         // Prepare parameters for execution. 
     53        # Prepare parameters for execution. 
    4054        $params = array(); 
    4155 
    42         // If array $_POST is not null , the submit method is POST. 
    43         if($_POST) { 
    44                 $params = $_POST; 
    45         } 
    46         // If array $_POST is null , and the array $_GET > 1, the submit method is GET. 
    47         else if(count($_GET) > 1)       { 
    48                 array_shift($_GET); 
    49                 $params = $_GET; 
     56        $request_method = $_SERVER['REQUEST_METHOD']; 
     57        switch ( $request_method ) 
     58        { 
     59                case 'GET' : 
     60                        array_shift($_GET); 
     61                        $params = $_GET; 
     62                break; 
     63                case 'POST' : 
     64                        $params = $_POST; 
     65                break; 
     66                case 'HEAD' : 
     67                case 'PUT' : 
     68                default : 
     69                        echo "controller - #5 : request method not avaible"; 
     70                        return false; 
    5071        } 
    5172 
    52         $result = array(); 
    53  
    54  
    55         // if params is not empty, then class method with parameters. 
    56         if($params) 
     73        # if params is not empty, then class method with parameters. 
     74        if ( $params ) 
    5775                $result = $obj -> $method($params); 
    5876        else 
    5977                $result = $obj -> $method(); 
    6078 
    61         // Return result json string into xml object. 
    62         if(!$cExecuteFormReturn) 
    63    { 
    64       $dom = new DOMDocument;//('1.0', 'UTF-8'); 
     79        printf("%s", $result); 
     80} 
    6581 
    66       if ( $returnMode == 'JSON') 
    67       { 
    68          $root = $dom->appendChild(new DOMElement('retorno')); 
    69          encode($result, 'encode'); 
    70          $result = ( !is_object($result) && !is_array($result) ) ? $result : json_encode($result); 
    71  
    72          $root->appendChild($dom->createCDATASection($result)); 
    73       } 
    74       else 
    75                 { 
    76                         $_SESSION['phpgw_info']['instant_messenger']['debug2'] = $result; 
    77                         $dom->loadXML('<retorno>' . utf8_encode($result) . '</retorno>'); 
    78                 } 
    79  
    80       $dom->normalizeDocument(); 
    81                 $retorno = $dom->saveXML(); 
    82       header('Pragma: anytextexeptno-cache', true); 
    83       header('Content-type: text/xml, charset=UTF-8'); 
    84                 print $retorno; 
    85    } 
    86         else 
    87                 $_SESSION['response'] = $result; 
    88  
    89    function encode(&$item, $val = 'encode') 
    90    { 
    91       switch( gettype($item) ) 
    92       { 
    93          case 'object' : 
    94                      $item = get_object_vars($item); 
    95                      encode($item); 
    96          break; 
    97          case 'array' : 
    98                      array_walk_recursive($item, 'encode'); 
    99          break; 
    100          default : $item = utf8_encode($item); 
    101       } 
    102    } 
     82function shop() 
     83{ 
     84} 
    10385?> 
  • trunk/instant_messenger/inc/Jabber.abstract.php

    r64 r151  
    11<?php 
    22/* 
    3 +-------------------------------------------------------------------------+ 
    4 |                                                                         | 
    5 | @FILE:        Jabber.abstract.php                                       | 
    6 | @ABSTRACT:    Jabber                                                    | 
    7 | @EXTENDS:     Socket (Socket.class.php)                                 | 
    8 |                                                                         | 
    9 | @DATE:        Wed May,16 2007 08:18:59                                  | 
    10 | @LAST_CHANGE: Wed May,16 2007 09:03:28                                  | 
    11 |                                                                         | 
    12 | @AUTHOR:      [NUTS] Rodrigo Souza - rodsouza@celepar.pr.gov.br        | 
    13 |                                                                         | 
    14 | @BRIEF:       Abstract class for connect with any Jabber server         | 
    15 |                                                                         | 
    16 +-------------------------------------------------------------------------+ 
     3+---------------------------------------------------------------------------------+ 
     4|                                                                                 | 
     5| @FILE:        Jabber.abstract.php                                               | 
     6| @ABSTRACT:    Jabber                                                            | 
     7| @EXTENDS:     Socket (Socket.class.php)                                         | 
     8|                                                                                 | 
     9| @DATE:        Wed May,16 2007 08:18:59                                          | 
     10| @LAST_CHANGE: Wed May,16 2007 09:03:28                                          | 
     11|                                                                                 | 
     12| @AUTHOR:      [NUTS] Rodrigo Souza - rodrigosouzadossantos [at] gmail [dot] com | 
     13|                                                                                 | 
     14| @BRIEF:       Abstract class for connect with any Jabber server                 | 
     15|                                                                                 | 
     16+---------------------------------------------------------------------------------+ 
    1717*/ 
    1818 
     
    2121abstract class Jabber extends Socket 
    2222{ 
    23    const J_FILE    = '/var/log/expresso/Jabber.log'; 
    24    const J_ALL     = false; 
    25    const J_ERROR   = true; 
    26    const J_WARNING = true; 
    27    const J_NOTICE  = true; 
    28  
    29    const ALL     = 'ALL'; 
    30    const ERROR   = 'ERROR'; 
    31    const WARNING = 'WARNING'; 
    32    const NOTICE  = 'NOTICE'; 
    33  
    34    private final function _connect( $pUser = false, $pPassword = false ) 
    35    { 
    36       try 
    37       {  
    38          if ( !preg_match('/^(.+)@(.+)\/(.+):(\d+)$/',$pUser, $matches) ) 
    39             throw new Exception('[connect] #1 ' . $pUser . ' must be [USER]@[DOMAIN]/[RESOURCE]:[PORT] and [PORT] is integer. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    40  
    41          list($subject, $USER, $SERVER, $RESOURCE, $PORT) = $matches; 
    42  
    43          if ( !($socket = $this->open('tcp://' . $SERVER . ':' . $PORT, 1, 1)) ) 
    44             throw new Exception('[connect] #2 can\'t access tcp://' . $SERVER . ':' . $PORT . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    45  
    46          $this->_socket = $socket; 
    47  
    48          $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
    49          $xml .= "<stream:stream to='" . $SERVER . "' xmlns='jabber:client' "; 
    50          $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
    51  
    52          if ( $this->write($xml) === false ) 
    53             throw new Exception('[connect] #3 it isn\'t possible write in the socket ' . $socket . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    54  
    55          $this->_server = $SERVER; 
    56          $this->_username = $USER; 
    57          $this->_password = $pPassword; 
    58          $this->_resource = $RESOURCE; 
    59       } 
    60       catch(Exception $e) 
    61       { 
    62          $this->writeLog('ERROR', $e->getMessage()); 
    63          return false; 
    64       } 
    65    } 
    66  
    67    protected function connect( $pUser = false, $pPassword = false ) 
    68    {    
    69       try 
    70       { 
    71          $this->_connect($pUser, $pPassword); 
     23        const J_FILE    = 'Jabber.log'; 
     24        const J_ALL     = false; 
     25        const J_ERROR   = true; 
     26        const J_WARNING = true; 
     27        const J_NOTICE  = true; 
     28 
     29        const ALL     = 'ALL'; 
     30        const ERROR   = 'ERROR'; 
     31        const WARNING = 'WARNING'; 
     32        const NOTICE  = 'NOTICE'; 
     33 
     34        private final function _connect( $pUser = false, $pPassword = false ) 
     35        { 
     36                try 
     37                { 
     38                        if ( !preg_match('/^(.+)@(.+)\/(.+):(\d+)$/',$pUser, $matches) ) 
     39                                throw new Exception('[connect] #1 ' . $pUser . ' must be [USER]@[DOMAIN]/[RESOURCE]:[PORT] and [PORT] is integer. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     40 
     41                        list($subject, $USER, $SERVER, $RESOURCE, $PORT) = $matches; 
     42 
     43                        if ( !($socket = $this->open('tcp://' . $SERVER . ':' . $PORT, 1, 1)) ) 
     44                                throw new Exception('[connect] #2 can\'t access tcp://' . $SERVER . ':' . $PORT . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     45 
     46                        $this->_socket = $socket; 
     47 
     48                        $return = fread($socket, 4096); 
     49                        fwrite($socket, $pUser); 
     50 
     51                        $return = fread($socket, 4096); 
     52                        fwrite($socket, $pPassword); 
     53 
     54                        $return = fread($socket, 4096); 
     55                        #echo __FUNCTION__ . "<br>\n"; 
     56                        #var_dump($return); 
     57                        #exit; 
     58 
     59                        if ( $return == "new" ) 
     60                        { 
     61                                $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
     62                                $xml .= "<stream:stream to='" . $SERVER . "' xmlns='jabber:client' "; 
     63                                $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
     64 
     65                                if ( $this->write($xml) === false ) 
     66                                        throw new Exception('[connect] #4 it isn\'t possible connect in the server becase exists a client connected with same user. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     67                        } 
     68 
     69                        $this->_server = $SERVER; 
     70                        $this->_username = $USER; 
     71                        $this->_password = $pPassword; 
     72                        $this->_resource = $RESOURCE; 
     73 
     74                        #var_dump($return); 
     75                        #exit; 
     76                        return $return; 
     77                } 
     78                catch(Exception $e) 
     79                { 
     80                        $this->writeLog('ERROR', $e->getMessage()); 
     81                        return false; 
     82                } 
     83        } 
     84 
     85        protected function connect( $pUser = false, $pPassword = false ) 
     86        { 
     87                try 
     88                { 
     89                        $_connect = $this->_connect($pUser, $pPassword); 
    7290                         
    73          if ( ($xml = $this->read()) === false ) 
    74             throw new Exception('[connect] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    75           
    76          if ( preg_match('/(<starttls .*<required\/><\/starttls>)/', $xml, $matches) ) 
    77          { 
    78             if ( !$this->starttls() ) 
    79                throw new Exception('[connect] #2 it isn\'t possible start tls. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    80  
    81             # $this->writeLog('NOTICE', 'Connected TLS'); 
    82          } 
    83          else 
    84                         { 
    85             if ( !$this->_plain() ) 
    86                throw new Exception('[connect] #3 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    87                         } 
    88  
    89          return true; 
    90       } 
    91       catch(Exception $e) 
    92       { 
    93          $this->writeLog('ERROR', $e->getMessage()); 
    94          $this->_disconnect(); 
    95          return false; 
    96       } 
    97    } 
    98  
    99    protected final function _disconnect() 
    100    { 
    101       try 
    102       { 
    103          $xml = "</stream:stream>"; 
    104  
    105          if ( $this->write($xml) === false ) 
    106             throw new Exception('[disconnect] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    107  
    108          if ( ($xml = $this->read()) === false ) 
    109             throw new Exception('[disconnect] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    110       } 
    111       catch(Exception $e) 
    112       { 
    113          $this->writeLog('ERROR', $e->getMessage()); 
    114          return false; 
    115       } 
    116    } 
    117  
    118    private final function starttls() 
    119    { 
    120       try 
    121       { 
    122          $xml = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"; 
    123          if ( $this->write($xml) === false ) 
    124             throw new Exception('[starttls] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    125  
    126          if ( ($xml = $this->read()) === false ) 
    127             throw new Exception('[starttls] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    128  
    129          if ( !preg_match('/<proceed.*\/>/', $xml, $matches) ) 
    130             throw new Exception('[starttls] #3 can\'t start tls in the socket ' .$this->_socket . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    131  
    132                    stream_socket_enable_crypto($this->_socket, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); 
    133  
    134          $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
    135          $xml .= "<stream:stream to='" . $this->_server . "' xmlns='jabber:client' "; 
    136          $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
    137          if ( $this->write($xml) === false ) 
    138             throw new Exception('[starttls] #4 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    139  
    140          usleep(90000); 
    141          $this->blocking($this->_socket, 0); 
    142  
    143          if ( ($xml = $this->read()) === false ) 
    144             throw new Exception('[starttls] #5 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    145  
    146          if ( !$this->_plain() ) 
    147             throw new Exception('[starttls] #6 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    148  
    149          return true; 
    150       } 
    151       catch(Exception $e) 
    152       { 
    153          $this->writeLog('ERROR', $e->getMessage()); 
    154          return false; 
    155       } 
    156    } 
    157  
    158    private final function _plain() 
    159    { 
    160       try 
    161       { 
    162          $this->blocking($this->_socket, 0); 
    163  
    164          if ( ($xml = $this->read()) === false ) 
    165             throw new Exception('[_plain] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    166  
    167          $xml  = "<username>" . $this->_username . "</username>"; 
    168          $xml .= "<password>" . $this->_password . "</password>"; 
    169          $xml .= "<resource>" . $this->_resource . "</resource>"; 
    170  
    171          unset($this->_password); 
    172  
    173          if ( !$this->iq('set', 'auth_1', NULL, NULL, "jabber:iq:auth", $xml) ) 
    174             throw new Exception('[_plain] #2 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    175  
    176          while ( !preg_match("/<iq xmlns='jabber:client' id='auth_1' type='(result|error)'/", ($readSocket = $this->read()), $matches) ) 
    177                    usleep(10000); 
     91                        if ( !$_connect ) 
     92                                throw new Exception('[connect] #0. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     93 
     94                        if ( $_connect == "new" ) 
     95                        { 
     96                                if ( ($xml = $this->read()) === false ) 
     97                                        throw new Exception('[connect] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     98 
     99                                if ( preg_match('/(<starttls .*<required\/><\/starttls>)/', $xml, $matches) ) 
     100                                { 
     101                                        if ( !$this->starttls() ) 
     102                                                throw new Exception('[connect] #2 it isn\'t possible start tls. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     103 
     104                                        # $this->writeLog('NOTICE', 'Connected TLS'); 
     105                                } 
     106                                else 
     107                                { 
     108                                        if ( !$this->_plain() ) 
     109                                                throw new Exception('[connect] #3 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     110                                } 
     111                        } 
     112 
     113                        return $_connect; 
     114                } 
     115                catch(Exception $e) 
     116                { 
     117                        $this->writeLog('ERROR', $e->getMessage()); 
     118                        $this->_disconnect(); 
     119                        return false; 
     120                } 
     121        } 
     122 
     123        protected final function _disconnect() 
     124        { 
     125                try 
     126                { 
     127                        $xml = "</stream:stream>"; 
     128 
     129                        if ( $this->write($xml) === false ) 
     130                                throw new Exception('[disconnect] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     131 
     132                        if ( ($xml = $this->read()) === false ) 
     133                                throw new Exception('[disconnect] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     134                } 
     135                catch(Exception $e) 
     136                { 
     137                        $this->writeLog('ERROR', $e->getMessage()); 
     138                        return false; 
     139                } 
     140        } 
     141 
     142        private final function starttls() 
     143        { 
     144                try 
     145                { 
     146                        $xml = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"; 
     147                        if ( $this->write($xml) === false ) 
     148                                throw new Exception('[starttls] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     149 
     150                        if ( ($xml = $this->read()) === false ) 
     151                                throw new Exception('[starttls] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     152 
     153                        if ( !preg_match('/<proceed.*\/>/', $xml, $matches) ) 
     154                                throw new Exception('[starttls] #3 can\'t start tls in the socket ' .$this->_socket . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     155 
     156                        stream_socket_enable_crypto($this->_socket, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); 
     157 
     158                        $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
     159                        $xml .= "<stream:stream to='" . $this->_server . "' xmlns='jabber:client' "; 
     160                        $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
     161                        if ( $this->write($xml) === false ) 
     162                                throw new Exception('[starttls] #4 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     163 
     164                        usleep(90000); 
     165                        $this->blocking($this->_socket, 0); 
     166 
     167                        if ( ($xml = $this->read()) === false ) 
     168                                throw new Exception('[starttls] #5 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     169 
     170                        if ( !$this->_plain() ) 
     171                                throw new Exception('[starttls] #6 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     172 
     173                        return true; 
     174                } 
     175                catch(Exception $e) 
     176                { 
     177                        $this->writeLog('ERROR', $e->getMessage()); 
     178                        return false; 
     179                } 
     180        } 
     181 
     182        private final function _plain() 
     183        { 
     184                try 
     185                { 
     186                        $this->blocking($this->_socket, 0); 
     187 
     188                        if ( ($xml = $this->read()) === false ) 
     189                                throw new Exception('[_plain] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     190 
     191                        $xml  = "<username>" . $this->_username . "</username>"; 
     192                        $xml .= "<password>" . $this->_password . "</password>"; 
     193                        $xml .= "<resource>" . $this->_resource . "</resource>"; 
     194 
     195                        unset($this->_password); 
     196 
     197                        if ( !$this->iq('set', 'auth_1', NULL, NULL, "jabber:iq:auth", $xml) ) 
     198                                throw new Exception('[_plain] #2 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     199 
     200                        while ( !preg_match("/<iq xmlns='jabber:client' id='auth_1' type='(result|error)'/", ($readSocket = $this->read()), $matches) ) 
     201                                usleep(10000); 
    178202 
    179203                        if($matches[1] == "error") 
    180204                                return false; 
    181205 
    182          if ( ($xml = $this->read()) === false ) 
    183             throw new Exception('[_plain] #3 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    184  
    185          return true; 
    186       } 
    187       catch(Exception $e) 
    188       { 
    189          $this->writeLog('ERROR', $e->getMessage()); 
    190          return false; 
    191       } 
    192    } 
     206                        if ( ($xml = $this->read()) === false ) 
     207                                throw new Exception('[_plain] #3 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     208 
     209                        return true; 
     210                } 
     211                catch(Exception $e) 
     212                { 
     213                        $this->writeLog('ERROR', $e->getMessage()); 
     214                        return false; 
     215                } 
     216        } 
    193217 
    194218        private final function _iq($pType = false, $pId = false, $pTo = false, $pFrom = false, $pXmlns = false, $pLoad = false ) 
     
    199223 
    200224                if ( $pXmlns == "vcard-temp" ) 
    201       { 
     225                { 
    202226                        $xml .= ">"; 
    203227                        $xml .= $pLoad; 
    204228                } 
    205       else 
    206       { 
     229                else 
     230                { 
    207231                        $xml .= "><query xmlns='" . $pXmlns . "'"; 
    208232                        $xml .= ( $pLoad ) ? ">" . $pLoad . "</query>" : "/>"; 
     
    210234 
    211235                $xml .= "</iq>"; 
    212                  
    213                 return $xml;     
    214         } 
    215  
    216    protected final function iq($pType = false, $pId = false, $pTo = false, $pFrom = false, $pXmlns = false, $pLoad = false) 
    217    { 
    218       try 
    219       { 
    220          if ( !preg_match("/^(get|set|result|error)$/i", $pType, $matches) ) 
    221             throw new Exception('[iq] #1 type must be GET, SET, RESULT or ERROR. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    222  
    223                    if ( $this->write($this->_iq($pType, $pId, $pTo, $pFrom, $pXmlns, $pLoad)) === false ) 
    224             throw new Exception('[iq] #2 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    225          else 
    226             return true; 
    227       } 
    228       catch(Exception $e) 
    229       { 
    230          $this->writeLog('ERROR', $e->getMessage()); 
    231          return false; 
    232       } 
    233    } 
     236 
     237                return $xml; 
     238        } 
     239 
     240        protected final function iq($pType = false, $pId = false, $pTo = false, $pFrom = false, $pXmlns = false, $pLoad = false) 
     241        { 
     242                try 
     243                { 
     244                        if ( !preg_match("/^(get|set|result|error)$/i", $pType, $matches) ) 
     245                                throw new Exception('[iq] #1 type must be GET, SET, RESULT or ERROR. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     246 
     247                        if ( $this->write($this->_iq($pType, $pId, $pTo, $pFrom, $pXmlns, $pLoad)) === false ) 
     248                                throw new Exception('[iq] #2 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     249                        else 
     250                                return true; 
     251                } 
     252                catch(Exception $e) 
     253                { 
     254                        $this->writeLog('ERROR', $e->getMessage()); 
     255                        return false; 
     256                } 
     257        } 
    234258 
    235259        protected final function presence($pType = false, $pTo = false, $pShow = false, $pStatus = false, $pPriority = false) 
    236260        { 
    237       try 
    238       { 
    239          $xml  = "<presence"; 
    240          $xml .= ($pTo)   ? " to='{$pTo}'" : ''; 
    241          $xml .= ($pType) ? " type='{$pType}'" : ''; 
    242           
    243          //$xml .= ($pStatus || $pShow || $pPriority) ? ">" : "/>"; 
    244          if ( !($pStatus || $pShow || $pPriority) ) 
     261                try 
     262                { 
     263                        $xml  = "<presence"; 
     264                        $xml .= ($pTo)   ? " to='{$pTo}'" : ''; 
     265                        $xml .= ($pType) ? " type='{$pType}'" : ''; 
     266 
     267                        if ( !($pStatus || $pShow || $pPriority) ) 
    245268                                $xml .= "/>"; 
    246269                        else 
    247270                        { 
    248                          $xml .= ">"; 
    249                  $xml .= ($pStatus) ? "<status>" . $pStatus . "</status>" : ''; 
    250                  $xml .= ($pShow) ? "<show>" . $pShow . "</show>" : ''; 
    251                  $xml .= ($pPriority) ? "<priority>" . $pPriority . "</priority>" : ''; 
    252                  $xml .= ($pStatus || $pShow || $pPriority) ? "</presence>" : ''; 
     271                                $xml .= ">"; 
     272                                $xml .= ($pStatus) ? "<status>" . $pStatus . "</status>" : ''; 
     273                                $xml .= ($pShow) ? "<show>" . $pShow . "</show>" : ''; 
     274                                $xml .= ($pPriority) ? "<priority>" . $pPriority . "</priority>" : ''; 
     275                                $xml .= ($pStatus || $pShow || $pPriority) ? "</presence>" : ''; 
    253276                        } 
    254  
    255          if ( $this->write($xml) === false ) 
    256             throw new Exception('[presence] #1 it isn\'t possible send presence for ' . $this->_server . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    257  
    258          return true; 
    259       } 
    260       catch(Exception $e) 
    261       { 
    262          $this->writeLog('ERROR', $e->getMessage()); 
    263          return false; 
    264       } 
    265         } 
    266  
    267    protected final function read() 
    268    { 
    269       $return = NULL; 
    270       do 
    271       { 
    272          $line = NULL; 
    273          $line = utf8_decode(parent::read($this->_socket, 4096)); 
    274  
    275          if ( $line === false ) 
    276          { 
    277             $return = false; 
    278             break; 
    279          } 
    280  
    281          if ( $line != NULL ) 
    282             $return .= $line;// . "\n"; 
    283       } 
    284       while ( $line != NULL ); 
    285  
    286       return $return; 
    287    } 
     277                         
     278                        if ( $this->write($xml) === false ) 
     279                                throw new Exception('[presence] #1 it isn\'t possible send presence for ' . $this->_server . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     280 
     281                        return true; 
     282                } 
     283                catch(Exception $e) 
     284                { 
     285                        $this->writeLog('ERROR', $e->getMessage()); 
     286                        return false; 
     287                } 
     288        } 
     289 
     290        protected final function read() 
     291        { 
     292                $return = NULL; 
     293                do 
     294                { 
     295                        $line = NULL; 
     296                        $line = utf8_decode(parent::read($this->_socket, 4096)); 
     297 
     298                        if ( $line === false ) 
     299                        { 
     300                                $return = false; 
     301                                break; 
     302                        } 
     303 
     304                        if ( $line != NULL ) 
     305                                $return .= $line;// . "\n"; 
     306                } 
     307                while ( $line != NULL ); 
     308 
     309                return $return; 
     310        } 
    288311 
    289312        protected final function write($pData = false) 
    290    { 
    291       if ( !$pData ) 
    292          return false; 
    293  
    294       return parent::write($this->_socket, utf8_encode($pData)); 
    295    } 
    296  
    297    protected final function writeLog($pType = false, $pLog = false) 
    298    { 
    299       if ( !defined('self::'.$pType) && !$pLog ) 
    300          return false; 
    301  
    302       if ( !(bool)constant('self::J_'.$pType) && !(bool)constant('self::J_ALL') ) 
    303          return false; 
    304  
    305       $log  = date('m/d/Y H:i:s'); 
    306       $log .= ' [' . constant('self::'.$pType) . '] :: '; 
    307       $log .= $pLog . "\n"; 
    308       if ( $fp = fopen (self::J_FILE, "a+") ) 
    309       { 
    310          fwrite($fp, $log); 
    311          fclose($fp); 
    312       } 
    313    } 
     313        { 
     314                if ( !$pData ) 
     315                        return false; 
     316 
     317                return parent::write($this->_socket, utf8_encode($pData)); 
     318        } 
     319 
     320        function __destruct() 
     321        { 
     322                $this->close($this->_socket); 
     323        } 
     324 
     325        protected final function writeLog($pType = false, $pLog = false) 
     326        { 
     327                if ( !defined('self::'.$pType) && !$pLog ) 
     328                        return false; 
     329 
     330                if ( !(bool)constant('self::J_'.$pType) && !(bool)constant('self::J_ALL') ) 
     331                        return false; 
     332 
     333                $log  = date('m/d/Y H:i:s'); 
     334                $log .= ' [' . constant('self::'.$pType) . '] :: '; 
     335                $log .= $pLog . "\n"; 
     336                if ( $fp = fopen (self::J_FILE, "a+") ) 
     337                { 
     338                        fwrite($fp, $log); 
     339                        fclose($fp); 
     340                } 
     341        } 
    314342} 
    315  
    316343?> 
  • trunk/instant_messenger/inc/Jabberd2.abstract.php

    r55 r151  
    77class Jabberd2 extends Jabber 
    88{ 
    9    final function connect($pUser = false, $pPassword = false) 
    10    { 
    11       try 
    12       { 
    13          if ( parent::connect($pUser, $pPassword) ) 
    14             if ( $this->presence() ) 
    15                return true; 
     9        final function connect($pUser = false, $pPassword = false) 
     10        { 
     11                try 
     12                { 
     13                        if ( $_connect = parent::connect($pUser, $pPassword) ) 
     14                                return $_connect; 
    1615 
    17          return false; 
    18       } 
    19       catch(Exception $e) 
    20       { 
    21          $this->writeLog('ERROR', $e->getMessage()); 
    22          return false; 
    23       } 
    24    } 
     16                        return false; 
     17                } 
     18                catch(Exception $e) 
     19                { 
     20                        $this->writeLog('ERROR', $e->getMessage()); 
     21                        return false; 
     22                } 
     23        } 
    2524 
    26    function disconnect() 
    27    { 
    28       $this->_disconnect(); 
    29    } 
     25        function closeSocket() 
     26        { 
     27                $this->close($this->_socket); 
     28        } 
    3029 
    31    final function readSocket() 
    32    { 
    33       return $this->read(); 
    34    } 
     30        function disconnect() 
     31        { 
     32                $this->_disconnect(); 
     33        } 
    3534 
    36    final function writeSocket($pData) 
    37    { 
    38       return $this->write($pData); 
    39    } 
     35        final function readSocket() 
     36        { 
     37                return $this->read(); 
     38        } 
     39 
     40        final function writeSocket($pData) 
     41        { 
     42                return $this->write($pData); 
     43        } 
     44 
     45        /* 
     46         * Jabber - Functions 
     47         */ 
     48 
     49        final function addContacts($pContact) 
     50        { 
     51                $jid = explode("@",$pContact['email']); 
     52                $jid = $jid[0]."@".$this->_server; 
     53                $name = $pContact['name']; 
     54                $group = $pContact['group']; 
     55 
     56                if(trim($jid[0]) != trim($this->_user)) 
     57                { 
     58                        if ( $jid ) 
     59                        { 
     60                                $newcontact  = "<item jid='".$jid."'"; 
     61                                $newcontact .= " name='" . $name . "'"; 
     62                                $newcontact .= "><group>" . $group . "</group></item>"; 
     63                        } 
     64                } 
     65                $addid = "adduser_" . time(); 
     66                if ( !$this->connected ) 
     67                        echo "disconnected"; 
     68                else 
     69                { 
     70                        if($this->writeSocket($this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $newcontact))) 
     71                        { 
     72                                $this->getContacts(); 
     73                                if($this->subscription($pContact['jid'],"subscribe")) 
     74                                        echo "OK"; 
     75                        } 
     76                } 
     77        } 
     78 
     79        final function getContacts() 
     80        { 
     81                $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster'); 
     82        } 
     83 
     84        final function getVcard($pJid) 
     85        { 
     86                if(is_array($pJid)) 
     87                { 
     88                        $jid = (trim($pJid['jid']) == "this") ? $this->_user . '@' . $this->_server : $pJid['jid']; 
     89 
     90                        if ( !$this->connected ) 
     91                                echo "disconnected"; 
     92                        else 
     93                        { 
     94                                $this->writeSocket($this->iq('get', 'vCard', $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>")); 
     95                                echo "OK"; 
     96                        } 
     97                } 
     98                else 
     99                { 
     100                        $this->iq('get', 'vCard', $pJid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); 
     101                } 
     102        } 
     103 
     104        final function newVcard($NewVcard) 
     105        { 
     106                $id = $this->_user; 
     107 
     108                if ( !$this->connected ) 
     109                        echo "disconnected"; 
     110                else 
     111                {                
     112                        $this->writeSocket($this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>")); 
     113                        echo "OK"; 
     114                }                        
     115        } 
    40116         
    41         final function setPresence($pPresence) 
     117        final function removeContact($pContact) 
    42118        { 
     119                $delid  = 'deluser_' . time(); 
     120                if( !$this->connected ) 
     121                        echo "disconnected"; 
     122                else 
     123                { 
     124                        if($this->writeSocket($this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>"))) 
     125                        { 
     126                                $this->getContacts(); 
     127                                if($this->subscription($pContact['jid'],"unsubscribed")) 
     128                                        echo "OK";                       
     129                        } 
     130                } 
     131        } 
     132 
     133        final function subscription($pTo, $pType = false) 
     134        { 
     135                $jid = (is_array($pTo)) ? $pTo['jid'] : $pTo ; 
     136                $type = (is_array($pTo)) ? $pTo['type'] : $pType ; 
     137 
     138                if ( !$this->connected ) 
     139                        return false; 
     140                else 
     141                { 
     142                        $this->writeSocket("<presence xmlns='jabber:client' from='".$this->_user."@".$this->_server."' type='".$type."' to='".$jid."'/>"); 
     143                        return true;                     
     144                } 
     145        } 
     146 
     147        final function setPresence($pPresence = false) 
     148        { 
     149                 
     150                if ( !$pPresence ) 
     151                        $this->presence(); 
     152 
    43153                $type = ( isset($pPresence['type']) ) ? $pPresence['type'] : NULL; 
    44154                $to = ( isset($pPresence['to']) ) ? $pPresence['to'] : NULL; 
     
    46156                $status = ( isset($pPresence['status']) ) ? $pPresence['status'] : NULL; 
    47157                $priority = ( isset($pPresence['priority']) ) ? $pPresence['priority'] : NULL; 
    48                  
     158 
    49159                $this->presence($type, $to, $show, $status, $priority); 
    50         } 
    51         /* 
    52          * Vcard 
    53          */ 
    54160 
    55    final function getVcard($pVcard) 
    56    { 
    57                 $this->iq('get', $pVcard, $pVcard, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); 
    58    } 
    59  
    60    final function newVcard($NewVcard) 
    61    { 
    62         $id = $_SESSION['phpgw_info']['instant_messenger']['user']; 
    63         $this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard."</vCard>");      
    64    } 
    65          
    66         /* 
    67          *  Contacts 
    68          */ 
    69  
    70    final function getContacts() 
    71    { 
    72                 $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster'); 
    73    } 
    74     
    75    final function addContacts($pContact) 
    76    { 
    77         $addid = "adduser_" . time(); 
    78         $this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $pContact); 
    79    } 
    80     
    81    final function removeContact($pContact) 
    82    { 
    83         $delid  = 'deluser_' . time(); 
    84         $this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact."' subscription='remove'/>"); 
    85    } 
    86     
    87    final function updateContact($pContact) 
    88    { 
    89         $upid = 'updateuser_' . time(); 
    90         $this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $pContact); 
    91    } 
    92     
    93    /* 
    94     * Presence  
    95     */ 
    96     
    97    final function SubscriptionAcceptRequest($to = NULL) 
    98         { 
    99                 $this->presence("subscribed", $to); 
    100161        } 
    101162 
    102         final function SubscriptionDenyRequest($to = NULL) 
     163        final function updateContact($pContact) 
    103164        { 
    104                 $this->presence("unsubscribed", $to); 
    105         } 
     165                $jid   = $pContact['jid']; 
     166                $name  = $pContact['name']; 
     167                $group = $pContact['group']; 
    106168 
    107         final function Subscribe($to = NULL) 
    108         { 
    109                 $this->presence("subscribe", $to); 
    110         } 
     169                if ( $jid ) 
     170                { 
     171                        $updatecontact  = "<item jid='$jid'"; 
     172                        $updatecontact .= " name='" . $name . "'"; 
     173                        $updatecontact .= "><group>" . $group . "</group></item>"; 
     174                } 
    111175 
    112         final function Unsubscribe($to = NULL) 
    113         { 
    114                 $this->presence("unsubscribe", $to); 
     176                $upid = 'updateuser_' . time(); 
     177                if ( !$this->connected ) 
     178                        echo "disconnected"; 
     179                else 
     180                { 
     181                        $this->writeSocket($this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact)); 
     182                        $this->getContacts(); 
     183                        echo "OK"; 
     184                } 
    115185        } 
    116186} 
  • trunk/instant_messenger/inc/Socket.abstract.php

    r63 r151  
    2020        protected final function open( $pSocket = false, $pTimeOut = 1, $pBlockingMode = 0 ) 
    2121        { 
    22       if ( !$pSocket ) 
    23          return false; 
     22                if ( !$pSocket ) 
     23                        return false; 
    2424 
    25       if ( $socket = @stream_socket_client($pSocket, $errno, $errstr) ) 
    26       { 
    27          stream_set_blocking($socket, $pBlockingMode); 
    28          stream_set_timeout($socket, $pTimeOut); 
    29       } 
    30       return $socket; 
     25                if ( $socket = @stream_socket_client($pSocket, $errno, $errstr) ) 
     26                { 
     27                        #stream_set_blocking($socket, $pBlockingMode); 
     28                        #stream_set_timeout($socket, $pTimeOut); 
     29                        stream_set_blocking($socket, 1); 
     30                        stream_set_timeout($socket, 1); 
     31                } 
     32                return $socket; 
    3133        } 
    3234 
    33    protected final function blocking($pSocket = false, $pBlockingMode = 1) 
    34    { 
    35       if ( !$pSocket || !is_resource($pSocket) ) 
    36          return false; 
     35        protected final function blocking($pSocket = false, $pBlockingMode = 1) 
     36        { 
     37                if ( !$pSocket || !is_resource($pSocket) ) 
     38                        return false; 
    3739 
    38       stream_set_blocking($pSocket, $pBlockingMode); 
    39    } 
     40                stream_set_blocking($pSocket, $pBlockingMode); 
     41        } 
    4042 
    4143 
    4244        protected function read( $pSocket = false, $pLength = 4096 ) 
    4345        { 
    44       ini_set( 'track_errors', '1' ); 
    45       $php_errormsg = ''; 
     46                ini_set( 'track_errors', '1' ); 
     47                $php_errormsg = ''; 
    4648 
    47       if ( !$pSocket || !is_resource($pSocket) ) 
    48          return false; 
     49                if ( !$pSocket || !is_resource($pSocket) ) 
     50                        return false; 
    4951 
    50       set_magic_quotes_runtime(0); 
    51       $return = @fread($pSocket, $pLength); 
    52       set_magic_quotes_runtime(get_magic_quotes_gpc()); 
     52                set_magic_quotes_runtime(0); 
     53                $return = @fread($pSocket, $pLength); 
     54                set_magic_quotes_runtime(get_magic_quotes_gpc()); 
    5355 
    5456 
    55       if ( $php_errormsg ) 
    56          return false; 
     57                if ( $php_errormsg ) 
     58                        return false; 
    5759 
    58       return $return; 
     60                return $return; 
    5961        } 
    6062 
    6163        protected function write( $pSocket = false, $pData = false ) 
    6264        { 
    63       ini_set( 'track_errors', '1' ); 
    64       $php_errormsg = ''; 
    65        
    66       if ( (!$pSocket || !is_resource($pSocket)) || !$pData ) 
    67          return false; 
     65                ini_set( 'track_errors', '1' ); 
     66                $php_errormsg = ''; 
    6867 
    69           $return = @fwrite($pSocket, $pData); 
    70        
    71       if ( $php_errormsg ) 
    72          return false; 
     68                if ( (!$pSocket || !is_resource($pSocket)) || !$pData ) 
     69                        return false; 
    7370 
    74       return $return; 
     71                $return = @fwrite($pSocket, $pData); 
     72 
     73                if ( $php_errormsg ) 
     74                        return false; 
     75 
     76                return $return; 
    7577        } 
    7678 
    7779        protected final function close( $pSocket = false ) 
    7880        { 
    79       if ( !$pSocket || !is_resource($pSocket) ) 
    80          return false; 
     81                if ( !$pSocket || !is_resource($pSocket) ) 
     82                        return false; 
    8183 
    8284                return fclose($pSocket); 
  • trunk/instant_messenger/inc/class.Ujabber.inc.php

    r89 r151  
    11<?php 
    22 
    3 class Ujabber 
     3require_once 'Jabberd2.abstract.php'; 
     4 
     5class Ujabber extends Jabberd2 
    46{ 
    5    /* 
    6     * Listen  
    7     */ 
    8     
    9    final function listen() 
    10    { 
    11       $return = null; 
     7        public final function __construct() 
     8        { 
     9                session_start(); 
    1210                 
    13                 if($_SESSION['phpgw_info']['instant_messenger']['IM_disconnect']) 
     11                $_user     = $_SESSION['phpgw_info']['instant_messenger']['user']; 
     12                $_pass     = $_SESSION['phpgw_info']['instant_messenger']['passwd']; 
     13                $_server   = $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
     14                $_port     = $_SESSION['phpgw_info']['instant_messenger']['port_jabber']; 
     15                $_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']; 
     16                 
     17                session_write_close(); 
     18 
     19                if ( $this->connect($_user . '@' . $_server . '/' . $_resource . ':' . $_port, $_pass) ) 
     20                        $this->connected = true; 
     21                else 
     22                        $this->connected = false; 
     23                 
     24                 
     25        } 
     26 
     27        public final function __destruct() 
     28        { 
     29                $this->closeSocket(); 
     30        } 
     31 
     32        public final function listen() 
     33        { 
     34                if ( !$this->connected ) 
     35                        return "disconnected"; 
     36 
     37                if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) 
    1438                { 
    15         $_SESSION['phpgw_info']['instant_messenger']['IM_disconnect'] = false; 
    16         return "disconnected"; 
    17                 } 
    18                  
    19            $_SESSION['phpgw_info']['instant_messenger']['timeClient'] = time(); 
    20       $_SESSION['phpgw_info']['instant_messenger']['socket']['block'] = true; 
    21       $xml = $_SESSION['phpgw_info']['instant_messenger']['socket']['in']; 
    22       //str_replace inserido por problemas com clientes que inserem 
    23       //quebra de linha no XML descomentar e retirar a seguinte para 
    24       //voltar ao padrão assim que possível 
    25       //24/10/2007 - problema verificado por usuários do SERPRO na 
    26       //plataforma Windows ocorrendo também no cliente Linux 
    27       //por Alexandre e Rodrigo 
    28                 $xml = str_replace("\n","",$xml); 
    29                 $xml = str_replace("\r","",$xml); 
    30  
    31       unset($_SESSION['phpgw_info']['instant_messenger']['socket']['in']); 
    32       $_SESSION['phpgw_info']['instant_messenger']['socket']['block'] = false; 
    33  
    34       ### Arranjo Tecnico ###  
    35       $vkrd = $xml; 
    36        
    37       if(isset($_SESSION['phpgw_info']['instant_messenger']['contacts'])) 
    38          unset($_SESSION['phpgw_info']['instant_messenger']['contacts']); 
    39  
    40       ### - messages - ### 
    41       //Linha abaixo dentro do padrão xmpp, entretanto clientes como 
    42       //o PSI não seguem o padrão assim ocorre problemas de comunicação 
    43       //descomentar e retirar a seguinte para voltar ao padrão assim 
    44       //que possível 
    45       //24/10/2007 - problema verificado por usuários do SERPRO na 
    46       //plataforma Windows ocorrendo também no cliente Linux 
    47       //por Alexandre e Rodrigo 
    48       //$_messages = "/<message[^>]+from='(\S+)'[^>]*>(?(?=.*?<composing |.*?<paused ).*?<(composing|paused) )(?(?=.*?<html).*?<html[^>]*><body[^>]*>(.*?)<\/body><\/html>).*?<\/message>/s"; 
    49       //retirar a linha abaixo para voltar ao padrão conforme acima 
    50       $_messages = "/<message[^>]+from='(\S+)'[^>]*>(?(?=.*?<composing |.*?<paused ).*?<(composing|paused) )(?(?=.*?<body).*?<body[^>]*>(.*?)<\/body>).*?<\/message>/s"; 
    51       $_messages = preg_match_all($_messages, $xml, $messages); 
    52       if ( $_messages !== false && $_messages > 0 ) 
    53       { 
    54          $xml = preg_replace("/<message.*?<\/message>/", "", $xml);          
    55          $return .= $this->getMessages($messages); 
    56       } 
    57       ### - Fim messages - ### 
    58  
    59       ### - contacts - ### 
    60       $_contacts = "/<iq[^>]+id='contacts'[^>]*>.*?<\/iq>/"; 
    61       $_contacts = preg_match_all($_contacts, $xml, $_xml); 
    62  
    63       $_contacts = "/<item.*?(?(?=[^>]+name)[^>]+name='(.*?)')[^>]+subscription='(.*?)'[^>]+jid='(.*?)'"; 
    64       $_contacts .= "(?(?=[^>]*\/>)[^>]*\/>|[^>]*><group>(.*?)<\/group><\/item>)/"; 
    65       $_contacts = preg_match_all($_contacts, $_xml[0][0], $contacts); 
    66       if ( $_contacts !== false && $_contacts > 0 ) 
    67       { 
    68          $xml = preg_replace("/<iq[^>]+id='contacts'[^>]*>.*?<\/iq>/", "", $xml); 
    69          $return .= rawurldecode(urldecode($this->getContacts($contacts))); 
    70       } 
    71       ### - Fim contacts - ### 
    72  
    73       ### - presence - ### 
    74       $xml = $_SESSION['phpgw_info']['instant_messenger']['presences'] . $xml; 
    75  
    76       $_presence  = "/<presence(?(?=[^>]+\/>)[^>]+\/>|[^>]+>.*?<\/presence>)/"; 
    77       $_presence = preg_match_all($_presence, $xml, $presence); 
    78  
    79       $patterns[0] = '/<priority>[^<]*<\/priority>|<(\S) (?(?=[^>]*\/>)[^>]*\/>|[^>]*>.*?<\/\1>)/'; 
    80       $patterns[1] = '/ xmlns=\'.*?\'| to=\'.*?\'/'; 
    81       $patterns[2] = '/> +</'; 
    82       $replacements[0] = ''; 
    83       $replacements[1] = ''; 
    84       $replacements[2] = '><'; 
    85       $_xml = preg_replace($patterns, $replacements, implode('', $presence[0])); 
    86  
    87       $_presence  = "/<presence[^>]+from='(\S+)'[^>]*type='(unavailable)'(?(?=[^>]*\/>)[^>]*\/>|[^>]*>.*?<\/presence>)|"; 
    88       $_presence .= "<presence[^>]+from='(\S+)'(?(?=[^>]+type)[^>]+type='(\S+)')[^>]*"; 
    89       $_presence .= "(?(?=\/>)\/>|>"; 
    90       $_presence .= "(?(?=<s[^>]*?>)<s[^>]*?>(.*?)<\/s[^>]*?>(?(?=<s[^>]*?>)<s[^>]*?>(.*?)<\/s[^>]*?>))"; 
    91       $_presence .= "<\/presence>)/"; 
    92       $_presence = preg_match_all($_presence, $_xml, $presence); 
    93       if ( $_presence !== false && $_presence > 0 ) 
    94       { 
    95          foreach ( $presence[5] as $key => $val ) 
    96          { 
    97             if ( !empty($presence[1][$key]) && (strpos($presence[1][$key], '/') !== false) ) 
    98                $presence[1][$key] = substr($presence[1][$key], 0, strpos($presence[1][$key], '/')); 
    99              
    100             if ( !empty($presence[3][$key]) && strpos($presence[3][$key], '/') !== false ) 
    101                $presence[3][$key] = substr($presence[3][$key], 0, strpos($presence[3][$key], '/')); 
    102     
    103             if ( !empty($val) && !preg_match("/^(away|chat|dnd|xa)$/", $val) ) 
    104                if ( preg_match("/^(away|chat|dnd|xa)$/", $presence[6][$key]) ) 
    105                { 
    106                   $aux = $presence[5][$key]; 
    107                   $presence[5][$key] = $presence[6][$key]; 
    108                   $presence[6][$key] = $aux; 
    109                } 
    110                else 
    111                { 
    112                   if ( empty($presence[6][$key]) )           
    113                      $presence[6][$key] = $presence[5][$key]; 
    114                   $presence[5][$key] = ''; 
    115                } 
    116          } 
    117          $xml = preg_replace("/<presence[^>]\/?>|<presence[^>]>.*?<\/presence>/", "", $xml); 
    118  
    119          $return .= $this->getPresence($presence); 
    120       } 
    121       ### - Fim presence - ### 
    122  
    123        
    124       ### - vcard - ### 
    125       ### - Arranjo Tecnico - ### 
    126       $_xml = $vkrd; 
    127       $_vcard = "/<iq.*? id='(.*?)' .*?(<vCard [^>]+\/>|<vCard.*?<\/vCard>)<\/iq>/";  
    128       $_vcard = preg_match_all($_vcard, $_xml, $vcard); 
    129       if( $_vcard !== false && $_vcard > 0) 
    130       { 
    131          $xml = preg_replace("/<iq.*?<vCard.*?<\/iq>/", "", $xml); 
    132          $return .= urldecode($this->getVcard($vcard)); 
    133       } 
    134       ### - Fim vcard - ### 
    135       ## Final do Listen; 
    136  
    137       return $return; 
    138    } 
    139     
    140    function reconnect() 
    141    { 
    142       require_once("IMConfigure.php"); 
    143  
    144       $_transport = TRANSPORT_NON_SECURITY; 
    145       $_port = PORT_NON_SECURITY; 
    146  
    147                 $SERVER = "127.0.0.1"; 
    148  
    149                 $fp  = ""; 
    150                 @$fp = stream_socket_client($_transport . "://" . $SERVER . ":" . $_port, $errno, $errstr, 10); 
    151  
    152                 if ( $fp ) 
    153                 { 
    154                         fwrite($fp, "GET /" . CONNECT . ";" . session_id() . " HTTP/1.1\r\nHost: " . $SERVER . ":" . $_port . "\r\nAccept: */*\r\n\r\n"); 
    155                         return 'true'; 
     39                        sleep(1); 
     40                        $xml = $this->readSocket(); 
     41                        printf("%s", $xml); 
    15642                } 
    15743                else 
    158                         return 'false'; 
    159    }  
    160     
    161    /* 
    162     * Contacts 
    163     */ 
     44                { 
     45                        ob_end_clean(); 
     46                        ignore_user_abort(true); 
     47                        ob_start(); 
    16448 
    165    function getContacts(array $pContacts) 
    166    { 
    167       $_group = array(); 
    168       $return = NULL; 
    169       $jid = array_unique($pContacts[3]); 
    170        
    171       foreach ( $jid as $key => $val ) 
    172       { 
    173          $_SESSION['phpgw_info']['instant_messenger']['contacts'][] = $val; 
     49                        $init = time(); 
    17450 
    175          $item  = NULL; 
    176          $item .= '<item name="' . (( !empty($pContacts[1][$key]) ) ? $pContacts[1][$key] : $val); 
    177          $item .= '" jid="' . $val; 
    178          $item .= '" subscription="' . $pContacts[2][$key]; 
    179          $item .= '" />'; 
     51                        while ( !connection_aborted() && time() - $init < 10 ) 
     52                        { 
     53                                # read from server and write in the client 
     54                                $xml = $this->readSocket(); 
     55                                $xml = ( strlen($xml) ) ? $xml : ' '; 
     56                                printf("%s", $xml ); 
    18057 
    181          $_group[utf8_decode(strtolower(!empty($pContacts[4][$key]) ? $pContacts[4][$key] : 'default'))][] = $item; 
    182       }  
    183        
    184       ksort($_group); 
     58                                ob_flush(); 
     59                                flush(); 
     60                                usleep(6000); 
     61                        } 
    18562 
    186       foreach ( $_group as $key => $val ) 
    187          $return .= '<group name="' . $key . '">' . implode('', $val) . '</group>'; 
     63                        ob_end_flush(); 
     64                } 
     65        } 
    18866 
    189       return '<contacts>' . $return . '</contacts>'; 
    190    } 
     67        public final function SendMessage($pSendMessage) 
     68        { 
     69                $pSendMessage['body'] = stripslashes($pSendMessage['body']); 
    19170 
    192    function requireContacts() 
    193    { 
    194       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['getContacts'] = NULL; 
    195    } 
    196     
    197   /* 
    198    * Presence  
    199    */ 
     71                $patterns = array('/&nbsp;| +/i', '/<br[^>]*>/i'); 
     72                $replace = array(' ', '<br />'); 
     73                $pSendMessage['body'] = preg_replace($patterns, $replace, $pSendMessage['body']); 
    20074 
    201    function setPresence($pPresence) 
    202    { 
    203       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['setPresence'] = $pPresence; 
    204       foreach($pPresence as $key=>$presence) 
    205         if($key == 'show' || $key == 'type') 
    206         { 
    207                 $_SESSION['phpgw_info']['instant_messenger']['MyPresence'] = $presence; 
    208         } 
    209    } 
    210     
    211    function MyPresence() 
    212    { 
    213         if(isset($_SESSION['phpgw_info']['instant_messenger']['MyPresence'])) 
    214                 return $_SESSION['phpgw_info']['instant_messenger']['MyPresence']; 
    215    } 
    216     
    217    function getPresence(array $pPresence) 
    218    { 
    219       $offline = array(); 
    220       foreach ( $pPresence[1] as $key => $val ) 
    221       { 
    222          if ( empty($val) ) 
    223             continue; 
     75                $_emotions  = '/<img emotion="(\S+)?"[^>]+>/'; 
     76                $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); 
    22477 
    225          $_offline = true; 
    226          for ( $i = $key; $i < sizeof($pPresence[1]); $i++ ) 
    227             if ( $pPresence[1][$key] == $pPresence[3][$i] || $pPresence[1][$key] == $pPresence[5][$i] ) 
    228                $_offline = false; 
     78                foreach ( $emotions[0] as $key => $val ) 
     79                        $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; 
    22980 
    230          if ( $_offline ) 
    231             $offline[$key] = $val; 
    232       } 
     81                $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); 
    23382 
    234       $online = array(); 
    235       foreach ( $pPresence[3] as $key => $val ) 
    236       { 
    237          if ( empty($val) ) 
    238             continue; 
     83                $to = $pSendMessage['to']; 
     84                $type = "chat"; 
     85                $id = ""; 
     86                $content = array( 
     87                        "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", 
     88                        "thread"  => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", 
     89                        "body"    => $pSendMessage['body'] ? $pSendMessage['body'] : "" 
     90                ); 
    23991 
    240          $_online = true; 
    241          for ( $i = ($key + 1); $i < sizeof($pPresence[3]); $i++ ) 
    242             if ( in_array($val, $offline) || $pPresence[3][$key] == $pPresence[3][$i] ) 
    243                $_online = false; 
     92                $payload = ""; 
    24493 
    245          if ( $_online ) 
    246             $online[$key] = $val; 
    247       } 
     94                if ($to && is_array($content)) 
     95                { 
     96                        if (!$id) 
     97                        { 
     98                                $id = $type . "_" . time(); 
     99                        } 
    248100 
    249       $return = NULL; 
     101                        $xml = "<message to='$to' type='$type' id='$id'>"; 
    250102 
    251       foreach ( $offline as $key => $val ) 
    252       { 
    253          $val = ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; 
    254          $return .= "<presence from='" . $val . "' type='unavailable' />"; 
    255       } 
    256        
    257       foreach ( $online as $key => $val ) 
    258       { 
    259          $val = ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; 
     103                        if ($content['subject']) 
     104                        { 
     105                                $xml .= "<subject>" . $content['subject'] . "</subject>"; 
     106                        } 
    260107 
    261          if ( empty($pPresence[4][$key]) ) 
    262             $pPresence[4][$key] = ( empty($pPresence[5][$key]) ) ? 
    263                'available' : $pPresence[5][$key]; 
     108                        if ($content['thread']) 
     109                        { 
     110                                $xml .= "<thread>" . $content['thread'] . "</thread>"; 
     111                        } 
    264112 
    265          $return .= "<presence from='" . $val . "' type='" . $pPresence[4][$key]; 
    266          if ( empty($pPresence[6][$key]) ) 
    267             $return .= "' />"; 
    268          else 
    269             $return .= "'>" . $pPresence[6][$key] . "</presence>"; 
     113                        //Linha abaixo dentro do padrão xmpp, entretanto clientes como 
     114                        //o PSI não seguem o padrão assim ocorre problemas de comunicação 
     115                        //descomentar e retirar a seguinte para voltar ao padrão assim 
     116                        //que possível 
     117                        //24/10/2007 - problema verificado por usuários do SERPRO na 
     118                        //plataforma Windows ocorrendo também no cliente Linux 
     119                        //por Alexandre e Rodrigo 
    270120 
    271          if ( strpos($pPresence[4][$key], 'subscribe') === false ) 
    272          { 
    273             $session .= "<presence from='" . $val . "'><show>" . $pPresence[4][$key] . "</show>"; 
    274             if ( !empty($pPresence[6][$key]) ) 
    275                $session .= "<status>" . $pPresence[6][$key] . "</status>"; 
    276             $session .= "</presence>"; 
    277          } 
    278       } 
     121                        //$xml .= "<html><body>" . $content['body'] . "</body></html>"; 
    279122 
    280       $_SESSION['phpgw_info']['instant_messenger']['presences'] = $session; 
     123                        //retirar a linha abaixo para voltar ao padrão conforme acima 
     124                        $xml .= "<body>" . $content['body'] . "</body>"; 
     125                        $xml .= $payload; 
     126                        $xml .= "</message>"; 
     127                        unset($id); 
    281128 
    282       return $return; 
    283    } 
    284  
    285    /* 
    286     * GetMessage 
    287     */ 
    288     
    289    function getMessages(array $pMessages) 
    290    { 
    291       $_messages = array(); 
    292       $return = NULL; 
    293  
    294       foreach ( $pMessages[1] as $key => $val ) 
    295       { 
    296          trim($pMessages[3][$key]); 
    297          if ( !empty($pMessages[3][$key]) ) 
    298             $_messages[$val][] = $pMessages[3][$key]; 
    299              
    300          if ( !empty($pMessages[2][$key]) ) 
    301          { 
    302             $return .= '<' . $pMessages[2][$key] . ' from="'; 
    303             $return .= ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; 
    304             $return .= '" />'; 
    305          } 
    306       } 
    307  
    308       foreach ( $_messages as $key => $val ) 
    309       { 
    310          $return .= '<messages from="' . $key . '">'; 
    311          foreach ( $val as $msg ) 
    312             $return .= '<message>' . $msg . '</message>'; 
    313          $return .= '</messages>'; 
    314       } 
    315  
    316       return $return; 
    317    } 
    318  
    319    /* 
    320     * SendMessage 
    321     */ 
    322  
    323    function SendMessage($pSendMessage) 
    324    { 
    325       $pSendMessage['body'] = stripslashes($pSendMessage['body']); 
    326       $_emotions  = '/<img emotion="(\S+)?"[^>]+>/'; 
    327       $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); 
    328  
    329       foreach ( $emotions[0] as $key => $val ) 
    330          $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; 
    331  
    332       $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); 
    333  
    334       $to = $pSendMessage['to']; 
    335       $type = "chat"; 
    336       $id = ""; 
    337       $content = array( 
    338          "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", 
    339          "thread" => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", 
    340          "body" => $pSendMessage['body'] ? $pSendMessage['body'] : "" 
    341       ); 
    342  
    343       $payload = ""; 
    344  
    345       if ($to && is_array($content)) 
    346       { 
    347          if (!$id) 
    348          { 
    349             $id = $type . "_" . time(); 
    350          } 
    351  
    352          $xml = "<message to='$to' type='$type' id='$id'>"; 
    353  
    354          if ($content['subject']) 
    355          { 
    356             $xml .= "<subject>" . $content['subject'] . "</subject>"; 
    357          } 
    358  
    359          if ($content['thread']) 
    360          { 
    361             $xml .= "<thread>" . $content['thread'] . "</thread>"; 
    362          } 
    363  
    364          //Linha abaixo dentro do padrão xmpp, entretanto clientes como 
    365          //o PSI não seguem o padrão assim ocorre problemas de comunicação 
    366          //descomentar e retirar a seguinte para voltar ao padrão assim 
    367          //que possível 
    368          //24/10/2007 - problema verificado por usuários do SERPRO na 
    369          //plataforma Windows ocorrendo também no cliente Linux 
    370          //por Alexandre e Rodrigo 
    371          //$xml .= "<html><body>" . $content['body'] . "</body></html>"; 
    372          //retirar a linha abaixo para voltar ao padrão conforme acima 
    373          $xml .= "<body>" . $content['body'] . "</body>"; 
    374          $xml .= $payload; 
    375          $xml .= "</message>"; 
    376          unset($id); 
    377  
    378          $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; 
    379       } 
    380       else 
    381       { 
    382          $this->writeLog("ERROR: SendMessage() #2"); 
    383          return FALSE; 
    384       } 
    385    } 
    386  
    387    /* 
    388     * Composing / Paused Message 
    389     */ 
    390  
    391    function composingMessage($pComposing) 
    392    { 
    393  
    394                 $xml  = "<message xmlns='jabber:client' to='".$pComposing['to']."' id='".time()."' type='chat'>"; 
    395                 $xml .= "<x xmlns='jabber:x:event'>"; 
    396                 $xml .= "<composing/>"; 
    397                 $xml .= "</x>"; 
    398                 $xml .= "<composing xmlns='http://jabber.org/protocol/chatstates'/>"; 
    399                 $xml .= "</message>"; 
    400         $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; 
    401    } 
    402     
    403    function pausedMessage($pComposing) 
    404    { 
    405                 $xml  = "<message xmlns='jabber:client' to='".$pComposing['to']."' id='".time()."' type='chat'>"; 
    406                 $xml .= "<x xmlns='jabber:x:event'/>"; 
    407                 $xml .= "<paused xmlns='http://jabber.org/protocol/chatstates'/>"; 
    408                 $xml .= "</message>"; 
    409  
    410                 $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; 
    411    } 
    412     
    413    /* 
    414     * UpdateContact 
    415     */ 
    416     
    417    function updateContact($pUser) 
    418    { 
    419       $jid   = $pUser['jid']; 
    420       $name  = $pUser['name']; 
    421       $group = $pUser['group']; 
    422        
    423       if ( $jid ) 
    424       { 
    425          $updatecontact  = "<item jid='$jid'"; 
    426          $updatecontact .= " name='" . $name . "'"; 
    427          $updatecontact .= "><group>" . $group . "</group></item>"; 
    428          $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['updateContact'] = $updatecontact; 
    429       } 
    430       $this->requireContacts(); 
    431    } 
    432     
    433    /* 
    434     * AddContact 
    435     */ 
    436     
    437    function addContacts($pUser) 
    438    { 
    439       $jid = explode("@",$pUser['email']); 
    440       $pJid = $jid[0]."@".$_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
    441       $pName = $pUser['name']; 
    442       $pGroup = $pUser['group']; 
    443  
    444       if(trim($jid[0]) != trim($this->username)) 
    445       { 
    446          if ( $pJid ) 
    447          { 
    448             $newcontact  = "<item jid='$pJid'"; 
    449             $newcontact .= " name='" . $pName . "'"; 
    450             $newcontact .= "><group>" . $pGroup . "</group></item>"; 
    451             $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['addContacts'] = $newcontact; 
    452             $this->subscribe($pJid); 
    453             $this->requireContacts();            
    454          } 
    455       } 
    456    } 
    457     
    458    /* 
    459     * RemoveContact 
    460     */ 
    461      
    462     function removeContact($pUser) 
    463     { 
    464          $pJid = $pUser['jid']; 
    465          $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['removeContact'] = $pJid; 
    466          $this->unsubscribed($pJid); 
    467          $this->requireContacts(); 
    468     } 
    469  
    470    /* 
    471     * Vcard 
    472     */ 
    473  
    474    function newVcard($pVcardUser) 
    475    { 
    476       $pVcard = explode("_vkrd_", $pVcardUser['vcard']); 
    477  
    478       $xmlVcard  = "<FN>".$pVcard[0]."</FN>"; 
    479       $xmlVcard .= "<NICKNAME>".$pVcard[1]."</NICKNAME>"; 
    480       $xmlVcard .= "<ORG>"; 
    481       $xmlVcard .= "<ORGNAME>".$pVcard[2]."</ORGNAME>"; 
    482       $xmlVcard .= "<ORGUNIT>".$pVcard[3]."</ORGUNIT>"; 
    483       $xmlVcard .= "</ORG>"; 
    484       $xmlVcard .= "<ROLE>".$pVcard[4]."</ROLE>"; 
    485       $xmlVcard .= "<BDAY>".$pVcard[5]."</BDAY>"; 
    486       $xmlVcard .= "<DESC>".$pVcard[6]."</DESC>"; 
    487        
    488       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['newVcard'] = $xmlVcard; 
    489  
    490    } 
    491     
    492    function getVcard(array $Vcard) 
    493    { 
    494       $div = ""; 
    495       $_expr = "/<[^<vCard xmlns=\'vcard\-temp\'>].*[^<\/vCard>]>/"; 
    496       array_shift($Vcard); 
    497       $div = '<vcard>'; 
    498       $jid_user = $_SESSION['phpgw_info']['instant_messenger']['user']; 
    499       $jid_user .= "@" . $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
    500       for($i = 0 ; $i < count($Vcard[0]) ; $i++) 
    501       { 
    502          preg_match($_expr,$Vcard[1][$i],$div_vcard); 
    503          $div_new[] = $div_vcard; 
    504  
    505          if ( $jid_user == $Vcard[0][$i] ) 
    506             $_SESSION['phpgw_info']['instant_messenger']['vcard'] = $div_new[$i][0]; 
    507           
    508          $div .= '<div id="vcard_'.$Vcard[0][$i].'">'.urldecode($div_new[$i][0]).'</div>'; 
    509       } 
    510       $div .= '</vcard>'; 
    511           
    512       return $div; 
    513    } 
    514     
    515    function Vcard() 
    516    { 
    517       $contacts = array(); 
    518       $contacts = $_SESSION['phpgw_info']['instant_messenger']['contacts']; 
    519       $jid_user = $this->getJid(); 
    520  
    521       if( count($contacts) > 0 ) 
    522       { 
    523          array_unshift($contacts,$jid_user); 
    524  
    525          foreach($contacts as $user) 
    526             $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][] = $user; 
    527          return "true"; 
    528       }else{ 
    529          return "false"; 
    530       } 
    531    } 
    532     
    533    function VcardUser() 
    534    { 
    535         $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][] = $this->getJid();; 
    536    } 
    537     
    538    function getJid() 
    539    { 
    540       $jid = $_SESSION['phpgw_info']['instant_messenger']['user'] . "@" . $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
    541       return $jid;    
    542    } 
    543     
    544    function subscribe($pJid) 
    545    { 
    546       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    547       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['Subscribe'] = $jid; 
    548    } 
    549     
    550    function subscribed($pJid) 
    551    { 
    552       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    553       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['SubscriptionAcceptRequest'] = $jid; 
    554    } 
    555     
    556    function unsubscribe($pJid) 
    557    { 
    558       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    559       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['Unsubscribe'] = $jid; 
    560    } 
    561     
    562    function unsubscribed($pJid) 
    563    { 
    564       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    565       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['SubscriptionDenyRequest'] = $jid;    
    566    } 
     129                        echo $xml; 
     130                        $this->writeSocket($xml); 
     131                        $this->close(); 
     132                } 
     133                else 
     134                { 
     135                        //$this->writeLog("ERROR: SendMessage() #2"); 
     136                        return false; 
     137                } 
     138        } 
    567139} 
    568140?> 
  • trunk/instant_messenger/inc/class.contacts_im.inc.php

    r86 r151  
    2020                 
    2121                $search_uids = "|"; 
    22                 foreach($db_acls as $tmp) 
    23                         $search_uids .= "(uidNumber=".$tmp['acl_account'].")"; 
     22                if(count($db_acls) > 0) 
     23                        foreach($db_acls as $tmp) 
     24                                $search_uids .= "(uidNumber=".$tmp['acl_account'].")"; 
    2425 
    2526                // Busca Usuarios 
     
    2728                 
    2829                $search_groups = "|"; 
    29                 foreach($db_acls as $tmp) 
    30                         $search_groups .= "(gidNumber=".$tmp['acl_account'].")"; 
     30                if(count($db_acls) > 0) 
     31                        foreach($db_acls as $tmp) 
     32                                $search_groups .= "(gidNumber=".$tmp['acl_account'].")"; 
    3133  
    3234                // Busca Grupos 
     
    5961        function list_contacts($param) 
    6062        { 
    61                 $users = $this->users_auth_im(); 
    62                 $ordenar = array(); 
    63                 $return = array(); 
    64                 $i = 0; 
     63                $users  = $this->users_auth_im(); 
     64                $order  = array(); 
     65                $return = "<uids>"; 
    6566                 
    6667                foreach($users as $tmp) 
    67                         $ordenar[] = $tmp['cn'].";".$tmp['mail'].";".$tmp['uid'].";".$tmp['dn']; 
     68                        $order[] = $tmp['cn'].";".$tmp['mail'].";".$tmp['uid'].";".$tmp['dn']; 
    6869                                         
    69                 natsort($ordenar); 
    70                 $uid_unique = @array_values(@array_unique($ordenar)); 
     70                natsort($order); 
     71                $uid_unique = @array_values(@array_unique($order)); 
    7172                 
    7273                foreach($uid_unique as $tmp) 
     
    7576                        if(strtolower($result[3]) == strtolower($param['ou'])) 
    7677                        { 
    77                                 $return[$i]['cn']   = $result[0]; 
    78                                 $return[$i]['mail'] = $result[1]; 
    79                                 $return[$i]['uid']  = $result[2]; 
    80                                 $i++; 
     78                                $return .= "<data>"; 
     79                                $return .= "<cn>" . $result[0] . "</cn>"; 
     80                                $return .= "<mail>" . $result[1] . "</mail>";                            
     81                                $return .= "<uid>" . $result[2] . "</uid>"; 
     82                                $return .= "</data>"; 
    8183                        } 
    8284                        unset($result); 
    8385                }                        
    84          
    85                 if(count($return) > 0) 
    86                         return $return; 
    87                 else 
    88                         return 0; 
     86                 
     87                $return .= "</uids>"; 
     88                return $return; 
    8989        } 
    9090         
  • trunk/instant_messenger/inc/class.db_im.inc.php

    r55 r151  
    1414        var $db_pass; 
    1515        var $db_type; 
     16        var $user_id; 
    1617        var $teste; 
    1718         
    18         function db_im(){ 
     19        function db_im() 
     20        { 
     21                session_start();                 
    1922                $this->db_name = $_SESSION['phpgw_info']['instant_messenger']['server']['db_name']; 
    2023                $this->db_host = $_SESSION['phpgw_info']['instant_messenger']['server']['db_host']; 
     
    2326                $this->db_pass = $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass']; 
    2427                $this->db_type = $_SESSION['phpgw_info']['instant_messenger']['server']['db_type']; 
     28                $this->user_id = $_SESSION['phpgw_info']['instant_messenger']['user_id']; 
    2529                 
    26                 $this->db = new db();            
     30                $this->db = new db(); 
    2731                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); 
     32                session_write_close();           
    2833        } 
    2934 
     
    5358        { 
    5459                $preferences = $param['preferences']; 
    55                 $user_id  = $_SESSION['phpgw_info']['instant_messenger']['user_id'];  
     60                $user_id  = $this->user_id; 
    5661                $app_name = $this->name_app(); 
    57  
     62                 
    5863                $query = "insert into phpgw_preferences values('".$user_id."','".$app_name."','".serialize($preferences)."')"; 
    5964                 
    60                 if($this->query_db($query))       
     65                if($this->query_db($query)) 
     66                {  
    6167                        return "true"; 
    62                 else{ 
     68                } 
     69                else 
     70                { 
    6371                        $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='".$app_name."' and preference_owner='".$user_id."'"; 
    6472                        if($this->query_db($query)) 
     
    7280        { 
    7381                $result = array(); 
    74                 $user_id  = $_SESSION['phpgw_info']['instant_messenger']['user_id']; 
     82                $user_id  = $this->user_id; 
    7583                $app_name = $this->name_app(); 
    7684                 
     
    8391                        $result[] = $this->db->row(); 
    8492 
    85                 if(count($result) > 0){ 
     93                if(count($result) > 0) 
    8694                        return unserialize($result[0]['preference_value']); 
    87                 }else{ 
    88                         return "ch_offline:true;in_time:1;rd_nm:true;rd_ch:false"; 
    89                 } 
    90         } 
     95                else 
     96                        return "ch_offline:true;time_xa_im:1;rd_nm:true;rd_ch:false"; 
     97        }                
    9198         
    9299        function name_app() 
  • trunk/instant_messenger/inc/class.ldap_im.inc.php

    r68 r151  
    66        private $conn; 
    77        private $user; 
     8        private $jid; 
    89        private $password; 
    910         
    1011        function __construct() 
    1112        { 
    12                 $this->ldap_host        = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; 
    13                 $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; 
    14                 $this->user             = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; 
    15                 $this->password         = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; 
     13                session_start(); 
     14                $this->ldap_host                = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; 
     15                $this->ldap_context     = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; 
     16                $this->user                     = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; 
     17                $this->password                 = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; 
     18                $this->jid                              = $_SESSION['phpgw_info']['instant_messenger']['user']; 
    1619                $this->connect_ldap(false); 
     20                session_write_close(); 
    1721        } 
    1822         
     
    3337        } 
    3438         
    35         function get_photo_ldap($user,$getPhoto) 
     39        function get_photo_ldap($pUser,$getPhoto) 
    3640        { 
    37                 $user = ( $user == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user ; 
     41                $user = ( $pUser == "im_avatar" ) ? $this->jid : $pUser ; 
    3842                 
    39                 if ($this->conn) { 
     43                if ($this->conn)  
     44                { 
    4045                        $filter="(&(uid=".$user.")(phpgwAccountType=u))";                
    4146                        $justthese = array("jpegphoto"); 
    42                         $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
    43                         $entry = ldap_first_entry($this->conn, $search); 
     47                        $search = @ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
     48                        $entry = @ldap_first_entry($this->conn, $search); 
    4449                        $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto"); 
    4550                         
    46                         if( count($jpeg_data) > 1){ 
    47  
     51                        if( count($jpeg_data) > 1) 
     52                        { 
    4853                                $photo = imagecreatefromstring($jpeg_data[0]); 
    49                                 if($photo){ 
    50                                         if($getPhoto){ 
     54                                if($photo) 
     55                                { 
     56                                        if($getPhoto) 
     57                                        { 
    5158                                                header("Content-Type: image/jpeg"); 
    5259                                                $width = imagesx($photo); 
     
    5966                                                return;          
    6067                                        }else{ 
    61                                                 return 1; 
     68                                                return "true"; 
    6269                                        }                                
    6370                                }else{ 
    64                                         return 0; 
     71                                        return "false"; 
    6572                                } 
    6673                        }else{ 
    67                                 return 0; 
     74                                return "false"; 
    6875                        } 
    6976                } 
     
    7279        function photo_ldap($user) 
    7380        { 
    74                 $uid = ( $user['uid'] == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user['uid'] ; 
     81                $uid = ( $user['uid'] == "im_avatar" ) ? $this->jid : $user['uid'] ; 
    7582                return $this->get_photo_ldap($uid,false); 
    7683        } 
     
    143150        function list_organizations_ldap() 
    144151        { 
    145                 $result_org = array(); 
    146                 $i = 0; 
    147                 if ($this->conn) { 
     152                $result_org = "<organizations><ou></ou>"; 
     153 
     154                if ($this->conn)  
     155                { 
    148156                        $filter="ou=*";          
    149157                        $justthese = array("ou"); 
     
    152160                } 
    153161                 
    154                 foreach($entry as $tmp){ 
    155                         if($tmp['ou'][0] != ""){ 
    156                                 $result_org[$i] = $tmp['ou'][0]; 
    157                                 $i++; 
    158                         } 
    159                 } 
    160                 sort($result_org); 
     162                foreach($entry as $tmp) 
     163                        if($tmp['ou'][0] != "") 
     164                                $result_org .= "<ou>" . $tmp['ou'][0] . "</ou>";   
     165 
     166                $result_org .= "</organizations>"; 
     167                 
    161168                return $result_org; 
    162169        } 
     
    176183} 
    177184 
    178 if(trim($_REQUEST['user']) != ""){ 
     185if(trim($_REQUEST['user']) != "") 
     186{ 
    179187        $obj_img = new ldap_im(); 
    180188        $obj_img->get_photo_ldap($_REQUEST['user'],true); 
  • trunk/instant_messenger/inc/im_acl.inc.php

    r75 r151  
    44      if ( $GLOBALS['phpgw_info']['user']['acl'][$i]['appname'] == 'instant_messenger') 
    55      { 
    6                         require_once("im_sessions.inc.php"); 
    7           
     6                   session_start(); 
    87         $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 
    9          $wz_dragdrop = $webserver_url."/phpgwapi/js/wz_dragdrop/"; 
    108         $webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/'; 
    11  
    129         if ( strrpos($webserver_url, '/') === false || strrpos($webserver_url, '/') != (strlen($webserver_url)-1) ) 
    13             $webserver_url .= '/'; 
     10                                $webserver_url .= '/'; 
    1411 
    1512         $webserver_url = $webserver_url . 'instant_messenger/'; 
    1613 
    17          require_once("IMConfigure.php"); 
     14                        require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/im_sessions.inc.php'; 
     15                        require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/load_lang.php'; 
     16                         
     17                        $DOCUMENT_ROOT = PHPGW_SERVER_ROOT .'/instant_messenger/'; 
     18          
     19         $js = array( 
     20                                                        'js/connector.js', 
     21                                                        'js/xtools.js', 
     22                                                        'js/jabber.js', 
     23                                                        'js/client.js', 
     24                                                        'js/images.js', 
     25                                                        'js/dragdrop.js', 
     26                                                        'js/build_win.js', 
     27                                                        'js/templates.js', 
     28                                                        'js/fcommon.js', 
     29                                                        'js/menu_action.js', 
     30                                                        'js/functions.js', 
     31                                                        'js/images.js', 
     32                                                        'js/cookies_im.js', 
     33                                                        'js/load.js',                                                    
     34                    ); 
    1835 
    19          $_transport = TRANSPORT_NON_SECURITY; 
    20          $_port = PORT_NON_SECURITY; 
     36                        print '<script type="text/javascript">var path_im = "'.$webserver_url.'";</script>'; 
     37                        foreach ( $js as $key => $val ) 
     38                                print '<script src="' . $webserver_url . $val . '?' . filemtime($DOCUMENT_ROOT . $val) . '"></script>'; 
     39                         
     40                        print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/window.css">'; 
     41                        print   '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/chat.css">'; 
     42                        print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/common.css">'; 
     43                        print '<script type="text/javascript">setTimeout("client()",1000);</script>';  
    2144 
    22                         $SERVER = "127.0.0.1"; 
    23  
    24                         $fp  = ""; 
    25                         @$fp = stream_socket_client($_transport . "://" . $SERVER . ":" . $_port, $errno, $errstr, 10); 
    26  
    27          if ( $fp ) 
    28          { 
    29             fwrite($fp, "GET /" . CONNECT . ";" . session_id() . " HTTP/1.1\r\nHost: " . $SERVER . ":" . $_port . "\r\nAccept: */*\r\n\r\n"); 
    30  
    31             $js = array( 
    32                         $webserver_url . 'js/XMLTools.js', 
    33                         $webserver_url . 'js/im_functions.js', 
    34                         $webserver_url . 'js/im_fcommon.js', 
    35                         $webserver_url . 'js/im_var_globals.js', 
    36                         $webserver_url . 'js/im_images.js', 
    37                         $webserver_url . 'js/im_smiles.js', 
    38                         $webserver_url . 'js/im_templates.js', 
    39                         $webserver_url . 'js/im_win.js', 
    40                         $webserver_url . 'js/im_menu_action.js', 
    41                         $webserver_url . 'js/im_conf_font.js', 
    42                         $webserver_url . 'js/im_preferences.js', 
    43                         $webserver_url . 'js/im_init.js', 
    44                                                       $webserver_url . 'js/im_subscription.js', 
    45                        ); 
    46  
    47             require_once('load_lang.php'); 
    48  
    49                 print ' 
    50                <link rel="stylesheet" href="' . $webserver_url . 'templates/default/css.css" /> 
    51                <link rel="stylesheet" href="' . $webserver_url . 'templates/default/messenger.css" /> 
    52                <script> 
    53                   var im_path="' . $webserver_url . '"; 
    54                   var ini_wzdd = false; 
    55                   if ( !window.dd ) 
    56                   { 
    57                      ini_wzdd = true; 
    58                      document.write(\'\<script src="' . $wz_dragdrop . 'wz_dragdrop.js"\>\<\/script\>\'); 
    59                      var im_path="' . $webserver_url . '"; 
    60                   } 
    61                </script>'; 
    62           
    63           print ' 
    64                <script> 
    65                   if ( ini_wzdd ) 
    66                      SET_DHTML("backFantom"+NO_DRAG); 
    67                </script>'; 
    68  
    69           foreach ( $js as $key => $val ) 
    70              print '<script src="' . $val . '?' . filemtime($_SERVER['DOCUMENT_ROOT'] . '/' . $val) . '"></script>'; 
    71            
    72          } 
    73          break; 
     45                        session_write_close(); 
    7446      } 
    7547   } 
  • trunk/instant_messenger/inc/im_sessions.inc.php

    r67 r151  
    11<?php 
    22 
    3           $_SESSION['phpgw_info']['instant_messenger']['user']             = $GLOBALS['phpgw_info']['user']['account_lid']; 
    4           $_SESSION['phpgw_info']['instant_messenger']['user_id']                        = $GLOBALS['phpgw_info']['user']['account_id'];          
    5      $_SESSION['phpgw_info']['instant_messenger']['passwd']           = $GLOBALS['phpgw_info']['user']['passwd']; 
    6      $_SESSION['phpgw_info']['instant_messenger']['name_jabber']      = $GLOBALS['phpgw_info']['server']['name_jabber']; 
    7      $_SESSION['phpgw_info']['instant_messenger']['port_jabber']      = $GLOBALS['phpgw_info']['server']['port_jabber']; 
    8      $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']  = $GLOBALS['phpgw_info']['server']['resource_jabber']; 
    9  
    10      # Conf. Ldap 
    11      $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']   = $GLOBALS['phpgw_info']['server']['server_ldap_jabber']; 
    12      $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']  = $GLOBALS['phpgw_info']['server']['context_ldap_jabber']; 
    13      $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']     = $GLOBALS['phpgw_info']['server']['user_ldap_jabber']; 
    14      $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabber']; 
    15      $_SESSION['phpgw_info']['instant_messenger']['size_file_jabber']   = $GLOBALS['phpgw_info']['server']['size_file_jabber'];  
    16  
    17      $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; 
    18      $_SESSION['phpgw_info']['instant_messenger']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host']; 
    19      $_SESSION['phpgw_info']['instant_messenger']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port']; 
    20      $_SESSION['phpgw_info']['instant_messenger']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user']; 
    21      $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass']; 
    22      $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; 
     3                $_SESSION['phpgw_info']['instant_messenger']['user']             = $GLOBALS['phpgw_info']['user']['account_lid']; 
     4                $_SESSION['phpgw_info']['instant_messenger']['user_id']                   = $GLOBALS['phpgw_info']['user']['account_id'];                
     5                $_SESSION['phpgw_info']['instant_messenger']['passwd']           = $GLOBALS['phpgw_info']['user']['passwd']; 
     6                $_SESSION['phpgw_info']['instant_messenger']['name_jabber']      = $GLOBALS['phpgw_info']['server']['name_jabber']; 
     7                $_SESSION['phpgw_info']['instant_messenger']['port_jabber']      = $GLOBALS['phpgw_info']['server']['port_jabber']; 
     8                $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']  = $GLOBALS['phpgw_info']['server']['resource_jabber']; 
     9                 
     10                $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']   = $GLOBALS['phpgw_info']['server']['server_ldap_jabber']; 
     11                $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']  = $GLOBALS['phpgw_info']['server']['context_ldap_jabber']; 
     12                $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']     = $GLOBALS['phpgw_info']['server']['user_ldap_jabber']; 
     13                $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabber']; 
     14                 
     15                $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; 
     16                $_SESSION['phpgw_info']['instant_messenger']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host']; 
     17                $_SESSION['phpgw_info']['instant_messenger']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port']; 
     18                $_SESSION['phpgw_info']['instant_messenger']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user']; 
     19                $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass']; 
     20                $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; 
    2321 
    2422?> 
  • trunk/instant_messenger/index.php

    r140 r151  
    11<?php 
    2         /****************************************************\ 
    3          *                                                                                                      * 
    4          *                              Im - Instant Messenger                          * 
    5          *                                                                                                      * 
    6         \****************************************************/ 
    7          
    8         $GLOBALS['phpgw_info']['flags'] = array( 
    9                 'currentapp' => 'instant_messenger', 
    10                 'im_version'    => '0.2' 
    11         ); 
     2        /***************************************************\ 
     3         * Im - Instant Messenger                                                                       * 
     4         * Authors - Alexandre Correia                                                  * 
     5         *                       Rodrigo Souza                                                                  * 
     6        \***************************************************/ 
     7 
     8        $GLOBALS['phpgw_info']['flags']['currentapp'] = 'instant_messenger'; 
     9        $GLOBALS['phpgw_info']['flags']['im_version'] = '0.3'; 
    1210         
    1311        include("../header.inc.php"); 
    1412    $im_version = $GLOBALS['phpgw_info']['flags']['im_version']; 
    1513 
    16         // Template   
    1714        $template_1 = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); 
    1815        $template_1->set_file(Array('instant_messenger' => 'index.tpl')); 
    1916        $template_1->set_block('instant_messenger','index'); 
    2017        $template_1->pfp('out','index'); 
     18 
     19        require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/im_sessions.inc.php'; 
     20 
     21   $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 
     22   $webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/'; 
     23   if ( strrpos($webserver_url, '/') === false || strrpos($webserver_url, '/') != (strlen($webserver_url)-1) ) 
     24                $webserver_url .= '/'; 
     25 
     26   $webserver_url = $webserver_url . 'instant_messenger/'; 
     27 
     28        print '<script type="text/javascript">var path_im = "'.$webserver_url.'";</script>'; 
    2129         
    22         // Session 
    23         $_SESSION['phpgw_info']['instant_messenger']['user']                            = $GLOBALS['phpgw_info']['user']['account_lid']; 
    24         $_SESSION['phpgw_info']['instant_messenger']['passwd']                        = $GLOBALS['phpgw_info']['user']['passwd']; 
    25         $_SESSION['phpgw_info']['instant_messenger']['name_jabber']           = $GLOBALS['phpgw_info']['server']['name_jabber']; 
    26         $_SESSION['phpgw_info']['instant_messenger']['port_jabber']           = $GLOBALS['phpgw_info']['server']['port_jabber']; 
    27         $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']      = $GLOBALS['phpgw_info']['server']['resource_jabber']; 
    28  
    29         // Conf. Ldap 
    30         $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']    = $GLOBALS['phpgw_info']['server']['server_ldap_jabber']; 
    31         $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']   = $GLOBALS['phpgw_info']['server']['context_ldap_jabber']; 
    32         $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']      = $GLOBALS['phpgw_info']['server']['user_ldap_jabber']; 
    33         $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']  = $GLOBALS['phpgw_info']['server']['password_ldap_jabber'];        
    34         $_SESSION['phpgw_info']['instant_messenger']['size_file_jabber']         = $GLOBALS['phpgw_info']['server']['size_file_jabber'];         
    35          
    36         $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; 
    37         $_SESSION['phpgw_info']['instant_messenger']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host']; 
    38         $_SESSION['phpgw_info']['instant_messenger']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port']; 
    39         $_SESSION['phpgw_info']['instant_messenger']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user']; 
    40         $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass'];         
    41         $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; 
    42  
    4330        // Footer 
    4431        $GLOBALS['phpgw']->common->phpgw_footer(); 
     32 
    4533?> 
     34<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">--> 
     35<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
     36        <head> 
     37                <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
     38                <title>IM</title> 
     39                <!-- JavaScript --> 
     40                <script type="text/javascript" src="js/connector.js"></script> 
     41                <script type="text/javascript" src="js/xtools.js"></script> 
     42                <script type="text/javascript" src="js/jabber.js"></script> 
     43                <script type="text/javascript" src="js/client.js"></script> 
     44                <script type="text/javascript" src="js/images.js"></script> 
     45                <script type="text/javascript" src="js/dragdrop.js"></script> 
     46                <script type="text/javascript" src="js/build_win.js"></script> 
     47 
     48                <!-- JavaScript Aux --> 
     49                <script type="text/javascript" src="js/templates.js"></script> 
     50                <script type="text/javascript" src="js/fcommon.js"></script> 
     51                <script type="text/javascript" src="js/menu_action.js"></script> 
     52                <script type="text/javascript" src="js/functions.js"></script> 
     53                <script type="text/javascript" src="js/images.js"></script> 
     54                <script type="text/javascript" src="js/cookies_im.js"></script> 
     55 
     56                <!-- CSS --> 
     57                <link rel="stylesheet" type="text/css" href="templates/default/css/window.css"> 
     58                <link rel="stylesheet" type="text/css" href="templates/default/css/chat.css"> 
     59                <link rel="stylesheet" type="text/css" href="templates/default/css/common.css"> 
     60 
     61                <script type="text/javascript" src="js/load.js"></script>                
     62        </head> 
  • trunk/instant_messenger/setup/setup.inc.php

    r68 r151  
    11<?php 
    2         /****************************************************\ 
    3          * Im - Instant Messenger                                                       * 
    4          * Alexandre Correia                                                            * 
    5          * Rodrigo Souza                                                                        * 
    6         \****************************************************/ 
     2        /******************************************************\ 
     3         * Im - Instant Messenger                                                                               * 
     4         * Alexandre Correia                                                                                            * 
     5         * Rodrigo Souza                                                                                                        * 
     6        \******************************************************/ 
    77         
    88        $setup_info['instant_messenger']['name']        = 'instant_messenger'; 
    99        $setup_info['instant_messenger']['title']       = 'Mensageiro Instantâneo'; 
    10         $setup_info['instant_messenger']['version']     = '0.2'; 
     10        $setup_info['instant_messenger']['version']     = '0.3'; 
    1111        $setup_info['instant_messenger']['app_order']   = 9; 
    1212        $setup_info['instant_messenger']['enable']      = 1; 
    1313         
    1414        /* Conf Table */ 
    15         $setup_info['instant_messenger']['tables'][] = 'phpgw_im_auth_user'; 
    16  
     15         
    1716        $setup_info['instant_messenger']['author']                      = '<b>Coordenadores do Projeto</b> : <br> - Joao Alfredo Knopik Junior (jakjr@celepar.pr.gov.br)<br> - Nilton Emilio Buhrer Neto (niltonneto@celepar.pr.gov.br)<br> <b>Desenvolvedores</b> <br> - Alexandre Correia (alexandrecorreia@celepar.pr.gov.br)<br>- Rodrigo Souza Santos (rodsouza@celepar.pr.gov.br)'; 
    1817        $setup_info['instant_messenger']['maintainer']          =  'Os mesmos'; 
     
    2019 
    2120        $setup_info['instant_messenger']['license']     = 'GPL'; 
    22         $setup_info['instant_messenger']['description'] = 'Módulo de IM com protocolo Jabber'; 
     21        $setup_info['instant_messenger']['description'] = 'Módulo de IM com Jabber'; 
    2322 
    2423        /* The hooks this app includes, needed for hooks registration */ 
  • trunk/instant_messenger/templates/default/config.tpl

    r86 r151  
    5050    <td><input type="password" name="newsettings[password_ldap_jabber]" value="{value_password_ldap_jabber}"></td> 
    5151   </tr> 
    52  
    53    <tr bgcolor="{row_off}"> 
    54     <td colspan="2"> Gerenciamento IMManager</td> 
    55    </tr> 
    56  
    57    <tr bgcolor="{row_on}"> 
    58         <td colspan="2"> 
    59                 <iframe src ="instant_messenger/templates/default/script_load.php?user={value_user_ldap_jabber}" frameborder="0" height="60px" scrolling="no"></iframe> 
    60         </td> 
    61    </tr> 
    6252<!-- END body --> 
    6353 
    6454<!-- BEGIN footer --> 
    65   <tr bgcolor="{th_bg}"> 
    66     <td colspan="2"> 
    67 &nbsp; 
    68     </td> 
    69   </tr> 
    7055  <tr> 
    7156    <td colspan="2" align="center"> 
  • trunk/instant_messenger/templates/default/index.tpl

    r69 r151  
    2424    O Expresso Messenger é uma aplicação que permite o envio e recebimento de mensagens instantaneamente. Através da sua lista de contatos, você pode trocar mensagens e arquivos com seus contatos. Através da lista também é possível saber se seus contatos estão Online ou Offline. Para a troca de mensagens basta clicar em cima do nome do seu contato, se o mesmo estiver online ( verifique a sessão <a href="#status">Indicador de Status</a> ) abrirá uma janela onde você poderá enviar/receber as mensagens. O Expresso Messenger está associado 
    2525    a um serviço de mensagens instantâneas Jabber, este serviço é responsável pelo armazenamento dos seus contatos, preferências e mensagens. 
    26          
     26 
    2727        <br clear="all"> 
    2828        <br> 
    2929        ( figura 1 ) 
    30     <img src="templates/default/images/lista_contatos.png" width="242" height="381" alt="Im Screenshot" align="left" style="padding-right:4px;">  
     30    <img src="templates/default/images/lista_contatos.png" width="205" height="233" alt="Im Screenshot" align="left" style="padding-right:4px;">  
    3131         
    3232    <br clear="all"> 
     
    3939        <br> 
    4040        ( figura 2 ) 
    41     <img src="templates/default/images/lista_contatos_primeira.png" width="222" height="337" alt="Im Screenshot" align="left" style="padding-right:4px;">  
     41    <img src="templates/default/images/lista_contatos_primeira.png" width="206" height="233" alt="Im Screenshot" align="left" style="padding-right:4px;">  
    4242     
    4343    <br clear="all"> 
     
    6161    <h2><a name="prefe">4. Menu Opções</a></h2> 
    6262        ( figura 3 ) 
    63     <img src="templates/default/images/menu_preferencias.png" width="272" height="173" alt="Menu Preferências" align="left"> 
     63    <img src="templates/default/images/menu_preferencias.png" width="207" height="234" alt="Menu Preferências" align="left"> 
    6464    <br clear="all"> 
    6565    <br> 
     
    8585        ( figura 4.1 ) 
    8686        <br/> 
    87     <img src="templates/default/images/adicionar_contato.png" width="536" height="342" alt="Adicionar Contato" align="left"> 
     87    <img src="templates/default/images/adicionar_contato.png" width="555" height="294" alt="Adicionar Contato" align="left"> 
    8888    <br clear="all"> 
    8989    <br> 
     
    9696        ( figura 4.2 ) 
    9797        <br/>    
    98     <img src="templates/default/images/remover_contato.png" width="314" height="157" alt="Remover Contato" align="left"> 
     98    <img src="templates/default/images/remover_contato.png" width="359" height="125" alt="Remover Contato" align="left"> 
    9999    <br clear="all"> 
    100100    <br> 
     
    105105        ( figura 4.3 ) 
    106106        <br/> 
    107     <img src="templates/default/images/menu_right.png" width="151" height="108" alt="Preferências Avançadas" align="left"> 
     107    <img src="templates/default/images/menu_right.png" width="212" height="126" alt="Preferências Avançadas" align="left"> 
    108108    <br clear="all"/> 
    109109    <br/> 
     
    121121    <h2><a name="info_ad">7. Vcard - Informações Adicionais</a></h2> 
    122122        ( figura 5 ) 
    123     <img src="templates/default/images/info_adicionais.png" width="410" height="267" alt="Informações Adicionais" align="left"> 
     123    <img src="templates/default/images/info_adicionais.png" width="480" height="227" alt="Informações Adicionais" align="left"> 
    124124    <br clear="all"/> 
    125125    <br/> 
     
    130130    <h2><a name="info_prefe">8. Preferências</a></h2> 
    131131        ( figura 6 ) 
    132     <img src="templates/default/images/preferencias.png" width="356" height="270" alt="Preferências" align="left"> 
     132    <img src="templates/default/images/preferencias.png" width="405" height="284" alt="Preferências" align="left"> 
    133133    <br clear="all"/> 
    134134    <br/> 
     
    138138    <h2><a name="troca_mens">9. Troca de Mensagens</a></h2> 
    139139        ( figura 7 ) 
    140     <img src="templates/default/images/troca_mensagem.png" width="332" height="272" alt="Troca de Mensagens" align="left"> 
     140    <img src="templates/default/images/troca_mensagem.png" width="319" height="314" alt="Troca de Mensagens" align="left"> 
    141141    <br clear="all"/> 
    142142    <br/> 
    143143 
    144144        Clicando com o mouse em cima do nome do contato escolhido, abrirá uma janela ( conforme figura 7 ), para a troca de mensagens. Nessa mesma janela existe um menu, o qual é possível 
    145         configurar o formato da : Fonte, Tamanho, Cor e o Estilo. Você também pode enviar os Smiles, clicando nessa figura <img src="templates/default/images/img/1.gif">. 
     145        configurar o formato da Fonte como : <b>Negrito</b>, <i>Itálico</i> e a cor. Você também pode enviar os Smiles, clicando nessa figura <img src="templates/default/images/emoticonlabel.gif">. 
    146146 
    147147    <h2><a name="troca_status">10. Troca de Status</a></h2> 
     
    159159    <img src="templates/default/images/dnd.gif" align="top"> - Ocupado <br/> 
    160160    <img src="templates/default/images/unavailable.gif" align="top"> - Offline - Não recebe mensagem <br/>     
    161     <img src="templates/default/images/img/icon_edit.gif" align="top"> - Mensagem - Personalize sua mensagem <br/>         
     161    <img src="templates/default/images/icon_edit.gif" align="top"> - Mensagem - Personalize sua mensagem <br/>         
    162162 
    163163    <hr noshade> 
  • trunk/instant_messenger/xsl/add_user.xsl

    r140 r151  
    99                <select id="im_ldap_ou" onchange="im.ldap_search_ou(this);"></select> 
    1010                <span id="_span_load_im" style="background-color:#cc4444;color:white;display:none;position:absolute;right:5px;top:26px">Carregando .....</span>  
     11                <br/> 
    1112                <select id="im_ldap_user" size="10" class="add_user" onclick="im.ldap_adduser(this);"></select> 
    1213        </div> 
     
    1516                <tr> 
    1617                        <td class="add_user"><b><xsl:value-of select="table/lang1"/>.:</b></td> 
    17                         <td><input id="text0" type="text" size="40" maxlength="40" readonly="true" class="add_user" /></td>              
     18                        <td><input id="im_jid" type="text" size="40" maxlength="40" readonly="true" class="add_user" /></td>             
    1819                </tr> 
    1920                <tr> 
    2021                        <td class="add_user"><b><xsl:value-of select="table/lang2"/>.:</b></td> 
    21                         <td><input id="text1" type="text" size="20" maxlength="20" class="add_user" /></td>              
     22                        <td><input id="im_name" type="text" size="20" maxlength="20" class="add_user" onclick="javascript:im.focus_select(this,event);" onmousedown="javascript:im.focus_select(this,event);"/></td>             
    2223                </tr> 
    2324                <tr> 
    2425                        <td class="add_user"><b><xsl:value-of select="table/lang3"/>.:</b></td> 
    25                         <td><input id="text2" type="text" size="20" maxlength="20" class="add_user" /></td>              
     26                        <td><input id="im_group" type="text" size="20" maxlength="20" class="add_user" onclick="javascript:im.focus_select(this,event);" onmousedown="javascript:im.focus_select(this,event);"/></td>            
    2627                </tr> 
    2728                <tr> 
    28                         <td><input id="text3" type="hidden" size="30" maxlength="30" /></td> 
     29                        <td><input id="im_uid" type="hidden" size="30" maxlength="30" /></td> 
    2930                </tr>                                                    
    3031                <tr> 
    3132                        <td colspan="2"> 
    32                                 <input type="button" value="{table/lang4}" /> 
    33                                 <input type="button" value="{table/lang5}" onclick="javascript:buildIM.window_close('add_user_im');" /> 
     33                                <input type="button" value="{table/lang4}" onclick="javascript:im.adduser();"/> 
     34                                <input type="button" value="{table/lang5}" onclick="javascript:im_window.window_close('add_user_im');" /> 
    3435                                <span id="im_status_add" style="color:#f00;font-weight:bold;margin-left:10px;"></span>                   
    3536                        </td> 
  • trunk/instant_messenger/xsl/contacts.xsl

    r55 r151  
    33<xsl:output method="html" omit-xml-declaration="yes"/> 
    44 
    5 <xsl:template match="/retorno/contacts"> 
    6    <html> 
    7    <head> 
    8    </head> 
    9    <body> 
    10       <div id="all_groups"> 
    11          <xsl:apply-templates select="group" /> 
    12       </div> 
    13    </body> 
    14    </html> 
     5<xsl:template match="iq/query"> 
     6                <xsl:apply-templates select="." mode="list" />   
    157</xsl:template> 
    168 
    17 <xsl:template match="group"> 
    18    <div style="margin-left:16px;overflow:hidden;" id="{@name}"> 
    19       <b><xsl:value-of select="@name" /></b> 
    20       <br /> 
    21       <xsl:apply-templates select="item" /> 
    22    </div> 
     9<xsl:template match="*" mode="list"> 
     10   <div id="im_contact_list" style="margin:2px;width:auto;height:200px;overflow-y:auto;"> 
     11           <xsl:for-each select="item"> 
     12                        <xsl:sort select="group" case-order="upper-first" /> 
     13                        <xsl:choose> 
     14                                <xsl:when test="not(group = preceding-sibling::item/group)"> 
     15                                        <img id="group_{group[current()]}" src="/instant_messenger/templates/default/images/group_open.gif" onclick="javascript:im.group_close('{group[current()]}');"/> 
     16                                        <b><xsl:value-of select="group[current()]" /><br/></b> 
     17                                        <xsl:apply-templates select="." mode="contacts"/> 
     18                                </xsl:when> 
     19                                <xsl:otherwise> 
     20                                        <xsl:apply-templates select="." mode="contacts"/> 
     21                                </xsl:otherwise> 
     22                        </xsl:choose> 
     23           </xsl:for-each> 
     24        </div>     
    2325</xsl:template> 
    2426 
    25 <xsl:template match="item"> 
    26    <div style="cursor:pointer;margin-left:8px;width:2000px" onmouseover="this.className='contato_hover'" onmouseout="this.className=''" onmousedown="javascript:IM.action_button(event, '{@jid}');" id="{@jid}"> 
    27       <xsl:value-of select="@name" /> 
    28    </div> 
     27<xsl:template match="*" mode="contacts"> 
     28 
     29        <xsl:choose> 
     30                <xsl:when test="@name"> 
     31                        <div style="margin-left:15px;cursor:pointer;display:block;" id="{@jid}" idgroup="{group}" idname="{@name}" onmousedown="templates.options(event, '{@jid}');"> 
     32                                <img id="img_{@jid}" src="/instant_messenger/templates/default/images/unavailable.gif" style="margin:0px 2px" /> 
     33                                <xsl:value-of select="@name"/> 
     34                                <br/> 
     35                                <span id="status_{@jid}" style="font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-style:italic; display:none" /> 
     36                        </div> 
     37                        <div id="sub_{@jid}"></div>                                                      
     38                </xsl:when> 
     39                <xsl:otherwise> 
     40                        <div style="margin-left:15px;cursor:pointer;display:block;" id="{@jid}" idgroup="{group}" idname="" onmousedown="templates.options(event, '{@jid}');"> 
     41                                <img id="img_{@jid}" src="/instant_messenger/templates/default/images/unavailable.gif" style="margin:0px 2px" /> 
     42                                <xsl:value-of select="@jid"/> 
     43                                <br/> 
     44                                <span id="status_{@jid}" style="font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif; font-style:italic; display:none;" /> 
     45                        </div> 
     46                        <div id="sub_{@jid}"></div>                      
     47                </xsl:otherwise> 
     48        </xsl:choose> 
     49         
    2950</xsl:template> 
    3051 
  • trunk/instant_messenger/xsl/message.xsl

    r55 r151  
    11<?xml version="1.0" encoding="ISO-8859-1"?> 
    2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > 
    33<xsl:output method="html" omit-xml-declaration="yes"/> 
    44 
    5 <xsl:template match="/"> 
    6    <html> 
    7    <head> 
    8    </head> 
    9    <body> 
    10       <xsl:copy-of select="." /> 
    11    </body> 
    12    </html> 
     5<xsl:template match="message"> 
     6        <!-- <b><xsl:value-of select="@from" /> :</b><br /> --> 
     7        <b> :</b><br />  
     8        <!-- 
     9        linha abaixo apresenta problema quando envia mtas msg seguidas 
     10        entretanto linha que está habilitada na sequencia nãofunciona no psy 
     11        --> 
     12         
     13        <xsl:apply-templates select="descendant::*[name()='body' and preceding::body]" mode='body' /> 
     14         
     15        <!-- 
     16        <xsl:apply-templates select="html/body" mode='body' /> 
     17        --> 
     18</xsl:template> 
     19 
     20<xsl:template match="*" mode="body"> 
     21        <xsl:copy-of select="." /> 
     22        <br /> 
     23        <br /> 
    1324</xsl:template> 
    1425 
  • trunk/instant_messenger/xsl/preferences.xsl

    r55 r151  
    33<xsl:output method="html" omit-xml-declaration="yes"/> 
    44 
    5 <xsl:template match="/preferences"> 
    6    <html> 
    7    <head> 
    8    </head> 
    9    <body> 
    10           <div id="im_preferences" style="margin-left:5px;margin-top:5px"> 
    11                   <fieldset><legend> Opções :</legend> 
    12                           <input id="ch_offline" type="checkbox" /> Exibir amigos desconectados 
    13                   </fieldset> 
    14                   <br /> 
    15                   <fieldset><legend> Ausente : </legend>         
    16                           Ficar ausente depois de <input id="in_time" type="input" size="2" maxlength="2"/> minutos : 
    17                   </fieldset>            
    18                   <br />         
    19                   <fieldset> 
    20                           <legend> Ativar aviso de mensagens recebidas :</legend> 
    21                   <input id="rd_nm" type="radio" name="rd_aviso" /> Normal <br /> 
    22                           <input id="rd_ch" type="radio" name="rd_aviso" /> Treme Tela 
    23                   </fieldset> 
    24                         <br/> 
    25                         <input type="button" value="Salvar" onclick="javascript:IM_Preferences.SetYourPreferences();" /> 
    26                         <input type="button" value="Fechar" onclick="javascript:im_win.windowClose('divYourPreferences_im');"/> 
    27           </div> 
    28    </body> 
    29    </html> 
     5<xsl:template match="preferences"> 
     6        <dl style="margin:5px"> 
     7                <dt><a href="javascript:void(0);" onclick="javascript:{function1};"><img src="{path}templates/default/images/menu.gif"/><xsl:value-of select="lang1"/></a></dt> 
     8                <dt><a href="javascript:void(0);" onclick="javascript:{function2};"><img src="{path}templates/default/images/menu.gif"/><xsl:value-of select="lang2"/></a></dt> 
     9                <dt><a href="javascript:void(0);" onclick="javascript:{function3};"><img src="{path}templates/default/images/menu.gif"/><xsl:value-of select="lang3"/></a></dt> 
     10                <dt><a href="javascript:void(0);" onclick="javascript:{function4};"><img src="{path}templates/default/images/menu.gif"/><xsl:value-of select="lang4"/></a></dt> 
     11        </dl> 
    3012</xsl:template> 
    3113 
  • trunk/instant_messenger/xsl/remove_user.xsl

    r140 r151  
    1010                                <span style="margin-left:7px"> 
    1111                                        <input type="button" value="{lang2}" onclick="javascript:im.remove_contact('im_remove_contact');"/> 
    12                                         <input type="button" value="{lang3}" onclick="javascript:buildIM.window_close('remove_user_im');"/> 
     12                                        <input type="button" value="{lang3}" onclick="javascript:im_window.window_close('remove_user_im');"/> 
    1313                                </span> 
    1414                        </div> 
  • trunk/instant_messenger/xsl/vcard_contacts.xsl

    r55 r151  
    33<xsl:output method="html" omit-xml-declaration="yes"/> 
    44 
    5 <xsl:template match="/retorno/vcard"> 
    6    <html> 
    7    <head> 
    8    </head> 
    9    <body> 
    10       <div id="_im_vcard_contacts_childs"> 
    11          <xsl:apply-templates select="div" /> 
    12       </div> 
    13    </body> 
    14    </html> 
    15 </xsl:template> 
    16  
    17 <xsl:template match="div"> 
    18    <div id="{@id}"> 
    19       <FN><xsl:value-of select="FN" /></FN> 
    20       <NICKNAME><xsl:value-of select="NICKNAME" /></NICKNAME>       
    21       <ROLE><xsl:value-of select="ROLE" /></ROLE> 
    22       <ORGNAME><xsl:value-of select="ORG/ORGNAME" /></ORGNAME> 
    23       <ORGUNIT><xsl:value-of select="ORG/ORGUNIT" /></ORGUNIT> 
    24       <BDAY><xsl:value-of select="BDAY" /></BDAY> 
    25       <DESC><xsl:value-of select="DESC" /></DESC> 
    26    </div> 
     5<xsl:template match="/vcard_contact"> 
     6                <div class="vcard_contact"> 
     7                        <div style="margin:3px"> 
     8                                <label style="font-weight:bold;"><xsl:value-of select="lang1" /> .: </label> 
     9                                <xsl:choose> 
     10                                        <xsl:when test="div/@fn"> 
     11                                                <xsl:value-of select="div/@fn" /> 
     12                                        </xsl:when> 
     13                                        <xsl:otherwise> 
     14                                                <xsl:value-of select="div/@FN" /> 
     15                                        </xsl:otherwise> 
     16                                </xsl:choose> 
     17                        </div> 
     18                        <div style="margin:3px"> 
     19                                <label style="font-weight:bold;"><xsl:value-of select="lang2" /> .: </label> 
     20                                <xsl:choose> 
     21                                        <xsl:when test="div/@nickname"> 
     22                                                <xsl:value-of select="div/@nickname" /> 
     23                                        </xsl:when> 
     24                                        <xsl:otherwise> 
     25                                                <xsl:value-of select="div/@NICKNAME" />                                          
     26                                        </xsl:otherwise>                                                 
     27                        </xsl:choose>                            
     28                        </div> 
     29                        <div style="margin:3px"> 
     30                                <label style="font-weight:bold;"><xsl:value-of select="lang3" /> .: </label> 
     31                                <xsl:choose>     
     32                                        <xsl:when test="div/@orgname"> 
     33                                                <xsl:value-of select="div/@orgname" /> 
     34                                        </xsl:when> 
     35                                        <xsl:otherwise> 
     36                                                <xsl:value-of select="div/@ORGNAME" /> 
     37                                        </xsl:otherwise> 
     38                                </xsl:choose> 
     39                        </div> 
     40                        <div style="margin:3px"> 
     41                                <label style="font-weight:bold;"><xsl:value-of select="lang4" /> .: </label> 
     42                                <xsl:choose> 
     43                                        <xsl:when test="div/@org"> 
     44                                                <xsl:value-of select="div/@org" /> 
     45                                        </xsl:when> 
     46                                        <xsl:otherwise> 
     47                                                <xsl:value-of select="div/@ORG" /> 
     48                                        </xsl:otherwise> 
     49                                </xsl:choose>                                    
     50                        </div> 
     51                        <div style="margin:3px"> 
     52                                <label style="font-weight:bold;"><xsl:value-of select="lang5" /> .: </label> 
     53                                <xsl:choose> 
     54                                        <xsl:when test="div/@role"> 
     55                                                <xsl:value-of select="div/@role" /> 
     56                                        </xsl:when> 
     57                                        <xsl:otherwise> 
     58                                                <xsl:value-of select="div/@ROLE" /> 
     59                                        </xsl:otherwise> 
     60                                </xsl:choose> 
     61                        </div> 
     62                        <div style="margin:3px">         
     63                                <label style="font-weight:bold;"><xsl:value-of select="lang6" /> .: </label> 
     64                                <xsl:choose> 
     65                                        <xsl:when test="div/@bday"> 
     66                                                <xsl:value-of select="div/@bday" /> 
     67                                        </xsl:when> 
     68                                        <xsl:otherwise> 
     69                                                <xsl:value-of select="div/@BDAY" /> 
     70                                        </xsl:otherwise> 
     71                                </xsl:choose> 
     72                        </div> 
     73                        <div style="margin:5px 0px"> 
     74                                <input type="button" value="{lang7}" onclick="javascript:im_window.window_close('{id}');" /> 
     75                        </div> 
     76                </div> 
     77                 
    2778</xsl:template> 
    2879 
  • trunk/instant_messenger/xsl/window.xsl

    r63 r151  
    44 
    55<xsl:template match="/window"> 
    6    <html> 
    7    <head> 
    8    </head> 
    9    <body> 
    10       <div id="{@id}_im_window_master" class="master" style="top:{@top};left:{@left};height:{(@height + 48)};width:{(@width + 12)};{@style};"> 
    11         <div id="{@id}_im_window" class="pai" style="height:{(@height + 40)};"> 
    12                 <div id="{@id}_im_window_icon" class="im_window_icon" /> 
    13             <div class="tit"><xsl:value-of select="@title" /></div> 
    14             <xsl:apply-templates select="/" mode='buttons' /> 
    15             <div class="filho" id="{@id}_im_window_body_inner" style="width:{@width};height:{@height};" /> 
    16          </div>       
    17       </div> 
    18  
    19       <div class="im-windowfantom-des" id="{@id}_im_window_fantom" /> 
    20       <div class="im-windowfantom-des" id="{@id}_im_window_movable" /> 
    21       <div class="im-window-resizehandle" id="{@id}_im_window_resize" style="visibility:hidden;" /> 
    22    </body> 
    23    </html> 
    24 </xsl:template> 
    25  
    26 <xsl:template match="/window" mode="buttons"> 
    27    <xsl:if test='@close and @close="true"'> 
    28       <div class="im-window-button im-window-closebutton" style="z-index:6000;right:4px" onclick="im_win.windowClose(this.parentNode.id);" /> 
    29    </xsl:if> 
    30  
    31    <xsl:if test='@maximize and @maximize="true"'> 
    32       <xsl:choose> 
    33          <xsl:when test='@close and @close="true"'> 
    34             <div class="im-window-button im-window-maximizerestorebutton" style="z-index:6000;right:20px" onclick="im_win.windowMaximizeRestore(this.parentNode.id);" /> 
    35          </xsl:when> 
    36          <xsl:otherwise> 
    37             <div class="im-window-button im-window-maximizerestorebutton" style="z-index:6000;right:4px" onclick="im_win.windowMaximizeRestore(this.parentNode.id);" /> 
    38          </xsl:otherwise> 
    39       </xsl:choose> 
    40    </xsl:if> 
    41  
    42    <xsl:if test='@minimize and @minimize="true"'> 
    43       <xsl:choose> 
    44          <xsl:when test='@close and @close="true" and @maximize and @maximize="true"'> 
    45             <div class="im-window-button im-window-minimizebutton" style="z-index:6000;right:36px" onclick="im_win.windowMinimize(this.parentNode.id);" /> 
    46          </xsl:when> 
    47          <xsl:when test='(@close and @close="true" or @maximize and @maximize="true") and not (@close and @close="true" and @maximize and @maximize="true")'> 
    48             <div class="im-window-button im-window-minimizebutton" style="z-index:6000;right:20px" onclick="im_win.windowMinimize(this.parentNode.id);" /> 
    49          </xsl:when> 
    50          <xsl:otherwise> 
    51             <div class="im-window-button im-window-minimizebutton" style="z-index:6000;right:4px" onclick="im_win.windowMinimize(this.parentNode.id);" /> 
    52          </xsl:otherwise> 
    53       </xsl:choose> 
    54    </xsl:if> 
     6        <div id="{name}_window_master" style="width:{width};" class="window" onmousedown="javascript:drag_drop.drag(event,this); javascript:im_window.window_focus(this);" dragdrop="true"> 
     7                <b class="corner blackcorner"> 
     8                        <b class="corner1 blackcorner1"><b></b></b> 
     9                        <b class="corner2 blackcorner2"><b></b></b> 
     10                        <b class="corner3 blackcorner3"></b> 
     11                        <b class="corner4 blackcorner4"></b> 
     12                        <b class="corner5 blackcorner5"></b> 
     13                </b> 
     14                <div class="titulo" dragdrop="true"> 
     15                        <span id="{name}_window_title" style="float:left;" dragdrop="true"> 
     16                                <xsl:value-of select="title" /> 
     17                        </span> 
     18                        <div id="{name}_window_title_buttons" style="float:right;"> 
     19                                <div id="{name}_button_minimize" style="display: {pButMin};" class="button_minimize" onclick="javascript:im_window.window_minimize('{name}');"></div> 
     20                                <div id="{name}_button_maximize" style="display: {pButMax};" class="button_maximize1" onclick="javascript:im_window.window_maximize('{name}');"></div> 
     21                                <div id="{name}_button_close" style="display: {pButClose};" class="button_close" onclick="javascript:im_window.window_close('{name}');"></div> 
     22                        </div> 
     23                </div> 
     24                <div id="{name}_window_body" class="body"> 
     25                        <div id="{name}_window_body_content" class="content" style="overflow:auto;"> 
     26                                <xsl:copy-of select="content" /> 
     27                        </div> 
     28                </div> 
     29                <div id="{name}_window_bottom" class="rodape" dragdrop="false"></div> 
     30        </div> 
    5531</xsl:template> 
    5632 
Note: See TracChangeset for help on using the changeset viewer.