/**
* HTTP API: WP_Http_Cookie class
*
* @package WordPress
* @subpackage HTTP
* @since 4.4.0
*/
/**
* Core class used to encapsulate a single cookie object for internal use.
*
* Returned cookies are represented using this class, and when cookies are set, if they are not
* already a WP_Http_Cookie() object, then they are turned into one.
*
* @todo The WordPress convention is to use underscores instead of camelCase for function and method
* names. Need to switch to use underscores instead for the methods.
*
* @since 2.8.0
*/
#[AllowDynamicProperties]
class WP_Http_Cookie {
/**
* Cookie name.
*
* @since 2.8.0
*
* @var string
*/
public $name;
/**
* Cookie value.
*
* @since 2.8.0
*
* @var string
*/
public $value;
/**
* When the cookie expires. Unix timestamp or formatted date.
*
* @since 2.8.0
*
* @var string|int|null
*/
public $expires;
/**
* Cookie URL path.
*
* @since 2.8.0
*
* @var string
*/
public $path;
/**
* Cookie Domain.
*
* @since 2.8.0
*
* @var string
*/
public $domain;
/**
* Cookie port or comma-separated list of ports.
*
* @since 2.8.0
*
* @var int|string
*/
public $port;
/**
* host-only flag.
*
* @since 5.2.0
*
* @var bool
*/
public $host_only;
/**
* Sets up this cookie object.
*
* The parameter $data should be either an associative array containing the indices names below
* or a header string detailing it.
*
* @since 2.8.0
* @since 5.2.0 Added `host_only` to the `$data` parameter.
*
* @param string|array $data {
* Raw cookie data as header string or data array.
*
* @type string $name Cookie name.
* @type mixed $value Value. Should NOT already be urlencoded.
* @type string|int|null $expires Optional. Unix timestamp or formatted date. Default null.
* @type string $path Optional. Path. Default '/'.
* @type string $domain Optional. Domain. Default host of parsed $requested_url.
* @type int|string $port Optional. Port or comma-separated list of ports. Default null.
* @type bool $host_only Optional. host-only storage flag. Default true.
* }
* @param string $requested_url The URL which the cookie was set on, used for default $domain
* and $port values.
*/
public function __construct( $data, $requested_url = '' ) {
if ( $requested_url ) {
$parsed_url = parse_url( $requested_url );
}
if ( isset( $parsed_url['host'] ) ) {
$this->domain = $parsed_url['host'];
}
$this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
if ( ! str_ends_with( $this->path, '/' ) ) {
$this->path = dirname( $this->path ) . '/';
}
if ( is_string( $data ) ) {
// Assume it's a header string direct from a previous request.
$pairs = explode( ';', $data );
// Special handling for first pair; name=value. Also be careful of "=" in value.
$name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) );
$value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 );
$this->name = $name;
$this->value = urldecode( $value );
// Removes name=value from items.
array_shift( $pairs );
// Set everything else as a property.
foreach ( $pairs as $pair ) {
$pair = rtrim( $pair );
// Handle the cookie ending in ; which results in an empty final pair.
if ( empty( $pair ) ) {
continue;
}
list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' );
$key = strtolower( trim( $key ) );
if ( 'expires' === $key ) {
$val = strtotime( $val );
}
$this->$key = $val;
}
} else {
if ( ! isset( $data['name'] ) ) {
return;
}
// Set properties based directly on parameters.
foreach ( array( 'name', 'value', 'path', 'domain', 'port', 'host_only' ) as $field ) {
if ( isset( $data[ $field ] ) ) {
$this->$field = $data[ $field ];
}
}
if ( isset( $data['expires'] ) ) {
$this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] );
} else {
$this->expires = null;
}
}
}
/**
* Confirms that it's OK to send this cookie to the URL checked against.
*
* Decision is based on RFC 2109/2965, so look there for details on validity.
*
* @since 2.8.0
*
* @param string $url URL you intend to send this cookie to
* @return bool true if allowed, false otherwise.
*/
public function test( $url ) {
if ( is_null( $this->name ) ) {
return false;
}
// Expires - if expired then nothing else matters.
if ( isset( $this->expires ) && time() > $this->expires ) {
return false;
}
// Get details on the URL we're thinking about sending to.
$url = parse_url( $url );
$url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' === $url['scheme'] ? 443 : 80 );
$url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
// Values to use for comparison against the URL.
$path = isset( $this->path ) ? $this->path : '/';
$port = isset( $this->port ) ? $this->port : null;
$domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] );
if ( false === stripos( $domain, '.' ) ) {
$domain .= '.local';
}
// Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
$domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain;
if ( ! str_ends_with( $url['host'], $domain ) ) {
return false;
}
// Port - supports "port-lists" in the format: "80,8000,8080".
if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) {
return false;
}
// Path - request path must start with path restriction.
if ( ! str_starts_with( $url['path'], $path ) ) {
return false;
}
return true;
}
/**
* Convert cookie name and value back to header string.
*
* @since 2.8.0
*
* @return string Header encoded cookie name and value.
*/
public function getHeaderValue() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
if ( ! isset( $this->name ) || ! isset( $this->value ) ) {
return '';
}
/**
* Filters the header-encoded cookie value.
*
* @since 3.4.0
*
* @param string $value The cookie value.
* @param string $name The cookie name.
*/
return $this->name . '=' . apply_filters( 'wp_http_cookie_value', $this->value, $this->name );
}
/**
* Retrieve cookie header for usage in the rest of the WordPress HTTP API.
*
* @since 2.8.0
*
* @return string
*/
public function getFullHeader() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
return 'Cookie: ' . $this->getHeaderValue();
}
/**
* Retrieves cookie attributes.
*
* @since 4.6.0
*
* @return array {
* List of attributes.
*
* @type string|int|null $expires When the cookie expires. Unix timestamp or formatted date.
* @type string $path Cookie URL path.
* @type string $domain Cookie domain.
* }
*/
public function get_attributes() {
return array(
'expires' => $this->expires,
'path' => $this->path,
'domain' => $this->domain,
);
}
}
� �}�v�ƲV��
/[dB� x�Le˒�\l˱�dg�h��A @Q���:�0O�v�b����/���ƕ EJJΜY�8�]]������٣㓣��߽ �h��>�?�1��@��|~*a5,r�,�=��c�1�.���+O�=�D}Ϳ�yV�����B&
�I�a�^�j�#;#?��p��6\�����/��Q7���ll�a}ސ#/2�4� ���a�sXG��gX
�U>�1���G��F1'F�h ��������1��Ҧs�"��in[�d`�Kۤ2{�۵#ȇ��Ё��Dv�=�9�l�������\Z��Y�Cd ��Ћ½���Ը���1�2(��;F0�{Hb'Up�+B�+�Y�I��T#<���U�5�m@U�n��lSF�>i���_���$�dX��Yn���hdN�x����#�*c�C��v���8LKJ�u��H��A���;�iD��փ0��j�@�d �`���X��]� ��d��40��y��%����� �.��y�)�_�-��(����B�,���z]m�U�>�e�.�D����E4
�sA$���qJ���E�*�6.��+Կ%�}8:><;�@����m�����ܧS�}J#@>ɀ\KC#��#����2W�`����l�*4���Ǻ�RT���ѯ:�ǺT��(���^�����AA�
���� �=�i*��%h�`&�X�j�~DGk��3����%02��c������Qt��fT���M쐌l����GS����Z}4��&mŮ���K# ^-���8��Z���ˋ���G?|F�(��ZdO�ɘ���K��W�KÙѓQ�z��04������?�������[%D�7�G�JT�ހ^� ���I�����Q�Q��Ԍ*jM���Ⴝ(��'��[�BH�A�V" W��\ ��nC?cQ��x�:ލMP+ Vk��r�\�S�����4�.�
F��$�
�^�L:�ѧ�j��Y��pn�����F�1��� ��>άnÄߣQ��lD��Ǚ���n�"�����?����h���ynH�,�$P}��Q��&�6U�m�;�g=���<�r�NA�fB>\HїRZK)�v<@��Ϫ@8 ^I-�ۉ���P*��������>�kE0�f�EG�}ˣzdoD~�/4x�xC�95=�>}Rg!�w�,���d4/N�{���L
B�j�V ��bgV��%K՚1���0ւ�!�T��C[y��ˀ�1xg���Tkޠb(���v�/�����VU��!p:� ���u@��f�G���@?
��Q��$��)�|�8��]Uu?R���BP"x�Gj�V0�V *��u4��M�����A�BZ�E�s;�6�j��o�5a�j�"\q8�fm>�@PQ-}{qeR?z Qu5ʼ���S������zm������~_C�<�~�����n��ZBq}��$%�>�y}#�J�g�=�2{T���gp�� �hHrg�!
2iJ����J��g���j����f ���Ԫ��dS3�S�!���0fACB�W�" Z�Wh(�@��_?}
����0�Yb�sh��Tݒ��P4h�"}7R"�u���w$|(��a�6������'�g��@(�$A�*G�hA�k䡿��`�F@��J�,��Z��aWZ ��������{��4~ϝr�Y6+�D AP1��{�T!��*amV�!���J4�n�Q�����>��j��P��i�J����O����xs~F��[V"m���������=�@ � )��Ƌ�#
�|<2gh�_�m=��,�5�EJ��і3��V
D�^+%a��?� n^���G����>U����Sps�XA8@U�2�_��G5�3g����C�*F��ӧ�a���?;��c��pBi�Glk���"ɜ�@ޓAS*�a�淛�a��z%�6P %4m���Xe��Բ���O�"��d�������������[�"����WV�\���Xv�;ƢO8�Ȟbn��C/�h�'0�\κ�É�.�sXD��B��2�F0��>Q�����lPT��^�p�1�ɪ���ox�K��/Ůh�2nv���5FJ:��Ev�a`��M"+b��A�Q=�P�c�`c�m��t�竸�nb!F�D��,�<���tmz���F��T�Hm�N���&$�e��~~�����`-�#7�Ea���ixb\YP�fEi��$�#>V KҔF����c��g�4E�[tz�r��]\pޯ363�����y����z#�ϋ�e©Ak˲���ʌ�,�̌�B��_Ք}Ҭ7�5�f�4��[�t���HN���֖{�w��[��>�յv��^���j��*�)�1��3;��� ��cc8�E�|bG�R�V��R�p��1#\�k�r�K�Ҷ䀂_yl�t��r8g�כ�� X�;�<�{��*�10��"�pu���Q�V �3��ak�9p��ݢ�d�+��RK��pg��v�AW� ��g�� ho��hQ�1:�9�p������AR��5Zׂ�Ш�kZ�S��NM�� &V�V��� �Y%��>��$]�pJ;����+��`wՄ�Z��nMk��R/1 �`�y�S��ҁ�VMMՀ�����ĭX�$Sm�&��~��Ѓ�vj�6���8F�IU$���T�������
�{��fM�n#oz��4�F0��;fӵ;M��Ċ�V�t��^��Y
`ŀ
�q0�lr�h�iX����Ihvk�[�j-q���dXU�j$hg��q��j�������-�@Kk�R���f�UI+&ZRkm}c�f�
Dl�4MOE���)h==��?���zi�+=���
�&������=�Z�0�w\V�ֆI�G� )�SWuf1��iZ�U���jFS�ry8��F
����Mh��RkE�%�?Sd!�h@h�C^l|�����Bd�^t�5�%��7L�:!�Qa��4���i0�vg
H@�5�-�WZk � �+�:��4�Fw
H@Z��.aq�,���
�P�u�<�Z#⟢k1.mQ�$8��~�Ԓ��U��o�ʮ��j�J+_\n�8����V�%�y�*
f ��u�Aɛ�|BZQ��kL�#�^U�dž�F�2�q`[y��g-H�u2JǷ��b6���b���l�,C�;�`B;��R!r@pCķ5bٗ��d���r�o9d��Y,r2�8p6u�r=�Y-�)�Q[y�]�A~�9��4EomU6C4.�L���\x|+F���*�G9����Qj6DW,V��
�6D�`Kp$��
�$�%���qC\ | ���t3��eo��#�;�`E�(Gb/[��1����t\��Y$�V�-�B��xy �R^�#o��I��Y���!����۽�}�o�K�Ca{sj��;Hxcot/�w�Q���m<Msv�6�r�'u�����y��A|��o���|w���;`��O�������܇݅�]|ם�j+�uWS��W�Y��}ԝI��M�,�sZ�;̮���x1b;,YC�K�ش=�Z]���P��We���e6v������v�e}h�RŽ�(�X�Ev�J��R�ЋQ��A\\xsCL��<[K��M �������Q�Њ�
�E%FR������������2~���e���w@�ʕ3ƫ2���U�˄��ya��,s:s�?f^Ķ�&���<�Ɠl_S���m��pb���wWX��.��V��2��qX~0�?2����6"�I㰩�O����>}�6��wضh|��)X�ܶ���eܶwqgG1 ҈B�[qgG�c4< �ƱN