phpBB

Development Wiki

Difference between revisions of "Tutorial.Parsing text"

From phpBB Development Wiki

m
(Edits from Confluence)
 
(17 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[http://helmed.info/topic/reti-di/ reti di calcolatori] [http://helmed.info/topic/case-in/ case in vendita a giussago] [http://ustall.org/web/trust-optical.htm trust optical usb mouse] [http://davte.info/library/html/l-isola.htm l isola che non c e bennato] [http://kinunia.cn/belinea.htm belinea 10 19 15] [http://helmed.info/topic/utility-installer/ utility installer] [http://amohseni.info/img/styles/midi-easy/ midi easy lady] [http://ashythro.info/library/html/lego-avventure/ lego avventure] [http://nobinters.org/musulman.htm musulman] [http://ustall.org/web/mp-del.htm mp3 del gladiatore] [http://ustall.org/web/emp-tw.htm emp tw20] [http://ustall.org/web/documentari.htm documentari] [http://chaba.info/aggiornamento-veloce/ aggiornamento veloce sulle tecnologie degli attual] [http://bloprofeldi.info/lib/navman-gold.htm navman gold] [http://saibso.org/in-.htm in  hotel] [http://saibso.org/le-zoo.htm le zoo] [http://nobinters.org/claudia-koll.htm claudia koll in cosi fan tutte] [http://kinunia.cn/pentium-dual.htm pentium dual core] [http://saibso.org/fotocopiatrice-scanner.htm fotocopiatrice scanner stampante a3] [http://saibso.org/th-pve.htm th 42pv500e] [http://kinunia.cn/dmlp.htm dmlp] [http://saibso.org/file-midi.htm file midi alice] [http://bloprofeldi.info/lib/lavoro-nice.htm lavoro nice] [http://saibso.org/video-di.htm video di britney spears] [http://helmed.info/topic/televisore-/ televisore 32 kv-32fq86] [http://nobinters.org/video-parno.htm video parno] [http://amohseni.info/img/styles/janet-jackson/ janet jackson] [http://nobinters.org/bmw-i.htm bmw 328i] [http://kinunia.cn/notebook-processore.htm notebook processore centrino] [http://kinunia.cn/volkswagen-golf.htm volkswagen golf gti to] [http://chaba.info/bubble-jet/ bubble jet i6500] [http://nobinters.org/digitale-orologi.htm digitale orologi] [http://helmed.info/topic/north-sails/ north sails occhiali] [http://davte.info/library/html/philips-telecomando.htm philips telecomando universale] [http://davte.info/library/html/intel-pentium.htm intel pentium extreme edition] [http://saibso.org/brahams-hungarian.htm brahams hungarian] [http://ustall.org/web/without-you.htm without you harry nilsson] [http://saibso.org/god-save.htm god save] [http://kinunia.cn/hymn-to.htm hymn to october red] [http://davte.info/library/html/email-virus.htm email virus] [http://amohseni.info/img/styles/schongau/ schongau] [http://helmed.info/topic/cartina-geografica/ cartina geografica toscana] [http://psisemiya.com/images/small/viera/ viera 42] [http://nobinters.org/incontri-gratis.htm incontri gratis piemonte] [http://kinunia.cn/rata-mutuo.htm rata mutuo] [http://chaba.info/tell-him/ tell him vonda shepard] [http://helmed.info/topic/malaluna/ malaluna] [http://kinunia.cn/sony-kvct.htm sony kv-14ct1] [http://amohseni.info/img/styles/villaggio-turistico/ villaggio turistico al mare] [http://helmed.info/topic/auto-noleggio/ auto noleggio messina] [http://psisemiya.com/images/small/loewe-xelos/ loewe xelos lcd 26] [http://amohseni.info/img/styles/hp/ hp 8200] [http://davte.info/library/html/quam-mirabilis.htm quam mirabilis] [http://saibso.org/vacanza-lavoro.htm vacanza lavoro] [http://amohseni.info/img/styles/its-a/ its a kind of magic] [http://amohseni.info/img/styles/gary-oldman/ gary oldman foto] [http://nobinters.org/wolfgang-amadeus.htm wolfgang amadeus mozart il flauto] [http://helmed.info/topic/diffusori-da/ diffusori da esterno] [http://kinunia.cn/leccami.htm leccami] [http://helmed.info/topic/www-mls/ www mls com] [http://ashythro.info/library/html/zafferano-bicchieri/ zafferano bicchieri] [http://ustall.org/web/zoran-jelenkovic.htm zoran jelenkovic] [http://amohseni.info/img/styles/tv-studio/ tv studio pctv] [http://bloprofeldi.info/lib/ati-fire.htm ati fire] [http://chaba.info/incanto-classic/ incanto classic saeco] [http://bloprofeldi.info/lib/risultati-motomondiale.htm risultati motomondiale 2004] [http://chaba.info/km-mitsubishi/ km0 mitsubishi pajero sport auto km 0] [http://bloprofeldi.info/lib/schede-madri.htm schede madri asus p4p800s] [http://saibso.org/sigma.htm sigma 12-24] [http://nobinters.org/sn-una.htm sn una tettona] [http://saibso.org/cittadinanza.htm cittadinanza] [http://psisemiya.com/images/small/canon-lbp/ canon lbp 2000 toner] [http://davte.info/library/html/microfono-ps.htm microfono ps2] [http://saibso.org/chi-ha.htm chi ha vinto piu coppe al mondo calcio] [http://ustall.org/web/dinotopia.htm dinotopia] [http://chaba.info/tablet-pc/ tablet pc 12 1 hp] [http://psisemiya.com/images/small/manifesto-ringraziamenti/ manifesto ringraziamenti] [http://chaba.info/fiat-coupe/ fiat coupe 1 8 turbo] [http://nobinters.org/nh-hotel.htm nh hotel] [http://bloprofeldi.info/lib/chacker.htm chacker] [http://ustall.org/web/soho-square.htm soho square] [http://ashythro.info/library/html/erikson-e/ erikson e la crisi psico sociale] [http://ustall.org/web/gioco-all.htm gioco all aperto bambino] [http://davte.info/library/html/minolta-toner.htm minolta toner] [http://nobinters.org/cuffie-wireless.htm cuffie wireless dolby digital] [http://helmed.info/topic/il-libro/ il libro della] [http://chaba.info/aldo-giovanni/ aldo giovanni e giacomo] [http://psisemiya.com/images/small/volo-aereo/ volo aereo palermo lampedusa] [http://helmed.info/topic/iraq/ iraq] [http://ustall.org/web/fotos-ivy.htm fotos ivy queen] [http://ustall.org/web/loona-bailando.htm loona bailando] [http://chaba.info/pulitore-vapore/ pulitore vapore] [http://psisemiya.com/images/small/smallville-kristin/ smallville kristin kreuk nuda] [http://psisemiya.com/images/small/fax-l/ fax 3310l] [http://saibso.org/prestito-bruxelles.htm prestito bruxelles] [http://kinunia.cn/bepi-koelliker.htm bepi koelliker] [http://saibso.org/regali-per.htm regali per casa] [http://amohseni.info/img/styles/dpr-/ dpr 686 del 3 5 1957] [http://helmed.info/topic/yety-sport/ yety sport 5] [http://helmed.info/topic/rrufeja/ rrufeja] [http://bloprofeldi.info/lib/toyota-mantova.htm toyota mantova] [http://nobinters.org/velodyne-vx.htm velodyne vx10] [http://saibso.org/camera-villorba.htm camera villorba] [http://ashythro.info/library/html/www-canzoni/ www canzoni di leone di lernia it] [http://kinunia.cn/foto-camera.htm foto camera digitale online] [http://amohseni.info/img/styles/olimpia-splendid/ olimpia splendid deumidificatore] [http://amohseni.info/img/styles/batterie-samsung/ batterie samsung e800] [http://kinunia.cn/ecco.htm ecco] [http://helmed.info/topic/i-cieli/ i cieli del mito libri] [http://bloprofeldi.info/lib/casper-slide.htm casper slide] [http://ustall.org/web/la-macchina.htm la macchina nera] [http://bloprofeldi.info/lib/kingston-ddr.htm kingston ddr sodimm] [http://helmed.info/topic/fromage-frais/ fromage frais] [http://nobinters.org/invernali.htm invernali] [http://nobinters.org/ninne-nanne.htm ninne nanne in italiano] [http://amohseni.info/img/styles/esce-il/ esce il drago entra la tigre] [http://psisemiya.com/images/small/peretta/ peretta] [http://chaba.info/volkswagen-fox/ volkswagen fox diesel] [http://kinunia.cn/dori-ghezzi.htm dori ghezzi wess] [http://psisemiya.com/images/small/cantautore/ cantautore] [http://saibso.org/garmin-gps.htm garmin gps iii] [http://ustall.org/web/seks-vidoe.htm seks vidoe] [http://helmed.info/topic/corpi/ corpi] [http://davte.info/library/html/vogliamoci-tanto.htm vogliamoci tanto bene] [http://ustall.org/web/lalbero-delle.htm lalbero delle pere] [http://amohseni.info/img/styles/the-biggest/ the biggest black cock] [http://saibso.org/un-grande.htm un grande amore] [http://amohseni.info/img/styles/picrite/ picrite] [http://bloprofeldi.info/lib/star-wars.htm star wars. clone wars. vol. 01] [http://kinunia.cn/jogos-da.htm jogos da playboy] [http://saibso.org/nike-calcio.htm nike calcio] [http://chaba.info/ecco-la/ ecco la demo di age of empires iii] [http://amohseni.info/img/styles/la-camera/ la camera della morte] [http://ustall.org/web/terratec-aureon.htm terratec aureon universe 7 1] [http://saibso.org/dvdrw-.htm dvd-rw 9 4 gb] [http://psisemiya.com/images/small/internet-a/ internet a passo di lumaca] [http://ashythro.info/library/html/piastra-per/ piastra per bistecchiera] [http://saibso.org/piscina-di.htm piscina di antegnate] [http://amohseni.info/img/styles/appendici-carrelli/ appendici carrelli] [http://nobinters.org/www-lady.htm www lady web it] [http://ashythro.info/library/html/guri-quarta/ guri quarta serie speciale 13 dicembre 2] [http://psisemiya.com/images/small/hub-/ hub 5 porte ethernet] [http://davte.info/library/html/rod.htm rod] [http://bloprofeldi.info/lib/usted-de.htm usted de diego torres] [http://psisemiya.com/images/small/olivetti-logos/ olivetti logos 682 s] [http://helmed.info/topic/piatti-in/ piatti in vetro] [http://psisemiya.com/images/small/trottolino/ trottolino] [http://helmed.info/topic/hp/ hp 200] [http://chaba.info/todo-lo/ todo lo que hago lo hago por ti] [http://kinunia.cn/sale-marino.htm sale marino integrale] [http://chaba.info/testo-voglia/ testo voglia di dance all night] [http://nobinters.org/kit-cp.htm kit cp 100] [http://psisemiya.com/images/small/film-erotici/ film erotici] [http://bloprofeldi.info/lib/helena-figo.htm helena figo sexy] [http://helmed.info/topic/orbs/ orbs] [http://psisemiya.com/images/small/athlon/ athlon 64 939 3000] [http://ashythro.info/library/html/pieces-de/ pieces de rechange] [http://chaba.info/processori-intel/ processori intel pentium 4 prescott] [http://davte.info/library/html/foto-naziskin.htm foto naziskin] [http://kinunia.cn/tocuh.htm tocuh] [http://ashythro.info/library/html/santo-antonio/ santo antonio] [http://saibso.org/pisa-san.htm pisa san francisco biglietti aerei] [http://davte.info/library/html/gamepad-pc.htm gamepad pc saitek] [http://bloprofeldi.info/lib/tarantelle-pugliesi.htm tarantelle pugliesi] [http://davte.info/library/html/breezin.htm breezin] [http://kinunia.cn/gamepad-joystick.htm gamepad joystick] [http://davte.info/library/html/hotel-centrale.htm hotel centrale jesolo] [http://bloprofeldi.info/lib/fotos-garotas.htm fotos garotas nuas] [http://kinunia.cn/navigatore-gps.htm navigatore gps blaupunkt] [http://davte.info/library/html/grimaudo.htm grimaudo] [http://helmed.info/topic/piastre-intercambiabili/ piastre intercambiabili] [http://saibso.org/cranberries-zombi.htm cranberries zombi] [http://davte.info/library/html/chat-gay.htm chat gay roma gratis] [http://kinunia.cn/bey.htm bey] [http://amohseni.info/img/styles/usb-sharp/ usb sharp gx30] [http://kinunia.cn/extremo.htm extremo] [http://psisemiya.com/images/small/mina-in/ mina in studio] [http://kinunia.cn/audi-a.htm audi a3 1.6] [http://ashythro.info/library/html/calciatore-nudo/ calciatore nudo] [http://psisemiya.com/images/small/lampade-risparmio/ lampade risparmio energetico] [http://helmed.info/topic/handel-cd/ handel cd] [http://chaba.info/logitech-premium/ logitech premium usb headset 350] [http://amohseni.info/img/styles/kuman/ kuman] [http://nobinters.org/mi-manchi.htm mi manchi pooh] [http://davte.info/library/html/dvd-x.htm dvd 8x princo] [http://ashythro.info/library/html/yonis/ yonis] [http://davte.info/library/html/musica-per.htm musica per i tuoi sogni] [http://ustall.org/web/pirandello-l.htm pirandello l esclusa] [http://amohseni.info/img/styles/piscine-montichiari/ piscine montichiari] [http://psisemiya.com/images/small/rex-rd/ rex rd 185 dx] [http://saibso.org/wwwpetardas-con.htm wwwpetardas con] [http://davte.info/library/html/cardim-fernao.htm cardim, fernao] [http://saibso.org/set-lettino.htm set lettino] [http://bloprofeldi.info/lib/bando-straordinario.htm bando straordinario 19 12 2005 servizio civile] [http://kinunia.cn/silke.htm silke] [http://nobinters.org/www-google.htm www google ro] [http://davte.info/library/html/europa-grecia.htm europa grecia isola] [http://kinunia.cn/ibm-t.htm ibm t43] [http://chaba.info/foto-di/ foto di pantere] [http://chaba.info/www-robertobaggio/ www robertobaggio it] == Parsing text with BBCodes, smilies etc. ==
+
== Database fields ==
 +
phpBB3 uses the following database fields where BBCode is allowed (forum description, forum rules, post content, ...):
 +
* '''foo''' - the text itself
 +
* '''foo_bbcode_uid''' - a randomly generated unique identifier to mark the bbcodes identified by the first pass encoding (which uses regular expressions) so they can be replaced using the quicker str_replace in the second pass.
 +
* '''foo_bbcode_bitfield''' - a [[wikipedia:Bit field|bit field]] containing the information which bbcode is used in the text so only the relavant ones need to be loaded from the database.
 +
* '''foo_options''' - a bit field containing the information whether bbcode, smilies and magic urls are enabled (OPTION_FLAG_BBCODE, OPTION_FLAG_SMILIES and OPTION_FLAG_LINKS). Sometimes you will find this separated into enable_bbcode, enable_smilies and enable_magic_url
 +
 
 +
column names vary from table to table.
 +
 
 +
== Parsing text with BBCodes, smilies etc. ==
  
 
=== Inserting text to the DB ===
 
=== Inserting text to the DB ===
Line 33: Line 42:
 
     'bbcode_bitfield'  => $bitfield,
 
     'bbcode_bitfield'  => $bitfield,
 
     'enable_bbcode'    => $allow_bbcode,
 
     'enable_bbcode'    => $allow_bbcode,
     'enable_urls'       => $allow_urls,
+
     'enable_magic_url' => $allow_urls,
 
     'enable_smilies'    => $allow_smilies,
 
     'enable_smilies'    => $allow_smilies,
 
);
 
);
Line 43: Line 52:
  
 
=== Displaying text downloaded from DB ===
 
