We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13226
    • 953 Posts
    Using "/comments" as the AffiliateSuffix can't be the solution, as that is not the affiliate referal code.

    For ThemeForest the affiliate suffix should be in the format "?ref=AFFILIATENAME"

    I have other affiliate links that use "?" in the suffix that don't belong to ThemeForest

    What is strange is this doesn't always happen only when the link is encoded and special characters are changed

    Just for info, it doesn't matter if "LinkWeb" is used or the "LinkTv" + "AffiliateSuffix", they both give the same result.

    So in my opinion the current snippet code doesn't work 100% as is. Any ideas ?
      • 13226
      • 953 Posts
      If you try the same setup but use this link:
      themeforest.net/item/club-cube-responsive-modx-theme-for-night-club/9378054

      It all works, but I see no real difference, the characters in the renderred HTML have also been changed [ed. note: iusemodx last edited this post 11 years, 8 months ago.]
        • 2762
        • 1,198 Posts
        Tested - Really strange issue!! shocked

        note:
        Special Character are always changed.
        Check the original article:



        Usage
        In the above example, the URL I chose to encode is “http://ctrtard.com/” . The encoded version of this URL is this:

        aHR0cDovL2N0cnRhcmQuY29tLw%3D%3D
        So to use this, you’re link would be:

        http://yourdomain.com/store/?item=aHR0cDovL2N0cnRhcmQuY29tLw%3D%3D



          Free MODx Graphic resources and Templates www.tattoocms.it
          -----------------------------------------------------

          MODx IT  www.modx.it
          -----------------------------------------------------

          bubuna.com - Web & Multimedia Design
          • 13226
          • 953 Posts
          So why do the links not work then ?
            • 2762
            • 1,198 Posts
            Actually, I Really don't know.
            Seems an issue with the base64 encoding, but It makes no sense to me

            I'm not a coder (i've just ported the script) and I do not know much about base64 encoding.
              Free MODx Graphic resources and Templates www.tattoocms.it
              -----------------------------------------------------

              MODx IT  www.modx.it
              -----------------------------------------------------

              bubuna.com - Web & Multimedia Design
              • 13226
              • 953 Posts
              Ah, OK

              The company I use to do programming has closed for christmas - will have to wait till 2nd week in January then they are back.

              If it's an easy not to costly experience I will post the results if and when I get them to look at it.

              If someone here has time that would be great, but at the moment I think everyone is more in xmas feeling than work feeling smiley
                • 13226
                • 953 Posts
                So, am back with the solution that works - at least for me.

                Original code:
                $linkurl = "<a $linkelements target=\"$targetlink\" rel=\"nofollow\" href=\"$landingurl$dummyparams&$urlparam=$url\">$textlink</a>";


                Modified code:
                $linkurl = "<a $linkelements target=\"$targetlink\" rel=\"nofollow\" href=\"$landingurl?$dummyparams$urlparam=$url\">$textlink</a>";


                Note: the "&" has moved position and replaced with a "?" in the "href" - it's that simple

                The trick is actualy building a correct URL.

                If you use dummy parameters they need to be correclty set-up. If you use the following it won't build a correct url:

                &dummyparams=`&pid=[*id*]&alias=[*alias*]`
                
                Results in:
                
                domain.com/?&pid=10&alias=myaliasmyurlparameter=BASE64URL


                Using this code it will work perfectly:

                &dummyparams=`pid=[*id*]&alias=[*alias*]&`


                Note the "&pid" has changed to "pid" and the "&" is now at the end. This would give out a url as follows:

                domain.com/?pid=10&alias=myalias&myurlparameter=BASE64CODEDURL
                [ed. note: iusemodx last edited this post 11 years, 8 months ago.]
                  • 4041
                  • 788 Posts
                  Add the following to the top of the snippet code, then change the $linkurl like below. This will automatically determine whether or not friendly urls are on or not, and add the appropriate symbol without needing to hardcode it.

                  // create the url seperator
                  $url_sep = $modx->config['friendly_urls'] =='0' ? '&' : '?';
                  


                  $linkurl = "<a $linkelements target=\"$targetlink\" rel=\"nofollow\" href=\"$landingurl$url_sep$dummyparams$urlparam=$url\">$textlink</a>";
                  
                  [ed. note: breezer last edited this post 11 years, 8 months ago.]
                    xforum
                    http://frsbuilders.net (under construction) forum for evolution
                    • 13226
                    • 953 Posts
                    @Breezer

                    Nice job, to differentiate between "&" (non furls) + "?" (furls)

                    But, you still have to know what you are doing when it comes to the dummy parameters

                    This won't work either with or without FURLS in the current "href" setup:
                    &dummyparams=`&pid=[*id*]&alias=[*alias*]`

                    This will work:
                    &dummyparams=`pid=[*id*]&alias=[*alias*]&`



                    If the "href" changes from:
                    href=\"$landingurl$url_sep$dummyparams$urlparam=$url\"

                    To:
                    href=\"$landingurl$url_sep$urlparam=$url$dummyparams\"


                    This will work either with or without FURLS:
                    &dummyparams=`&pid=[*id*]&alias=[*alias*]`

                    This won't work:
                    &dummyparams=`pid=[*id*]&alias=[*alias*]&`



                    Either way - the dummy parameters must be tested before publishing to a live site
                      • 13226
                      • 953 Posts
                      My versions updated code to 1.0.3

                      // CloakLinks 1.0.3
                      // author: by Nicola Lambathakis
                      // credits: http://ctrtard.com/affiliate-marketing/better-affiliate-link-cloaking-for-seo/
                      // Contributors: iusemodx, breezer
                      // 
                      // method 1: using a template variable [!CloakLinks? &landing=`49` &textlink=`site preview` &LinkTv=`AffiliateLink`!]
                      // method 1 + custom url parameter [!CloakLinks? &landing=`49` &urlparam=`visit` &textlink=`site preview` &LinkTv=`AffiliateLink`!]
                      // method 2 [!CloakLinks? &landing=`49` &textlink=`site preview` &LinkWeb=`http://modx.com/`!]
                      // 
                      // $url_sep differentiates between "&" (non furls) and "?" (furls)
                      // 
                      // Parameters:
                      // &textlink = text placeholder | default value: "Go to the website"
                      // &targetlink = href target attribute | default value: "_blank"
                      // &landing = resource id of the landing page for redirect (must contain a [[CloakLinksRedirect]] snippet call)
                      // &LinkTv = (method 1) name of the Text template variable containing the affiliate link
                      // &LinkWeb = (method 2) full affiliate link
                      // &AffiliateSuffix = link suffix for affiliate code (ie: 123456789 or [*affiliatecodetv*])
                      // &urlparam = custom parameter url | default value: "goto"
                      // &linkelements = allows the addition of extras like class, title etc.
                      // &dummyparams = "Dummy" parameters e.g. &dummyparams=`pid=[*id*]&alias=[*alias*]&`
                      // &ErrorEmptyLink = text placeholder for empty tv and/or missing linkweb parameter | default value: "Empty Link"
                      
                      $url_sep = $modx->config['friendly_urls'] =='0' ? '&' : '?';
                      $textlink = isset ($textlink) ? $textlink : "Go to the website";
                      $linkelements = isset ($linkelements) ? $linkelements : "";
                      $dummyparams = isset ($dummyparams) ? $dummyparams : "";
                      $targetlink = isset ($targetlink) ? $targetlink : "_blank";
                      $landing = isset ($landing) ? $landing : "[*id*]";
                      $landingurl = ($modx->makeUrl($landing, '', '', 'full'));
                      $LinkWeb = isset($LinkWeb) ? $LinkWeb : '';
                      $LinkTv = isset($LinkTv) ? $LinkTv : '';
                      $AffiliateSuffix = isset($AffiliateSuffix) ? $AffiliateSuffix : '';
                      $ErrorEmptyLink = isset($ErrorEmptyLink) ? $ErrorEmptyLink : "Empty Link";
                      $urlparam = isset($urlparam) ? $urlparam : "goto";
                       
                         
                      if($LinkTv == ""){
                      $url = $LinkWeb.$AffiliateSuffix;
                      } else {
                      $Link = $modx->getTemplateVarOutput(''.$LinkTv.'',$id);
                      $url = $Link[''.$LinkTv.''].$AffiliateSuffix;
                      }
                         
                      $url = base64_encode($url);
                      $url = urlencode($url);
                         
                      $linkurl = "<a $linkelements target=\"$targetlink\" rel=\"nofollow\" href=\"$landingurl$url_sep$dummyparams$urlparam=$url\">$textlink</a>";
                         
                      if($LinkTv == "" && $LinkWeb == ""){
                      echo $ErrorEmptyLink;
                      } else {
                      echo $linkurl;
                      }