installed plugin W3 Total Cache
version 2.3.2
This commit is contained in:
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* A copy of the License is located at
|
||||
*
|
||||
* http://aws.amazon.com/apache2.0
|
||||
*
|
||||
* or in the "license" file accompanying this file. This file is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// CLASS
|
||||
|
||||
/**
|
||||
* Wraps the underlying `RequestCore` class with some AWS-specific customizations.
|
||||
*
|
||||
* @version 2011.06.02
|
||||
* @license See the included NOTICE.md file for more information.
|
||||
* @copyright See the included NOTICE.md file for more information.
|
||||
* @link http://aws.amazon.com/php/ PHP Developer Center
|
||||
*/
|
||||
class CFRequest extends RequestCore
|
||||
{
|
||||
/**
|
||||
* The default class to use for HTTP Requests (defaults to <CFRequest>).
|
||||
*/
|
||||
public $request_class = 'CFRequest';
|
||||
|
||||
/**
|
||||
* The default class to use for HTTP Responses (defaults to <CFResponse>).
|
||||
*/
|
||||
public $response_class = 'CFResponse';
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// CONSTRUCTOR
|
||||
|
||||
/**
|
||||
* Constructs a new instance of this class.
|
||||
*
|
||||
* @param string $url (Optional) The URL to request or service endpoint to query.
|
||||
* @param string $proxy (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
|
||||
* @param array $helpers (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.
|
||||
* @return $this A reference to the current instance.
|
||||
*/
|
||||
public function __construct($url = null, $proxy = null, $helpers = null)
|
||||
{
|
||||
parent::__construct($url, $proxy, $helpers);
|
||||
|
||||
// Standard settings for all requests
|
||||
$this->add_header('Expect', '100-continue');
|
||||
$this->set_useragent(CFRUNTIME_USERAGENT);
|
||||
$this->cacert_location = (defined('AWS_CERTIFICATE_AUTHORITY') ? AWS_CERTIFICATE_AUTHORITY : false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* A copy of the License is located at
|
||||
*
|
||||
* http://aws.amazon.com/apache2.0
|
||||
*
|
||||
* or in the "license" file accompanying this file. This file is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// CLASS
|
||||
|
||||
/**
|
||||
* Wraps the underlying `ResponseCore` class with some AWS-specific customizations.
|
||||
*
|
||||
* @version 2010.10.11
|
||||
* @license See the included NOTICE.md file for more information.
|
||||
* @copyright See the included NOTICE.md file for more information.
|
||||
* @link http://aws.amazon.com/php/ PHP Developer Center
|
||||
*/
|
||||
class CFResponse extends ResponseCore {}
|
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* A copy of the License is located at
|
||||
*
|
||||
* http://aws.amazon.com/apache2.0
|
||||
*
|
||||
* or in the "license" file accompanying this file. This file is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// CLASS
|
||||
|
||||
/**
|
||||
* Wraps the underlying `SimpleXMLIterator` class with enhancements for rapidly traversing the DOM tree,
|
||||
* converting types, and comparisons.
|
||||
*
|
||||
* @version 2011.04.25
|
||||
* @license See the included NOTICE.md file for more information.
|
||||
* @copyright See the included NOTICE.md file for more information.
|
||||
* @link http://aws.amazon.com/php/ PHP Developer Center
|
||||
* @link http://php.net/SimpleXML SimpleXML
|
||||
*/
|
||||
class CFSimpleXML extends SimpleXMLIterator
|
||||
{
|
||||
/**
|
||||
* Stores the namespace name to use in XPath queries.
|
||||
*/
|
||||
public $xml_ns;
|
||||
|
||||
/**
|
||||
* Stores the namespace URI to use in XPath queries.
|
||||
*/
|
||||
public $xml_ns_url;
|
||||
|
||||
/**
|
||||
* Catches requests made to methods that don't exist. Specifically, looks for child nodes via XPath.
|
||||
*
|
||||
* @param string $name (Required) The name of the method.
|
||||
* @param array $arguments (Required) The arguments passed to the method.
|
||||
* @return mixed Either an array of matches, or a single <CFSimpleXML> element.
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
// Remap $this
|
||||
$self = $this;
|
||||
|
||||
// Re-base the XML
|
||||
$self = new CFSimpleXML($self->asXML());
|
||||
|
||||
// Determine XPath query
|
||||
$self->xpath_expression = 'descendant-or-self::' . $name;
|
||||
|
||||
// Get the results and augment with CFArray
|
||||
$results = $self->xpath($self->xpath_expression);
|
||||
if (!count($results)) return false;
|
||||
$results = new CFArray($results);
|
||||
|
||||
// If an integer was passed, return only that result
|
||||
if (isset($arguments[0]) && is_int($arguments[0]))
|
||||
{
|
||||
if (isset($results[$arguments[0]]))
|
||||
{
|
||||
return $results[$arguments[0]];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternate approach to constructing a new instance. Supports chaining.
|
||||
*
|
||||
* @param string $data (Required) A well-formed XML string or the path or URL to an XML document if $data_is_url is <code>true</code>.
|
||||
* @param integer $options (Optional) Used to specify additional LibXML parameters. The default value is <code>0</code>.
|
||||
* @param boolean $data_is_url (Optional) Specify a value of <code>true</code> to specify that data is a path or URL to an XML document instead of string data. The default value is <code>false</code>.
|
||||
* @param string $ns (Optional) The XML namespace to return values for.
|
||||
* @param boolean $is_prefix (Optional) (No description provided by PHP.net.)
|
||||
* @return CFSimpleXML Creates a new <CFSimpleXML> element.
|
||||
*/
|
||||
public static function init($data, $options = 0, $data_is_url, $ns, $is_prefix = false)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<'))
|
||||
{
|
||||
throw new Exception('PHP 5.3 or newer is required to instantiate a new class with CLASS::init().');
|
||||
}
|
||||
|
||||
$self = get_called_class();
|
||||
return new $self($data, $options, $data_is_url, $ns, $is_prefix);
|
||||
}
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// TRAVERSAL
|
||||
|
||||
/**
|
||||
* Wraps the results of an XPath query in a <CFArray> object.
|
||||
*
|
||||
* @param string $expr (Required) The XPath expression to use to query the XML response.
|
||||
* @return CFArray A <CFArray> object containing the results of the XPath query.
|
||||
*/
|
||||
public function query($expr)
|
||||
{
|
||||
return new CFArray($this->xpath($expr));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent or a preferred ancestor of the current element.
|
||||
*
|
||||
* @param string $node (Optional) Name of the ancestor element to match and return.
|
||||
* @return CFSimpleXML A <CFSimpleXML> object containing the requested node.
|
||||
*/
|
||||
public function parent($node = null)
|
||||
{
|
||||
if ($node)
|
||||
{
|
||||
$parents = $this->xpath('ancestor-or-self::' . $node);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parents = $this->xpath('parent::*');
|
||||
}
|
||||
|
||||
return $parents[0];
|
||||
}
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// ALTERNATE FORMATS
|
||||
|
||||
/**
|
||||
* Gets the current XML node as a true string.
|
||||
*
|
||||
* @return string The current XML node as a true string.
|
||||
*/
|
||||
public function to_string()
|
||||
{
|
||||
return (string) $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current XML node as <CFArray>, a child class of PHP's <php:ArrayObject> class.
|
||||
*
|
||||
* @return CFArray The current XML node as a <CFArray> object.
|
||||
*/
|
||||
public function to_array()
|
||||
{
|
||||
return new CFArray(json_decode(json_encode($this), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current XML node as a stdClass object.
|
||||
*
|
||||
* @return array The current XML node as a stdClass object.
|
||||
*/
|
||||
public function to_stdClass()
|
||||
{
|
||||
return json_decode(json_encode($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current XML node as a JSON string.
|
||||
*
|
||||
* @return string The current XML node as a JSON string.
|
||||
*/
|
||||
public function to_json()
|
||||
{
|
||||
return json_encode($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current XML node as a YAML string.
|
||||
*
|
||||
* @return string The current XML node as a YAML string.
|
||||
*/
|
||||
public function to_yaml()
|
||||
{
|
||||
return sfYaml::dump(json_decode(json_encode($this), true), 5);
|
||||
}
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// COMPARISONS
|
||||
|
||||
/**
|
||||
* Whether or not the current node exactly matches the compared value.
|
||||
*
|
||||
* @param string $value (Required) The value to compare the current node to.
|
||||
* @return boolean Whether or not the current node exactly matches the compared value.
|
||||
*/
|
||||
public function is($value)
|
||||
{
|
||||
return ((string) $this === $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the current node contains the compared value.
|
||||
*
|
||||
* @param string $value (Required) The value to use to determine whether it is contained within the node.
|
||||
* @return boolean Whether or not the current node contains the compared value.
|
||||
*/
|
||||
public function contains($value)
|
||||
{
|
||||
return (stripos((string) $this, $value) !== false);
|
||||
}
|
||||
}
|
@ -0,0 +1,394 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
* A copy of the License is located at
|
||||
*
|
||||
* http://aws.amazon.com/apache2.0
|
||||
*
|
||||
* or in the "license" file accompanying this file. This file is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// CLASS
|
||||
|
||||
/**
|
||||
* Contains a set of utility methods for connecting to, and working with, AWS.
|
||||
*
|
||||
* @version 2010.09.30
|
||||
* @license See the included NOTICE.md file for more information.
|
||||
* @copyright See the included NOTICE.md file for more information.
|
||||
* @link http://aws.amazon.com/php/ PHP Developer Center
|
||||
*/
|
||||
class CFUtilities
|
||||
{
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// CONSTANTS
|
||||
|
||||
/**
|
||||
* Define the RFC 2616-compliant date format.
|
||||
*/
|
||||
const DATE_FORMAT_RFC2616 = 'D, d M Y H:i:s \G\M\T';
|
||||
|
||||
/**
|
||||
* Define the ISO-8601-compliant date format.
|
||||
*/
|
||||
const DATE_FORMAT_ISO8601 = 'Y-m-d\TH:i:s\Z';
|
||||
|
||||
/**
|
||||
* Define the MySQL-compliant date format.
|
||||
*/
|
||||
const DATE_FORMAT_MYSQL = 'Y-m-d H:i:s';
|
||||
|
||||
|
||||
/*%******************************************************************************************%*/
|
||||
// METHODS
|
||||
|
||||
/**
|
||||
* Constructs a new instance of this class.
|
||||
*
|
||||
* @return $this A reference to the current instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of a class constant, while avoiding the `T_PAAMAYIM_NEKUDOTAYIM` error. Misspelled because `const` is a reserved word.
|
||||
*
|
||||
* @param object $class (Required) An instance of the class containing the constant.
|
||||
* @param string $const (Required) The name of the constant to retrieve.
|
||||
* @return mixed The value of the class constant.
|
||||
*/
|
||||
public function konst($class, $const)
|
||||
{
|
||||
if (is_string($class))
|
||||
{
|
||||
$ref = new ReflectionClass($class);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ref = new ReflectionObject($class);
|
||||
}
|
||||
|
||||
return $ref->getConstant($const);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a HEX value to Base64.
|
||||
*
|
||||
* @param string $str (Required) Value to convert.
|
||||
* @return string Base64-encoded string.
|
||||
*/
|
||||
public function hex_to_base64($str)
|
||||
{
|
||||
$raw = '';
|
||||
|
||||
for ($i = 0; $i < strlen($str); $i += 2)
|
||||
{
|
||||
$raw .= chr(hexdec(substr($str, $i, 2)));
|
||||
}
|
||||
|
||||
return base64_encode($raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an associative array into a query string.
|
||||
*
|
||||
* @param array $array (Required) Array to convert.
|
||||
* @return string URL-friendly query string.
|
||||
*/
|
||||
public function to_query_string($array)
|
||||
{
|
||||
$temp = array();
|
||||
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if (is_string($key) && !is_array($value))
|
||||
{
|
||||
$temp[] = rawurlencode($key) . '=' . rawurlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
return implode('&', $temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an associative array into a sign-able string.
|
||||
*
|
||||
* @param array $array (Required) Array to convert.
|
||||
* @return string URL-friendly sign-able string.
|
||||
*/
|
||||
public function to_signable_string($array)
|
||||
{
|
||||
$t = array();
|
||||
|
||||
foreach ($array as $k => $v)
|
||||
{
|
||||
$t[] = $this->encode_signature2($k) . '=' . $this->encode_signature2($v);
|
||||
}
|
||||
|
||||
return implode('&', $t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the value according to RFC 3986.
|
||||
*
|
||||
* @param string $string (Required) String to convert.
|
||||
* @return string URL-friendly sign-able string.
|
||||
*/
|
||||
public function encode_signature2($string)
|
||||
{
|
||||
$string = rawurlencode($string);
|
||||
return str_replace('%7E', '~', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a query string into an associative array. Multiple, identical keys will become an indexed array.
|
||||
*
|
||||
* @param string $qs (Required) Query string to convert.
|
||||
* @return array Associative array of keys and values.
|
||||
*/
|
||||
public function query_to_array($qs)
|
||||
{
|
||||
$query = explode('&', $qs);
|
||||
$data = array();
|
||||
|
||||
foreach ($query as $q)
|
||||
{
|
||||
$q = explode('=', $q);
|
||||
|
||||
if (isset($data[$q[0]]) && is_array($data[$q[0]]))
|
||||
{
|
||||
$data[$q[0]][] = urldecode($q[1]);
|
||||
}
|
||||
else if (isset($data[$q[0]]) && !is_array($data[$q[0]]))
|
||||
{
|
||||
$data[$q[0]] = array($data[$q[0]]);
|
||||
$data[$q[0]][] = urldecode($q[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data[urldecode($q[0])] = urldecode($q[1]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return human readable file sizes.
|
||||
*
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @author Ryan Parman <ryan@getcloudfusion.com>
|
||||
* @license http://www.php.net/license/3_01.txt PHP License
|
||||
* @param integer $size (Required) Filesize in bytes.
|
||||
* @param string $unit (Optional) The maximum unit to use. Defaults to the largest appropriate unit.
|
||||
* @param string $default (Optional) The format for the return string. Defaults to `%01.2f %s`.
|
||||
* @return string The human-readable file size.
|
||||
* @link http://aidanlister.com/repos/v/function.size_readable.php Original Function
|
||||
*/
|
||||
public function size_readable($size, $unit = null, $default = null)
|
||||
{
|
||||
// Units
|
||||
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB');
|
||||
$mod = 1024;
|
||||
$ii = count($sizes) - 1;
|
||||
|
||||
// Max unit
|
||||
$unit = array_search((string) $unit, $sizes);
|
||||
if ($unit === null || $unit === false)
|
||||
{
|
||||
$unit = $ii;
|
||||
}
|
||||
|
||||
// Return string
|
||||
if ($default === null)
|
||||
{
|
||||
$default = '%01.2f %s';
|
||||
}
|
||||
|
||||
// Loop
|
||||
$i = 0;
|
||||
while ($unit != $i && $size >= 1024 && $i < $ii)
|
||||
{
|
||||
$size /= $mod;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return sprintf($default, $size, $sizes[$i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a number of seconds into Hours:Minutes:Seconds.
|
||||
*
|
||||
* @param integer $seconds (Required) The number of seconds to convert.
|
||||
* @return string The formatted time.
|
||||
*/
|
||||
public function time_hms($seconds)
|
||||
{
|
||||
$time = '';
|
||||
|
||||
// First pass
|
||||
$hours = (int) ($seconds / 3600);
|
||||
$seconds = $seconds % 3600;
|
||||
$minutes = (int) ($seconds / 60);
|
||||
$seconds = $seconds % 60;
|
||||
|
||||
// Cleanup
|
||||
$time .= ($hours) ? $hours . ':' : '';
|
||||
$time .= ($minutes < 10 && $hours > 0) ? '0' . $minutes : $minutes;
|
||||
$time .= ':';
|
||||
$time .= ($seconds < 10) ? '0' . $seconds : $seconds;
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first value that is set. Based on [Try.these()](http://api.prototypejs.org/language/Try/these/) from [Prototype](http://prototypejs.org).
|
||||
*
|
||||
* @param array $attrs (Required) The attributes to test, as strings. Intended for testing properties of the $base object, but also works with variables if you place an @ symbol at the beginning of the command.
|
||||
* @param object $base (Optional) The base object to use, if any.
|
||||
* @param mixed $default (Optional) What to return if there are no matches. Defaults to `null`.
|
||||
* @return mixed Either a matching property of a given object, boolean `false`, or any other data type you might choose.
|
||||
*/
|
||||
public function try_these($attrs, $base = null, $default = null)
|
||||
{
|
||||
if ($base)
|
||||
{
|
||||
foreach ($attrs as $attr)
|
||||
{
|
||||
if (isset($base->$attr))
|
||||
{
|
||||
return $base->$attr;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($attrs as $attr)
|
||||
{
|
||||
if (isset($attr))
|
||||
{
|
||||
return $attr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be removed once all calls are updated.
|
||||
*
|
||||
* @deprecated Use <php:json_encode()> instead.
|
||||
* @param mixed $obj (Required) The PHP object to convert into a JSON string.
|
||||
* @return string A JSON string.
|
||||
*/
|
||||
public function json_encode($obj)
|
||||
{
|
||||
return json_encode($obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a SimpleXML response to an array structure.
|
||||
*
|
||||
* @param ResponseCore $response (Required) A response value.
|
||||
* @return array The response value as a standard, multi-dimensional array.
|
||||
*/
|
||||
public function convert_response_to_array(ResponseCore $response)
|
||||
{
|
||||
return json_decode(json_encode($response), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a date stamp is ISO-8601 formatted, and if not, makes it so.
|
||||
*
|
||||
* @param string $datestamp (Required) A date stamp, or a string that can be parsed into a date stamp.
|
||||
* @return string An ISO-8601 formatted date stamp.
|
||||
*/
|
||||
public function convert_date_to_iso8601($datestamp)
|
||||
{
|
||||
if (!preg_match('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}((\+|-)\d{2}:\d{2}|Z)/m', $datestamp))
|
||||
{
|
||||
return gmdate(self::DATE_FORMAT_ISO8601, strtotime($datestamp));
|
||||
}
|
||||
|
||||
return $datestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the data is Base64 encoded or not.
|
||||
*
|
||||
* @license http://us.php.net/manual/en/function.base64-decode.php#81425 PHP License
|
||||
* @param string $s (Required) The string to test.
|
||||
* @return boolean Whether the string is Base64 encoded or not.
|
||||
*/
|
||||
public function is_base64($s)
|
||||
{
|
||||
return (bool) preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the data is a JSON string or not.
|
||||
*
|
||||
* @param string $s (Required) The string to test.
|
||||
* @return boolean Whether the string is a valid JSON object or not.
|
||||
*/
|
||||
public function is_json($s)
|
||||
{
|
||||
return !!(json_decode($s) instanceof stdClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes `\uXXXX` entities into their real unicode character equivalents.
|
||||
*
|
||||
* @param string $s (Required) The string to decode.
|
||||
* @return string The decoded string.
|
||||
*/
|
||||
public function decode_uhex($s)
|
||||
{
|
||||
preg_match_all('/\\\u([0-9a-f]{4})/i', $s, $matches);
|
||||
$matches = $matches[count($matches) - 1];
|
||||
$map = array();
|
||||
|
||||
foreach ($matches as $match)
|
||||
{
|
||||
if (!isset($map[$match]))
|
||||
{
|
||||
$map['\u' . $match] = html_entity_decode('&#' . hexdec($match) . ';', ENT_NOQUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
return str_replace(array_keys($map), $map, $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random GUID.
|
||||
*
|
||||
* @author Alix Axel <http://www.php.net/manual/en/function.com-create-guid.php#99425>
|
||||
* @license http://www.php.net/license/3_01.txt PHP License
|
||||
* @return string A random GUID.
|
||||
*/
|
||||
public function generate_guid()
|
||||
{
|
||||
return sprintf(
|
||||
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(16384, 20479),
|
||||
mt_rand(32768, 49151),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user