/** * @param Am_Event_UserBeforeInsert $event */ function onUserBeforeInsert(Am_Event_UserBeforeInsert $event) { // skip this code if running from aMember CP if (defined('AM_ADMIN') && AM_ADMIN) { return; } $aff_id = $this->findAffId($aff_source); $e = new Am_Event(self::AFF_BIND_AFFILIATE, array('user' => $event->getUser())); $e->setReturn($aff_id); $this->getDi()->hook->call($e); $aff_id = $e->getReturn(); // remember for usage in onUserAfterInsert $this->last_aff_id = $aff_id; if ($aff_id > 0) { $event->getUser()->aff_id = intval($aff_id); $event->getUser()->aff_added = sqlTime('now'); if ($aff_source) { $event->getUser()->data()->set('aff-source', $aff_source); } } if (empty($event->getUser()->is_affiliate)) { $event->getUser()->is_affiliate = $this->getDi()->config->get('aff.signup_type') == 1 ? 1 : 0; } }
/** * if $_COOKIE is empty, find matches for user by IP address in aff_clicks table * @param Am_Event_UserBeforeInsert $event */ function onUserBeforeInsert(Am_Event_UserBeforeInsert $event) { // skip this code if running from aMember CP if (defined('AM_ADMIN') && AM_ADMIN) { return; } $aff_id = @$_COOKIE[self::COOKIE_NAME]; if (empty($aff_id)) { $aff_id = $this->getDi()->affClickTable->findAffIdByIp($_SERVER['REMOTE_ADDR']); } // remember for usage in onUserAfterInsert $this->last_aff_id = $aff_id; if ($aff_id > 0) { $event->getUser()->aff_id = intval($aff_id); } if (empty($event->getUser()->is_affiliate)) { $event->getUser()->is_affiliate = $this->getDi()->config->get('aff.signup_type') == 1 ? 1 : 0; } }