--- donation.module 2009-11-01 00:49:13.000000000 +0100 +++ donation.module 2009-11-01 00:49:06.000000000 +0100 @@ -42,6 +42,65 @@ } /** + * Implementation of hook_hook_info(). + */ +function donation_hook_info() { + return array( + 'Donations' => array( + 'donation' => array( + 'anonymous_donation' => array( + 'runs when' => t('After an donation was made by an anonymous user'), + ), + 'authenticated_donation' => array( + 'runs when' => t('After a donation was made by an authenticated user'), + ), + ), + ), + ); +} + +/** + * Implementation of hook_action_info_alter(). + */ +function donation_action_info_alter(&$info) { + foreach ($info as $type => $data) { + if (stripos($type, "user_") === 0 || stripos($type, "system_") === 0) { + if (isset($info[$type]['hooks']['donation'])) { + array_merge($info[$type]['hooks']['donation'], array('anonymous_donation', 'authenticated_donation')); + } + else { + $info[$type]['hooks']['donation'] = array('anonymous_donation', 'authenticated_donation'); + } + } + } +} + +/** + * Hook hook_donation(), which is fired whenever a new donation is made. + * + * @param $op Either 'anonymous_donation' or 'authenticated_donation' depending on + * if an unknown or known user (to Drupal) has made the donation. + * @param $user NULL for anonymous donations, otherwise this is the user of the + * user making the donation. + */ +function donation_donation($op, $user = NULL) { + // Check if we support the given action + if (!in_array($op, array('anonymous_donation', 'authenticated_donation'))) { + return; + } + + // Simply trigger actions + $aids = _trigger_get_hook_aids('donation', $op); + $context = array( + 'hook' => 'donation', + 'op' => $op, + 'user' => $user, + 'uid' => (isset($user) ? $user->uid : NULL), + ); + actions_do(array_keys($aids), $user, $context); +} + +/** * Implementation of hook_menu(). */ function donation_menu() { @@ -538,6 +597,15 @@ $amount, $currency, variable_get(DONATION_STATE, DONATION_PUBLIC)); + + if ($uid) { + $user = user_load(array('uid' => $uid)); + module_invoke_all('donation', 'authenticated_donation', $user); + } + else { + module_invoke_all('donation', 'anonymous_donation', NULL); + } + watchdog('donation', 'Donation from @name (@mail) amount of @amount @currency.', array( '@name' => $name, '@mail' => $payer_email,