Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief License Key Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 30 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Purchase;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* License Key Model
|
||||
*/
|
||||
abstract class _LicenseKey extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_licensekeys';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'lkey_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Column
|
||||
*/
|
||||
public static $databaseColumnId = 'key';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'lkey_purchase' );
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
{
|
||||
$classname = 'IPS\nexus\Purchase\LicenseKey\\' . ucfirst( $data['lkey_type'] );
|
||||
|
||||
/* Initiate an object */
|
||||
$obj = new $classname;
|
||||
$obj->_new = FALSE;
|
||||
|
||||
/* Import data */
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
if( static::$databasePrefix AND mb_strpos( $k, static::$databasePrefix ) === 0 )
|
||||
{
|
||||
$k = \substr( $k, \strlen( static::$databasePrefix ) );
|
||||
}
|
||||
|
||||
$obj->_data[ $k ] = $v;
|
||||
}
|
||||
$obj->changed = array();
|
||||
|
||||
/* Init */
|
||||
if ( method_exists( $obj, 'init' ) )
|
||||
{
|
||||
$obj->init();
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
$exploded = explode( '\\', get_class( $this ) );
|
||||
$this->type = mb_strtolower( array_pop( $exploded ) );
|
||||
$this->active = TRUE;
|
||||
$this->uses = 0;
|
||||
$this->activate_data = array();
|
||||
$this->generated = new \IPS\DateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set purchase
|
||||
*
|
||||
* @param \IPS\nexus\Purchase $purchase The purchase
|
||||
* @return void
|
||||
*/
|
||||
public function set_purchase( \IPS\nexus\Purchase $purchase )
|
||||
{
|
||||
$this->_data['purchase'] = $purchase->id;
|
||||
$this->_data['member'] = $purchase->member->member_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set purchase
|
||||
*
|
||||
* @return \IPS\nexus\Purchase
|
||||
*/
|
||||
public function get_purchase()
|
||||
{
|
||||
return \IPS\nexus\Purchase::load( $this->_data['purchase'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set activate data
|
||||
*
|
||||
* @param array $data The data
|
||||
* @return void
|
||||
*/
|
||||
public function set_activate_data( array $data )
|
||||
{
|
||||
$this->_data['activate_data'] = json_encode( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set activate data
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
*/
|
||||
public function get_activate_data()
|
||||
{
|
||||
return json_decode( $this->_data['activate_data'], TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set generated time
|
||||
*
|
||||
* @param \IPS\DateTime $generated Generated time
|
||||
* @return void
|
||||
*/
|
||||
public function set_generated( \IPS\DateTime $generated )
|
||||
{
|
||||
$this->_data['generated'] = $generated->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set generated time
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
*/
|
||||
public function get_generated()
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['generated'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
if ( !$this->key )
|
||||
{
|
||||
do
|
||||
{
|
||||
$this->key = $this->generate();
|
||||
}
|
||||
while ( count( \IPS\Db::i()->select( '*', 'nexus_licensekeys', array( 'lkey_key=?', $this->key ) ) ) );
|
||||
}
|
||||
return parent::save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief License Key Model - MD5
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 30 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Purchase\LicenseKey;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* License Key Model - MD5
|
||||
*/
|
||||
class _Mdfive extends \IPS\nexus\Purchase\LicenseKey
|
||||
{
|
||||
/**
|
||||
* Generates a License Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
return md5( uniqid() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief License Key Model - Standard
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 30 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Purchase\LicenseKey;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* License Key Model - Standard
|
||||
*/
|
||||
class _Standard extends \IPS\nexus\Purchase\LicenseKey
|
||||
{
|
||||
/**
|
||||
* @brief Number of blocks
|
||||
*/
|
||||
protected static $blocks = 5;
|
||||
|
||||
/**
|
||||
* @brief Number of characters in a block
|
||||
*/
|
||||
protected static $characters = 4;
|
||||
|
||||
/**
|
||||
* @brief Lowest allowed ASCII number
|
||||
*/
|
||||
protected static $low = 48; // 0
|
||||
|
||||
/**
|
||||
* @brief Highest allowed ASCII number
|
||||
*/
|
||||
protected static $high = 90; // Z
|
||||
|
||||
/**
|
||||
* @brief Disallowed ASCII numbers
|
||||
*/
|
||||
protected static $disallowed = array( 58, 59, 60, 61, 62, 63, 64 ); // Various non A-Z / 0-9 characters
|
||||
|
||||
/**
|
||||
* @brief Seperator between blocks
|
||||
*/
|
||||
protected static $seperator = '-';
|
||||
|
||||
/**
|
||||
* Generates a License Key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$key = array();
|
||||
foreach ( range( 1, self::$blocks ) as $i )
|
||||
{
|
||||
$_k = '';
|
||||
foreach ( range( 1, self::$characters ) as $j )
|
||||
{
|
||||
do
|
||||
{
|
||||
$chr = rand( self::$low, self::$high );
|
||||
}
|
||||
while ( in_array( $chr, self::$disallowed ) );
|
||||
$_k .= chr( $chr );
|
||||
}
|
||||
$key[] = $_k;
|
||||
}
|
||||
|
||||
return implode( self::$seperator, $key );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Renewal Term Object
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 13 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Purchase;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renewal Term Object
|
||||
*/
|
||||
class _RenewalTerm
|
||||
{
|
||||
/**
|
||||
* @brief Cost
|
||||
*/
|
||||
public $cost;
|
||||
|
||||
/**
|
||||
* @brief Interval
|
||||
*/
|
||||
public $interval;
|
||||
|
||||
/**
|
||||
* @brief Tax
|
||||
*/
|
||||
public $tax;
|
||||
|
||||
/**
|
||||
* @brief Add to base price?
|
||||
*/
|
||||
public $addToBase = FALSE;
|
||||
|
||||
/**
|
||||
* @brief Grace period
|
||||
*/
|
||||
public $gracePeriod;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\nexus\Money|array $cost Cost
|
||||
* @param \DateInterval $interval Interval
|
||||
* @param \IPS\nexus\Tax|NULL $tax Tax
|
||||
* @param bool $addToBase Add to base?
|
||||
* @param \DateInterval|NULL $gracePeriod Grace period
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $cost, \DateInterval $interval, \IPS\nexus\Tax $tax = NULL, $addToBase = FALSE, \DateInterval $gracePeriod = NULL )
|
||||
{
|
||||
$this->cost = $cost;
|
||||
$this->interval = $interval;
|
||||
$this->tax = $tax;
|
||||
$this->addToBase = $addToBase;
|
||||
$this->gracePeriod = $gracePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get term
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTerm()
|
||||
{
|
||||
if( $this->interval->y )
|
||||
{
|
||||
return array( 'term' => $this->interval->y, 'unit' => 'y' );
|
||||
}
|
||||
elseif( $this->interval->m )
|
||||
{
|
||||
return array( 'term' => $this->interval->m, 'unit' => 'm' );
|
||||
}
|
||||
else
|
||||
{
|
||||
return array( 'term' => $this->interval->d, 'unit' => 'd' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get term unit
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTermUnit()
|
||||
{
|
||||
$term = $this->getTerm();
|
||||
$lang = \IPS\Member::loggedIn()->language();
|
||||
switch( $term['unit'] )
|
||||
{
|
||||
case 'd':
|
||||
return $lang->pluralize( $lang->get('renew_days'), array( $term['term'] ) );
|
||||
case 'm':
|
||||
return $lang->pluralize( $lang->get('renew_months'), array( $term['term'] ) );
|
||||
case 'y':
|
||||
return $lang->pluralize( $lang->get('renew_years'), array( $term['term'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of days
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function days()
|
||||
{
|
||||
$days = 0;
|
||||
if ( $this->interval->y )
|
||||
{
|
||||
$days += ( 365 * $this->interval->y );
|
||||
}
|
||||
if ( $this->interval->m )
|
||||
{
|
||||
$days += ( ( 365 / 12 ) * $this->interval->m );
|
||||
}
|
||||
if ( $this->interval->d )
|
||||
{
|
||||
$days += $this->interval->d;
|
||||
}
|
||||
return $days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate cost per day
|
||||
*
|
||||
* @return \IPS\nexus\Money Cost per day
|
||||
*/
|
||||
public function costPerDay()
|
||||
{
|
||||
$days = $this->days();
|
||||
if ( !$days )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->cost->amount / $days, $this->cost->currency );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To String
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
//return \IPS\Member::loggedIn()->language()->addToStack( 'renew_option', FALSE, array( 'sprintf' => array( $this->cost, $this->getTermUnit() ) ) );
|
||||
return sprintf( \IPS\Member::loggedIn()->language()->get( 'renew_option'), $this->cost, $this->getTermUnit() ) ;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user