Translation update done using Pootle.
[phpmyadmin-themes.git] / libraries / export / yaml.php
blob550eb1d2254509c4067b3f22665af20af0500a0c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions used to build YAML dumps of tables
6 * @package phpMyAdmin-Export-YAML
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
15 if (isset($plugin_list)) {
16 $plugin_list['yaml'] = array(
17 'text' => 'YAML',
18 'extension' => 'yml',
19 'mime_type' => 'text/yaml',
20 'force_file' => true,
21 'options' => array(
22 array('type' => 'begin_group', 'name' => 'general_opts'),
23 array(
24 'type' => 'hidden',
25 'name' => 'structure_or_data',
27 array('type' => 'end_group')
29 'options_text' => __('Options'),
31 } else {
33 /**
34 * Set of functions used to build exports of tables
37 /**
38 * Outputs comment
40 * @param string Text of comment
42 * @return bool Whether it suceeded
44 function PMA_exportComment($text)
46 PMA_exportOutputHandler('# ' . $text . $GLOBALS['crlf']);
47 return true;
50 /**
51 * Outputs export footer
53 * @return bool Whether it suceeded
55 * @access public
57 function PMA_exportFooter()
59 PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
60 return true;
63 /**
64 * Outputs export header
66 * @return bool Whether it suceeded
68 * @access public
70 function PMA_exportHeader()
72 PMA_exportOutputHandler('%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']);
73 return true;
76 /**
77 * Outputs database header
79 * @param string Database name
81 * @return bool Whether it suceeded
83 * @access public
85 function PMA_exportDBHeader($db)
87 return true;
90 /**
91 * Outputs database footer
93 * @param string Database name
95 * @return bool Whether it suceeded
97 * @access public
99 function PMA_exportDBFooter($db)
101 return true;
105 * Outputs create database database
107 * @param string Database name
109 * @return bool Whether it suceeded
111 * @access public
113 function PMA_exportDBCreate($db)
115 return true;
119 * Outputs the content of a table in YAML format
121 * @param string the database name
122 * @param string the table name
123 * @param string the end of line sequence
124 * @param string the url to go back in case of error
125 * @param string SQL query for obtaining data
127 * @return bool Whether it suceeded
129 * @access public
131 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
133 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
135 $columns_cnt = PMA_DBI_num_fields($result);
136 for ($i = 0; $i < $columns_cnt; $i++) {
137 $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
139 unset($i);
141 $buffer = '';
142 $record_cnt = 0;
143 while ($record = PMA_DBI_fetch_row($result)) {
144 $record_cnt++;
146 // Output table name as comment if this is the first record of the table
147 if ($record_cnt == 1) {
148 $buffer = '# ' . $db . '.' . $table . $crlf;
149 $buffer .= '-' . $crlf;
150 } else {
151 $buffer = '-' . $crlf;
154 for ($i = 0; $i < $columns_cnt; $i++) {
155 if (! isset($record[$i])) {
156 continue;
159 $column = $columns[$i];
161 if (is_null($record[$i])) {
162 $buffer .= ' ' . $column . ': null' . $crlf;
163 continue;
166 if (is_numeric($record[$i])) {
167 $buffer .= ' ' . $column . ': ' . $record[$i] . $crlf;
168 continue;
171 $record[$i] = str_replace(array('\\', '"', "\n", "\r"), array('\\\\', '\"', '\n', '\r'), $record[$i]);
172 $buffer .= ' ' . $column . ': "' . $record[$i] . '"' . $crlf;
175 if (! PMA_exportOutputHandler($buffer)) {
176 return FALSE;
179 PMA_DBI_free_result($result);
181 return true;