Пример #1
0
/**
 * Filter the content and encode any bad HTML tags
 *
 * @since bbPress (r4641)
 *
 * @param string $content Topic and reply content
 * @return string Partially encodedd content
 */
function bbp_encode_bad($content = '')
{
    // Setup variables
    $content = _wp_specialchars($content, ENT_NOQUOTES);
    $content = preg_split('@(`[^`]*`)@m', $content, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
    $allowed = bbp_kses_allowed_tags();
    $empty = array('br' => true, 'hr' => true, 'img' => true, 'input' => true, 'param' => true, 'area' => true, 'col' => true, 'embed' => true);
    // Loop through allowed tags and compare for empty and normal tags
    foreach ($allowed as $tag => $args) {
        $preg = $args ? "{$tag}(?:\\s.*?)?" : $tag;
        // Which walker to use based on the tag and arguments
        if (isset($empty[$tag])) {
            array_walk($content, 'bbp_encode_empty_callback', $preg);
        } else {
            array_walk($content, 'bbp_encode_normal_callback', $preg);
        }
    }
    // Return the joined content array
    return implode('', $content);
}
Пример #2
0
/**
 * Display all of the allowed tags in HTML format with attributes.
 *
 * This is useful for displaying in the post area, which elements and
 * attributes are supported. As well as any plugins which want to display it.
 *
 * @since bbPress (r2780)
 *
 * @uses bbp_kses_allowed_tags() To get the allowed tags
 * @uses apply_filters() Calls 'bbp_allowed_tags' with the tags
 * @return string HTML allowed tags entity encoded.
 */
function bbp_get_allowed_tags()
{
    $allowed = '';
    foreach ((array) bbp_kses_allowed_tags() as $tag => $attributes) {
        $allowed .= '<' . $tag;
        if (0 < count($attributes)) {
            foreach (array_keys($attributes) as $attribute) {
                $allowed .= ' ' . $attribute . '=""';
            }
        }
        $allowed .= '> ';
    }
    return apply_filters('bbp_get_allowed_tags', htmlentities($allowed));
}