Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( !function_exists('cgmp_parse_wiki_style_links') ):
- function cgmp_parse_wiki_style_links($text) {
- // Google Maps link : #*
- $pattern = "/\#\*[^\#\*]*\#\*/";
- preg_match_all($pattern, $text, $gmaplinks);
- if (isset($gmaplinks[0])) {
- foreach ($gmaplinks[0] as $gmaplink) {
- $text = str_replace($gmaplink, "[TOKEN]", $text);
- $gmaplink = preg_replace("/(\#\*)/", "", $gmaplink);
- $anchor = "<a target='_blank' href='http://maps.google.fr/maps/?q=".$gmaplink."'>Voir sur Google Maps</a>";
- $text = str_replace("[TOKEN]", $anchor, $text);
- }
- }
- // <br> : #-
- $pattern = "/\#\-[^\#\-]*/";
- preg_match_all($pattern, $text, $newlines);
- if (isset($newlines[0])) {
- foreach ($newlines[0] as $newline) {
- $text = str_replace($newline, "[TOKEN]", $text);
- $newline = preg_replace("/(\#\-)/", "", $newline);
- $anchor = "<br>".$newline;
- $text = str_replace("[TOKEN]", $anchor, $text);
- }
- }
- // Images : #@
- $pattern = "/\#\@[^\#\@]*\#\@/";
- preg_match_all($pattern, $text, $images);
- if (isset($images[0])) {
- foreach ($images[0] as $image) {
- $text = str_replace($image, "[TOKEN]", $text);
- $image = preg_replace("/(\#\@)/", "", $image);
- $anchor = "<img src='".$image."'>";
- $text = str_replace("[TOKEN]", $anchor, $text);
- }
- }
- // Links : #
- $pattern = "/\#[^\#]*\#/";
- preg_match_all($pattern, $text, $wikilinks);
- if (isset($wikilinks[0])) {
- foreach ($wikilinks[0] as $wikilink) {
- $text = str_replace($wikilink, "[TOKEN]", $text);
- $wikilink = preg_replace("/(\#)|(\#)/", "", $wikilink);
- $url_data = preg_split("/[\s,]+/", $wikilink, 2);
- $href = trim($url_data[0]);
- $linkName = "Click Here";
- if (isset($url_data[1])) {
- $linkName = trim($url_data[1]);
- }
- $anchor = "<a target='_blank' href='".$href."'>".$linkName."</a>";
- $text = str_replace("[TOKEN]", $anchor, $text);
- }
- }
- return $text;
- }
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement