Classes

File helper/FormatingHelper.class.php

File helper/FormatingHelper.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 
<?php
/**
 * Formating helper
 * @package     Helper
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Regis VIARRE <crowkait@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2016 10 24
 * @since       PHPBoost 3.0 - 2010 01 21
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class FormatingHelper
{
    const NO_EDITOR_UNPARSE = false;

    /**
     * Parses a string with several default parameters. This methods exists to lighten the number of lines written.
     * @param string $content Content to parse
     * @param string[] $forbidden_tags List of the forbidden formatting tags
     * @param bool $addslashes if true, the parsed string will be escaped.
     * @return string The parsed string.
     */
    public static function strparse($content, $forbidden_tags = array(), $addslashes = true)
    {
        $parser = AppContext::get_content_formatting_service()->get_default_parser();

        //On assigne le contenu à interpréter. Il supprime les antislashes d'échappement seulement si ils ont été ajoutés par magic_quotes
        $parser->set_content($content);

        //Si il y a des balises interdites, on lui signale
        if (!empty($forbidden_tags))
        {
            $parser->set_forbidden_tags($forbidden_tags);
        }
        //Au travail maintenant !
        $parser->parse();

        //Renvoie le résultat. Echappe par défaut les caractères critiques afin d'être envoyé en base de données
        $result = $parser->get_content();
        if ($addslashes)
        {
            $result = addslashes($result);
        }
        return $result;
    }

    /**
     * Unparses a string with several default parameters. This methods exists to lighten the number of lines written.
     * @param string $content Content to unparse
     * @return string The unparsed string.
     * @see ContentFormattingUnparser
     */
    public static function unparse($content)
    {
        $parser = AppContext::get_content_formatting_service()->get_default_unparser();
        $parser->set_content(stripslashes($content));
        $parser->parse();

        return $parser->get_content();
    }

    /**
     * Second parses a string with several default parameters. This methods exists to lighten the number of lines written.
     * @param string $content Content to second parse
     * @return string The second parsed string.
     * @see ContentSecondParser
     */
    public static function second_parse($content)
    {
        $parser = AppContext::get_content_formatting_service()->get_default_second_parser();
        $parser->set_content($content);
        $parser->parse();

        return $parser->get_content();
    }

    /**
     * Second parses relative urls to absolute urls.
     * @param string $url Url to second parse
     * @return string The second parsed url.
     * @see Url
     */
    public static function second_parse_url($url)
    {
        $Url = new Url($url);
        return $Url->absolute();
    }
}
?>