summaryrefslogtreecommitdiff
path: root/framework/Web/UI/THiddenFieldPageStatePersister.php
diff options
context:
space:
mode:
authorxue <>2005-11-10 12:47:19 +0000
committerxue <>2005-11-10 12:47:19 +0000
commit55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 (patch)
treea0599d5e36fdbb3f1e169ae56bab7d529597e3eb /framework/Web/UI/THiddenFieldPageStatePersister.php
Initial import of prado framework
Diffstat (limited to 'framework/Web/UI/THiddenFieldPageStatePersister.php')
-rw-r--r--framework/Web/UI/THiddenFieldPageStatePersister.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/framework/Web/UI/THiddenFieldPageStatePersister.php b/framework/Web/UI/THiddenFieldPageStatePersister.php
new file mode 100644
index 00000000..d2cb5226
--- /dev/null
+++ b/framework/Web/UI/THiddenFieldPageStatePersister.php
@@ -0,0 +1,59 @@
+<?php
+
+require_once(PRADO_DIR.'/Web/UI/TPageStatePersister.php');
+
+class THiddenFieldPageStatePersister extends TPageStatePersister
+{
+ private $_page;
+
+ public function __construct($page)
+ {
+ $this->_page=$page;
+ }
+
+ public function save($state)
+ {
+ $data=Prado::serialize($state);
+ $hmac=$this->computeHMAC($data,$this->getKey());
+ if(function_exists('gzuncompress') && function_exists('gzcompress'))
+ $data=gzcompress($hmac.$data);
+ else
+ $data=$hmac.$data;
+ $this->_page->saveStateField($data);
+ }
+
+ public function load()
+ {
+ $str=$this->_page->loadStateField();
+ if($str==='')
+ return null;
+ if(function_exists('gzuncompress') && function_exists('gzcompress'))
+ $data=gzuncompress($str);
+ else
+ $data=$str;
+ if($data!==false && strlen($data)>32)
+ {
+ $hmac=substr($data,0,32);
+ $state=substr($data,32);
+ if($hmac===$this->computeHMAC($state,$this->getKey()))
+ return Prado::unserialize($state);
+ }
+ throw new Exception('viewstate data is corrupted.');
+ }
+
+ private function getKey()
+ {
+ return 'abcdefe';
+ }
+
+ private function computeHMAC($data,$key)
+ {
+ if (strlen($key) > 64)
+ $key = pack('H32', md5($key));
+ elseif (strlen($key) < 64)
+ $key = str_pad($key, 64, "\0");
+ return md5((str_repeat("\x5c", 64) ^ substr($key, 0, 64)) . pack('H32', md5((str_repeat("\x36", 64) ^ substr($key, 0, 64)) . $data)));
+ }
+}
+
+?> \ No newline at end of file