From 6682f91db69d6f983acbf37ef7cf8aa8d93e9e1c Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 22 Oct 2006 22:00:24 +0000 Subject: [PATCH] concise is better git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1009 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/pltableeditor.php | 12 +-- classes/xmlrpcclient.php | 233 ++++++++++++++-------------------------------- 2 files changed, 74 insertions(+), 171 deletions(-) diff --git a/classes/pltableeditor.php b/classes/pltableeditor.php index 39eb9e7..955ac30 100644 --- a/classes/pltableeditor.php +++ b/classes/pltableeditor.php @@ -61,7 +61,7 @@ class PLTableEditor { // desc will be the title of the column $a['desc'] = $a['Field']; $a['display'] = true; - + if (substr($a['Type'],0,8) == 'varchar(') { // limit editing box size $a['Size'] = $a['Maxlength'] = substr($a['Type'], 8, strlen($a['Type']) - 9); @@ -102,7 +102,7 @@ class PLTableEditor { if ($descr['Type'] == 'timestamp') { // set readable timestamp $date =& $entry[$field]; - $date = preg_replace('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', '\3/\2/\1 \4:\5:\6', $date); + $date = preg_replace('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', '\3/\2/\1 \4:\5:\6', $date); } if ($descr['Type'] == 'date') { $date =& $entry[$field]; @@ -116,7 +116,7 @@ class PLTableEditor { $this->vars[$name]['desc'] = $desc; $this->vars[$name]['display'] = $display; } - // add a join table, when deleting a row corresponding entries will be deleted in these tables + // add a join table, when deleting a row corresponding entries will be deleted in these tables function add_join_table($name,$joinid,$joindel,$joinextra="") { if ($joindel) $this->jtables[$name] = array("joinid" => $joinid,"joinextra" => $joinextra?(" AND ".$joinextra):""); @@ -186,9 +186,9 @@ class PLTableEditor { } $val = "'".addslashes($val)."'"; } elseif (Post::has($field)) { - $val = Post::v($field); + $val = Post::v($field); if ($descr['Type'] == 'timestamp') { - $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/', '\3\2\1\4\5\6', $val); + $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/', '\3\2\1\4\5\6', $val); } elseif ($descr['Type'] == 'date') { $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})/', '\3-\2-\1', $val); @@ -196,7 +196,7 @@ class PLTableEditor { $val = "'".addslashes($val)."'"; } else { $cancel = true; - $page->trig("Il manque le champ ".$field); + $page->trig("Il manque le champ ".$field); } $values .= $val; } diff --git a/classes/xmlrpcclient.php b/classes/xmlrpcclient.php index 8784a0c..3f50e7a 100644 --- a/classes/xmlrpcclient.php +++ b/classes/xmlrpcclient.php @@ -1,146 +1,5 @@ url = $url; $this->urlparts = parse_url($this->url); - foreach (array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) { - if (!isset($this->urlparts[$part])) { - $this->urlparts[$part] = null; - } + + if (empty($this->urlparts['port'])) { + $this->urlparts['port'] = 80; } + + if (empty($this->urlparts['path'])) { + $this->urlparts['path'] = '/'; + } + } + + private function http_post($request) + { + $host = $path = $port = $user = $pass = null; + extract($this->urlparts); + + if ($scheme == 'https') { + $host = 'ssl://'.$host; + } + + $query_fd = fsockopen($host, $port, $errno, $errstr, 10); + if (!$query_fd) + return null; + + $auth = ''; + if ($user) { + $auth = 'Authorization: Basic ' . base64_encode("$user:$pass") . "\r\n"; + } + + $content_len = strlen($request); + $http_request = + "POST $path HTTP/1.0\r\n" . + $auth . + "Content-Type: text/xml\r\n" . + "Content-Length: $content_len\r\n" . + "Connection: Close\r\n" . + "Host: $host:$port\r\n" . + "\r\n" . + $request; + + fputs($query_fd, $http_request, strlen($http_request)); + + $buf = ''; + while (!feof($query_fd)) { + $buf .= fread($query_fd, 8192); + } + + fclose($query_fd); + return $buf; + } + + private function find_and_decode_xml($buf) + { + $pos = strpos($buf, 'urlparts['host']; - $requestprms['port'] = $this->urlparts['port']; - $requestprms['uri'] = $this->urlparts['path']; - $requestprms['user'] = $this->urlparts['user']; - $requestprms['pass'] = $this->urlparts['pass']; - $requestprms['method'] = $function; - $requestprms['args'] = $arguments; - $requestprms['timeout'] = 0; - $requestprms['secure'] = 0; - - $result = xu_rpc_http_concise($requestprms); + $query = xmlrpc_encode_request($method, $args); + $answer = $this->http_post($query, $this->urlparts); + $result = $this->find_and_decode_xml($answer); + if (is_array($result) && isset($result['faultCode'])) { - print('Error in xmlrpc call \''.$function.'\''."\n"); - print(' code : '.$result['faultCode']."\n"); - print(' message: '.$result['faultString']."\n"); + trigger_error("Error in xmlrpc call $function\n". + " code : {$result['faultCode']}\n". + " message: {$result['faultString']}\n"); return null; } return $result; } - } // vim:set et sw=4 sts=4 sws=4: -- 2.1.4