News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Amazon Affiliate Mods?

Started by dcr7, March 13, 2021, 06:52:53 PM

Previous topic - Next topic

dcr7

Are there any mods for, or is anyone working on a mod for, Amazon affiliate links?  Preferably one that will work with SMF 2.1.  All I've found are older ones.

Something like this:
https://custom.simplemachines.org/mods/index.php?mod=893

Note on the page says the mod was taken over by another user, but the link goes to an error page.

Kindred

That mod was for 1.1.x and never updated to 2.0.x
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

shadav

there's nothing for 2.1, there are 3 mods for 2.x that may or may not be updated when 2.1 is finalized
https://custom.simplemachines.org/mods/index.php?mod=1540
https://custom.simplemachines.org/mods/index.php?mod=1553
https://custom.simplemachines.org/mods/index.php?mod=1541

all 3 mods allow you to use your amazon affiliate link

if you are wanting to post like the links you get off of amazon into a post what I did was used
Personalized BBC (which says it works for 2.1 rc 2)
created a bbcode
<iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="{content}">
    </iframe>

and then on the code that amazon gives you remove everything before the src="
and only keep the part between the src=" and then the next "
paste that into your post and wrap it with whatever tags you used, I just used aa

so in the end it should look something like
[aa]//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=SOME NUMBERS AND MUMBO JUMBO HERE and your affiliate link&marketplace=amazon&region=SOME MORE MUMBO JUMBO HERE...all the way down til the part that says price_color=333333&title_color=c44e19&bg_color=ffffff[/aa]

I'm sure there's a better way, but I wasn't sure how amazon does all of it's links so this way there shouldn't be an issue since you're using the entire long link of theirs

szinski

I solved this issue by using some custom code that I wrote.

Edit Sources/Subs.php

Search for this:

        // Cleanup whitespace.
        $message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br />', '<br /> ' => '<br />&nbsp;', '&#13;' => "\n"));

And insert this below it:
        // Fix Amazon links (SCZ)
        if (preg_match_all('/<a href="([^"]+)/i', $message, $links))
        {
                // SKIP IF NO LINKS
                if (!empty($links))
                {
                        // REMOVE DUPLICATES/EMPTIES
                        $links = array_unique($links[1]);

                        // LOOP THROUGH EACH LINK
                        foreach($links as $link)
                        {
                                $parsed = parse_url($link);
                                if (isset($parsed['host']))
                                {
                                        // MATCH AMAZON.COM AND AMZN.COM LINKS
                                        if (preg_match('/(.*)(amazon|amzn)\.(com|co.uk|de|fr|co.jp|ca|cn|it|es|in)+/i', $parsed['host']))
                                        {
                                                $my = preg_match('/(\/(dp|gp\/product|exec\/obidos\/(ASIN|tg\/detail\/-))\/\w{10}\b)/i', $parsed['path'], $amazon_link);
                                                if (isset($amazon_link[1]))
                                                {
                                                        $product_link = $amazon_link[1];
                                                }
                                                else
                                                {
                                                        $my = preg_match('/^(\/\w{10}\b)/i', $parsed['path'], $amzn_link);
                                                        if (isset($amzn_link[1]))
                                                        {
                                                                $product_link = $amzn_link[1];
                                                        }
                                                }

                                                if (isset($product_link))
                                                {
                                                        $replace = 'https://' . $parsed['host'] . $product_link . '/?tag=myaffiliate-20';
                                                        $message = str_replace($link, $replace, $message);
                                                }
                                        }
                                }
                                unset($parsed, $product_link);
                        }
                }
        }

Don't forget to change "myaffiliate-20" to your own affiliate ID number.

I've tested this with both SMF 2.0 and SMF 2.1 and it works.

FYI, this code doesn't touch the underlying message as saved to the database, it converts Amazon links into shortened links with your affiliate ID appended to the end ON THE FLY (as the message is being displayed). If the OP edits the message, it will appear exactly as he typed it... the transformation happens when the message is displayed. Pretty clever if I don't say so myself. :)

Enjoy!

Advertisement: