1,'trackbacks'=>0,'order'=>'ASC','bypage'=>20,'moderation'=>0,'categories'=>0,'stats'=>0, 'skin'=>'default','nb_posts'=>0,'syntaxe'=>'bbcode','avatars'=>0,'preview'=>1); var $tableStructure = "CREATE TABLE blogs (id INT NOT NULL PRIMARY KEY auto_increment, owner INT NOT NULL, title VARCHAR(255) NOT NULL, unixname VARCHAR(32) NOT NULL, comments INT(1) NOT NULL, trackbacks INT(1) NOT NULL, `order` ENUM('ASC','DESC') NOT NULL, bypage INT(2) NOT NULL, moderation INT(1) NOT NULL, categories INT(1) NOT NULL, stats INT(1) NOT NULL, skin VARCHAR(16) NOT NULL, syntaxe VARCHAR(16) NOT NULL, avatars INT(1) NOT NULL, preview INT(1) NOT NULL, lastpost INT NOT NULL, nb_posts INT(5) NOT NULL, text TEXT NOT NULL);"; function checkDB() { if(!$this->db) xHTML::Error("Impossible d'utiliser la base de données!",'Aucune variable $this->db valide trouvée dans la classe Blogs.',TRUE); } function initializeDB() { $this->checkDB(); $this->db->uquery($this->tableStructure); return TRUE; } function getBlogUrl($unixname) { $url = str_replace("UNIXNAME",$unixname,$this->blogsUrl); return $url; } function setCurrent($owner,$blog) { $req = 'UPDATE users SET currentblog="'.$blog.'" WHERE id="'.$owner.'"'; $this->db->uquery($req); return TRUE; } function getByOwner($owner) { $req = 'SELECT id,unixname,title FROM blogs WHERE owner="'.$owner.'";'; $result = $this->db->aquery($req); return $result; } function getById($id) { $req = 'SELECT * FROM blogs WHERE id="'.$id.'";'; $result = $this->db->aquery($req); $result[0]['url'] = $this->getBlogUrl($result[0]['unixname']); return $result[0]; } function add($owner,$unixname="",$title="",$text="") { if(($errcode = userInput::checkUnixname($unixname)) !== TRUE) return $errcode; if(empty($title)) $title = "Pas de titre"; #return "EMPTY_TITLE"; if(empty($text)) $text = "Pas de description."; #return "EMPTY_TEXT"; $query = 'INSERT INTO blogs (id,owner,unixname,title,text,`'.implode('`,`',array_keys($this->defaultValues)).'`) VALUES ("","'.$owner.'","'.$unixname.'","'.$title.'","'.$text.'","'.implode('","',array_values($this->defaultValues)).'");'; $this->db->uquery($query); $this->_create($unixname,$title); return TRUE; } function _create($unixname,$title) { @mkdir("public/".$unixname); @mkdir("public/$unixname/thumbs"); @mkdir("public/$unixname/images"); @mkdir("public/$unixname/docs"); $fp = @fopen("public/$unixname/index.html","w"); if($fp) { fputs($fp,''.$title.'

Le belog "'.$title.'" vient d\'être créé, il ne contient pas encore de billet.

Powered by Belog.be

'); fclose($fp); } return TRUE; } function generateIndex($id) { } function generateArchive($id,$month) { } function generateCategory($id,$id_cat) { } function getList($owner) { $out = $this->db->aquery('SELECT * FROM messages WHERE owner="'.$owner.'" ORDER BY date DESC'); $this->listNb = count($out); return $out; } } class Billets { var $db = FALSE; var $listNb; var $tableStructure = "CREATE TABLE billets (id INT NOT NULL PRIMARY KEY auto_increment, blog INT NOT NULL, title VARCHAR(255) NOT NULL, date INT NOT NULL, uri VARCHAR(255) NOT NULL, comments INT(1) NOT NULL, trackbacks INT(1) NOT NULL, syntaxe VARCHAR(16) NOT NULL, ip VARCHAR(20) NOT NULL, draft INT(1) NOT NULL, text TEXT NOT NULL, text_html TEXT NOT NULL);"; function checkDB() { if(!$this->db) xHTML::Error("Impossible d'utiliser la base de données!",'Aucune variable $this->db valide trouvée dans la classe Billets.',TRUE); } function initializeDB() { $this->checkDB(); $this->db->uquery($this->tableStructure); return TRUE; } function checkUri($uri) { $uri = eregi_replace("[^a-z0-9éàèùôê_-]","",$uri); $uri = substr($uri,0,250); return $uri; } function getUriFromTitle($title) { $uri = strtolower(strtoupper($title)); $uri = strtr($uri,"àáâãäå","a"); $uri = strtr($uri,"c","c"); $uri = strtr($uri,"òóôõöø","o"); $uri = strtr($uri,"èéêë","e"); $uri = strtr($uri,"ìíîï","i"); $uri = strtr($uri,"ùúûüÿ","u"); $uri = strtr($uri,"ñ","n"); $uri = ereg_replace("[^a-z0-9_- ]",'',$uri); $uri = str_replace(" ","-",$uri); return $uri; } function add($blog,$title="",$text="",$options=array()) { if(empty($title)) return "Le titre est vide, vous devez fournir un titre."; if(empty($text)) return "Le contenu du billet est vide, vous devez fournir un contenu au billet."; if(is_array($options) || count($options) > 0) $date = $options['date']; if(empty($date)) $date = time(); if(empty($options['uri'])) $options['uri'] = $this->getUriFromTitle($title); $options['uri'] = $this->checkUri($options['uri']); $text_html = $this->textToHtml($text,$options['syntaxe']); $query = 'INSERT INTO billets (id,blog,title,date,text,text_html,uri,comments,trackbacks,syntaxe,ip,draft) '. 'VALUES ("","'.$blog.'","'.$title.'","'.$date.'","'.$text.'","'.$text_html.'","'.$options['uri']. '","'.$options['comments'].'","'.$options['trackbacks'].'","'.$options['syntaxe'].'","'.$ip.'","'.$options['draft'].'");'; $this->db->uquery($query); return TRUE; } function getList($owner) { $out = $this->db->aquery('SELECT * FROM messages WHERE owner="'.$owner.'" ORDER BY date DESC'); $this->listNb = count($out); return $out; } } class Commentaires { var $db = FALSE; var $listNb; var $tableStructure = "CREATE TABLE commentaires (id INT NOT NULL PRIMARY KEY auto_increment, blog INT NOT NULL, nick VARCHAR(32) NOT NULL, email VARCHAR(255) NOT NULL, website VARCHAR(255) NOT NULL, date INT NOT NULL, ip VARCHAR(20) NOT NULL, text TEXT NOT NULL, read INT(1) NOT NULL DEFAULT '0');"; function checkDB() { if(!$this->db) xHTML::Error("Impossible d'utiliser la base de données!",'Aucune variable $this->db valide trouvée dans la classe Commentaires.',TRUE); } function initializeDB() { $this->checkDB(); $this->db->uquery($this->tableStructure); return TRUE; } function getUnreadCount($blog) { $req = 'SELECT COUNT(id) FROM commentaires WHERE `read`="0" AND blog="'.$blog.'"'; $result = $this->db->aquery($req); return $result[0][0]; } function getUnreadList($blog) { $req = 'SELECT * FROM commentaires WHERE `read`="0" AND blog="'.$blog.'" ORDER BY date DESC'; $result = $this->db->aquery($req); return $result; } function markRead($id) { $this->db->uquery('UPDATE commentaires SET read="1" WHERE id="'.$id.'"'); return TRUE; } function add($blog,$title="",$date="",$text="") { if(empty($date)) $date = time(); if(empty($text)) xHTML::Error("Field text is empty.","You cannot leave this field empty, it is required.",TRUE); $query = 'INSERT INTO billets (id,blog,title,date,text) VALUES ("","'.$blog.'","'.$title.'","'.$date.'","'.$text.'");'; $this->db->uquery($query); return TRUE; } function getList($owner) { $out = $this->db->aquery('SELECT * FROM messages WHERE owner="'.$owner.'" ORDER BY date DESC'); $this->listNb = count($out); return $out; } } class Categories { var $db = FALSE; var $listNb; var $tableStructure = "CREATE TABLE categories (id INT NOT NULL PRIMARY KEY auto_increment, blog INT NOT NULL, title VARCHAR(255) NOT NULL, uri VARCHAR(255) NOT NULL);"; function checkDB() { if(!$this->db) xHTML::Error("Impossible d'utiliser la base de données!",'Aucune variable $this->db valide trouvée dans la classe Categories.',TRUE); } function initializeDB() { $this->checkDB(); $this->db->uquery($this->tableStructure); return TRUE; } function add($blog,$title="",$date="",$text="") { if(empty($date)) $date = time(); if(empty($text)) xHTML::Error("Field text is empty.","You cannot leave this field empty, it is required.",TRUE); $query = 'INSERT INTO billets (id,blog,title,date,text) VALUES ("","'.$blog.'","'.$title.'","'.$date.'","'.$text.'");'; $this->db->uquery($query); return TRUE; } function getList($blog) { $out = $this->db->aquery('SELECT * FROM categories WHERE blog="'.$blog.'" ORDER BY title DESC'); return $out; } } // xHTML Class // v0.1.0 class xHTML { // head(title,css file,don't show menu) function head($title="",$style="",$no_header=FALSE) { $out = array(); $out[] = ''; $out[] = ''; $out[] = ''; $out[] = ' '.$title.' - belog.be'; $out[] = ' '; $out[] = ' '; if(file_exists("styles/$style.css")) $out[] = ' '; $out[] = ''; $out[] = ''; $out[] = ''; $out[] = ''; if(!$no_header) { $out[] = "
\n

Gérer mon blog

\n \n
\n"; } $out[] = '

'.$title.'

'; $out[] = '
'; $out = implode("\n",$out); return $out; } function foot($no_footer=FALSE) { $out = "
\n"; $out.= "\n"; $out.= "\n"; return $out; } function script($src="",$content="") { if(!empty($src)) $out = '\n"; else $out = "\n"; return $out; } function Protect($field) { $field = stripslashes($field); $field = htmlspecialchars($field); return $field; } function noCache() { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); } function Error($message,$debug="",$die=FALSE) { if($die) { echo xHTML::head("Erreur","admin"); echo '

'.htmlspecialchars(stripslashes($message))."

\n"; if(!empty($debug)) echo '

Informations: '.htmlspecialchars(stripslashes($debug))."

\n"; echo xHTML::foot(); exit; } } function Antispam($email) { $len = strlen($email); for($x = 0; $x < $len; $x++) { $ord = ord(substr($email,$x,1)); $temp.= "&#".$ord.";"; } return $temp; } function dateForm($fieldName="date",$timestamp="",$hours=TRUE) { if(empty($timestamp)) $timestamp = time(); $out = ' '; $currentYear = date("Y",$timestamp); /*';*/ $out.= ' '; if($hours) $out.= ' - : '; return $out; } function getMonthName($i) { $months = array(1=>"Janvier",2=>"Février",3=>"Mars",4=>"Avril",5=>"Mai",6=>"Juin",7=>"Juillet",8=>"Août", 9=>"Septembre",10=>"Octobre",11=>"Novembre",12=>"Décembre"); return $months[$i]; } function getDayName($i) { $days = array(1=>"Lundi",2=>"Mardi",3=>"Mercredi",4=>"Jeudi",5=>"Vendredi",6=>"Samedi",7=>"Dimanche"); return $days[$i]; } function dateShort($i) { $j = explode("-",$i); if($j[1] < 10) $j[1] = substr($j[1],1); $out = $j[2]." ".$this->getMonthName($j[1])." ".$j[0]; return $out; } function date2timestamp($i) { $j = explode("-",$i); return mktime(0,0,0,$j[1],$j[2],$j[0]); } } // Class Users // For managing users // v0.1.0 class Users { var $db = FALSE; var $cookieName = "phpinkSession"; var $tableStructure = "CREATE TABLE users (id INTEGER PRIMARY KEY auto_increment, login VARCHAR(30) NOT NULL, currentblog INT NOT NULL, openid VARCHAR(255) NOT NULL, password VARCHAR(32) NOT NULL, email VARCHAR(255) NOT NULL, access INT NOT NULL, session_id VARCHAR(32), lastcheck INT, lasthost VARCHAR(255));"; var $firstUser = "INSERT INTO users (id,login,password,access) VALUES (0,'admin', 'e2fc714c4727ee9395f324cd2e7f331f','100');"; function checkDB() { if(!$this->db) xHTML::Error("Impossible d'utiliser la base de données!",'Aucune variable $this->db valide trouvée dans la classe Users.',TRUE); } function initializeDB() { $this->checkDB(); $this->db->uquery($this->tableStructure); $this->db->uquery($this->firstUser); return TRUE; } function Login($login,$password,$sessionTime="0") { if(userInput::checkLogin($login) !== TRUE) xHTML::Error("Nom d'utilisateur invalide!",'',TRUE); if(userInput::checkLogin($password) !== TRUE) xHTML::Error("Mot de passe invalide!",'',TRUE); $sessionTime = intval($sessionTime); $this->checkDB(); $result = $this->db->array_query("SELECT id,password FROM users WHERE login='".$login."'"); if(!$result || (count($result) != 1)) xHTML::Error("Impossible de trouver ce nom d'utilisateur!",'',TRUE); $result = $result[0]; if($result['password'] != md5($password)) { xHTML::Error("Mot de passe invalide! Réessayez...",'',TRUE); } $sessionID = md5($login.$password.$sessionTime.time()); $this->db->uquery("UPDATE users SET session_id='".$sessionID."' WHERE id='".$result['id']."';"); $this->updateSession($sessionID); if(empty($sessionTime)) $sessionExpire = "0"; elseif(substr($sessionTime,-1) == "d") $sessionExpire = time() + (substr($sessionTime,0,-1) * 3600 * 24); else $sessionExpire = time() + ($sessionTime * 3600); setcookie($this->cookieName,$sessionID,$sessionExpire,"/"); return TRUE; } function updateSession($sessionID) { $time = time(); $host = gethostbyaddr($_SERVER['REMOTE_ADDR']); $this->db->uquery("UPDATE users SET lastcheck='".$time."', lasthost='".$host."';"); return TRUE; } function checkSession() { $sessionID = $_COOKIE[$this->cookieName]; if(strlen($sessionID) != 32) return FALSE; $result = $this->db->aquery("SELECT * FROM users WHERE session_id='".$sessionID."';"); if(!$result) return FALSE; if($result[0]['session_id'] != $sessionID) return FALSE; return $result[0]; } function Logout($sessionID="") { if(empty($sessionID)) $sessionID = $_COOKIES[$this->cookieName]; $this->updateSession($sessionID); $this->db->uquery("UPDATE users SET session_id='' WHERE session_id='".$sessionID."';"); setcookie($this->cookieName,"",time()+30*24*3600,"/"); return TRUE; } function haveAccess($accessLevel,$userLevel="") { if(empty($userLevel)) $userLevel = $GLOBALS['userData']['access']; if($userLevel >= $accessLevel) return TRUE; return FALSE; } function modify($id,$datas) { extract($datas); if(!empty($password1) && !empty($password2)) { if(($error = userInput::checkPassword($password1,$password2)) !== TRUE) xHTML::Error($error,'',TRUE); $datas['password'] = md5($password1); } if(($error = userInput::checkLogin($login)) !== TRUE) xHTML::Error($error,'',TRUE); unset($datas['password1'],$datas['password2']); $items = array(); foreach($datas as $key=>$value) { $items[] = "$key=\"$value\""; } $query = "UPDATE users SET ".implode(", ",$items)." WHERE id='".$id."'"; $this->db->uquery($query); return TRUE; } function add($datas) { extract($datas); if(($error = userInput::checkPassword($password1,$password2)) !== TRUE) xHTML::Error($error,'',TRUE); $datas['password'] = md5($password1); if(($error = userInput::checkLogin($login)) !== TRUE) xHTML::Error($error,'',TRUE); unset($datas['password1'],$datas['password2']); $items = array(); $values = array(); foreach($datas as $key=>$value) { $items[] = "`$key`"; $values[] = "\"$value\""; } $query = "INSERT INTO users (".implode(",",$items).") VALUES (".implode(",",$values).")"; $this->db->uquery($query); return TRUE; } function getList($condition="") { if(!empty($condition)) $condition = "WHERE ".$condition; $result = $this->db->aquery("SELECT * FROM users ".$condition." ORDER BY name"); $out = array(); foreach($result as $rec) $out[$rec['id']] = $rec; return $out; } function get($id) { $result = $this->db->aquery("SELECT * FROM users WHERE id='".$id."'"); return $result[0]; } function getByLogin($login) { $result = $this->db->aquery("SELECT * FROM users WHERE login='".$login."'"); return $result[0]; } function genPass() { if(func_num_args() == 1) $nb = func_get_arg(0); else $nb = 8; // on utilise certains chiffres : 1 = i, 5 = S, 6=b, 3=E, 9=G, 0=O $lettre = array(); $lettre[0] = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'o', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'D', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '9', '0', '6', '5', '1', '3'); $lettre[1] = array('a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y' , '1', '3', '0' ); $lettre[-1] = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z', 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z', '5', '6', '9'); $retour = ""; $prec = 1; $precprec = -1; srand((double)microtime()*20001107); // pour genere la suite de lettre, on dit : si les deux lettres sonts // des consonnes (resp. des voyelles) on affiche des voyelles (resp, des consonnes). // si les lettres sont de type differents, on affiche une lettre de l'alphabet while(strlen($retour) < $nb) { $type = ($precprec + $prec)/2; $r = $lettre[$type][array_rand($lettre[$type], 1)]; $retour .= $r; $precprec = $prec; $prec = in_array($r, $lettre[-1]) - in_array($r, $lettre[1]); } return $retour; } function delete($id) { $this->db->uquery("DELETE FROM users WHERE id=\"".$id."\""); return TRUE; } } // User Input // v0.1.0 class userInput { function checkPassword($pass1,$pass2) { if($pass1 != $pass2) return "Les deux mots de passe entrés sont différents. Vous devez entrer deux fois le même mot de passe."; if(strlen($pass1) < 4) return "Le mot de passe est trop court. Merci d'entrer un mot de passe de minimum 4 caractères."; if(!ereg("^[a-zA-Z0-9]+$",$pass1)) return "Le mot de passe contient des caractères invalides. Caractères autorisés: A-Z, a-z, 0-9, _ et -."; return TRUE; } function checkLogin($login) { if(strlen($login) < 4) return "Nom d'utilisateur trop court. Merci d'utiliser un nom d'utilisateur de min. 4 caractères."; if(strlen($login) > 30) return "Nom d'utilisateur trop long. Merci d'entrer un nom d'utilisateur de max. 30 caractères."; if(!ereg("^[a-zA-Z0-9]+$",$login)) return "Le nom d'utilisateur utilise des caractères invalides. Caractères autorisés: A-Z, a-z, 0-9."; return TRUE; } function checkUnixname($name) { if(strlen($name) < 4) return "TOO_SHORT"; if(strlen($name) > 32) return "TOO_LONG"; if(!ereg("^[a-z0-9]+$",$name)) return "INVALID"; return TRUE; } } function zerofill($var,$length) { while(strlen($var) < $length) $var = "0".$var; return $var; } ?>