Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Purchase;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -22,7 +22,20 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* License Key Model
|
||||
*/
|
||||
abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
{
|
||||
/**
|
||||
* License Key Types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function licenseKeyTypes()
|
||||
{
|
||||
return array(
|
||||
'Standard' => 'IPS\nexus\Purchase\LicenseKey\Standard',
|
||||
'Mdfive' => 'IPS\nexus\Purchase\LicenseKey\Mdfive',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
@@ -62,7 +75,8 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
{
|
||||
$classname = 'IPS\nexus\Purchase\LicenseKey\\' . mb_ucfirst( $data['lkey_type'] );
|
||||
$types = static::licenseKeyTypes();
|
||||
$classname = $types[ mb_ucfirst( $data['lkey_type'] ) ];
|
||||
|
||||
/* Initiate an object */
|
||||
$obj = new $classname;
|
||||
@@ -97,7 +111,7 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$exploded = explode( '\\', get_class( $this ) );
|
||||
$exploded = explode( '\\', \get_class( $this ) );
|
||||
$this->type = mb_strtolower( array_pop( $exploded ) );
|
||||
$this->active = TRUE;
|
||||
$this->uses = 0;
|
||||
@@ -182,7 +196,7 @@ abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$this->key = $this->generate();
|
||||
}
|
||||
while ( count( \IPS\Db::i()->select( '*', 'nexus_licensekeys', array( 'lkey_key=?', $this->key ) ) ) );
|
||||
while ( \count( \IPS\Db::i()->select( '*', 'nexus_licensekeys', array( 'lkey_key=?', $this->key ) ) ) );
|
||||
}
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Purchase\LicenseKey;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Purchase\LicenseKey;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -70,8 +70,8 @@ class _Standard extends \IPS\nexus\Purchase\LicenseKey
|
||||
{
|
||||
$chr = rand( static::$low, static::$high );
|
||||
}
|
||||
while ( in_array( $chr, static::$disallowed ) );
|
||||
$_k .= chr( $chr );
|
||||
while ( \in_array( $chr, static::$disallowed ) );
|
||||
$_k .= \chr( $chr );
|
||||
}
|
||||
$key[] = $_k;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -122,7 +122,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
|
||||
try
|
||||
{
|
||||
$description = call_user_func( array( $this->extension(), 'getPurchaseNameInfo' ), $this );
|
||||
$extension = $this->extension();
|
||||
$description = $extension::getPurchaseNameInfo( $this );
|
||||
|
||||
if( empty( $description ) )
|
||||
{
|
||||
@@ -251,8 +252,9 @@ class _Purchase extends \IPS\Node\Model
|
||||
$this->nameWithStickyFields = $this->_data['name'];
|
||||
try
|
||||
{
|
||||
$info = call_user_func( array( $this->extension(), 'getPurchaseNameInfo' ), $this );
|
||||
if ( count( $info ) )
|
||||
$extension = $this->extension();
|
||||
$info = $extension::getPurchaseNameInfo( $this );
|
||||
if ( \count( $info ) )
|
||||
{
|
||||
$this->nameWithStickyFields .= ' (' . implode( ' · ', $info ) . ')';
|
||||
}
|
||||
@@ -305,10 +307,12 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
if ( $this->_data['active'] and !$active )
|
||||
{
|
||||
$this->_data['active'] = FALSE;
|
||||
$this->onExpire();
|
||||
}
|
||||
elseif ( !$this->_data['active'] and $active )
|
||||
{
|
||||
$this->_data['active'] = TRUE;
|
||||
$this->onReactivate();
|
||||
}
|
||||
}
|
||||
@@ -391,7 +395,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
else
|
||||
{
|
||||
$this->_data['expire'] = $date->getTimestamp();
|
||||
$this->active = ( !$this->cancelled and $date->add( new \DateInterval( 'PT' . intval( $this->grace_period ) . 'S' ) )->getTimestamp() > time() );
|
||||
$this->active = ( !$this->cancelled and $date->add( new \DateInterval( 'PT' . \intval( $this->grace_period ) . 'S' ) )->getTimestamp() > time() );
|
||||
}
|
||||
if ( $this->id )
|
||||
{
|
||||
@@ -628,7 +632,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
*/
|
||||
public function set_grouped_renewals( $data )
|
||||
{
|
||||
$this->_data['grouped_renewals'] = !is_null( $data ) ? json_encode( $data ) : NULL;
|
||||
$this->_data['grouped_renewals'] = !\is_null( $data ) ? json_encode( $data ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -721,7 +725,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'getIcon' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::getIcon( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -738,7 +743,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'getTypeTitle' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::getTypeTitle( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -755,7 +761,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'purchaseImage' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::purchaseImage( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -772,9 +779,10 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'acpPage' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::acpPage( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( \OutOfRangeException | \BadMethodCallException $e )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -791,7 +799,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'acpEdit' ), $this, $form, $renewals );
|
||||
$extension = $this->extension();
|
||||
return $extension::acpEdit( $this, $form, $renewals );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -809,7 +818,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'acpEditSave' ), $this, $values );
|
||||
$extension = $this->extension();
|
||||
return $extension::acpEditSave( $this, $values );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -826,9 +836,10 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'clientAreaPage' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::clientAreaPage( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( \OutOfRangeException | \BadMethodCallException $e )
|
||||
{
|
||||
return array( 'packageInfo' => '', 'purchaseInfo' => '' );
|
||||
}
|
||||
@@ -843,7 +854,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'acpAction' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::acpAction( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -860,7 +872,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'clientAreaAction' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::clientAreaAction( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -877,7 +890,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'acpSupportView' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::acpSupportView( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -894,7 +908,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'supportSeverity' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::supportSeverity( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -911,7 +926,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'renewalPaymentMethodIds' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::renewalPaymentMethodIds( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -932,7 +948,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func_array( array( $this->extension(), $method ), array_merge( array( $this ), $params ) );
|
||||
return \call_user_func_array( array( $this->extension(), $method ), array_merge( array( $this ), $params ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
@@ -1097,7 +1113,22 @@ class _Purchase extends \IPS\Node\Model
|
||||
public function canView( $member = NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
|
||||
/* Show only purchases from active applications */
|
||||
try
|
||||
{
|
||||
$app = \IPS\Application::load( $this->app );
|
||||
}
|
||||
catch ( \UnexpectedValueException $e )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( !$app->canAccess() )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( $this->member->member_id === $member->member_id or array_key_exists( $member->member_id, iterator_to_array( $this->member->alternativeContacts( array( \IPS\Db::i()->findInSet( 'purchases', array( $this->id ) ) ) ) ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
@@ -1120,7 +1151,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'canChangeExpireDate' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::canChangeExpireDate( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -1163,7 +1195,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
|
||||
try
|
||||
{
|
||||
$date = call_user_func( array( $this->extension(), 'canRenewUntil' ), $this, $admin );
|
||||
$extension = $this->extension();
|
||||
$date = $extension::canRenewUntil( $this, $admin );
|
||||
|
||||
if ( $inCycles and $date instanceof \IPS\DateTime )
|
||||
{
|
||||
@@ -1195,7 +1228,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
return call_user_func( array( $this->extension(), 'canBeRenewed' ), $this );
|
||||
$extension = $this->extension();
|
||||
return $extension::canBeRenewed( $this );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
@@ -1263,15 +1297,24 @@ class _Purchase extends \IPS\Node\Model
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @param bool $deleteChildren If TRUE, child purchases will also be deleted. If FALSE, they will become unassociated.
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete( $deleteChildren = TRUE )
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'nexus_Purchases', $this->id, NULL, 'purchase' );
|
||||
|
||||
foreach ( $this->children() as $child )
|
||||
foreach ( $this->children( NULL ) as $child )
|
||||
{
|
||||
$child->delete();
|
||||
if ( $deleteChildren )
|
||||
{
|
||||
$child->delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
$child->parent = NULL;
|
||||
$child->save();
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
@@ -1458,7 +1501,8 @@ class _Purchase extends \IPS\Node\Model
|
||||
|
||||
try
|
||||
{
|
||||
$return = array_merge( $return, call_user_func( array( $this->extension(), 'acpButtons' ), $this, $url ) );
|
||||
$extension = $this->extension();
|
||||
$return = array_merge( $return, $extension::acpButtons( $this, $url ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
|
||||
@@ -1481,7 +1525,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
$return['group'] = array(
|
||||
'icon' => 'compress',
|
||||
'title' => 'group_with_parent',
|
||||
'link' => $url->setQueryString( 'do', 'group' ),
|
||||
'link' => $url->setQueryString( 'do', 'group' )->csrf(),
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('group_with_parent_info') )
|
||||
);
|
||||
}
|
||||
@@ -1490,7 +1534,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
$return['group'] = array(
|
||||
'icon' => 'expand',
|
||||
'title' => 'ungroup_from_parent',
|
||||
'link' => $url->setQueryString( 'do', 'ungroup' ),
|
||||
'link' => $url->setQueryString( 'do', 'ungroup' )->csrf(),
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('ungroup_from_parent_info') )
|
||||
);
|
||||
}
|
||||
@@ -1513,7 +1557,7 @@ class _Purchase extends \IPS\Node\Model
|
||||
$return['reactivate'] = array(
|
||||
'icon' => 'check',
|
||||
'title' => 'reactivate',
|
||||
'link' => $url->setQueryString( 'do', 'reactivate' ),
|
||||
'link' => $url->setQueryString( 'do', 'reactivate' )->csrf(),
|
||||
'data' => array( 'confirm' => '' )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Purchase;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -58,7 +58,7 @@ class _RenewalTerm
|
||||
* @param \DateInterval|NULL $gracePeriod Grace period
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $cost, \DateInterval $interval, \IPS\nexus\Tax $tax = NULL, $addToBase = FALSE, \DateInterval $gracePeriod = NULL )
|
||||
public function __construct( $cost, \DateInterval $interval = NULL, \IPS\nexus\Tax $tax = NULL, $addToBase = FALSE, \DateInterval $gracePeriod = NULL )
|
||||
{
|
||||
$this->cost = $cost;
|
||||
$this->interval = $interval;
|
||||
@@ -100,7 +100,14 @@ class _RenewalTerm
|
||||
switch( $term['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
return $lang->pluralize( $lang->get('renew_days'), array( $term['term'] ) );
|
||||
if ( $term['term'] % 7 == 0 )
|
||||
{
|
||||
return $lang->pluralize( $lang->get('renew_weeks'), array( $term['term'] / 7 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return $lang->pluralize( $lang->get('renew_days'), array( $term['term'] ) );
|
||||
}
|
||||
case 'm':
|
||||
return $lang->pluralize( $lang->get('renew_months'), array( $term['term'] ) );
|
||||
case 'y':
|
||||
@@ -341,7 +348,7 @@ class _RenewalTerm
|
||||
$cost = new \IPS\nexus\Money( $cost->amount->multiply( new \IPS\Math\Number( "$quantity" ) ), $cost->currency );
|
||||
}
|
||||
|
||||
return sprintf( \IPS\Member::loggedIn()->language()->get( 'renew_option'), $cost, $this->getTermUnit() ) ;
|
||||
return sprintf( \IPS\Member::loggedIn()->language()->get( 'renew_option'), $cost, $this->getTermUnit() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user