--- ./lm_paypal_subscriptions.module 2009-01-03 08:09:35.000000000 -0500 +++ /usr/local/music/src/ardour/website/trunk/modules/lm_paypal/lm_paypal_subscriptions.module 2009-03-12 11:38:14.000000000 -0400 @@ -61,6 +61,7 @@ define('LM_PAYPAL_SUBSCRIPTIONS_STATUS_CANCELLED', 4); define('LM_PAYPAL_SUBSCRIPTIONS_STATUS_EOT', 5); define('LM_PAYPAL_SUBSCRIPTIONS_STATUS_BLOCKED', 6); +define('LM_PAYPAL_ANONYMOUS_UID', 0); /** * Initialize global variables. @@ -388,7 +389,9 @@ // I cannot tell if they are logged in or not .. so presume they are. $logged_in = TRUE; } - else { + else if ($user->uid == LM_PAYPAL_ANONYMOUS_UID) { + $logged_in = true; + } else { $logged_in = ($user->uid != 0); } @@ -557,26 +560,31 @@ $header = array(t('Name'), t('Description'), t('Action')); while ($so = db_fetch_object($subs)) { - $already = lm_paypal_user_subscribed($so->subid, $account); - $item_name = check_plain($so->item_name); - if ($already) { - $sub = t('already subscribed'); - } - else { - if (!$logged_in) { - $login = l(t('login'), 'user'); - $register = l(t('create new account'), 'user/register'); - $sub = t("You must !login or !register to subscribe", array("!login" => $login, "!register" => $register)); - } - else { - $sub = l( - t('subscribe'), - "lm_paypal/subscribe/$so->subid", - array('attributes' => array( - 'alt' => t('Link to the subscription page'), - 'title' => t('Click here to subscribe now!')))); - } + if ($user->uid == LM_PAYPAL_ANONYMOUS_UID) { + $sub = l(t('subscribe'), "lm_paypal/subscribe/$so->subid"); + } else { + $already = lm_paypal_user_subscribed($so->subid, $account); + + $item_name = check_plain($so->item_name); + if ($already) { + $sub = t('already subscribed'); + } + else { + if (!$logged_in) { + $login = l(t('login'), 'user'); + $register = l(t('create new account'), 'user/register'); + $sub = t("You must !login or !register to subscribe", array("!login" => $login, "!register" => $register)); + } + else { + $sub = l( + t('subscribe'), + "lm_paypal/subscribe/$so->subid", + array('attributes' => array( + 'alt' => t('Link to the subscription page'), + 'title' => t('Click here to subscribe now!')))); + } + } } $rows[] = array('data' => array( @@ -613,6 +621,10 @@ function lm_paypal_user_subscribed($subid, $account = NULL) { global $user; + if ($user->uid == LM_PAYPAL_ANONYMOUS_UID) { + return FALSE; + } + if (is_null($account)) { $uid = $user->uid; } @@ -657,6 +669,9 @@ */ function lm_paypal_can_subscribe($subid) { global $user; + if ($user->uid == LM_PAYPAL_ANONYMOUS_UID) { + return TRUE; + } if ($user->uid == 0 ) { return FALSE; } @@ -1854,14 +1869,15 @@ // if the subscription amount is zero (usually a trial period) lm_paypal_subscriber_set_status($ipn->subscr_id, LM_PAYPAL_SUBSCRIPTIONS_STATUS_LIVE); - if ($so->kind == 0) { + if ($uid != LM_PAYPAL_ANONYMOUS_UID && $so->kind == 0) { lm_paypal_user_gain_role($uid, $so->rid); } - else if ($so->kind == 2) { + else if ($uid != LM_PAYPAL_ANONYMOUS_UID && $so->kind == 2) { lm_paypal_user_gain_group($uid, $so->rid); } - if ($so->send_admin_onsub && is_numeric($so->uid_admin)) { + if ($uid != LM_PAYPAL_ANONYMOUS_UID && + $so->send_admin_onsub && is_numeric($so->uid_admin)) { // Email admin to let them know of a new subscriber // note: t() will be called inside lm_paypal_mail_user // Extra variables (in addition to the default ones provided) @@ -1879,7 +1895,7 @@ $variables); } - if ($so->send_user_onsub) { + if ($uid != LM_PAYPAL_ANONYMOUS_UID && $so->send_user_onsub) { // Email user to confirm a new subscriber // note: t() will be called inside lm_paypal_mail_user // Extra variables (in addition to the default ones provided) @@ -1971,14 +1987,15 @@ $status = ($end == 'eot' ? LM_PAYPAL_SUBSCRIPTIONS_STATUS_EOT : LM_PAYPAL_SUBSCRIPTIONS_STATUS_CANCEL); lm_paypal_subscriber_set_status($ipn->subscr_id, $status); - if ($so->kind == 0) { + if ($uid! = LM_PAYPAL_ANONYMOUS_UID && $so->kind == 0) { lm_paypal_user_loose_role($uid, $so->rid); } - else if ($so->kind == 2) { + else if ($uid != LM_PAYPAL_ANONYMOUS_UID && $so->kind == 2) { lm_paypal_user_loose_group($uid, $so->rid); } - if ($so->send_admin_onend && is_numeric($so->uid_admin)) { + if ($uid != LM_PAYPAL_ANONYMOUS_UID && + $so->send_admin_onend && is_numeric($so->uid_admin)) { // Email admin to let them know of an eot or cancellation // note: t() will be called inside lm_paypal_mail_user // Extra variables (in addition to the default ones provided) @@ -1996,7 +2013,7 @@ $variables); } - if ($so->send_user_onend) { + if ($uid != LM_PAYPAL_ANONYMOUS_UID && $so->send_user_onend) { // Email user to confirm an eot or cancellation // note: t() will be called inside lm_paypal_mail_user // Extra variables (in addition to the default ones provided)