
Velichko Anton
 
Профиль
Группа: Участник
Сообщений: 851
Регистрация: 28.4.2005
Где: Санкт-Петербург
Репутация: нет Всего: 18
|
Я могу выложить код где формируется пекодировка из XML. | Код | <?
if (!defined("SAPID_STARTED")) die("Hacking attempt!");
if (isset($_POST["post_site"]) and stripslashes($_POST["post_site"]["new_xml"]) and isset($_SESSION["user"]["LOGIN"])) {
$tree->build_structure(); if ($_POST["recylceId"] and $DEMO_MODE!="enabled") { $d_ids=explode(",", $_POST["recylceId"]);
function get_node_children($node){ $ids[]=$node["ID"]; if(is_array($node["CHILDREN"])) foreach ($node["CHILDREN"] as $var=>$id) { $ids=array_merge($ids, get_node_children($node[$var])); } return $ids; }
foreach ($d_ids as $delete_id) { foreach ($tree->map as $page) { if ($page["ID"]==trim($delete_id)) { eval("\$node=\$tree->structure" . $page["POINTER"] . "; unset(\$tree->structure" . $page["POINTER"] . ");"); } }
if (is_array($node)) { $ids=get_node_children($node); foreach ($ids as $id) $id_pattern.=$id . "|"; $id_pattern=preg_replace("/\|$/", "", $id_pattern); $d = dir($root_path . "usr/xml/content/"); while (false !== ($entry = $d->read())) { if ($entry!="." and $entry!=".." and preg_match("/^(".$id_pattern.")\.xml/is", $entry)) { @unlink($root_path . "usr/xml/content/" . $entry); } } $d->close(); } } }
ignore_user_abort(true); $fp=@fopen($root_path ."usr/xml/tree.xml", "w+"); if (!$fp) message_die("Couldn't open </b>" . $root_path ."usr/xml/tree.xml</b> for writing!");
function decode($arr){ $unicode=array("0410","0411","0412","0413","0414","0415","0416","0417","0418","0419","041A","041B","041C","041D","041E","041F","0420","0421","0422","0423","0424","0425","0426","0427","0428","0429","042A","042B","042C","042D","042E","042F","0430","0431","0432","0433","0434","0435","0436","0437","0438","0439","043A","043B","043C","043D","043E","043F","0440","0441","0442","0443","0444","0445","0446","0447","0448","0449","044A","044B","044C","044D","044E","044F"); $cyr=array("À","Á","Â","Ã","Ä","Å","Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò","Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß","à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ"); $unicode=array_flip($unicode); if($cyr[$unicode[$arr[1]]]) return $cyr[$unicode[$arr[1]]]; else return null; } fwrite($fp, iconv($default_charset, "utf-8", str_replace("\r\n", "\n", str_replace("<?xml version=\"1.0\"?>", "<?xml version=\"1.0\" encoding=\"utf-8\"?>", stripslashes(preg_replace_callback("/%u([0-9ABCDEF]{4})/", "decode", $_POST["post_site"]["new_xml"])))))); fclose($fp); ignore_user_abort(false); }
$structure=$tree->build_structure();
$pointer=""; if (is_array($env["argv"])) foreach ($env["argv"] as $arg) $pointer.="[\"" . $arg . "\"]";
if ($pointer=="") { $code="\$env[\"page\"]=\$structure".$tree->default_pointer.";"; $code.="\$env[\"argv\"][0]=".$tree->default_pointer_var.";"; $code.="\$env[\"page\"][\"ID\"]=".$tree->default_pointer_id.";"; } else $code="\$env[\"page\"]=\$structure[\"root\"]".$pointer.";";
@eval($code);
//Doing recursive page search function check_virtual ($pointer="", $page=false){ global $tree, $env; if (!$env["page"]) { $pointer=""; foreach ($env["argv"] as $arg) { $prev_page=$page; $prev_pointer=$pointer; $pointer.="[\"" . $arg . "\"]"; $code="\$page=\$tree->structure[\"root\"]".$pointer.";"; eval($code); if (!is_array($page) and $prev_page["virtual"]["MASK"]) { //check for current argv to match given mask $exp=preg_replace(array("/#/", "/\?/"), array("\d", "[a-zA-Z]"), $prev_page["virtual"]["MASK"]); preg_match("/^" . $exp . "$/", $arg, $matches); if ($matches) { //Ok, arg mathes given pattern eval("\$tree->structure[\"root\"]".$pointer."=\$prev_page[\"virtual\"]; unset(\$tree->structure[\"root\"]".$prev_pointer . "[\"virtual\"]);"); $env["virtual_path_mask"].=$arg . "/"; check_virtual($pointer, $page); } } } } }
if (!$env["page"]) { check_virtual(); $code="\$env[\"page\"]=\$tree->structure[\"root\"]".$pointer.";"; @eval($code); }
?>
|
и вот здесь | Код | <?PHP // vim: set expandtab tabstop=4 shiftwidth=4: // +----------------------------------------------------------------------+ // | SAPID: XML Sapiens Engine Demonstrator | // +----------------------------------------------------------------------+ // | Author: Max Baryshnikov aka Mephius <[email protected]> | // | Copyright (c) 2004 Max Baryshnikov | // | http://sapid.sourceforge.net | // +----------------------------------------------------------------------+ // | This source file is free software; you can redistribute it and/or | // | modify it under the terms of the GNU Lesser General Public | // | License as published by the Free Software Foundation; either | // | version 2.1 of the License, or (at your option) any later version. | // | | // | This source file is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // | Lesser General Public License for more details. | // +----------------------------------------------------------------------+ // Release: 08.09.04 (dd/mm/yy) // $Id: tree.lib.php,v 1.2 2005/06/14 14:23:48 mephius Exp $
class tree { var $pointer; var $prev_pointer; var $last_var; var $structure; var $xml_file; var $xml; var $element; var $element_count; var $default_pointer; var $map; var $depth; var $default_pointer_var; var $default_pointer_id;
/** * @return tree * @param string $filename * @desc tree class constructor */ function tree($filename){ $this->pointer=""; $this->element=""; $this->element_count=0; $this->structure=array(); $this->map=array(); $this->xml_file=$filename; }
/** * @return void * @param XML Parser resourse ID $parser * @param string $name * @param string $attrs * @desc XML Parser start element handler */ function startElement($parser, $name, $attrs) { $this->depth++; $this->element=$name; if ($name=="TREEITEM") { $this->element_count++; $this->prev_pointer=$this->pointer; if ($attrs["VAR"]) { $this->pointer.="['" . $attrs["VAR"] . "']"; $this->last_var=$attrs["VAR"]; }else { $this->pointer.="['" . $name . "']"; $this->last_var=$name; } $this->element_count=(str_replace("id_", "", $attrs["ID"])?str_replace("id_", "", $attrs["ID"]):0); $this->map[$this->element_count]["ID"]=$this->element_count; $tmp=str_replace(array("['root", "']['"), array("", "/"), $this->pointer); $this->map[$this->element_count]["POINTER"]=$this->pointer; $this->map[$this->element_count]["HREF"]=str_replace("']", "/", $tmp); $this->map[$this->element_count]["VAR"]=$attrs["VAR"]; $this->map[$this->element_count]["OWNER"]=$attrs["OWNER"]; $this->map[$this->element_count]["GROUP"]=$attrs["GROUP"]; $this->map[$this->element_count]["PERMISSIONS"]=$attrs["PERMISSIONS"]; @eval("\$this->structure" . $this->prev_pointer . "[\"CHILDREN\"][\"".$this->last_var."\"]=" . $this->map[$this->element_count]["ID"] . ";"); @eval("\$this->structure" . $this->pointer . "[\"ID\"]=" . $this->map[$this->element_count]["ID"] . ";");
$this->map[$this->element_count]["LEVEL"]=$this->depth-2; if ($this->map[$this->element_count]["LEVEL"]==1 and !$this->default_pointer) { $this->default_pointer=$this->pointer; $this->default_pointer_var=$attrs["VAR"]; $this->default_pointer_id=$this->element_count; } } }
/** * @return void * @param XML Parser resourse ID $parser * @param string $name * @desc XML Parser end element handler */ function endElement($parser, $name) { $this->depth--; if ($name=="TREEITEM") { $this->pointer=preg_replace("/(.*)(\['(.*)'\])$/", "\\1", $this->pointer); } }
/** * @return void * @param XML Parser resourse ID $parser * @param string $data * @desc XML Parser data handler */ function charData($parser, $data) { if ($this->element!="TREEITEM" and trim($data)!="") { $this->map[$this->element_count][$this->element]=iconv("UTF-8", $GLOBALS["default_charset"], $data); // if($this->element=="ID") { // @eval("\$this->structure" . $this->prev_pointer . "[\"CHILDREN\"][".$this->last_var."]=" . intval($data) . ";"); // } } if (addslashes(trim($data))!="") eval("\$this->structure".$this->pointer."[\"".$this->element."\"]=\"".addslashes(iconv("UTF-8", $GLOBALS["default_charset"], trim($data)))."\";"); }
/** * @return array * @desc Build tree from xml */ function build_structure(){ $fp=@fopen($this->xml_file, "r+"); if (!$fp) message_die("Couldn't open <b>" . $this->xml_file . "</b> for reading!"); $size=filesize($this->xml_file); $this->xml=fread($fp, $size); fclose($fp);
$xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, array(&$this, "startElement"), array(&$this, "endElement")); xml_set_character_data_handler($xml_parser, array(&$this, "charData")); if (!xml_parse($xml_parser, $this->xml)) { message_die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } xml_parser_free($xml_parser); return $this->structure; }
function array2xml($tree, $depth=1){ $xml=""; $spacer=""; for ($i=0; $i<$depth; $i++) $spacer.="\t"; foreach ($tree as $key=>$value) { if (gettype($value)=="array" and $key!="CHILDREN") { $depth++; $xml.=$spacer . "<treeitem var=\"".$key."\" id=\"id_".$value["ID"]."\">\n" . $this->array2xml($value, $depth) . $spacer . "</treeitem>\n"; $depth--; } elseif($key!="VAR" and $value!="" and $key!="ID") $xml.=$spacer . "<".strtolower($key).">".$value."</".strtolower($key).">\n"; } return $xml;
}
}
// If function iconv doesn't exist, provide a simple replacement using utf8.class if(!function_exists("iconv")){ require_once(ROOT_PATH . "usr/system/utf/utf8.class.php");
function iconv($in_charset, $out_charset, $string){ global $conv; $in_charset=preg_replace("/WINDOWS(-)?/i", "CP", strtoupper($in_charset)); $out_charset=preg_replace("/WINDOWS(-)?/i", "CP", strtoupper($out_charset));
if($in_charset!="UTF-8"){ if(!$conv[$in_charset]) $conv[$in_charset] = new utf8($in_charset); return $conv[$in_charset]->strToUtf8($string); }else{ if(!$conv[$out_charset]) $conv[$out_charset] = new utf8($out_charset); return $conv[$out_charset]->utf8ToStr($string); } } }
?>
|
--------------------
ГЫ...
|