Systeme de nouvelle poo

Description

Un systeme de nouvelle complet géré par une class PHP5.

+ facile d'intégration
+ sécurisé
+ prise en charge des exceptions PHP5
+ un seul fichier
+ un zip contenant un exemple COMPLET de son utilisation

Source / Exemple :


<?php
/**

  • @desc News Object.
*
  • @name News
  • @since 1.0
*
  • @author Berlemont Quentin
  • @copyright 2006 Berlemont Quentin
  • /
class News { /**
  • @desc Database Access Link.
*
  • @access private
  • @since 1.0
  • @type link_identifier
  • /
private $link; /**
  • @desc Create new News Object instance.
*
  • @param string host
  • @param string user
  • @param string password
  • @param string database
*
  • @access public
  • @since 1.0
  • /
public function __construct($host, $user, $password, $database) { $this -> link = mysql_connect($host, $user, $password); mysql_select_db($database, $this -> link); } /**
  • @desc Send News.
*
  • @param int cat_id
  • @param string title
  • @param string author
  • @param string text
*
  • @access public
  • @since 1.0
  • /
public function SendNews($cat_id, $title, $author, $text) { if (isset($cat_id) AND !empty($cat_id) AND !is_numeric($cat_id)) throw new Exception('ID doit être numérique'); $title = trim(mysql_real_escape_string($title)); $author = trim(mysql_real_escape_string($author)); $text = trim(mysql_real_escape_string($text)); $query = "INSERT INTO `news` ( `cat_id` , `title` , `author` , `text` , `date` ) VALUES ( '" . $cat_id . "', '" . $title . "', '" . $author . "', '" . $text . "', '" . time() . "' )"; if (!mysql_query($query, $this -> link)) throw new Exception('Requête invalide : ' . mysql_error()); } /**
  • @desc Send News Cat.
*
  • @param string name
  • @param string description
*
  • @access public
  • @since 1.0
  • /
public function SendNewsCat($name, $description) { $name = trim(mysql_real_escape_string($name)); $description = trim(mysql_real_escape_string($description)); $query = "INSERT INTO `news_cat` ( `name` , `description` ) VALUES ( '" . $name . "', '" . $description . "' )"; if (!mysql_query($query, $this -> link)) throw new Exception('Requête invalide : ' . mysql_error()); } /**
  • @desc Edit News.
*
  • @param int news_id
  • @param int cat_id
  • @param string title
  • @param string author
  • @param string text
*
  • @access public
  • @since 1.0
  • /
public function EditNews($news_id, $cat_id, $title, $author, $text) { if (isset($news_id) AND !empty($news_id) AND !is_numeric($news_id)) throw new Exception('ID doit être numérique'); if (isset($cat_id) AND !empty($cat_id) AND !is_numeric($cat_id)) throw new Exception('ID doit être numérique'); $title = trim(mysql_real_escape_string($title)); $author = trim(mysql_real_escape_string($author)); $text = trim(mysql_real_escape_string($text)); $query = "UPDATE `news` SET `cat_id` = '" . $cat_id . "', `title` = '" . $title . "', `author` = '" . $author . "', `text` = '" . $text . "' WHERE `news_id` = '" . $news_id . "'"; if (!mysql_query($query, $this -> link)) throw new Exception('Requête invalide : ' . mysql_error()); } /**
  • @desc Edit News Cat.
*
  • @param int cat_id
  • @param string name
  • @param string description
*
  • @access public
  • @since 1.0
  • /
public function EditNewsCat($cat_id, $name, $description) { if (isset($cat_id) AND !empty($cat_id) AND !is_numeric($cat_id)) throw new Exception('ID doit être numérique'); $name = trim(mysql_real_escape_string($name)); $description = trim(mysql_real_escape_string($description)); $query = "UPDATE `news_cat` SET `name` = '" . $name . "', `description` = '" . $description . "' WHERE `cat_id` = '" . $cat_id . "'"; if (!mysql_query($query, $this -> link)) throw new Exception('Requête invalide : ' . mysql_error()); } /**
  • @desc Delete News.
*
  • @param int news_id
*
  • @access public
  • @since 1.0
  • /
public function DeleteNews($news_id) { if (isset($news_id) AND !empty($news_id) AND !is_numeric($news_id)) throw new Exception('ID doit être numérique'); $query = "DELETE FROM `news` WHERE `news_id` = '" . $news_id . "'"; if (!mysql_query($query, $this -> link)) throw new Exception('Requête invalide : ' . mysql_error()); } /**
  • @desc Delete News Cat
*
  • @param int cat_id
*
  • @access public
  • @since 1.0
  • /
public function DeleteNewsCat($cat_id) { if (isset($cat_id) AND !empty($cat_id) AND !is_numeric($cat_id)) throw new Exception('ID doit être numérique'); $query = "DELETE FROM `news_cat` WHERE `cat_id` = '" . $cat_id . "'"; if (!mysql_query($query, $this -> link)) throw new Exception('Requête invalide : ' . mysql_error()); } /**
  • @desc Get News Cat.
*
  • @param int cat_id
*
  • @return array
*
  • @access public
  • @since 1.0
  • /
public function GetNewsCat($cat_id) { $query = "SELECT * FROM `news_cat` WHERE `cat_id` = '" . $cat_id . "'"; $query_id = mysql_query($query, $this -> link); if (!$query_id) throw new Exception('Requête invalide : ' . mysql_error()); $array = array(); $array = mysql_fetch_array($query_id, $this -> link); return $array; } /**
  • @desc Get List of News Cat.
*
  • @return array
*
  • @access public
  • @since 1.0
  • /
public function GetListNewsCat() { $query = "SELECT * FROM `news_cat`"; $query_id = mysql_query($query, $this -> link); if (!$query_id) throw new Exception('Requête invalide : ' . mysql_error()); $array = array(); while($data = mysql_fetch_array($query_id, $this -> link)) { $array[$data['cat_id']] = array('cat_id' => $data['cat_id'], 'name' => $data['name'], 'description' => $data['description']); } return $array; } /**
  • @desc Get News.
*
  • @param int news_id
*
  • @return array
*
  • @access public
  • @since 1.0
  • /
public function GetNews($news_id) { if (isset($news_id) AND !empty($news_id) AND !is_numeric($news_id)) throw new Exception('ID doit être numérique'); $query = "SELECT news.*, news_cat.* FROM `news` LEFT JOIN `news_cat` ON news.`cat_id` = news_cat.`cat_id` WHERE news.`news_id` = '" . $news_id . "'"; $query_id = mysql_query($query, $this -> link); if (!$query_id) throw new Exception('Requête invalide : ' . mysql_error()); $array = array(); $array = mysql_fetch_array($query_id, $this -> link); return $array; } /**
  • @desc Get List of News.
*
  • @return array
*
  • @access public
  • @since 1.0
  • /
public function GetListNews() { $query = "SELECT news.*, news_cat.* FROM `news` LEFT JOIN `news_cat` ON news.`cat_id` = news_cat.`cat_id`"; $query_id = mysql_query($query, $this -> link); if (!$query_id) throw new Exception('Requête invalide : ' . mysql_error()); $array = array(); while($data = mysql_fetch_array($query_id, $this -> link)) { $array[$data['news_id']] = array('news_id' => $data['news_id'], 'cat_id' => $data['cat_id'], 'name' => $data['name'], 'description' => $data['description'], 'title' => $data['title'], 'author' => $data['author'], 'text' => $data['text'], 'date' => $data['date']); } return $array; } } ?>

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.