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
73 * @author Garvin Hicking <me@supergarv.de>
81 * @staticvar array mimetypes
82 * @return array array[mimetype], array[transformation]
84 function PMA_getAvailableMIMEtypes()
88 if (null !== $stack) {
95 $handle = opendir('./libraries/transformations');
101 while ($file = readdir($handle)) {
102 $filestack[] = $file;
108 foreach ($filestack as $file) {
109 if (preg_match('|^.*__.*\.inc\.php$|', $file)) {
110 // File contains transformation functions.
111 $base = explode('__', str_replace('.inc.php', '', $file));
112 $mimetype = str_replace('_', '/', $base[0]);
113 $stack['mimetype'][$mimetype] = $mimetype;
115 $stack['transformation'][] = $mimetype . ': ' . $base[1];
116 $stack['transformation_file'][] = $file;
118 } elseif (preg_match('|^.*\.inc\.php$|', $file)) {
119 // File is a plain mimetype, no functions.
120 $base = str_replace('.inc.php', '', $file);
122 if ($base != 'global') {
123 $mimetype = str_replace('_', '/', $base);
124 $stack['mimetype'][$mimetype] = $mimetype;
125 $stack['empty_mimetype'][$mimetype] = $mimetype;
134 * Gets the mimetypes for all columns of a table
136 * @uses $GLOBALS['controllink']
137 * @uses PMA_getRelationsParam()
138 * @uses PMA_backquote()
139 * @uses PMA_sqlAddslashes()
140 * @uses PMA_DBI_fetch_result()
141 * @author Mike Beck <mikebeck@users.sourceforge.net>
142 * @author Garvin Hicking <me@supergarv.de>
144 * @param string $db the name of the db to check for
145 * @param string $table the name of the table to check for
146 * @param string $strict whether to include only results having a mimetype set
147 * @return array [field_name][field_key] = field_value
149 function PMA_getMIME($db, $table, $strict = false)
151 $cfgRelation = PMA_getRelationsParam();
153 if (! $cfgRelation['commwork']) {
158 SELECT `column_name`,
161 `transformation_options`
162 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
163 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
164 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
165 AND ( `mimetype` != \'\'' . (!$strict ?
'
166 OR `transformation` != \'\'
167 OR `transformation_options` != \'\'' : '') . ')';
168 return PMA_DBI_fetch_result($com_qry, 'column_name', null, $GLOBALS['controllink']);
169 } // end of the 'PMA_getMIME()' function
172 * Set a single mimetype to a certain value.
174 * @uses PMA_DBI_QUERY_STORE
175 * @uses PMA_getRelationsParam()
176 * @uses PMA_backquote()
177 * @uses PMA_sqlAddslashes()
178 * @uses PMA_query_as_cu()
179 * @uses PMA_DBI_num_rows()
180 * @uses PMA_DBI_fetch_assoc()
181 * @uses PMA_DBI_free_result()
184 * @param string $db the name of the db
185 * @param string $table the name of the table
186 * @param string $key the name of the column
187 * @param string $mimetype the mimetype of the column
188 * @param string $transformation the transformation of the column
189 * @param string $transformation_options the transformation options of the column
190 * @param string $forcedelete force delete, will erase any existing comments for this column
191 * @return boolean true, if comment-query was made.
193 function PMA_setMIME($db, $table, $key, $mimetype, $transformation,
194 $transformation_options, $forcedelete = false)
196 $cfgRelation = PMA_getRelationsParam();
198 if (! $cfgRelation['commwork']) {
205 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
206 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
207 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
208 AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
209 $test_rs = PMA_query_as_cu($test_qry, true, PMA_DBI_QUERY_STORE
);
211 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
212 $row = @PMA_DBI_fetch_assoc
($test_rs);
213 PMA_DBI_free_result($test_rs);
216 && (strlen($mimetype) ||
strlen($transformation)
217 ||
strlen($transformation_options) ||
strlen($row['comment']))) {
219 UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
220 SET `mimetype` = \'' . PMA_sqlAddslashes($mimetype) . '\',
221 `transformation` = \'' . PMA_sqlAddslashes($transformation) . '\',
222 `transformation_options` = \'' . PMA_sqlAddslashes($transformation_options) . '\'';
224 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
227 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
228 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
229 AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
230 } elseif (strlen($mimetype) ||
strlen($transformation)
231 ||
strlen($transformation_options)) {
232 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
233 . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
235 . '\'' . PMA_sqlAddslashes($db) . '\','
236 . '\'' . PMA_sqlAddslashes($table) . '\','
237 . '\'' . PMA_sqlAddslashes($key) . '\','
238 . '\'' . PMA_sqlAddslashes($mimetype) . '\','
239 . '\'' . PMA_sqlAddslashes($transformation) . '\','
240 . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
243 if (isset($upd_query)){
244 return PMA_query_as_cu($upd_query);
248 } // end of 'PMA_setMIME()' function