Added new functions documentation

* Corrected typos in existing documentation
* Added function documentation for the brand new parser and new functionnalities
* Added examples and better presentation of existing example.

PS: if anybody has an idea for the constant list presentation, i'll be glad, it can be divided in categories. but not available for the moment.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@243665 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
De Cock Xavier 2007-10-05 22:13:33 +00:00
parent 05850f7f97
commit 92282cde5c
6 changed files with 658 additions and 9 deletions

View file

@ -1,5 +1,5 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<section xml:id="bbcode.constants" xmlns="http://docbook.org/ns/docbook">
&reftitle.constants;
&extension.constants;
@ -67,7 +67,7 @@
<listitem>
<simpara>
This BBCode tag require argument sub-parsing (the argument is also parsed by
the BBCode extension).
the BBCode extension). As Of 0.10.2 another parser can be used as argument parser.
</simpara>
</listitem>
</varlistentry>
@ -82,6 +82,197 @@
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_FLAGS_SMILEYS_ON</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This BBCode Tag accepts smileys.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_FLAGS_SMILEYS_OFF</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This BBCode Tag does not accept smileys.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_FLAGS_ONE_OPEN_PER_LEVEL</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This BBCode Tag automatically closes if another tag of
the same type is found at the same nesting level.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_FLAGS_REMOVE_IF_EMPTY</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This BBCode Tag is automatically removed
if content is empty it allows to produce ligther HTML.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_ARG_DOUBLE_QUOTE</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option allowing argument quoting with
double quotes (")
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_ARG_SINGLE_QUOTE</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option allowing argument quoting with
single quotes (')
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_ARG_HTML_QUOTE</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option allowing argument quoting with
HTML version of double quotes (&amp;quot;)
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_AUTO_CORRECT</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option changing the way errors are
treated. It automatically closes tag in the order they
are opened. And treat tags with only an open tag as if
there were a close tag present.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_CORRECT_REOPEN_TAGS</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option changing the way errors are
treated. It automatically reopens tag if close tags are
not in the good order.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_DISABLE_TREE_BUILD</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option disabling the BBCode parsing
it can be useful if only the "smiley" replacement must
be used.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_DEFAULT_SMILEYS_ON</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option setting smileys to ON if no
flag is given at tag level.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_DEFAULT_SMILEYS_OFF</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option setting smileys to OFF if no
flag is given at tag level.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_FORCE_SMILEYS_OFF</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This is a parser option disabling completely the
smileys parsing.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_SET_FLAGS_SET</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This permits to SET the complete flag set on a parser.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_SET_FLAGS_ADD</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This permits to switch a flag set ON on a parser.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>BBCODE_SET_FLAGS_REMOVE</constant>
(<type>integer</type>) - since 0.10.2
</term>
<listitem>
<simpara>
This permits to switch a flag set OFF on a parser.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</section>

View file

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<refentry xml:id="function.bbcode-add-smiley" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bbcode_add_smiley</refname>
<refpurpose>Adds a smiley to the parser</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>bbcode_add_smiley</methodname>
<methodparam><type>resource</type><parameter>bbcode_container</parameter></methodparam>
<methodparam><type>string</type><parameter>smiley</parameter></methodparam>
<methodparam><type>string</type><parameter>replace_by</parameter></methodparam>
</methodsynopsis>
<para>
Adds a smiley to the parser
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>bbcode_container</parameter></term>
<listitem>
<para>
BBCode_Container resource, returned by <function>bbcode_create</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>smiley</parameter></term>
<listitem>
<para>
The string that will be replaced when found.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>replace_by</parameter></term>
<listitem>
<para>
The string that replace smiley when found.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>bbcode_add_smiley</function> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
/*
* Prepare the rule set
*/
$arrayBBCode=array(
''=> array('type'=>BBCODE_TYPE_ROOT,
'childs'=>'!i'),
'b'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<b>',
'close_tag'=>'</b>'),
'u'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<u>',
'close_tag'=>'</u>',
'flags'=>BBCODE_FLAGS_SMILEYS_OFF),
'i'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<i>',
'close_tag'=>'</i>',
'childs'=>'b'),
);
/*
* Parsed Text
*/
$text=<<<EOF
[i] No parse Test [/i] :)
[b] Parsed, with smiley :( [/b]
[u] Parsed, with no smiley :D [/u]
EOF;
/*
* Init the parser
*/
$BBHandler=bbcode_create($arrayBBCode);
/*
* Add Smiley rules to parser
*/
bbcode_add_smiley($BBHandler, ":)", "<img src=\"smiley.gif\" alt=\":)\" />");
bbcode_add_smiley($BBHandler, ":(", "<img src=\"sad.gif\" alt=\":(\" />");
bbcode_add_smiley($BBHandler, ":D", "<img src=\"happy.gif\" alt=\":D\" />");
bbcode_add_smiley($BBHandler, ":p", "<img src=\"tong.gif\" alt=\":p\" />");
bbcode_add_smiley($BBHandler, ":|", "<img src=\"special.gif\" alt=\":|\" />");
bbcode_add_smiley($BBHandler, ":6:", "<img src=\"six.gif\" alt=\":6:\" />");
/*
* Parse the text
*/
echo bbcode_parse($BBHandler,$text);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
[i] No parse Test [/i] <img src="smiley.gif" alt=":)" />
<b> Parsed, with smiley <img src="sad.gif" alt=":(" /> </b>
<u> Parsed, with no smiley :D </u>
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<!-- $Revision: 1.8 $ -->
<refentry xml:id="function.bbcode-create" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bbcode_create</refname>
@ -79,15 +79,15 @@
<listitem>
<simpara>
<varname remap="structfield">childs</varname> optional - List of
accepted childs for the tag. The format of the list is a comma
accepted child for the tag. The format of the list is a comma
separated string. If the list starts with ! it will be the list of
rejected childs for the tag.
rejected Shields for the tag.
</simpara>
</listitem>
<listitem>
<simpara>
<varname remap="structfield">parent</varname> optional - List of
accepted childs for the tag. The format of the list is a comma
accepted childes for the tag. The format of the list is a comma
separated string.
</simpara>
</listitem>

View file

@ -0,0 +1,169 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<refentry xml:id="function.bbcode-set-arg-parser" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bbcode_set_arg_parser</refname>
<refpurpose>Attach another parser in order to use another rule set for argument parsing</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>bbcode_set_arg_parser</methodname>
<methodparam><type>resource</type><parameter>bbcode_container</parameter></methodparam>
<methodparam><type>resource</type><parameter>bbcode_arg_parser</parameter></methodparam>
</methodsynopsis>
<para>
Attaches another parser to the bbcode_container.
This parser is used only when arguments must be parsed.
If this function is not used, the default argument parser
is the parser itself.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>bbcode_container</parameter></term>
<listitem>
<para>
BBCode_Container resource, returned by <function>bbcode_create</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>bbcode_arg_parser</parameter></term>
<listitem>
<para>
BBCode_Container resource, returned by <function>bbcode_create</function>.
It will be used only for parsed arguments
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>bbcode_set_arg_parser</function> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
/*
* Generating bbcode ruleset for main parser
*/
$arrayBBCode=array(
'quote'=> array('type'=>BBCODE_TYPE_ARG,
'open_tag'=>'<quote><h4>Source: {PARAM}</h4>',
'close_tag'=>'</quote>',
'flags'=>BBCODE_FLAGS_REMOVE_IF_EMPTY|BBCODE_FLAGS_ARG_PARSING),
'b'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<b>', 'close_tag'=>'</b>',
'flags'=>BBCODE_FLAGS_REMOVE_IF_EMPTY),
'u'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<u>', 'close_tag'=>'</u>',
'flags'=>BBCODE_FLAGS_SMILEYS_OFF | BBCODE_FLAGS_REMOVE_IF_EMPTY | BBCODE_FLAGS_SMILEYS_OFF),
'i'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<i>', 'close_tag'=>'</i>',
'flags'=>BBCODE_FLAGS_REMOVE_IF_EMPTY),
);
/*
* Generating bbcode ruleset for argument parser
*/
$arrayBBCode_arg=array(
'b'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<b class="sub">', 'close_tag'=>'</b>',
'flags'=>BBCODE_FLAGS_REMOVE_IF_EMPTY),
'u'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<u>', 'close_tag'=>'</u>',
'flags'=>BBCODE_FLAGS_SMILEYS_OFF | BBCODE_FLAGS_REMOVE_IF_EMPTY | BBCODE_FLAGS_SMILEYS_OFF),
'i'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<i>', 'close_tag'=>'</i>',
'flags'=>BBCODE_FLAGS_REMOVE_IF_EMPTY),
);
/*
* Text we are going to parse
*/
$text=<<<EOF
[quote="[b]Test[/b]"]
Foo :)
[/quote]
[b]Bar example :)[/b] :)
EOF;
/*
* Init the two parsers
*/
$BBHandler=bbcode_create($arrayBBCode);
$BBArgHandler=bbcode_create($arrayBBCode_arg);
/*
* Setting Flags on the parsers
*/
bbcode_set_flags($BBHandler,
BBCODE_CORRECT_REOPEN_TAGS|BBCODE_DEFAULT_SMILEYS_ON|BBCODE_ARG_DOUBLE_QUOTE|
BBCODE_ARG_SINGLE_QUOTE|BBCODE_ARG_HTML_QUOTE,BBCODE_SET_FLAGS_SET);
bbcode_set_flags($BBArgHandler,
BBCODE_CORRECT_REOPEN_TAGS|BBCODE_DEFAULT_SMILEYS_ON|BBCODE_ARG_DOUBLE_QUOTE|
BBCODE_ARG_SINGLE_QUOTE|BBCODE_ARG_HTML_QUOTE,BBCODE_SET_FLAGS_SET);
/*
* Setting $BBArgHandler as the BBHandler argument parser
*/
bbcode_set_arg_parser($BBHandler,$BBArgHandler);
/*
* Adding Smileys handling rules to Main parser
*/
bbcode_add_smiley($BBHandler, ":)", "<img src=\"smiley.gif\" alt=\":)\" />");
/*
* Use the main parser to parse text
*/
echo bbcode_parse($BBHandler,$text);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
<quote><h4>Source: <b class="sub">Test</b></h4>
Foo <img src="smiley.gif" alt=":)" />
</quote>
<b>Bar example :)</b> <img src="smiley.gif" alt=":)" />
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<refentry xml:id="function.bbcode-set-flags" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>bbcode_set_flags</refname>
<refpurpose>Set or alter parser options</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>bbcode_set_flags</methodname>
<methodparam><type>resource</type><parameter>bbcode_container</parameter></methodparam>
<methodparam><type>int</type><parameter>flags</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>mode</parameter></methodparam>
</methodsynopsis>
<para>
Set or alter parser options
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>bbcode_container</parameter></term>
<listitem>
<para>
BBCode_Container resource, returned by <function>bbcode_create</function>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
The flag set that must be applied to the bbcode_container options
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>mode</parameter></term>
<listitem>
<para>
One of the BBCODE_SET_FLAGS_* constant to set, unset
a specific flag set or to replace the flag set by flags.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>bbcode_set_flags</function> usage example</title>
<programlisting role="php">
<![CDATA[
<?php
/*
* Preparing RuleSet
*/
$arrayBBCode=array(
'b'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<b>', 'close_tag'=>'</b>'),
'u'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<u>', 'close_tag'=>'</u>'),
'i'=> array('type'=>BBCODE_TYPE_NOARG,
'open_tag'=>'<i>', 'close_tag'=>'</i>'),
);
/*
* Paired incorrectly nested BBCode
*/
$text="[i] Parser [b] Auto Correction [/i] at work [/b]\n";
$BBHandler=bbcode_create($arrayBBCode);
echo bbcode_parse($BBHandler,$text);
// Enabling reopening of automaticaly closed elements
bbcode_set_flags($BBHandler,BBCODE_CORRECT_REOPEN_TAGS,
BBCODE_SET_FLAGS_SET);
echo bbcode_parse($BBHandler,$text);
/*
* Unpaired incorrectly nested BBCode
*/
$text="[i] Parser [b] Auto Correction [/i] at work\n";
echo bbcode_parse($BBHandler,$text);
// Enabling automatic close of pending tags
bbcode_set_flags($BBHandler,
BBCODE_CORRECT_REOPEN_TAGS|BBCODE_AUTO_CORRECT,
BBCODE_SET_FLAGS_SET);
echo bbcode_parse($BBHandler,$text);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
<i> Parser <b> Auto Correction </b></i> at work
<i> Parser <b> Auto Correction </b></i><b> at work </b>
<i> Parser [b] Auto Correction </i> at work
<i> Parser <b> Auto Correction </b></i><b> at work
</b>
]]>
</screen>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<!-- $Revision: 1.4 $ -->
<!-- Membership: external, pecl -->
<reference xml:id="ref.bbcode" xmlns="http://docbook.org/ns/docbook">
<title>BBCode Functions</title>
@ -15,9 +15,9 @@
approach based on regular expressions. Further more, it helps provide
valid HTML by reordering open / close tags and by automatically closing
unclosed tags.
</para><para>
Since 0.10.1 It supports argument quoting with single quotes,
double quotes and html escaped double quotes.
double quotes and HTML escaped double quotes.
</para>
</section>