static function printPrefixFilter($query) { static $loop_already_started; if ($loop_already_started) { return; } # If this is feed we bail out if (Is_Feed()) { return; } # If the current query is not a post query we bail out if (!(GetType($query) == 'object' && Get_Class($query) == 'WP_Query')) { return; } global $wp_current_filter; if (In_Array('wp_head', $wp_current_filter)) { return; } # Conditions if ($query->Is_Main_Query() && !$query->Get('suppress_filters')) { $is_archive_filter = self::isGlossaryArchive($query) && Options::Get('prefix_filter_for_archives'); $is_singular_filter = $query->Is_Singular(Post_Type::$post_type_name) && Options::Get('prefix_filter_for_singulars'); # Get the Filter depth $filter_depth = False; if ($is_archive_filter) { $filter_depth = Options::Get('prefix_filter_archive_depth'); } elseif ($is_singular_filter) { $filter_depth = Options::Get('prefix_filter_singular_depth'); } if ($is_archive_filter || $is_singular_filter) { Prefix_Filter::printFilter($filter_depth); $loop_already_started = True; } } }
function GetCompleteValues(&$form, $arguments) { if (!isset($arguments['CompleteValues']) || GetType($complete_values = $arguments['CompleteValues']) != 'array' || count($complete_values) == 0) { return 'it were not specified valid complete values'; } $this->complete_values = $complete_values; return ''; }
public function cdata($parser, $data) { $element = $this->structure[$this->path]['Components']; $previous = $this->path . ',' . strval($element - 1); if ($element > 0 && GetType($this->structure[$previous]) == 'string') { $this->structure[$previous] .= $data; } else { $this->setelementdata($this->path . ',' . $element, $data); $this->structure[$this->path]['Components']++; } return $this->parser ? $this->doCdata($data) : false; }
function DumpStructure(&$structure, &$positions, $path) { echo "[" . $positions[$path]["Line"] . "," . $positions[$path]["Column"] . "," . $positions[$path]["Byte"] . "]"; if (GetType($structure[$path]) == "array") { echo "<" . $structure[$path]["Tag"] . ">"; for ($element = 0; $element < $structure[$path]["Elements"]; $element++) { DumpStructure($structure, $positions, $path . ",{$element}"); } echo "</" . $structure[$path]["Tag"] . ">"; } else { echo $structure[$path]; } }
function DecodeText($encoded, &$encode_time) { if (GetType($colon = strpos($encoded, ":")) != "integer" || ($encode_time = intval(substr($encoded, $colon + 1))) == 0 || $encode_time > time() || !($encrypted = base64_decode(substr($encoded, 0, $colon)))) { return ""; } $iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_CFB); $iv = str_repeat(chr(0), $iv_size); $key_size = mcrypt_get_key_size(MCRYPT_3DES, MCRYPT_MODE_CFB); $key = $encode_time . $this->key; if (strlen($key) > $key_size) { $key = substr($key, 0, $key_size); } return mcrypt_cfb(MCRYPT_3DES, $key, $encrypted, MCRYPT_DECRYPT, $iv); }
function Unserialize() { if (isset($this->cookie_value)) { return $this->cookie_value; } if (!isset($_COOKIE[$this->cookie_name]) || strlen($serialized = $this->Decrypt($_COOKIE[$this->cookie_name], $encode_time)) == 0) { return null; } $value = @unserialize($serialized); if (GetType($value) != 'array') { return null; } return $this->cookie_value = $value; }
function DecryptValidation($encoded) { if (GetType($colon = strpos($encoded, ':')) != 'integer' || strlen($encoded) <= $colon + 3 || ($encrypt_time = intval(substr($encoded, $colon + 3))) == 0 || $encrypt_time > time() || !($encrypted = base64_decode(substr($encoded, 0, $colon)))) { return ''; } $iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_CFB); $iv = str_repeat(chr(0), $iv_size); $key_size = mcrypt_get_key_size(MCRYPT_3DES, MCRYPT_MODE_CFB); $salt = substr($encoded, $colon + 1, 2); $key = $salt . $this->key; if (strlen($key) > $key_size) { $key = substr($key, 0, $key_size); } return mcrypt_cfb(MCRYPT_3DES, $key, $encrypted, MCRYPT_DECRYPT, $iv); }
function AddInput(&$form, $arguments) { if (!isset($arguments['OPTIONS']) || GetType($arguments['OPTIONS']) != 'array' || count($this->options = $arguments['OPTIONS']) == 0) { return 'it were not specified the list select options'; } if (!isset($arguments['VALUE']) || !isset($this->options[$this->VALUE = $arguments['VALUE']])) { return 'it was not specified a valid list select value'; } if (isset($arguments['Columns']) && (GetType($arguments['Columns']) != 'array' || count($this->columns = $arguments['Columns']) == 0)) { return 'it was not specified a valid list select columns'; } if (isset($arguments['Rows']) && (GetType($arguments['Rows']) != 'array' || count($this->rows = $arguments['Rows']) == 0)) { return 'it was not specified a valid list select columns'; } if (isset($arguments['CLASS'])) { $this->CLASS = $arguments['CLASS']; } if (isset($arguments['STYLE'])) { $this->STYLE = $arguments['STYLE']; } if (isset($arguments['SIZE'])) { $this->SIZE = $arguments['SIZE']; } $this->name = $this->GenerateInputID($form, $this->input, 'radio'); $to = count($this->options); for ($o = 0, Reset($this->options); $o < $to; Next($this->options), ++$o) { $option = Key($this->options); $a = array('TYPE' => 'radio', 'NAME' => $this->name, 'ID' => $this->name . $option, 'VALUE' => $option); if ($o == 0) { if (isset($arguments['LABEL'])) { $a['LABEL'] = $arguments['LABEL']; } if (isset($arguments['ACCESSKEY'])) { $a['ACCESSKEY'] = $arguments['ACCESSKEY']; } } if (!strcmp($option, $this->VALUE)) { $a['CHECKED'] = 1; } if (strlen($error = $form->AddInput($a))) { return $error; } } Reset($this->options); $this->focus_input = $this->name . Key($this->options); return ''; }
function test_quoting(&$message, $test_values, $cs, $quote, $email_header, &$tests, &$failed) { Reset($test_values); $end = GetType($value = Key($test_values)) != "string"; for (; !$end; $tests++) { echo "Test value \"", $value, "\"..."; flush(); $encoded = $quote ? $message->QuoteText($value) : $message->QuotedPrintableEncode($value, $cs, 1, $email_header); if (strcmp($encoded, $test_values[$value])) { echo "\tFAIL: returned \"", $encoded, "\" and not \"", $test_values[$value], "\" as expected!\n"; $failed++; } else { echo "\tOK!\n"; } Next($test_values); $end = GetType($value = Key($test_values)) != "string"; } }
function Tokenize($string, $separator = "") { if (!strcmp($separator, "")) { $separator = $string; $string = $this->next_token; } for ($character = 0; $character < strlen($separator); $character++) { if (GetType($position = strpos($string, $separator[$character])) == "integer") { $found = isset($found) ? min($found, $position) : $position; } } if (isset($found)) { $this->next_token = substr($string, $found + 1); return substr($string, 0, $found); } else { $this->next_token = ""; return $string; } }
function CopyAddresses($message, &$results, $header) { if (!isset($message['Headers'][$header])) { return; } if (!isset($message['ExtractedAddresses'][$header])) { $parser = new rfc822_addresses_class(); $parser->ignore_syntax_errors = $this->ignore_syntax_errors; $values = GetType($message['Headers'][$header]) == 'array' ? $message['Headers'][$header] : array($message['Headers'][$header]); $tv = count($values); $addresses = array(); for ($v = 0; $v < $tv; ++$v) { if ($parser->ParseAddressList($values[$v], $a)) { if ($v == 0) { $addresses = $a; } else { $tl = count($a); for ($l = 0; $l < $tl; ++$l) { $addresses[] = $a[$l]; } } } } } else { $addresses = $message['ExtractedAddresses'][$header]; } if (count($addresses)) { $results[ucfirst(substr($header, 0, strlen($header) - 1))] = $addresses; } }
function EscapeSpecialCharacters($string) { if (GetType($string) != "string") { $string = strval($string); } for ($escaped = "", $character = 0; $character < strlen($string); $character++) { switch ($string[$character]) { case "\"": case ">": case "<": $code = Ord($string[$character]); break; default: $code = Ord($string[$character]); if ($code < 32 || $code > 127) { break; } $escaped .= $string[$character]; continue 2; } $escaped .= "&#{$code};"; } return $escaped; }
/** * Adds to the "To" recipient collection. * * @param mixed $RecipientEmail An email (or array of emails) to add to the "To" recipient collection. * @param string $RecipientName The recipient name associated with $RecipientEmail. If $RecipientEmail is * an array of email addresses, this value will be ignored. */ public function To($RecipientEmail, $RecipientName = '') { if (is_string($RecipientEmail)) { if (strpos($RecipientEmail, ',') > 0) { $RecipientEmail = explode(',', $RecipientEmail); // trim no need, PhpMailer::AddAnAddress() will do it return $this->To($RecipientEmail, $RecipientName); } if ($this->PhpMailer->SingleTo) { return $this->AddTo($RecipientEmail, $RecipientName); } if (!$this->_IsToSet) { $this->_IsToSet = TRUE; $this->AddTo($RecipientEmail, $RecipientName); } else { $this->Cc($RecipientEmail, $RecipientName); } return $this; } elseif ($RecipientEmail instanceof stdClass) { $RecipientName = GetValue('Name', $RecipientEmail); $RecipientEmail = GetValue('Email', $RecipientEmail); return $this->To($RecipientEmail, $RecipientName); } elseif ($RecipientEmail instanceof Gdn_DataSet) { foreach ($RecipientEmail->ResultObject() as $Object) { $this->To($Object); } return $this; } elseif (is_array($RecipientEmail)) { $Count = count($RecipientEmail); if (!is_array($RecipientName)) { $RecipientName = array_fill(0, $Count, ''); } if ($Count == count($RecipientName)) { $RecipientEmail = array_combine($RecipientEmail, $RecipientName); foreach ($RecipientEmail as $Email => $Name) { $this->To($Email, $Name); } } else { trigger_error(ErrorMessage('Size of arrays do not match', 'Email', 'To'), E_USER_ERROR); } return $this; } trigger_error(ErrorMessage('Incorrect first parameter (' . GetType($RecipientEmail) . ') passed to function.', 'Email', 'To'), E_USER_ERROR); }
function RestoreCookies($cookies, $clear = 1) { $new_cookies = $clear ? array() : $this->cookies; for ($secure_cookies = 0, Reset($cookies); $secure_cookies < count($cookies); Next($cookies), $secure_cookies++) { $secure = Key($cookies); if (GetType($secure) != "integer") { return $this->SetError("invalid cookie secure value type (" . serialize($secure) . ")"); } for ($cookie_domain = 0, Reset($cookies[$secure]); $cookie_domain < count($cookies[$secure]); Next($cookies[$secure]), $cookie_domain++) { $domain_pattern = Key($cookies[$secure]); if (GetType($domain_pattern) != "string") { return $this->SetError("invalid cookie domain value type (" . serialize($domain_pattern) . ")"); } for (Reset($cookies[$secure][$domain_pattern]), $path_part = 0; $path_part < count($cookies[$secure][$domain_pattern]); Next($cookies[$secure][$domain_pattern]), $path_part++) { $path = Key($cookies[$secure][$domain_pattern]); if (GetType($path) != "string" || strcmp(substr($path, 0, 1), "/")) { return $this->SetError("invalid cookie path value type (" . serialize($path) . ")"); } for (Reset($cookies[$secure][$domain_pattern][$path]), $cookie = 0; $cookie < count($cookies[$secure][$domain_pattern][$path]); Next($cookies[$secure][$domain_pattern][$path]), $cookie++) { $cookie_name = Key($cookies[$secure][$domain_pattern][$path]); $expires = $cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"]; $value = $cookies[$secure][$domain_pattern][$path][$cookie_name]["value"]; if (GetType($expires) != "string" || strlen($expires) && !preg_match("#^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\$#", $expires)) { return $this->SetError("invalid cookie expiry value type (" . serialize($expires) . ")"); } $new_cookies[$secure][$domain_pattern][$path][$cookie_name] = array("name" => $cookie_name, "value" => $value, "domain" => $domain_pattern, "path" => $path, "expires" => $expires, "secure" => $secure); } } } } $this->cookies = $new_cookies; return ""; }
function GetCredentials(&$credentials, $defaults, &$interactions) { Reset($credentials); $end = GetType($key = Key($credentials)) != "string"; for (; !$end;) { if (!isset($this->credentials[$key])) { if (isset($defaults[$key])) { $credentials[$key] = $defaults[$key]; } else { $this->error = "the requested credential " . $key . " is not defined"; return SASL_NOMECH; } } else { $credentials[$key] = $this->credentials[$key]; } Next($credentials); $end = GetType($key = Key($credentials)) != "string"; } return SASL_CONTINUE; }
function GetLOBFieldValue($prepared_query, $parameter, $lob, &$value) { if (!$this->Connect()) { return 0; } $success = 1; if ($blob = ibase_blob_create($this->auto_commit ? $this->connection : $this->transaction_id)) { while (!MetabaseEndOfLOB($lob)) { if (MetabaseReadLOB($lob, $data, $this->lob_buffer_length) < 0) { $this->SetError("Get LOB field value", MetabaseLOBError($lob)); $success = 0; break; } if (!ibase_blob_add($blob, $data)) { $this->SetError("Get LOB field value", "Could not add data to a large object: " . ibase_errmsg()); $success = 0; break; } } if ($success) { if (GetType($value = ibase_blob_close($blob))) { if (!isset($this->query_parameters[$prepared_query])) { $this->query_parameters[$prepared_query] = array(0, ""); $this->query_parameter_values[$prepared_query] = array(); } $query_parameter = count($this->query_parameters[$prepared_query]); $this->query_parameter_values[$prepared_query][$parameter] = $query_parameter; $this->query_parameters[$prepared_query][$query_parameter] = $value; $value = "?"; } else { $success = 0; } } if (!$success) { ibase_blob_cancel($blob); } } else { $this->SetError("Get LOB field value", "Could not create a large object: " . ibase_errmsg()); $success = 0; } return $success; }
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); } $error = $http->ReadWholeReplyBody($data); $http->Close(); if (strlen($error)) { return $this->SetError('it was not possible to access the ' . $options['Resource'] . ': ' . $error); } $this->response_status = intval($http->response_status); $content_type = isset($headers['content-type']) ? strtolower(trim(strtok($headers['content-type'], ';'))) : 'unspecified'; switch ($content_type) { case 'text/javascript': case 'application/json': if (!function_exists('json_decode')) { return $this->SetError('the JSON extension is not available in this PHP setup'); } $object = json_decode($data); switch (GetType($object)) { case 'object': if (!isset($options['ConvertObjects']) || !$options['ConvertObjects']) { $response = $object; } else { $response = array(); foreach ($object as $property => $value) { $response[$property] = $value; } } break; case 'array': $response = $object; break; default: if (!isset($object)) { return $this->SetError('it was not returned a valid JSON definition of the ' . $options['Resource'] . ' values'); } $response = $object; break; } break; case 'application/x-www-form-urlencoded': case 'text/plain': case 'text/html': parse_str($data, $response); break; default: $response = $data; break; } if ($this->response_status >= 200 && $this->response_status < 300) { $this->access_token_error = ''; } else { $this->access_token_error = 'it was not possible to access the ' . $options['Resource'] . ': it was returned an unexpected response status ' . $http->response_status . ' Response: ' . $data; if ($this->debug) { $this->OutputDebug('Could not retrieve the OAuth access. Error: ' . $this->access_token_error); } if (isset($options['FailOnAccessError']) && $options['FailOnAccessError']) { $this->error = $this->access_token_error; return false; } } return true; }
function VerifyWhiteSpace($path) { if ($this->store_positions) { $line = $parser->positions[$path]["Line"]; $column = $parser->positions[$path]["Column"]; $byte_index = $parser->positions[$path]["Byte"]; } else { $line = $column = 1; $byte_index = 0; } if (!isset($this->structure[$path])) { $this->SetErrorPosition(2, "element path does not exist", $line, $column, $byte_index); return $this->error; } if (GetType($this->structure[$path]) != "string") { $this->SetErrorPosition(2, "element is not data", $line, $column, $byte_index); return $this->error; } $data = $this->structure[$path]; for ($previous_return = 0, $position = 0; $position < strlen($data); $position++) { switch ($data[$position]) { case " ": case "\t": $column++; $byte_index++; $previous_return = 0; break; case "\n": if (!$previous_return) { $line++; } $column = 1; $byte_index++; $previous_return = 0; break; case "\r": $line++; $column = 1; $byte_index++; $previous_return = 1; break; default: $this->SetErrorPosition(2, "data is not white space", $line, $column, $byte_index); return $this->error; } } return ""; }
protected function _sendHttp($post_values, $uri) { /* This function Copyright (C) 2005-2006 Thomas Harding, Manuel Lemos */ $this->response_completed[] = "no"; unset($this->serverouptut); self::_putDebug(_("Processing HTTP request"), 2); $this->serveroutput->headers = array(); $this->serveroutput->body = ""; $http = new http_class(); if (!$this->unix) { $http->host = $this->host; } else { $http->host = "localhost"; } $http->with_exceptions = $this->with_exceptions; if ($this->debug_http) { $http->debug = 1; $http->html_debug = 0; } else { $http->debug = 0; $http->html_debug = 0; } $url = "http://" . $this->host; if ($this->ssl) { $url = "https://" . $this->host; } if ($this->unix) { $url = "unix://" . $this->host; } $http->port = $this->port; $http->timeout = $this->http_timeout; $http->data_timeout = $this->http_data_timeout; $http->force_multipart_form_post = false; $http->user = $this->username; $http->password = $this->password; $error = $http->GetRequestArguments($url, $arguments); $arguments["RequestMethod"] = "POST"; $arguments["Headers"] = array("Content-Type" => "application/ipp"); $arguments["BodyStream"] = array(array("Data" => $post_values["Data"])); if (isset($post_values["File"])) { $arguments["BodyStream"][] = array("File" => $post_values["File"]); } if (isset($post_values["FileType"]) && !strcmp($post_values["FileType"], "TEXT")) { $arguments["BodyStream"][] = array("Data" => Chr(12)); } $arguments["RequestURI"] = $uri; if ($this->with_exceptions && $this->handle_http_exceptions) { try { $success = $http->Open($arguments); } catch (httpException $e) { throw new ippException(sprintf("http error: %s", $e->getMessage()), $e->getErrno()); } } else { $success = $http->Open($arguments); } if ($success[0] == true) { $success = $http->SendRequest($arguments); if ($success[0] == true) { self::_putDebug("H T T P R E Q U E S T :"); self::_putDebug("Request headers:"); for (Reset($http->request_headers), $header = 0; $header < count($http->request_headers); Next($http->request_headers), $header++) { $header_name = Key($http->request_headers); if (GetType($http->request_headers[$header_name]) == "array") { for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++) { self::_putDebug($header_name . ": " . $http->request_headers[$header_name][$header_value]); } } else { self::_putDebug($header_name . ": " . $http->request_headers[$header_name]); } } self::_putDebug("Request body:"); self::_putDebug(htmlspecialchars($http->request_body) . "*********** END REQUEST BODY *********"); $i = 0; $headers = array(); unset($this->serveroutput->headers); $http->ReadReplyHeaders($headers); self::_putDebug("H T T P R E S P O N S E :"); self::_putDebug("Response headers:"); for (Reset($headers), $header = 0; $header < count($headers); Next($headers), $header++) { $header_name = Key($headers); if (GetType($headers[$header_name]) == "array") { for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++) { self::_putDebug($header_name . ": " . $headers[$header_name][$header_value]); $this->serveroutput->headers[$i] = $header_name . ": " . $headers[$header_name][$header_value]; $i++; } } else { self::_putDebug($header_name . ": " . $headers[$header_name]); $this->serveroutput->headers[$i] = $header_name . ": " . $headers[$header_name]; $i++; } } self::_putDebug("\n\nResponse body:\n"); $this->serveroutput->body = ""; for (;;) { $http->ReadReplyBody($body, 1024); if (strlen($body) == 0) { break; } self::_putDebug(htmlentities($body)); $this->serveroutput->body .= $body; } self::_putDebug("********* END RESPONSE BODY ********"); } } $http->Close(); return true; }
function ReadSession(&$session) { $session = null; $name = $this->file['name']; if (!file_exists($name)) { return true; } if (!($this->opened_file = fopen($name, 'c+'))) { return $this->SetPHPError('could not open the token file ' . $name, $php_error_message); } if (!flock($this->opened_file, LOCK_SH)) { return $this->SetPHPError('could not lock the token file ' . $name . ' for reading', $php_error_message); } $json = ''; while (!feof($this->opened_file)) { $data = fread($this->opened_file, 1000); if (!$data && !feof($this->opened_file)) { $this->SetError('could not read the token file' . $name, $php_error_message); fclose($this->opened_file); $this->opened_file = false; return false; } $json .= $data; } flock($this->opened_file, LOCK_UN); $session = json_decode($json); if (!isset($session)) { return $this->SetPHPError('It was not possible to decode the OAuth token file ' . $name, $php_errormsg); } if (GetType($session) !== 'object') { return $this->SetError('It was not possible to decode the OAuth token file ' . $name . ' because it seems corrupted'); } return true; }
function SendMailing($mailing) { if (strlen($this->error)) { return $this->error; } if (!isset($this->mailings[$mailing])) { return $this->OutputError("it was not specified a valid mailing"); } if (isset($this->mailings[$mailing]["Envelope"])) { return $this->OutputError("the mailing was not yet ended"); } $this->ResetMessage(); $base_path = $this->mailings[$mailing]["BasePath"]; if (GetType($header_lines = @File($base_path . ".h")) != "array") { return $this->OutputPHPError("could not read the mailing headers file " . $base_path . ".h", $php_errormsg); } for ($line = 0; $line < count($header_lines); ++$line) { $header_name = $this->Tokenize($header_lines[$line], ": "); $this->headers[$header_name] = trim($this->Tokenize("\n")); } if (!($envelope_file = @fopen($base_path . ".e", "rb"))) { return $this->OutputPHPError("could not open the mailing envelope file " . $base_path . ".e", $php_errormsg); } for ($bcc = $data = "", $position = 0; !feof($envelope_file) || strlen($data);) { if (GetType($break = strpos($data, chr(0), $position)) != "integer") { if (GetType($chunk = @fread($envelope_file, $this->file_buffer_length)) != "string") { fclose($envelope_file); return $this->OutputPHPError("could not read the mailing envelop file " . $base_path . ".e", $php_errormsg); } $data = substr($data, $position) . $chunk; $position = 0; continue; } if ($break == $position) { break; } switch ($data[$position]) { case "F": $this->headers["Return-Path"] = substr($data, $position + 1, $break - $position - 1); break; case "T": $bcc .= (strlen($bcc) == 0 ? "" : ", ") . substr($data, $position + 1, $break - $position - 1); break; default: return $this->OutputError("invalid mailing envelope file " . $base_path . ".e"); } $position = $break + 1; } fclose($envelope_file); if (strlen($bcc) == 0) { return $this->OutputError("the mailing envelop file " . $base_path . ".e does not contain any recipients"); } $this->headers["Bcc"] = $bcc; if (!($body_file = @fopen($base_path . ".b", "rb"))) { return $this->OutputPHPError("could not open the mailing body file " . $base_path . ".b", $php_errormsg); } for ($data = ""; !feof($body_file);) { if (GetType($chunk = @fread($body_file, $this->file_buffer_length)) != "string") { fclose($body_file); return $this->OutputPHPError("could not read the mailing body file " . $base_path . ".b", $php_errormsg); } $data .= $chunk; } fclose($body_file); if (strlen($error = $this->StartSendingMessage())) { return $error; } if (strlen($error = $this->SendMessageHeaders($this->headers)) == 0 && strlen($error = $this->SendMessageBody($data)) == 0) { $error = $this->EndSendingMessage(); } $this->StopSendingMessage(); return $error; }
under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------ */ if (isset($_NAMESERVERS) && (GetType($_NAMESERVERS) != "array" || count($_NAMESERVERS) == 0)) { unset($_NAMESERVERS); } /*************************************************************************** Description $_NAMESERVER[] The array that contains IP addresses or domain names of name servers used for DNS resolution. If nothing is set before require()'ing this library, the values will automatically prepared. bool getmxrr( string $hostname, arrayref $mxhosts, arrayref $weight ); This function works in the same way as getmxrr(), however the
function SetRecipient($recipient) { if ($this->direct_delivery) { if (GetType($at = strrpos($recipient, "@")) != "integer") { return "it was not specified a valid direct recipient"; } $domain = substr($recipient, $at + 1); switch ($this->state) { case "Disconnected": if (!$this->Connect($domain)) { return 0; } if (!$this->MailFrom("")) { $error = $this->error; $this->Disconnect(); $this->error = $error; return 0; } break; case "SenderSet": case "RecipientSet": if (strcmp($this->connected_domain, $domain)) { $this->error = "it is not possible to deliver directly to recipients of different domains"; return 0; } break; default: $this->error = "connection is already established and the recipient is already set"; return 0; } } else { switch ($this->state) { case "SenderSet": case "RecipientSet": break; default: $this->error = "connection is not in the recipient setting state"; return 0; } } $this->error = ""; if (!$this->PutLine("RCPT TO:<{$recipient}>")) { return 0; } if (isset($this->esmtp_extensions["PIPELINING"])) { $this->pending_recipients++; if ($this->pending_recipients >= $this->maximum_piped_recipients) { if (!$this->FlushRecipients()) { return 0; } } } else { if ($this->VerifyResultLines(array("250", "251"), $responses) <= 0) { return 0; } } $this->state = "RecipientSet"; return 1; }
function httpClientPost($url, $paramters) { //$url='https://login.yahoo.com/config/login?'; //$url="https://accounts.google.com/ServiceLogin"; //log echo '<br/> httpClient $url: '. $url ; //log echo '<br/> httpClient $paramters: ' ; //log var_dump($paramters); $resultbody; set_time_limit(0); $http = new http_class(); $http->timeout = 0; $http->data_timeout = 0; $http->debug = 0; $http->html_debug = 1; //$url="https://login.yahoo.com/config/login"; if ($this->isDebug) { echo "<br/>url:" . $url; echo "<br/>arguments:<br/>"; var_dump($paramters); } $error = $http->GetRequestArguments($url, $arguments); $arguments["RequestMethod"] = "POST"; //$arguments['Protocol']='https'; //$arguments['HostName']='login.yahoo.com'; //$arguments['HostPort']='443'; //$arguments['RequestMethod']='POST'; $arguments['PostValues'] = $paramters; /* $arguments["PostValues"]=array( "somefield"=>"Upload forms", "MAX_FILE_SIZE"=>"1000000" ); $arguments["PostFiles"]=array( "userfile"=>array( "Data"=>"This is just a plain text attachment file named attachment.txt .", "Name"=>"attachment.txt", "Content-Type"=>"automatic/name", ), "anotherfile"=>array( "FileName"=>"test_http_post.php", "Content-Type"=>"automatic/name", ) ); $arguments["Referer"]="http://www.alltheweb.com/"; */ if ($this->isDebug) { echo "<H2><LI>Opening connection to:</H2>\n<PRE>", HtmlEntities($arguments["HostName"]), "</PRE>\n"; echo '<br/> <b>$arguments: </b><br/> '; var_dump($arguments); } flush(); $error = $http->Open($arguments); if ($this->isDebug) { echo "<br/><br/>http->open:" . $error . "<br/>"; } if ($error == "") { $error = $http->SendRequest($arguments); if ($this->isDebug) { echo "<br/>[http->SendRequest:" . $error . "]<br/><br/>"; } if ($error == "") { //log echo "<H2><LI>Request:</LI</H2>\n<PRE>\n".HtmlEntities($http->request)."</PRE>\n"; //log echo "<H2><LI>Request headers:</LI</H2>\n<PRE>\n"; for (Reset($http->request_headers), $header = 0; $header < count($http->request_headers); Next($http->request_headers), $header++) { $header_name = Key($http->request_headers); if (GetType($http->request_headers[$header_name]) == "array") { for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++) { //log echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n"; } } else { //log echo $header_name.": ".$http->request_headers[$header_name],"\r\n"; } } //log echo "</PRE>\n"; if ($this->isDebug) { echo "<H4><LI>HTTP Request body:</LI></H4>error_code:\n" . $http->error_code . "<br/><PRE>request_body:\n" . HtmlEntities($http->request_body) . "</PRE>\n"; } flush(); $headers = array(); $error = $http->ReadReplyHeaders($headers); if ($error == "") { //log echo "<H2><LI>Response headers:</LI</H2>\n<PRE>\n"; for (Reset($headers), $header = 0; $header < count($headers); Next($headers), $header++) { $header_name = Key($headers); if (GetType($headers[$header_name]) == "array") { for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++) { if ($this->isDebug) { echo "http header:" . $header_name . ": " . $headers[$header_name][$header_value], "\r\n"; } } } else { if ($this->isDebug) { echo $header_name . ": " . $headers[$header_name], "\r\n"; } } } //log echo "</PRE>\n"; flush(); //log echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n"; for (;;) { $error = $http->ReadReplyBody($body, 1000); if ($error != "" || strlen($body) == 0) { break; } //log echo HtmlSpecialChars($body); $this->httpResponseStatus = $http->response_status; $resultbody = $body; if ($this->isDebug) { echo "<br/>http-> get response_status: " . $http->response_status . "<br/> "; echo "<br/>http-> get body: " . $resultbody . "<br/> "; } } //log echo "</PRE>\n"; flush(); } } $http->Close(); } if (strlen($error)) { if ($this->isDebug) { echo " <H4>POST Error: ", $error, "</H4> "; } } return $resultbody; }
function Initialize() { if (strlen($this->server) === 0) { return true; } $this->oauth_version = $this->dialog_url = $this->access_token_url = $this->request_token_url = $this->append_state_to_redirect_uri = ''; $this->authorization_header = true; $this->url_parameters = false; $this->token_request_method = 'GET'; $this->signature_method = 'HMAC-SHA1'; $this->access_token_authentication = ''; $this->access_token_parameter = ''; $this->default_access_token_type = ''; $this->store_access_token_response = false; switch ($this->server) { case 'Facebook': $this->oauth_version = '2.0'; $this->dialog_url = 'https://www.facebook.com/dialog/oauth?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}'; $this->access_token_url = 'https://graph.facebook.com/oauth/access_token'; break; case 'github': $this->oauth_version = '2.0'; $this->dialog_url = 'https://github.com/login/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}'; $this->access_token_url = 'https://github.com/login/oauth/access_token'; break; case 'Google': $this->oauth_version = '2.0'; $this->dialog_url = 'https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}'; $this->offline_dialog_url = 'https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&state={STATE}&access_type=offline&approval_prompt=force'; $this->access_token_url = 'https://accounts.google.com/o/oauth2/token'; break; case 'LinkedIn': $this->oauth_version = '1.0a'; $this->request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken?scope={SCOPE}'; $this->dialog_url = 'https://api.linkedin.com/uas/oauth/authenticate'; $this->access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken'; $this->url_parameters = true; break; case 'Microsoft': $this->oauth_version = '2.0'; $this->dialog_url = 'https://login.live.com/oauth20_authorize.srf?client_id={CLIENT_ID}&scope={SCOPE}&response_type=code&redirect_uri={REDIRECT_URI}&state={STATE}'; $this->access_token_url = 'https://login.live.com/oauth20_token.srf'; break; case 'Twitter': $this->oauth_version = '1.0a'; $this->request_token_url = 'https://api.twitter.com/oauth/request_token'; $this->dialog_url = 'https://api.twitter.com/oauth/authenticate'; $this->access_token_url = 'https://api.twitter.com/oauth/access_token'; $this->url_parameters = false; break; case 'Yahoo': $this->oauth_version = '1.0a'; $this->request_token_url = 'https://api.login.yahoo.com/oauth/v2/get_request_token'; $this->dialog_url = 'https://api.login.yahoo.com/oauth/v2/request_auth'; $this->access_token_url = 'https://api.login.yahoo.com/oauth/v2/get_token'; $this->authorization_header = false; break; default: if (!($json = @file_get_contents($this->configuration_file))) { if (!file_exists($this->configuration_file)) { return $this->SetError('the OAuth server configuration file ' . $this->configuration_file . ' does not exist'); } return $this->SetPHPError('could not read the OAuth server configuration file ' . $this->configuration_file, $php_errormsg); } $oauth_server = json_decode($json); if (!isset($oauth_server)) { return $this->SetPHPError('It was not possible to decode the OAuth server configuration file ' . $this->configuration_file . ' eventually due to incorrect format', $php_errormsg); } if (GetType($oauth_server) !== 'object') { return $this->SetError('It was not possible to decode the OAuth server configuration file ' . $this->configuration_file . ' because it does not correctly define a JSON object'); } if (!isset($oauth_server->servers) || GetType($oauth_server->servers) !== 'object') { return $this->SetError('It was not possible to decode the OAuth server configuration file ' . $this->configuration_file . ' because it does not correctly define a JSON object for servers'); } if (!isset($oauth_server->servers->{$this->server})) { return $this->SetError($this->server . ' is not yet a supported type of OAuth server. Please send a request in this class support forum (preferred) http://www.phpclasses.org/oauth-api , or if it is a security or private matter, contact the author Manuel Lemos mlemos@acm.org to request adding built-in support to this type of OAuth server.'); } $properties = $oauth_server->servers->{$this->server}; if (GetType($properties) !== 'object') { return $this->SetError('The OAuth server configuration file ' . $this->configuration_file . ' for the "' . $this->server . '" server does not correctly define a JSON object'); } $types = array('oauth_version' => 'string', 'request_token_url' => 'string', 'dialog_url' => 'string', 'offline_dialog_url' => 'string', 'access_token_url' => 'string', 'append_state_to_redirect_uri' => 'string', 'authorization_header' => 'boolean', 'url_parameters' => 'boolean', 'token_request_method' => 'string', 'signature_method' => 'string', 'access_token_authentication' => 'string', 'access_token_parameter' => 'string', 'default_access_token_type' => 'string', 'store_access_token_response' => 'boolean'); $required = array('oauth_version' => array(), 'request_token_url' => array('1.0', '1.0a'), 'dialog_url' => array(), 'access_token_url' => array()); foreach ($properties as $property => $value) { if (!isset($types[$property])) { return $this->SetError($property . ' is not a supported property for the "' . $this->server . '" server in the OAuth server configuration file ' . $this->configuration_file); } $type = GetType($value); $expected = $types[$property]; if ($type !== $expected) { return $this->SetError(' the property "' . $property . '" for the "' . $this->server . '" server is not of type "' . $expected . '", it is of type "' . $type . '", in the OAuth server configuration file ' . $this->configuration_file); } $this->{$property} = $value; unset($required[$property]); } foreach ($required as $property => $value) { if (count($value) && in_array($this->oauth_version, $value)) { return $this->SetError('the property "' . $property . '" is not defined for the "' . $this->server . '" server in the OAuth server configuration file ' . $this->configuration_file); } } break; } return true; }
function IssueNOOP() { if ($this->state != "TRANSACTION") { return $this->SetError("connection is not in TRANSACTION state"); } if ($this->PutLine("NOOP") == 0) { return $this->SetError("Could not send the NOOP command"); } $response = $this->GetLine(); if (GetType($response) != "string") { return $this->SetError("Could not NOOP command response"); } if ($this->Tokenize($response, " ") != "+OK") { return $this->SetError("Could not issue the NOOP command: " . $this->Tokenize("\r\n")); } return ""; }
function QueryAll($query, &$all, $types = "") { if (!($result = $this->Query($query))) { return 0; } if (GetType($types) == "array") { if (!($success = $this->SetResultTypes($result, $types))) { $this->FreeResult($result); return 0; } } return $this->FetchResultAll($result, $all); }
function &SetConnection($set, &$current_name, &$pop3) { static $connections = array(); if ($set > 0) { $current_name = strval(count($connections)); $connections[$current_name] =& $pop3; } elseif ($set < 0) { $connections[$current_name] = ''; $current_name = ''; } elseif (isset($connections[$current_name]) && GetType($connections[$current_name]) != 'string') { $connection =& $connections[$current_name]; return $connection; } return $pop3; }
function Query($query) { $this->Debug("Query: {$query}"); $first = $this->first_selected_row; $limit = $this->selected_row_limit; $this->first_selected_row = $this->selected_row_limit = 0; if (!strcmp($this->database_name, "")) { return $this->SetError("Query", "it was not specified a valid database name to select"); } if (!$this->Connect()) { return 0; } $query_string = strtolower(strtok(ltrim($query), " \t\n\r")); if (($select = isset($this->select_queries[$query_string])) && $limit > 0) { $query .= " LIMIT {$first},{$limit}"; } if (mysql_select_db($this->database_name, $this->connection) && ($result = mysql_query($query, $this->connection))) { if ($select) { switch (GetType($result)) { case "resource": case "integer": $this->highest_fetched_row[$result] = -1; break; default: $error = mysql_error($this->connection); return $this->SetError("Query", "this select query did not return valid result set value: " . $query . (strlen($error) ? " (" . $error . ")" : "")); } } else { $this->affected_rows = mysql_affected_rows($this->connection); } } else { return $this->SetError("Query", mysql_error($this->connection)); } return $result; }
function NumberOfRows($result) { $result_value = intval($result); if (!isset($this->current_row[$result_value])) { return $this->SetError("Number of rows", "attemped to obtain the number of rows contained in an unknown query result"); } if (!isset($this->rows[$result_value])) { if (!$this->GetColumnNames($result)) { return 0; } if (isset($this->limits[$result_value])) { if (!$this->SkipFirstRows($result)) { $this->rows[$result_value] = 0; return 0; } $limit = $this->limits[$result_value][1]; } else { $limit = 0; } if ($limit == 0 || $this->current_row[$result_value] + 1 < $limit) { if (isset($this->row_buffer[$result_value])) { $this->current_row[$result_value]++; $this->results[$result_value][$this->current_row[$result_value]] = $this->row_buffer[$result_value]; unset($this->row_buffer[$result_value]); } for (; ($limit == 0 || $this->current_row[$result_value] + 1 < $limit) && GetType($this->results[$result_value][$this->current_row[$result_value] + 1] = ifx_fetch_row($result)) == "array"; $this->current_row[$result_value]++) { } } $this->rows[$result_value] = $this->current_row[$result_value] + 1; } return $this->rows[$result_value]; }