1 | <?php
|
---|
2 | /* $Id: xml.php 9082 2006-05-30 06:43:00Z nijel $ */
|
---|
3 | // vim: expandtab sw=4 ts=4 sts=4:
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Set of functions used to build XML dumps of tables
|
---|
7 | */
|
---|
8 |
|
---|
9 | if (isset($GLOBALS['db']) && strlen($GLOBALS['db'])) { /* Can't do server export */
|
---|
10 |
|
---|
11 | if (isset($plugin_list)) {
|
---|
12 | $plugin_list['xml'] = array(
|
---|
13 | 'text' => 'strXML',
|
---|
14 | 'extension' => 'xml',
|
---|
15 | 'mime_type' => 'text/xml',
|
---|
16 | 'options' => array(
|
---|
17 | array('type' => 'hidden', 'name' => 'data'),
|
---|
18 | ),
|
---|
19 | 'options_text' => 'strXMLOptions',
|
---|
20 | );
|
---|
21 | } else {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Outputs comment
|
---|
25 | *
|
---|
26 | * @param string Text of comment
|
---|
27 | *
|
---|
28 | * @return bool Whether it suceeded
|
---|
29 | */
|
---|
30 | function PMA_exportComment($text) {
|
---|
31 | return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Outputs export footer
|
---|
36 | *
|
---|
37 | * @return bool Whether it suceeded
|
---|
38 | *
|
---|
39 | * @access public
|
---|
40 | */
|
---|
41 | function PMA_exportFooter() {
|
---|
42 | return TRUE;
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Outputs export header
|
---|
47 | *
|
---|
48 | * @return bool Whether it suceeded
|
---|
49 | *
|
---|
50 | * @access public
|
---|
51 | */
|
---|
52 | function PMA_exportHeader() {
|
---|
53 | global $crlf;
|
---|
54 | global $cfg;
|
---|
55 |
|
---|
56 | if ($GLOBALS['output_charset_conversion']) {
|
---|
57 | $charset = $GLOBALS['charset_of_file'];
|
---|
58 | } else {
|
---|
59 | $charset = $GLOBALS['charset'];
|
---|
60 | }
|
---|
61 |
|
---|
62 | $head = '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
|
---|
63 | . '<!--' . $crlf
|
---|
64 | . '-' . $crlf
|
---|
65 | . '- phpMyAdmin XML Dump' . $crlf
|
---|
66 | . '- version ' . PMA_VERSION . $crlf
|
---|
67 | . '- http://www.phpmyadmin.net' . $crlf
|
---|
68 | . '-' . $crlf
|
---|
69 | . '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
|
---|
70 | if (!empty($cfg['Server']['port'])) {
|
---|
71 | $head .= ':' . $cfg['Server']['port'];
|
---|
72 | }
|
---|
73 | $head .= $crlf
|
---|
74 | . '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
|
---|
75 | . '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
|
---|
76 | . '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
|
---|
77 | . '-->' . $crlf . $crlf;
|
---|
78 | return PMA_exportOutputHandler($head);
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Outputs database header
|
---|
83 | *
|
---|
84 | * @param string Database name
|
---|
85 | *
|
---|
86 | * @return bool Whether it suceeded
|
---|
87 | *
|
---|
88 | * @access public
|
---|
89 | */
|
---|
90 | function PMA_exportDBHeader($db) {
|
---|
91 | global $crlf;
|
---|
92 | $head = '<!--' . $crlf
|
---|
93 | . '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
|
---|
94 | . '-->' . $crlf
|
---|
95 | . '<' . $db . '>' . $crlf;
|
---|
96 | return PMA_exportOutputHandler($head);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Outputs database footer
|
---|
101 | *
|
---|
102 | * @param string Database name
|
---|
103 | *
|
---|
104 | * @return bool Whether it suceeded
|
---|
105 | *
|
---|
106 | * @access public
|
---|
107 | */
|
---|
108 | function PMA_exportDBFooter($db) {
|
---|
109 | global $crlf;
|
---|
110 | return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Outputs create database database
|
---|
115 | *
|
---|
116 | * @param string Database name
|
---|
117 | *
|
---|
118 | * @return bool Whether it suceeded
|
---|
119 | *
|
---|
120 | * @access public
|
---|
121 | */
|
---|
122 | function PMA_exportDBCreate($db) {
|
---|
123 | return TRUE;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Outputs the content of a table
|
---|
129 | *
|
---|
130 | * @param string the database name
|
---|
131 | * @param string the table name
|
---|
132 | * @param string the end of line sequence
|
---|
133 | * @param string the url to go back in case of error
|
---|
134 | * @param string SQL query for obtaining data
|
---|
135 | *
|
---|
136 | * @return bool Whether it suceeded
|
---|
137 | *
|
---|
138 | * @access public
|
---|
139 | */
|
---|
140 | function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
|
---|
141 | $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
---|
142 |
|
---|
143 | $columns_cnt = PMA_DBI_num_fields($result);
|
---|
144 | for ($i = 0; $i < $columns_cnt; $i++) {
|
---|
145 | $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
|
---|
146 | }
|
---|
147 | unset($i);
|
---|
148 |
|
---|
149 | $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
|
---|
150 | if (!PMA_exportOutputHandler($buffer)) {
|
---|
151 | return FALSE;
|
---|
152 | }
|
---|
153 |
|
---|
154 | while ($record = PMA_DBI_fetch_row($result)) {
|
---|
155 | $buffer = ' <' . $table . '>' . $crlf;
|
---|
156 | for ($i = 0; $i < $columns_cnt; $i++) {
|
---|
157 | if ( isset($record[$i]) && !is_null($record[$i])) {
|
---|
158 | $buffer .= ' <' . $columns[$i] . '>' . htmlspecialchars($record[$i])
|
---|
159 | . '</' . $columns[$i] . '>' . $crlf;
|
---|
160 | }
|
---|
161 | }
|
---|
162 | $buffer .= ' </' . $table . '>' . $crlf;
|
---|
163 |
|
---|
164 | if (!PMA_exportOutputHandler($buffer)) {
|
---|
165 | return FALSE;
|
---|
166 | }
|
---|
167 | }
|
---|
168 | PMA_DBI_free_result($result);
|
---|
169 |
|
---|
170 | return TRUE;
|
---|
171 | } // end of the 'PMA_getTableXML()' function
|
---|
172 | }
|
---|
173 | }
|
---|
174 | ?>
|
---|