当前位置: 首页>>代码示例>>PHP>>正文


PHP KSort函数代码示例

本文整理汇总了PHP中KSort函数的典型用法代码示例。如果您正苦于以下问题:PHP KSort函数的具体用法?PHP KSort怎么用?PHP KSort使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了KSort函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ValidateEmailHost

 function ValidateEmailHost($email, $hosts = 0)
 {
     if (!$this->ValidateEmailAddress($email)) {
         return 0;
     }
     $user = strtok($email, "@");
     $domain = strtok("");
     if (GetMXRR($domain, &$hosts, &$weights)) {
         $mxhosts = array();
         for ($host = 0; $host < count($hosts); $host++) {
             $mxhosts[$weights[$host]] = $hosts[$host];
         }
         KSort($mxhosts);
         for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
             $hosts[$host] = $mxhosts[Key($mxhosts)];
         }
     } else {
         $hosts = array();
         if (strcmp(@gethostbyname($domain), $domain) != 0) {
             $hosts[] = $domain;
         }
     }
     return count($hosts) != 0;
 }
开发者ID:Pengzw,项目名称:c3crm,代码行数:24,代码来源:email_validation.php

示例2: Connect

 function Connect($domain = "")
 {
     if (strcmp($this->state, "Disconnected")) {
         $this->error = "connection is already established";
         return 0;
     }
     $this->disconnected_error = 0;
     $this->error = $error = "";
     $this->esmtp_host = "";
     $this->esmtp_extensions = array();
     $hosts = array();
     if ($this->direct_delivery) {
         if (strlen($domain) == 0) {
             return 1;
         }
         $hosts = $weights = $mxhosts = array();
         $getmxrr = $this->getmxrr;
         if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
             for ($host = 0; $host < count($hosts); $host++) {
                 $mxhosts[$weights[$host]] = $hosts[$host];
             }
             KSort($mxhosts);
             for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
                 $hosts[$host] = $mxhosts[Key($mxhosts)];
             }
         } else {
             if (strcmp(@gethostbyname($domain), $domain) != 0) {
                 $hosts[] = $domain;
             }
         }
     } else {
         if (strlen($this->host_name)) {
             $hosts[] = $this->host_name;
         }
         if (strlen($this->pop3_auth_host)) {
             $user = $this->user;
             if (strlen($user) == 0) {
                 $this->error = "it was not specified the POP3 authentication user";
                 return 0;
             }
             $password = $this->password;
             if (strlen($password) == 0) {
                 $this->error = "it was not specified the POP3 authentication password";
                 return 0;
             }
             $domain = $this->pop3_auth_host;
             $this->error = $this->ConnectToHost($domain, $this->pop3_auth_port, "Resolving POP3 authentication host \"" . $domain . "\"...");
             if (strlen($this->error)) {
                 return 0;
             }
             if (strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication server greeting was not found";
                 return 0;
             }
             if (!$this->PutLine("USER " . $this->user) || strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication user was not accepted: " . $this->Tokenize("\r\n");
                 return 0;
             }
             if (!$this->PutLine("PASS " . $password) || strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication password was not accepted: " . $this->Tokenize("\r\n");
                 return 0;
             }
             fclose($this->connection);
             $this->connection = 0;
         }
     }
     if (count($hosts) == 0) {
         $this->error = "could not determine the SMTP to connect";
         return 0;
     }
     for ($host = 0, $error = "not connected"; strlen($error) && $host < count($hosts); $host++) {
         $domain = $hosts[$host];
         $error = $this->ConnectToHost($domain, $this->host_port, "Resolving SMTP server domain \"{$domain}\"...");
     }
     if (strlen($error)) {
         $this->error = $error;
         return 0;
     }
     $timeout = $this->data_timeout ? $this->data_timeout : $this->timeout;
     if ($timeout && function_exists("socket_set_timeout")) {
         socket_set_timeout($this->connection, $timeout, 0);
     }
     if ($this->debug) {
         $this->OutputDebug("Connected to SMTP server \"" . $domain . "\".");
     }
     if (!strcmp($localhost = $this->localhost, "") && !strcmp($localhost = getenv("SERVER_NAME"), "") && !strcmp($localhost = getenv("HOST"), "")) {
         $localhost = "localhost";
     }
     $success = 0;
     if ($this->VerifyResultLines("220", $responses) > 0) {
         $success = $this->StartSMTP($localhost);
//.........这里部分代码省略.........
开发者ID:automatweb,项目名称:automatweb_sales,代码行数:101,代码来源:smtp.php

示例3: SendAPIRequest

 function SendAPIRequest($url, $method, $parameters, $oauth, $options, &$response)
 {
     $this->response_status = 0;
     $http = new http_class();
     $http->debug = $this->debug && $this->debug_http;
     $http->log_debug = true;
     $http->sasl_authenticate = 0;
     $http->user_agent = $this->oauth_user_agent;
     if ($this->debug) {
         $this->OutputDebug('Accessing the ' . $options['Resource'] . ' at ' . $url);
     }
     $arguments = array();
     $method = strtoupper($method);
     $authorization = '';
     $type = isset($options['RequestContentType']) ? strtolower(trim(strtok($options['RequestContentType'], ';'))) : 'application/x-www-form-urlencoded';
     if (isset($oauth)) {
         $values = array('oauth_consumer_key' => $this->client_id, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
         if ($this->url_parameters && $type === 'application/x-www-form-urlencoded' && count($parameters)) {
             $first = strpos($url, '?') === false;
             foreach ($parameters as $parameter => $value) {
                 $url .= ($first ? '?' : '&') . UrlEncode($parameter) . '=' . UrlEncode($value);
             }
             $parameters = array();
         }
         $value_parameters = $type !== 'application/x-www-form-urlencoded' ? array() : $parameters;
         $values = array_merge($values, $oauth, $value_parameters);
         $uri = strtok($url, '?');
         $sign = $method . '&' . $this->Encode($uri) . '&';
         $first = true;
         $sign_values = $values;
         $u = parse_url($url);
         if (isset($u['query'])) {
             parse_str($u['query'], $q);
             foreach ($q as $parameter => $value) {
                 $sign_values[$parameter] = $value;
             }
         }
         KSort($sign_values);
         foreach ($sign_values as $parameter => $value) {
             $sign .= $this->Encode(($first ? '' : '&') . $parameter . '=' . $this->Encode($value));
             $first = false;
         }
         $key = $this->Encode($this->client_secret) . '&' . $this->Encode($this->access_token_secret);
         $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
         if ($this->authorization_header) {
             $authorization = 'OAuth';
             $first = true;
             foreach ($values as $parameter => $value) {
                 $authorization .= ($first ? ' ' : ',') . $parameter . '="' . $this->Encode($value) . '"';
                 $first = false;
             }
         } else {
             if ($method === 'GET') {
                 $first = strcspn($url, '?') == strlen($url);
                 foreach ($values as $parameter => $value) {
                     $url .= ($first ? '?' : '&') . $parameter . '=' . $this->Encode($value);
                     $first = false;
                 }
                 $post_values = array();
             } else {
                 $post_values = $values;
             }
         }
     }
     if (strlen($error = $http->GetRequestArguments($url, $arguments))) {
         return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
     }
     if (strlen($error = $http->Open($arguments))) {
         return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
     }
     $arguments['RequestMethod'] = $method;
     switch ($type) {
         case 'application/x-www-form-urlencoded':
             if (isset($options['RequestBody'])) {
                 return $this->SetError('the request body is defined automatically from the parameters');
             }
             $arguments['PostValues'] = $parameters;
             break;
         case 'application/json':
             $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
             if (!isset($options['RequestBody'])) {
                 $arguments['Body'] = json_encode($parameters);
                 break;
             }
         default:
             if (!isset($options['RequestBody'])) {
                 return $this->SetError('it was not specified the body value of the of the API call request');
             }
             $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
             $arguments['Body'] = $options['RequestBody'];
             break;
     }
     $arguments['Headers']['Accept'] = isset($options['Accept']) ? $options['Accept'] : '*/*';
     if (strlen($authorization)) {
         $arguments['Headers']['Authorization'] = $authorization;
     }
     if (strlen($error = $http->SendRequest($arguments)) || strlen($error = $http->ReadReplyHeaders($headers))) {
         $http->Close();
         return $this->SetError('it was not possible to retrieve the ' . $options['Resource'] . ': ' . $error);
     }
//.........这里部分代码省略.........
开发者ID:huangciyin,项目名称:pH7-Social-Dating-CMS,代码行数:101,代码来源:oauth_client.php

示例4: ValidateEmailHost

 function ValidateEmailHost($email, &$hosts)
 {
     if (!$this->ValidateEmailAddress($email)) {
         return 0;
     }
     $user = $this->Tokenize($email, "@");
     $domain = $this->Tokenize("");
     $hosts = $weights = array();
     $getmxrr = $this->getmxrr;
     if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
         $mxhosts = array();
         for ($host = 0; $host < count($hosts); $host++) {
             $mxhosts[$weights[$host]] = $hosts[$host];
         }
         KSort($mxhosts);
         for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
             $hosts[$host] = $mxhosts[Key($mxhosts)];
         }
     } else {
         if (strcmp($ip = @gethostbyname($domain), $domain) && (strlen($this->exclude_address) == 0 || strcmp(@gethostbyname($this->exclude_address), $ip))) {
             $hosts[] = $domain;
         }
     }
     return count($hosts) != 0;
 }
开发者ID:BackupTheBerlios,项目名称:ascore,代码行数:25,代码来源:lib_DNS.php

示例5: Sign

 function Sign(&$url, $method, $parameters, $oauth, $request_content_type, $has_files, $post_values_in_uri, &$authorization, &$post_values)
 {
     $values = array('oauth_consumer_key' => $this->client_id, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => $this->signature_method, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
     if ($has_files) {
         $value_parameters = array();
     } else {
         if (($this->url_parameters || $method !== 'POST') && $request_content_type === 'application/x-www-form-urlencoded' && count($parameters)) {
             $first = strpos($url, '?') === false;
             foreach ($parameters as $parameter => $value) {
                 $url .= ($first ? '?' : '&') . UrlEncode($parameter) . '=' . UrlEncode($value);
                 $first = false;
             }
             $parameters = array();
         }
         $value_parameters = $request_content_type !== 'application/x-www-form-urlencoded' ? array() : $parameters;
     }
     $header_values = $method === 'GET' ? array_merge($values, $oauth, $value_parameters) : array_merge($values, $oauth);
     $values = array_merge($values, $oauth, $value_parameters);
     $key = $this->Encode($this->client_secret) . '&' . $this->Encode($this->access_token_secret);
     switch ($this->signature_method) {
         case 'PLAINTEXT':
             $values['oauth_signature'] = $key;
             break;
         case 'HMAC-SHA1':
             $uri = strtok($url, '?');
             $sign = $method . '&' . $this->Encode($uri) . '&';
             $first = true;
             $sign_values = $values;
             $u = parse_url($url);
             if (isset($u['query'])) {
                 parse_str($u['query'], $q);
                 foreach ($q as $parameter => $value) {
                     $sign_values[$parameter] = $value;
                 }
             }
             KSort($sign_values);
             foreach ($sign_values as $parameter => $value) {
                 $sign .= $this->Encode(($first ? '' : '&') . $parameter . '=' . $this->Encode($value));
                 $first = false;
             }
             $header_values['oauth_signature'] = $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
             break;
         default:
             return $this->SetError($this->signature_method . ' signature method is not yet supported');
     }
     if ($this->authorization_header) {
         $authorization = 'OAuth';
         $first = true;
         foreach ($header_values as $parameter => $value) {
             $authorization .= ($first ? ' ' : ',') . $parameter . '="' . $this->Encode($value) . '"';
             $first = false;
         }
         $post_values = $parameters;
     } else {
         if ($method !== 'POST' || $post_values_in_uri) {
             $first = strcspn($url, '?') == strlen($url);
             foreach ($values as $parameter => $value) {
                 $url .= ($first ? '?' : '&') . $parameter . '=' . $this->Encode($value);
                 $first = false;
             }
             $post_values = array();
         } else {
             $post_values = $values;
         }
     }
     return true;
 }
开发者ID:sukanyamandal,项目名称:open,代码行数:67,代码来源:oauth_client.php

示例6: UIntersectArrayMerge

 static function UIntersectArrayMerge($Array1, $Array2, $CompareFunction)
 {
     $ResultArray = Array_UIntersect_Assoc($Array1, $Array2, $CompareFunction) + $Array2;
     KSort($ResultArray);
     return $ResultArray;
 }
开发者ID:davispuh,项目名称:php-utils,代码行数:6,代码来源:Utilities.php

示例7: Connect

 function Connect($domain = "")
 {
     $this->error = $error = "";
     $this->esmtp_host = "";
     $this->esmtp_extensions = array();
     $hosts = array();
     if ($this->direct_delivery) {
         if (strlen($domain) == 0) {
             return 1;
         }
         $hosts = $weights = $mxhosts = array();
         $getmxrr = $this->getmxrr;
         if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
             for ($host = 0; $host < count($hosts); $host++) {
                 $mxhosts[$weights[$host]] = $hosts[$host];
             }
             KSort($mxhosts);
             for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
                 $hosts[$host] = $mxhosts[Key($mxhosts)];
             }
         } else {
             if (strcmp(@gethostbyname($domain), $domain) != 0) {
                 $hosts[] = $domain;
             }
         }
     } else {
         if (strlen($this->host_name)) {
             $hosts[] = $this->host_name;
         }
     }
     if (count($hosts) == 0) {
         $this->error = "could not determine the SMTP to connect";
         return 0;
     }
     if (strcmp($this->state, "Disconnected")) {
         $this->error = "connection is already established";
         return 0;
     }
     for ($host = 0;; $host++) {
         $domain = $hosts[$host];
         if (ereg('^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$', $domain)) {
             $ip = $domain;
         } else {
             if ($this->debug) {
                 $this->OutputDebug("Resolving SMTP server domain \"{$domain}\"...");
             }
             if (!strcmp($ip = @gethostbyname($domain), $domain)) {
                 $ip = "";
             }
         }
         if (strlen($ip) == 0 || strlen($this->exclude_address) && !strcmp(@gethostbyname($this->exclude_address), $ip)) {
             if ($host == count($hosts) - 1) {
                 $this->error = "could not resolve the host domain \"" . $domain . "\"";
                 return 0;
             }
             continue;
         }
         if ($this->debug) {
             $this->OutputDebug("Connecting to SMTP server ip \"{$ip}\"...");
         }
         if ($this->connection = $this->timeout ? fsockopen($ip, $this->host_port, $errno, $error, $this->timeout) : fsockopen($ip, $this->host_port)) {
             break;
         }
         if ($host == count($hosts) - 1) {
             switch ($this->timeout ? strval($error) : "??") {
                 case "-3":
                     $this->error = "-3 socket could not be created";
                     break;
                 case "-4":
                     $this->error = "-4 dns lookup on hostname \"" . $domain . "\" failed";
                     break;
                 case "-5":
                     $this->error = "-5 connection refused or timed out";
                     break;
                 case "-6":
                     $this->error = "-6 fdopen() call failed";
                     break;
                 case "-7":
                     $this->error = "-7 setvbuf() call failed";
                     break;
                 default:
                     $this->error = $error . " could not connect to the host \"" . $this->host_name . "\"";
                     break;
             }
             return 0;
         }
     }
     if ($this->debug) {
         $this->OutputDebug("Connected to SMTP server ip \"{$ip}\".");
     }
     if (!strcmp($localhost = $this->localhost, "") && !strcmp($localhost = getenv("SERVER_NAME"), "") && !strcmp($localhost = getenv("HOST"), "")) {
         $localhost = "localhost";
     }
     $success = 0;
     if ($this->VerifyResultLines("220", $responses) > 0) {
         if ($this->esmtp || strlen($this->user)) {
             if ($this->PutLine("EHLO {$localhost}") && $this->VerifyResultLines("250", $responses) > 0) {
                 $this->esmtp_host = $this->Tokenize($responses[0], " ");
                 for ($response = 1; $response < count($responses); $response++) {
                     $extension = strtoupper($this->Tokenize($responses[$response], " "));
//.........这里部分代码省略.........
开发者ID:innomatic-libs,项目名称:smtpsendlib,代码行数:101,代码来源:SMTPSend.php

示例8: Comp_Load

    $Comp = Comp_Load('Formats/Percent', $WorkComplite['Discont']);
    if (Is_Error($Comp)) {
        return ERROR | @Trigger_Error(500);
    }
    #-------------------------------------------------------------------------------
    $Cost = Comp_Load('Formats/Currency', $WorkComplite['Cost']);
    if (Is_Error($Cost)) {
        return ERROR | @Trigger_Error(500);
    }
    #-------------------------------------------------------------------------------
    $Verifies[$CreateDate] = array('Founding' => SPrintF('%s %s', $WorkComplite['Service'], $WorkComplite['Comment']), 'Measure' => $WorkComplite['Measure'], 'Amount' => (int) $WorkComplite['Amount'], 'Cost' => $Cost, 'Discont' => $Comp, 'Debet' => 0, 'Credit' => $WorkComplite['Summ']);
    #-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
KSort($Verifies);
#-------------------------------------------------------------------------------
$Table = array(array(new Tag('TD', array('class' => 'Head'), 'Дата'), new Tag('TD', array('class' => 'Head'), 'Основание'), new Tag('TD', array('class' => 'Head'), 'Ед. изм.'), new Tag('TD', array('class' => 'Head'), 'Кол-во'), new Tag('TD', array('class' => 'Head'), 'Цена'), new Tag('TD', array('class' => 'Head'), 'Скидка'), new Tag('TD', array('class' => 'Head'), 'Дебет'), new Tag('TD', array('class' => 'Head'), 'Кредит')));
#-------------------------------------------------------------------------------
$Total = array('Debet' => 0, 'Credit' => 0);
#-------------------------------------------------------------------------------
foreach ($Verifies as $CreateDate => $Verify) {
    #-------------------------------------------------------------------------------
    $Comp = Comp_Load('Formats/Date/Standard', (int) $CreateDate);
    if (Is_Error($Comp)) {
        return ERROR | @Trigger_Error(500);
    }
    #-------------------------------------------------------------------------------
    $Line = array($Comp, $Verify['Founding'], $Verify['Measure'], $Verify['Amount'], $Verify['Cost'], $Verify['Discont']);
    #-------------------------------------------------------------------------------
    $Credit = $Verify['Credit'];
开发者ID:carriercomm,项目名称:jbs,代码行数:31,代码来源:VerifyReport.comp.php

示例9: Styles_Menu

function Styles_Menu($Path)
{
    /****************************************************************************/
    $__args_types = array('string');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    $Result = $Chain = array();
    #-----------------------------------------------------------------------------
    do {
        #---------------------------------------------------------------------------
        $Menu = Styles_XML(SPrintF('Menus/%s.xml', $Path));
        if (Is_Error($Menu)) {
            return ERROR | @Trigger_Error('[Styles_Menu]: не удалось загрузить файл меню');
        }
        #---------------------------------------------------------------------------
        Array_UnShift($Chain, $Menu);
        #---------------------------------------------------------------------------
        $Path = isset($Menu['RootID']) ? $Menu['RootID'] : FALSE;
        #---------------------------------------------------------------------------
    } while ($Path);
    #-----------------------------------------------------------------------------
    foreach ($Chain as $Menu) {
        Array_Union($Result, $Menu);
    }
    #-----------------------------------------------------------------------------
    $Items =& $Result['Items'];
    #-----------------------------------------------------------------------------
    if (isset($Result['Comp'])) {
        #---------------------------------------------------------------------------
        $Comp = Comp_Load($Result['Comp']);
        if (Is_Error($Comp)) {
            return ERROR | @Trigger_Error(500);
        }
        #---------------------------------------------------------------------------
        if (Is_Array($Comp)) {
            Array_Union($Items, $Comp);
        }
    }
    #-----------------------------------------------------------------------------
    foreach (Array_Keys($Items) as $ItemID) {
        #---------------------------------------------------------------------------
        $Item =& $Items[$ItemID];
        #---------------------------------------------------------------------------
        if (!Is_Array($Item)) {
            continue;
        }
        #---------------------------------------------------------------------------
        if (isset($Item['UnActive'])) {
            unset($Items[$ItemID]);
        }
        #---------------------------------------------------------------------------
        $IsActive = FALSE;
        #---------------------------------------------------------------------------
        foreach ($Item['Paths'] as $Path) {
            #-------------------------------------------------------------------------
            $IsActive = Preg_Match(SPrintF('/%s/', $Path), $GLOBALS['__URI']) || Preg_Match(SPrintF('/%s/', $Path), $_SERVER['REQUEST_URI']);
            #-------------------------------------------------------------------------
            if ($IsActive) {
                break;
            }
        }
        #---------------------------------------------------------------------------
        $Item['IsActive'] = $IsActive;
    }
    #-----------------------------------------------------------------------------
    KSort($Items);
    #-----------------------------------------------------------------------------
    return $Result;
}
开发者ID:carriercomm,项目名称:jbs,代码行数:71,代码来源:Styles.php

示例10: SendAPIRequest

 function SendAPIRequest($url, $method, $parameters, $oauth, $options, &$response)
 {
     $this->response_status = 0;
     $http = new http_class();
     $http->debug = $this->debug && $this->debug_http;
     $http->log_debug = true;
     $http->sasl_authenticate = 0;
     $http->user_agent = $this->oauth_user_agent;
     $http->redirection_limit = isset($options['FollowRedirection']) ? intval($options['FollowRedirection']) : 0;
     $http->follow_redirect = $http->redirection_limit != 0;
     if ($this->debug) {
         $this->OutputDebug('Accessing the ' . $options['Resource'] . ' at ' . $url);
     }
     $post_files = array();
     $method = strtoupper($method);
     $authorization = '';
     $type = isset($options['RequestContentType']) ? strtolower(trim(strtok($options['RequestContentType'], ';'))) : ($method === 'POST' || isset($oauth) ? 'application/x-www-form-urlencoded' : '');
     if (isset($oauth)) {
         $values = array('oauth_consumer_key' => $this->client_id, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => $this->signature_method, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
         $files = isset($options['Files']) ? $options['Files'] : array();
         if (count($files)) {
             foreach ($files as $name => $value) {
                 if (!isset($parameters[$name])) {
                     return $this->SetError('it was specified an file parameters named ' . $name);
                 }
                 $file = array();
                 switch (isset($value['Type']) ? $value['Type'] : 'FileName') {
                     case 'FileName':
                         $file['FileName'] = $parameters[$name];
                         break;
                     case 'Data':
                         $file['Data'] = $parameters[$name];
                         break;
                     default:
                         return $this->SetError($value['Type'] . ' is not a valid type for file ' . $name);
                 }
                 $file['Content-Type'] = isset($value['ContentType']) ? $value['ContentType'] : 'automatic/name';
                 $post_files[$name] = $file;
             }
             unset($parameters[$name]);
             if ($method !== 'POST') {
                 $this->OutputDebug('For uploading files the method should be POST not ' . $method);
                 $method = 'POST';
             }
             if ($type !== 'multipart/form-data') {
                 if (isset($options['RequestContentType'])) {
                     return $this->SetError('the request content type for uploading files should be multipart/form-data');
                 }
                 $type = 'multipart/form-data';
             }
             $value_parameters = array();
         } else {
             if ($this->url_parameters && $type === 'application/x-www-form-urlencoded' && count($parameters)) {
                 $first = strpos($url, '?') === false;
                 foreach ($parameters as $parameter => $value) {
                     $url .= ($first ? '?' : '&') . UrlEncode($parameter) . '=' . UrlEncode($value);
                     $first = false;
                 }
                 $parameters = array();
             }
             $value_parameters = $type !== 'application/x-www-form-urlencoded' ? array() : $parameters;
         }
         $header_values = $method === 'GET' ? array_merge($values, $oauth, $value_parameters) : array_merge($values, $oauth);
         $values = array_merge($values, $oauth, $value_parameters);
         $key = $this->Encode($this->client_secret) . '&' . $this->Encode($this->access_token_secret);
         switch ($this->signature_method) {
             case 'PLAINTEXT':
                 $values['oauth_signature'] = $key;
                 break;
             case 'HMAC-SHA1':
                 $uri = strtok($url, '?');
                 $sign = $method . '&' . $this->Encode($uri) . '&';
                 $first = true;
                 $sign_values = $values;
                 $u = parse_url($url);
                 if (isset($u['query'])) {
                     parse_str($u['query'], $q);
                     foreach ($q as $parameter => $value) {
                         $sign_values[$parameter] = $value;
                     }
                 }
                 KSort($sign_values);
                 foreach ($sign_values as $parameter => $value) {
                     $sign .= $this->Encode(($first ? '' : '&') . $parameter . '=' . $this->Encode($value));
                     $first = false;
                 }
                 $header_values['oauth_signature'] = $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
                 break;
             default:
                 return $this->SetError($this->signature_method . ' signature method is not yet supported');
         }
         if ($this->authorization_header) {
             $authorization = 'OAuth';
             $first = true;
             foreach ($header_values as $parameter => $value) {
                 $authorization .= ($first ? ' ' : ',') . $parameter . '="' . $this->Encode($value) . '"';
                 $first = false;
             }
             $post_values = $parameters;
         } else {
//.........这里部分代码省略.........
开发者ID:lungcc,项目名称:DrupalLoginCidadao,代码行数:101,代码来源:oauth_client.php


注:本文中的KSort函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。