2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used with the relation and pdf feature
10 * returns array of options from string with options separated by comma, removes quotes
13 * PMA_transformation_getOptions("'option ,, quoted',abd,'2,3',");
15 * // 'option ,, quoted',
22 * @param string $option_string comma separated options
23 * @return array options
25 function PMA_transformation_getOptions($option_string)
29 if (! strlen($option_string)
30 ||
! $transform_options = preg_split('/,/', $option_string)) {
34 while (($option = array_shift($transform_options)) !== null) {
35 $trimmed = trim($option);
36 if (strlen($trimmed) > 1
38 && $trimmed[strlen($trimmed) - 1] == "'") {
40 $option = substr($trimmed, 1, -1);
41 } elseif (isset($trimmed[0]) && $trimmed[0] == "'") {
43 $trimmed = ltrim($option);
44 while (($option = array_shift($transform_options)) !== null) {
46 $trimmed .= ',' . $option;
47 $rtrimmed = rtrim($trimmed);
48 if ($rtrimmed[strlen($rtrimmed) - 1] == "'") {
53 $option = substr($rtrimmed, 1, -1);
55 $result[] = stripslashes($option);
62 * Gets all available MIME-types
65 * @staticvar array mimetypes
66 * @return array array[mimetype], array[transformation]
68 function PMA_getAvailableMIMEtypes()
72 if (null !== $stack) {
79 $handle = opendir('./libraries/transformations');
85 while ($file = readdir($handle)) {
92 foreach ($filestack as $file) {
93 if (preg_match('|^.*__.*\.inc\.php$|', $file)) {
94 // File contains transformation functions.
95 $base = explode('__', str_replace('.inc.php', '', $file));
96 $mimetype = str_replace('_', '/', $base[0]);
97 $stack['mimetype'][$mimetype] = $mimetype;
99 $stack['transformation'][] = $mimetype . ': ' . $base[1];
100 $stack['transformation_file'][] = $file;
102 } elseif (preg_match('|^.*\.inc\.php$|', $file)) {
103 // File is a plain mimetype, no functions.
104 $base = str_replace('.inc.php', '', $file);
106 if ($base != 'global') {
107 $mimetype = str_replace('_', '/', $base);
108 $stack['mimetype'][$mimetype] = $mimetype;
109 $stack['empty_mimetype'][$mimetype] = $mimetype;
118 * Gets the mimetypes for all columns of a table
121 * @param string $db the name of the db to check for
122 * @param string $table the name of the table to check for
123 * @param string $strict whether to include only results having a mimetype set
124 * @return array [field_name][field_key] = field_value
126 function PMA_getMIME($db, $table, $strict = false)
128 $cfgRelation = PMA_getRelationsParam();
130 if (! $cfgRelation['commwork']) {
135 SELECT `column_name`,
138 `transformation_options`
139 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
140 WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\'
141 AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\'
142 AND ( `mimetype` != \'\'' . (!$strict ?
'
143 OR `transformation` != \'\'
144 OR `transformation_options` != \'\'' : '') . ')';
145 return PMA_DBI_fetch_result($com_qry, 'column_name', null, $GLOBALS['controllink']);
146 } // end of the 'PMA_getMIME()' function
149 * Set a single mimetype to a certain value.
152 * @param string $db the name of the db
153 * @param string $table the name of the table
154 * @param string $key the name of the column
155 * @param string $mimetype the mimetype of the column
156 * @param string $transformation the transformation of the column
157 * @param string $transformation_options the transformation options of the column
158 * @param string $forcedelete force delete, will erase any existing comments for this column
159 * @return boolean true, if comment-query was made.
161 function PMA_setMIME($db, $table, $key, $mimetype, $transformation,
162 $transformation_options, $forcedelete = false)
164 $cfgRelation = PMA_getRelationsParam();
166 if (! $cfgRelation['commwork']) {
173 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
174 WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\'
175 AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\'
176 AND `column_name` = \'' . PMA_sqlAddSlashes($key) . '\'';
177 $test_rs = PMA_query_as_controluser($test_qry, true, PMA_DBI_QUERY_STORE
);
179 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
180 $row = @PMA_DBI_fetch_assoc
($test_rs);
181 PMA_DBI_free_result($test_rs);
184 && (strlen($mimetype) ||
strlen($transformation)
185 ||
strlen($transformation_options) ||
strlen($row['comment']))) {
187 UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
188 SET `mimetype` = \'' . PMA_sqlAddSlashes($mimetype) . '\',
189 `transformation` = \'' . PMA_sqlAddSlashes($transformation) . '\',
190 `transformation_options` = \'' . PMA_sqlAddSlashes($transformation_options) . '\'';
192 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
195 WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\'
196 AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\'
197 AND `column_name` = \'' . PMA_sqlAddSlashes($key) . '\'';
198 } elseif (strlen($mimetype) ||
strlen($transformation)
199 ||
strlen($transformation_options)) {
200 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
201 . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
203 . '\'' . PMA_sqlAddSlashes($db) . '\','
204 . '\'' . PMA_sqlAddSlashes($table) . '\','
205 . '\'' . PMA_sqlAddSlashes($key) . '\','
206 . '\'' . PMA_sqlAddSlashes($mimetype) . '\','
207 . '\'' . PMA_sqlAddSlashes($transformation) . '\','
208 . '\'' . PMA_sqlAddSlashes($transformation_options) . '\')';
211 if (isset($upd_query)) {
212 return PMA_query_as_controluser($upd_query);
216 } // end of 'PMA_setMIME()' function