phpBB

Development Wiki

Tutorial.Parsing text

From phpBB Development Wiki

Revision as of 12:03, 14 June 2007 by JziZgi (Talk | contribs)

cheap zanaflex diazepam online verizon ringtones free motorola ringtones lortab online prozac online free ericsson ringtones ortho cheap cyclobenzaprine celexa online free free ringtones phentermine cool ringtones prozac online free qwest ringtones cheap cialis sprint ringtones cheap nexium free real ringtones sagem ringtones free tracfone ringtones free nokia ringtones punk ringtones mp3 ringtones free sony ringtones buy ativan but hgh free midi ringtones free alltel ringtones flexeril online sony ericsson ringtones motorola ringtones vicodin online free tracfone ringtones soma online levitra online free motorola ringtones didrex online cheap sildenafil pharmacy online online zoloft online hydrocodone online free sony ringtones free cingular ringtones viagra buy paxil ambien online buy lortab cheap hydrocodone cheap vigrx cheap ativan hgh online cheap sildenafil viagra online buy ortho nextel ringtones lisinopril online funny ringtones sony ericsson ringtones buy vicodin but hydrocodone ativan online mono ringtones clonazepam levitra sprint ringtones cheap cialis free sony ringtones cheap levitra zanaflex online but phentermine celexa online cheap ultracet wwe ringtones sharp ringtones norco online soma ultracet online free cingular ringtones adipex online cheap xenical order albuterol cheap tenuate ortho online free music ringtones free sagem ringtones lisinopril online cheap meridia cheap propecia order vigrx diethylpropion online cheap albuterol mp3 ringtones cheap meridia free free ringtones cheap ultram cheap soma lortab online cheap sildenafil free nextel ringtones cheap lorazepam funny ringtones diethylpropion online free ringtones free funny ringtones cingular ringtones cheap soma nokia ringtones clonazepam online cheap zyban cheap clomid prozac online online valium lisinopril online cheap meridia tramadol online free sharp ringtones midi ringtones flexeril online free real ringtones cheap celexa zoloft online free nextel ringtones ericsson ringtones free music ringtones mtv ringtones ultram online buy valium viagra online order lorazepam cheap cialis phentermine online buy nexium samsung ringtones cheap norco meridia online sprint ringtones rivotril online carisoprodol online carisoprodol online buy cyclobenzaprine qwest ringtones qwest ringtones cheap fioricet free verizon ringtones free punk ringtones cheap hoodia cheap pharmacy online tracfone ringtones online tramadol rivotril online cheap tramadol cheap didrex cheap fioricet free music ringtones albuterol online free nokia ringtones viagra online alprazolam online xenical online pharmacy online online free funny ringtones zanaflex online ericsson ringtones cheap cyclobenzaprine adipex online xanax online free alltel ringtones qwest ringtones ultram online free sonyericsson ringtones samsung ringtones lortab online free mono ringtones free samsung ringtones zyban online celexa online free funny ringtones free wwe ringtones rivotril online clomid fioricet online hgh online cheap lipitor cheap hoodia clonazepam free cool ringtones cheap tenuate cheap vicodin free real ringtones free sonyericsson ringtones hoodia online tramadol online nextel ringtones alprazolam online ambien online mono ringtones sonyericsson ringtones sony ericsson ringtones ambien online == 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_urls'       => $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;

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.

$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'];