00001 <?php
00002
00003
00004
00009 function PMA_transformation_getOptions($string) {
00010 $transform_options = array();
00011
00012 if ($string != '') {
00013 if ($string{0} == "'" && $string{strlen($string)-1} == "'") {
00014 $transform_options = explode('\',\'', substr($string, 1, strlen($string)-2));
00015 } else {
00016 $transform_options = array(0 => $string);
00017 }
00018 }
00019
00020 return $transform_options;
00021 }
00022
00032 function PMA_getAvailableMIMEtypes() {
00033 $handle = opendir('./libraries/transformations');
00034
00035 $stack = array();
00036 $filestack = array();
00037
00038 while (($file = readdir($handle)) != false) {
00039 $filestack[$file] = $file;
00040 }
00041
00042 closedir($handle);
00043
00044 if (is_array($filestack)) {
00045 @ksort($filestack);
00046 foreach($filestack AS $key => $file) {
00047
00048 if (preg_match('|^.*__.*\.inc\.php(3?)$|', trim($file), $match)) {
00049
00050 $base = explode('__', str_replace('.inc.php' . $match[1], '', $file));
00051
00052 $mimetype = str_replace('_', '/', $base[0]);
00053 $stack['mimetype'][$mimetype] = $mimetype;
00054
00055 $stack['transformation'][] = $mimetype . ': ' . $base[1];
00056 $stack['transformation_file'][] = $file;
00057
00058 } else if (preg_match('|^.*\.inc\.php(3?)$|', trim($file), $match)) {
00059
00060 $base = str_replace('.inc.php' . $match[1], '', $file);
00061
00062 if ($base != 'global') {
00063 $mimetype = str_replace('_', '/', $base);
00064 $stack['mimetype'][$mimetype] = $mimetype;
00065 $stack['empty_mimetype'][$mimetype] = $mimetype;
00066 }
00067 }
00068
00069 }
00070 }
00071
00072 return $stack;
00073 }
00074
00090 function PMA_getMIME($db, $table, $strict = false) {
00091 global $cfgRelation;
00092
00093 $com_qry = 'SELECT column_name, mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_info'])
00094 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
00095 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00096 . ' AND (mimetype != \'\'' . (!$strict ? ' OR transformation != \'\' OR transformation_options != \'\'' : '') . ')';
00097 $com_rs = PMA_query_as_cu($com_qry);
00098
00099 while ($row = @PMA_mysql_fetch_array($com_rs)) {
00100 $col = $row['column_name'];
00101 $mime[$col]['mimetype'] = $row['mimetype'];
00102 $mime[$col]['transformation'] = $row['transformation'];
00103 $mime[$col]['transformation_options'] = $row['transformation_options'];
00104 }
00105
00106 if (isset($mime) && is_array($mime)) {
00107 return $mime;
00108 } else {
00109 return FALSE;
00110 }
00111 }
00112
00130 function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false) {
00131 global $cfgRelation;
00132
00133 $test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info'])
00134 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
00135 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00136 . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
00137 $test_rs = PMA_query_as_cu($test_qry);
00138
00139 if ($test_rs && mysql_num_rows($test_rs) > 0) {
00140 $row = @PMA_mysql_fetch_array($test_rs);
00141
00142 if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) {
00143 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info'])
00144 . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\','
00145 . ' transformation = \'' . PMA_sqlAddslashes($transformation) . '\','
00146 . ' transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\''
00147 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
00148 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00149 . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
00150 } else {
00151 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
00152 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
00153 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00154 . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
00155 }
00156 } else if (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
00157 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info'])
00158 . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
00159 . ' VALUES('
00160 . '\'' . PMA_sqlAddslashes($db) . '\','
00161 . '\'' . PMA_sqlAddslashes($table) . '\','
00162 . '\'' . PMA_sqlAddslashes($key) . '\','
00163 . '\'' . PMA_sqlAddslashes($mimetype) . '\','
00164 . '\'' . PMA_sqlAddslashes($transformation) . '\','
00165 . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
00166 }
00167
00168 if (isset($upd_query)){
00169 $upd_rs = PMA_query_as_cu($upd_query);
00170 unset($upd_query);
00171 return true;
00172 } else {
00173 return false;
00174 }
00175 }
00176
00186 function PMA_sanitizeTransformationFile(&$filename) {
00187
00188
00189 $include_file = preg_replace('@\.\.*@', '.', $filename);
00190
00191
00192 $testfile = preg_replace('@\.inc\.php3$@', '.inc.php', $include_file);
00193 if ($include_file{strlen($include_file)-1} == '3' && file_exists('./libraries/transformations/' . $testfile)) {
00194 $include_file = $testfile;
00195 $filename = $testfile;
00196 }
00197
00198 return $include_file;
00199 }
00200 ?>