| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662 | 
							- <?php
 
- # ***** BEGIN LICENSE BLOCK *****
 
- # This file is part of DotClear.
 
- # Copyright (c) 2004 Olivier Meunier and contributors. All rights
 
- # reserved.
 
- #
 
- # DotClear is free software; you can redistribute it and/or modify
 
- # it under the terms of the GNU General Public License as published by
 
- # the Free Software Foundation; either version 2 of the License, or
 
- # (at your option) any later version.
 
- # 
 
- # DotClear is distributed in the hope that it will be useful,
 
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
- # GNU General Public License for more details.
 
- # 
 
- # You should have received a copy of the GNU General Public License
 
- # along with DotClear; if not, write to the Free Software
 
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
- #
 
- # ***** END LICENSE BLOCK *****
 
- require_once dirname(__FILE__).'/class.blogpost.php';
 
- require_once dirname(__FILE__).'/class.blogcomment.php';
 
- /**
 
- @class	blog
 
- === Introduction ===
 
- La classe blog prend en charge toute la gestion du blog. Elle nécessite pour
 
- fonctionner qu'un objet de type '''connection''' soit existant et que la librairie
 
- '''files''' soit également disponible.
 
- Avec cette classe, il est possible de réaliser toutes les tâches
 
- d'administration (ajouts, modifications, suppressions d'éléments) ainsi que les
 
- sélections de billets.
 
- @param	connection	con			Objet connection
 
- @param	string		encoding		Jeu de caractères
 
- @param	string		t_post		Nom de la table post
 
- @param	string		t_user		Nom de la table user
 
- @param	string		t_categorie	Nom de la table categorie
 
- @param	string		t_comment		Nom de la table comment
 
- @param	string		t_ping		Nom de la table ping
 
- @param	array		error		Tableau contenant les erreurs
 
- @param	string		user_id		ID de l'utilisateur
 
- @param	integer		pub_mode		Niveau de publication
 
- @param	string		date_format	Format de la date
 
- @param	string		time_format	Format de l'heure
 
- @param	string		rs_blogpost	Nom de la classe gérant les billets
 
- @param	string		rs_blogcomment	Nom de la classe gérant les commentaires
 
- @param	string		lang			Langue
 
- */
 
- class blog
 
