Community Support Forums — WordPress® ( Users Helping Users ) — 2011-08-24T05:56:41-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=1636 2011-08-24T05:56:41-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=32776#p32776 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> Statistics: Posted by Cristián Lávaque — August 24th, 2011, 5:56 am


]]>
2011-08-24T05:40:15-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=32775#p32775 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
What do you think could be causing this?

Statistics: Posted by Cristián Lávaque — August 24th, 2011, 5:40 am


]]>
2011-08-10T22:07:05-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30480#p30480 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>

Statistics: Posted by Cristián Lávaque — August 10th, 2011, 10:07 pm


]]>
2011-08-10T20:57:53-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30475#p30475 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> Statistics: Posted by Jason Caldwell — August 10th, 2011, 8:57 pm


]]>
2011-08-10T18:53:25-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30462#p30462 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
Code:
// Shorten registration link.
add_filter('ws_plugin__s2member_register_link_gen_alternative''s2_alt_shorten_link');
function 
s2_alt_shorten_link($link)
{
    if (
$_GET['s2member_paypal_proxy'] === 'clickbank')
    {
        
$id = (!empty($_POST['txn_id']) ?
            
$_POST['txn_id']
        : (!empty(
$_POST['payer_email']) ?
            
md5($_POST['payer_email'])
        : (!empty(
$_POST['subscr_id']) ?
            
$_POST['subscr_id']
        : 
            
time()
        )));

        return 
c_ws_plugin__s2member_utils_urls::remote('http://example.com/go/yourls-api.php?signature=xxxxxxxx&action=shorturl&format=simple&keyword=register-' $id '&url=' rawurlencode($link));
    }
}
 

Statistics: Posted by Cristián Lávaque — August 10th, 2011, 6:53 pm


]]>
2011-08-10T18:23:37-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30454#p30454 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
Code:
$id = !empty($_POST['txn_id']) ?
            $_POST['txn_id']
        : !empty($_POST['payer_email']) ?
            md5($_POST['payer_email'])
        : !empty($_POST['subscr_id']) ?
            $_POST['subscr_id']
        : time(); 

It is recommended that you avoid "stacking" ternary expressions. PHP's behaviour when using more than one ternary operator within a single statement is non-obvious. See details here: http://php.net/manual/en/language.opera ... arison.php

While the article above discourages this, you will find that I DO this even so. However, when I do this, I always wrap the second and/or third ternary expressions inside brackets () so that I get the actual return value of that sub-ternary expression, for lack of a better term. In cases where I'm checking for more than two or three conditions, I may expand it out of a ternary expression and into a switch or if/else.

The behavior of ternary expressions is NOT desirable in PHP, in this regard; especially since it conflicts with the way they are handled in JavaScript. Your code would be fine in JavaScript.

Statistics: Posted by Jason Caldwell — August 10th, 2011, 6:23 pm


]]>
2011-08-10T18:08:01-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30448#p30448 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
Code:
// Shorten registration link.
add_filter('ws_plugin__s2member_register_link_gen_alternative', 's2_alt_shorten_link');
function s2_alt_shorten_link($link)
{
    if ($_GET['s2member_paypal_proxy'] === 'clickbank')
    {
        $id = !empty($_POST['txn_id']) ?
            $_POST['txn_id']
        : !empty(
$_POST['payer_email']) ?
            
md5($_POST['payer_email'])
        : !empty($_POST['subscr_id']) ?
            $_POST['subscr_id']
        : time();

        return c_ws_plugin__s2member_utils_urls::remote('http://example.com/go/yourls-api.php?signature=xxxxxxxx&action=shorturl&format=simple&keyword=register-' . $id . '&url=' . rawurlencode($link));
    }
}
 

Statistics: Posted by Cristián Lávaque — August 10th, 2011, 6:08 pm


]]>
2011-08-10T16:48:27-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30444#p30444 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
I'll just go through the variables until finding one that exists and if nothing is avaialble, will default to uniqid or time.

Statistics: Posted by Cristián Lávaque — August 10th, 2011, 4:48 pm


]]>
2011-08-10T16:41:17-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30442#p30442 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
Other unique identifiers might include the User's IP address, which is held inside $_POST["option_selection2"]

Statistics: Posted by Jason Caldwell — August 10th, 2011, 4:41 pm


]]>
2011-08-10T16:21:44-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30435#p30435 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
Are $_POST['subscr_id'] or $_POST['payer_email'] only available if $_POST['txn_id'] is, or could it be that txn_id is not there but one of subscr_id is?

I'm guessing that payer_email would be the most reliable one, is that correct? If so, I could md5($_POST['payer_email']) or some other one that outputs less characters (do you know one?).