=== Displaying text downloaded from DB ===
This example uses the bbcode_options field which is used in forums and groups description parsing.
+
This example uses the bbcode_options field which is used in forums and groups description parsing:
 
<php>
 
<php>
 
$sql = 'SELECT text, bbcode_uid, bbcode_bitfield, bbcode_options
 
$sql = 'SELECT text, bbcode_uid, bbcode_bitfield, bbcode_options
Line 56: Line 65:
 
</php>
 
</php>
  
This uses the enable_bbcode, enable_smilies and enable_magic_url flags which can be used instead of the above method and is used in parsing posts.
+
 
 +
The next one uses the enable_bbcode, enable_smilies and enable_magic_url flags which can be used instead of the above method and is used in parsing posts:
 
<php>
 
<php>
 
$sql = 'SELECT text, bbcode_uid, bbcode_bitfield, enable_bbcode, enable_smilies, enable_magic_url
 
$sql = 'SELECT text, bbcode_uid, bbcode_bitfield, enable_bbcode, enable_smilies, enable_magic_url
Line 64: Line 74:
 
$db->sql_freeresult($result);
 
$db->sql_freeresult($result);
  
$row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0)
+
$row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) +
     (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0)  
+
     (($row['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) +
 
     (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
 
     (($row['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
 
$text = generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
 
$text = generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
Line 85: Line 95:
 
echo $row['text'];
 
echo $row['text'];
 
</php>
 
</php>
 +
 +
=== The database options to use for the fields ===
 +
<highlightSyntax language="sqlnew">
 +
`bbcode_bitfield` varchar(255) collate utf8_bin NOT NULL default '',
 +
`bbcode_uid` varchar(8) collate utf8_bin NOT NULL,
 +
`bbcode_options` mediumint(4) collate utf8_bin NOT NULL,
 +
</highlightSyntax>
 
{{tutorial-stub}}
 
{{tutorial-stub}}
 +
<br>
 +
==See Also==
 +
* [[Strip_bbcode]]
 +
* [[Generate_text_for_display]]
 +
* [[Generate_text_for_storage]]
 +
<br>
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
[[Category:API]]
 
[[Category:API]]
 +
[[Category:BBCode]]

Latest revision as of 14:29, 13 February 2011

Database fields

phpBB3 uses the following database fields where BBCode is allowed (forum description, forum rules, post content, ...):

  • foo - the text itself
  • foo_bbcode_uid - a randomly generated unique identifier to mark the bbcodes identified by the first pass encoding (which uses regular expressions) so they can be replaced using the quicker str_replace in the second pass.
  • foo_bbcode_bitfield - a bit field containing the information which bbcode is used in the text so only the relavant ones need to be loaded from the database.
  • foo_options - a bit field containing the information whether bbcode, smilies and magic urls are enabled (OPTION_FLAG_BBCODE, OPTION_FLAG_SMILIES and OPTION_FLAG_LINKS). Sometimes you will find this separated into enable_bbcode, enable_smilies and enable_magic_url

column names vary from table to table.

Parsing text with BBCodes, smilies etc.

Inserting text to the DB

$text utf8_normalize_nfc(request_var('text'''true));
$uid $bitfield $options ''// will be modified by generate_text_for_storage
$allow_bbcode $allow_urls $allow_smilies true;
generate_text_for_storage($text$uid$bitfield$options$allow_bbcode$allow_urls$allow_smilies);

$sql_ary = array(
    
'text'              => $text,
    
'bbcode_uid'        => $uid,
    
'bbcode_bitfield'   => $bitfield,
    
'bbcode_options'    => $options,
);

$sql 'INSERT INTO ' YOUR_TABLE ' ' $db->sql_build_array('INSERT'$sql_ary);
$db->sql_query($sql);

The above method uses the bbcode options database field which is used in many places instead of enable_smiles, enable_bbcode and enable_magic_url

Here is how to insert it into the database using the enable_smilies, enable_bbcode and enable_magic_url tables

$text utf8_normalize_nfc(request_var('text'''true));
$uid $bitfield $options ''// will be modified by generate_text_for_storage
$allow_bbcode $allow_urls $allow_smilies true;
generate_text_for_storage($text$uid$bitfield$options$allow_bbcode$allow_urls$allow_smilies);

$sql_ary = array(
    
'text'              => $text,
    
'bbcode_uid'        => $uid,
    
'bbcode_bitfield'   => $bitfield,
    
'enable_bbcode'     => $allow_bbcode,
    
'enable_magic_url'  => $allow_urls,
    
'enable_smilies'    => $allow_smilies,
);

$sql 'INSERT INTO ' YOUR_TABLE ' ' $db->sql_build_array('INSERT'$sql_ary);
$db->sql_query($sql);

Displaying text downloaded from DB

This example uses the bbcode_options field which is used in forums and groups description parsing:

$sql 'SELECT text, bbcode_uid, bbcode_bitfield, bbcode_options
    FROM ' 
YOUR_TABLE;
$result $db->sql_query($sql);
$row $db->sql_fetchrow($result);
$db->sql_freeresult($result);

$text generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);

echo 
$text;


The next one uses the enable_bbcode, enable_smilies and enable_magic_url flags which can be used instead of the above method and is used in parsing posts:

$sql 'SELECT text, bbcode_uid, bbcode_bitfield, enable_bbcode, enable_smilies, enable_magic_url
    FROM ' 
YOUR_TABLE;
$result $db->sql_query($sql);
$row $db->sql_fetchrow($result);
$db->sql_freeresult($result);

$row['bbcode_options'] = (($row['enable_bbcode']) ? OPTION_FLAG_BBCODE 0) +
    ((
$row['enable_smilies']) ? OPTION_FLAG_SMILIES 0) + 
    ((
$row['enable_magic_url']) ? OPTION_FLAG_LINKS 0);
$text generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);

echo 
$text;

Generating text for editing

$sql 'SELECT text, bbcode_uid
    FROM ' 
YOUR_TABLE;
$result $db->sql_query_limit($sql1);
$row $db->sql_fetchrow($result);
$db->sql_freeresult($result);

decode_message($row['text'], $row['bbcode_uid']);

echo 
$row['text'];

The database options to use for the fields


`bbcode_bitfield` varchar(255) collate utf8_bin NOT NULL default '',
`bbcode_uid` varchar(8) collate utf8_bin NOT NULL,
`bbcode_options` mediumint(4) collate utf8_bin NOT NULL,


See Also