Advertisement
Guest User

Formulario.php for Drvy

a guest
Apr 5th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.79 KB | None | 0 0
  1. <?php
  2. require_once(dirname(__FILE__) . '/Settings.php');
  3.  
  4. function reem($texto1) {
  5.  
  6. //Rememplazamos caracteres especiales latinos minusculas
  7. $find = array('á', 'é', 'í', 'ó', 'ú', 'ñ', '\"', '€', 'ü', 'Á', 'É', 'Í', 'Ó', 'Ú', 'Ñ', 'Ü', 'ç', 'Ç', '¿', '¡');
  8. $repl = array('&aacute;', '&eacute;', '&iacute;', '&oacute;', '&uacute;', '&ntilde;', '&quot;', '&euro;', '&uuml;', '&Aacute;', '&Eacute;', '&Iacute;', '&Oacute;', '&Uacute;', '&Ntilde;', '&Uuml;', '&ccedil;', '&Ccedil;', '&#191;', '&#161;');
  9. $texto1 = str_replace($find, $repl, $texto1);
  10.  
  11. return $texto1;
  12.  
  13. }
  14.  
  15. function tecla2($cadena) {
  16.    // Si es una letra o numero de 1 caracter de logitud, se le añadira <div class="tecla">
  17.    // Pero si coincide con las palabras flechas,enter etc... se le añadira <img src="" />
  18.    $buscarRegex = array('/^([A-ZñÑ0-9]{1})$/i','/^(flechas|enter|control|alt|espacio|der|izq|mover|shift)$/i');
  19.    $reemplazo = array('<div class="tecla">$1</div>','<img src="ico/$1.png" alt="tecla-$1" />');
  20.    $mag = preg_replace($buscarRegex, $reemplazo, $cadena,-1,$contador);
  21.    // Si las sustituciones son menores a 1, significa que no se ha encontrado el patrón.
  22.    if($contador >= 1){return $mag;}else{return 'desconocida';}
  23. }
  24.  
  25. function sanear_string($string)
  26. {
  27.  
  28.     $string = trim($string);
  29.  
  30.     $string = str_replace(
  31.         array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),
  32.         array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'),
  33.         $string
  34.     );
  35.  
  36.     $string = str_replace(
  37.         array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),
  38.         array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'),
  39.         $string
  40.     );
  41.  
  42.     $string = str_replace(
  43.         array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),
  44.         array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'),
  45.         $string
  46.     );
  47.  
  48.     $string = str_replace(
  49.         array('ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),
  50.         array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'),
  51.         $string
  52.     );
  53.  
  54.     $string = str_replace(
  55.         array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),
  56.         array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'),
  57.         $string
  58.     );
  59.  
  60.     $string = str_replace(
  61.         array('ñ', 'Ñ', 'ç', 'Ç'),
  62.         array('n', 'N', 'c', 'C',),
  63.         $string
  64.     );
  65.  
  66.     //Esta parte se encarga de eliminar cualquier caracter extraño
  67.     $string = str_replace(
  68.         array("\\", "¨", "º", "-", "~",
  69.              "#", "@", "|", "!", "\"",
  70.              "·", "$", "%", "&", "/",
  71.              "(", ")", "?", "'", "¡",
  72.              "¿", "[", "^", "`", "]",
  73.              "+", "}", "{", "¨", "´",
  74.              ">", "< ", ";", ",", ":",
  75.              ".", " "),
  76.         '',
  77.         $string
  78.     );
  79.  
  80.  
  81.     return strtolower($string);
  82. }
  83.  
  84. /* Por cada campo de tecla ... */
  85. foreach($_POST['tecla'] as $tecla){
  86.    /* Le pasamos tecla2 y le agregamos a un array. */
  87.    $teclas[] = tecla2($tecla);
  88. }
  89.  
  90. /* Lo mismo con las acciones.. */
  91. foreach($_POST['accion'] as $accion){
  92.    $acciones = reem($accion);
  93. }
  94.  
  95. $miniatura = $_REQUEST['miniatura'] ;
  96. $linkjuego = $_REQUEST['linkjuego'] ;
  97. $nombre = reem($_REQUEST['nombre']) ;
  98. $descripcion = reem($_REQUEST['descripcion']) ;
  99. $cat = reem($_POST['cat']) ;
  100. $cat2 = sanear_string($_POST['cat']);
  101. $tipo = $_POST['tipo_de_juego'];
  102. $teclas = serialize($teclas);
  103. $acciones = serialize($acciones);
  104.  
  105. mysql_connect ($db_server, $db_user, $db_passwd) or die ('Error: ' . mysql_error());
  106. mysql_select_db ($db_name);
  107. $query="INSERT INTO juegos (miniatura, linkjuego, nombre, descripcion, categoria, cat2, tipo, teclas, acciones) VALUES ('$miniatura', '$linkjuego', '$nombre', '$descripcion', '$cat', '$cat2', '$tipo', '$teclas','$acciones')";
  108. mysql_query($query) or die ('Error: ' . mysql_error());
  109. header("location:okay.html")
  110. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement