Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,36 +12,54 @@
|
||||
namespace IPS\nexus\extensions\core\CommunityEnhancements;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\core\AdminNotification;
|
||||
use IPS\Extensions\CommunityEnhancementsAbstract;
|
||||
use IPS\GeoLocation;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use LogicException;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Community Enhancement
|
||||
*/
|
||||
class _MaxMind
|
||||
class MaxMind extends CommunityEnhancementsAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Enhancement is enabled?
|
||||
*/
|
||||
public $enabled = FALSE;
|
||||
public bool $enabled = FALSE;
|
||||
|
||||
/**
|
||||
* @brief IPS-provided enhancement?
|
||||
*/
|
||||
public $ips = FALSE;
|
||||
public bool $ips = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Enhancement has configuration options?
|
||||
*/
|
||||
public $hasOptions = TRUE;
|
||||
public bool $hasOptions = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Icon data
|
||||
*/
|
||||
public $icon = "maxmind.png";
|
||||
public string $icon = "maxmind.png";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -50,7 +68,7 @@ class _MaxMind
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->enabled = (bool) \IPS\Settings::i()->maxmind_key;
|
||||
$this->enabled = (bool) Settings::i()->maxmind_key;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,15 +76,15 @@ class _MaxMind
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function edit()
|
||||
public function edit() : void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'maxmind_enable', (bool) \IPS\Settings::i()->maxmind_key, FALSE, array( 'togglesOn' => array( 'maxmind_key', 'maxmind_gateways', 'maxmind_error' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'maxmind_id', \IPS\Settings::i()->maxmind_id, FALSE, array(), NULL, NULL, NULL, 'maxmind_id' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'maxmind_key', \IPS\Settings::i()->maxmind_key, FALSE, array(), NULL, NULL, NULL, 'maxmind_key' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'maxmind_gateways', ( !\IPS\Settings::i()->maxmind_gateways or \IPS\Settings::i()->maxmind_gateways === '*' ) ? 0 : explode( ',', \IPS\Settings::i()->maxmind_gateways ), FALSE, array( 'class' => 'IPS\nexus\Gateway', 'multiple' => TRUE, 'zeroVal' => 'all' ), NULL, NULL, NULL, 'maxmind_gateways' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'maxmind_error', \IPS\Settings::i()->maxmind_error, FALSE, array( 'options' => array( 'okay' => 'maxmind_error_okay', 'hold' => 'maxmind_error_hold' ) ), NULL, NULL, NULL, 'maxmind_error' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'maxmind_tracking_code', (bool) \IPS\Settings::i()->maxmind_tracking_code, FALSE, array(), NULL, NULL, NULL, 'maxmind_tracking_code' ) );
|
||||
$form = new Form;
|
||||
$form->add( new YesNo( 'maxmind_enable', (bool) Settings::i()->maxmind_key, FALSE, array( 'togglesOn' => array( 'maxmind_key', 'maxmind_gateways', 'maxmind_error' ) ) ) );
|
||||
$form->add( new Text( 'maxmind_id', Settings::i()->maxmind_id, FALSE, array(), NULL, NULL, NULL, 'maxmind_id' ) );
|
||||
$form->add( new Text( 'maxmind_key', Settings::i()->maxmind_key, FALSE, array(), NULL, NULL, NULL, 'maxmind_key' ) );
|
||||
$form->add( new Node( 'maxmind_gateways', ( !Settings::i()->maxmind_gateways or Settings::i()->maxmind_gateways === '*' ) ? 0 : explode( ',', Settings::i()->maxmind_gateways ), FALSE, array( 'class' => 'IPS\nexus\Gateway', 'multiple' => TRUE, 'zeroVal' => 'all' ), NULL, NULL, NULL, 'maxmind_gateways' ) );
|
||||
$form->add( new Radio( 'maxmind_error', Settings::i()->maxmind_error, FALSE, array( 'options' => array( 'okay' => 'maxmind_error_okay', 'hold' => 'maxmind_error_hold' ) ), NULL, NULL, NULL, 'maxmind_error' ) );
|
||||
$form->add( new YesNo( 'maxmind_tracking_code', (bool) Settings::i()->maxmind_tracking_code, FALSE, array(), NULL, NULL, NULL, 'maxmind_tracking_code' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -76,7 +94,7 @@ class _MaxMind
|
||||
{
|
||||
unset( $values['maxmind_enable'] );
|
||||
$this->testSettings( $values['maxmind_key'], $values['maxmind_id'] );
|
||||
$values['maxmind_gateways'] = \is_array( $values['maxmind_gateways'] ) ? implode( ',', array_keys( $values['maxmind_gateways'] ) ) : '*';
|
||||
$values['maxmind_gateways'] = is_array( $values['maxmind_gateways'] ) ? implode( ',', array_keys( $values['maxmind_gateways'] ) ) : '*';
|
||||
$form->saveAsSettings( $values );
|
||||
}
|
||||
else
|
||||
@@ -88,25 +106,25 @@ class _MaxMind
|
||||
$form->saveAsSettings( $values );
|
||||
}
|
||||
|
||||
\IPS\core\AdminNotification::remove( 'nexus', 'Maxmind' );
|
||||
\IPS\Output::i()->inlineMessage = \IPS\Member::loggedIn()->language()->addToStack('saved');
|
||||
AdminNotification::remove( 'nexus', 'Maxmind' );
|
||||
Output::i()->inlineMessage = Member::loggedIn()->language()->addToStack('saved');
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
catch ( LogicException $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
Output::i()->sidebar['actions'] = array(
|
||||
'help' => array(
|
||||
'title' => 'learn_more',
|
||||
'icon' => 'question-circle',
|
||||
'link' => \IPS\Http\Url::ips( 'docs/maxmind' ),
|
||||
'link' => Url::ips( 'docs/maxmind' ),
|
||||
'target' => '_blank'
|
||||
),
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,32 +132,32 @@ class _MaxMind
|
||||
*
|
||||
* @param $enabled bool Enable/Disable
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function toggle( $enabled )
|
||||
public function toggle( bool $enabled ) : void
|
||||
{
|
||||
if ( $enabled )
|
||||
{
|
||||
throw new \LogicException;
|
||||
throw new LogicException;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Settings::i()->changeValues( array( 'maxmind_key' => '', 'maxmind_id' => '' ) );
|
||||
\IPS\core\AdminNotification::remove( 'nexus', 'Maxmind' );
|
||||
Settings::i()->changeValues( array( 'maxmind_key' => '', 'maxmind_id' => '' ) );
|
||||
AdminNotification::remove( 'nexus', 'Maxmind' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Settings
|
||||
*
|
||||
* @param string|NULL $key Key to check
|
||||
* @param string|NULL $id ID to check
|
||||
* @param string|null $key Key to check
|
||||
* @param string|null $id ID to check
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
* @throws LogicException
|
||||
*/
|
||||
protected function testSettings( $key=NULL, $id=NULL )
|
||||
protected function testSettings( string $key=NULL, string $id=NULL ) : void
|
||||
{
|
||||
$testAddress = new \IPS\GeoLocation;
|
||||
$testAddress = new GeoLocation;
|
||||
$testAddress->addressLines = array( 'Invision Power Services, Inc.', 'PO Box 2365' );
|
||||
$testAddress->city = 'Forest';
|
||||
$testAddress->region = 'VA';
|
||||
@@ -147,13 +165,13 @@ class _MaxMind
|
||||
$testAddress->postalCode = '24551';
|
||||
|
||||
$maxMind = new \IPS\nexus\Fraud\MaxMind\Request( FALSE, $key, $id );
|
||||
$maxMind->setIpAddress( \IPS\Request::i()->ipAddress() );
|
||||
$maxMind->setIpAddress( Request::i()->ipAddress() );
|
||||
$maxMind->setBillingAddress( $testAddress );
|
||||
$maxMind = $maxMind->request();
|
||||
|
||||
if ( $maxMind->error )
|
||||
{
|
||||
throw new \LogicException( $maxMind->error );
|
||||
throw new LogicException( $maxMind->error );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user