source: trunk/expressoMail1_2/inc/class.functions.inc.php @ 1503

Revision 1503, 5.7 KB checked in by rodsouza, 15 years ago (diff)

Ticket #622 - Utilizar XML para internacionalização.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        class Functions{
3                function CallVoipConnect($params){
4                        $fromNumber = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['telephone_number'];
5                        if(!$fromNumber)
6                                return false;
7                        $fromNumber = substr($fromNumber,strlen($fromNumber) - 4, strlen($fromNumber) - 1);
8                        $toNumber       = $params['to'] ? substr($params['to'],strlen($params['to']) - 4, strlen($params['to']) - 1) : 0;
9                       
10                        $voipServer     = $_SESSION['phpgw_info']['expressomail']['server']['voip_server'];
11                        $voipUrl        = $_SESSION['phpgw_info']['expressomail']['server']['voip_url'];
12                        $voipPort       = $_SESSION['phpgw_info']['expressomail']['server']['voip_port'];
13                       
14                        // Se for celular, passa os digitos do número e conecta com outro VoIP Server.....
15                        if($params['typePhone'] == 'mob'){
16                                $toNumber       = $params['to'];
17                                $voipServer     = $_SESSION['phpgw_info']['expressomail']['server']['voip_server'];
18                                $voipUrl        = $_SESSION['phpgw_info']['expressomail']['server']['voip_url'];
19                                $voipPort       = $_SESSION['phpgw_info']['expressomail']['server']['voip_port'];                               
20                        }       
21                               
22                        if(!$voipServer || !$voipUrl || !$voipPort)
23                                return false;
24                        $url            = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber;                 
25                        $sMethod = 'GET ';
26            $crlf = "\r\n";
27            $sRequest = " HTTP/1.1" . $crlf;
28            $sRequest .= "Host: localhost" . $crlf;
29            $sRequest .= "Accept: */* " . $crlf;
30            $sRequest .= "Connection: Close" . $crlf . $crlf;           
31            $sRequest = $sMethod . $url . $sRequest;   
32            $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);           
33            if (!$sockHttp)  {
34                return false;
35            }
36            $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort);
37            if (!$resSocketConnect) {
38                return false;
39            }
40            $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest));
41            if (!$resSocketWrite) {
42                return false;
43            }   
44            $sResponse = '';   
45            while ($sRead = socket_read($sockHttp, 512)) {
46                $sResponse .= $sRead;
47            }           
48           
49            socket_close($sockHttp);           
50            $pos = strpos($sResponse, $crlf . $crlf);
51            return substr($sResponse, $pos + 2 * strlen($crlf));                                                                       
52                }
53
54                function getDirContents($dir){
55                        //$dir = dirname($dir);
56       
57                        if (!is_dir($dir))      {
58                                        return 'Error: Cannot load files in :'. $dir.' !';
59                        }
60                       
61                        if ($root=@opendir($dir))       {
62                       
63                       while ($file=readdir($root))     {                 
64                           if($file!="." && $file!="..")
65                                   $files[]=$dir."/".$file;           
66                       }
67                       
68                        }
69                       
70                   return $files;
71                }
72                               
73                function getFilesJs($includeFiles = '', $update_version = ''){
74                       
75                        $files = $this -> getDirContents('js');
76                        $str_files = '';
77                       
78                        if($includeFiles) {
79                                $includeFiles = explode(",",trim($includeFiles));
80                                // Bug fixed for array_search function
81                                $includeFiles[count($includeFiles)] = $includeFiles[0];
82                                $includeFiles[0] = null;
83                                // End Bug fixed.
84                        }                                                                                                               
85                        for($i = 0; $i < count($files); $i++) {                         
86                                if(count(explode('.js',$files[$i])) > 1) {
87                                        if($includeFiles  && array_search(trim($files[$i]),$includeFiles)){     
88                                                $str_files .= "<script src='".$files[$i]."?".$update_version."' type='text/javascript'></script>";                                             
89                                        }
90                                }
91                        }
92                       
93                        return $str_files;
94                }                                                               
95
96                function getReturnExecuteForm(){
97                        $response = $_SESSION['response'];
98                        $_SESSION['response'] = null;
99                        return $response;
100                }
101
102                function getLang( $key )
103                {
104                        static $language = NULL;
105
106                        if ( ! $language )
107                        {
108                                $_SESSION[ 'debug' ][ 'init_t' ] = time( );
109                                $_SESSION[ 'debug' ][ 'init_m' ] = microtime( );
110
111                                $xml = new DOMDocument;
112                                $xml -> preserveWhiteSpace = false;
113                                $xml -> load( dirname( __FILE__ )
114                                        . '/../setup/phpgw_'
115                                        . $_SESSION['phpgw_info']['expressomail']['user']['preferences']['common']['lang']
116                                        . '.xml'
117                                );
118
119                                $xpath = new DOMXPath( $xml );
120
121                                $_key = 'key';
122                                $_lang = 'translation';
123
124                                $language = array( );
125                                foreach( $xml -> documentElement -> childNodes as $entry )
126                                        $language[ $xpath->query( $_key, $entry ) -> item( 0 ) -> nodeValue ] = $xpath->query( $_lang, $entry ) -> item( 0 ) -> nodeValue;
127
128                                $_SESSION[ 'debug' ][ 'end_t' ] = time( );
129                                $_SESSION[ 'debug' ][ 'end_m' ] = microtime( );
130                        }
131
132                        if ( array_key_exists( $key, $language ) )
133                                return $language[ $key ];
134                        else
135                                return ( $key . '*' );
136                }
137
138                function get_preferences()      {
139                        return $_SESSION['phpgw_info']['user']['preferences']['expressoMail'];
140                }
141                // Unicode Conversor: convert everything from UTF-8 into an NCR[Numeric Character Reference]
142                function utf8_to_ncr($content)  {
143            $result = "";           
144            while ($strlen = mb_strlen($content)) {
145                $c = mb_substr($content, 0, 1, "UTF-8");
146                $h = ord($c{0});   
147                    if ($h <= 0x7F || $h < 0xC2) {
148                        $result .= $c;
149                    }
150                        else if ($h <= 0xDF) {
151                        $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
152                        $result .= "&#" . $h . ";";
153                    } else if ($h <= 0xEF) {
154                        $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F);
155                        $result .= "&#" . $h . ";";
156                    } else if ($h <= 0xF4) {
157                        $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F);
158                        $result .= "&#" . $h . ";";
159                    }               
160                $content = mb_substr( $content, 1, $strlen, "UTF-8");
161            }
162            return mb_convert_encoding($result,"UTF-8");
163        }
164    }   
165?>
Note: See TracBrowser for help on using the repository browser.