c2ephp
|
00001 <?php 00002 require_once(dirname(__FILE__).'/PrayBlock.php'); 00003 require_once(dirname(__FILE__).'/../../support/StringReader.php'); 00005 00018 abstract class TagBlock extends PrayBlock { 00020 private $tags; 00021 00023 00030 public function TagBlock($prayfile,$name,$content,$flags,$type) { 00031 parent::PrayBlock($prayfile,$name,$content,$flags,$type); 00032 if($prayfile instanceof PRAYFile) { 00033 } else if(is_array($prayfile)) { 00034 $this->tags = $prayfile; 00035 } 00036 } 00038 00040 00044 public function GetTag($key) { 00045 $this->EnsureDecompiled(); 00046 foreach($this->tags as $tk => $tv) { 00047 if($key == $tk) { 00048 return $tv; 00049 } 00050 } 00051 } 00053 00057 public function GetTags() { 00058 $this->EnsureDecompiled(); 00059 return $this->tags; 00060 } 00061 00063 00069 public function SetTag($tag,$value) { 00070 $this->EnsureDecompiled(); 00071 $this->tags[$tag] = $value; 00072 } 00074 00076 00081 protected function CompileBlockData() { 00082 $compiled = ''; 00083 $ints = array(); 00084 $strings = array(); 00085 foreach($this->tags as $key=>$value) { 00086 if(is_int($value)) { 00087 $ints[$key] = $value; 00088 } else { 00089 $strings[$key] = $value; 00090 } 00091 } 00092 $compiled .= pack('V',sizeof($ints)); 00093 foreach($ints as $key=>$value) { 00094 $compiled .= pack('V',strlen($key)); 00095 $compiled .= $key; 00096 $compiled .= pack('V',$value); 00097 } 00098 $compiled .= pack('V',sizeof($strings)); 00099 foreach($strings as $key=>$value) { 00100 $compiled .= pack('V',strlen($key)); 00101 $compiled .= $key; 00102 $compiled .= pack('V',strlen($value)); 00103 $compiled .= $value; 00104 } 00105 return $compiled; 00106 } 00107 00109 00112 protected function DecompileBlockData() { 00113 //use GetData because it decompresses if necessary. 00114 $blockReader = new StringReader($this->GetData()); 00115 00116 $numInts = $blockReader->ReadInt(4); 00117 for($i=0;$i<$numInts;$i++) { 00118 $nameLength = $blockReader->ReadInt(4); 00119 $name = $blockReader->Read($nameLength); 00120 $int = $blockReader->ReadInt(4); 00121 $this->tags[$name] = $int; 00122 } 00123 00124 00125 $numStrings = $blockReader->ReadInt(4); 00126 for($i=0;$i<$numStrings;$i++) { 00127 $nameLength = $blockReader->ReadInt(4); 00128 $name = $blockReader->Read($nameLength); 00129 $stringLength = $blockReader->ReadInt(4); 00130 $string = $blockReader->Read($stringLength); 00131 $this->tags[$name] = $string; 00132 } 00133 } 00135 } 00136 ?>