Statistics: Posted by Cristián Lávaque — August 10th, 2011, 4:21 pm


]]>
2011-08-10T15:16:50-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30428#p30428 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> $_POST['subscr_id'] or $_POST['payer_email']
Short of that, you could generate your own with uniqid().
http://php.net/manual/en/function.uniqid.php

Statistics: Posted by Jason Caldwell — August 10th, 2011, 3:16 pm


]]>
2011-08-10T12:59:23-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30400#p30400 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> Statistics: Posted by Cristián Lávaque — August 10th, 2011, 12:59 pm


]]>
2011-08-10T12:55:04-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30398#p30398 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>

Is it safe to assume that after a ClickBank purchase $_POST['txn_id'] will always be set and with the receipt code?
Yes, in the current release it is safe to assume this. I'd still check for it though, just in case something changes in a future release, it will help to safeguard your custom routine a bit.

Statistics: Posted by Jason Caldwell — August 10th, 2011, 12:55 pm


]]>
2011-08-08T02:15:17-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=30160#p30160 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
Code:
// Shorten registration link.
add_filter('ws_plugin__s2member_register_link_gen_alternative', 's2_alt_shorten_link');
function s2_alt_shorten_link($link)
{
    if ($_GET['s2member_paypal_proxy'] === 'clickbank')
    {
        return c_ws_plugin__s2member_utils_urls::remote('http://example.com/go/yourls-api.php?signature=xxxxxxxx&action=shorturl&format=simple&keyword=register-' . $_POST['txn_id'] . '&url=' . rawurlencode($link));
    }
}
 


Is it safe to assume that after a ClickBank purchase $_POST['txn_id'] will always be set and with the receipt code?

This would create URLs like http://example.com/go/register-8KR7BXRE. Knowing the ClickBank receipt code, it will be easy to give the user his registration URL again if he lost it.

Statistics: Posted by Cristián Lávaque — August 8th, 2011, 2:15 am


]]>
2011-03-11T12:44:07-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7719#p7719 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>

Statistics: Posted by Cristián Lávaque — March 11th, 2011, 12:44 pm


]]>
2011-03-11T05:53:42-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7706#p7706 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
clavaque wrote:
Great! That way we won't have to re-apply the hack after each s2Member update. :)

Is there any way I can get the ClickBank transaction receipt number in the s2hacks.php file for this?

Although s2Member Pro initially deals with ClickBank IPNs through a dedicated handler, these ClickBank IPNs are reformulated internally by s2Member Pro, and the ClickBank Receipt # ultimately comes through s2Member's core PayPal processor as the $_POST["txn_id"] variable.

So if you really need to, you can use some of the Hooks/Filters made available inside: /s2member/includes/classes/paypal-notify-in.inc.php. You're looking for $paypal["txn_id"] in that file.

To answer your question. Here is how I would do it in the context of these Filters.
Code:
<?php
add_filter 
("ws_plugin__s2member_register_link_gen_alternative", "my_link_shortener");
add_filter ("ws_plugin__s2member_sp_access_link_gen_alternative", "my_link_shortener");
function my_link_shortener ($long_link) /* Raw link ( the long version ). */
    {
        if($_GET["s2member_paypal_proxy"] === "clickbank" && $_POST["txn_id"])
            { $clickbank_receipt_number = $_POST["txn_id"]; }
            
        return 
/* Shorten this */ $long_link;
    }
?>

Statistics: Posted by Jason Caldwell — March 11th, 2011, 5:53 am


]]>
2011-03-10T18:11:13-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7700#p7700 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> Statistics: Posted by lewayotte — March 10th, 2011, 6:11 pm


]]>
2011-03-10T15:15:53-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7684#p7684 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>

Is there any way I can get the ClickBank transaction receipt number in the s2hacks.php file for this?

Statistics: Posted by Cristián Lávaque — March 10th, 2011, 3:15 pm


]]>
2011-03-10T14:52:29-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7677#p7677 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> Great work guys. Thank you for sharing.

Starting with s2Member v3.5.3 we'll add two additional Filters.
1. ws_plugin__s2member_register_link_gen_alternative ( Membership Access )
2. ws_plugin__s2member_sp_access_link_gen_alternative ( Specific Post/Page Access )

So starting with s2Member v3.5.3+, you can do something like this.

1. Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( file name is not important )

2. Do something like this to your hacks file.
Code:
<?php
add_filter 
("ws_plugin__s2member_register_link_gen_alternative", "my_link_shortener");
add_filter ("ws_plugin__s2member_sp_access_link_gen_alternative", "my_link_shortener");
function my_link_shortener ($long_link) /* Raw link ( the long version ). */
    {
        return /* Shorten this */ $long_link;
    }
