Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- PHP Class : Noticion 1.0
- (C) Doddy Hackman 2015
- */
- class noticion
- {
- private $db;
- public function datos($host, $user, $pass, $db)
- {
- $this->db = $db;
- if (@mysql_connect($host, $user, $pass)) {
- if (@mysql_select_db($db)) {
- return true;
- }
- }
- }
- public function crear_categoria($nuevacategoria)
- {
- $todo1 = "create table categoria_$nuevacategoria (
- id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
- titulo VARCHAR(255) NOT NULL,
- contenido TEXT NOT NULL,
- fecha VARCHAR(255) NOT NULL,
- PRIMARY KEY (id));
- ";
- $todo2 = "create table comentarios_$nuevacategoria (
- id_noticia int(10),
- id_comentario int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
- mensaje TEXT NOT NULL,
- apodo VARCHAR(255) NOT NULL,
- fecha VARCHAR(255) NOT NULL,
- PRIMARY KEY (id_comentario));
- ";
- if (@mysql_query($todo1)) {
- if (@mysql_query($todo2)) {
- return true;
- }
- }
- }
- public function eliminar_categoria($eliminarcategoria)
- {
- if (@mysql_query("DROP TABLE categoria_$eliminarcategoria")) {
- if (@mysql_query("DROP TABLE comentarios_$eliminarcategoria")) {
- return true;
- }
- }
- }
- public function eliminar_noticia($id, $categoria)
- {
- if (is_numeric($id)) {
- if (@mysql_query("DELETE FROM categoria_$categoria where
- id='$id'")) {
- return true;
- }
- }
- }
- public function nueva_noticia($x_titulo, $x_contenido, $x_fecha, $categoria)
- {
- $sumo = mysql_query("SELECT MAX(id) FROM categoria_$categoria");
- $s = mysql_fetch_row($sumo);
- foreach ($s as $d) {
- $x_id = $d + 1;
- }
- if (@mysql_query("INSERT INTO categoria_$categoria
- (id,titulo,contenido,fecha)values
- ('$x_id','$x_titulo','$x_contenido','$x_fecha')")) {
- return true;
- }
- }
- public function ver_este($id, $categoria)
- {
- if (is_numeric($id)) {
- $total = array();
- if ($que = @mysql_query("SELECT id,titulo,contenido,fecha FROM
- categoria_$categoria WHERE id='$id'")) {
- while ($ver = @mysql_fetch_array($que)) {
- return array(
- $ver[0],
- $ver[1],
- $ver[2],
- $ver[3]
- );
- }
- }
- }
- }
- public function listar_categorias()
- {
- $found = array();
- if ($re = @mysql_query("show tables from " . $this->db)) {
- while ($dat = mysql_fetch_row($re)) {
- $separo = split("_", $dat[0]);
- array_push($found, $separo[1]);
- }
- return array(
- $found
- );
- }
- }
- public function ver_todo($categoria)
- {
- $total = array();
- if ($que = @mysql_query("SELECT id,titulo,contenido,fecha FROM
- categoria_$categoria")) {
- while ($ver = @mysql_fetch_array($que)) {
- array_push($total, $ver);
- }
- return array(
- $total
- );
- }
- }
- public function modificar_noticia($categoria, $id, $tit, $con, $fech)
- {
- if (@mysql_query("UPDATE categoria_$categoria SET
- id='$id',titulo='$tit',contenido='$con',fecha='$fech' where id='$id'")) {
- return true;
- }
- }
- public function crear_comentario($categoria, $id_noticia, $fecha, $apodo, $mensaje)
- {
- $sumo = mysql_query("SELECT MAX(id_comentario) FROM comentarios_
- $categoria");
- $s = mysql_fetch_row($sumo);
- foreach ($s as $d) {
- $x_id = $d + 1;
- }
- if (mysql_query("INSERT INTO comentarios_$categoria
- (fecha,apodo,mensaje,id_noticia,id_comentario)values
- ('$fecha','$apodo','$mensaje','$id_noticia','$x_id')")) {
- return true;
- }
- }
- public function modificar_comentario($categoria, $id, $fecha, $apodo, $contenido)
- {
- if (@mysql_query("UPDATE comentarios_$categoria SET
- id_comentario='$id',fecha='$fecha',apodo='$apodo',mensaje='$contenido'
- where id_comentario='$id'")) {
- return true;
- }
- }
- public function ver_comentarios($categoria, $id)
- {
- $todo = array();
- if ($ver = @mysql_query("SELECT
- id_noticia,id_comentario,apodo,mensaje,fecha FROM comentarios_$categoria")) {
- while ($que = @mysql_fetch_array($ver)) {
- if ($que[0] == 1) {
- array_push($todo, $que);
- }
- }
- return array(
- $todo
- );
- }
- }
- public function borrar_comentario($categoria, $id)
- {
- if (is_numeric($id)) {
- if (@mysql_query("DELETE FROM comentarios_$categoria where
- id_comentario='$id'")) {
- return true;
- }
- }
- }
- public function cantidad_posts($categoria)
- {
- $valor = mysql_query("SELECT MAX(id) FROM categoria_
- $categoria");
- $cantidad = mysql_fetch_row($valor);
- return $cantidad[0];
- }
- public function cerrar()
- {
- if (mysql_close()) {
- return true;
- }
- }
- }
- // The End ?
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement