props = array(); $this->jar_name = $jar_name; $this->use_pclzip = $use_pclzip; $this->path_to_pclzip = $path_to_pclzip; $this->parse(); } function __destruct() { unset($this->props); } public function add_app_property($key, $val) { if (!isset($this->props[$key])) { $this->props[$key] = $val; return TRUE; } return FALSE; } public function get_app_property($key) { return isset($this->props[$key]) ? $this->props[$key] : NULL; } public function set_app_property($key, $val) { if (isset($this->props[$key])) { $this->props[$key] = $val; return TRUE; } return FALSE; } public function get_permissions() { return $this->get_permissions0(); } public function get_permissions_opt() { return $this->get_permissions0(TRUE); } public function get_keys() { return $this->get_from_props(); } public function get_vals() { return $this->get_from_props(TRUE); } /* это, пожалуй, лишнее public function get_props() { return $this->props; } public function set_props($props) { $this->props = $props; } */ public function midlets_count() { } public function count() { return count($this->props); } public function save() { $tmp_file_name = 'META-INF/MANIFEST.MF'; $tmp_file_pointer = fopen($tmp_file_name, 'w+'); foreach($this->props as $key => $val) { fwrite($tmp_file_pointer, $key . ': ' . $val . '\n'); } fclose($tmp_file_pointer); if ($this->use_pclzip) { return $this->save_pclzip(); } return $this->save_za(); } public function echo() { foreach($this->props as $key => $val) { echo $key . ': ' . $val; } } private function parse() { $tmp_file_name = $this->read_manifest(); $arr = file($tmp_file_name); foreach($arr as $str) { $pos = strpos($str, ':'); if ($pos >= 0) { $this->props[trim(substr($str, 0, $pos))] = trim(substr($str, $pos+1))); } else { /* бывает глючит и часть значения переносится на другую строку: * MIDlet-1: midlet, /ic * on, ChildMIDlet */ echo 'WARNING', $str; $this->props[count($this->props)-1] .= trim($str); } } unlink($tmp_file_name); } private function read_manifest() { if ($this->use_pclzip) { return $this->read_mf_pclzip(); } return $this->read_mf_za(); } private function read_mf_pclzip() { include_once $path_to_pclzip; $jar = new PclZip($this->jar_name); return 'META-INF/MANIFEST.MF'; } private function read_mf_za() { $jar = new ZipArchive; $jar->open($this->jar_name); return 'META-INF/MANIFEST.MF'; } private function save_pclzip() { include_once $path_to_pclzip; return FALSE; } private function save_az() { return FALSE; } private function get_permissions0($f = FALSE) { $val = $this->get_app_property('MIDlet-Permissions' . ($f ? '-Opt' : '')); return $val != NULL ? explode(',' $val) : NULL; } private function get_from_props($f = FALSE) { $out = array(); foreach($this->props as $key => $val) { $out[] = $f ? $val : $key; } return $out; } } ?>