?>
In a later release, I'll see if we can add some additional pre-integrated alternatives into the Dashboard for s2Member Pro. I'm a Google® fan myself. http://goo.gl/

( Google API docs: http://code.google.com/apis/urlshortene ... arted.html ) This is still in Labs though.

Statistics: Posted by Jason Caldwell — March 10th, 2011, 2:52 pm


]]>
2011-03-02T17:43:14-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7331#p7331 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>

Since I'll be using them for other links, not just registration ones, I didn't name the YOURLS directory "reg" or something similar, instead I'm using the keyword parameter when shortening the URL. Because I need to make the URLs unique, I also added time() to the keyword.

And because the domain name now is my own, I removed the anchor with the domain name that s2Member adds by default to TinyURLs.

Code:
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::remote ('http://**********.com/go/yourls-api.php?signature=**********&action=shorturl&format=simple&keyword=register-' . time() . '&url=' . rawurlencode ($register_link))))
    return apply_filters ("ws_plugin__s2member_register_link_gen", $tinyurl, get_defined_vars ()); 


Which ouputs something like: http://**********.com/go/register-1299104688

I'd much rather use the ClickBank transaction receipt number, but don't know how to get it. In the IPN log it's named ctransreceipt. Any idea how I can get that into the URL?

Statistics: Posted by Cristián Lávaque — March 2nd, 2011, 5:43 pm


]]>
2011-03-01T19:59:16-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7289#p7289 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]> functions directory any more, now it's under classes and the line we've been quoting is now slightly different:

Code:
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::remote ("http://tinyurl.com/api-create.php?url=" . rawurlencode ($register_link)))) 


This is most probably because of the speed optimizations in the latest releases.

Now, thinking about it further, it may not even be necessary to have a function to abstract the url shrinking service, a variable may be enough:

Code:
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::remote ($shrink_service . rawurlencode ($register_link)))) 


With $shrink_service being easy to change into another one without touching s2Member's code.

But it may be even better to have the function after all, cause then you'd write less each time you need to shrink a URL and whatever improvement/change is done to that code, happens in a single place:

Code:
if ($shrink && ($tinyurl = c_ws_plugin__s2member_utils_urls::shrink ($register_link))) 

Statistics: Posted by Cristián Lávaque — March 1st, 2011, 7:59 pm


]]>
2011-03-01T19:13:28-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7287#p7287 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
I guess we're both asking for the same with a slightly different approach. :)

Statistics: Posted by Cristián Lávaque — March 1st, 2011, 7:13 pm


]]>
2011-03-01T19:09:47-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7286#p7286 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
My diff included has the apply_filter because if they include it in the source, it is a way of changing the shortening URL without changing the source... is that circular?

What I mean is, if they (PrimoThemes) included my diff into their code, then we'd just need to have my code in the functions.php file to overwrite that setting.

Lew

Statistics: Posted by lewayotte — March 1st, 2011, 7:09 pm


]]>
2011-03-01T18:46:04-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=7284#p7284 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>
My problem is that editing register-access.inc.php like that will make me have to re-apply the edits after an s2Member update.

Is there any way to edit that code in a way that it'll keep working after an update?

Looking at the line you're quoting, I think that instead of having the TinyURL URL hardcoded in the function, it should be something more abstratct that'll allow using other services with ease.

Maybe having an s2member_url_shrink($url) function that we can edit easily and will change the behaviour in the different places where URLs are shrunk.

In that function we can have a variable for the shrinking service's URL part before the URL to shrink, like:

http://tinyurl.com/api-create.php?url=
http://leenk.me/reg/yourls-api.php?sign ... imple&url=

and any other shortening service.

Now, if you went and edited the register-access.inc.php, why didn't you just change the shortening service URL directly instead of using the apply_filter() function, etc.? Like this

Code:
if ($shrink && ($tinyurl = ws_plugin__s2member_remote ('http://leenk.me/reg/yourls-api.php?signature=XXXXXXXX&action=shorturl&format=simple&url=' . rawurlencode ($register_link)))) 


Would that not work?

Statistics: Posted by Cristián Lávaque — March 1st, 2011, 6:46 pm


]]>
2011-01-15T15:33:01-05:00 http://www.primothemes.com/forums/viewtopic.php?t=1636&p=5632#p5632 <![CDATA[Re: URL Shortener WP Filter (DIFF Attached)]]>

Statistics: Posted by Cristián Lávaque — January 15th, 2011, 3:33 pm


]]>