title = $registry->getClass('class_localization')->words['enhancements_mandrill']; $this->description = $registry->getClass('class_localization')->words['enhancements_mandrill_desc']; $this->enabled = ( ipsRegistry::$settings['mandrill_api_key'] ); } /** * Edit Settings * * @param string Error * @return string Output */ public function editSettings( $error='' ) { ipsRegistry::getClass('class_localization')->loadLanguageFile( 'admin_bulkmail', 'members' ); if ( $this->enabled ) { return ipsRegistry::getClass('output')->loadTemplate( 'cp_skin_bulkmail', 'members' )->mandrillManage( $error ); } else { return ipsRegistry::getClass('output')->loadTemplate( 'cp_skin_bulkmail', 'members' )->mandrillSignup( $error ); } } /** * Save Settings */ public function saveSettings() { /* Are we turning off? */ if ( ipsRegistry::$request['off'] ) { IPSLib::updateSettings( array( 'mandrill_username' => '', 'mandrill_api_key' => '' ) ); ipsRegistry::getClass('output')->silentRedirect( ipsRegistry::$settings['_base_url'] . "app=core&module=applications&section=enhancements&do=edit&service=enhancements_members_mandrill" ); return; } /* Load language files so we have error messages if we need em */ ipsRegistry::getClass('class_localization')->loadLanguageFile( 'admin_bulkmail', 'members' ); /* Are we adding new values or just enabling SMTP? */ if ( ipsRegistry::$request['smtp_on'] ) { ipsRegistry::$request['username'] = ipsRegistry::$settings['mandrill_username']; ipsRegistry::$request['api_key'] = ipsRegistry::$settings['mandrill_api_key']; ipsRegistry::$request['smtp'] = 1; $update = array(); } else { /* Trim (like a haircut, but with strings) */ ipsRegistry::$request['username'] = trim( ipsRegistry::$request['username'] ); ipsRegistry::$request['api_key'] = trim( ipsRegistry::$request['api_key'] ); /* If we don't have anything, tell them off */ if ( !ipsRegistry::$request['username'] or !ipsRegistry::$request['username'] ) { return $this->editSettings( 'mandrill_setup_noinfo' ); } /* Now shoot that over to Mandrill to make sure they're cool with it */ require_once IPSLib::getAppDir('members') . '/sources/classes/mandrill.php'; $mandrill = new Mandrill( ipsRegistry::$request['api_key'] ); $info = $mandrill->users_info(); if ( $info === NULL or $info->username != ipsRegistry::$request['username'] ) { return $this->editSettings( 'mandrill_bad_credentials' ); } /* So we're saving at least the API key and the username */ $update = array( 'mandrill_username' => ipsRegistry::$request['username'], 'mandrill_api_key' => ipsRegistry::$request['api_key'] ); } /* If they want to use Mandrill for SMTP too, update those settings */ if ( ipsRegistry::$request['smtp'] ) { $update['smtp_host'] = 'smtp.mandrillapp.com'; $update['mail_method'] = 'smtp'; $update['smtp_port'] = 587; $update['mail_wrap_brackets'] = 0; $update['smtp_user'] = ipsRegistry::$request['username']; $update['smtp_pass'] = ipsRegistry::$request['api_key']; $update['smtp_helo'] = 'HELO'; } /* Update the settings */ IPSLib::updateSettings( $update ); /* And boink the hell out of it */ ipsRegistry::getClass('output')->silentRedirect( ipsRegistry::$settings['_base_url'] . "app=core&module=applications&section=enhancements&do=edit&service=enhancements_members_mandrill" ); return; } }