Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+10 -6
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -94,7 +94,7 @@ class _Ad extends \IPS\nexus\Package
},
'formatValue' => function( $element )
{
if( !is_array( $element->value ) AND $element->value == -1 )
if( !\is_array( $element->value ) AND $element->value == -1 )
{
return array( 'value' => -1, 'type' => 'i' );
}
@@ -122,12 +122,12 @@ class _Ad extends \IPS\nexus\Package
{
if( isset( $values['p_exempt'] ) )
{
$values['p_exempt'] = is_array( $values['p_exempt'] ) ? implode( ',', $values['p_exempt'] ) : $values['p_exempt'];
$values['p_exempt'] = \is_array( $values['p_exempt'] ) ? implode( ',', $values['p_exempt'] ) : $values['p_exempt'];
}
if ( isset( $values['p_expire'] ) and is_array( $values['p_expire'] ) )
if ( isset( $values['p_expire'] ) and \is_array( $values['p_expire'] ) )
{
$values['expire'] = intval( $values['p_expire']['value'] );
$values['expire'] = \intval( $values['p_expire']['value'] );
$values['expire_unit'] = $values['p_expire']['type'];
unset( $values['p_expire'] );
}
@@ -379,6 +379,7 @@ class _Ad extends \IPS\nexus\Package
/**
* Get ACP Page HTML
*
* @param \IPS\nexus\Purchase $purchase Purchase record
* @return string
*/
public function acpPage( \IPS\nexus\Purchase $purchase )
@@ -440,13 +441,16 @@ class _Ad extends \IPS\nexus\Package
'ad_maximum_unit' => $this->expire_unit,
'ad_additional_settings'=> json_encode( array() ),
'ad_html_https_set' => 0,
'ad_member' => $purchase->member->member_id
'ad_member' => $purchase->member->member_id,
'ad_type' => \IPS\core\Advertisement::AD_IMAGES,
) );
$extra = $purchase->extra;
$extra['ad'] = $insertId;
$purchase->extra = $extra;
$purchase->save();
\IPS\core\AdminNotification::send( 'nexus', 'Advertisement', NULL, TRUE, $purchase );
parent::onPurchaseGenerated( $purchase, $invoice );
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -132,7 +132,7 @@ class _CustomField extends \IPS\CustomField
public function form( &$form )
{
parent::form( $form );
$packages = array();
foreach ( array_filter( explode( ',', $this->packages ) ) as $id )
{
@@ -146,7 +146,7 @@ class _CustomField extends \IPS\CustomField
{
return !( $node instanceof \IPS\nexus\Package\Group );
} ) ), 'pf_desc' );
$form->add( new \IPS\Helpers\Form\YesNo( 'cf_sticky', $this->sticky, FALSE, array(), NULL, NULL, NULL, 'cf_sticky' ), 'pf_type' );
$form->add( new \IPS\Helpers\Form\YesNo( 'cf_sticky', $this->sticky ?: FALSE, FALSE, array(), NULL, NULL, NULL, 'cf_sticky' ), 'pf_type' );
$form->add( new \IPS\Helpers\Form\YesNo( 'cf_allow_attachments', $this->id ? $this->allow_attachments : 1, FALSE, array( ), NULL, NULL, NULL, 'pf_allow_attachments' ) );
$form->addHeader( 'display_settings' );
@@ -174,7 +174,7 @@ class _CustomField extends \IPS\CustomField
*/
public function formatFormValues( $values )
{
if( isset( $values['cf_packages'] ) AND is_array( $values['cf_packages'] ) )
if( isset( $values['cf_packages'] ) AND \is_array( $values['cf_packages'] ) )
{
$values['packages'] = implode( ',', array_map( function( $node ){ return $node->id; }, $values['cf_packages'] ) );
unset( $values['cf_packages'] );
@@ -197,17 +197,22 @@ class _CustomField extends \IPS\CustomField
*
* @param mixed $value The value
* @param callback $customValidationCode Custom validation code
* @param \IPS\Content|NULL $content The associated content, if editing
* @return \IPS\Helpers\Form\FormAbstract
*/
public function buildHelper( $value=NULL, $customValidationCode=NULL )
public function buildHelper( $value=NULL, $customValidationCode=NULL, \IPS\Content $content = NULL )
{
if ( $this->type === 'UserPass' )
{
$class = 'IPS\nexus\Form\\' . $this->type;
return new $class( static::$langKey . '_' . $this->id, $value, $this->not_null, array(), NULL, NULL, NULL, static::$langKey . '_' . $this->id );
}
elseif ( $this->type === 'Ftp' )
{
return new \IPS\Helpers\Form\Ftp( static::$langKey . '_' . $this->id, $value, $this->not_null, array( 'validate' => $this->validate ), NULL, NULL, NULL, static::$langKey . '_' . $this->id );
}
return parent::buildHelper( $value, $customValidationCode );
return parent::buildHelper( $value, $customValidationCode, $content );
}
/**
@@ -221,7 +226,7 @@ class _CustomField extends \IPS\CustomField
{
if ( $this->type === 'UserPass' )
{
if ( !is_array( $value ) )
if ( !\is_array( $value ) )
{
$value = json_decode( \IPS\Text\Encrypt::fromTag( $value )->decrypt(), TRUE );
}
+1 -1
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -0,0 +1,235 @@
<?php
/**
* @brief Package Filter
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage Nexus
* @since 22 Aug 2018
*/
namespace IPS\nexus\Package;
/* 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;
}
/**
* Package Filter
*/
class _Filter extends \IPS\Node\Model
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'nexus_package_filters';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'pfilter_';
/**
* @brief [Node] Order Database Column
*/
public static $databaseColumnOrder = 'order';
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'menu__nexus_store_filters';
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
*/
public static $titleLangPrefix = 'nexus_product_filter_';
/**
* @brief [Node] ACP Restrictions
* @code
array(
'app' => 'core', // The application key which holds the restrictrions
'module' => 'foo', // The module key which holds the restrictions
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
'add' => 'foo_add',
'edit' => 'foo_edit',
'permissions' => 'foo_perms',
'delete' => 'foo_delete'
),
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
* @endcode
*/
protected static $restrictions = array(
'app' => 'nexus',
'module' => 'store',
'all' => 'packages_manage',
);
/**
* [Node] Add/Edit Form
*
* @param \IPS\Helpers\Form $form The form
* @return void
*/
public function form( &$form )
{
$form->addHeader( 'pfilter_basic_settings' );
$form->add( new \IPS\Helpers\Form\Translatable( 'pfilter_admin_name', NULL, TRUE, array( 'app' => 'nexus', 'key' => $this->id ? "nexus_product_filter_{$this->id}" : NULL ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'pfilter_public_name', NULL, TRUE, array( 'app' => 'nexus', 'key' => $this->id ? "nexus_product_filter_{$this->id}_public" : NULL ) ) );
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->sortable = TRUE;
foreach ( \IPS\Lang::languages() as $lang )
{
if ( $lang->enabled )
{
\IPS\Member::loggedIn()->language()->words["lang_{$lang->id}"] = $lang->title;
$matrix->columns["lang_{$lang->id}"] = function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Text( $key, $value );
};
}
}
if ( $this->id )
{
foreach ( \IPS\Db::i()->select( '*', 'nexus_package_filters_values', array( 'pfv_filter=?', $this->id ), 'pfv_order' ) as $filterValue )
{
$matrix->rows[ $filterValue['pfv_value'] ][ 'lang_' . $filterValue['pfv_lang'] ] = $filterValue['pfv_text'];
}
}
$form->addHeader( 'pfilter_options' );
$form->addMatrix( 'pfilter_options', $matrix );
}
/**
* [Node] Format form values from add/edit form for save
*
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
{
if ( !$this->id )
{
$this->save();
}
if( isset( $values['pfilter_admin_name'] ) )
{
\IPS\Lang::saveCustom( 'nexus', "nexus_product_filter_{$this->id}", $values['pfilter_admin_name'] );
unset( $values['pfilter_admin_name'] );
}
if( isset( $values['pfilter_public_name'] ) )
{
\IPS\Lang::saveCustom( 'nexus', "nexus_product_filter_{$this->id}_public", $values['pfilter_public_name'] );
unset( $values['pfilter_public_name'] );
}
$order = 1;
$deletedIds = $this->id ? iterator_to_array( \IPS\Db::i()->select( 'pfv_value', 'nexus_package_filters_values', array( 'pfv_filter=?', $this->id ) )->setKeyField('pfv_value') ) : array();
foreach ( $values['pfilter_options'] as $k => $_values )
{
unset( $deletedIds[ $k ] );
if ( mb_substr( $k, 0, 5 ) === '_new_' )
{
$id = \IPS\Db::i()->select( 'MAX(pfv_value)', 'nexus_package_filters_values', array( 'pfv_filter=?', $this->id ) )->first() + 1;
foreach ( $_values as $langId => $text )
{
\IPS\Db::i()->insert( 'nexus_package_filters_values', array(
'pfv_filter' => $this->id,
'pfv_value' => $id,
'pfv_lang' => \intval( mb_substr( $langId, 5 ) ),
'pfv_text' => $text,
'pfv_order' => $order
) );
}
}
else
{
foreach ( $_values as $langId => $text )
{
\IPS\Db::i()->update( 'nexus_package_filters_values', array(
'pfv_text' => $text,
'pfv_order' => $order
), array( 'pfv_filter=? AND pfv_value=? AND pfv_lang=?', $this->id, $k, \intval( mb_substr( $langId, 5 ) ) ) );
}
}
$order++;
}
if ( $deletedIds )
{
\IPS\Db::i()->delete( 'nexus_package_filters_values', \IPS\Db::i()->in( 'pfv_value', $deletedIds ) );
}
unset( $values['pfilter_options'] );
return $values;
}
/**
* [ActiveRecord] Delete Record
*
* @return void
*/
public function delete()
{
\IPS\Db::i()->delete( 'nexus_package_filters_values', array( 'pfv_filter=?', $this->id ) );
parent::delete();
}
/**
* Work out filter query string value
*
* @param array $queryString Query string
* @param int $filterId ID of the filter
* @param int|null $valueToAdd Value to add to the filter array
* @param int|null $valueToRemove Value to remove from the filter array
* @return void
*/
public static function queryString( $queryString, $filterId, $valueToAdd=NULL, $valueToRemove = NULL )
{
$queryString = $queryString ?: array();
if ( $valueToAdd )
{
if ( isset( $queryString[ $filterId ] ) )
{
$new = explode( ',', $queryString[ $filterId ] );
$new[] = $valueToAdd;
$queryString[ $filterId ] = implode( ',', $new );
}
else
{
$queryString[ $filterId ] = $valueToAdd;
}
}
elseif ( $valueToRemove and isset( $queryString[ $filterId ] ) )
{
$new = explode( ',', $queryString[ $filterId ] );
unset( $new[ array_search( $valueToRemove, $new ) ] );
if ( $new )
{
$queryString[ $filterId ] = implode( ',', $new );
}
else
{
unset( $queryString[ $filterId ] );
}
}
return $queryString;
}
}
+139 -8
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -57,6 +57,11 @@ class _Group extends \IPS\Node\Model
* @brief [Node] Subnode class
*/
public static $subnodeClass = 'IPS\nexus\Package';
/**
* @brief Content Item Class
*/
public static $contentItemClass = 'IPS\nexus\Package\Item';
/**
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
@@ -89,6 +94,29 @@ class _Group extends \IPS\Node\Model
'module' => 'store',
'prefix' => 'packages_',
);
/**
* Return only the root groups that have packages OR subcategories/groups
*
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
* @param mixed $where Additional WHERE clause
* @return array
*/
public static function rootsWithViewablePackages( $permissionCheck='view', $member=NULL, $where=array() )
{
$roots = static::roots( $permissionCheck, $member, $where );
foreach( $roots as $index => $group )
{
if( !$group->hasSubgroups() AND !$group->hasPackages( NULL, array( array( "p_store=1 AND ( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', \IPS\Member::loggedIn()->groups ) . ' )' ) ) ) )
{
unset( $roots[ $index ] );
}
}
return $roots;
}
/**
* Load record based on a URL
@@ -117,7 +145,8 @@ class _Group extends \IPS\Node\Model
* @return void
*/
public function form( &$form )
{
{
$form->addHeader('pg_basic_settings');
$form->add( new \IPS\Helpers\Form\Translatable( 'pg_name', NULL, TRUE, array( 'app' => 'nexus', 'key' => $this->id ? "nexus_pgroup_{$this->id}" : NULL ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'pg_desc', NULL, FALSE, array(
'app' => 'nexus',
@@ -130,7 +159,7 @@ class _Group extends \IPS\Node\Model
)
) ) );
$class = get_called_class();
$class = \get_called_class();
$form->add( new \IPS\Helpers\Form\Node( 'pg_parent', $this->id ? $this->parent : 0, TRUE, array( 'class' => 'IPS\nexus\Package\Group', 'subnodes' => FALSE, 'zeroVal' => 'no_parent', 'permissionCheck' => function( $node ) use ( $class )
{
@@ -141,7 +170,24 @@ class _Group extends \IPS\Node\Model
return !isset( \IPS\Request::i()->id ) or ( $node->id != \IPS\Request::i()->id and !$node->isChildOf( $node::load( \IPS\Request::i()->id ) ) );
} ) ) );
$form->add( new \IPS\Helpers\Form\Upload( 'pg_image', $this->image ? \IPS\File::get( 'nexus_PackageGroups', $this->image ) : NULL, FALSE, array( 'storageExtension' => 'nexus_PackageGroups', 'image' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\Upload( 'pg_image', $this->image ? \IPS\File::get( 'nexus_PackageGroups', $this->image ) : NULL, FALSE, array( 'storageExtension' => 'nexus_PackageGroups', 'image' => TRUE, 'allowStockPhotos' => TRUE ) ) );
$priceFilters = array();
if ( $this->price_filters )
{
foreach ( json_decode( $this->price_filters, TRUE ) as $currency => $prices )
{
foreach ( $prices as $i => $price )
{
$priceFilters[ $i ][ $currency ] = $price;
}
}
}
$form->addHeader('pg_filters_header');
$form->add( new \IPS\Helpers\Form\Node( 'pg_filters', explode( ',', $this->filters ), FALSE, array( 'class' => 'IPS\nexus\Package\Filter', 'multiple' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\Stack( 'pg_price_filters', $priceFilters, FALSE, array( 'stackFieldType' => 'IPS\nexus\Form\Money' ) ) );
}
/**
@@ -151,7 +197,7 @@ class _Group extends \IPS\Node\Model
* @return array
*/
public function formatFormValues( $values )
{
{
if( isset( $values['pg_parent'] ) )
{
$values['parent'] = $values['pg_parent'] ? $values['pg_parent']->id : 0;
@@ -183,6 +229,18 @@ class _Group extends \IPS\Node\Model
\IPS\Lang::saveCustom( 'nexus', "nexus_pgroup_{$this->id}_desc", $values['pg_desc'] );
unset( $values['pg_desc'] );
}
$values['pg_filters'] = $values['pg_filters'] ? implode( ',', array_keys( $values['pg_filters'] ) ) : NULL;
$priceFilters = array();
foreach ( $values['pg_price_filters'] as $filter )
{
foreach ( $filter as $currency => $amount )
{
$priceFilters[ $currency ][] = $amount->amount->jsonSerialize();
}
}
$values['pg_price_filters'] = \count( $priceFilters ) ? json_encode( $priceFilters ) : NULL;
return $values;
}
@@ -245,13 +303,47 @@ class _Group extends \IPS\Node\Model
* Does this group have packages?
*
* @param \IPS\Member|NULL|FALSE $member The member to perform the permission check for, or NULL for currently logged in member, or FALSE for no permission check
* @param mixed $_where Additional WHERE clause
* @param mixed $_where Additional WHERE clause
* @param bool $viewableOnly Only check packages the member can view
* @return bool
*/
public function hasPackages( $member=NULL, $_where=array() )
public function hasPackages( $member=NULL, $_where=array(), $viewableOnly=FALSE )
{
if( $viewableOnly === TRUE )
{
$member = $member ?: \IPS\Member::loggedIn();
$_where[] = array( "p_store=1 AND ( p_member_groups='*' OR " . \IPS\Db::i()->findInSet( 'p_member_groups', $member->groups ) . ' )' );
}
return ( $this->childrenCount( $member === FALSE ? FALSE : 'view', $member, NULL, $_where ) > 0 );
}
/**
* Get Filter Options
*
* @param \IPS\Lang $language The language to return options in
* @return array
*/
public function filters( \IPS\Lang $language )
{
$return = array();
if ( $this->filters )
{
foreach ( \IPS\Db::i()->select( 'pfilter_id', 'nexus_package_filters', array( \IPS\Db::i()->in( 'pfilter_id', explode( ',', $this->filters ) ) ), 'pfilter_order' ) as $filterId )
{
$return[ $filterId ] = array();
}
foreach ( \IPS\Db::i()->select( '*', 'nexus_package_filters_values', array( array( \IPS\Db::i()->in( 'pfv_filter', array_keys( $return ) ) ), array( 'pfv_lang=?', $language->id ) ), 'pfv_order' ) as $value )
{
$return[ $value['pfv_filter'] ][ $value['pfv_value'] ] = $value['pfv_text'];
}
}
return $return;
}
/**
* [ActiveRecord] Duplicate
@@ -285,6 +377,45 @@ class _Group extends \IPS\Node\Model
$this->save();
}
}
/**
* Is this node currently queued for deleting or moving content?
*
* @return bool
*/
public function deleteOrMoveQueued()
{
return FALSE;
}
/**
* [Node] Get buttons to display in tree
* Example code explains return value
*
* @code
array(
array(
'icon' => 'plus-circle', // Name of FontAwesome icon to use
'title' => 'foo', // Language key to use for button's title parameter
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
'class' => 'modalLink' // CSS Class to use on link (Optional)
),
... // Additional buttons
);
* @endcode
* @param string $url Base URL
* @param bool $subnode Is this a subnode?
* @return array
*/
public function getButtons( $url, $subnode=FALSE )
{
$buttons = parent::getButtons( $url, $subnode );
}
if( isset( $buttons['content'] ) )
{
$buttons['content']['title'] = 'mass_manage_productgroups';
}
return $buttons;
}
}
+36 -35
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -53,7 +53,7 @@ class _Hosting extends \IPS\nexus\Package
{
$stickyCustomFields = array_filter( parent::getPurchaseNameInfo( $purchase ) );
if ( !count( $stickyCustomFields ) )
if ( !\count( $stickyCustomFields ) )
{
try
{
@@ -120,7 +120,7 @@ class _Hosting extends \IPS\nexus\Package
{
if( isset( $values['p_queue'] ) )
{
$values['p_queue'] = is_object( $values['p_queue'] ) ? $values['p_queue']->id : $values['p_queue'];
$values['p_queue'] = \is_object( $values['p_queue'] ) ? $values['p_queue']->id : $values['p_queue'];
}
return parent::formatFormValues( $values );
@@ -168,7 +168,7 @@ class _Hosting extends \IPS\nexus\Package
if ( isset( $changes[ $k ] ) )
{
/* What is the current value? */
$currentValue = call_user_func( array( $account, $method ) );
$currentValue = $account->$method();
if ( $currentValue === NULL )
{
$currentValue = -1;
@@ -252,7 +252,7 @@ class _Hosting extends \IPS\nexus\Package
$domainTypeOptions = array();
$domainTypeToggles = array();
$domainPrices = NULL;
if ( \IPS\Settings::i()->nexus_enom_un and $domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE ) and count( $domainPrices ) )
if ( \IPS\Settings::i()->nexus_enom_un and $domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE ) and \count( $domainPrices ) )
{
$domainTypeOptions['buy'] = 'ha_domain_buy';
$domainTypeToggles['buy'] = array( 'ha_domain_to_buy' );
@@ -265,17 +265,17 @@ class _Hosting extends \IPS\nexus\Package
if ( \IPS\Settings::i()->nexus_hosting_allow_own_domain )
{
$ownDomainOptions = explode( ',', \IPS\Settings::i()->nexus_hosting_own_domains );
if ( in_array( 'nameservers', $ownDomainOptions ) or in_array( 'aname', $ownDomainOptions ) or ( in_array( 'cname', $ownDomainOptions ) and $canParkDomains ) )
if ( \in_array( 'nameservers', $ownDomainOptions ) or \in_array( 'aname', $ownDomainOptions ) or ( \in_array( 'cname', $ownDomainOptions ) and $canParkDomains ) )
{
$domainTypeOptions['own'] = 'ha_domain_own';
$domainTypeToggles['own'] = array( 'ha_domain_to_use' );
}
}
if ( !count( $domainTypeOptions ) )
if ( !\count( $domainTypeOptions ) )
{
\IPS\Output::i()->error( 'hosting_err_public', '4X245/4', 500, 'hosting_err_no_domains' );
}
if ( count( $domainTypeOptions ) > 1 )
if ( \count( $domainTypeOptions ) > 1 )
{
$form->add( new \IPS\Helpers\Form\Radio( 'ha_domain_type', NULL, TRUE, array( 'options' => $domainTypeOptions, 'toggles' => $domainTypeToggles ) ) );
}
@@ -385,14 +385,14 @@ class _Hosting extends \IPS\nexus\Package
$options = explode( ',', \IPS\Settings::i()->nexus_hosting_own_domains );
if ( $domain->type === \IPS\nexus\DomainLookup::DOMAIN_TYPE_DOMAIN )
{
if ( !in_array( 'nameservers', $options ) )
if ( !\in_array( 'nameservers', $options ) )
{
throw new \DomainException('domain_must_be_subdomain');
}
}
else
{
if ( !in_array( 'aname', $options ) and ( !in_array( 'cname', $options ) or !$this->maxpark ) )
if ( !\in_array( 'aname', $options ) and ( !\in_array( 'cname', $options ) or !$this->maxpark ) )
{
throw new \DomainException('domain_cannot_be_subdomain');
}
@@ -429,7 +429,7 @@ class _Hosting extends \IPS\nexus\Package
if ( $domain->type === \IPS\nexus\DomainLookup::DOMAIN_TYPE_DOMAIN )
{
if ( !in_array( 'nameservers', $options ) )
if ( !\in_array( 'nameservers', $options ) )
{
throw new \DomainException('domain_must_be_subdomain');
}
@@ -458,12 +458,12 @@ class _Hosting extends \IPS\nexus\Package
else
{
$aname = NULL;
if ( in_array( 'aname', $options ) )
if ( \in_array( 'aname', $options ) )
{
$aname = \IPS\nexus\Hosting\Server::load( $values['server'] )->ip;
}
if ( in_array( 'cname', $options ) and $this->maxpark )
if ( \in_array( 'cname', $options ) and $this->maxpark )
{
if ( !$cname )
{
@@ -481,7 +481,7 @@ class _Hosting extends \IPS\nexus\Package
$isValid = FALSE;
$records = @dns_get_record( $values['ha_domain_to_use'], 0 + ( $aname ? DNS_A : 0 ) + ( $cname ? DNS_CNAME : 0 ) );
if ( is_array( $records ) )
if ( \is_array( $records ) )
{
foreach ( $records as $record )
{
@@ -521,7 +521,7 @@ class _Hosting extends \IPS\nexus\Package
try
{
$server = \IPS\nexus\Hosting\Server::load( \IPS\Request::i()->server );
if ( !in_array( $this->queue, explode( ',', $server->queues ) ) )
if ( !\in_array( $this->queue, explode( ',', $server->queues ) ) )
{
throw new \OutOfRangeException;
}
@@ -609,7 +609,7 @@ class _Hosting extends \IPS\nexus\Package
*/
public function generateInvoiceForm( \IPS\Helpers\Form $form, $k )
{
$class = get_class();
$class = \get_class();
$field = new \IPS\Helpers\Form\Text( 'ha_domain_to_use' . $k, NULL, NULL, array(), function( $value ) use ( $class )
{
if ( !$value )
@@ -697,15 +697,15 @@ class _Hosting extends \IPS\nexus\Package
$form->add( new \IPS\Helpers\Form\Text( 'account_username', $account->username, TRUE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
$form->add( new \IPS\Helpers\Form\Text( 'account_password', $account->password, TRUE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
$form->add( new \IPS\Helpers\Form\Text( 'account_domain', $account->domain, TRUE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_quota', ( $account->diskspaceAllowance() !== NULL ? intval( $account->diskspaceAllowance() ) / 1048576 / 1.024 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, 'MB' ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_bwlimit', ( $account->monthlyBandwidthAllowance() !== NULL ? intval( $account->monthlyBandwidthAllowance() ) / 1048576 / 1.024 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, \IPS\Member::loggedIn()->language()->get('mb_per_month') ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxftp', ( $account->maxFtpAccounts() !== NULL ? intval( $account->maxFtpAccounts() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsql', ( $account->maxDatabases() !== NULL ? intval( $account->maxDatabases() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpop', ( $account->maxEmailAccounts() !== NULL ? intval( $account->maxEmailAccounts() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxlst', ( $account->maxMailingLists() !== NULL ? intval( $account->maxMailingLists() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsub', ( $account->maxSubdomains() !== NULL ? intval( $account->maxSubdomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpark', ( $account->maxParkedDomains() !== NULL ? intval( $account->maxParkedDomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxaddon', ( $account->maxAddonDomains() !== NULL ? intval( $account->maxAddonDomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_quota', ( $account->diskspaceAllowance() !== NULL ? \intval( $account->diskspaceAllowance() ) / 1048576 / 1.024 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, 'MB' ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_bwlimit', ( $account->monthlyBandwidthAllowance() !== NULL ? \intval( $account->monthlyBandwidthAllowance() ) / 1048576 / 1.024 : -1 ), TRUE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ), NULL, NULL, \IPS\Member::loggedIn()->language()->get('mb_per_month') ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxftp', ( $account->maxFtpAccounts() !== NULL ? \intval( $account->maxFtpAccounts() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsql', ( $account->maxDatabases() !== NULL ? \intval( $account->maxDatabases() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpop', ( $account->maxEmailAccounts() !== NULL ? \intval( $account->maxEmailAccounts() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxlst', ( $account->maxMailingLists() !== NULL ? \intval( $account->maxMailingLists() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxsub', ( $account->maxSubdomains() !== NULL ? \intval( $account->maxSubdomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxpark', ( $account->maxParkedDomains() !== NULL ? \intval( $account->maxParkedDomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'p_maxaddon', ( $account->maxAddonDomains() !== NULL ? \intval( $account->maxAddonDomains() ) : -1 ), FALSE, array( 'unlimited' => -1, 'endSuffix' => \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'p_hasshell', $account->hasSSHAccess(), FALSE, array(), NULL, NULL, \IPS\Theme::i()->getTemplate('hosting')->accountEditWarning() ) );
$form->add( new \IPS\Helpers\Form\Custom( 'do_not_update_server', FALSE, FALSE, array(
'rowHtml' => function()
@@ -714,7 +714,7 @@ class _Hosting extends \IPS\nexus\Package
}
) ) );
if ( count( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_parent=?', 'nexus', 'bandwidth', $purchase->id ) ) ) )
if ( \count( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_app=? AND ps_type=? AND ps_parent=?', 'nexus', 'bandwidth', $purchase->id ) ) ) )
{
\IPS\Member::loggedIn()->language()->words['p_bwlimit_warning'] = \IPS\Member::loggedIn()->language()->addToStack('bandwidth_edit_warn');
}
@@ -938,7 +938,7 @@ class _Hosting extends \IPS\nexus\Package
$account->save();
return;
}
return $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
case 'bandwidth':
$bandwidthOptions = json_decode( \IPS\Settings::i()->nexus_hosting_bandwidth, TRUE );
@@ -996,7 +996,7 @@ class _Hosting extends \IPS\nexus\Package
return;
}
return $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'forms', 'core' ) ), 'popupTemplate' ) );
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
case 'changedomain':
$account = \IPS\nexus\Hosting\Account::load( $purchase->id );
@@ -1092,7 +1092,7 @@ class _Hosting extends \IPS\nexus\Package
try
{
$server = \IPS\nexus\Hosting\Server::load( $purchase->extra['server'] );
if ( !in_array( $this->queue, explode( ',', $server->queues ) ) )
if ( !\in_array( $this->queue, explode( ',', $server->queues ) ) )
{
throw new \OutOfRangeException;
}
@@ -1116,23 +1116,24 @@ class _Hosting extends \IPS\nexus\Package
$username = mb_substr( preg_replace("/[^a-z\s]/", '', mb_strtolower( $purchase->extra['domain'] ) ), 0, 8 );
while ( mb_strlen( $username ) < 8 )
{
$username .= chr( rand( 97, 122 ) );
$username .= \chr( rand( 97, 122 ) );
}
/* If it already exists, change characters until we get one that doesn't */
do
{
$select = \IPS\Db::i()->select( '*', 'nexus_hosting_accounts', array( 'account_username=? AND account_server=?', $username, $server->id ) );
if ( count( $select ) or !$server->checkUsername( $username ) )
if ( \count( $select ) or !$server->checkUsername( $username ) )
{
$charToChange = rand( 0, 8 - 1 );
$username[ $charToChange ] = chr( rand( 97, 122 ) );
$username[ $charToChange ] = \chr( rand( 97, 122 ) );
}
}
while ( count( $select ) or !$server->checkUsername( $username ) );
while ( \count( $select ) or !$server->checkUsername( $username ) );
/* Create the account */
$class = 'IPS\nexus\Hosting\\' . mb_ucfirst( $server->type ) . '\Account';
$availableTypes = \IPS\nexus\Hosting\Account::accountTypes();
$class = $availableTypes[ mb_ucfirst( $server->type ) ];
$account = new $class;
$account->ps_id = $purchase->id;
$account->server = $server;
@@ -1295,7 +1296,7 @@ class _Hosting extends \IPS\nexus\Package
foreach ( array( 'quota' => 'diskspaceAllowance', 'bwlimit' => 'monthlyBandwidthAllowance', 'maxftp' => 'maxFtpAccounts', 'maxsql' => 'maxDatabases', 'maxpop' => 'maxEmailAccounts', 'maxlst' => 'maxMailingLists', 'maxsub' => 'maxSubdomains', 'maxpark' => 'maxParkedDomains', 'maxaddon' => 'maxAddonDomains', 'hasshell' => 'hasSSHAccess' ) as $k => $method )
{
/* What is the current value? */
$currentValue = call_user_func( array( $account, $method ) );
$currentValue = $account->$method();
if ( $currentValue === NULL )
{
$currentValue = -1;
+126 -38
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -130,6 +130,33 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
$member = $member ?: \IPS\Member::loggedIn();
return $this->member_groups === '*' or $member->inGroup( explode( ',', $this->member_groups ) );
}
/**
* Delete Package Data
*
* @return void
*/
public function delete()
{
/* Delete Images */
foreach( \IPS\Db::i()->select( '*', 'nexus_package_images', array( 'image_product=?', $this->id ) ) as $image )
{
try
{
\IPS\File::get( 'nexus_Products', $image['image_location'] )->delete();
}
catch ( \Exception $e ) { }
}
\IPS\Db::i()->delete( 'nexus_package_images', array( 'image_product=?', $this->id ) );
/* Delete Product Options */
\IPS\Db::i()->delete( 'nexus_product_options', array( 'opt_package=?', $this->id ) );
/* Delete Base Prices */
\IPS\Db::i()->delete( 'nexus_package_base_prices', array( 'id=?', $this->id ) );
parent::delete();
}
/**
* Get items with permisison check
@@ -196,10 +223,11 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
/**
* Can review?
*
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
* @param \IPS\Member\NULL $member The member (NULL for currently logged in member)
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will return TRUE if "Post Before Registering" feature is enabled
* @return bool
*/
public function canReview( $member=NULL )
public function canReview( $member=NULL, $considerPostBeforeRegistering = TRUE )
{
if ( !$this->reviewable )
{
@@ -208,7 +236,7 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
$member = $member ?: \IPS\Member::loggedIn();
if ( !parent::canReview( $member ) )
if ( !parent::canReview( $member, $considerPostBeforeRegistering ) )
{
return FALSE;
}
@@ -224,17 +252,18 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
/**
* Should new reviews be moderated?
*
* @param \IPS\Member $member The member posting
* @param \IPS\Member $member The member posting
* @param bool $considerPostBeforeRegistering If TRUE, and $member is a guest, will check if a newly registered member would be moderated
* @return bool
*/
public function moderateNewReviews( \IPS\Member $member )
public function moderateNewReviews( \IPS\Member $member, $considerPostBeforeRegistering = FALSE )
{
if ( $this->review_moderate )
{
return TRUE;
}
return parent::moderateNewReviews( $member );
return parent::moderateNewReviews( $member, $considerPostBeforeRegistering );
}
/**
@@ -257,16 +286,16 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
*/
public function embedContent( $params )
{
$memberCurrency = ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
$memberCurrency = ( ( isset( \IPS\Request::i()->cookie['currency'] ) and \in_array( \IPS\Request::i()->cookie['currency'], \IPS\nexus\Money::currencies() ) ) ? \IPS\Request::i()->cookie['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
$package = \IPS\nexus\Package::load( $this->id );
/* Do we have renewal terms? */
$renewalTerm = NULL;
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
if ( count( $renewOptions ) )
if ( \count( $renewOptions ) )
{
$renewalTerm = TRUE;
if ( count( $renewOptions ) === 1 )
if ( \count( $renewOptions ) === 1 )
{
$renewalTerm = array_pop( $renewOptions );
$renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $renewalTerm['cost'][ $memberCurrency ]['amount'], $memberCurrency ), new \DateInterval( 'P' . $renewalTerm['term'] . mb_strtoupper( $renewalTerm['unit'] ) ), $package->tax ? \IPS\nexus\Tax::load( $package->tax ) : NULL, $renewalTerm['add'] );
@@ -373,7 +402,7 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
*/
public static function basicDataColumns()
{
return array( 'p_id', 'p_base_price', 'p_reviews', 'p_discounts', 'p_renew_options', 'p_tax', 'p_stock' );
return array( 'p_id', 'p_base_price', 'p_reviews', 'p_discounts', 'p_renew_options', 'p_tax', 'p_stock', 'p_initial_term' );
}
/**
@@ -381,9 +410,10 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
*
* @param array $indexData Data from the search index
* @param array $itemData Basic data about the item. Only includes columns returned by item::basicDataColumns()
* @param string|NULL $action Action
* @return \IPS\Http\Url
*/
public static function urlFromIndexData( $indexData, $itemData )
public static function urlFromIndexData( $indexData, $itemData, $action = NULL )
{
return \IPS\Http\Url::internal( "app=nexus&module=store&controller=product&id={$indexData['index_item_id']}", 'front', 'store_product', \IPS\Member::loggedIn()->language()->addToStack( 'nexus_package_' . $indexData['index_item_id'], FALSE, array( 'seotitle' => TRUE ) ) );
}
@@ -463,33 +493,14 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
{
$url = static::urlFromIndexData( $indexData, $itemData );
/* Work out the price to display @todo - make this more efficient */
try
{
$customer = \IPS\nexus\Customer::loggedIn();
$currency = ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : $customer->defaultCurrency();
$priceMayChange = FALSE;
$priceNotIncludingDiscounts = NULL;
$renewOptions = $itemData['p_renew_options'] ? json_decode( $itemData['p_renew_options'], TRUE ) : array();
$price = \IPS\nexus\Package::lowestPriceFromData( $customer, $currency, $indexData['index_item_id'], json_decode( $itemData['p_base_price'], TRUE ), json_decode( $itemData['p_discounts'], TRUE ), $renewOptions, $itemData['p_stock'], $itemData['extra']['tax'] ? \IPS\nexus\Tax::constructFromData( $itemData['extra']['tax'] ) : NULL, $priceMayChange, $priceNotIncludingDiscounts );
if ( $price < $priceNotIncludingDiscounts )
{
$price = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->priceDiscounted( new \IPS\nexus\Money( $priceNotIncludingDiscounts, $currency ), new \IPS\nexus\Money( $price, $currency ), $priceMayChange, TRUE, 'ipsStream_price' );
}
else
{
$price = \IPS\Theme::i()->getTemplate( 'store', 'nexus' )->price( new \IPS\nexus\Money( $price, $currency ), $priceMayChange, TRUE, 'ipsStream_price' );
}
}
catch ( \OutOfRangeException $e )
{
$price = NULL;
}
/* Work out the price to display */
$customer = \IPS\nexus\Customer::loggedIn();
$currency = ( isset( \IPS\Request::i()->cookie['currency'] ) and \in_array( \IPS\Request::i()->cookie['currency'], \IPS\nexus\Money::currencies() ) ) ? \IPS\Request::i()->cookie['currency'] : $customer->defaultCurrency();
$renewOptions = $itemData['p_renew_options'] ? json_decode( $itemData['p_renew_options'], TRUE ) : array();
$priceInfo = \IPS\nexus\Package::fullPriceInfoFromData( $customer, $currency, $indexData['index_item_id'], json_decode( $itemData['p_base_price'], TRUE ), json_decode( $itemData['p_discounts'], TRUE ), $renewOptions, $itemData['p_stock'], $itemData['extra']['tax'] ? \IPS\nexus\Tax::constructFromData( $itemData['extra']['tax'] ) : NULL, $itemData['p_initial_term'] ? new \DateInterval("P{$itemData['p_initial_term']}") : NULL );
/* Display */
return \IPS\Theme::i()->getTemplate( 'global', 'nexus', 'front' )->searchResultProductSnippet( $indexData, $itemData, isset( $itemData['extra']['image'] ) ? $itemData['extra']['image'] : NULL, $url, $price, $view == 'condensed' );
return \IPS\Theme::i()->getTemplate( 'global', 'nexus', 'front' )->searchResultProductSnippet( $indexData, $itemData, isset( $itemData['extra']['image'] ) ? $itemData['extra']['image'] : NULL, $url, $priceInfo, $view == 'condensed' );
}
/**
@@ -504,7 +515,7 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
{
/* Commerce Items have no own content type, so we can use only the general mod permissions */
$member = $member ?: \IPS\Member::loggedIn();
if ( in_array( $type, array( 'hide', 'unhide', 'delete' ) ) and $container )
if ( \in_array( $type, array( 'hide', 'unhide', 'delete' ) ) and $container )
{
if ( $member->modPermission( "can_{$type}" ) )
{
@@ -514,4 +525,81 @@ class _Item extends \IPS\Content\Item implements \IPS\Content\Featurable, \IPS\C
return parent::modPermission( $type, $member, $container );
}
/**
* Should posting this increment the poster's post count?
*
* @param \IPS\Node\Model|NULL $container Container
* @return void
*/
public static function incrementPostCount( \IPS\Node\Model $container = NULL )
{
return FALSE;
}
/**
* Can edit?
*
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
* @return bool
*/
public function canEdit( $member=NULL )
{
return FALSE;
}
/**
* Do Moderator Action
*
* @param string $action The action
* @param \IPS\Member|NULL $member The member doing the action (NULL for currently logged in member)
* @param string|NULL $reason Reason (for hides)
* @param bool $immediately Delete immediately
* @return void
* @throws \OutOfRangeException|\InvalidArgumentException|\RuntimeException
*/
public function modAction( $action, \IPS\Member $member = NULL, $reason = NULL, $immediately = FALSE )
{
throw new \InvalidArgumentException;
}
/**
* Can move?
*
* @param \IPS\Member|NULL $member The member to check for (NULL for currently logged in member)
* @return bool
*/
public function canMove( $member=NULL )
{
return FALSE;
}
/**
* Returns the meta description
*
* @param string|NULL $return Specific description to use (useful for paginated displays to prevent having to run extra queries)
* @return string
* @throws \BadMethodCallException
*/
public function metaDescription( $return = NULL )
{
return \IPS\Member::loggedIn()->language()->addToStack("nexus_package_{$this->id}_desc", FALSE, array( 'striptags' => TRUE ) );
}
/**
* Get container
*
* @return \IPS\Node\Model
* @note Certain functionality requires a valid container but some areas do not use this functionality (e.g. messenger)
* @throws \OutOfRangeException|\BadMethodCallException
*/
public function container()
{
if( $this->custom > 0 )
{
throw new \BadMethodCallException;
}
return parent::container();
}
}
File diff suppressed because it is too large. Load diff
+37 -31
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -48,11 +48,11 @@ class _Product extends \IPS\nexus\Package
if ( !$customEdit ) // After the package has been created, these are unimportant
{
$return['package_settings']['physical'] = new \IPS\Helpers\Form\YesNo( 'p_physical', $package->type === 'product' ? $package->physical : FALSE, FALSE, array( 'togglesOn' => array( 'p_weight', 'p_length', 'p_width', 'p_height', 'p_shipping' ) ) );
$return['package_settings']['weight'] = new \IPS\nexus\Form\Weight( 'p_weight', $package->type === 'product' ? new \IPS\nexus\Shipping\Weight( $package->weight ) : NULL, FALSE, array(), NULL, NULL, NULL, 'p_weight' );
$return['package_settings']['length'] = new \IPS\nexus\Form\Length( 'p_length', $package->type === 'product' ? new \IPS\nexus\Shipping\Length( $package->length ) : NULL, FALSE, array(), NULL, NULL, NULL, 'p_length' );
$return['package_settings']['width'] = new \IPS\nexus\Form\Length( 'p_width', $package->type === 'product' ? new \IPS\nexus\Shipping\Length( $package->width ) : NULL, FALSE, array(), NULL, NULL, NULL, 'p_width' );
$return['package_settings']['height'] = new \IPS\nexus\Form\Length( 'p_height', $package->type === 'product' ? new \IPS\nexus\Shipping\Length( $package->height ) : NULL, FALSE, array(), NULL, NULL, NULL, 'p_height' );
$return['package_settings']['physical'] = new \IPS\Helpers\Form\YesNo( 'p_physical', $package->type === 'product' ? $package->physical : FALSE, FALSE, array( 'disableCopy' => TRUE, 'togglesOn' => array( 'p_weight', 'p_length', 'p_width', 'p_height', 'p_shipping' ), 'togglesOff' => array( 'elProductTaxWarningContainer' ) ) );
$return['package_settings']['weight'] = new \IPS\nexus\Form\Weight( 'p_weight', $package->type === 'product' ? new \IPS\nexus\Shipping\Weight( $package->weight ) : NULL, FALSE, array( 'disableCopy' => TRUE ), NULL, NULL, NULL, 'p_weight' );
$return['package_settings']['length'] = new \IPS\nexus\Form\Length( 'p_length', $package->type === 'product' ? new \IPS\nexus\Shipping\Length( $package->length ) : NULL, FALSE, array( 'disableCopy' => TRUE ), NULL, NULL, NULL, 'p_length' );
$return['package_settings']['width'] = new \IPS\nexus\Form\Length( 'p_width', $package->type === 'product' ? new \IPS\nexus\Shipping\Length( $package->width ) : NULL, FALSE, array( 'disableCopy' => TRUE ), NULL, NULL, NULL, 'p_width' );
$return['package_settings']['height'] = new \IPS\nexus\Form\Length( 'p_height', $package->type === 'product' ? new \IPS\nexus\Shipping\Length( $package->height ) : NULL, FALSE, array( 'disableCopy' => TRUE ), NULL, NULL, NULL, 'p_height' );
$availableShippingMethods = array();
foreach ( \IPS\nexus\Shipping\FlatRate::roots() as $rate )
@@ -75,15 +75,10 @@ class _Product extends \IPS\nexus\Package
$licenseKeyOptions = array();
$licenseKeyToggles = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Purchase/LicenseKey' ) as $file )
foreach ( \IPS\nexus\Purchase\LicenseKey::licenseKeyTypes() as $key => $class )
{
if ( !$file->isDot() and $file != 'index.html' )
{
$key = mb_substr( $file, 0, -4 );
$class = 'IPS\nexus\Purchase\LicenseKey\\' . $key;
$licenseKeyOptions[ mb_strtolower( $key ) ] = 'lkey_' . $key;
$licenseKeyToggles[ mb_strtolower( $key ) ] = array( 'p_lkey_identifier', 'p_lkey_uses' );
}
$licenseKeyOptions[ mb_strtolower( $key ) ] = 'lkey_' . $key;
$licenseKeyToggles[ mb_strtolower( $key ) ] = array( 'p_lkey_identifier', 'p_lkey_uses' );
}
if ( !empty( $licenseKeyOptions ) )
{
@@ -126,7 +121,7 @@ class _Product extends \IPS\nexus\Package
if( isset( $values['p_weight'] ) )
{
$values['p_weight'] = is_object( $values['p_weight'] ) ? $values['p_weight']->kilograms : 0;
$values['p_weight'] = \is_object( $values['p_weight'] ) ? $values['p_weight']->kilograms : 0;
}
else
{
@@ -135,7 +130,7 @@ class _Product extends \IPS\nexus\Package
if( isset( $values['p_length'] ) )
{
$values['p_length'] = is_object( $values['p_length'] ) ? $values['p_length']->metres : 0;
$values['p_length'] = \is_object( $values['p_length'] ) ? $values['p_length']->metres : 0;
}
else
{
@@ -144,7 +139,7 @@ class _Product extends \IPS\nexus\Package
if( isset( $values['p_width'] ) )
{
$values['p_width'] = is_object( $values['p_width'] ) ? $values['p_width']->metres : 0;
$values['p_width'] = \is_object( $values['p_width'] ) ? $values['p_width']->metres : 0;
}
else
{
@@ -153,7 +148,7 @@ class _Product extends \IPS\nexus\Package
if( isset( $values['p_height'] ) )
{
$values['p_height'] = is_object( $values['p_height'] ) ? $values['p_height']->metres : 0;
$values['p_height'] = \is_object( $values['p_height'] ) ? $values['p_height']->metres : 0;
}
else
{
@@ -162,7 +157,7 @@ class _Product extends \IPS\nexus\Package
if( isset( $values['p_shipping'] ) )
{
$values['p_shipping'] = is_array( $values['p_shipping'] ) ? implode( ',', $values['p_shipping'] ) : '*';
$values['p_shipping'] = \is_array( $values['p_shipping'] ) ? implode( ',', $values['p_shipping'] ) : '*';
}
return parent::formatFormValues( $values );
@@ -196,18 +191,26 @@ class _Product extends \IPS\nexus\Package
if ( array_key_exists( 'lkey', $changes ) )
{
$oldKey = NULL;
try
$lKey = $purchase->licenseKey();
if ( $lKey )
{
$purchase->licenseKey()->delete();
$lKey->delete();
}
catch ( \OutOfRangeException $e ) { }
$class = 'IPS\nexus\Purchase\LicenseKey\\' . mb_ucfirst( $this->lkey );
$licenseKey = new $class;
$licenseKey->identifier = $this->lkey_identifier;
$licenseKey->purchase = $purchase;
$licenseKey->max_uses = $this->lkey_uses;
$licenseKey->save();
$licenseTypes = \IPS\nexus\Purchase\LicenseKey::licenseKeyTypes();
if( class_exists( $licenseTypes[ mb_ucfirst( $this->lkey ) ]) )
{
$class = $licenseTypes[ mb_ucfirst( $this->lkey ) ];
$licenseKey = new $class;
$licenseKey->identifier = $this->lkey_identifier;
$licenseKey->purchase = $purchase;
$licenseKey->max_uses = $this->lkey_uses;
$licenseKey->save();
}
}
elseif ( array_key_exists( 'lkey_identifier', $changes ) or array_key_exists( 'lkey_uses', $changes ) )
{
@@ -344,6 +347,7 @@ class _Product extends \IPS\nexus\Package
{
case 'lkeyReset':
\IPS\Dispatcher::i()->checkAcpPermission( 'lkeys_reset' );
\IPS\Session::i()->csrfCheck();
$oldKey = NULL;
try
@@ -359,7 +363,8 @@ class _Product extends \IPS\nexus\Package
/* Invalidate License Key Cache so old data is not loaded */
$purchase->licenseKey = NULL;
$class = 'IPS\nexus\Purchase\LicenseKey\\' . mb_ucfirst( $this->lkey );
$licenseTypes = \IPS\nexus\Purchase\LicenseKey::licenseKeyTypes();
$class = $licenseTypes[ mb_ucfirst( $this->lkey ) ];
$licenseKey = new $class;
$licenseKey->identifier = $this->lkey_identifier;
$licenseKey->purchase = $purchase;
@@ -385,7 +390,8 @@ class _Product extends \IPS\nexus\Package
{
if ( $this->lkey )
{
$class = 'IPS\nexus\Purchase\LicenseKey\\' . mb_ucfirst( $this->lkey );
$licenseTypes = \IPS\nexus\Purchase\LicenseKey::licenseKeyTypes();
$class = $licenseTypes[ mb_ucfirst( $this->lkey ) ];
$licenseKey = new $class;
$licenseKey->identifier = $this->lkey_identifier;
$licenseKey->purchase = $purchase;
@@ -12,7 +12,7 @@
namespace IPS\nexus\Package;
/* 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;
@@ -121,16 +121,16 @@ class _Review extends \IPS\Content\Review implements \IPS\Content\EditHistory, \
*/
public function embedContent( $params )
{
$memberCurrency = ( ( isset( $_SESSION['currency'] ) and in_array( $_SESSION['currency'], \IPS\nexus\Money::currencies() ) ) ? $_SESSION['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
$memberCurrency = ( ( isset( \IPS\Request::i()->cookie['currency'] ) and \in_array( \IPS\Request::i()->cookie['currency'], \IPS\nexus\Money::currencies() ) ) ? \IPS\Request::i()->cookie['currency'] : \IPS\nexus\Customer::loggedIn()->defaultCurrency() );
$package = \IPS\nexus\Package::load( $this->id );
/* Do we have renewal terms? */
$renewalTerm = NULL;
$renewOptions = $package->renew_options ? json_decode( $package->renew_options, TRUE ) : array();
if ( count( $renewOptions ) )
if ( \count( $renewOptions ) )
{
$renewalTerm = TRUE;
if ( count( $renewOptions ) === 1 )
if ( \count( $renewOptions ) === 1 )
{
$renewalTerm = array_pop( $renewOptions );
$renewalTerm = new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $renewalTerm['cost'][ $memberCurrency ]['amount'], $memberCurrency ), new \DateInterval( 'P' . $renewalTerm['term'] . mb_strtoupper( $renewalTerm['unit'] ) ), $package->tax ? \IPS\nexus\Tax::load( $package->tax ) : NULL, $renewalTerm['add'] );