Beispiel #1
1
 /**
  * Convert BBCode to HTML.
  * 
  * @param string $bbcode
  * @return string
  */
 public static function bbcode($bbcode)
 {
     $parser = new \JBBCode\Parser();
     $parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());
     $builder = new \JBBCode\CodeDefinitionBuilder('quote', '<blockquote>{param}</blockquote>');
     $parser->addCodeDefinition($builder->build());
     $builder = new \JBBCode\CodeDefinitionBuilder('code', '<pre><code>{param}</code></pre>');
     $builder->setParseContent(false);
     $parser->addCodeDefinition($builder->build());
     $parser->parse($bbcode);
     $html = $parser->getAsHtml();
     return Filters\HTMLFilter::clean($html);
 }
Beispiel #2
0
 /**
  * Sanitize a variable.
  * 
  * @param string $input
  * @param string $type
  * @return string|false
  */
 public static function sanitize($input, $type)
 {
     switch ($type) {
         // Escape HTML special characters.
         case 'escape':
             if (!utf8_check($input)) {
                 return false;
             }
             return escape($input);
             // Strip all HTML tags.
         // Strip all HTML tags.
         case 'strip':
             if (!utf8_check($input)) {
                 return false;
             }
             return escape(strip_tags($input));
             // Clean up HTML content to prevent XSS attacks.
         // Clean up HTML content to prevent XSS attacks.
         case 'html':
             if (!utf8_check($input)) {
                 return false;
             }
             return Filters\HTMLFilter::clean($input);
             // Clean up the input to be used as a safe filename.
         // Clean up the input to be used as a safe filename.
         case 'filename':
             if (!utf8_check($input)) {
                 return false;
             }
             return Filters\FilenameFilter::clean($input);
             // Unknown filters return false.
         // Unknown filters return false.
         default:
             return false;
     }
 }