[Easymod-cvs] easymod/install/em_files/includes/em em_parser_xml.php,1.1,1.2
Status: Beta
Brought to you by:
wgeric
From: Eric F. <wg...@us...> - 2005-12-22 00:14:55
|
Update of /cvsroot/easymod/easymod/install/em_files/includes/em In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22201 Modified Files: em_parser_xml.php Log Message: XML parser should work. If I missed any actions, tell me Index: em_parser_xml.php =================================================================== RCS file: /cvsroot/easymod/easymod/install/em_files/includes/em/em_parser_xml.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** em_parser_xml.php 4 Dec 2005 03:12:30 -0000 1.1 --- em_parser_xml.php 22 Dec 2005 00:14:43 -0000 1.2 *************** *** 24,33 **** /** * Filename of the MOD begin parsed. */ var $mod_file; var $data = array(); var $parser; - var $XML; /** --- 24,60 ---- /** * Filename of the MOD begin parsed. + * @type string */ var $mod_file; + /** + * Valid MOD actions. + * @type array + */ + var $valid_actions = array(); + + /** + * Header parts from the MOD + * @type array + */ + var $header = array(); + + /** + * Actions for the MOD + * @type array + */ + var $actions = array(); + + /** + * Parsed XML file in an array + * @type array + */ var $data = array(); + + /** + * XML parser resource + * @type resource + */ var $parser; /** *************** *** 41,54 **** $this->mod_file = $mod_file; } ! function _parse() { ! global $io; ! if(empty($io)) ! { ! $io = new_io(); ! } ! ! $XML = $io->open_file($this->mod_file); $this->parser = xml_parser_create(); --- 68,75 ---- $this->mod_file = $mod_file; } ! function _parse() { ! $XML = open_file($this->mod_file); $this->parser = xml_parser_create(); *************** *** 59,64 **** $XML = str_replace('<', '<![CDATA[<]]>', $XML); $XML = str_replace('>', '<![CDATA[>]]>', $XML); ! $this->XML = xml_parse($this->parser, $XML); ! if(!$this->XML) { die(sprintf("XML error: %s at line %d (file: {$this->mod_file})", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser))); --- 80,84 ---- $XML = str_replace('<', '<![CDATA[<]]>', $XML); $XML = str_replace('>', '<![CDATA[>]]>', $XML); ! if(!xml_parse($this->parser, $XML)) { die(sprintf("XML error: %s at line %d (file: {$this->mod_file})", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser))); *************** *** 93,97 **** function _tag_closed($parser, $name) { ! $this->data[count($this->data)-2]['children'][$name] = $this->data[count($this->data)-1]; array_pop($this->data); } --- 113,117 ---- function _tag_closed($parser, $name) { ! $this->data[count($this->data)-2]['children'][$name][] = $this->data[count($this->data)-1]; array_pop($this->data); } *************** *** 107,133 **** } ! $mod_header = array(); ! $header_info = $this->data[0]['children']['HEADER']['children']; // Name and decription ! $mod_header['name'] = $header_info['TITLE']['data']; ! $mod_header['desc'] = $header_info['DESCRIPTION']['data']; // Version ! $version_info = $header_info['MOD-VERSION']['children']; ! $mod_header['version'] = $version_info['MAJOR']['data'] . '.' . $version_info['MINOR']['data'] . '.' . $version_info['REVISION']['data']; ! $mod_header['version'] = (isset($version_info['RELEASE']['data'])) ? $mod_header['version'] . $version_info['RELEASE']['data'] : $mod_header['version']; ! ! return $mod_header; ! } ! ! function parse_sql() ! { ! } function parse_actions() { } --- 127,223 ---- } ! $header_info = $this->data[0]['children']['HEADER'][0]['children']; // Name and decription ! // @TODO check lang attribute to see if it is the correct language ! $this->header['name'] = trim($header_info['TITLE'][0]['data']); ! $this->header['desc'] = trim($header_info['DESCRIPTION'][0]['data']); ! $this->header['author-notes'] = trim($header_info['AUTHOR-NOTES'][0]['data']); // Version ! $version_info = $header_info['MOD-VERSION'][0]['children']; ! $this->header['version'] = trim($version_info['MAJOR'][0]['data']) . '.' . trim($version_info['MINOR'][0]['data']) . '.' . trim($version_info['REVISION']['data']); ! $this->header['version'] = (isset($version_info['RELEASE'][0]['data'])) ? $this->header['version'] . $version_info['RELEASE'][0]['data'] : $this->header['version']; ! ! $author_info = $header_info['AUTHOR-GROUP'][0]['children']['AUTHOR']; ! for($i = 0, $total = sizeof($author_info); $i < $total; $i++) ! { ! $this->header['author'][] = array( ! 'username' => trim($author_info[$i]['children']['USERNAME'][0]['data']), ! 'email' => trim($author_info[$i]['children']['EMAIL'][0]['data']), ! 'realname' => trim($author_info[$i]['children']['REALNAME'][0]['data']), ! 'website' => trim($author_info[$i]['children']['HOMEPAGE'][0]['data'])); ! } ! ! return $this->header; } function parse_actions() { + $actions = $this->data[0]['children']['ACTION-GROUP'][0]['children']; + // sql + $sql_info = $actions['SQL']; + for( $i = 0, $total = sizeof($sql_info); $i < $total; $i++ ) + { + $this->actions['sql'][] = ( !empty($sql_info[$i]['data']) ) ? trim($sql_info[$i]['data']): ''; + } + + // copy + $copy_info = $actions['COPY']; + for( $i = 0, $total = sizeof($copy_info); $i < $total; $i++ ) + { + $copy_files = $copy_info[$i]['children']['FILE']; + for( $j = 0, $file_total = sizeof($copy_files); $j < $file_total; $j++ ) + { + $this->actions['copy'][] = array( + 'from' => str_replace('\\', '/', $copy_files[$j]['children']['FROM'][0]['data']), + 'to' => str_replace('\\', '/', $copy_files[$j]['children']['TO'][0]['data'])); + } + } + + // open + $open_info = $actions['OPEN']; + for( $i = 0, $total = sizeof($open_info); $i < $total; $i++ ) + { + $current_file = str_replace('\\', '/', trim($open_info[$i]['attrs']['SRC'])); + $this->actions['open'][$current_file] = array(); + + $edit_info = $open_info[$i]['children']['EDIT']; + for($j = 0, $edit_total = sizeof($edit_info); $j < $edit_total; $j++) + { + $action_info = $edit_info[$j]['children']; + $this->actions['open'][$current_file]['edit'][$j]['find'] = $action_info['FIND'][0]['data']; + + $actions = $action_info['ACTION']; + for($k = 0, $action_total = sizeof($actions); $k < $action_total; $k++) + { + $this->actions['open'][$current_file]['edit'][$j]['action'][] = array( + 'line' => 0, + 'type' => str_replace(',', '-', str_replace(' ', '', $actions[$k]['attrs']['TYPE'])), + 'code' => $actions[$k]['data'] + ); + } + + $inline_info = $action_info['INLINE-EDIT']; + for($k = 0, $inline_total = sizeof($inline_info); $k < $inline_total; $k++) + { + $inline_actions = $inline_info[$k]['children']; + + $this->actions['open'][$current_file]['edit'][$j]['in-line-edit'][$k]['in-line-find'] = $inline_actions['INLINE-FIND'][0]['data']; + + $actions = $inline_actions['INLINE-ACTION']; + for($x = 0, $actions_total = sizeof($actions); $x < $actions_total; $x++) + { + $type = str_replace(',', '-', str_replace(' ', '', $actions[$x]['attrs']['TYPE'])); + $this->actions['open'][$current_file]['edit'][$j]['in-line-edit'][$k]['in-line-action'][] = array( + 'line' => 0, + 'type' => (( $type != 'increment' ) ? 'in-line-' : '') . $type , + 'code' => $actions[$x]['data'] + ); + } + } + } + } } |