Hi,
I have a custom code into class_bbcode.php file in vbulletin forum this code will redirect every url in any thread in that forum to another website. Here is the code
Code: [Select]
// --------------------- 123456
$rightlink='http://www.domainname.com?GO*'.bin2hex($rightlink);
// --------------------- 123456
// standard URL hyperlink
return "<a href=\"$rightlink\" target=\"_blank\">$text</a>";
In php is there any way where I can throw exceptions for some urls. For example every url in any thread will be redirected to www.domainname.com however I don't want this code to redirect urls within the forum it self let say the forum url is www.123.com so when any user post a thread and put www.123.com it will go through redirection.

Here is some help from other users:

You could just check if the has the domain in it.

if(preg_match('/https?://(?:www.)?domain.com/', $something)) {
//it has the url
}

Or you could just use strpos.

Also:

one way you could so it is using strstr() like so

if(strstr($rightlink, "domain.com")) { 
  //somthing for domain.com 
} else { 
  //for everything else 
} 

I tried adding these solutions to the orignal code but it did not work .

    You probably shouldn't be making a new thread with the same question just because it wasn't answered right away...

    but anyways, I think I read your question right, you're looking for any url with "123.com" in it wont be ridirected to domainname.com right?

    If so, I think this should work.

    //Get path, ie www.domain.com
    $urlpath = parse_url($rightlink);
    //domains not to be used with domainname.com
    $exception = "123.com";
    
    //If the path of the url contains or matches the exception.. don't use domain.com link
    if(strpos($urlpath['path'], $exception) || $urlpath['path'] === $exception) { 
    	return "<a href=\"$rightlink\">$text</a>";
    } else { 
    	//If the path of the url doesn't matches the exception.. make link a domain.com link
    	$rightlink='http://www.domainname.com?GO*'.bin2hex($rightlink);
    	return "<a href=\"$rightlink\" target=\"_blank\">$text</a>";
    }
    

      ...which looks perfect. And if you REALLY want to make that an exception, invoke "throw new Exception('this is the wrong link'), BEFORE returning as above, put the invocation to that in a try loop and catch it. That way you have both: the "dubious" url and an error handler that can take (immediate) further action.

      Got me on the run, best from the south.

        coldwerturkey;10890166 wrote:

        You probably shouldn't be making a new thread with the same question just because it wasn't answered right away...

        but anyways, I think I read your question right, you're looking for any url with "123.com" in it wont be ridirected to domainname.com right?

        If so, I think this should work.

        //Get path, ie www.domain.com
        $urlpath = parse_url($rightlink);
        //domains not to be used with domainname.com
        $exception = "123.com";
        
        //If the path of the url contains or matches the exception.. don't use domain.com link
        if(strpos($urlpath['path'], $exception) || $urlpath['path'] === $exception) { 
        	return "<a href=\"$rightlink\">$text</a>";
        } else { 
        	//If the path of the url doesn't matches the exception.. make link a domain.com link
        	$rightlink='http://www.domainname.com?GO*'.bin2hex($rightlink);
        	return "<a href=\"$rightlink\" target=\"_blank\">$text</a>";
        }
        

        Thank you, I have tried what you have told me exactly but this what happend

        Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in /home/m7shsh/public_html/vb/includes/class_bbcode.php on line 2171

          There is no parse error in the code that coldwerturkey posted, so you'll need to show us line 2171 ( :eek: ) of the class_bbcode.php file along with a few lines before it in order for us to determine if it's some simple syntax error there.

            NogDog;10890283 wrote:

            There is no parse error in the code that coldwerturkey posted, so you'll need to show us line 2171 ( :eek: ) of the class_bbcode.php file along with a few lines before it in order for us to determine if it's some simple syntax error there.

            Thank you here is the code:

            	/**
            	* Returns whether this parser is a WYSIWYG parser. Useful to change
            	* behavior slightly for a WYSIWYG parser without rewriting code.
            	*
            	* @return	bool	True if it is; false otherwise
            	*/
            	function is_wysiwyg()
            	{
            		return false;
            	}
            }
            
            // ####################################################################
            
            if (!function_exists('stripos'))
            //line 2171{
            	/**
            	* Case-insensitive version of strpos(). Defined if it does not exist.
            	*
            	* @param	string		Text to search for
            	* @param	string		Text to search in
            	* @param	int			Position to start search at
            	*
            	* @param	int|false	Position of text if found, false otherwise
            	*/
            	function stripos($haystack, $needle, $offset = 0)
            	{
            		$foundstring = stristr(substr($haystack, $offset), $needle);
            		return $foundstring === false ? false : strlen($haystack) - strlen($foundstring);
            	}
            }
            

            Here is where i"m posting the code starting line 1776

            	/**
            	* Handles a [url] tag. Creates a link to another web page.
            	*
            	* @param	string	If tag has option, the displayable name. Else, the URL.
            	* @param	string	If tag has option, the URL.
            	*
            	* @return	string	HTML representation of the tag.
            	*/
            	function handle_bbcode_url($text, $link)
            	{
            		$rightlink = trim($link);
            		if (empty($rightlink))
            		{
            			// no option -- use param
            			$rightlink = trim($text);
            		}
            		$rightlink = str_replace(array('`', '"', "'", '['), array('`', '&quot;', ''', '['), $this->strip_smilies($rightlink));
            
            	// remove double spaces -- fixes issues with wordwrap
            	$rightlink = str_replace('  ', '', $rightlink);
            
            	if (!preg_match('#^[a-z0-9]+(?<!about|javascript|vbscript|data):#si', $rightlink))
            	{
            		$rightlink = "http://$rightlink";
            	}
            
            	if (!trim($link) OR str_replace('  ', '', $text) == $rightlink)
            	{
            		$tmp = unhtmlspecialchars($rightlink);
            		if (vbstrlen($tmp) > 55 AND $this->is_wysiwyg() == false)
            		{
            			$text = htmlspecialchars_uni(substr($tmp, 0, 36) . '...' . substr($tmp, -14));
            		}
            		else
            		{
            			// under the 55 chars length, don't wordwrap this
            			$text = str_replace('  ', '', $text);
            		}
            	}
            //Get path, ie www.domain.com 
            $urlpath = parse_url($rightlink); 
            //domains not to be used with domainname.com 
            $exception = "123.com"; 
            
            //If the path of the url contains or matches the exception.. don't use domain.com link 
            if(strpos($urlpath['path'], $exception) || $urlpath['path'] === $exception) { 
                return "<a href=\"$rightlink\">$text</a>"; 
            } else { 
                //If the path of the url doesn't matches the exception.. make link a domain.com link 
                $rightlink='http://www.domianname.com?GO*'.bin2hex($rightlink); 
                return "<a href=\"$rightlink\" target=\"_blank\">$text</a>"; 
            } 
            

            i replaced the originals domain names and left 123.com as an example.
            Thank you

              It is probably an opening /* earlier on in the code.
              A highlighting editor would show it.

                This line has a quoting problem:

                $rightlink = str_replace(array('`', '"', "'", '['), array('`', '&quot;', [color=red][b]'''[/b][/color], '['), $this->strip_smilies($rightlink));
                

                The three single quotes in red need to be either [FONT="Courier New"]"'"[/FONT] or [FONT="Courier New"]'"'[/FONT], depending on what you want the replacement to be.

                  NogDog;10890294 wrote:

                  This line has a quoting problem:

                  $rightlink = str_replace(array('`', '"', "'", '['), array('`', '&quot;', [color=red][b]'''[/b][/color], '['), $this->strip_smilies($rightlink));
                  

                  The three single quotes in red need to be either [FONT="Courier New"]"'"[/FONT] or [FONT="Courier New"]'"'[/FONT], depending on what you want the replacement to be.

                  Well it appears that non of these has a problems the problem occurs when I add
                  this code which means something else need to be add it to it

                  //Get path, ie www.domain.com 
                  $urlpath = parse_url($rightlink); 
                  //domains not to be used with domainname.com 
                  $exception = "123.com"; 
                  
                  //If the path of the url contains or matches the exception.. don't use domain.com link 
                  if(strpos($urlpath['path'], $exception) || $urlpath['path'] === $exception) { 
                      return "<a href=\"$rightlink\">$text</a>"; 
                  } else { 
                      //If the path of the url doesn't matches the exception.. make link a domain.com link 
                      $rightlink='http://www.domainname.com?GO*'.bin2hex($rightlink); 
                      return "<a href=\"$rightlink\" target=\"_blank\">$text</a>"; 
                  } 
                    Write a Reply...