Ejemplo n.º 1
0
 function _parse_simple_tags()
 {
     global $LANG;
     import('util/url');
     $array_preg = array('b' => '`\\[b\\](.+)\\[/b\\]`isU', 'i' => '`\\[i\\](.+)\\[/i\\]`isU', 'u' => '`\\[u\\](.+)\\[/u\\]`isU', 's' => '`\\[s\\](.+)\\[/s\\]`isU', 'sup' => '`\\[sup\\](.+)\\[/sup\\]`isU', 'sub' => '`\\[sub\\](.+)\\[/sub\\]`isU', 'img' => '`\\[img(?:=(top|middle|bottom))?\\]((?:[./]+|(?:https?|ftps?)://(?:[a-z0-9-]+\\.)*[a-z0-9-]+(?:\\.[a-z]{2,4})?(?::[0-9]{1,5})?/?)[^,\\n\\r\\t\\f]+\\.(jpg|jpeg|bmp|gif|png|tiff|svg))\\[/img\\]`iU', 'color' => '`\\[color=((?:white|black|red|green|blue|yellow|purple|orange|maroon|pink)|(?:#[0-9a-f]{6}))\\](.+)\\[/color\\]`isU', 'bgcolor' => '`\\[bgcolor=((?:white|black|red|green|blue|yellow|purple|orange|maroon|pink)|(?:#[0-9a-f]{6}))\\](.+)\\[/bgcolor\\]`isU', 'size' => '`\\[size=([1-9]|(?:[1-4][0-9]))\\](.+)\\[/size\\]`isU', 'font' => '`\\[font=(arial|times|courier(?: new)?|impact|geneva|optima)\\](.+)\\[/font\\]`isU', 'pre' => '`\\[pre\\](.+)\\[/pre\\]`isU', 'align' => '`\\[align=(left|center|right|justify)\\](.+)\\[/align\\]`isU', 'float' => '`\\[float=(left|right)\\](.+)\\[/float\\]`isU', 'anchor' => '`\\[anchor=([a-z_][a-z0-9_-]*)\\](.*)\\[/anchor\\]`isU', 'acronym' => '`\\[acronym=([^\\n[\\]<]+)\\](.*)\\[/acronym\\]`isU', 'style' => '`\\[style=(success|question|notice|warning|error)\\](.+)\\[/style\\]`isU', 'swf' => '`\\[swf=([0-9]{1,3}),([0-9]{1,3})\\](((?:[./]+|(?:https?|ftps?)://([a-z0-9-]+\\.)*[a-z0-9-]+\\.[a-z]{2,4})+(?:[a-z0-9~_-]+/)*[a-z0-9_+.:?/=#%@&;,-]*))\\[/swf\\]`iU', 'movie' => '`\\[movie=([0-9]{1,3}),([0-9]{1,3})\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/movie\\]`iU', 'sound' => '`\\[sound\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/sound\\]`iU', 'math' => '`\\[math\\](.+)\\[/math\\]`iU', 'mail' => '`(?<=\\s|^)([a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4})(?=\\s|\\n|\\r|<|$)`iU', 'mail2' => '`\\[mail=([a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4})\\]([^\\n\\r\\t\\f]+)\\[/mail\\]`iU', 'url1' => '`\\[url\\]((?!javascript:)' . Url::get_wellformness_regex() . ')\\[/url\\]`isU', 'url2' => '`\\[url=((?!javascript:)' . Url::get_wellformness_regex() . ')\\]([^\\n\\r\\t\\f]+)\\[/url\\]`isU', 'url3' => '`(\\s+)(' . Url::get_wellformness_regex(REGEX_MULTIPLICITY_REQUIRED) . ')(\\s|<+)`isU', 'url4' => '`(\\s+)(www\\.' . Url::get_wellformness_regex(REGEX_MULTIPLICITY_NOT_USED) . ')(\\s|<+)`isU');
     $array_preg_replace = array('b' => "<strong>\$1</strong>", 'i' => "<em>\$1</em>", 'u' => "<span style=\"text-decoration: underline;\">\$1</span>", 's' => "<strike>\$1</strike>", 'sup' => '<sup>$1</sup>', 'sub' => '<sub>$1</sub>', 'img' => "<img src=\"\$2\" alt=\"\" class=\"valign_\$1\" />", 'color' => "<span style=\"color:\$1;\">\$2</span>", 'bgcolor' => "<span style=\"background-color:\$1;\">\$2</span>", 'size' => "<span style=\"font-size: \$1px;\">\$2</span>", 'font' => "<span style=\"font-family: \$1;\">\$2</span>", 'pre' => "<pre>\$1</pre>", 'align' => "<p style=\"text-align:\$1\">\$2</p>", 'float' => "<p class=\"float_\$1\">\$2</p>", 'anchor' => "<span id=\"\$1\">\$2</span>", 'acronym' => "<acronym title=\"\$1\" class=\"bb_acronym\">\$2</acronym>", 'style' => "<span class=\"\$1\">\$2</span>", 'swf' => '[[MEDIA]]insertSwfPlayer(\'$3\', $1, $2);[[/MEDIA]]', 'movie' => '[[MEDIA]]insertMoviePlayer(\'$3\', $1, $2);[[/MEDIA]]', 'sound' => '[[MEDIA]]insertSoundPlayer(\'$1\');[[/MEDIA]]', 'math' => '[[MATH]]$1[[/MATH]]', 'mail' => "<a href=\"mailto:\$1\">\$1</a>", 'mail2' => "<a href=\"mailto:\$1\">\$2</a>", 'url1' => '<a href="$1">$1</a>', 'url2' => '<a href="$1">$2</a>', 'url3' => '$1<a href="$2">$2</a>$3', 'url4' => '$1<a href="$2">$2</a>$3');
     $parse_line = true;
     if (!empty($this->forbidden_tags)) {
         if (in_array('url', $this->forbidden_tags)) {
             $this->forbidden_tags[] = 'url1';
             $this->forbidden_tags[] = 'url2';
             $this->forbidden_tags[] = 'url3';
             $this->forbidden_tags[] = 'url4';
         }
         if (in_array('mail', $this->forbidden_tags)) {
             $this->forbidden_tags[] = 'mail';
             $this->forbidden_tags[] = 'mail2';
         }
         foreach ($this->forbidden_tags as $key => $tag) {
             if ($tag == 'line') {
                 $parse_line = false;
             } else {
                 unset($array_preg[$tag]);
                 unset($array_preg_replace[$tag]);
             }
         }
     }
     $this->content = preg_replace($array_preg, $array_preg_replace, $this->content);
     if ($parse_line) {
         $this->content = str_replace('[line]', '<hr class="bb_hr" />', $this->content);
     }
     if (!in_array('title', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[title=([1-4])\\](.+)\\[/title\\]`iU', array(&$this, '_parse_title'), $this->content);
     }
     if (!in_array('wikipedia', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[wikipedia(?: page="([^"]+)")?(?: lang="([a-z]+)")?\\](.+)\\[/wikipedia\\]`isU', array(&$this, '_parse_wikipedia_links'), $this->content);
     }
     ##Parsage des balises imbriquées.
     if (!in_array('quote', $this->forbidden_tags)) {
         $this->_parse_imbricated('[quote]', '`\\[quote\\](.+)\\[/quote\\]`sU', '<span class="text_blockquote">' . $LANG['quotation'] . ':</span><div class="blockquote">$1</div>', $this->content);
         $this->_parse_imbricated('[quote=', '`\\[quote=([^\\]]+)\\](.+)\\[/quote\\]`sU', '<span class="text_blockquote">$1:</span><div class="blockquote">$2</div>', $this->content);
     }
     if (!in_array('hide', $this->forbidden_tags)) {
         $this->_parse_imbricated('[hide]', '`\\[hide\\](.+)\\[/hide\\]`sU', '<span class="text_hide">' . $LANG['hide'] . ':</span><div class="hide" onclick="bb_hide(this)"><div class="hide2">$1</div></div>', $this->content);
     }
     if (!in_array('indent', $this->forbidden_tags)) {
         $this->_parse_imbricated('[indent]', '`\\[indent\\](.+)\\[/indent\\]`sU', '<div class="indent">$1</div>', $this->content);
     }
     if (!in_array('block', $this->forbidden_tags)) {
         $this->_parse_imbricated('[block]', '`\\[block\\](.+)\\[/block\\]`sU', '<div class="bb_block">$1</div>', $this->content);
         $this->_parse_imbricated('[block style=', '`\\[block style="([^"]+)"\\](.+)\\[/block\\]`sU', '<div class="bb_block" style="$1">$2</div>', $this->content);
     }
     if (!in_array('fieldset', $this->forbidden_tags)) {
         $this->_parse_imbricated('[fieldset', '`\\[fieldset(?: legend="(.*)")?(?: style="([^"]*)")?\\](.+)\\[/fieldset\\]`sU', '<fieldset class="bb_fieldset" style="$2"><legend>$1</legend>$3</fieldset>', $this->content);
     }
 }
Ejemplo n.º 2
0
 function test_get_wellformness_regex()
 {
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED), URL::FORBID_JS_REGEX . URL::PROTOCOL_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED), URL::USER_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED), URL::DOMAIN_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED), URL::FOLDERS_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED), URL::FILE_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED), URL::ARGS_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_REQUIRED), URL::ANCHOR_REGEX);
     self::assertEquals(Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_REQUIRED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, RegexHelper::REGEX_MULTIPLICITY_NOT_USED, false), URL::PROTOCOL_REGEX);
 }
Ejemplo n.º 3
0
 /**
  * @desc Parses all BBCode simple tags.
  * The simple tags are those which can be treated enough requiring many different treatments.
  * The not simple tags are [code], [html], [table] and its content [row] [col] [head], [list].
  */
 protected function parse_simple_tags()
 {
     global $LANG;
     $array_preg = array('b' => '`\\[b\\](.+)\\[/b\\]`isU', 'i' => '`\\[i\\](.+)\\[/i\\]`isU', 'u' => '`\\[u\\](.+)\\[/u\\]`isU', 's' => '`\\[s\\](.+)\\[/s\\]`isU', 'sup' => '`\\[sup\\](.+)\\[/sup\\]`isU', 'sub' => '`\\[sub\\](.+)\\[/sub\\]`isU', 'color' => '`\\[color=((?:white|black|red|green|blue|yellow|purple|orange|maroon|pink)|(?:#[0-9a-f]{6}))\\](.+)\\[/color\\]`isU', 'bgcolor' => '`\\[bgcolor=((?:white|black|red|green|blue|yellow|purple|orange|maroon|pink)|(?:#[0-9a-f]{6}))\\](.+)\\[/bgcolor\\]`isU', 'size' => '`\\[size=([1-9]|(?:[1-4][0-9]))\\](.+)\\[/size\\]`isU', 'font' => '`\\[font=(andale mono|arial(?: black)?|book antiqua|comic sans ms|courier(?: new)?|georgia|helvetica|impact|symbol|tahoma|terminal|times new roman|trebuchet ms|verdana|webdings|wingdings)\\](.+)\\[/font\\]`isU', 'pre' => '`\\[pre\\](.+)\\[/pre\\]`isU', 'align' => '`\\[align=(left|center|right|justify)\\](.+)\\[/align\\]`isU', 'float' => '`\\[float=(left|right)\\](.+)\\[/float\\]`isU', 'anchor' => '`\\[anchor=([a-z_][a-z0-9_-]*)\\](.*)\\[/anchor\\]`isU', 'acronym' => '`\\[acronym=([^\\n[\\]<]+)\\](.*)\\[/acronym\\]`isU', 'style' => '`\\[style=(success|question|notice|warning|error)\\](.+)\\[/style\\]`isU', 'swf' => '`\\[swf=([0-9]{1,3}),([0-9]{1,3})\\](((?:[./]+|(?:https?|ftps?)://([a-z0-9-]+\\.)*[a-z0-9-]+\\.[a-z]{2,4})+(?:[a-z0-9~_-]+/)*[a-z0-9_+.:?/=#%@&;,-]*))\\[/swf\\]`iU', 'movie' => '`\\[movie=([0-9]{1,3}),([0-9]{1,3})\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/movie\\]`iU', 'sound' => '`\\[sound\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/sound\\]`iU', 'math' => '`\\[math\\](.+)\\[/math\\]`iU', 'mail' => '`(?<=\\s|^)([a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4})(?=\\s|\\n|\\r|<|$)`iU', 'mail2' => '`\\[mail=([a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4})\\]([^\\n\\r\\t\\f]+)\\[/mail\\]`iU', 'url1' => '`\\[url\\]((?!javascript:)' . Url::get_wellformness_regex() . ')\\[/url\\]`sU', 'url2' => '`\\[url=((?!javascript:)' . Url::get_wellformness_regex() . ')\\]([^\\n\\r\\t\\f]+)\\[/url\\]`sU', 'url3' => '`(\\s+)(' . Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_REQUIRED) . ')(\\s|<+)`sU', 'url4' => '`(\\s+)(www\\.' . Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED) . ')(\\s|<+)`sU', 'youtube1' => '`\\[youtube=([0-9]{1,3}),([0-9]{1,3})\\](((?:[./]+|(?:https?|ftps?)://([a-z0-9-]+\\.)*[a-z0-9-]+\\.[a-z]{2,4})+(?:[a-z0-9~_-]+/)*[a-z0-9_+.:?/=#%@&;,-]*))\\[/youtube\\]`iU', 'youtube2' => '`\\[youtube\\](((?:[./]+|(?:https?|ftps?)://([a-z0-9-]+\\.)*[a-z0-9-]+\\.[a-z]{2,4})+(?:[a-z0-9~_-]+/)*[a-z0-9_+.:?/=#%@&;,-]*))\\[/youtube\\]`iU', 'lightbox' => '`\\[lightbox=((?!javascript:)' . Url::get_wellformness_regex() . ')\\]([^\\n\\r\\t\\f]+)\\[/lightbox\\]`isU');
     $array_preg_replace = array('b' => "<strong>\$1</strong>", 'i' => "<em>\$1</em>", 'u' => "<span style=\"text-decoration: underline;\">\$1</span>", 's' => "<s>\$1</s>", 'sup' => '<sup>$1</sup>', 'sub' => '<sub>$1</sub>', 'color' => "<span style=\"color:\$1;\">\$2</span>", 'bgcolor' => "<span style=\"background-color:\$1;\">\$2</span>", 'size' => "<span style=\"font-size: \$1px;\">\$2</span>", 'font' => "<span style=\"font-family: \$1;\">\$2</span>", 'pre' => "<pre>\$1</pre>", 'align' => "<p style=\"text-align:\$1\">\$2</p>", 'float' => "<p class=\"float-\$1\">\$2</p>", 'anchor' => "<span id=\"\$1\">\$2</span>", 'acronym' => "<abbr title=\"\$1\">\$2</abbr>", 'style' => "<span class=\"\$1\">\$2</span>", 'swf' => '[[MEDIA]]insertSwfPlayer(\'$3\', $1, $2);[[/MEDIA]]', 'movie' => '[[MEDIA]]insertMoviePlayer(\'$3\', $1, $2);[[/MEDIA]]', 'sound' => '[[MEDIA]]insertSoundPlayer(\'$1\');[[/MEDIA]]', 'math' => '[[MATH]]$1[[/MATH]]', 'mail' => "<a href=\"mailto:\$1\">\$1</a>", 'mail2' => "<a href=\"mailto:\$1\">\$2</a>", 'url1' => '<a href="$1">$1</a>', 'url2' => '<a href="$1">$2</a>', 'url3' => '$1<a href="$2">$2</a>$3', 'url4' => '$1<a href="$2">$2</a>$3', 'youtube1' => '[[MEDIA]]insertYoutubePlayer(\'$3\', $1, $2);[[/MEDIA]]', 'youtube2' => '[[MEDIA]]insertYoutubePlayer(\'$1\', 560, 315);[[/MEDIA]]', 'lightbox' => '<a href="$1" data-lightbox="formatter">$2</a>');
     $parse_line = true;
     //Suppression des remplacements des balises interdites.
     if (!empty($this->forbidden_tags)) {
         //Si on interdit les liens, on ajoute toutes les manières par lesquelles elles peuvent passer
         if (in_array('url', $this->forbidden_tags)) {
             $this->forbidden_tags[] = 'url1';
             $this->forbidden_tags[] = 'url2';
             $this->forbidden_tags[] = 'url3';
             $this->forbidden_tags[] = 'url4';
         }
         if (in_array('mail', $this->forbidden_tags)) {
             $this->forbidden_tags[] = 'mail';
             $this->forbidden_tags[] = 'mail2';
         }
         foreach ($this->forbidden_tags as $key => $tag) {
             if ($tag == 'line') {
                 $parse_line = false;
             } else {
                 unset($array_preg[$tag]);
                 unset($array_preg_replace[$tag]);
             }
         }
     }
     //Remplacement : on parse les balises classiques
     $this->content = preg_replace($array_preg, $array_preg_replace, $this->content);
     //Line tag
     if ($parse_line) {
         $this->content = str_replace('[line]', '<hr class="bb_hr" />', $this->content);
     }
     //Title tag
     if (!in_array('title', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[title=([1-6])\\](.+)\\[/title\\]`iU', array($this, 'parse_title'), $this->content);
     }
     //Image tag
     if (!in_array('img', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[img(?: alt="([^"]+)")?(?: title="([^"]+)")?(?: style="([^"]+)")?(?: class="([^"]+)")?\\]((?:[./]+|(?:https?|ftps?)://(?:[a-z0-9-]+\\.)*[a-z0-9-]+(?:\\.[a-z]{2,4})?(?::[0-9]{1,5})?/?)[^,\\n\\r\\t\\f]+\\.(jpg|jpeg|bmp|gif|png|tiff|svg))\\[/img\\]`iU', array($this, 'parse_img'), $this->content);
         $this->content = preg_replace_callback('`\\[img(?: alt="([^"]+)")?(?: title="([^"]+)")?(?: style="([^"]+)")?(?: class="([^"]+)")?\\]data:(.+)\\[/img\\]`iU', array($this, 'parse_img'), $this->content);
     }
     //Wikipedia tag
     if (!in_array('wikipedia', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[wikipedia(?: page="([^"]+)")?(?: lang="([a-z]+)")?\\](.+)\\[/wikipedia\\]`isU', array($this, 'parse_wikipedia_links'), $this->content);
     }
     ##Parsage des balises imbriquées.
     //Quote tag
     if (!in_array('quote', $this->forbidden_tags)) {
         $this->_parse_imbricated('[quote]', '`\\[quote\\](.+)\\[/quote\\]`sU', '<span class="formatter-blockquote">' . $LANG['quotation'] . ':</span><div class="blockquote">$1</div>');
         $this->_parse_imbricated('[quote=', '`\\[quote=([^\\]]+)\\](.+)\\[/quote\\]`sU', '<span class="formatter-blockquote">$1:</span><div class="blockquote">$2</div>');
     }
     //Hide tag
     if (!in_array('hide', $this->forbidden_tags)) {
         $this->_parse_imbricated('[hide]', '`\\[hide\\](.+)\\[/hide\\]`sU', '<span class="formatter-hide">' . LangLoader::get_message('hidden', 'common') . ':</span><div class="hide" onclick="bb_hide(this)"><div class="hide2">$1</div></div>');
     }
     //Indent tag
     if (!in_array('indent', $this->forbidden_tags)) {
         $this->_parse_imbricated('[indent]', '`\\[indent\\](.+)\\[/indent\\]`sU', '<div class="indent">$1</div>');
     }
     //Block tag
     if (!in_array('block', $this->forbidden_tags)) {
         $this->_parse_imbricated('[block]', '`\\[block\\](.+)\\[/block\\]`sU', '<div class="formatter-block">$1</div>');
         $this->_parse_imbricated('[block style=', '`\\[block style="([^"]+)"\\](.+)\\[/block\\]`sU', '<div class="formatter-block" style="$1">$2</div>');
     }
     //Fieldset tag
     if (!in_array('fieldset', $this->forbidden_tags)) {
         $this->_parse_imbricated('[fieldset', '`\\[fieldset(?: legend="(.*)")?(?: style="([^"]*)")?\\](.+)\\[/fieldset\\]`sU', '<fieldset class="formatter-fieldset" style="$2"><legend>$1</legend>$3</fieldset>');
     }
     // Feed tag
     if (!in_array('feed', $this->forbidden_tags)) {
         $this->parse_feed_tag();
     }
 }
Ejemplo n.º 4
0
 function _parse_bbcode_tags()
 {
     global $LANG;
     import('util/url');
     $array_preg = array('pre' => '`\\[pre\\](.+)\\[/pre\\]`isU', 'float' => '`\\[float=(left|right)\\](.+)\\[/float\\]`isU', 'acronym' => '`\\[acronym=([^\\n[\\]<]+)\\](.*)\\[/acronym\\]`isU', 'style' => '`\\[style=(success|question|notice|warning|error)\\](.+)\\[/style\\]`isU', 'swf' => '`\\[swf=([0-9]{1,3}),([0-9]{1,3})\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/swf\\]`iU', 'movie' => '`\\[movie=([0-9]{1,3}),([0-9]{1,3})\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/movie\\]`iU', 'sound' => '`\\[sound\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/sound\\]`iU', 'math' => '`\\[math\\](.+)\\[/math\\]`iU', 'url' => '`(\\s+)(' . Url::get_wellformness_regex(REGEX_MULTIPLICITY_REQUIRED) . ')(\\s|<+)`isU', 'url2' => '`(\\s+)(www\\.' . Url::get_wellformness_regex(REGEX_MULTIPLICITY_NOT_USED) . ')(\\s|<+)`isU', 'mail' => '`(\\s+)([a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4})(\\s+)`i');
     $array_preg_replace = array('pre' => "<pre>\$1</pre>", 'float' => "<p class=\"float_\$1\">\$2</p>", 'acronym' => "<acronym title=\"\$1\" class=\"bb_acronym\">\$2</acronym>", 'style' => "<span class=\"\$1\">\$2</span>", 'swf' => "[[MEDIA]]insertSwfPlayer('\$3', \$1, \$2);[[/MEDIA]]", 'movie' => "[[MEDIA]]insertMoviePlayer('\$3', \$1, \$2);[[/MEDIA]]", 'sound' => "[[MEDIA]]insertSoundPlayer('\$1');[[/MEDIA]]", 'math' => '[[MATH]]$1[[/MATH]]', 'url' => "\$1<a href=\"\$2\">\$2</a>\$3", 'url2' => "\$1<a href=\"http://\$2\">\$2</a>\$3", 'mail' => "\$1<a href=\"mailto:\$2\">\$2</a>\$3");
     if (!empty($this->forbidden_tags)) {
         if (in_array('url', $this->forbidden_tags)) {
             $this->forbidden_tags[] = 'url2';
         }
         $other_tags = array('table', 'quote', 'hide', 'indent', 'list');
         foreach ($this->forbidden_tags as $key => $tag) {
             if (in_array($tag, $other_tags)) {
                 $array_preg[$tag] = '`\\[' . $tag . '.*\\](.+)\\[/' . $tag . '\\]`isU';
                 $array_preg_replace[$tag] = "\$1";
             } else {
                 unset($array_preg[$tag]);
                 unset($array_preg_replace[$tag]);
             }
         }
     }
     $this->content = preg_replace($array_preg, $array_preg_replace, $this->content);
     ##Nested tags
     if (!in_array('hide', $this->forbidden_tags)) {
         $this->_parse_imbricated('[hide]', '`\\[hide\\](.+)\\[/hide\\]`sU', '<span class="text_hide">' . $LANG['hide'] . ':</span><div class="hide" onclick="bb_hide(this)"><div class="hide2">$1</div></div>', $this->content);
     }
     if (!in_array('block', $this->forbidden_tags)) {
         $this->_parse_imbricated('[block]', '`\\[block\\](.+)\\[/block\\]`sU', '<div class="bb_block">$1</div>', $this->content);
         $this->_parse_imbricated('[block style=', '`\\[block style="([^"]+)"\\](.+)\\[/block\\]`sU', '<div class="bb_block" style="$1">$2</div>', $this->content);
     }
     if (!in_array('fieldset', $this->forbidden_tags)) {
         $this->_parse_imbricated('[fieldset', '`\\[fieldset(?: legend="(.*)")?(?: style="([^"]*)")?\\](.+)\\[/fieldset\\]`sU', '<fieldset class="bb_fieldset" style="$2"><legend>$1</legend>$3</fieldset>', $this->content);
     }
     if (!in_array('wikipedia', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[wikipedia(?: page="([^"]+)")?(?: lang="([a-z]+)")?\\](.+)\\[/wikipedia\\]`isU', array(&$this, '_parse_wikipedia_links'), $this->content);
     }
     if (!in_array('hide', $this->forbidden_tags)) {
         $this->_parse_imbricated('[hide]', '`\\[hide\\](.+)\\[/hide\\]`sU', '<span class="text_hide">' . $LANG['hide'] . ':</span><div class="hide" onclick="bb_hide(this)"><div class="hide2">$1</div></div>', $this->content);
     }
     if (!in_array('quote', $this->forbidden_tags)) {
         $this->_parse_imbricated('[quote]', '`\\[quote\\](.+)\\[/quote\\]`sU', '<span class="text_blockquote">' . $LANG['quotation'] . ':</span><div class="blockquote">$1</div>', $this->content);
         $this->_parse_imbricated('[quote=', '`\\[quote=([^\\]]+)\\](.+)\\[/quote\\]`sU', '<span class="text_blockquote">$1:</span><div class="blockquote">$2</div>', $this->content);
     }
 }
Ejemplo n.º 5
0
 static function check_wellformness($url, $protocol = REGEX_MULTIPLICITY_OPTIONNAL, $user = REGEX_MULTIPLICITY_OPTIONNAL, $domain = REGEX_MULTIPLICITY_OPTIONNAL, $folders = REGEX_MULTIPLICITY_OPTIONNAL, $file = REGEX_MULTIPLICITY_OPTIONNAL, $args = REGEX_MULTIPLICITY_OPTIONNAL, $anchor = REGEX_MULTIPLICITY_OPTIONNAL, $forbid_js = true)
 {
     return preg_match('`^' . Url::get_wellformness_regex($protocol, $user, $domain, $folders, $file, $args, $anchor, $forbid_js) . '$`i', $url);
 }
Ejemplo n.º 6
0
 /**
  * @desc Parses the formatting which is not supported by TinyMCE and is made in BBCode.
  */
 private function parse_bbcode_tags()
 {
     global $LANG;
     $array_preg = array('b' => '`\\[b\\](.+)\\[/b\\]`isU', 'i' => '`\\[i\\](.+)\\[/i\\]`isU', 'u' => '`\\[u\\](.+)\\[/u\\]`isU', 's' => '`\\[s\\](.+)\\[/s\\]`isU', 'pre' => '`\\[pre\\](.+)\\[/pre\\]`isU', 'float' => '`\\[float=(left|right)\\](.+)\\[/float\\]`isU', 'acronym' => '`\\[acronym=([^\\n[\\]<]+)\\](.*)\\[/acronym\\]`isU', 'style' => '`\\[style=(success|question|notice|warning|error)\\](.+)\\[/style\\]`isU', 'swf' => '`\\[swf=([0-9]{1,3}),([0-9]{1,3})\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/swf\\]`iU', 'movie' => '`\\[movie=([0-9]{1,3}),([0-9]{1,3})\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/movie\\]`iU', 'sound' => '`\\[sound\\]([a-z0-9_+.:?/=#%@&;,-]*)\\[/sound\\]`iU', 'math' => '`\\[math\\](.+)\\[/math\\]`iU', 'url' => '`(\\s+)(' . Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_REQUIRED) . ')(\\s|<+)`sU', 'url2' => '`(\\s+)(www\\.' . Url::get_wellformness_regex(RegexHelper::REGEX_MULTIPLICITY_NOT_USED) . ')(\\s|<+)`sU', 'mail' => '`(\\s+)([a-zA-Z0-9._-]+@[a-z0-9._-]{2,}\\.[a-z]{2,4})(\\s+)`i', 'lightbox' => '`\\[lightbox=((?!javascript:)' . Url::get_wellformness_regex() . ')\\]([^\\n\\r\\t\\f]+)\\[/lightbox\\]`isU');
     $array_preg_replace = array('b' => "<strong>\$1</strong>", 'i' => "<em>\$1</em>", 'u' => "<span style=\"text-decoration: underline;\">\$1</span>", 's' => "<s>\$1</s>", 'pre' => "<pre>\$1</pre>", 'float' => "<p class=\"float-\$1\">\$2</p>", 'acronym' => "<abbr title=\"\$1\">\$2</abbr>", 'style' => "<span class=\"\$1\">\$2</span>", 'swf' => "[[MEDIA]]insertSwfPlayer('\$3', \$1, \$2);[[/MEDIA]]", 'movie' => "[[MEDIA]]insertMoviePlayer('\$3', \$1, \$2);[[/MEDIA]]", 'sound' => "[[MEDIA]]insertSoundPlayer('\$1');[[/MEDIA]]", 'math' => '[[MATH]]$1[[/MATH]]', 'url' => "\$1<a href=\"\$2\">\$2</a>\$3", 'url2' => "\$1<a href=\"http://\$2\">\$2</a>\$3", 'mail' => "\$1<a href=\"mailto:\$2\">\$2</a>\$3", 'lightbox' => '<a href="$1" data-lightbox="formatter">$2</a>');
     //Suppression des remplacements des balises interdites.
     if (!empty($this->forbidden_tags)) {
         //Si on interdit les liens, on ajoute toutes les manières par lesquelles elles peuvent passer
         if (in_array('url', $this->forbidden_tags)) {
             $this->forbidden_tags[] = 'url2';
         }
         $other_tags = array('table', 'quote', 'hide', 'indent', 'list');
         foreach ($this->forbidden_tags as $key => $tag) {
             //Balise interdite : on la supprime
             if (in_array($tag, $other_tags)) {
                 $array_preg[$tag] = '`\\[' . $tag . '.*\\](.+)\\[/' . $tag . '\\]`isU';
                 $array_preg_replace[$tag] = "\$1";
             } else {
                 unset($array_preg[$tag]);
                 unset($array_preg_replace[$tag]);
             }
         }
     }
     //Remplacement : on parse les balises classiques
     $this->content = preg_replace($array_preg, $array_preg_replace, $this->content);
     ##Nested tags
     //Hide tag
     if (!in_array('hide', $this->forbidden_tags)) {
         $this->_parse_imbricated('[hide]', '`\\[hide\\](.+)\\[/hide\\]`sU', '<span class="formatter-hide">' . LangLoader::get_message('hidden', 'common') . ':</span><div class="hide" onclick="bb_hide(this)"><div class="hide2">$1</div></div>', $this->content);
     }
     //Block tag
     if (!in_array('block', $this->forbidden_tags)) {
         $this->_parse_imbricated('[block]', '`\\[block\\](.+)\\[/block\\]`sU', '<div class="formatter-block">$1</div>', $this->content);
         $this->_parse_imbricated('[block style=', '`\\[block style="([^"]+)"\\](.+)\\[/block\\]`sU', '<div class="formatter-block" style="$1">$2</div>', $this->content);
     }
     //Fieldset tag
     if (!in_array('fieldset', $this->forbidden_tags)) {
         $this->_parse_imbricated('[fieldset', '`\\[fieldset(?: legend="(.*)")?(?: style="([^"]*)")?\\](.+)\\[/fieldset\\]`sU', '<fieldset class="formatter-fieldset" style="$2"><legend>$1</legend>$3</fieldset>', $this->content);
     }
     //Wikipedia tag
     if (!in_array('wikipedia', $this->forbidden_tags)) {
         $this->content = preg_replace_callback('`\\[wikipedia(?: page="([^"]+)")?(?: lang="([a-z]+)")?\\](.+)\\[/wikipedia\\]`isU', array($this, 'parse_wikipedia_links'), $this->content);
     }
     //Hide tag
     if (!in_array('hide', $this->forbidden_tags)) {
         $this->_parse_imbricated('[hide]', '`\\[hide\\](.+)\\[/hide\\]`sU', '<span class="formatter-hide">' . LangLoader::get_message('hidden', 'common') . ':</span><div class="hide" onclick="bb_hide(this)"><div class="hide2">$1</div></div>', $this->content);
     }
     //Quote tag (this tag is managed by TinyMCE but it can also be used in BBCode syntax)
     if (!in_array('quote', $this->forbidden_tags)) {
         $this->_parse_imbricated('[quote]', '`\\[quote\\](.+)\\[/quote\\]`sU', '<span class="formatter-blockquote">' . $LANG['quotation'] . ':</span><div class="blockquote">$1</div>', $this->content);
         $this->_parse_imbricated('[quote=', '`\\[quote=([^\\]]+)\\](.+)\\[/quote\\]`sU', '<span class="formatter-blockquote">$1:</span><div class="blockquote">$2</div>', $this->content);
     }
     if (!in_array('feed', $this->forbidden_tags)) {
         $this->parse_feed_tag();
     }
 }