Documentation TYPO3 par Ameos

transformations.lib.php

00001 <?php
00002 /* $Id: transformations.lib.php,v 2.10 2005/08/14 21:34:01 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
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     // strip possible slashes to behave like documentation says
00021     $result = array();
00022     foreach($transform_options as $val) {
00023         $result[] = stripslashes($val);
00024     }
00025     return $result;
00026 }
00027 
00037 function PMA_getAvailableMIMEtypes() {
00038     $handle = opendir('./libraries/transformations');
00039 
00040     $stack = array();
00041     $filestack = array();
00042 
00043     while (($file = readdir($handle)) != false) {
00044         $filestack[$file] = $file;
00045     }
00046 
00047     closedir($handle);
00048 
00049     if (is_array($filestack)) {
00050         @ksort($filestack);
00051         foreach ($filestack AS $key => $file) {
00052 
00053             if (preg_match('|^.*__.*\.inc\.php(3?)$|', trim($file), $match = array())) {
00054                 // File contains transformation functions.
00055                 $base = explode('__', str_replace('.inc.php' . $match[1], '', $file));
00056 
00057                 $mimetype = str_replace('_', '/', $base[0]);
00058                 $stack['mimetype'][$mimetype] = $mimetype;
00059 
00060                 $stack['transformation'][] = $mimetype . ': ' . $base[1];
00061                 $stack['transformation_file'][] = $file;
00062 
00063             } else if (preg_match('|^.*\.inc\.php(3?)$|', trim($file), $match)) {
00064                 // File is a plain mimetype, no functions.
00065                 $base = str_replace('.inc.php' . $match[1], '', $file);
00066 
00067                 if ($base != 'global') {
00068                     $mimetype = str_replace('_', '/', $base);
00069                     $stack['mimetype'][$mimetype] = $mimetype;
00070                     $stack['empty_mimetype'][$mimetype] = $mimetype;
00071                 }
00072             }
00073 
00074         }
00075     }
00076 
00077     return $stack;
00078 }
00079 
00095 function PMA_getMIME($db, $table, $strict = false) {
00096     global $cfgRelation;
00097 
00098     $com_qry  = 'SELECT column_name, mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_info'])
00099               . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
00100               . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00101               . ' AND (mimetype != \'\'' . (!$strict ? ' OR transformation != \'\' OR transformation_options != \'\'' : '') . ')';
00102     $com_rs   = PMA_query_as_cu($com_qry);
00103 
00104     while ($row = @PMA_DBI_fetch_assoc($com_rs)) {
00105         $col                                    = $row['column_name'];
00106         $mime[$col]['mimetype']                 = $row['mimetype'];
00107         $mime[$col]['transformation']           = $row['transformation'];
00108         $mime[$col]['transformation_options']   = $row['transformation_options'];
00109     } // end while
00110     PMA_DBI_free_result($com_rs);
00111     unset($com_rs);
00112 
00113     if (isset($mime) && is_array($mime)) {
00114         return $mime;
00115      } else {
00116         return FALSE;
00117      }
00118  } // end of the 'PMA_getMIME()' function
00119 
00137 function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false) {
00138     global $cfgRelation;
00139 
00140     $test_qry  = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info'])
00141                 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
00142                 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00143                 . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
00144     $test_rs   = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE);
00145 
00146     if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
00147         $row = @PMA_DBI_fetch_assoc($test_rs);
00148         PMA_DBI_free_result($test_rs);
00149         unset($test_rs);
00150 
00151         if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) {
00152             $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info'])
00153                    . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\','
00154                    . '     transformation = \'' . PMA_sqlAddslashes($transformation) . '\','
00155                    . '     transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\''
00156                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
00157                    . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00158                    . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
00159         } else {
00160             $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])
00161                    . ' WHERE db_name  = \'' . PMA_sqlAddslashes($db) . '\''
00162                    . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
00163                    . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
00164         }
00165     } else if (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
00166         $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info'])
00167                    . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
00168                    . ' VALUES('
00169                    . '\'' . PMA_sqlAddslashes($db) . '\','
00170                    . '\'' . PMA_sqlAddslashes($table) . '\','
00171                    . '\'' . PMA_sqlAddslashes($key) . '\','
00172                    . '\'' . PMA_sqlAddslashes($mimetype) . '\','
00173                    . '\'' . PMA_sqlAddslashes($transformation) . '\','
00174                    . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
00175     }
00176 
00177     if (isset($upd_query)){
00178         $upd_rs    = PMA_query_as_cu($upd_query);
00179         PMA_DBI_free_result($upd_rs);
00180         unset($upd_rs);
00181         return true;
00182     } else {
00183         return false;
00184     }
00185 } // end of 'PMA_setMIME()' function
00186 
00196 function PMA_sanitizeTransformationFile(&$filename) {
00197     // garvin: for security, never allow to break out from transformations directory
00198 
00199     $include_file = PMA_securePath($filename);
00200 
00201     // This value can also contain a 'php3' value, in which case we map this filename to our new 'php' variant
00202     $testfile = preg_replace('@\.inc\.php3$@', '.inc.php', $include_file);
00203     if ($include_file{strlen($include_file)-1} == '3' && file_exists('./libraries/transformations/' . $testfile)) {
00204         $include_file = $testfile;
00205         $filename     = $testfile; // Corrects the referenced variable for further actions on the filename;
00206     }
00207 
00208     return $include_file;
00209 } // end of 'PMA_sanitizeTransformationFile()' function
00210 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6