Advertisement
Doddy

Noticion 1.0

Feb 1st, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.70 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. PHP Class : Noticion 1.0
  6.  
  7. (C) Doddy Hackman 2015
  8.  
  9. */
  10.  
  11.  
  12. class noticion
  13. {
  14.    
  15.     private $db;
  16.    
  17.     public function datos($host, $user, $pass, $db)
  18.     {
  19.        
  20.         $this->db = $db;
  21.        
  22.         if (@mysql_connect($host, $user, $pass)) {
  23.             if (@mysql_select_db($db)) {
  24.                 return true;
  25.             }
  26.         }
  27.     }
  28.    
  29.     public function crear_categoria($nuevacategoria)
  30.     {
  31.        
  32.         $todo1 = "create table categoria_$nuevacategoria (
  33. id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  34. titulo VARCHAR(255) NOT NULL,
  35. contenido TEXT NOT NULL,
  36. fecha VARCHAR(255) NOT NULL,
  37. PRIMARY KEY (id));
  38. ";
  39.        
  40.         $todo2 = "create table comentarios_$nuevacategoria (
  41. id_noticia int(10),
  42. id_comentario int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  43. mensaje TEXT NOT NULL,
  44. apodo VARCHAR(255) NOT NULL,
  45. fecha VARCHAR(255) NOT NULL,
  46. PRIMARY KEY (id_comentario));
  47. ";
  48.        
  49.         if (@mysql_query($todo1)) {
  50.             if (@mysql_query($todo2)) {
  51.                 return true;
  52.             }
  53.         }
  54.        
  55.     }
  56.    
  57.     public function eliminar_categoria($eliminarcategoria)
  58.     {
  59.        
  60.         if (@mysql_query("DROP TABLE categoria_$eliminarcategoria")) {
  61.             if (@mysql_query("DROP TABLE comentarios_$eliminarcategoria")) {
  62.                 return true;
  63.             }
  64.            
  65.         }
  66.     }
  67.    
  68.    
  69.     public function eliminar_noticia($id, $categoria)
  70.     {
  71.         if (is_numeric($id)) {
  72.             if (@mysql_query("DELETE FROM categoria_$categoria where
  73.  
  74. id='$id'")) {
  75.                 return true;
  76.             }
  77.         }
  78.     }
  79.    
  80.     public function nueva_noticia($x_titulo, $x_contenido, $x_fecha, $categoria)
  81.     {
  82.         $sumo = mysql_query("SELECT MAX(id) FROM categoria_$categoria");
  83.        
  84.         $s = mysql_fetch_row($sumo);
  85.        
  86.         foreach ($s as $d) {
  87.             $x_id = $d + 1;
  88.         }
  89.         if (@mysql_query("INSERT INTO categoria_$categoria
  90.  
  91. (id,titulo,contenido,fecha)values
  92.  
  93. ('$x_id','$x_titulo','$x_contenido','$x_fecha')")) {
  94.             return true;
  95.         }
  96.     }
  97.    
  98.     public function ver_este($id, $categoria)
  99.     {
  100.         if (is_numeric($id)) {
  101.             $total = array();
  102.             if ($que = @mysql_query("SELECT id,titulo,contenido,fecha FROM
  103.  
  104. categoria_$categoria WHERE id='$id'")) {
  105.                 while ($ver = @mysql_fetch_array($que)) {
  106.                     return array(
  107.                         $ver[0],
  108.                         $ver[1],
  109.                         $ver[2],
  110.                         $ver[3]
  111.                     );
  112.                 }
  113.             }
  114.         }
  115.     }
  116.    
  117.     public function listar_categorias()
  118.     {
  119.        
  120.         $found = array();
  121.        
  122.         if ($re = @mysql_query("show tables from " . $this->db)) {
  123.            
  124.             while ($dat = mysql_fetch_row($re)) {
  125.                 $separo = split("_", $dat[0]);
  126.                 array_push($found, $separo[1]);
  127.             }
  128.             return array(
  129.                 $found
  130.             );
  131.         }
  132.        
  133.     }
  134.    
  135.     public function ver_todo($categoria)
  136.     {
  137.         $total = array();
  138.         if ($que = @mysql_query("SELECT id,titulo,contenido,fecha FROM
  139.  
  140. categoria_$categoria")) {
  141.             while ($ver = @mysql_fetch_array($que)) {
  142.                 array_push($total, $ver);
  143.             }
  144.             return array(
  145.                 $total
  146.             );
  147.         }
  148.     }
  149.    
  150.     public function modificar_noticia($categoria, $id, $tit, $con, $fech)
  151.     {
  152.         if (@mysql_query("UPDATE categoria_$categoria SET
  153.  
  154. id='$id',titulo='$tit',contenido='$con',fecha='$fech' where id='$id'")) {
  155.             return true;
  156.         }
  157.     }
  158.    
  159.     public function crear_comentario($categoria, $id_noticia, $fecha, $apodo, $mensaje)
  160.     {
  161.        
  162.         $sumo = mysql_query("SELECT MAX(id_comentario) FROM comentarios_
  163.  
  164. $categoria");
  165.        
  166.         $s = mysql_fetch_row($sumo);
  167.        
  168.         foreach ($s as $d) {
  169.             $x_id = $d + 1;
  170.         }
  171.        
  172.         if (mysql_query("INSERT INTO comentarios_$categoria
  173.  
  174. (fecha,apodo,mensaje,id_noticia,id_comentario)values
  175.  
  176. ('$fecha','$apodo','$mensaje','$id_noticia','$x_id')")) {
  177.             return true;
  178.         }
  179.        
  180.     }
  181.    
  182.     public function modificar_comentario($categoria, $id, $fecha, $apodo, $contenido)
  183.     {
  184.         if (@mysql_query("UPDATE comentarios_$categoria SET
  185.  
  186. id_comentario='$id',fecha='$fecha',apodo='$apodo',mensaje='$contenido'
  187.  
  188. where id_comentario='$id'")) {
  189.             return true;
  190.         }
  191.     }
  192.    
  193.     public function ver_comentarios($categoria, $id)
  194.     {
  195.         $todo = array();
  196.         if ($ver = @mysql_query("SELECT
  197.  
  198. id_noticia,id_comentario,apodo,mensaje,fecha FROM comentarios_$categoria")) {
  199.             while ($que = @mysql_fetch_array($ver)) {
  200.                 if ($que[0] == 1) {
  201.                     array_push($todo, $que);
  202.                 }
  203.             }
  204.             return array(
  205.                 $todo
  206.             );
  207.         }
  208.        
  209.     }
  210.    
  211.    
  212.     public function borrar_comentario($categoria, $id)
  213.     {
  214.         if (is_numeric($id)) {
  215.             if (@mysql_query("DELETE FROM comentarios_$categoria where
  216.  
  217. id_comentario='$id'")) {
  218.                 return true;
  219.             }
  220.         }
  221.     }
  222.    
  223.    
  224.     public function cantidad_posts($categoria)
  225.     {
  226.         $valor    = mysql_query("SELECT MAX(id) FROM categoria_
  227.  
  228. $categoria");
  229.         $cantidad = mysql_fetch_row($valor);
  230.         return $cantidad[0];
  231.     }
  232.    
  233.    
  234.     public function cerrar()
  235.     {
  236.         if (mysql_close()) {
  237.             return true;
  238.         }
  239.     }
  240.    
  241. }
  242.  
  243. // The End ?
  244.  
  245. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement