1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662 |
- <?php
- require_once dirname(__FILE__).'/class.blogpost.php';
- require_once dirname(__FILE__).'/class.blogcomment.php';
- 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;
-
-
-
-
- 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($mode)
- {
- $this->pub_mode = $mode;
- }
-
-
- function setLang($lang)
- {
- $this->lang = $lang;
- }
-
-
- function setDateFormat($d='%A %e %B %Y',$h='%H:%M')
- {
- $this->date_format = $d;
- $this->time_format = $h;
- }
-
-
- function setURL($type,$url)
- {
- $this->front_url[$type] = $url;
- }
-
-
- function resetError()
- {
- $this->error = array();
- }
-
-
- function setError($msg,$no=0)
- {
- $this->error[] = array($no,$msg);
- }
-
-
-
- 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;
- }
- }
-
-
-
-
-
- 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($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($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($id,$level,$pwd,$nom,$prenom,$pseudo,$email,
- $post_format='html',$edit_size=10,$pref_cat=1,$lang='',$delta=0,$post_pub=1)
- {
-
- 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)) {
-
- $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;
- }
-
-
- $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($id,$new_id,$level,$pwd,$nom,$prenom,$pseudo,$email,
- $post_format='html',$edit_size=10,$pref_cat=1,$lang='',$delta=0,$post_pub=1)
- {
-
- 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)).'\',';
- }
-
-
- $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)) {
-
-
- $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($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');
- }
- }
-
-
-
-
-
- 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($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($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);
-
-
- $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($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);
-
-
- $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($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($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($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;
- }
-
-
-
-
-
- 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($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($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($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($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($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($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($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()
- {
- $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($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)
- {
-
- 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 {
-
-
- $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($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)
- {
-
- 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($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).'\' '.
-
- '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($id)
- {
- $updReq = 'UPDATE '.$this->t_post.' SET '.
- 'post_pub = 1-post_pub '.
-
- '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($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()
- {
- if (defined('DC_UPDATE_FILE_W') && DC_UPDATE_FILE_W) {
- files::touch(DC_UPDATE_FILE,time());
- }
- }
-
-
- 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($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);
- }
-
-
-
-
-
- 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($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($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($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($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;
-
-
- 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);
-
-
- $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($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;
-
-
- 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($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($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;
- }
- }
- }
-
-
-
-
-
- function postTbPingURL($post_id,$url,$blog_name,$content='')
- {
-
- $post = $this->getPostByID($post_id);
-
- if ($post->isEmpty()) {
- $this->setError(__('Entry does not exists'),1000);
- return false;
- }
-
-
-
-
-
- $URL = parse_url($url);
- if (empty($URL['scheme']) || $URL['scheme'] != 'http' || empty($URL['path'])) {
- $this->setError('URL invalide',1000);
- return false;
- }
-
-
- $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'] : '';
-
-
- $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);
- }
-
-
- $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
- );
- }
-
-
- if ($http->post($link,$params) === false) {
- $this->setError('HTTP : '.$http->getError(),3000);
- return false;
- }
-
-
- $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;
- }
-
-
- $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 {
-
-
- $this->postPingNotify($post_id,$url);
- return true;
- }
- }
-
-
- 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($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($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);
- }
-
-
-
-
-
- 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()
- {
- $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();
- }
-
-
-
-
-
- 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($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>';
-
- } else {
- return $uri;
- }
- }
-
-
- function secureString($str)
- {
- $str = trim($str);
- $str = stripslashes($str);
- $str = strip_tags($str);
- $str = htmlspecialchars($str);
- return $str;
- }
-
-
- 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($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($string,$utf8=false)
- {
- return htmlspecialchars($this->removeEntities($string),ENT_NOQUOTES);
- }
-
-
- function removeEntities($string)
- {
-
- $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($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;
- }
- }
- ?>
|