Submit
Path:
~
/
/
var
/
softaculous
/
sitepad
/
editor
/
site-data
/
plugins
/
kkart-pro
/
includes
/
File Content:
class-kkart-session-handler.php
<?php /** * Handle data for the current customers session. * Implements the KKART_Session abstract class. * * From 2.5 this uses a custom table for session storage. Based on https://github.com/kloon/kkart-large-sessions. * * @class KKART_Session_Handler * @version 2.5.0 * @package Kkart\Classes */ use Automattic\Jetpack\Constants; defined( 'ABSPATH' ) || exit; /** * Session handler class. */ class KKART_Session_Handler extends KKART_Session { /** * Cookie name used for the session. * * @var string cookie name */ protected $_cookie; /** * Stores session expiry. * * @var string session due to expire timestamp */ protected $_session_expiring; /** * Stores session due to expire timestamp. * * @var string session expiration timestamp */ protected $_session_expiration; /** * True when the cookie exists. * * @var bool Based on whether a cookie exists. */ protected $_has_cookie = false; /** * Table name for session data. * * @var string Custom session table name */ protected $_table; /** * Constructor for the session class. */ public function __construct() { $this->_cookie = apply_filters( 'kkart_cookie', 'wp_kkart_session_' . COOKIEHASH ); $this->_table = $GLOBALS['wpdb']->prefix . 'kkart_sessions'; } /** * Init hooks and session data. * * @since 3.3.0 */ public function init() { $this->init_session_cookie(); add_action( 'kkart_set_cart_cookies', array( $this, 'set_customer_session_cookie' ), 10 ); add_action( 'shutdown', array( $this, 'save_data' ), 20 ); add_action( 'wp_logout', array( $this, 'destroy_session' ) ); if ( ! is_user_logged_in() ) { add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); } } /** * Setup cookie and customer ID. * * @since 3.6.0 */ public function init_session_cookie() { $cookie = $this->get_session_cookie(); if ( $cookie ) { $this->_customer_id = $cookie[0]; $this->_session_expiration = $cookie[1]; $this->_session_expiring = $cookie[2]; $this->_has_cookie = true; $this->_data = $this->get_session_data(); // If the user logs in, update session. if ( is_user_logged_in() && strval( get_current_user_id() ) !== $this->_customer_id ) { $guest_session_id = $this->_customer_id; $this->_customer_id = strval( get_current_user_id() ); $this->_dirty = true; $this->save_data( $guest_session_id ); $this->set_customer_session_cookie( true ); } // Update session if its close to expiring. if ( time() > $this->_session_expiring ) { $this->set_session_expiration(); $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); } } else { $this->set_session_expiration(); $this->_customer_id = $this->generate_customer_id(); $this->_data = $this->get_session_data(); } } /** * Sets the session cookie on-demand (usually after adding an item to the cart). * * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. * * Warning: Cookies will only be set if this is called before the headers are sent. * * @param bool $set Should the session cookie be set. */ public function set_customer_session_cookie( $set ) { if ( $set ) { $to_hash = $this->_customer_id . '|' . $this->_session_expiration; $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; $this->_has_cookie = true; if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { kkart_setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); } } } /** * Should the session cookie be secure? * * @since 3.6.0 * @return bool */ protected function use_secure_cookie() { return apply_filters( 'kkart_session_use_secure_cookie', kkart_site_is_https() && is_ssl() ); } /** * Return true if the current user has an active session, i.e. a cookie to retrieve values. * * @return bool */ public function has_session() { return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. } /** * Set session expiration. */ public function set_session_expiration() { $this->_session_expiring = time() + intval( apply_filters( 'kkart_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. $this->_session_expiration = time() + intval( apply_filters( 'kkart_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. } /** * Generate a unique customer ID for guests, or return user ID if logged in. * * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. * * @return string */ public function generate_customer_id() { $customer_id = ''; if ( is_user_logged_in() ) { $customer_id = strval( get_current_user_id() ); } if ( empty( $customer_id ) ) { $lib = ABSPATH . 'site-inc/class-phpass.php'; $lib = file_exists($lib) ? $lib : ABSPATH . 'wp-includes/class-phpass.php'; require_once($lib); $hasher = new PasswordHash( 8, false ); $customer_id = md5( $hasher->get_random_bytes( 32 ) ); } return $customer_id; } /** * Get the session cookie, if set. Otherwise return false. * * Session cookies without a customer ID are invalid. * * @return bool|array */ public function get_session_cookie() { $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { return false; } list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); if ( empty( $customer_id ) ) { return false; } // Validate hash. $to_hash = $customer_id . '|' . $session_expiration; $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { return false; } return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); } /** * Get session data. * * @return array */ public function get_session_data() { return $this->has_session() ? (array) $this->get_session( $this->_customer_id, array() ) : array(); } /** * Gets a cache prefix. This is used in session names so the entire cache can be invalidated with 1 function call. * * @return string */ private function get_cache_prefix() { return KKART_Cache_Helper::get_cache_prefix( KKART_SESSION_CACHE_GROUP ); } /** * Save data and delete guest session. * * @param int $old_session_key session ID before user logs in. */ public function save_data( $old_session_key = 0 ) { // Dirty if something changed - prevents saving nothing new. if ( $this->_dirty && $this->has_session() ) { global $wpdb; $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->prefix}kkart_sessions (`session_key`, `session_value`, `session_expiry`) VALUES (%s, %s, %d) ON DUPLICATE KEY UPDATE `session_value` = VALUES(`session_value`), `session_expiry` = VALUES(`session_expiry`)", $this->_customer_id, maybe_serialize( $this->_data ), $this->_session_expiration ) ); wp_cache_set( $this->get_cache_prefix() . $this->_customer_id, $this->_data, KKART_SESSION_CACHE_GROUP, $this->_session_expiration - time() ); $this->_dirty = false; if ( get_current_user_id() != $old_session_key && ! is_object( get_user_by( 'id', $old_session_key ) ) ) { $this->delete_session( $old_session_key ); } } } /** * Destroy all session data. */ public function destroy_session() { $this->delete_session( $this->_customer_id ); $this->forget_session(); } /** * Forget all session data without destroying it. */ public function forget_session() { kkart_setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); kkart_empty_cart(); $this->_data = array(); $this->_dirty = false; $this->_customer_id = $this->generate_customer_id(); } /** * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. * * @param int $uid User ID. * @return string */ public function nonce_user_logged_out( $uid ) { return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; } /** * Cleanup session data from the database and clear caches. */ public function cleanup_sessions() { global $wpdb; $wpdb->query( $wpdb->prepare( "DELETE FROM $this->_table WHERE session_expiry < %d", time() ) ); // @codingStandardsIgnoreLine. if ( class_exists( 'KKART_Cache_Helper' ) ) { KKART_Cache_Helper::invalidate_cache_group( KKART_SESSION_CACHE_GROUP ); } } /** * Returns the session. * * @param string $customer_id Custo ID. * @param mixed $default Default session value. * @return string|array */ public function get_session( $customer_id, $default = false ) { global $wpdb; if ( Constants::is_defined( 'WP_SETUP_CONFIG' ) ) { return false; } // Try to get it from the cache, it will return false if not present or if object cache not in use. $value = wp_cache_get( $this->get_cache_prefix() . $customer_id, KKART_SESSION_CACHE_GROUP ); if ( false === $value ) { $value = $wpdb->get_var( $wpdb->prepare( "SELECT session_value FROM $this->_table WHERE session_key = %s", $customer_id ) ); // @codingStandardsIgnoreLine. if ( is_null( $value ) ) { $value = $default; } $cache_duration = $this->_session_expiration - time(); if ( 0 < $cache_duration ) { wp_cache_add( $this->get_cache_prefix() . $customer_id, $value, KKART_SESSION_CACHE_GROUP, $cache_duration ); } } return maybe_unserialize( $value ); } /** * Delete the session from the cache and database. * * @param int $customer_id Customer ID. */ public function delete_session( $customer_id ) { global $wpdb; wp_cache_delete( $this->get_cache_prefix() . $customer_id, KKART_SESSION_CACHE_GROUP ); $wpdb->delete( $this->_table, array( 'session_key' => $customer_id, ) ); } /** * Update the session expiry timestamp. * * @param string $customer_id Customer ID. * @param int $timestamp Timestamp to expire the cookie. */ public function update_session_timestamp( $customer_id, $timestamp ) { global $wpdb; $wpdb->update( $this->_table, array( 'session_expiry' => $timestamp, ), array( 'session_key' => $customer_id, ), array( '%d', ) ); } }
Submit
FILE
FOLDER
Name
Size
Permission
Action
abstracts
---
0755
admin
---
0755
cli
---
0755
customizer
---
0755
data-stores
---
0755
emails
---
0755
export
---
0755
gateways
---
0755
import
---
0755
integrations
---
0755
interfaces
---
0755
legacy
---
0755
libraries
---
0755
log-handlers
---
0755
payment-tokens
---
0755
queue
---
0755
rest-api
---
0755
shipping
---
0755
shortcodes
---
0755
theme-support
---
0755
tracks
---
0755
traits
---
0755
walkers
---
0755
wccom-site
---
0755
widgets
---
0755
body-props-settings.php
8379 bytes
0644
class-kkart-ajax.php
131339 bytes
0644
class-kkart-api.php
5090 bytes
0644
class-kkart-auth.php
11939 bytes
0644
class-kkart-autoloader.php
2842 bytes
0644
class-kkart-background-emailer.php
4703 bytes
0644
class-kkart-background-updater.php
3580 bytes
0644
class-kkart-breadcrumb.php
9692 bytes
0644
class-kkart-cache-helper.php
10967 bytes
0644
class-kkart-cart-fees.php
3498 bytes
0644
class-kkart-cart-session.php
14806 bytes
0644
class-kkart-cart-totals.php
28388 bytes
0644
class-kkart-cart.php
64753 bytes
0644
class-kkart-checkout.php
45656 bytes
0644
class-kkart-cli.php
1043 bytes
0644
class-kkart-comments.php
13305 bytes
0644
class-kkart-countries.php
43222 bytes
0644
class-kkart-coupon.php
33350 bytes
0644
class-kkart-customer-download-log.php
3458 bytes
0644
class-kkart-customer-download.php
10606 bytes
0644
class-kkart-customer.php
27894 bytes
0644
class-kkart-data-exception.php
1306 bytes
0644
class-kkart-data-store.php
6022 bytes
0644
class-kkart-datetime.php
2251 bytes
0644
class-kkart-deprecated-action-hooks.php
6697 bytes
0644
class-kkart-deprecated-filter-hooks.php
6413 bytes
0644
class-kkart-discounts.php
31706 bytes
0644
class-kkart-download-handler.php
23930 bytes
0644
class-kkart-emails.php
22698 bytes
0644
class-kkart-embed.php
4284 bytes
0644
class-kkart-form-handler.php
44776 bytes
0644
class-kkart-frontend-scripts.php
26623 bytes
0644
class-kkart-geo-ip.php
31165 bytes
0644
class-kkart-geolite-integration.php
2042 bytes
0644
class-kkart-geolocation.php
10586 bytes
0644
class-kkart-https.php
4397 bytes
0644
class-kkart-install.php
55130 bytes
0644
class-kkart-integrations.php
1316 bytes
0644
class-kkart-log-levels.php
2597 bytes
0644
class-kkart-logger.php
8405 bytes
0644
class-kkart-meta-data.php
2231 bytes
0644
class-kkart-order-factory.php
3212 bytes
0644
class-kkart-order-item-coupon.php
4118 bytes
0644
class-kkart-order-item-fee.php
8909 bytes
0644
class-kkart-order-item-meta.php
5939 bytes
0644
class-kkart-order-item-product.php
13366 bytes
0644
class-kkart-order-item-shipping.php
7933 bytes
0644
class-kkart-order-item-tax.php
6593 bytes
0644
class-kkart-order-item.php
10947 bytes
0644
class-kkart-order-query.php
2578 bytes
0644
class-kkart-order-refund.php
5009 bytes
0644
class-kkart-order.php
62493 bytes
0644
class-kkart-payment-gateways.php
5367 bytes
0644
class-kkart-payment-tokens.php
6047 bytes
0644
class-kkart-post-data.php
18242 bytes
0644
class-kkart-post-types.php
27128 bytes
0644
class-kkart-privacy-background-process.php
1734 bytes
0644
class-kkart-privacy-erasers.php
13603 bytes
0644
class-kkart-privacy-exporters.php
14458 bytes
0644
class-kkart-privacy.php
15212 bytes
0644
class-kkart-product-attribute.php
7052 bytes
0644
class-kkart-product-download.php
6159 bytes
0644
class-kkart-product-external.php
4889 bytes
0644
class-kkart-product-factory.php
3683 bytes
0644
class-kkart-product-grouped.php
5319 bytes
0644
class-kkart-product-query.php
2222 bytes
0644
class-kkart-product-simple.php
1899 bytes
0644
class-kkart-product-variable.php
21983 bytes
0644
class-kkart-product-variation.php
17610 bytes
0644
class-kkart-query.php
31129 bytes
0644
class-kkart-rate-limiter.php
2133 bytes
0644
class-kkart-regenerate-images-request.php
8365 bytes
0644
class-kkart-regenerate-images.php
15607 bytes
0644
class-kkart-register-wp-admin-settings.php
4990 bytes
0644
class-kkart-rest-authentication.php
19811 bytes
0644
class-kkart-rest-exception.php
273 bytes
0644
class-kkart-session-handler.php
10821 bytes
0644
class-kkart-shipping-rate.php
5388 bytes
0644
class-kkart-shipping-zone.php
13404 bytes
0644
class-kkart-shipping-zones.php
4169 bytes
0644
class-kkart-shipping.php
11607 bytes
0644
class-kkart-shortcodes.php
17618 bytes
0644
class-kkart-structured-data.php
17614 bytes
0644
class-kkart-tax.php
36697 bytes
0644
class-kkart-template-loader.php
18878 bytes
0644
class-kkart-tracker.php
23049 bytes
0644
class-kkart-validation.php
5975 bytes
0644
class-kkart-webhook.php
30567 bytes
0644
class-kkart.php
33477 bytes
0644
kkart-account-functions.php
12995 bytes
0644
kkart-attribute-functions.php
21083 bytes
0644
kkart-cart-functions.php
17683 bytes
0644
kkart-conditional-functions.php
12079 bytes
0644
kkart-core-functions.php
84228 bytes
0644
kkart-coupon-functions.php
2711 bytes
0644
kkart-formatting-functions.php
42607 bytes
0644
kkart-notice-functions.php
7623 bytes
0644
kkart-order-functions.php
34333 bytes
0644
kkart-order-item-functions.php
5177 bytes
0644
kkart-page-functions.php
7084 bytes
0644
kkart-product-functions.php
48433 bytes
0644
kkart-rest-functions.php
10876 bytes
0644
kkart-stock-functions.php
12753 bytes
0644
kkart-template-functions.php
168595 bytes
0644
kkart-template-hooks.php
11322 bytes
0644
kkart-term-functions.php
19918 bytes
0644
kkart-update-functions.php
66440 bytes
0644
kkart-user-functions.php
27222 bytes
0644
kkart-webhook-functions.php
5713 bytes
0644
kkart-widget-functions.php
2126 bytes
0644
premium.php
943 bytes
0644
premium_functions.php
957 bytes
0644
shortcode_functions.php
72821 bytes
0644
shortcodes.php
272113 bytes
0644
template.php
2921 bytes
0644
N4ST4R_ID | Naxtarrr