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',
29 * @uses stripslashes()
30 * @param string $option_string comma separated options
31 * @return array options
33 function PMA_transformation_getOptions($option_string)
37 if (! strlen($option_string)
38 ||
! $transform_options = preg_split('/,/', $option_string)) {
42 while (($option = array_shift($transform_options)) !== null) {
43 $trimmed = trim($option);
44 if (strlen($trimmed) > 1
46 && $trimmed[strlen($trimmed) - 1] == "'") {
48 $option = substr($trimmed, 1, -1);
49 } elseif (isset($trimmed[0]) && $trimmed[0] == "'") {
51 $trimmed = ltrim($option);
52 while (($option = array_shift($transform_options)) !== null) {
54 $trimmed .= ',' . $option;
55 $rtrimmed = rtrim($trimmed);
56 if ($rtrimmed[strlen($rtrimmed) - 1] == "'") {
61 $option = substr($rtrimmed, 1, -1);
63 $result[] = stripslashes($option);
70 * Gets all available MIME-types
80 * @staticvar array mimetypes
81 * @return array array[mimetype], array[transformation]
83 function PMA_getAvailableMIMEtypes()
87 if (null !== $stack) {
94 $handle = opendir('./libraries/transformations');
100 while ($file = readdir($handle)) {
101 $filestack[] = $file;
107 foreach ($filestack as $file) {
108 if (preg_match('|^.*__.*\.inc\.php$|', $file)) {
109 // File contains transformation functions.
110 $base = explode('__', str_replace('.inc.php', '', $file));
111 $mimetype = str_replace('_', '/', $base[0]);
112 $stack['mimetype'][$mimetype] = $mimetype;
114 $stack['transformation'][] = $mimetype . ': ' . $base[1];
115 $stack['transformation_file'][] = $file;
117 } elseif (preg_match('|^.*\.inc\.php$|', $file)) {
118 // File is a plain mimetype, no functions.
119 $base = str_replace('.inc.php', '', $file);
121 if ($base != 'global') {
122 $mimetype = str_replace('_', '/', $base);
123 $stack['mimetype'][$mimetype] = $mimetype;
124 $stack['empty_mimetype'][$mimetype] = $mimetype;
133 * Gets the mimetypes for all columns of a table
135 * @uses $GLOBALS['controllink']
136 * @uses PMA_getRelationsParam()
137 * @uses PMA_backquote()
138 * @uses PMA_sqlAddslashes()
139 * @uses PMA_DBI_fetch_result()
141 * @param string $db the name of the db to check for
142 * @param string $table the name of the table to check for
143 * @param string $strict whether to include only results having a mimetype set
144 * @return array [field_name][field_key] = field_value
146 function PMA_getMIME($db, $table, $strict = false)
148 $cfgRelation = PMA_getRelationsParam();
150 if (! $cfgRelation['commwork']) {
155 SELECT `column_name`,
158 `transformation_options`
159 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
160 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
161 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
162 AND ( `mimetype` != \'\'' . (!$strict ?
'
163 OR `transformation` != \'\'
164 OR `transformation_options` != \'\'' : '') . ')';
165 return PMA_DBI_fetch_result($com_qry, 'column_name', null, $GLOBALS['controllink']);
166 } // end of the 'PMA_getMIME()' function
169 * Set a single mimetype to a certain value.
171 * @uses PMA_DBI_QUERY_STORE
172 * @uses PMA_getRelationsParam()
173 * @uses PMA_backquote()
174 * @uses PMA_sqlAddslashes()
175 * @uses PMA_query_as_controluser()
176 * @uses PMA_DBI_num_rows()
177 * @uses PMA_DBI_fetch_assoc()
178 * @uses PMA_DBI_free_result()
181 * @param string $db the name of the db
182 * @param string $table the name of the table
183 * @param string $key the name of the column
184 * @param string $mimetype the mimetype of the column
185 * @param string $transformation the transformation of the column
186 * @param string $transformation_options the transformation options of the column
187 * @param string $forcedelete force delete, will erase any existing comments for this column
188 * @return boolean true, if comment-query was made.
190 function PMA_setMIME($db, $table, $key, $mimetype, $transformation,
191 $transformation_options, $forcedelete = false)
193 $cfgRelation = PMA_getRelationsParam();
195 if (! $cfgRelation['commwork']) {
202 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
203 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
204 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
205 AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
206 $test_rs = PMA_query_as_controluser($test_qry, true, PMA_DBI_QUERY_STORE
);
208 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
209 $row = @PMA_DBI_fetch_assoc
($test_rs);
210 PMA_DBI_free_result($test_rs);
213 && (strlen($mimetype) ||
strlen($transformation)
214 ||
strlen($transformation_options) ||
strlen($row['comment']))) {
216 UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
217 SET `mimetype` = \'' . PMA_sqlAddslashes($mimetype) . '\',
218 `transformation` = \'' . PMA_sqlAddslashes($transformation) . '\',
219 `transformation_options` = \'' . PMA_sqlAddslashes($transformation_options) . '\'';
221 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
224 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
225 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
226 AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
227 } elseif (strlen($mimetype) ||
strlen($transformation)
228 ||
strlen($transformation_options)) {
229 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
230 . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
232 . '\'' . PMA_sqlAddslashes($db) . '\','
233 . '\'' . PMA_sqlAddslashes($table) . '\','
234 . '\'' . PMA_sqlAddslashes($key) . '\','
235 . '\'' . PMA_sqlAddslashes($mimetype) . '\','
236 . '\'' . PMA_sqlAddslashes($transformation) . '\','
237 . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
240 if (isset($upd_query)){
241 return PMA_query_as_controluser($upd_query);
245 } // end of 'PMA_setMIME()' function