- {
 
- 	var $con;
 
- 	var $encoding;
 
- 	var $t_post;
 
- 	var $t_user;
 
- 	var $t_categorie;
 
- 	var $t_comment;
 
- 	var $t_ping;
 
- 	var $error;
 
- 	var $user_id;
 
- 	var $pub_mode;
 
- 	var $date_format;
 
- 	var $time_format;
 
- 	var $rs_blogpost;
 
- 	var $rs_blogcomment;
 
- 	var $lang;
 
- 	
 
- 	/** @doc
 
- 	=== Méthodes générales === */
 
- 	
 
- 	/**
 
- 	@function	blog
 
- 	
 
- 	'''Constructeur'''. Cette méthode initialise l'objet Blog.
 
- 	
 
- 	@param	string	con		Objet de type connection
 
- 	@param	string	prefix	Préfixe des noms des tables ('')
 
- 	@param	integer	pub_mode	Niveau de publication ('1')
 
- 	@param	string	encoding	Jeu de caractère ('ISO-8859-1')
 
- 	*/
 
- 	function blog(&$con,$prefix='',$pub_mode=1,$encoding='ISO-8859-1')
 
- 	{
 
- 		$this->con = $con;
 
- 		
 
- 		$this->encoding = $encoding;
 
- 		
 
- 		$this->t_post = $prefix.'post';
 
- 		$this->t_user = $prefix.'user';
 
- 		$this->t_categorie = $prefix.'categorie';
 
- 		$this->t_comment = $prefix.'comment';
 
- 		$this->t_ping = $prefix.'ping';
 
- 		$this->t_log = $prefix.'log';
 
- 		$this->t_link = $prefix.'link';
 
- 		
 
- 		$this->error = array();
 
- 		
 
- 		$this->setPubMode($pub_mode);
 
- 		$this->setLang(NULL);
 
- 		$this->setDateFormat();
 
- 		
 
- 		$this->user_id = '';
 
- 		
 
- 		$this->rs_blogpost = 'blogpost';
 
- 		$this->rs_blogcomment = 'blogcomment';
 
- 	}
 
- 	
 
- 	/**
 
- 	@function setPubMode
 
- 	
 
- 	Cette méthode définit le niveau de plublication des éléments (billets et
 
- 	commentaires) que l'on va traiter avec l'objet. Il prend les valeurs 0
 
- 	(éléments non publiés uniquement), 1 (éléments publiés uniquement) ou NULL
 
- 	(tous les éléments)
 
- 	
 
- 	Le niveau de publication sera pris en compte dans nombre de méthodes de
 
- 	sélection des billets ou des commentaires.
 
- 	
 
- 	@param	integer	mode		Niveau de publication
 
- 	*/
 
- 	function setPubMode($mode)
 
- 	{
 
- 		$this->pub_mode = $mode;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function setLang
 
- 	
 
- 	Définit un critère de tri pour la langue des billets. Utilisable sur la
 
- 	partie publique si on souhaite n'afficher que les billets d'une certaine
 
- 	langue.
 
- 	
 
- 	@param	string	lang		Langue
 
- 	*/
 
- 	function setLang($lang)
 
- 	{
 
- 		$this->lang = $lang;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function setDateFormat
 
- 	
 
- 	Définit le format de la date des éléments qui seront retournés.
 
- 	
 
- 	@param	string	d		Format de la date ('%A %e %B %Y')
 
- 	@param	string	h		Format de l'heure ('%H:%M')
 
- 	*/
 
- 	function setDateFormat($d='%A %e %B %Y',$h='%H:%M')
 
- 	{
 
- 		$this->date_format = $d;
 
- 		$this->time_format = $h;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function setURL
 
- 	
 
- 	Définit les différents modèles d'URL du blog.
 
- 	
 
- 	@param	string	type		Type d'URL
 
- 	@param	string	url		Modèle d'URL
 
- 	*/
 
- 	function setURL($type,$url)
 
- 	{
 
- 		$this->front_url[$type] = $url;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function resetError
 
- 	
 
- 	Remet les erreurs à zéro.
 
- 	*/
 
- 	function resetError()
 
- 	{
 
- 		$this->error = array();
 
- 	}
 
- 	
 
- 	/**
 
- 	@function setError
 
- 	
 
- 	Ajoute une erreur dans la pile des erreurs.
 
- 	
 
- 	@param	string	msg		Message
 
- 	@param	integer	no		Numéro de l'erreur (0)
 
- 	*/
 
- 	function setError($msg,$no=0)
 
- 	{
 
- 		$this->error[] = array($no,$msg);
 
- 	}
 
- 	
 
- 	/*
 
- 	TODO: revoir les erreurs au format non html
 
- 	*/
 
- 	/**
 
- 	@function error
 
- 	
 
- 	Récupère les erreurs et renvoie une chaîne ou ''false'' si aucune erreur.
 
- 	
 
- 	Le paramètre $html indique si l'on souhaite obtenir les erreurs au format
 
- 	HTML et $with_nb si la méthode doit également renvoyer les numéros
 
- 	(uniquement visibles au format HTML)
 
- 	
 
- 	@param	boolean	html		Au format HTML (false)
 
- 	@param	boolean	with_nb	Avec les numéros (true)
 
- 	@return	string
 
- 	*/
 
- 	function error($html=false,$with_nb=true)
 
- 	{
 
- 		if (count($this->error) > 0) {
 
- 			if (!$html) {
 
- 				return $this->error;
 
- 			} else {
 
- 				$res = '<ul>'."\n";
 
- 				foreach($this->error as $v) {
 
- 					$res .= '<li>'.
 
- 					( ($with_nb) ? '<span class="errno">'.$v[0].'</span> - ' : '').
 
- 					'<span class="errmsg">'.$v[1].'</span></li>'."\n";
 
- 				}
 
- 				return $res."</ul>\n";
 
- 			}
 
- 		} else {
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Utilisateurs
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes de gestion des utilisateurs === */
 
- 	
 
- 	/**
 
- 	@function setUser
 
- 	
 
- 	Force un utilisateur, seulement si user_level est inférieur à 5
 
- 	ou si $force est vrai.
 
- 	
 
- 	@param	string	id		ID de l'utilisateur
 
- 	@param	boolean	force	Forcer l'utilisateur (false)
 
- 	*/
 
- 	function setUser($id,$force=false)
 
- 	{
 
- 		if (($rs = $this->getUser($id)) !== false && !$rs->isEmpty()) {
 
- 			if ($force || $rs->field('user_level') < 5) {
 
- 				$this->user_id = $id;
 
- 				$this->user_email = $rs->field('user_email');
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function checkUser
 
- 	
 
- 	Existence d'un utilisateur. Cette méthode renvoie vrai ou faux selon que
 
- 	l'utilisateur existe ou non. Les mots de passe et niveau sont optionnels.
 
- 	Le paramètre $md5 indique si la chaîne de mot de passe est passé en clair
 
- 	ou comme md5 à	la méthode.
 
- 	
 
- 	@param	string	id		ID de l'utilisateur
 
- 	@param	string	pwd		Mot de passe (NULL)
 
- 	@param	integer	level	Niveau de l'utilisateur (NULL)
 
- 	@param	boolean	md5		Passage du mot de passe en md5 (true)
 
- 	
 
- 	@return	boolean
 
- 	*/
 
- 	function checkUser($id,$pwd=NULL,$level=NULl,$md5=true)
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($pwd !== NULL) {
 
- 			$pwd = ($md5) ? md5($pwd) : $this->con->escapeStr($pwd);
 
- 			$reqPlus .= 'AND user_pwd = \''.$pwd.'\' ';
 
- 		}
 
- 		
 
- 		if ($level !== NULL) {
 
- 			$reqPlus .= 'AND user_level >= '.(integer) $level.' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT user_id FROM '.$this->t_user.' '.
 
- 				'WHERE user_id = \''.$this->con->escapeStr($id).'\' '.
 
- 				$reqPlus;
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return !$rs->isEmpty();
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function	getUser
 
- 	
 
- 	Renvoie les données concernant un ou plusieurs utilisateurs. Si aucun
 
- 	paramètre $id n'est donné, tous les utilisateurs seront renvoyés dans un
 
- 	recordset. La méthode renvoie false si elle échoue.
 
- 	
 
- 	@param	string	id		ID de l'utilisateur ('')
 
- 	@return	recordset
 
- 	*/
 
- 	function getUser($id='')
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($id != '') {
 
- 			$reqPlus .= 'AND U.user_id = \''.$this->con->escapeStr($id).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT U.user_id,user_level,user_nom,user_prenom,'.
 
- 				'user_pseudo,user_email,user_post_format,user_edit_size,'.
 
- 				'user_pref_cat, user_lang, user_delta, user_post_pub, '.
 
- 				'count(P.post_id) AS nb_post '.
 
- 				'FROM '.$this->t_user.' U '.
 
- 				'	LEFT JOIN '.$this->t_post.' P ON U.user_id = P.user_id '.
 
- 				'WHERE 1 '.
 
- 				$reqPlus.
 
- 				'GROUP BY U.user_id '.
 
- 				'ORDER BY U.user_id ASC ';
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function addUser
 
- 	
 
- 	Ajout d'un utilisateur. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	string	id			ID de l'utilisateur
 
- 	@param	integer	level		Niveau de l'utilisateur
 
- 	@param	string	pwd			Mot de passe
 
- 	@param	string	nom			Nom de l'utilisateur
 
- 	@param	string	prenom		Prénom de l'utilisateur
 
- 	@param	string	pseudo		Pseudo de l'utilisateur
 
- 	@param	string	email		Email de l'utilisateur
 
- 	@param	string	post_format	Format d'édition préféré ('html')
 
- 	@param	string	edit_size		Hauteur de la zone d'éditions (10)
 
- 	@param	integer	pref_cat		Catégorie préférée (1)
 
- 	@param	string	lang			Langue de l'utilisateur ('')
 
- 	@param	integer	delta		Décalage horaire (0)
 
- 	@param	boolean	post_pub		Status de publication par défaut (true)
 
- 	@return	boolean
 
- 	*/
 
- 	function addUser($id,$level,$pwd,$nom,$prenom,$pseudo,$email,
 
- 	$post_format='html',$edit_size=10,$pref_cat=1,$lang='',$delta=0,$post_pub=1)
 
- 	{
 
- 		# Vérifications habituelles
 
- 		if (!preg_match('|^[a-zA-Z0-9]+$|',trim($id))) {
 
- 			$this->setError(__('No such user ID or invalid user ID'),1000);
 
- 		}
 
- 		
 
- 		if (trim($level) != 0 && $level != 1 && $level != 5 && $level != 9) {
 
- 			$this->setError(__('Invalid user level'),1000);
 
- 		}
 
- 		
 
- 		if (trim($pwd) == '') {
 
- 			$this->setError(__('User password missing'),1000);
 
- 		}
 
- 		
 
- 		if (trim($nom) == '') {
 
- 			$this->setError(__('User name missing'),1000);
 
- 		}
 
- 		
 
- 		if (trim($email) != '' && !$this->isEmail($email)) {
 
- 			$this->setError(__('Invalid email address'),1000);
 
- 		}
 
- 		
 
- 		if ($post_format != 'html' && $post_format != 'wiki') {
 
- 			$this->setError(__('Invalid publication format'),1000);
 
- 		}
 
- 		
 
- 		if (!$this->checkCat($pref_cat)) {
 
- 			# Si la catégorie demandée n'existe pas on met la première
 
- 			$rs = $this->con->select('SELECT cat_id FROM '.
 
- 								$this->t_categorie.' '.
 
- 								'ORDER BY cat_id ASC LIMIT 0,1');
 
- 			$pref_cat = $rs->field('cat_id');
 
- 		}
 
- 		
 
- 		if ((integer) $edit_size <= 0) {
 
- 			$this->setError(__('Invalid edit size'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		# Insertion
 
- 		$insReq = 'INSERT INTO '.$this->t_user.' '.
 
- 				'(user_id,user_level,user_pwd,user_nom,user_prenom,'.
 
- 				'user_pseudo,user_email,user_post_format,user_edit_size,'.
 
- 				'user_pref_cat,user_lang,user_delta,user_post_pub) '.
 
- 				'VALUES '."\n".' ('.
 
- 				'\''.$this->con->escapeStr($this->secureString($id)).'\','.
 
- 				'\''.$this->con->escapeStr((integer) $level).'\','.
 
- 				'\''.md5(trim($pwd)).'\','.
 
- 				'\''.$this->con->escapeStr($this->secureString($nom)).'\','.
 
- 				'\''.$this->con->escapeStr($this->secureString($prenom)).'\','.
 
- 				'\''.$this->con->escapeStr($this->secureString($pseudo)).'\','.
 
- 				'\''.$this->con->escapeStr($this->secureString($email)).'\','.
 
- 				'\''.$this->con->escapeStr($this->secureString($post_format)).'\','.
 
- 				'\''.$this->con->escapeStr((integer) $edit_size).'\','.
 
- 				'\''.$this->con->escapeStr((integer) $pref_cat).'\','.
 
- 				'\''.$this->con->escapeStr($lang).'\','.
 
- 				'\''.$this->con->escapeStr((integer) $delta).'\','.
 
- 				'\''.$this->con->escapeStr((integer) $post_pub).'\''.
 
- 				') ';
 
- 		
 
- 		if (!$this->con->execute($insReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('user',$id,'Create user');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function updUser
 
- 	
 
- 	Modification d'un utilisateur. Renvoie vrai en cas de succès.
 
- 	
 
- 	Si le mot de passe est vide, il ne sera pas changé.
 
- 	
 
- 	@param	string	id			ID de l'utilisateur
 
- 	@param	string	new_id		Nouvel ID de l'utilisateur
 
- 	@param	integer	level		Niveau de l'utilisateur
 
- 	@param	string	pwd			Mot de passe
 
- 	@param	string	nom			Nom de l'utilisateur
 
- 	@param	string	prenom		Prénom de l'utilisateur
 
- 	@param	string	pseudo		Pseudo de l'utilisateur
 
- 	@param	string	email		Email de l'utilisateur
 
- 	@param	string	post_format	Format d'édition préféré ('html')
 
- 	@param	string	edit_size		Hauteur de la zone d'éditions (10)
 
- 	@param	integer	pref_cat		Catégorie préférée (1)
 
- 	@param	string	lang			Langue de l'utilisateur ('')
 
- 	@param	integer	delta		Décalage horaire (0)
 
- 	@param	boolean	post_pub		Status de publication par défaut (true)
 
- 	@return	boolean
 
- 	*/
 
- 	function updUser($id,$new_id,$level,$pwd,$nom,$prenom,$pseudo,$email,
 
- 	$post_format='html',$edit_size=10,$pref_cat=1,$lang='',$delta=0,$post_pub=1)
 
- 	{
 
- 		# Vérifications habituelles
 
- 		if (!preg_match('|^[a-zA-Z0-9]+$|',trim($id))) {
 
- 			$this->setError(__('No such user ID or invalid user ID'),1000);
 
- 		}
 
- 		
 
- 		if (trim($new_id) == '') {
 
- 			$new_id = $id;
 
- 		}
 
- 		
 
- 		if ($level != 0 && $level != 1 && $level != 5 && $level != 9) {
 
- 			$this->setError(__('Invalid user level'),1000);
 
- 		}
 
- 		
 
- 		if (trim($nom) == '') {
 
- 			$this->setError(__('User name missing'),1000);
 
- 		}
 
- 		
 
- 		if (trim($email) != '' && !$this->isEmail($email)) {
 
- 			$this->setError(__('Invalid email address'),1000);
 
- 		}
 
- 		
 
- 		if (trim($post_format) != 'html' && $post_format != 'wiki') {
 
- 			$this->setError(__('Invalid publication format'),1000);
 
- 		}
 
- 		
 
- 		if (!$this->checkCat($pref_cat)) {
 
- 			$this->setError(__('Category does not exist'),2005);
 
- 		}
 
- 		
 
- 		if ((integer) $edit_size <= 0) {
 
- 			$this->setError(__('Invalid edit size'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$reqPlus = '';
 
- 		if (trim($pwd) != '') {
 
- 			$reqPlus .= 'user_pwd = \''.md5(trim($pwd)).'\',';
 
- 		}
 
- 		
 
- 		# Modification
 
- 		$updReq = 'UPDATE '.$this->t_user.' SET '.
 
- 				$reqPlus.
 
- 				'user_id = \''.$this->con->escapeStr($this->secureString($new_id)).'\','.
 
- 				'user_level = \''.$this->con->escapeStr((integer) $level).'\','.
 
- 				'user_nom = \''.$this->con->escapeStr($this->secureString($nom)).'\','.
 
- 				'user_prenom = \''.$this->con->escapeStr($this->secureString($prenom)).'\','.
 
- 				'user_pseudo = \''.$this->con->escapeStr($this->secureString($pseudo)).'\','.
 
- 				'user_email = \''.$this->con->escapeStr($this->secureString($email)).'\','.
 
- 				'user_post_format = \''.$this->con->escapeStr($this->secureString($post_format)).'\','.
 
- 				'user_edit_size = \''.$this->con->escapeStr((integer) $edit_size).'\','.
 
- 				'user_pref_cat =  \''.$this->con->escapeStr((integer) $pref_cat).'\', '.
 
- 				'user_lang =  \''.$this->con->escapeStr($lang).'\', '.
 
- 				'user_delta =  \''.$this->con->escapeStr((integer) $delta).'\', '.
 
- 				'user_post_pub =  \''.$this->con->escapeStr((integer) $post_pub).'\' '.
 
- 				'WHERE user_id = \''.$this->con->escapeStr($id).'\' ';
 
- 		
 
- 		if (!$this->con->execute($updReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('user',$id,'Update user');
 
- 			
 
- 			if (trim($id) != trim($new_id)) {
 
- 				# Si mise à jour de l'ID on le change dans les posts
 
- 				
 
- 				$ouvReq = 'UPDATE '.$this->t_post.' SET '.
 
- 						'user_id = \''.$this->con->escapeStr($this->secureString($new_id)).'\' '.
 
- 						'WHERE user_id = \''.$this->con->escapeStr($id).'\' ';
 
- 				
 
- 				if (!$this->con->execute($ouvReq)) {
 
- 					$this->setError('MySQL : '.$this->con->error(),2000);
 
- 					return false;
 
- 				}
 
- 			}
 
- 		}
 
- 		return true;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function delUser
 
- 	
 
- 	Suppression d'un utilisateur. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	string	id			ID de l'utilisateur
 
- 	@return	boolean
 
- 	*/
 
- 	function delUser($id)
 
- 	{
 
- 		if (trim($id) == '') {
 
- 			$this->setError(__('No such user ID or invalid user ID'),1000);
 
- 		}
 
- 		
 
- 		$rs = $this->getUser($id);
 
- 		if ($rs->field('nb_post') > 0) {
 
- 			$this->setError(__('This user has entries'));
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$delReq = 'DELETE FROM '.$this->t_user.' '.
 
- 				'WHERE user_id = \''.$this->con->escapeStr($id).'\' ';
 
- 		
 
- 		if (!$this->con->execute($delReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('user',$id,'Delete user');
 
- 		}
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Categories
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes de gestion des catégories === */
 
- 	
 
- 	/**
 
- 	@function checkCat
 
- 	
 
- 	Vérifie l'existence d'une catégorie. Renvoie vrai ou faux.
 
- 	
 
- 	@param	integer	cat_id		ID de la catégorie
 
- 	
 
- 	@return	boolean
 
- 	*/
 
- 	function checkCat($cat_id)
 
- 	{
 
- 		$strReq = 'SELECT count(*) FROM '.$this->t_categorie.' '.
 
- 				'WHERE cat_id = '.(integer) $this->con->escapeStr($cat_id).' ';
 
- 		$rs = $this->con->select($strReq);
 
- 		
 
- 		if ($rs->field(0) == '0') {
 
- 			return false;
 
- 		} else {
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getCat
 
- 	
 
- 	Sélectionne une ou plusieurs catégories. La paramètre $cat_id peut être
 
- 	un entier, le champ ''cat_id'' sera alors pris en compte. S'il s'agit
 
- 	d'une chaine, la comparaison sera faite sur ''cat_libelle_url''.
 
- 	
 
- 	Si le paramètre $cat_id est une chaine vide, toutes les catégories seront
 
- 	renvoyées dans le recordset (fonctionnement par défaut).
 
- 	
 
- 	La méthode renvoie false en cas d'erreur.
 
- 	
 
- 	@param	mixed	cat_id		Identifiant de la catégorie ('')
 
- 	@param	string	order_by		Champ par lequel ordonner les résultats ('cat_ord')
 
- 	@return	recordset
 
- 	*/
 
- 	function getCat($cat_id='',$order_by='cat_ord')
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($cat_id != '') {
 
- 			if (preg_match('/^[0-9]+$/',$cat_id)) {
 
- 				$reqPlus .= 'AND C.cat_id = '.$this->con->escapeStr($cat_id).' ';
 
- 			} else {
 
- 				$reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat_id).'\' ';
 
- 			}
 
- 		}
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 'AND post_pub = '.(integer) $this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->lang !== NULL) {
 
- 			$reqPlus .= 'AND post_lang = \''.$this->con->escapeStr($this->lang).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT C.cat_id, cat_libelle, cat_desc, cat_libelle_url, '.
 
- 				'cat_ord, count(P.post_id) AS nb_post '.
 
- 				'FROM '.$this->t_categorie.' C '.
 
- 					'LEFT JOIN '.$this->t_post.' P ON C.cat_id = P.cat_id '.
 
- 				'WHERE 1 '.
 
- 				$reqPlus.
 
- 				'GROUP BY C.cat_id '.
 
- 				'ORDER BY '.$this->con->escapeStr($order_by);
 
- 		
 
- 		if (($rs =$this->con->select($strReq)) !== false) {
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function addCat
 
- 	
 
- 	Ajout d'un catégorie. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	string	libelle		Libellé de la catégorie
 
- 	@param	string	desc			Description de la catégorie ('')
 
- 	@param	string	libelle_url	Libellé "URLisé" de la catégorie ('')
 
- 	@return	boolean
 
- 	*/
 
- 	function addCat($libelle,$desc='',$libelle_url='')
 
- 	{
 
- 		$libelle = trim($libelle);
 
- 		$libelle_url = trim($libelle_url);
 
- 		
 
- 		if ($libelle == '') {
 
- 			$this->setError(__('Empty category title'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$libelle_url = ($libelle_url == '') ? $libelle : $libelle_url;
 
- 		$libelle_url = $this->str2url($libelle_url);
 
- 		
 
- 		# Ajout des protections sur le libelle_url
 
- 		$libelle_url = ucfirst(preg_replace('/^[0-9]{4,}/','',$libelle_url));
 
- 		
 
- 		if ($libelle_url == '') {
 
- 			$this->setError(__('Empty or invalid URLed title'),1000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		$libelle = $this->secureString($libelle);
 
- 		
 
- 		$strReq = 'SELECT MAX(cat_ord) FROM '.$this->t_categorie;
 
- 		$rs = $this->con->select($strReq);
 
- 		$max_ord = $rs->f(0);
 
- 		
 
- 		$insReq = 'INSERT INTO '.$this->t_categorie.' '.
 
- 				'(cat_libelle,cat_libelle_url,cat_desc,cat_ord) VALUES ('.
 
- 				'\''.$this->con->escapeStr($libelle).'\','.
 
- 				'\''.$this->con->escapeStr($libelle_url).'\', '.
 
- 				'\''.$this->con->escapeStr($desc).'\','.
 
- 				($max_ord+1).
 
- 				') ';
 
- 		
 
- 		if (!$this->con->execute($insReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('categorie',$libelle,'Create category');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function updCat
 
- 	
 
- 	Modification d'un catégorie. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	cat_id		ID de la catégorie à modifier
 
- 	@param	string	libelle		Libellé de la catégorie
 
- 	@param	string	desc			Description de la catégorie ('')
 
- 	@param	string	libelle_url	Libellé "URLisé" de la catégorie ('')
 
- 	@return	boolean
 
- 	*/
 
- 	function updCat($cat_id,$libelle,$desc='',$libelle_url='')
 
- 	{
 
- 		$libelle = trim($libelle);
 
- 		$libelle_url = trim($libelle_url);
 
- 		
 
- 		if ($libelle == '') {
 
- 			$this->setError(__('Empty category title'),1000);
 
- 		}
 
- 		
 
- 		if (!$this->checkCat($cat_id)) {
 
- 			$this->setError(__('Category does not exist'),2005);
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$libelle_url = ($libelle_url == '') ? $libelle : $libelle_url;
 
- 		$libelle_url = $this->str2url($libelle_url);
 
- 		
 
- 		# Ajout des protections sur le libelle_url
 
- 		$libelle_url = ucfirst(preg_replace('/^[0-9]{4,}/','',$libelle_url));
 
- 		
 
- 		if ($libelle_url == '') {
 
- 			$this->setError(__('Empty or invalid URLed title'),1000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		$libelle = $this->con->escapeStr($this->secureString($libelle));
 
- 		
 
- 		$updReq = 'UPDATE '.$this->t_categorie.' SET '.
 
- 				'cat_libelle = \''.$libelle.'\','.
 
- 				'cat_desc = \''.$this->con->escapeStr($desc).'\', '.
 
- 				'cat_libelle_url = \''.$this->con->escapeStr($libelle_url).'\' '.
 
- 				'WHERE cat_id = '.$this->con->escapeStr($cat_id).' ';
 
- 		
 
- 		if (!$this->con->execute($updReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('categorie',$cat_id,'Update category');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function delCat
 
- 	
 
- 	Suppression d'une catégorie donnée. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	cat_id		ID de la catégorie
 
- 	@return	boolean
 
- 	*/
 
- 	function delCat($cat_id)
 
- 	{
 
- 		if ($cat_id == '') {
 
- 			$this->setError(__('No category ID'),1000);
 
- 		}
 
- 		
 
- 		$rs = $this->getCat($cat_id);
 
- 		
 
- 		if($rs->f('nb_post') > 0) {
 
- 			$this->setError(__('This category is not empty'),2010);
 
- 		} 
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$delReq = 'DELETE FROM '.$this->t_categorie.' '.
 
- 				'WHERE cat_id = '.$this->con->escapeStr($cat_id).' ';
 
- 		
 
- 		if (!$this->con->execute($delReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->reordCats();
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('categorie',$cat_id,'Delete category');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function reordCats
 
- 	
 
- 	Réordonner les catégories. Cette méthode va remettre les catégorie dans
 
- 	l'ordre (selon les ID ou selon les noms si $byname est vrai).
 
- 	
 
- 	Si $check_url est vrai, les titres "URLisés" seront normalisés.
 
- 	
 
- 	@param	boolean	chekc_url		Normaliser les titres URLisés (false)
 
- 	@param	boolean	byname		Ordonner par noms (false)
 
- 	*/
 
- 	function reordCats($check_url=false,$byname=false)
 
- 	{
 
- 		$ordby = $byname ? 'cat_libelle' : 'cat_ord';
 
- 		
 
- 		$i = 0;
 
- 		$strReq = 'SELECT cat_id, cat_libelle_url '.
 
- 				'FROM '.$this->t_categorie.' '.
 
- 				'ORDER BY '.$ordby.' ';
 
- 		$rs = $this->con->select($strReq);
 
- 		
 
- 		while (!$rs->EOF())
 
- 		{
 
- 			$reqPlus = '';
 
- 			if ($check_url &&
 
- 			preg_match('/^[a-z]/',$rs->f('cat_libelle_url')))
 
- 			{
 
- 					$reqPlus = ',cat_libelle_url = \''.ucfirst($rs->f('cat_libelle_url')).'\' ';
 
- 			}
 
- 			
 
- 			$updReq = 'UPDATE '.$this->t_categorie.' SET '.
 
- 					'cat_ord = '.$i.' '.
 
- 					$reqPlus.
 
- 					'WHERE cat_id = '.$rs->f('cat_id');
 
- 			
 
- 			if (!$this->con->execute($updReq)) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			}
 
- 			
 
- 			$i++;
 
- 			$rs->moveNext();
 
- 		}
 
- 		
 
- 		$this->triggerMassUpd();
 
- 		return true;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function ordCats
 
- 	
 
- 	Ordonne les catégories en utilisant les valeurs du tableau $ord. La clé est
 
- 	l'identifiant de la catégorie et la valeur, l'ordre de celle-ci.
 
- 	
 
- 	La méthode renvoie vrai en cas de succès.
 
- 	
 
- 	@param	array	ord			Tableau contenant l'ordre de chaque catégorie
 
- 	@return	boolean
 
- 	*/
 
- 	function ordCats($ord)
 
- 	{
 
- 		if (!is_array($ord)) {
 
- 			$this->setError('Bad argument',1000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		foreach ($ord as $k => $v)
 
- 		{
 
- 			$updReq = 'UPDATE '.$this->t_categorie.' SET '.
 
- 					'cat_ord = '.(integer) $v.' '.
 
- 					'WHERE cat_id = '.(integer) $k;
 
- 			
 
- 			if (!$this->con->execute($updReq)) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			}
 
- 		}
 
- 		
 
- 		$this->triggerMassUpd();
 
- 		return true;
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Billets
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes de gestion des billets === */
 
- 	
 
- 	/**
 
- 	@function SQL
 
- 	
 
- 	Cette méthode renvoie une requête SQL prête à être exploitée pour
 
- 	sélectionner des billets selon divers critères.
 
- 	
 
- 	La valeur de $reqPlus doit commencer par ''AND''. $limit peut être un
 
- 	nombre ou un critère de limite classique (0,n).
 
- 	
 
- 	@param	string	reqPlus		Critères SQL supplémentaires ('')
 
- 	@param	string	order		Critère de tri des billets ('post_dt ASC')
 
- 	@param	string	limit		Critère de limitation des résultats
 
- 	@return	string
 
- 	*/
 
- 	function SQL($reqPlus='',$order='post_dt ASC',$limit='')
 
- 	{
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 'AND post_pub = '.(integer) $this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->lang !== NULL) {
 
- 			$reqPlus .= 'AND post_lang = \''.$this->con->escapeStr($this->lang).'\' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT post_id, post_chapo, post_chapo_wiki, post_content, '.
 
- 				'post_content_wiki, post_notes, post_titre, post_titre_url, '.
 
- 				'post_dt, post_upddt, post_creadt, post_pub, '.
 
- 				'post_open_comment, post_open_tb, nb_comment, nb_trackback, '.
 
- 				'post_lang, post_selected, U.user_id, U.user_nom, '.
 
- 				'U.user_prenom, U.user_pseudo, U.user_email, '.
 
- 				'DATE_FORMAT(post_dt,\'%Y%m%d\') AS postdate, '.
 
- 				'DATE_FORMAT(post_dt,\'%H:%i\') AS posthour, '.
 
- 				'DATE_FORMAT(post_dt,\'%d\') AS postday, '.
 
- 				'DATE_FORMAT(post_dt,\'%m\') AS postmonth, '.
 
- 				'DATE_FORMAT(post_dt,\'%Y\') AS postyear, '.
 
- 				'P.cat_id, C.cat_libelle, C.cat_libelle_url '.
 
- 				'FROM '.$this->t_post.' P, '.$this->t_categorie.' C, '.
 
- 					$this->t_user.' U '.
 
- 				'WHERE P.cat_id = C.cat_id '.
 
- 				'AND U.user_id = P.user_id '.
 
- 				$reqPlus.
 
- 				'ORDER BY '.$this->con->escapeStr($order).' ';
 
- 		
 
- 		if ($limit != '') {
 
- 			$limit = (preg_match('/^[0-9]+$/',$limit)) ? '0,'.$limit : $limit;
 
- 			$strReq .= 'LIMIT '.$limit.' ';
 
- 		}
 
- 		
 
- 		return $strReq;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getLastNews
 
- 	
 
- 	Cette functions renvoie un recordset (ou l'objet défini par la propriété
 
- 	'''rs_blogpost''') contenant les n derniers billets.
 
- 	
 
- 	$cat peut être une chaîne ou un entier selon que l'on souhaite travailler
 
- 	avec ''cat_id'' ou ''cat_libelle_url''.
 
- 	
 
- 	@param	integer	limit		Nombre de résultats à renvoyer (20)
 
- 	@param	mixed	cat			Restreindre à la catégorie donnée
 
- 	@param	string	order		Critère de tri ('post_dt DESC')
 
- 	@param	boolean	selected		Uniquement les billets marqués ''post_selected'' (false)
 
- 	@param	string	lang			Restreindre à la langue donnée
 
- 	@return	recordset
 
- 	*/
 
- 	function getLastNews($limit=20,$cat='',$order='post_dt DESC',$selected=false,$lang='')
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($cat != '') {
 
- 			if (preg_match('/^[0-9]+$/',$cat)) {
 
- 				$reqPlus .= 'AND C.cat_id = '.$cat.' ';
 
- 			} else {
 
- 				$reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
 
- 			}
 
- 		}
 
- 		
 
- 		if ($selected) {
 
- 			$reqPlus .= 'AND P.post_selected = 1 ';
 
- 		}
 
- 		
 
- 		if ($lang != '') {
 
- 			$reqPlus .= 'AND P.post_lang = \''.$this->con->escapeStr($lang).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = $this->SQL($reqPlus,$order,$limit);
 
- 		
 
- 		if (($rs = $this->con->select($strReq,$this->rs_blogpost)) !== false) {
 
- 			$rs->setBlog($this);
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getPostByID
 
- 	
 
- 	Sélection d'un billet par son ID. Cette méthode renvoie un recordset
 
- 	étendu (comme la précédente) contenant le billet sélectionné.
 
- 	
 
- 	@param	integer	id		ID du billet
 
- 	@return	recordset
 
- 	*/
 
- 	function getPostByID($id)
 
- 	{
 
- 		$reqPlus = 'AND post_id = '.(integer) $id.' ';
 
- 		
 
- 		$strReq = $this->SQL($reqPlus);
 
- 		
 
- 		if (($rs = $this->con->select($strReq,$this->rs_blogpost)) !== false) {
 
- 			$rs->setBlog($this);
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getPostByDate
 
- 	
 
- 	Sélection de billet par une date. Les paramètre de mois et d'année sont
 
- 	obligatoire. Les aures optionnels. La catégorie peut être une chaîne ou
 
- 	un entier.
 
- 	
 
- 	La méthode renvoie un recordset étendu.
 
- 	
 
- 	@param	integer	y			Année
 
- 	@param	integer	m			Mois
 
- 	@param	integer	d			Jour ('')
 
- 	@param	mixed	cat			Restreindre à la catégorié donnée
 
- 	@param	string	order		Critère de tri ('post_dt DESC')
 
- 	@param	boolean	selected		Uniquement les billets marqués ''post_selected'' (false)
 
- 	@param	string	lang			Restreindre à la langue donnée
 
- 	@return	recordset
 
- 	*/
 
- 	function getPostByDate($y,$m,$d='',$cat='',$order='post_dt DESC',$selected=false,$lang='')
 
- 	{
 
- 		$reqPlus = 'AND DATE_FORMAT(post_dt,\'%Y\') = \''.(integer) $y.'\' ';
 
- 		$reqPlus .= 'AND DATE_FORMAT(post_dt,\'%c\') = \''.(integer) $m.'\' ';
 
- 		
 
- 		if ($d != '') {
 
- 			$reqPlus .= 'AND DATE_FORMAT(post_dt,\'%e\') = \''.(integer) $d.'\' ';
 
- 		}
 
- 		
 
- 		if ($cat != '') {
 
- 			if (preg_match('/^[0-9]+$/',$cat)) {
 
- 				$reqPlus .= 'AND C.cat_id = '.$cat.' ';
 
- 			} else {
 
- 				$reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
 
- 			}
 
- 		}
 
- 		
 
- 		if ($selected) {
 
- 			$reqPlus .= 'AND P.post_selected = 1 ';
 
- 		}
 
- 		
 
- 		if ($lang != '') {
 
- 			$reqPlus .= 'AND P.post_lang = \''.$this->con->escapeStr($lang).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = $this->SQL($reqPlus,$order);
 
- 		
 
- 		if (($rs = $this->con->select($strReq,$this->rs_blogpost)) !== false) {
 
- 			$rs->setBlog($this);
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function searchPost
 
- 	
 
- 	Recherche d'un billet selon des mots clé et renvoie un recordset étendu. La
 
- 	recherche est faite sur les champs ''post_content'', ''post_titre'' et
 
- 	''post_chapo''.
 
- 	
 
- 	@param	string	w			Mots clé
 
- 	@return	recordset
 
- 	*/
 
- 	function searchPost($w)
 
- 	{
 
- 		$strip = array('+',')','(',',','\'');
 
- 		$w = strtolower($w);
 
- 		$w = str_replace($strip,' ',$w);
 
- 		$w = preg_replace('/( )+/',' ',$w);
 
- 		
 
- 		$reqPlus = '';
 
- 		foreach(explode(' ',$w) as $v)
 
- 		{
 
- 			$reqPlus .= 'AND (LOWER(post_content) LIKE \'%'.$this->con->escapeStr($v).'%\' OR '.
 
- 			'LOWER(post_titre) LIKE \'%'.$this->con->escapeStr($v).'%\' OR '.
 
- 			'LOWER(post_chapo) LIKE \'%'.$this->con->escapeStr($v).'%\') ';
 
- 		}
 
- 		
 
- 		$strReq = $this->SQL($reqPlus,'post_dt DESC');
 
- 		
 
- 		if (($rs = $this->con->select($strReq,$this->rs_blogpost)) !== false) {
 
- 			$rs->setBlog($this);
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getAllDates
 
- 	
 
- 	Obtenir les dates (jours ou mois) du blog. Cette méthode renvoie un
 
- 	tableau contenant toutes les dates du blog. On peut restreindre la
 
- 	recherche à une année, un mois (d'une année donnée) ou un jour.
 
- 	
 
- 	Le critère de catégorie peut être une chaîne ou un entier.
 
- 	
 
- 	La tableau renvoyé est un tableau de plusieurs lignes dont la clé est
 
- 	un timestamp et la valeur la date au format YYYY-MM-DD.
 
- 	
 
- 	@param	string	type			Type de date ; y, d ou m
 
- 	@param	integer	y			Année ('')
 
- 	@param	integer	m			Mois ('')
 
- 	@param	integer	d			Jour ('')
 
- 	@param	mixed	cat			Restreindre à la catégorié donnée ('')
 
- 	@return	array
 
- 	*/
 
- 	function getAllDates($type='m',$y='',$m='',$d='',$cat='')
 
- 	{
 
- 		if ($type == 'y') {
 
- 			$dt_f = '%Y-01-01';
 
- 		} elseif ($type == 'd') {
 
- 			$dt_f = '%Y%-%m-%d';
 
- 		} else {
 
- 			$dt_f = '%Y-%m-01';
 
- 		}
 
- 		
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 'AND post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->lang !== NULL) {
 
- 			$reqPlus .= 'AND post_lang = \''.$this->con->escapeStr($this->lang).'\' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		if ($y != '') {
 
- 			$reqPlus .= 'AND DATE_FORMAT(post_dt,\'%Y\') = \''.(integer) $y.'\' ';
 
- 		}
 
- 		
 
- 		if ($m != '') {
 
- 			$reqPlus .= 'AND DATE_FORMAT(post_dt,\'%c\') = \''.(integer) $m.'\' ';
 
- 		}
 
- 		
 
- 		if ($d != '') {
 
- 			$reqPlus .= 'AND DATE_FORMAT(post_dt,\'%e\') = \''.(integer) $d.'\' ';
 
- 		}
 
- 		
 
- 		if ($cat != '') {
 
- 			if (preg_match('/^[0-9]+$/',$cat)) {
 
- 				$reqPlus .= 'AND C.cat_id = '.$cat.' ';
 
- 			} else {
 
- 				$reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
 
- 			}
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT DISTINCT(DATE_FORMAT(post_dt,\''.$dt_f.'\')) '.
 
- 				'FROM '.$this->t_post.' P, '.$this->t_categorie.' C '.
 
- 				'WHERE P.cat_id = C.cat_id '.
 
- 				$reqPlus.
 
- 				'ORDER BY post_dt DESC ';
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) === false) {
 
- 			echo $this->con->error();
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$res = array();
 
- 			while(!$rs->EOF()) {
 
- 				$res[strtotime($rs->field(0))] = $rs->field(0);
 
- 				$rs->moveNext();
 
- 			}
 
- 			return $res;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getEarlierDate
 
- 	
 
- 	Renvoie la date au format standard du billet le plus récent ou false en cas
 
- 	d'erreur. $cat peut être une chaîne ou un entier.
 
- 	
 
- 	@param	mixed	cat			Identifiant de la catégorie
 
- 	@return	string
 
- 	*/
 
- 	function getEarlierDate($cat='')
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($cat != '') {
 
- 			if (preg_match('/^[0-9]+$/',$cat)) {
 
- 				$reqPlus .= 'AND C.cat_id = '.$cat.' ';
 
- 			} else {
 
- 				$reqPlus .= 'AND C.cat_libelle_url = \''.$this->con->escapeStr($cat).'\' ';
 
- 			}
 
- 		}
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 'AND post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->lang !== NULL) {
 
- 			$reqPlus .= 'AND post_lang = \''.$this->con->escapeStr($this->lang).'\' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT MAX(post_dt) '.
 
- 				'FROM '.$this->t_post.' P, '.$this->t_categorie.' C '.
 
- 				'WHERE P.cat_id = C.cat_id '.
 
- 				$reqPlus;
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return $rs->field(0);
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getNextID
 
- 	
 
- 	Renvoie un recordset contenant l'id, le titre et la date du billet
 
- 	suivant le timestamp donné par $ts. $dir prend les valeurs 1 (billet
 
- 	suivant) ou 0 (billet précédent).
 
- 	
 
- 	@param	string	ts			Timestamp du billet
 
- 	@param	integer	dir			Direction de recherche
 
- 	@return	recordset
 
- 	*/
 
- 	function getNextID($ts,$dir=1)
 
- 	{
 
- 		$ts = (integer) $ts;
 
- 		
 
- 		$reqPlus = '';
 
- 		
 
- 		if($dir > 0) {
 
-                $sign = '>';
 
-                $order = 'ASC';
 
-           }
 
-           else {
 
-                $sign = '<';
 
-                $order = 'DESC';
 
-           }
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 'AND post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->lang !== NULL) {
 
- 			$reqPlus .= 'AND post_lang = \''.$this->con->escapeStr($this->lang).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT post_id, post_titre, post_dt '.
 
- 				'FROM '.$this->t_post.' '.
 
- 				'WHERE UNIX_TIMESTAMP(post_dt) '.$sign.' \''.$ts.'\' '.
 
- 				$reqPlus.
 
- 				'ORDER BY post_dt '.$this->con->escapeStr($order).' '.
 
- 				'LIMIT 0,1 ';
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getPostLanguages
 
- 	
 
- 	Renvoie un recordset contenant toutes les langues du blog, ou false en cas
 
- 	d'erreur.
 
- 	
 
- 	@return recordset
 
- 	*/
 
- 	function getPostLanguages()
 
- 	{
 
- 		$reqPlus = '';
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 'AND post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT DISTINCT(post_lang) '.
 
- 				'FROM '.$this->t_post.' '.
 
- 				'WHERE post_lang <> \'\' '.
 
- 				$reqPlus.' '.
 
- 				'ORDER BY post_lang ASC ';
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function addPost
 
- 	
 
- 	Création d'un billet. Renvoie l'ID du billet en cas de succès et false en
 
- 	cas d'erreur.
 
- 	
 
- 	@param	string	user_id		ID de l'utilisateur
 
- 	@param	string	titre		Titre du billet
 
- 	@param	string	titre_url		Titre "URLisé" du billet
 
- 	@param	string	chapo		Chapo
 
- 	@param	string	content		Contenu
 
- 	@param	string	notes		Notes
 
- 	@param	integer	cat_id		ID de la catégorie du billet
 
- 	@param	string	format		Format du billet, html ou wiki ('html')
 
- 	@param	boolean	publish		Publier le billet (true)
 
- 	@param	boolean	open_comment	Ouvrir les commentaires du billet (true)
 
- 	@param	boolean	open_tb		Ouvrir les trackbacks sur le billet (true)
 
- 	@param	string	lang			Langue du billet ('')
 
- 	@param	boolean	selected		Billet sélectionné (false)
 
- 	@param	boolean	delta		Décalage horaire du rédacteur (0)
 
- 	@return	integer
 
- 	*/
 
- 	function addPost($user_id,$titre,$titre_url,$chapo,$content,$notes,$cat_id,
 
- 	$format='html',$publish=true,$open_comment=true,$open_tb=true,$lang='',
 
- 	$selected=false,$delta=0)
 
- 	{
 
- 		# Vérifications d'usage
 
- 		if ($this->checkUser($user_id) === false ) {
 
- 			$this->setError(__('No such user ID or invalid user ID'),1000);
 
- 		}
 
- 		
 
- 		if (trim($titre) == '') {
 
- 			$this->setError(__('Empty entry title'),1000);
 
- 		}
 
- 		
 
- 		if (trim($content) == '') {
 
- 			$this->setError(__('Empty entry content'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error()) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$chapo_wiki = $content_wiki = '';
 
- 		if ($format == 'wiki')
 
- 		{
 
- 			$objWiki = new wiki2xhtml();
 
- 			
 
- 			if ($this->encoding != 'UTF-8') {
 
- 				$objWiki->setOpt('active_fix_word_entities',1);
 
- 			}
 
- 			
 
- 			if (strpos($lang,'fr') === 0) {
 
- 				$objWiki->setOpt('active_fr_syntax',1);
 
- 			}
 
- 			
 
- 			$content_wiki = $content;
 
- 			$content = $objWiki->transform($content);
 
- 			$chapo_wiki = $chapo;
 
- 			$chapo = $objWiki->transform($chapo);
 
- 		}
 
- 		
 
- 		$titre = htmlspecialchars($titre);
 
- 		
 
- 		if (trim($titre_url) == '') {
 
- 			$titre_url = $this->str2url($titre);
 
- 		}
 
- 		$titre_url = $this->str2url($titre_url);
 
- 		
 
- 		$insReq = 'INSERT INTO '.$this->t_post.' '.
 
- 				'(user_id,cat_id,post_dt,post_creadt,post_upddt,'.
 
- 				'post_titre,post_titre_url,post_chapo,post_chapo_wiki,'.
 
- 				'post_content,post_content_wiki,post_notes,post_pub,'.
 
- 				'post_open_comment,post_open_tb,post_lang,post_selected) '.
 
- 				'VALUES '.
 
- 				'(\''.$this->con->escapeStr($user_id).'\','.
 
- 				'\''.$this->con->escapeStr($cat_id).'\','.
 
- 				'ADDDATE(SYSDATE(),INTERVAL \''.$delta.'\' HOUR),'.
 
- 				'SYSDATE(),'.
 
- 				'ADDDATE(SYSDATE(),INTERVAL \''.$delta.'\' HOUR),'.
 
- 				'\''.$this->con->escapeStr($titre).'\','.
 
- 				'\''.$this->con->escapeStr($titre_url).'\','.
 
- 				'\''.$this->con->escapeStr($chapo).'\','.
 
- 				'\''.$this->con->escapeStr($chapo_wiki).'\','.
 
- 				'\''.$this->con->escapeStr($content).'\','.
 
- 				'\''.$this->con->escapeStr($content_wiki).'\','.
 
- 				'\''.$this->con->escapeStr($notes).'\','.
 
- 				'\''.(integer) $publish.'\','.
 
- 				'\''.(integer) $open_comment.'\','.
 
- 				'\''.(integer) $open_tb.'\','.
 
- 				'\''.$this->con->escapeStr($lang).'\','.
 
- 				'\''.(integer) $selected.'\') ';
 
- 		
 
- 		if (!$this->con->execute($insReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			# On récupère l'id et on refait une passe de mise à jour
 
- 			# si le format est en wiki
 
- 			$post_id = $this->con->getLastID();
 
- 			
 
- 			if ($format == 'wiki') {
 
- 				$objWiki->setOpt('note_prefix','pnote-'.$post_id);
 
- 				
 
- 				$content = $objWiki->transform($content_wiki);
 
- 				$chapo = $objWiki->transform($chapo_wiki);
 
- 				
 
- 				$updReq = 'UPDATE '.$this->t_post.' SET '.
 
- 				'post_chapo = \''.$this->con->escapeStr($chapo).'\', '.
 
- 				'post_content = \''.$this->con->escapeStr($content).'\' '.
 
- 				'WHERE post_id = '.$post_id.' ';
 
- 				
 
- 				$this->con->execute($updReq);
 
- 			}
 
- 			
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('post',$post_id,'Create post');
 
- 			return $post_id;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function updPost
 
- 	
 
- 	Modification d'un billet. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	string	post_id		ID du billet à modifier
 
- 	@param	string	titre		Titre du billet
 
- 	@param	string	titre_url		Titre "URLisé" du billet
 
- 	@param	string	chapo		Chapo
 
- 	@param	string	content		Contenu
 
- 	@param	string	notes		Notes
 
- 	@param	integer	cat_id		ID de la catégorie du billet
 
- 	@param	string	format		Format du billet, html ou wiki ('html')
 
- 	@param	boolean	publish		Publier le billet (true)
 
- 	@param	boolean	open_comment	Ouvrir les commentaires du billet (true)
 
- 	@param	boolean	open_tb		Ouvrir les trackbacks sur le billet (true)
 
- 	@param	string	date			Nouveau timestamp du billet
 
- 	@param	string	lang			Langue du billet ('')
 
- 	@param	boolean	selected		Billet sélectionné (false)
 
- 	@param	boolean	delta		Décalage horaire du rédacteur (0)
 
- 	@return	boolean
 
- 	*/
 
- 	function updPost($post_id,$titre,$titre_url,$chapo,$content,$notes,$cat_id,
 
- 	$format='html',$publish=true,$open_comment=true,$open_tb=true,$date='',
 
- 	$lang='',$selected=false,$delta=0)
 
- 	{
 
- 		# Vérifications d'usage
 
- 		if (trim($post_id) == '' ) {
 
- 			$this->setError(__('No such post ID'),1000);
 
- 		}
 
- 		
 
- 		if (trim($titre) == '') {
 
- 			$this->setError(__('Empty entry title'),1000);
 
- 		}
 
- 		
 
- 		if (trim($content) == '') {
 
- 			$this->setError(__('Empty entry content'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error()) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$chapo_wiki = $content_wiki = '';
 
- 		if ($format == 'wiki')
 
- 		{
 
- 			$objWiki = new wiki2xhtml();
 
- 			
 
- 			if ($this->encoding != 'UTF-8') {
 
- 				$objWiki->setOpt('active_fix_word_entities',1);
 
- 			}
 
- 			
 
- 			if (strpos($lang,'fr') === 0) {
 
- 				$objWiki->setOpt('active_fr_syntax',1);
 
- 			}
 
- 			
 
- 			$objWiki->setOpt('note_prefix','pnote-'.$post_id);
 
- 			
 
- 			$content_wiki = $content;
 
- 			$content = $objWiki->transform($content);
 
- 			$chapo_wiki = $chapo;
 
- 			$chapo = $objWiki->transform($chapo);
 
- 		}
 
- 		
 
- 		$titre = htmlspecialchars($titre);
 
- 		
 
- 		if (trim($titre_url) == '') {
 
- 			$titre_url = $this->str2url($titre);
 
- 		}
 
- 		$titre_url = $this->str2url($titre_url);
 
- 		
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($date != '') {
 
- 			$reqPlus = 'post_dt = \''.date('Y-m-d H:i:s',$date).'\', ';
 
- 		}
 
- 		
 
- 		$updReq = 'UPDATE '.$this->t_post.' SET '.
 
- 				'cat_id = \''.$this->con->escapeStr($cat_id).'\', '.
 
- 				'post_titre = \''.$this->con->escapeStr($titre).'\', '.
 
- 				'post_titre_url = \''.$this->con->escapeStr($titre_url).'\', '.
 
- 				'post_chapo = \''.$this->con->escapeStr($chapo).'\', '.
 
- 				'post_chapo_wiki = \''.$this->con->escapeStr($chapo_wiki).'\', '.
 
- 				'post_content = \''.$this->con->escapeStr($content).'\', '.
 
- 				'post_content_wiki = \''.$this->con->escapeStr($content_wiki).'\', '.
 
- 				'post_notes = \''.$this->con->escapeStr($notes).'\', '.
 
- 				'post_pub = \''.(integer) $this->con->escapeStr($publish).'\', '.
 
- 				'post_open_comment = \''.(integer) $this->con->escapeStr($open_comment).'\', '.
 
- 				'post_open_tb = \''.(integer) $this->con->escapeStr($open_tb).'\', '.
 
- 				'post_lang = \''.$this->con->escapeStr($lang).'\', '.
 
- 				'post_selected = \''.(integer) $selected.'\', '.
 
- 				$reqPlus.
 
- 				'post_upddt = ADDDATE(SYSDATE(),INTERVAL \''.$delta.'\' HOUR) '.
 
- 				'WHERE post_id = '.(integer) $post_id.' ';
 
- 		
 
- 		if (!$this->con->execute($updReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('post',$post_id,'Update post');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function updPostCat
 
- 	
 
- 	Change la catégorie d'un billet donné. Renvoi vrai en cas de succès.
 
- 	
 
- 	@param	integer	post_id		ID du billet
 
- 	@param	integer	cat_id		ID de la catégorie
 
- 	@return	boolean
 
- 	*/
 
- 	function updPostCat($post_id,$cat_id)
 
- 	{
 
- 		if (trim($post_id) == '' ) {
 
- 			$this->setError(__('No such post ID'),1000);
 
- 		}
 
- 		
 
- 		if (trim($cat_id) == '') {
 
- 			$this->setError(__('No such cat ID'),1000);
 
- 		}
 
- 		
 
- 		$updReq = 'UPDATE '.$this->t_post.' SET '.
 
- 				'cat_id = \''.$this->con->escapeStr($cat_id).'\' '.
 
- 				//',post_upddt = SYSDATE() '.
 
- 				'WHERE post_id = '.$post_id.' ';
 
- 		
 
- 		if (!$this->con->execute($updReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('post',$post_id,'Update post category');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function statusPost
 
- 	
 
- 	Inverse le status de publication d'un billet.
 
- 	
 
- 	@param	integer	id			ID du billet
 
- 	@return	boolean
 
- 	*/
 
- 	function statusPost($id)
 
- 	{
 
- 		$updReq = 'UPDATE '.$this->t_post.' SET '.
 
- 				'post_pub = 1-post_pub '.
 
- 				//',post_upddt = SYSDATE() '.
 
- 				'WHERE post_id = '.$id.' ';
 
- 		
 
- 		if (!$this->con->execute($updReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('post',$id,'Change status');
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function delPost
 
- 	
 
- 	Supprime un billet et tous les commentaires associés. Renvoie vrai en cas
 
- 	de succès.
 
- 	
 
- 	@param	integer	id			ID du billet
 
- 	@return	boolean
 
- 	*/
 
- 	function delPost($id)
 
- 	{
 
- 		$delReq = 'DELETE FROM '.$this->t_post.' '.
 
- 				'WHERE post_id = '.(integer) $id.' ';
 
- 		
 
- 		if (!$this->con->execute($delReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->tiggerLog('post',$id,'Delete post');
 
- 			
 
- 			$delCom = 'DELETE FROM '.$this->t_comment.' '.
 
- 					'WHERE post_id = '.$id.' ';
 
- 			if (!$this->con->execute($delCom)) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			}
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function triggerMassUpd
 
- 	
 
- 	"Déclencheur" changeant la date d'un fichier pour indiquer la
 
- 	dernière modification. Le fichier est défini par la constante
 
- 	DC_UPDATE_FILE et la constante DC_UPDATE_FILE_W indique si ce dernier est
 
- 	accessible en écriture.
 
- 	*/
 
- 	function triggerMassUpd()
 
- 	{
 
- 		if (defined('DC_UPDATE_FILE_W') && DC_UPDATE_FILE_W) {
 
- 			files::touch(DC_UPDATE_FILE,time());
 
- 		}
 
- 	} 
 
- 	
 
- 	/**
 
- 	@function triggerPostNbComment
 
- 	
 
- 	"Déclencheur" pour mettre à jour le nombre de commentaires
 
- 	publiés d'un billet. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	id			ID du billet
 
- 	@return	boolean
 
- 	*/
 
- 	function triggerPostNbComment($id)
 
- 	{
 
- 		$strReq = 'SELECT COUNT(comment_id) '.
 
- 				'FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_trackback <> 1 '.
 
- 				'AND post_id = '.(integer) $id.' '.
 
- 				'AND comment_pub = 1 ';
 
- 		$rsC = $this->con->select($strReq);
 
- 		
 
- 		$strReq = 'SELECT COUNT(comment_id) '.
 
- 				'FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_trackback = 1 '.
 
- 				'AND post_id = '.(integer) $id.' '.
 
- 				'AND comment_pub = 1 ';
 
- 		$rsT = $this->con->select($strReq);
 
- 		
 
- 		$updReq = 'UPDATE '.$this->t_post.' '.
 
- 				'SET nb_comment = '.$rsC->f(0).', '.
 
- 				'nb_trackback = '.$rsT->f(0).' '.
 
- 				'WHERE post_id = '.(integer) $id.' ';
 
- 		
 
- 		if (!$this->con->execute($updReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 		return true;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function tiggerLog
 
- 	
 
- 	"Déclencheur" remplissant la table de logs. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	string	table		Nom de la table
 
- 	@param	string	key			Valeur de la clé de la table
 
- 	@param	string	log			Description du log
 
- 	@param	string	user			ID de l'utilisateur
 
- 	@return	boolean
 
- 	*/
 
- 	function tiggerLog($table,$key,$log,$user='')
 
- 	{
 
- 		if ($user == '') {
 
- 			if (!empty($_SESSION['sess_user_id'])) {
 
- 				$user = $_SESSION['sess_user_id'];
 
- 			} else {
 
- 				$user = $this->user_id;
 
- 			}
 
- 		}
 
- 		
 
- 		$insReq = 'INSERT INTO '.$this->t_log.' '.
 
- 				'(`user_id`,`table`,`key`,`date`,`ip`,`log`) VALUES ('.
 
- 				'\''.$this->con->escapeStr($user).'\','.
 
- 				'\''.$this->con->escapeStr($table).'\','.
 
- 				'\''.$this->con->escapeStr($key).'\','.
 
- 				'SYSDATE(),'.
 
- 				'\''.$this->con->escapeStr(@$_SERVER['REMOTE_ADDR']).'\','.
 
- 				'\''.$this->con->escapeStr($log).'\''.
 
- 				')';
 
- 		
 
- 		$this->con->execute($insReq);
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Commentaires
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes de gestion des commentaires === */
 
- 	
 
- 	/**
 
- 	@function getNbComments
 
- 	
 
- 	Retourn le nombre de commentaires d'un billet sous forme d'un entier.
 
- 	
 
- 	@param	integer	id			ID du billet
 
- 	@return	integer
 
- 	*/
 
- 	function getNbComments($id='')
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .=
 
- 			'AND C.comment_pub = '.$this->pub_mode.' '.
 
- 			'AND P.post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		if ($id != '') {
 
- 			$reqPlus .= 'AND P.post_id = '.(integer) $id.' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT count(comment_id) '.
 
- 				'FROM '.$this->t_comment.' C, '.$this->t_post.' P '.
 
- 				'WHERE P.post_id = C.post_id '.
 
- 				'AND comment_trackback <> 1 '.
 
- 				$reqPlus;
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return $rs->field(0);
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getNbTrackbacks
 
- 	
 
- 	Retourn le nombre de trackbacks d'un billet sous forme d'un entier.
 
- 	
 
- 	@param	integer	id			ID du billet
 
- 	@return	integer
 
- 	*/
 
- 	function getNbTrackbacks($id='')
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .=
 
- 			'AND C.comment_pub = '.$this->pub_mode.' '.
 
- 			'AND P.post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		if ($id != '') {
 
- 			$reqPlus .= 'AND P.post_id = '.(integer) $id.' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT count(comment_id) '.
 
- 				'FROM '.$this->t_comment.' C, '.$this->t_post.' P '.
 
- 				'WHERE P.post_id = C.post_id '.
 
- 				'AND comment_trackback = 1 '.
 
- 				$reqPlus;
 
- 		
 
- 		if (($rs = $this->con->select($strReq)) !== false) {
 
- 			return $rs->field(0);
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getComments
 
- 	
 
- 	Sélection des commentaires et trackbacks d'un billet. Renvoie un recordset
 
- 	étendu du type défini par la propriété '''rs_blogcomment'''. Si la valeur de
 
- 	$post_id est vide, tous les commentaires seront renvoyés.
 
- 	
 
- 	@param	integer	post_id		ID du billet ('')
 
- 	@param	string	order		Send de l'ordre des commentaires, ASC ou DESC ('ASC')
 
- 	@param	integer	limit		Nombre de commentaires à séléctionner (NULL)
 
- 	@return	recordset
 
- 	*/
 
- 	function getComments($post_id='',$order='ASC',$limit=NULL)
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .= 
 
- 			'AND C.comment_pub = '.$this->pub_mode.' '.
 
- 			'AND P.post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		if ($post_id != '') {
 
- 			$reqPlus .= 'AND C.post_id = '.(integer) $post_id.' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT comment_id, comment_dt, comment_upddt, comment_auteur, '.
 
- 				'comment_email, comment_site, comment_content, comment_trackback, '.
 
- 				'comment_pub, comment_ip, P.post_titre, P.post_titre_url, P.post_id, '.
 
- 				'DATE_FORMAT(P.post_dt,\'%d\') AS postday, '.
 
- 				'DATE_FORMAT(P.post_dt,\'%m\') AS postmonth, '.
 
- 				'DATE_FORMAT(P.post_dt,\'%Y\') AS postyear, '.
 
- 				'DATE_FORMAT(comment_dt,\'%Y%m%d\') AS comment_date '.
 
- 				'FROM '.$this->t_comment.' C, '.$this->t_post.' P '.
 
- 				'WHERE P.post_id = C.post_id '.
 
- 				$reqPlus.
 
- 				'ORDER BY comment_dt '.$this->con->escapeStr($order).' ';
 
- 		
 
- 		if ($limit !== NULL) {
 
- 			$limit = (preg_match('/^[0-9]+$/',$limit)) ? '0,'.$limit : $limit;
 
- 			$strReq .= 'LIMIT '.$limit.' ';
 
- 		}
 
- 		
 
- 		if (($rs = $this->con->select($strReq,$this->rs_blogcomment)) !== false) {
 
- 			$rs->setBlog($this);
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getComment
 
- 	
 
- 	Récupération d'un commentaire par son ID. Renvoie un recordset étendu.
 
- 	
 
- 	@param	integer	id			ID du commentaire
 
- 	@return	recordset
 
- 	*/
 
- 	function getComment($id)
 
- 	{
 
- 		$reqPlus = '';
 
- 		
 
- 		if ($this->pub_mode !== NULL) {
 
- 			$reqPlus .=
 
- 			'AND C.comment_pub = '.$this->pub_mode.' '.
 
- 			'AND P.post_pub = '.$this->pub_mode.' ';
 
- 		}
 
- 		
 
- 		if ($this->user_id != '') {
 
- 			$reqPlus .= 'AND P.user_id = \''.$this->con->escapeStr($this->user_id).'\' ';
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT comment_id, comment_dt, comment_upddt, comment_auteur, '.
 
- 				'comment_email, comment_site, comment_content, comment_trackback, '.
 
- 				'comment_pub, comment_ip, P.post_titre, P.post_id, P.user_id,'.
 
- 				'DATE_FORMAT(comment_dt,\'%Y%m%d\') AS comment_date '.
 
- 				'FROM '.$this->t_comment.' C, '.$this->t_post.' P '.
 
- 				'WHERE C.comment_id = '.(integer) $id.' '.
 
- 				'AND C.post_id = P.post_id '.
 
- 				$reqPlus;
 
- 		
 
- 		if (($rs = $this->con->select($strReq,$this->rs_blogcomment)) !== false) {
 
- 			$rs->setBlog($this);
 
- 			return $rs;
 
- 		} else {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function addComment
 
- 	
 
- 	Création d'un commentaire. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	post_id		ID du billet
 
- 	@param	string	auteur		Nom de l'auteur du commentaire
 
- 	@param	string	email		Email de l'auteur du commentaire
 
- 	@param	string	site			Site de l'auteur du commentaire
 
- 	@param	string	content		Contenu du commentaire
 
- 	@param	boolean	trackback		Le commentaire est un trackback (false)
 
- 	@param	integer	delta		Décalage horaire de l'auteur du commentaire (0)
 
- 	@param	boolean	pub			Commentaire publié (true)
 
- 	@return	boolean
 
- 	*/
 
- 	function addComment($post_id,$auteur,$email,$site,$content,
 
- 	$trackback=false,$delta=0,$pub=1)
 
- 	{
 
- 		$post_id = (integer) $post_id;
 
- 		$auteur = $this->secureString($auteur);
 
- 		$email = $this->secureString($email);
 
- 		$site = $this->secureString($site);
 
- 		
 
- 		$pub = (integer) (boolean) $pub;
 
- 		
 
- 		# Vérifications
 
- 		if (!trim($post_id)) {
 
- 			$this->setError(__('No entry ID'),1000);
 
- 		}
 
- 		
 
- 		if (!trim($auteur)) {
 
- 			$this->setError(__('Empty comment author'),1000);
 
- 		}
 
- 		
 
- 		if (!trim($content)) {
 
- 			$this->setError(__('Empty comment content'),1000);
 
- 		}
 
- 		
 
- 		if ($email != '' && !$this->isEmail($email)) {
 
- 			$this->setError(__('Invalid email address'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$site = preg_replace('|^http://|','',$site);
 
- 		
 
- 		# Insertion
 
- 		$insReq = 'INSERT INTO '.$this->t_comment.' '.
 
- 				'(post_id,comment_dt,comment_upddt,comment_auteur,comment_email,'.
 
- 				'comment_site,comment_content,comment_ip,comment_pub,'.
 
- 				'comment_trackback) VALUES '.
 
- 				'(\''.$this->con->escapeStr($post_id).'\', '.
 
- 				'ADDDATE(SYSDATE(),INTERVAL \''.$delta.'\' HOUR),SYSDATE(), '.
 
- 				'\''.$this->con->escapeStr($auteur).'\', '.
 
- 				'\''.$this->con->escapeStr($email).'\', '.
 
- 				'\''.$this->con->escapeStr($site).'\', '.
 
- 				'\''.$this->con->escapeStr($content).'\', '.
 
- 				'\''.$this->con->escapeStr(@$_SERVER['REMOTE_ADDR']).'\', '.
 
- 				(integer) $pub.','.
 
- 				(integer) $trackback.') ';
 
- 		
 
- 		if (!$this->con->execute($insReq)) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			$this->triggerPostNbComment($post_id);
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function updComment
 
- 	
 
- 	Modification d'un commentaire. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	id			ID du commentaire
 
- 	@param	string	auteur		Nom de l'auteur du commentaire
 
- 	@param	string	email		Email de l'auteur du commentaire
 
- 	@param	string	site			Site de l'auteur du commentaire
 
- 	@param	string	content		Contenu du commentaire
 
- 	@param	boolean	pub			Commentaire publié (true)
 
- 	@return	boolean
 
- 	*/
 
- 	function updComment($id,$auteur,$email,$site,$content,$pub)
 
- 	{
 
- 		$id = (integer) $id;
 
- 		$auteur = $this->secureString($auteur);
 
- 		$email = $this->secureString($email);
 
- 		$site = $this->secureString($site);
 
- 		$content = $content;
 
- 		$pub = (integer) $pub;
 
- 		
 
- 		# Vérifications usuelles
 
- 		if (!$auteur) {
 
- 			$this->setError(__('Empty comment author'),1000);
 
- 		}
 
- 		
 
- 		if (!$content) {
 
- 			$this->setError(__('Empty comment content'),1000);
 
- 		}
 
- 		
 
- 		if ($email != '' && !$this->isEmail($email)) {
 
- 			$this->setError(__('Invalid email address'),1000);
 
- 		}
 
- 		
 
- 		if ($this->error() !== false) {
 
- 			return false;
 
- 		}
 
- 		
 
- 		$strReq = 'SELECT post_id FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_id = \''.$id.'\' ';
 
- 		
 
- 		$rs = $this->con->select($strReq);
 
- 		
 
- 		if (!$rs->isEmpty())
 
- 		{
 
- 			$site = preg_replace('|^http://|','',$site);
 
- 			
 
- 			$updReq = 'UPDATE '.$this->t_comment.' SET '.
 
- 					'comment_auteur = \''.$this->con->escapeStr($auteur).'\', '.
 
- 					'comment_email = \''.$this->con->escapeStr($email).'\', '.
 
- 					'comment_site = \''.$this->con->escapeStr($site).'\', '.
 
- 					'comment_content = \''.$this->con->escapeStr($content).'\', '.
 
- 					'comment_pub = '.(integer) $pub.', '.
 
- 					'comment_upddt = SYSDATE() '.
 
- 					'WHERE comment_id = '.(integer) $id.' ';
 
- 			
 
- 			if (!$this->con->execute($updReq)) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			} else {
 
- 				$this->tiggerLog('comment',$id,'Update comment');
 
- 				$this->triggerMassUpd();
 
- 				$this->triggerPostNbComment($rs->f('post_id'));
 
- 				return true;
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function statusComment
 
- 	
 
- 	Inversion du status d'un commentaire. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	id			ID du commentaire
 
- 	@return	boolean
 
- 	*/
 
- 	function statusComment($id)
 
- 	{
 
- 		$strReq = 'SELECT post_id FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_id = '.(integer) $id.' ';
 
- 		
 
- 		$rs = $this->con->select($strReq);
 
- 		
 
- 		if (!$rs->isEmpty())
 
- 		{
 
- 			$updReq = 'UPDATE '.$this->t_comment.' SET '.
 
- 					'comment_pub = 1-comment_pub, '.
 
- 					'comment_upddt = SYSDATE() '.
 
- 					'WHERE comment_id = '.(integer) $id.' ';
 
- 			
 
- 			if (!$this->con->execute($updReq)) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			} else {
 
- 				$this->tiggerLog('comment',$id,'Change status');
 
- 				$this->triggerMassUpd();
 
- 				$this->triggerPostNbComment($rs->f('post_id'));
 
- 				return true;
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function delComment
 
- 	
 
- 	Suppression d'un commentaire. Renvoie vrai en cas de succès.
 
- 	
 
- 	@param	integer	id			ID du commentaire
 
- 	@return	boolean
 
- 	*/
 
- 	function delComment($id)
 
- 	{
 
- 		$strReq = 'SELECT post_id FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_id = '.(integer) $id.' ';
 
- 		
 
- 		$rs = $this->con->select($strReq);
 
- 		
 
- 		if (!$rs->isEmpty())
 
- 		{
 
- 			$delReq = 'DELETE FROM '.$this->t_comment.' '.
 
- 					'WHERE comment_id = '.(integer) $id.' ';
 
- 			
 
- 			if (!$this->con->execute($delReq)) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			} else {
 
- 				$this->tiggerLog('comment',$id,'Delete comment');
 
- 				$this->triggerMassUpd();
 
- 				$this->triggerPostNbComment($rs->f('post_id'));
 
- 				return true;
 
- 			}
 
- 		}
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Trackback et ping
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes de gestion des trackback et des pings === */
 
- 	
 
- 	/**
 
- 	@function postTbPingURL
 
- 	
 
- 	Effectue un ping sur un autre blog. Renvoie vrai en cas de succès.
 
- 	
 
- 	Si le contenu du ping n'est pas donné, les 255 premier caractères du
 
- 	billet ou du chapo seront utilisés à la place.
 
- 	
 
- 	@param	integer	post_id		ID du billet
 
- 	@param	string	url			URL à pinguer
 
- 	@param	string	blog_name		Nom du blog à envoyer
 
- 	@param	string	content		Contenu facultatif du ping ('')
 
- 	@return	boolean
 
- 	*/
 
- 	function postTbPingURL($post_id,$url,$blog_name,$content='')
 
- 	{
 
- 		# le billet existe ?
 
- 		$post = $this->getPostByID($post_id);
 
- 		
 
- 		if ($post->isEmpty()) {
 
- 			$this->setError(__('Entry does not exists'),1000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		# On a déjà fait un ping pour cette url et ce billet ?
 
- 		/*if ($this->postPingCheck($post_id,$url) === true) {
 
- 			$this->setError('URI déjà pinguée pour ce billet',1200);
 
- 			return false;
 
- 		}*/
 
- 		
 
- 		# On test si l'url est bien du http
 
- 		$URL = parse_url($url);
 
- 		if (empty($URL['scheme']) || $URL['scheme'] != 'http' || empty($URL['path'])) {
 
- 			$this->setError('URL invalide',1000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		# Reconstruction de l'url
 
- 		$host = $URL['host'];
 
- 		$port = (!empty($URL['port'])) ? $URL['port'] : 80;
 
- 		$user = (!empty($URL['user'])) ? $URL['user'] : '';
 
- 		$pass = (!empty($URL['pass'])) ? $URL['pass'] : '';
 
- 				
 
- 		$link = $URL['path'];
 
- 		$link .= (!empty($URL['query'])) ? '?'.$URL['query'] : '';
 
- 		$link .= (!empty($URL['fragment'])) ? '#'.$URL['fragment'] : '';
 
- 		
 
- 		# Tentative de ping
 
- 		$http = new HttpClient($host,$port);
 
- 		$http->timeout = 10;
 
- 		$http->setUserAgent('DotClear HTTP Client - http://www.dotclear.net/');
 
- 		$http->useGzip(false);
 
- 		$http->setPersistReferers(false);
 
- 		
 
- 		if ($user != '' || $pass != '') {
 
- 			$http->setAuthorization($user,$pass);
 
- 		}
 
- 		
 
- 		# On vérifie si on a un encoding utf-8
 
- 		$do_utf8 = false;
 
- 		if ($this->encoding == 'UTF-8')
 
- 		{
 
- 			if ($http->post($link,array('__info' => 1)) === false) {
 
- 				$this->setError('HTTP : '.$http->getError(),3000);
 
- 				return false;
 
- 			}
 
- 			
 
- 			$tmp = $http->getContent();
 
- 			
 
- 			if (preg_match('/<encoding>(UTF-8|utf-8)<\/encoding>/msU',$tmp)) {
 
- 				$do_utf8 = true;
 
- 			}
 
- 		}
 
- 		
 
- 		if (trim($content) == '') {
 
- 			$content = $post->f('post_content');
 
- 		}
 
- 		$content = strip_tags($content);
 
- 		
 
- 		if ($do_utf8) {
 
- 			$params = array(
 
- 			'title' => $post->f('post_titre'),
 
- 			'excerpt' => util::cutString($content,255),
 
- 			'url' => 'http://'.$_SERVER['HTTP_HOST'].$post->getPermURL(),
 
- 			'blog_name' => $blog_name,
 
- 			'utf8' => 1
 
- 			);
 
- 		} elseif ($this->encoding == 'UTF-8') {
 
- 			$params = array(
 
- 			'title' => utf8_decode($post->f('post_titre')),
 
- 			'excerpt' => util::cutString(utf8_decode($content),255),
 
- 			'url' => 'http://'.$_SERVER['HTTP_HOST'].$post->getPermURL(),
 
- 			'blog_name' => utf8_decode($blog_name)
 
- 			);
 
- 		} else {
 
- 			$params = array(
 
- 			'title' => $post->f('post_titre'),
 
- 			'excerpt' => util::cutString($content,255),
 
- 			'url' => 'http://'.$_SERVER['HTTP_HOST'].$post->getPermURL(),
 
- 			'blog_name' => $blog_name
 
- 			);
 
- 		}
 
- 		
 
- 		# On fait le ping
 
- 		if ($http->post($link,$params) === false) {
 
- 			$this->setError('HTTP : '.$http->getError(),3000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		# Tout va bien on continue
 
- 		$res = $http->getContent();
 
- 		
 
- 		$pattern = '|<response>.*<error>(.*)</error>(.*)'.
 
- 				'(<message>(.*)</message>(.*))?'.
 
- 				'</response>|msU';
 
- 		
 
- 		if (!preg_match($pattern,$res,$matches))
 
- 		{
 
- 			$this->setError(__('Source is not a ping URL'),3000);
 
- 			return false;
 
- 		}
 
- 		
 
- 		# On continue, le match est OK
 
- 		$ping_error = $matches[1];
 
- 		$ping_msg = (!empty($matches[4])) ? $matches[4] : '';
 
- 		
 
- 		if ($ping_error != '0') {
 
- 			$this->setError(__('Trackback error').' : '.$ping_msg,3000);
 
- 			return false;
 
- 		} else {
 
- 			# Oui ! Le trackback est passé ! champagne :))
 
- 			# On va faire la notification
 
- 			$this->postPingNotify($post_id,$url);
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function postPingNotify
 
- 	
 
- 	Notification du trackback dans la table d'historique des pings. Renvoie
 
- 	vrai en cas de succès.
 
- 	
 
- 	@param	integer	post_id		ID du billet
 
- 	@param	string	url			URL du ping
 
- 	@return	boolean
 
- 	*/
 
- 	function postPingNotify($post_id,$url)
 
- 	{
 
- 		$insReq = 'INSERT INTO '.$this->t_ping.' '.
 
- 				'(post_id,ping_url,ping_dt) VALUES '.
 
- 				'('.(integer) $post_id.','.
 
- 				'\''.$this->con->escapeStr($url).'\','.
 
- 				'SYSDATE()) ';
 
- 		
 
- 		if ($this->con->execute($insReq) === false) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function postPingCheck
 
- 	
 
- 	Vérification si ping pas déjà fait pour un post. Renvoie vrai si il y a
 
- 	déjà un ping dans la table.
 
- 	
 
- 	@param	integer	post_id		ID du billet
 
- 	@param	string	url			URL du ping
 
- 	@return	boolean
 
- 	*/
 
- 	function postPingCheck($post_id,$url)
 
- 	{
 
- 		$strReq = 'SELECT post_id '.
 
- 				'FROM '.$this->t_ping.' '.
 
- 				'WHERE post_id = '.(integer) $post_id.' '.
 
- 				'AND ping_url = \''.$this->con->escapeStr($url).'\' ';
 
- 		
 
- 		$rs = $this->con->select($strReq);
 
- 		return !$rs->isEmpty();
 
- 	}
 
- 	
 
- 	/**
 
- 	@function postGetPings
 
- 	
 
- 	Sélection des ping réalisés pour un post donnée. Renvoie un recordset.
 
- 	
 
- 	@param	integer	post_id		ID du billet
 
- 	@return	recordset
 
- 	*/
 
- 	function postGetPings($post_id)
 
- 	{
 
- 		$strReq = 'SELECT post_id,ping_url,ping_dt '.
 
- 				'FROM '.$this->t_ping. ' '.
 
- 				'WHERE post_id = '.(integer) $post_id.' ';
 
- 		
 
- 		return $this->con->select($strReq);
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Outils MySQL
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes relatives à la base de données === */
 
- 	
 
- 	/**
 
- 	@function optimize
 
- 	
 
- 	Optimise les tables de la base de données. Les tables concernées sont
 
- 	uniquement celles prises en charge par la classe. Renvoie vrai en cas de
 
- 	succès.
 
- 	
 
- 	@return	boolean
 
- 	*/
 
- 	function optimize()
 
- 	{
 
- 		$strReq = 'OPTIMIZE TABLE '.
 
- 				'`'.$this->t_post.'`, '.
 
- 				'`'.$this->t_user.'`, '.
 
- 				'`'.$this->t_categorie.'`, '.
 
- 				'`'.$this->t_comment.'`, '.
 
- 				'`'.$this->t_ping.'`,'.
 
- 				'`'.$this->t_log.'`,'.
 
- 				'`'.$this->t_link.'`';
 
- 		
 
- 		if ($this->con->execute($strReq) === false) {
 
- 			$this->setError('MySQL : '.$this->con->error(),2000);
 
- 			return false;
 
- 		} else {
 
- 			$this->triggerMassUpd();
 
- 			return true;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function countAll
 
- 	
 
- 	Recompte l'ensemble des commentaires et trackbacks du blog.
 
- 	*/
 
- 	function countAll()
 
- 	{
 
- 		$strReq = 'SELECT COUNT(comment_id), post_id '.
 
- 				'FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_trackback <> 1 '.
 
- 				'AND comment_pub = 1 '.
 
- 				'GROUP BY post_id ';
 
- 		$rsC = $this->con->select($strReq);
 
- 		
 
- 		$strReq = 'SELECT COUNT(comment_id), post_id '.
 
- 				'FROM '.$this->t_comment.' '.
 
- 				'WHERE comment_trackback = 1 '.
 
- 				'AND comment_pub = 1 '.
 
- 				'GROUP BY post_id ';
 
- 		$rsT = $this->con->select($strReq);
 
- 		
 
- 		while(!$rsC->EOF())
 
- 		{
 
- 			$updReq = 'UPDATE '.$this->t_post.' '.
 
- 					'SET nb_comment='.$rsC->f(0).' '.
 
- 					'WHERE post_id='.$rsC->f(1).' ';
 
- 			
 
- 			if ($this->con->execute($updReq) === false) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			}
 
- 			$rsC->moveNext();
 
- 		}
 
- 		
 
- 		while(!$rsT->EOF())
 
- 		{
 
- 			$updReq = 'UPDATE '.$this->t_post.' '.
 
- 					'SET nb_trackback='.$rsT->f(0).' '.
 
- 					'WHERE post_id='.$rsT->f(1).' ';
 
- 			
 
- 			if ($this->con->execute($updReq) === false) {
 
- 				$this->setError('MySQL : '.$this->con->error(),2000);
 
- 				return false;
 
- 			}
 
- 			$rsT->moveNext();
 
- 		}
 
- 		$this->triggerMassUpd();
 
- 	}
 
- 	
 
- 	/* ===================================================
 
- 	Utilitaires
 
- 	=================================================== */
 
- 	/** @doc
 
- 	=== Méthodes utilitaires === */
 
- 	
 
- 	/**
 
- 	@function parseContent
 
- 	
 
- 	Cette méthode remplace les URL et les liens mailto par des liens HTML dans
 
- 	la chaîne $string et renvoie une chaîne transformée.
 
- 	
 
- 	@param	string	string		Chaine à parser
 
- 	@return	string
 
- 	*/
 
- 	function parseContent($string)
 
- 	{
 
- 		$string = preg_replace_callback('/(http|https|ftp):(\/\/){0,1}([^\"\s]*)/i',
 
- 				array('blog','parseUri'),$string);
 
- 		
 
- 		$string = preg_replace(
 
- 				'|([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)|mi',
 
- 				'<a href="mailto:$1">$1</a>',
 
- 				$string
 
- 				);
 
- 		
 
- 		return $string;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function parseUri
 
- 	
 
- 	Cette fonction est utilisée par ''parseContent'' pour créer le lien HTML
 
- 	depuis une URL. L'intitulé est raccourci si l'URL dépasse 25 caractères.
 
- 	
 
- 	C'est une fonction de callback qui n'est d'aucune utilité sortie de son
 
- 	contexte.
 
- 	
 
- 	@param	array	matches		Tableau contenant l'URL
 
- 	@return	string
 
- 	*/
 
- 	function parseUri($matches)
 
- 	{
 
- 		$uri = $matches[1].':'.$matches[2].$matches[3];
 
- 		$t = parse_url($uri);
 
- 		
 
- 		$link = (strlen($matches[3]) > 25) ? substr($matches[3],0,25).'...' : $matches[3];
 
- 		
 
- 		if (!empty($t['scheme'])) {
 
- 			return '<a href="'.$uri.'" title="'.$uri.'" rel="nofollow">'.$link.'</a>';
 
- 			//return '[<a href="'.$uri.'" title="'.$uri.'">URL <em>'.$t['host'].'</em></a>]';
 
- 		} else {
 
- 			return $uri;
 
- 		}
 
- 	}
 
- 	
 
- 	/**
 
- 	@function secureString
 
- 	
 
- 	Renvoie une chaîne après en avoir supprimé les tags HTML et passé les
 
- 	caractères spéciaux en entités.
 
- 	
 
- 	@param	string	str			Chaîne à sécurisé
 
- 	@return	string
 
- 	*/
 
- 	function secureString($str)
 
- 	{
 
- 		$str = trim($str);
 
- 		$str = stripslashes($str);
 
- 		$str = strip_tags($str);
 
- 		$str = htmlspecialchars($str);
 
- 		return $str;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function isEmail
 
- 	
 
- 	Teste si une chaîne est une adresse email valide.
 
- 	
 
- 	@param	string	str			Chaîne à tester
 
- 	@return	boolean
 
- 	*/
 
- 	function isEmail($str)
 
- 	{
 
- 		return preg_match('/^[a-zA-Z0-9_+-]+(\.[a-zA-Z0-9_+-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/',$str);
 
- 	}
 
- 	
 
- 	/**
 
- 	@function getPart
 
- 	
 
- 	Renvoie une partie de la chaîne $string en coupant à la longueur $l
 
- 	désirée. La chaîne est coupée aux espaces.
 
- 	
 
- 	@param	string	string		Chaîne à couper
 
- 	@param	integer	l			Longueur désirée
 
- 	@return	string
 
- 	*/
 
- 	function getPart($string,$l=40)
 
- 	{
 
- 		$res = '';
 
- 		$r = explode(' ',$string);
 
- 		for($i=0;$i<count($r);$i++)
 
- 		{
 
- 			if($i<$l) {
 
- 				$res .= $r[$i].' ';
 
- 			} else {
 
- 				break;
 
- 			}
 
- 		}
 
- 		return $res;
 
- 	}
 
- 	
 
- 	/**
 
- 	@function toXML
 
- 	
 
- 	Renvoie une chaîne propre à être passée dans un fichier XML (entités
 
- 	numériques, etc.). La paramètre $utf8 n'est plus d'aucune utilité.
 
- 	
 
- 	@param	string	string		Chaîne à transformer
 
- 	@param	boolean	utf8			Chaîne en UTF-8 (false)
 
- 	@return	string
 
- 	*/
 
- 	function toXML($string,$utf8=false)
 
- 	{
 
- 		return htmlspecialchars($this->removeEntities($string),ENT_NOQUOTES);
 
- 	}
 
- 	
 
- 	/**
 
- 	@function removeEntities
 
- 	
 
- 	Remplace les entités d'une chaîne par leurs équivalents normaux. Les
 
- 	caractères provenant du jeu de caractère incorect de Windows sont également
 
- 	convertis.
 
- 	
 
- 	Cette méthode utilise la propriété '''encoding''' de la classe et transforme
 
- 	les caractères en UTF-8 si le jeu de caractère est UTF-8.
 
- 	
 
- 	Cette méthode est utilisée par la méthode ''toXML''.
 
- 	
 
- 	@param	string	string		Chaîne à transformer
 
- 	@return	string
 
- 	*/
 
- 	function removeEntities($string)
 
- 	{
 
- 		# Tableau des codes de 130 à 140 et 145 à 156
 
- 		$tags = array('‚' => '‚','ƒ' => 'ƒ','„' => '„',
 
- 		'…' => '…','†' => '†','‡' => '‡','ˆ' => 'ˆ',
 
- 		'‰' => '‰','Š' => 'Š','‹' => '‹','Œ' => 'Œ',
 
- 		'‘' => '‘','’' => '’','“' => '“','”' => '”',
 
- 		'•' => '•','–' => '–','—' => '—','˜' => '˜',
 
- 		'™' => '™','š' => 'š','›' => '›','œ' => 'œ',
 
- 		'Ÿ' => 'Ÿ','€' => '€');
 
- 		
 
- 		$vtags = array(
 
- 		'‚' => '‚','ƒ' => 'ƒ','„' => '„','…' => '…',
 
- 		'†' => '†','‡' => '‡','ˆ' => 'ˆ','‰' => '‰',
 
- 		'Š' => 'Š','‹' => '‹','Œ' => 'Œ','‘' => '‘',
 
- 		'’' => '’','“' => '“','”' => '”','•' => '•',
 
- 		'–' => '–','—' => '—','˜' => '˜','™' => '™',
 
- 		'š' => 'š','›' => '›','œ' => 'œ','Ÿ' => 'Ÿ',
 
- 		'€' => '€');
 
- 		
 
- 		if ($this->encoding == 'UTF-8') {
 
- 			$tags = get_html_translation_table(HTML_ENTITIES);
 
- 			$tags = array_flip($tags);
 
- 			array_walk($tags,create_function('&$v','$v = utf8_encode($v);'));
 
- 			$tags = array_flip($tags);
 
- 			$string = $this->decodeUnicodeEntities($string) ;
 
- 		} else {
 
- 			$tags = array_merge($tags,get_html_translation_table(HTML_ENTITIES));
 
- 		}
 
- 		
 
- 		foreach($tags as $k => $v) {
 
- 			$ASCIItags[$k] = '&#'.ord($k).';';
 
- 		}
 
- 		
 
- 		$string = str_replace($tags,array_flip($tags),$string);
 
- 		$string = str_replace($ASCIItags,array_flip($ASCIItags),$string);
 
- 		$string = str_replace(array_values($vtags),array_keys($vtags),$string);
 
- 		
 
- 		return $string;
 
- 	}
 
- 	
 
- 	
 
- 	function decodeUnicodeEntities($str)
 
- 	{
 
- 		return preg_replace_callback('/&#(\\d+);/',array($this,'code2utf'),$str);
 
- 	}
 
- 	
 
- 	function code2utf($m)
 
- 	{
 
- 		if ($m[1] < 128) {
 
- 			return chr($m[1]);
 
- 		}
 
- 		if ($m[1] < 2048) {
 
- 			return chr(($m[1] >> 6) + 192).chr(($m[1] & 63) + 128);
 
- 		}
 
- 		if ($m[1] < 65536) {
 
- 			return chr(($m[1] >> 12) + 224).chr((($m[1] >> 6) & 63) + 128).
 
- 			chr(($m[1] & 63) + 128);
 
- 		}
 
- 		if ($m[1] < 2097152) {
 
- 			return chr(($m[1] >> 18) + 240).chr((($m[1] >> 12) & 63) + 28).
 
- 			chr((($m[1] >> 6) & 63) + 128).chr(($m[1] & 63) + 128);
 
- 		}
 
- 		return '';
 
- 	}
 
- 	
 
- 	/**
 
- 	@function str2url
 
- 	
 
- 	Transforme la chaîne $str en une chaîne propre à être un élément d'une URL.
 
- 	
 
- 	@param	string	str			Chaîne à transformer
 
- 	@return	string
 
- 	*/
 
- 	function str2url($str)
 
- 	{
 
- 		if ($this->encoding == 'UTF-8') {
 
- 			$str = $this->removeEntities(utf8_decode($str));
 
- 		} else {
 
- 			$str = $this->removeEntities($str);
 
- 		}
 
- 		
 
- 		$str = strtr($str,
 
- 		"ÀÁÂÃÄÅàáâãäåÇçÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûü¾ÝÿýÑñ",
 
- 		"AAAAAAaaaaaaCcOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuYYyyNn");
 
- 		
 
- 		$str = str_replace('Æ','AE',$str);
 
- 		$str = str_replace('æ','ae',$str);
 
- 		$str = str_replace('¼','OE',$str);
 
- 		$str = str_replace('½','oe',$str);
 
- 		
 
- 		$str = preg_replace('/[^a-z0-9_\s\'\:\/\[\]-]/','',strtolower($str));
 
- 		
 
- 		$str = preg_replace('/[\s\'\:\/\[\]-]+/',' ',trim($str));
 
- 	
 
- 		$res = str_replace(' ','-',$str);
 
- 		
 
- 		return $res;
 
- 	}
 
- }
 
- /**
 
- @doc
 
- === Exemples d'utilisation ===
 
- Ces exemples supposent qu'un objet $blog soit une instance de la classe.
 
- ==== Sélection des derniers billets ====
 
- Dans cet exemple, nous sélectionnons les 10 derniers billets du blog dans la
 
- catégorie dont l'ID est 1, puis nous en affichons le titre.
 
- {{{
 
- #!php
 
- <?php
 
- $rs = $blog->getLastNews(10,1);
 
- while ($rs->fetch()) {
 
- 	echo '<p>'.$rs->f('post_titre').'</p>';
 
- }
 
- ?>
 
- }}}
 
- */
 
- ?>
 
 
  |