/**
  *	This funtion add a new object to the persistent object store.
  *
  *	@param	$name		The name of the object.
  *	@param	$object		The object to store.
  *  @param  $passwd     (optional) If not null, the data will be encrypted with this password.
  *  @param  $expire     (optional) The lifetime of the object in seconds. Defaults to 0 (session only).
  *  @param  $override   (optional) If an existing value should be overridden or not. Default is true.
  */
 function set($name, $object, $passwd = null, $expire = null, $override = true)
 {
     // Initialize the store
     YDPersistent::_init();
     // Don't overwrite existing values
     if (YDPersistent::exists($name) && $override === false) {
         return;
     }
     // Set the expire time
     if (is_null($expire)) {
         $expire = YDConfig::get('YD_PERSISTENT_DEFAULT_LIFETIME', 0);
     }
     // Convert the object to a base64 encoded serialized version
     $object_data = base64_encode(serialize($object));
     // Encrypt the data if needed
     if (is_null($passwd) && !is_null(YDConfig::get('YD_PERSISTENT_DEFAULT_PASSWORD', null))) {
         $passwd = YDConfig::get('YD_PERSISTENT_DEFAULT_PASSWORD', null);
     }
     if (!is_null($passwd)) {
         $object_data = YDEncryption::encrypt($passwd, $object_data);
     }
     // Get the scope
     $scope = YDConfig::get('YD_PERSISTENT_SCOPE', '/');
     // Save the object
     $_COOKIE[YDConfig::get('YD_PERSISTENT_STORE_NAME')][$name] = $object_data;
     setcookie(YDConfig::get('YD_PERSISTENT_STORE_NAME') . '[' . $name . ']', $object_data, $expire, $scope);
 }
 function actionDefault()
 {
     // Show the current object
     YDDebugUtil::dump($this, 'Original object before encryption');
     // Get the serialized version of ourselves
     //$data = $this->serialize();
     YDDebugUtil::dump($this, 'Input data');
     // Show the password we are using
     YDDebugUtil::dump(YD_SELF_SCRIPT, 'Encryption password');
     // Encrypt the data
     $data_encrypted = YDEncryption::encrypt(YD_SELF_SCRIPT, $this);
     YDDebugUtil::dump($data_encrypted, 'Encrypted data');
     // Decrypt the data
     $data_decrypted = YDEncryption::decrypt(YD_SELF_SCRIPT, $data_encrypted);
     //YDDebugUtil::dump( $data_decrypted, 'Decrypted data' );
     // Show the decrypted object
     YDDebugUtil::dump($data_decrypted, 'Original object after decryption');
 }
 /**
  *	This function will check if there is a product in the cart.
  *
  *  @param $id	Product ID.
  *
  *  @returns	Boolean indicating if the product is already in the cart.
  */
 function inCart($id)
 {
     return array_key_exists(YDEncryption::encrypt(YDConfig::get('YD_CART_PASSWORD'), $id), $this->item);
 }