PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website bán phụ tùng oto PHP/phpMyAdmin1/libraries/transformations.lib.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 209 lines | 121 code | 28 blank | 60 comment | 30 complexity | 0f6a3cd25056be16d7e8c6f23fd7c12e MD5 | raw file
  1. <?php
  2. /* $Id: transformations.lib.php 8340 2006-01-19 15:39:29Z cybot_tm $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Set of functions used with the relation and pdf feature
  6. */
  7. function PMA_transformation_getOptions($string) {
  8. $transform_options = array();
  9. if ($string != '') {
  10. if ($string{0} == "'" && $string{strlen($string)-1} == "'") {
  11. $transform_options = explode('\',\'', substr($string, 1, strlen($string)-2));
  12. } else {
  13. $transform_options = array(0 => $string);
  14. }
  15. }
  16. // strip possible slashes to behave like documentation says
  17. $result = array();
  18. foreach ($transform_options as $val) {
  19. $result[] = stripslashes($val);
  20. }
  21. return $result;
  22. }
  23. /**
  24. * Gets all available MIME-types
  25. *
  26. * @return array array[mimetype], array[transformation]
  27. *
  28. * @access public
  29. *
  30. * @author Garvin Hicking <me@supergarv.de>
  31. */
  32. function PMA_getAvailableMIMEtypes() {
  33. $handle = opendir('./libraries/transformations');
  34. $stack = array();
  35. $filestack = array();
  36. while (($file = readdir($handle)) != false) {
  37. $filestack[$file] = $file;
  38. }
  39. closedir($handle);
  40. if (is_array($filestack)) {
  41. @ksort($filestack);
  42. foreach ($filestack AS $key => $file) {
  43. if (preg_match('|^.*__.*\.inc\.php$|', trim($file))) {
  44. // File contains transformation functions.
  45. $base = explode('__', str_replace('.inc.php', '', $file));
  46. $mimetype = str_replace('_', '/', $base[0]);
  47. $stack['mimetype'][$mimetype] = $mimetype;
  48. $stack['transformation'][] = $mimetype . ': ' . $base[1];
  49. $stack['transformation_file'][] = $file;
  50. } elseif (preg_match('|^.*\.inc\.php$|', trim($file))) {
  51. // File is a plain mimetype, no functions.
  52. $base = str_replace('.inc.php', '', $file);
  53. if ($base != 'global') {
  54. $mimetype = str_replace('_', '/', $base);
  55. $stack['mimetype'][$mimetype] = $mimetype;
  56. $stack['empty_mimetype'][$mimetype] = $mimetype;
  57. }
  58. }
  59. }
  60. }
  61. return $stack;
  62. }
  63. /**
  64. * Gets the mimetypes for all rows of a table
  65. *
  66. * @param string the name of the db to check for
  67. * @param string the name of the table to check for
  68. * @param string whether to include only results having a mimetype set
  69. *
  70. * @return array [field_name][field_key] = field_value
  71. *
  72. * @global array the list of relations settings
  73. *
  74. * @access public
  75. *
  76. * @author Mike Beck <mikebeck@users.sourceforge.net> / Garvin Hicking <me@supergarv.de>
  77. */
  78. function PMA_getMIME($db, $table, $strict = false) {
  79. global $cfgRelation;
  80. $com_qry = 'SELECT column_name, mimetype, transformation, transformation_options FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
  81. . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
  82. . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
  83. . ' AND (mimetype != \'\'' . (!$strict ? ' OR transformation != \'\' OR transformation_options != \'\'' : '') . ')';
  84. $com_rs = PMA_query_as_cu($com_qry);
  85. while ($row = @PMA_DBI_fetch_assoc($com_rs)) {
  86. $col = $row['column_name'];
  87. $mime[$col]['mimetype'] = $row['mimetype'];
  88. $mime[$col]['transformation'] = $row['transformation'];
  89. $mime[$col]['transformation_options'] = $row['transformation_options'];
  90. } // end while
  91. PMA_DBI_free_result($com_rs);
  92. unset($com_rs);
  93. if (isset($mime) && is_array($mime)) {
  94. return $mime;
  95. } else {
  96. return FALSE;
  97. }
  98. } // end of the 'PMA_getMIME()' function
  99. /**
  100. * Set a single mimetype to a certain value.
  101. *
  102. * @param string the name of the db
  103. * @param string the name of the table
  104. * @param string the name of the column
  105. * @param string the mimetype of the column
  106. * @param string the transformation of the column
  107. * @param string the transformation options of the column
  108. * @param string (optional) force delete, will erase any existing comments for this column
  109. *
  110. * @return boolean true, if comment-query was made.
  111. *
  112. * @global array the list of relations settings
  113. *
  114. * @access public
  115. */
  116. function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformation_options, $forcedelete = false) {
  117. global $cfgRelation;
  118. $test_qry = 'SELECT mimetype, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
  119. . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
  120. . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
  121. . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
  122. $test_rs = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE);
  123. if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
  124. $row = @PMA_DBI_fetch_assoc($test_rs);
  125. PMA_DBI_free_result($test_rs);
  126. unset($test_rs);
  127. if (!$forcedelete && (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0 || strlen($row['comment']) > 0)) {
  128. $upd_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
  129. . ' SET mimetype = \'' . PMA_sqlAddslashes($mimetype) . '\','
  130. . ' transformation = \'' . PMA_sqlAddslashes($transformation) . '\','
  131. . ' transformation_options = \'' . PMA_sqlAddslashes($transformation_options) . '\''
  132. . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
  133. . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
  134. . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
  135. } else {
  136. $upd_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
  137. . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
  138. . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''
  139. . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\'';
  140. }
  141. } elseif (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) {
  142. $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
  143. . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
  144. . ' VALUES('
  145. . '\'' . PMA_sqlAddslashes($db) . '\','
  146. . '\'' . PMA_sqlAddslashes($table) . '\','
  147. . '\'' . PMA_sqlAddslashes($key) . '\','
  148. . '\'' . PMA_sqlAddslashes($mimetype) . '\','
  149. . '\'' . PMA_sqlAddslashes($transformation) . '\','
  150. . '\'' . PMA_sqlAddslashes($transformation_options) . '\')';
  151. }
  152. if (isset($upd_query)){
  153. $upd_rs = PMA_query_as_cu($upd_query);
  154. PMA_DBI_free_result($upd_rs);
  155. unset($upd_rs);
  156. return true;
  157. } else {
  158. return false;
  159. }
  160. } // end of 'PMA_setMIME()' function
  161. /**
  162. * Returns the real filename of a configured transformation
  163. *
  164. * @param string the current filename
  165. *
  166. * @return string the new filename
  167. *
  168. * @access public
  169. */
  170. function PMA_sanitizeTransformationFile(&$filename) {
  171. // garvin: for security, never allow to break out from transformations directory
  172. $include_file = PMA_securePath($filename);
  173. // This value can also contain a 'php3' value, in which case we map this filename to our new 'php' variant
  174. $testfile = preg_replace('@\.inc\.php3$@', '.inc.php', $include_file);
  175. if ($include_file{strlen($include_file)-1} == '3' && file_exists('./libraries/transformations/' . $testfile)) {
  176. $include_file = $testfile;
  177. $filename = $testfile; // Corrects the referenced variable for further actions on the filename;
  178. }
  179. return $include_file;
  180. } // end of 'PMA_sanitizeTransformationFile()' function
  181. ?>