Jump to content

[SOLVED] Need help with preg_match line in SMF modification


Colleen78

Recommended Posts

Hello,

 

The creator of a modification I am using for my SMF 1.1.5 board seems to have stopped offering support so I'd like to fix this issue myself.

 

The modification takes Amazon links in my forum and adds my associate ID. Here's a link to the modification if it helps, http://custom.simplemachines.org/mods/index.php?mod=893

 

The error I am getting in the error log is this:

 

8: Undefined index: host

File: /home2/mydomain/public_html/Sources/Subs.php

Line: 2390

 

This is that line:

						if (preg_match('/(.*)amazon\.(com|co.uk|de|fr|co.jp|ca)+/i', $parsed['host'])) {

 

Here is the rest of the code from around and including that line:

 

					// CYCLE THROUGH EACH LINK
				foreach($links as $link) {
					$parsed = parse_url($link);
					// MATCH ANY AMAZON LINKS AND CREATE REPLACEMENTS
					if (preg_match('/(.*)amazon\.(com|co.uk|de|fr|co.jp|ca)+/i', $parsed['host'])) {
						$parsed['host'] = str_replace('www.','',$parsed['host']);
						$parsed['host'] = str_replace('amazon.','',$parsed['host']);
						// IF THE DOMAIN EXTENSION IS VALID
						if(isset($temp[$parsed['host']])) {
							$search[] = '<a href="'. $link. '"' ;
							$replace[] = '<a href="'. str_replace($parsed['host'], $modSettings['amazonlinksassociatestore'], $link) . ((strpos($link,'?') === FALSE) ? '?' : '&') .  'tag='. $modSettings['amazonlinksassociateid'].'"' ;
						}
					}
					// TIDY UP
					unset($parsed);
				}

 

No other parts of the modification mention "$parsed" so I believe the error is limited to these few lines and am guessing it's not coded properly. If anyone has any ideas how to fix this, please let me know. :) Thanks!

Link to comment
Share on other sites

I am not sure what you mean, but I did notice this is happening when someone views a page which contains a link that is not an amazon link, if they view a page with an amazon link in the post, no errors, and it works fines, but if I view a post with a link to anything else I get these errors.

 

I think it needs to be coded in what to do if it's a normal link and not an amazon link.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.