Buenas a todos,
no se si esto va a aquí, estoy recién comenzando en SMF. La cosa es que quería añadir un BBCODE propio, y en el archivo Subs.php he añadido lo siguiente:
array(
'tag' => 'personal',
'type' => 'unparsed_content',
'parameters' => array(
'id' => array('optional' => false),
),
'content' => '<div id="{id}" style="visibility:hidden;display:none">[b]$1[/b]</div>',
'block_level' => 'true',
),
Con $1 se recupera el contenido que vaya entre [personal][/personal], pero quisiera hacerle un strip_tags a ese contenido, puesto que me convierte las comillas y otros caracteres a su código de html, cosa que no quiero. Quieor que se respete tal cual.
Aparte de esto, quizás sería mejor que me hiciese un plugin o una función propia, pero no sé por donde empezar. Si me pasan el link de algún tutorial se lo agradezco.
Muchas gracias, un saludo!!
Edito: No es un strip_tags, la cosa sería poder aplicarle un filtro php a ese $1 que es el contenido.
puedes crear tu propia funcion para validar el bbc mediante:
'validate' => create_function('&$tag, &$data, $disabled', '
tu código para validar el bbc '),
suponiendo que usas 2.0 revisa el principio donde se defienen los botones:
/* The following bbc are formatted as an array, with keys as follows:
ahi te dan ejemplos de lo que puedes hacer:
type: one of...
- (missing): [tag]parsed content[/tag]
- unparsed_equals: [tag=xyz]parsed content[/tag]
- parsed_equals: [tag=parsed data]parsed content[/tag]
- unparsed_content: [tag]unparsed content[/tag]
- closed: [tag], [tag/], [tag /]
- unparsed_commas: [tag=1,2,3]parsed content[/tag]
- unparsed_commas_content: [tag=1,2,3]unparsed content[/tag]
- unparsed_equals_content: [tag=...]unparsed content[/tag]
parameters: an optional array of parameters, for the form
[tag abc=123]content[/tag]. The array is an associative array
where the keys are the parameter names, and the values are an
array which may contain the following:
- match: a regular expression to validate and match the value.
- quoted: true if the value should be quoted.
- validate: callback to evaluate on the data, which is $data.
- value: a string in which to replace $1 with the data.
either it or validate may be used, not both.
- optional: true if the parameter is optional.
test: a regular expression to test immediately after the tag's
'=', ' ' or ']'. Typically, should have a \] at the end.
Optional.
content: only available for unparsed_content, closed,
unparsed_commas_content, and unparsed_equals_content.
$1 is replaced with the content of the tag. Parameters
are replaced in the form {param}. For unparsed_commas_content,
$2, $3, ..., $n are replaced.
before: only when content is not used, to go before any
content. For unparsed_equals, $1 is replaced with the value.
For unparsed_commas, $1, $2, ..., $n are replaced.
after: similar to before in every way, except that it is used
when the tag is closed.
disabled_content: used in place of content when the tag is
disabled. For closed, default is '', otherwise it is '$1' if
block_level is false, '<div>$1</div>' elsewise.
disabled_before: used in place of before when disabled. Defaults
to '<div>' if block_level, '' if not.
disabled_after: used in place of after when disabled. Defaults
to '</div>' if block_level, '' if not.
block_level: set to true the tag is a "block level" tag, similar
to HTML. Block level tags cannot be nested inside tags that are
not block level, and will not be implicitly closed as easily.
One break following a block level tag may also be removed.
trim: if set, and 'inside' whitespace after the begin tag will be
removed. If set to 'outside', whitespace after the end tag will
meet the same fate.
validate: except when type is missing or 'closed', a callback to
validate the data as $data. Depending on the tag's type, $data
may be a string or an array of strings (corresponding to the
replacement.)
quoted: when type is 'unparsed_equals' or 'parsed_equals' only,
may be not set, 'optional', or 'required' corresponding to if
the content may be quoted. This allows the parser to read
[tag="abc]def[esdf]"] properly.
require_parents: an array of tag names, or not set. If set, the
enclosing tag *must* be one of the listed tags, or parsing won't
occur.
require_children: similar to require_parents, if set children
won't be parsed if they are not in the list.
disallow_children: similar to, but very different from,
require_children, if it is set the listed tags will not be
parsed inside the tag.
parsed_tags_allowed: an array restricting what BBC can be in the
parsed_equals parameter, if desired.
Y esto no sirve?
http://www.simplemachines.org/community/index.php?topic=387440.0
me parece que el ya sabe como crearlo, lo que necesita es una funcion para validar su contenido o en dado caso que el contenido no sea parseado, para eso sirve el parámetro "validate" por ejemplo el validate del tag code:
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
global $context;
if (!isset($disabled[\'code\']))
{
$php_parts = preg_split(\'~(<\?php|\?>)~\', $data, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
{
// Do PHP code coloring?
if ($php_parts[$php_i] != \'<?php\')
continue;
$php_string = \'\';
while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != \'?>\')
{
$php_string .= $php_parts[$php_i];
$php_parts[$php_i++] = \'\';
}
$php_parts[$php_i] = highlight_php_code($php_string . $php_parts[$php_i]);
}
// Fix the PHP code stuff...
$data = str_replace("<pre style=\"display: inline;\">\t</pre>", "\t", implode(\'\', $php_parts));
// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
else
$data = str_replace("\t", " ", $data);
// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
if ($context[\'browser\'][\'is_opera\'])
$data .= \' \';
}'),
Como dice Miss All Sunday ya seguí dicho tutorial para añadir, ahora necesito validar. Pues voy a ver si tirando de los ejemplos que me das, puedo conseguir hacer lo que quiero. Supongo que $data será el contenido, mañana con calma le echa un vistazo.
Muchas gracias, y volveré para contar que tal me fue.
Un saludo.
Lo conseguí, al final fue simple:
array(
'tag' => 'personal',
'type' => 'unparsed_content',
'parameters' => array(
'id' => array('optional' => false),
),
'content' => '<div id="{id}" style="visibility:hidden;display:none">$1</div>',
'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
$data = strip_tags($data);
$data = str_replace(""", "\"", $data);
'),
'block_level' => 'true',
),
Gracias por la ayuda, un saludo.
marco como resuelto :)