2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used with the relation and pdf feature
11 * returns array of options from string with options separated by comma, removes quotes
14 * PMA_transformation_getOptions("'option ,, quoted',abd,'2,3',");
16 * // 'option ,, quoted',
30 * @uses stripslashes()
31 * @param string $option_string comma separated options
32 * @return array options
34 function PMA_transformation_getOptions($option_string)
38 if (! strlen($option_string)
39 ||
! $transform_options = preg_split('/,/', $option_string)) {
43 while (($option = array_shift($transform_options)) !== null) {
44 $trimmed = trim($option);
45 if (strlen($trimmed) > 1
47 && $trimmed[strlen($trimmed) - 1] == "'") {
49 $option = substr($trimmed, 1, -1);
50 } elseif (isset($trimmed[0]) && $trimmed[0] == "'") {
52 $trimmed = ltrim($option);
53 while (($option = array_shift($transform_options)) !== null) {
55 $trimmed .= ',' . $option;
56 $rtrimmed = rtrim($trimmed);
57 if ($rtrimmed[strlen($rtrimmed) - 1] == "'") {
62 $option = substr($rtrimmed, 1, -1);
64 $result[] = stripslashes($option);
71 * Gets all available MIME-types
74 * @author Garvin Hicking <me@supergarv.de>
82 * @staticvar array mimetypes
83 * @return array array[mimetype], array[transformation]
85 function PMA_getAvailableMIMEtypes()
89 if (null !== $stack) {
96 $handle = opendir('./libraries/transformations');
102 while ($file = readdir($handle)) {
103 $filestack[] = $file;
109 foreach ($filestack as $file) {
110 if (preg_match('|^.*__.*\.inc\.php$|', $file)) {
111 // File contains transformation functions.
112 $base = explode('__', str_replace('.inc.php', '', $file));
113 $mimetype = str_replace('_', '/', $base[0]);
114 $stack['mimetype'][$mimetype] = $mimetype;
116 $stack['transformation'][] = $mimetype . ': ' . $base[1];
117 $stack['transformation_file'][] = $file;
119 } elseif (preg_match('|^.*\.inc\.php$|', $file)) {
120 // File is a plain mimetype, no functions.
121 $base = str_replace('.inc.php', '', $file);
123 if ($base != 'global') {
124 $mimetype = str_replace('_', '/', $base);
125 $stack['mimetype'][$mimetype] = $mimetype;
126 $stack['empty_mimetype'][$mimetype] = $mimetype;
135 * Gets the mimetypes for all columns of a table
137 * @uses $GLOBALS['controllink']
138 * @uses PMA_getRelationsParam()
139 * @uses PMA_backquote()
140 * @uses PMA_sqlAddslashes()
141 * @uses PMA_DBI_fetch_result()
142 * @author Mike Beck <mikebeck@users.sourceforge.net>
143 * @author Garvin Hicking <me@supergarv.de>
145 * @param string $db the name of the db to check for
146 * @param string $table the name of the table to check for
147 * @param string $strict whether to include only results having a mimetype set
148 * @return array [field_name][field_key] = field_value
150 function PMA_getMIME($db, $table, $strict = false)
152 $cfgRelation = PMA_getRelationsParam();
154 if (! $cfgRelation['commwork']) {
159 SELECT `column_name`,
162 `transformation_options`
163 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
164 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
165 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
166 AND ( `mimetype` != \'\'' . (!$strict ?
'
167 OR `transformation` != \'\'
168 OR `transformation_options` != \'\'' : '') . ')';
169 return PMA_DBI_fetch_result($com_qry, 'column_name', null, $GLOBALS['controllink']);
170 } // end of the 'PMA_getMIME()' function
173 * Set a single mimetype to a certain value.
175 * @uses PMA_DBI_QUERY_STORE
176 * @uses PMA_getRelationsParam()
177 * @uses PMA_backquote()
178 * @uses PMA_sqlAddslashes()
179 * @uses PMA_query_as_controluser()
180 * @uses PMA_DBI_num_rows()
181 * @uses PMA_DBI_fetch_assoc()
182 * @uses PMA_DBI_free_result()
185 * @param string $db the name of the db
186 * @param string $table the name of the table
187 * @param string $key the name of the column
188 * @param string $mimetype the mimetype of the column
189 * @param string $transformation the transformation of the column
190 * @param string $transformation_options the transformation options of the column
191 * @param string $forcedelete force delete, will erase any existing comments for this column
192 * @return boolean true, if comment-query was made.
194 function PMA_setMIME($db, $table, $key, $mimetype, $transformation,
195 $transformation_options, $forcedelete = false)
197 $cfgRelation = PMA_getRelationsParam();
199 if (! $cfgRelation['commwork']) {
206 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
207 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
208 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
209 AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
210 $test_rs = PMA_query_as_controluser($test_qry, true, PMA_DBI_QUERY_STORE
);
212 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
213 $row = @PMA_DBI_fetch_assoc
($test_rs);
214 PMA_DBI_free_result($test_rs);
217 && (strlen($mimetype) ||
strlen($transformation)
218 ||
strlen($transformation_options) ||
strlen($row['comment']))) {
220 UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
221 SET `mimetype` = \'' . PMA_sqlAddslashes($mimetype) . '\',
222 `transformation` = \'' . PMA_sqlAddslashes($transformation) . '\',
223 `transformation_options` = \'' . PMA_sqlAddslashes($transformation_options) . '\'';
225 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
228 WHERE `db_name` = \'' . PMA_sqlAddslashes($db) . '\'
229 AND `table_name` = \'' . PMA_sqlAddslashes($table) . '\'
230 AND `column_name` = \'' . PMA_sqlAddslashes($key) . '\'';
231 } elseif (strlen($mimetype) ||
strlen($transformation)
232 ||
strlen($transformation_options)) {
233 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
234 . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
236 . '\'' . PMA_sqlAddslashes($db) . '\','
237 . '\'' . PMA_sqlAddslashes($table) . '\','
238 . '\'' . PMA_sqlAddslashes($key) . '\','
239 . '\'' . PMA_sqlAddslashes($mimetype) . '\','
240 . '\'' . PMA_sqlAddslashes($transformation) . '\','
241 . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
244 if (isset($upd_query)){
245 return PMA_query_as_controluser($upd_query);
249 } // end of 'PMA_setMIME()' function