diff -cr lm_paypal.orig/lm_paypal.admin.inc lm_paypal/lm_paypal.admin.inc *** lm_paypal.orig/lm_paypal.admin.inc 2009-04-04 16:29:56.000000000 +0000 --- lm_paypal/lm_paypal.admin.inc 2010-01-25 21:34:38.000000000 +0000 *************** *** 44,49 **** --- 44,77 ---- '#description' => t('Maximum age of an old IPN record in hours before it is deleted. Type 0 if you want to keep them forever.'), ); + $form['lm_paypal_cron_publish'] = array( + '#type' => 'checkbox', + '#title' => t('Cron Publish nodes'), + '#default_value' => variable_get('lm_paypal_cron_publish', FALSE), + '#description' => t('Normally you must set the workflow for your node types to "Published". Using this option you can set them to "unPublished". The cron process will publish them after payment is made and unpublish them when they expire.'), + ); + + $form['lm_paypal_expire_fudge'] = array( + '#type' => 'checkbox', + '#title' => t('Expire fudge'), + '#default_value' => variable_get('lm_paypal_expire_fudge', FALSE), + '#description' => t('Add a 24 hour fudge to the expire time. Use if the cron runs only once per day or if you are using varnish or another cache server that only expires cache once per day.'), + ); + + $form['lm_paypal_prefix_nid'] = array( + '#type' => 'checkbox', + '#title' => t('Prefix node id'), + '#default_value' => variable_get('lm_paypal_prefix_nid', FALSE), + '#description' => t('Prefix paypal item description with node id. ie: 312/item description'), + ); + + $form['lm_paypal_prefix_hostname'] = array( + '#type' => 'checkbox', + '#title' => t('Prefix hostname'), + '#default_value' => variable_get('lm_paypal_prefix_hostname', FALSE), + '#description' => t('Prefix paypal item description with hostname. ie: hostname/item description'), + ); + $form['lm_paypal_obey_test_ipns'] = array( '#type' => 'checkbox', '#title' => t('LM PayPal Obey Test IPNS'), diff -cr lm_paypal.orig/lm_paypal.info lm_paypal/lm_paypal.info *** lm_paypal.orig/lm_paypal.info 2009-05-31 00:14:04.000000000 +0000 --- lm_paypal/lm_paypal.info 2010-01-23 20:23:41.000000000 +0000 *************** *** 6,12 **** ; Information added by drupal.org packaging script on 2009-05-31 ! version = "6.x-2.x-dev" core = "6.x" project = "lm_paypal" datestamp = "1243728844" --- 6,12 ---- ; Information added by drupal.org packaging script on 2009-05-31 ! version = "6.x-2.x-dev-k" core = "6.x" project = "lm_paypal" datestamp = "1243728844" diff -cr lm_paypal.orig/lm_paypal.install lm_paypal/lm_paypal.install *** lm_paypal.orig/lm_paypal.install 2009-01-05 11:53:16.000000000 +0000 --- lm_paypal/lm_paypal.install 2010-01-25 18:23:11.000000000 +0000 *************** *** 25,30 **** --- 25,33 ---- drupal_uninstall_schema('lm_paypal'); variable_del('lm_paypal_debug'); variable_del('lm_paypal_host'); + variable_del('lm_paypal_cron_publish'); + variable_del('lm_paypal_prefix_nid'); + variable_del('lm_paypal_prefix_hostname'); variable_del('lm_paypal_business'); variable_del('lm_paypal_obey_test_ipns'); variable_del('lm_paypal_ipns_max_age'); diff -cr lm_paypal.orig/lm_paypal.ipn.inc lm_paypal/lm_paypal.ipn.inc *** lm_paypal.orig/lm_paypal.ipn.inc 2009-04-04 15:03:11.000000000 +0000 --- lm_paypal/lm_paypal.ipn.inc 2010-01-25 23:00:35.000000000 +0000 *************** *** 8,13 **** --- 8,14 ---- * IPN is present as a form submission which this routine unravels and saves for * processing. */ + function lm_paypal_ipn_in() { // file_put_contents('/tmp/ipn-post.txt', serialize($_POST)); watchdog(LM_PAYPAL, 'lm_paypal_ipn_in called', NULL); *************** *** 32,38 **** } } - $validated = _lm_paypal_validate_ipn($_POST); // Sanitize and remove risky fields from $_POST to make it suitable for --- 33,38 ---- *************** *** 46,52 **** $wr = drupal_write_record('lm_paypal_ipns', $ipn); if ($wr == SAVED_NEW) { $last = $ipn['id']; ! watchdog(LM_PAYPAL, 'lm_paypal_ipn_in $last = '. $ipn['id'], NULL); $link = l(t('view'), "admin/settings/lm_paypal/id/$ipn[id]"); if ($validated) { --- 46,52 ---- $wr = drupal_write_record('lm_paypal_ipns', $ipn); if ($wr == SAVED_NEW) { $last = $ipn['id']; ! watchdog(LM_PAYPAL, 'lm_paypal_ipn_in $last = '. $ipn['id'], array(),NULL); $link = l(t('view'), "admin/settings/lm_paypal/id/$ipn[id]"); if ($validated) { *************** *** 78,83 **** --- 78,86 ---- * The id of the saved IPN to be processed. */ function lm_paypal_process_in($ipn) { + + watchdog(LM_PAYPAL, 'lm_paypal_ipn_proccess_in called', NULL); + $business = lm_paypal_api_get_business(); $link = l(t('view'), "admin/settings/lm_paypal/id/$ipn->id"); *************** *** 104,111 **** --- 107,119 ---- // Additionally, IPNs are displatched to a txn_type-specific hook. $txn_type = preg_replace('/[^a-z0-9_]*/', '', $ipn->txn_type); + + watchdog(LM_PAYPAL, 'type --- %type',array('%type' => $ipn->txn_type)); + $results2 = module_invoke_all('lm_paypal_ipn_' . $txn_type, $ipn); + lm_paypal_mark_processed($ipn); + // Determine whether _some_ module handled the IPN, and warn if not. $processed = FALSE; foreach ($results1 as $res) { *************** *** 184,200 **** function lm_paypal_lm_paypal_ipn_web_accept($ipn) { // error_log("Called lm_paypal_lm_paypal_ipn_web_accept($ipn->txn_id)"); _lm_paypal_process_in_web_accept($ipn); return TRUE; } - - /** * Process a newly arrived web_accept IPN message * * @param $ipn */ function _lm_paypal_process_in_web_accept($ipn) { $debug = variable_get('lm_paypal_debug', LM_PAYPAL_DEBUG_DEFAULT); if ($debug) { watchdog(LM_PAYPAL, 'in_web_accept'); --- 192,208 ---- function lm_paypal_lm_paypal_ipn_web_accept($ipn) { // error_log("Called lm_paypal_lm_paypal_ipn_web_accept($ipn->txn_id)"); _lm_paypal_process_in_web_accept($ipn); + return TRUE; } /** * Process a newly arrived web_accept IPN message * * @param $ipn */ function _lm_paypal_process_in_web_accept($ipn) { + $debug = variable_get('lm_paypal_debug', LM_PAYPAL_DEBUG_DEFAULT); if ($debug) { watchdog(LM_PAYPAL, 'in_web_accept'); *************** *** 203,209 **** $link = l(t('view'), "admin/settings/lm_paypal/id/$ipn->id"); if (lm_paypal_already_processed($ipn->txn_id)) { ! watchdog( LM_PAYPAL, 'This transaction has already been processed, ignored: %id', array('%id' => check_plain($ipn->txn_id)), --- 211,217 ---- $link = l(t('view'), "admin/settings/lm_paypal/id/$ipn->id"); if (lm_paypal_already_processed($ipn->txn_id)) { ! watchdog( LM_PAYPAL, 'This transaction has already been processed, ignored: %id', array('%id' => check_plain($ipn->txn_id)), *************** *** 212,218 **** return; } ! lm_paypal_mark_processed($ipn); if ($ipn->payment_status == 'Pending') { watchdog( --- 220,226 ---- return; } ! //lm_paypal_mark_processed($ipn); if ($ipn->payment_status == 'Pending') { watchdog( *************** *** 224,229 **** --- 232,238 ---- return; } + $custom = lm_paypal_unpack_ipn_custom($ipn); $uid = $custom['uid']; $other = $custom['other']; *************** *** 327,332 **** --- 336,342 ---- } } + return; /* // Find the correct web_accept processor $ranges = lm_paypal_web_accept_register(); diff -cr lm_paypal.orig/lm_paypal.module lm_paypal/lm_paypal.module *** lm_paypal.orig/lm_paypal.module 2009-05-30 17:05:54.000000000 +0000 --- lm_paypal/lm_paypal.module 2010-01-25 22:59:08.000000000 +0000 *************** *** 125,130 **** --- 125,133 ---- * Implementation of hook_cron(). */ function lm_paypal_cron() { + + process_subscribers(); + _lm_paypal_clean_stored_ipns(); } *************** *** 309,316 **** --- 312,321 ---- } function _lm_paypal_clean_stored_ipns() { + $ipns_max_age = (int) variable_get('lm_paypal_ipns_max_age', LM_PAYPAL_IPNS_MAX_AGE_DEFAULT); // Do not launch this action if no max age is specified (keep for ever). + if ($ipns_max_age > 0) { if (lm_paypal_debug()) { watchdog(LM_PAYPAL, 'cron'); *************** *** 320,325 **** --- 325,408 ---- } } + function lm_paypal_cron_publish() { + return (bool) variable_get('lm_paypal_cron_publish', FALSE); + } + + function lm_paypal_expire_fudge() { + return (bool) variable_get('lm_paypal_expire_fudge', FALSE); + } + + function lm_paypal_prefix_nid() { + return (bool) variable_get('lm_paypal_prefix_nid', FALSE); + } + + function lm_paypal_prefix_hostname() { + return (bool) variable_get('lm_paypal_prefix_hostname', FALSE); + } + + function process_subscribers() { + + watchdog(LM_PAYPAL,"cron process_subscribers node"); + + $sql = "SELECT * from {lm_paypal_subscribers} where status = '1'"; + $result = db_query($sql); + if (! $result) { + watchdog(LM_PAYPAL,"no subscribers to process"); + } + while ($ss = db_fetch_object($result)) { + + $so = lm_paypal_subscriptions_load_subscription($ss->subid); + + $expires = lm_paypal_expire_date($ss->subid,$ss->started); + + $dt = date('m/d/y',$expires); + + watchdog(LM_PAYPAL,"node %nid - expires %expires",array('%nid' => $ss->nid, '%expires' => $dt)); + + $status=1; + if (time() > $expires) { + $status=0; //unpublish this node if expired. + } + + if (lm_paypal_cron_publish()) { + if ($ss->nid != 0) { + $node=node_load($ss->nid); + if ($status != $node->status) { + $node->status=$status; + $node = node_submit($node); + + if ($node->validated) { + node_save($node); + } else { + watchdog(LM_PAYPAL,"cron FAILED SAVE node: %nid - %title",array('%nid' => $node->nid, '%title' =>$node->title)); + } + } + } + } + + if ($status != 1) { + $sql = "UPDATE {lm_paypal_subscribers} SET status = 5 WHERE subscr_id = '%s'"; + $result = db_query($sql, $ss->subscr_id); + + if (! $result) { + watchdog(LM_PAYPAL,"failed subscriber update"); + } + + if ($so->kind == 0) { + lm_paypal_subscriptions_user_loose_role($ss->uid, $so->rid); + $variables = array('%Subscription' => $so->item_name, '%Days' => $so->nearend_days, '%Node' => ''); + } else { + if ($so->kind == 2) lm_paypal_subscriptions_user_loose_group($ss->uid, $so->rid); + $variables = array('%Subscription' => $so->item_name, '%Days' => $so->nearend_days, '%Node' => $node); + } + + lm_paypal_mail_user($ss->uid, $ss->uid, $so->send_user_onend_subject, $so->send_user_onend_body, $variables); + } + + } + } + /** * Default return_path for paypal. * *************** *** 525,530 **** --- 608,614 ---- '#value' => isset($options['item_name']) ? check_plain($options['item_name']) : t('Donation'), '#name' => 'item_name', ); + $form['item_number'] = array( '#type' => 'hidden', '#value' => isset($options['item_number']) ? ((int) $options['item_number']) : 0, *************** *** 593,599 **** --- 677,690 ---- if (empty($custom) || is_array($custom)) { $custom = array(); } + $custom['module'] = LM_PAYPAL_SUBSCRIPTIONS; $custom['uid'] = $user->uid; + $nid=request_uri(); + $nid=str_replace("/lm_paypal","",$nid); + if (strpos($nid,"/node/") !== false) { + $custom['nid'] = str_replace("/node/","",$nid); + } + $form['custom'] = array( '#type' => 'hidden', '#value' => serialize($custom), *************** *** 894,925 **** * a better way around this but there was nothing mentioned in the * documentation.) */ ! function lm_paypal_mail_user($to_uid, $about_uid, $subject, $message, $vars) { // TODO: use Token module global $base_url; if (lm_paypal_debug()) { ! watchdog(LM_PAYPAL, "lm_paypal_mail_user($to_uid, $about_uid, $subject, $message, $vars)", NULL); } $to_account = user_load(array('uid' => $to_uid, 'status' => 1)); $to = $to_account->mail; $about_user = user_load(array('uid' => $about_uid, 'status' => 1)); ! //TODO: Maybe use the subscription adminstrators email instead? $from = variable_get('site_mail', ini_get('sendmail_from')); $variables = array( '%Username' => $about_user->name, '%Login' => $about_user->login, ! '%Site' => variable_get('site_name', 'drupal'), '%Uri' => $base_url, '%Uri_brief' => substr($base_url, strlen('http://')), '%Mailto' => $to, ! '%Date' => format_date(time()), ); ! $variables = $variables + $vars; $body = strtr(t($message), $variables); $subject = strtr(t($subject), $variables); --- 985,1021 ---- * a better way around this but there was nothing mentioned in the * documentation.) */ ! function lm_paypal_mail_user($to_uid, $about_uid, $subject, $message, &$vars = array()) { // TODO: use Token module global $base_url; if (lm_paypal_debug()) { ! watchdog(LM_PAYPAL, "lm_paypal_mail_user(%tuid, %auid, %sub, %msg, %vars)", array('%tuid' => $to_uid,'%auid' => $about_uid, '%sub' => $subject, '%msg' => $message, '%vars' => $vars)); } $to_account = user_load(array('uid' => $to_uid, 'status' => 1)); $to = $to_account->mail; $about_user = user_load(array('uid' => $about_uid, 'status' => 1)); ! //TODO: Maybe use the subscription adminstrators email instead? $from = variable_get('site_mail', ini_get('sendmail_from')); + $site_name = ( variable_get('site_name', false ) ? ' ('. variable_get('site_name', '') .')' : '' ); + $variables = array( '%Username' => $about_user->name, '%Login' => $about_user->login, ! '%Site' => $site_name, '%Uri' => $base_url, '%Uri_brief' => substr($base_url, strlen('http://')), '%Mailto' => $to, ! '%Date' => format_date(time()) ); ! $variables = array_merge($variables, $vars); ! ! $body = str_replace("%site","%Site",$body); ! $subject = str_replace("%site","%Site",$subject); $body = strtr(t($message), $variables); $subject = strtr(t($subject), $variables); *************** *** 976,978 **** --- 1072,1085 ---- return array(); } } + + function lm_paypal_expire_date($subid,$started) { + + $so = lm_paypal_subscriptions_load_subscription($subid); + $fudge = 0; + if (lm_paypal_expire_fudge()) $fudge = 1; // 24 hour fudge to allow cron to run or boost and varnish to clear. + $expires = $started + $fudge + lm_paypal_subscription_days($so) * 3600*24; + + return $expires; + + } diff -cr lm_paypal.orig/lm_paypal_paid_adverts/lm_paypal_paid_adverts.module lm_paypal/lm_paypal_paid_adverts/lm_paypal_paid_adverts.module *** lm_paypal.orig/lm_paypal_paid_adverts/lm_paypal_paid_adverts.module 2009-04-17 00:33:46.000000000 +0000 --- lm_paypal/lm_paypal_paid_adverts/lm_paypal_paid_adverts.module 2010-01-25 18:49:12.000000000 +0000 *************** *** 36,41 **** --- 36,42 ---- $cache[$object->node_type][$object->subid] = $object->subid; } } + if ($node_type) { return isset($cache[$node_type]) ? $cache[$node_type] : array(); } *************** *** 76,82 **** */ function lm_paypal_paid_adverts_type_is_handled($node_type) { $live = lm_paypal_paid_adverts_get_live_subscriptions($node_type); ! return ! empty($live); } /** --- 77,83 ---- */ function lm_paypal_paid_adverts_type_is_handled($node_type) { $live = lm_paypal_paid_adverts_get_live_subscriptions($node_type); ! return (!empty($live)); } /** *************** *** 104,110 **** // Does this node type have a PayPal subscription associated with it if (is_array($ts) && count($ts) > 0) { // It does so print some help ! $output = '
'. t('Not yet paid for. To make this article viewable by others you need to pay with PayPal. Please take out ONE of the subscriptions below.') .'
'; $type_subs = lm_paypal_paid_adverts_get_live_subscriptions(); if (! empty($type_subs[$node->type])) foreach ($type_subs[$node->type] as $subid => $enabled) { if ($enabled) { require_once(drupal_get_path('module', 'lm_paypal_subscriptions').'/lm_paypal_subscriptions.pages.inc'); $output .= lm_paypal_subscribe_subscription($subid, 15, NULL, $node->nid); } } return $output; } --- 283,316 ---- if (lm_paypal_paid_adverts_node_is_paid($node)) { require_once(drupal_get_path('module', 'lm_paypal_subscriptions').'/lm_paypal_subscriptions.pages.inc'); $sub .= lm_paypal_subscribe_subscription($node->lm_paypal_paid_adverts->payement_subid, 23); ! return t("This has been paid for by the subscription: !sub. Thank you.", array("!sub" => $sub)); } ! $term_subid = $_SESSION['lm_paypal_I_agree']; ! ! if ($term_subid) { ! $output .= ''. t('To make your payment, click "Proceed to Paypal" button below.') . '
'; ! } else { ! $output .= ''. t('Not yet paid for. To Publish, Please agree to 1 of the options below') .'
'; ! } $type_subs = lm_paypal_paid_adverts_get_live_subscriptions(); if (! empty($type_subs[$node->type])) foreach ($type_subs[$node->type] as $subid => $enabled) { if ($enabled) { + if ($term_subid == $subid || !$term_subid) { require_once(drupal_get_path('module', 'lm_paypal_subscriptions').'/lm_paypal_subscriptions.pages.inc'); $output .= lm_paypal_subscribe_subscription($subid, 15, NULL, $node->nid); + } } } + + if ($term_subid) { + // This reset the subid agreement + // lm_paypal_get_form_index(TRUE); // reset form index + lm_paypal_subscriptions_get_agreement(NULL, FALSE); + } + + lm_paypal_get_form_index(TRUE); // reset form index return $output; } *************** *** 301,318 **** if ($op == 'view' && (user_access('administer lm_paypal') || $user->uid == $account->uid)) { $account->content['paid_adverts'] = array( '#type' => 'user_profile_category', ! '#title' => t('PayPal Paid Adverts'), '#weight' => 6, // under History which is 5. ); $account->content['paid_adverts']['subs'] = array( '#type' => 'user_profile_item', ! '#title' => t('Adverts you paid with us:'), '#value' => lm_paypal_paid_adverts_list_nodes($account->uid, 10), ); } } function lm_paypal_paid_adverts_list_nodes($uid = 0, $nodes_per_page = 50) { $type_subs = lm_paypal_paid_adverts_get_live_subscriptions(); if (!is_numeric($uid) || ((int) $uid) != $uid) { --- 326,344 ---- if ($op == 'view' && (user_access('administer lm_paypal') || $user->uid == $account->uid)) { $account->content['paid_adverts'] = array( '#type' => 'user_profile_category', ! '#title' => t('PayPal Payments'), '#weight' => 6, // under History which is 5. ); $account->content['paid_adverts']['subs'] = array( '#type' => 'user_profile_item', ! '#title' => t(''), '#value' => lm_paypal_paid_adverts_list_nodes($account->uid, 10), ); } } function lm_paypal_paid_adverts_list_nodes($uid = 0, $nodes_per_page = 50) { + $type_subs = lm_paypal_paid_adverts_get_live_subscriptions(); if (!is_numeric($uid) || ((int) $uid) != $uid) { *************** *** 321,330 **** $header = array( array('data' => t('#'), 'field' => 'n.nid', 'sort' => 'desc'), ! array('data' => t('User'), 'field' => 'u.name'), array('data' => t('Title'), 'field' => 'n.title'), array('data' => t('Type'), 'field' => 'n.type'), ! array('data' => t('Published')), ); // Create a list of known paid node types --- 347,356 ---- $header = array( array('data' => t('#'), 'field' => 'n.nid', 'sort' => 'desc'), ! array('data' => t('Name'), 'field' => 'u.name'), array('data' => t('Title'), 'field' => 'n.title'), array('data' => t('Type'), 'field' => 'n.type'), ! array('data' => t('Status')), ); // Create a list of known paid node types *************** *** 346,356 **** $rows = array(); if ($nts > 0) { if ($uid == 0) { $sql = db_rewrite_sql("SELECT n.nid, n.uid, u.name, n.title, n.type FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND n.type IN $tstr"); } else { ! $sql = db_rewrite_sql("SELECT n.nid, n.uid, u.name, n.title, n.type FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.uid = %d AND n.status = 1 AND n.type IN $tstr"); } $tablesort = tablesort_sql($header); --- 372,383 ---- $rows = array(); if ($nts > 0) { + if ($uid == 0) { $sql = db_rewrite_sql("SELECT n.nid, n.uid, u.name, n.title, n.type FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND n.type IN $tstr"); } else { ! $sql = db_rewrite_sql("SELECT n.nid, n.uid, u.name, n.title, n.type, s.started, s.subid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {lm_paypal_subscribers} s ON n.nid = s.nid WHERE n.uid = %d AND n.type IN $tstr"); } $tablesort = tablesort_sql($header); *************** *** 365,382 **** $paidfor = lm_paypal_paid_adverts_node_is_paid($node); $subid = lm_paypal_paid_adverts_node_is_handled($node); ! if ($paidfor) { ! $pub = t('published'); } else { ! $pub = l(t('not published'), "node/$n->nid/lm_paypal", array( 'attributes' => array( 'alt' => t('Link to the page allowing you to publish this ad.'), 'title' => t('Click to pay for this ad to be published immediately.'), ), )); - } $link_to_node = l($n->title, "node/$n->nid", array( --- 392,429 ---- $paidfor = lm_paypal_paid_adverts_node_is_paid($node); $subid = lm_paypal_paid_adverts_node_is_handled($node); ! $published = $node->status; ! if (!lm_paypal_cron_publish()) $published = 1; ! ! $expires = ""; ! $started = ""; ! $msg_dt = "processing"; ! ! if ($n->subid) { ! $started = $n->started; ! $expires = lm_paypal_expire_date($n->subid,$n->started); ! $msg_dt = "paid " . date("m/d/Y", $started); ! if (time() > $expires) $msg_dt = "ended " . date("m/d/Y", $expires); ! } ! ! if ($paidfor || $started) { ! if ($published == 1) { ! $msg = "running"; ! } else { ! $msg = $msg_dt; ! } ! // $pub = t($msg); } else { ! $msg = 'unpaid'; ! } ! $pub = l($msg, "node/$n->nid/lm_paypal", array( 'attributes' => array( 'alt' => t('Link to the page allowing you to publish this ad.'), 'title' => t('Click to pay for this ad to be published immediately.'), ), )); $link_to_node = l($n->title, "node/$n->nid", array( *************** *** 386,406 **** ), ) ); - $rows[] = array('data' => ! array( ! $n->nid, ! l($n->name, "user/$n->uid"), ! $link_to_node, ! check_plain($node_types[$n->type]), ! $pub, ! ), ); } } if (!$rows) { ! $rows[] = array(array('data' => t('No paid adverts.'), 'colspan' => 5)); } $output = theme('table', $header, $rows); --- 433,452 ---- ), ) ); $rows[] = array('data' => ! array( ! $n->nid, ! l($n->name, "user/$n->uid"), ! $link_to_node, ! check_plain($node_types[$n->type]), ! $pub, ! ), ); } } if (!$rows) { ! $rows[] = array(array('data' => t('No PayPal payments have been made.'), 'colspan' => 5)); } $output = theme('table', $header, $rows); *************** *** 412,432 **** /** * Implementation of hook_nodeapi(). */ ! function lm_paypal_paid_adverts_nodeapi(&$node, $op, $a3, $a4) { if ($op == 'load') { if ($subscription = lm_paypal_paid_adverts_type_is_handled($node->type)) { $data = new stdClass(); $data->is_handled = TRUE; $data->subscriptions = lm_paypal_paid_adverts_get_live_subscriptions($node->type); ! $data->payement_subid = lm_paypal_subscriptions_node_subscribed($node); return array('lm_paypal_paid_adverts' => $data); } } ! if ($op == 'view' ! && lm_paypal_paid_adverts_node_is_handled($node) ! && ! $node->lm_paypal_paid_adverts->payement_subid) ! { /* * If our user own the node, we have to avert him the node can be paid using * paypal. --- 458,482 ---- /** * Implementation of hook_nodeapi(). */ ! function lm_paypal_paid_adverts_nodeapi(&$node, $op, $a3 = NULL , $a4 = NULL) { ! if ($op == 'load') { if ($subscription = lm_paypal_paid_adverts_type_is_handled($node->type)) { $data = new stdClass(); $data->is_handled = TRUE; $data->subscriptions = lm_paypal_paid_adverts_get_live_subscriptions($node->type); ! $data->payement_subid = lm_paypal_subscriptions_node_subscribed($node->nid); return array('lm_paypal_paid_adverts' => $data); } } ! if (lm_paypal_cron_publish()) { ! if ($node->status == 1) return; ! } ! ! if ($op == 'view' && lm_paypal_paid_adverts_node_is_handled($node)) { ! if (! $node->lm_paypal_paid_adverts->payement_subid) { ! /* * If our user own the node, we have to avert him the node can be paid using * paypal. *************** *** 434,441 **** if (lm_paypal_paid_adverts_paypal_access($node)) { $subid = key($node->lm_paypal_paid_adverts->subscriptions); $node->content['paid_adverts_message'] = array( ! '#value' => ''.t('This classified ad for subscription #@subid is still unpaid. Other users will not be able to access it.', array( '@subid' => $subid )).'
', '#weight' => -10, --- 484,492 ---- if (lm_paypal_paid_adverts_paypal_access($node)) { $subid = key($node->lm_paypal_paid_adverts->subscriptions); + #'#value' => ''.t('This item #@subid is still unpaid. Other users will not be able to access it.', array( $node->content['paid_adverts_message'] = array( ! '#value' => '
'.t('This item is still unpaid. Other users will not be able to access it.
Use the "Paypal Publish" above to make it live.', array(
'@subid' => $subid
)).'
') . check_markup($terms, $terms_format) . ! t('
Before you can subscribe you must agree to these terms and conditions
'), ); // Some countries made legally mandatory the checkbox to agress before submit // TODO: maybe we should put this checkbox in a variable_get from module $form['terms_accepted'] = array( '#type' => 'checkbox', // TODO: and the text is bad too, we should really put it in a variable too ! '#title' => t('Checking this option, I confirm that I read and understood all terms.'), '#default_value' => 0, ); ! $form['terms_subid'] = array( ! '#type' => 'hidden', ! '#value' => $subid, ! ); $form['submit'] = array( '#type' => 'submit', '#value' => t('I agree'), ); return $form; } function lm_paypal_subscription_terms_submit($form, &$form_state) { if ($form_state['values']['terms_accepted']) { ! $subid = ($form_state['values']['terms_subid']); lm_paypal_subscriptions_get_agreement($subid, TRUE); } else { --- 269,343 ---- } } + function lm_paypal_subscriptions_terms_form_1($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_2($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_3($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_4($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_5($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_6($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_7($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_8($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + function lm_paypal_subscriptions_terms_form_9($form_state, $subid, $terms, $terms_format) { + return lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format); + } + /** * The user has to agree to the terms and conditions */ function lm_paypal_subscriptions_terms_form($form_state, $subid, $terms, $terms_format) { + $form['#submit'] = array('lm_paypal_subscription_terms_submit'); // This reset the subid agreement ! // commented out below and moved logic to somewhere else . ! // lm_paypal_subscriptions_get_agreement(NULL, FALSE); $form['terms'] = array( '#type' => 'markup', '#value' => t('') . check_markup($terms, $terms_format) . ! t('
Before you can subscribe, you must agree to these terms and conditions
'), ); // Some countries made legally mandatory the checkbox to agress before submit // TODO: maybe we should put this checkbox in a variable_get from module $form['terms_accepted'] = array( '#type' => 'checkbox', // TODO: and the text is bad too, we should really put it in a variable too ! '#title' => t('Checking this option, I confirm that I have read and understood all terms.'), '#default_value' => 0, + '#return_value' => $subid, ); ! // $form['terms_subid'] = array( ! // '#type' => 'hidden', ! // '#value' => $subid, ! // ); $form['submit'] = array( '#type' => 'submit', '#value' => t('I agree'), ); + return $form; } function lm_paypal_subscription_terms_submit($form, &$form_state) { + if ($form_state['values']['terms_accepted']) { ! $subid = ($form_state['values']['terms_accepted']); lm_paypal_subscriptions_get_agreement($subid, TRUE); } else { *************** *** 290,296 **** } } ! /** * Display single subscription with a link to PayPal. * * @param int $subid --- 345,351 ---- } } ! /* * Display single subscription with a link to PayPal. * * @param int $subid *************** *** 323,332 **** return $output; } $terms = trim($so->terms); if (! empty($terms)) { if (! lm_paypal_subscriptions_get_agreement($subid)) { ! $output .= drupal_get_form('lm_paypal_subscriptions_terms_form', $subid, $so->terms, $so->terms_format); return $output; } } --- 378,393 ---- return $output; } + if (isset($_SESSION['lm_paypal_I_agree'])) { + if ($_SESSION['lm_paypal_I_agree'] != $subid) return; // only display term that was agreed to. + } + $terms = trim($so->terms); if (! empty($terms)) { if (! lm_paypal_subscriptions_get_agreement($subid)) { ! $next_form_index = lm_paypal_get_form_index(); ! $id = 'lm_paypal_subscriptions_terms_form_' . $next_form_index; ! $output .= drupal_get_form($id, $subid, $so->terms, $so->terms_format); return $output; } } *************** *** 347,354 **** --- 408,427 ---- $return_path = lm_paypal_subscriptions_get_inprogress(); } + // add host and node id to item desription + $nid=request_uri() . "/"; + if (strpos($nid,"node") !== 0) { + $nid=str_replace("/lm_paypal/","",$nid); + $nid=str_replace("/node/","",$nid); + } else { + $nid=""; + } + $item_name = check_plain($so->item_name); + if (lm_paypal_prefix_nid()) $item_name = $nid . "/" . $item_name; + if (lm_paypal_prefix_hostname()) $item_name = $_SERVER['SERVER_NAME'] . "/" . $item_name; + // Output a form that will redirect the user to PayPal - note all the fields // are hidden so only the submit appears $hidden = array(); *************** *** 367,373 **** --- 440,449 ---- $hidden['p3'] = check_plain($so->p3); $hidden['t3'] = check_plain($so->t3); } + + $cmd = LM_PAYPAL_FORM_CMD_BUY_NOW; if (! empty($so->srt)) { + $cmd = LM_PAYPAL_FORM_CMD_SUBSCRIBE; $hidden['srt'] = check_plain($so->srt); // If recurring times is set but recurring isn't then set it otherwise // PayPal will reject this request *************** *** 375,386 **** --- 451,464 ---- $hidden['src'] = "1"; } } + if (! empty($so->src)) { $hidden['src'] = check_plain($so->src); } $hidden['sra'] = "1"; $hidden['no_note'] = "1"; $hidden['usr_manage'] = "0"; + $output .= drupal_get_form( 'lm_paypal_api_payment_form', $so->a3, *************** *** 394,400 **** 'module' => LM_PAYPAL_SUBSCRIPTIONS, ), 'hidden' => $hidden, ! 'cmd' => LM_PAYPAL_FORM_CMD_SUBSCRIBE, ) ); --- 472,478 ---- 'module' => LM_PAYPAL_SUBSCRIPTIONS, ), 'hidden' => $hidden, ! 'cmd' => $cmd, ) );