Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+275 -158
View File
@@ -12,89 +12,168 @@
namespace IPS\nexus\Package;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\core\AdminNotification;
use IPS\core\Advertisement;
use IPS\Db;
use IPS\Extensions\AdvertisementLocationsAbstract;
use IPS\Helpers\Form;
use IPS\Helpers\Form\CheckboxSet;
use IPS\Helpers\Form\Custom;
use IPS\Helpers\Form\Node;
use IPS\Helpers\Form\Number;
use IPS\Helpers\Form\Upload;
use IPS\Helpers\Form\WidthHeight;
use IPS\Helpers\Form\YesNo;
use IPS\Http\Url;
use IPS\Member;
use IPS\Member\Group;
use IPS\nexus\Invoice;
use IPS\nexus\Package;
use IPS\nexus\Purchase;
use IPS\nexus\Purchase\RenewalTerm;
use IPS\Request;
use IPS\Theme;
use OutOfRangeException;
use UnderflowException;
use function defined;
use function intval;
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;
}
/**
* Advertisement Package
*/
class _Ad extends \IPS\nexus\Package
class Ad extends Package
{
/**
* @brief Database Table
*/
protected static $packageDatabaseTable = 'nexus_packages_ads';
protected static string $packageDatabaseTable = 'nexus_packages_ads';
/**
* @brief Which columns belong to the local table
*/
protected static $packageDatabaseColumns = array( 'p_locations', 'p_exempt', 'p_expire', 'p_expire_unit', 'p_max_height', 'p_max_width' );
protected static array $packageDatabaseColumns = array( 'p_locations', 'p_exempt', 'p_expire', 'p_expire_unit', 'p_max_height', 'p_max_width', 'p_settings' );
/**
* @brief Icon
*/
public static $icon = 'newspaper-o';
public static string $icon = 'newspaper';
/**
* @brief Title
*/
public static $title = 'advertisement';
public static string $title = 'advertisement';
/* !ACP Package Form */
/**
* ACP Fields
*
* @param \IPS\nexus\Package $package The package
* @param bool $custom If TRUE, is for a custom package
* @param bool $customEdit If TRUE, is editing a custom package
* @return array
* @param Package $package The package
* @param bool $custom If TRUE, is for a custom package
* @param bool $customEdit If TRUE, is editing a custom package
* @return array
*/
public static function acpFormFields( \IPS\nexus\Package $package, $custom=FALSE, $customEdit=FALSE )
public static function acpFormFields( Package $package, bool $custom=FALSE, bool $customEdit=FALSE ): array
{
$return = array();
if ( !$customEdit ) // If we're editing a custom package, they can get to this by editing the advertisement
{
$locations = array(
'ad_global_header' => array(),
'ad_global_footer' => array(),
'ad_sidebar' => array(),
$currentValues = ( $package->id AND $package->settings ) ? json_decode( $package->settings, true ) : array();
/* Add the location fields, remember to call extensions for additional locations.
Array format: location => array of toggle fields to show */
$defaultLocations = array(
'ad_global_header' => array( 'ad_apps' ),
'ad_global_footer' => array( 'ad_apps' ),
'ad_sidebar' => array( 'ad_apps' ),
);
foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
$settingFields = [];
/* Add a field to restrict by app */
$settingFields[] = new Node( 'ad_apps', $currentValues['ad_apps'] ?? 0, false, array(
'class' => Application::class,
'multiple' => true,
'zeroVal' => 'all',
'subnodes' => false
), null, null, null, 'ad_apps' );
/* Now grab ad location extensions */
foreach ( Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
{
$result = $extension->getSettings( array() );
$locations = array_merge( $locations, $result['locations'] );
/* @var AdvertisementLocationsAbstract $extension */
$result = $extension->getSettings( $currentValues );
$defaultLocations = array_merge( $defaultLocations, $result['locations'] );
/* If this is a list view, add setting fields for interaval and repeat */
if( $extension::$listView )
{
$settingFields[] = new Number( 'ad_view_number', ( isset( $currentValues['ad_view_number'] ) AND $currentValues['ad_view_number'] ) ? $currentValues['ad_view_number'] : 1, FALSE, array( 'min' => 1 ), NULL, NULL, Member::loggedIn()->language()->addToStack('ad_view_number_suffix'), 'ad_view_number' );
$settingFields[] = new Number( 'ad_view_repeat', $currentValues['ad_view_repeat'] ?? 1, FALSE, array( 'unlimited' => -1 ), NULL, NULL, Member::loggedIn()->language()->addToStack('ad_view_repeat_suffix'), 'ad_view_repeat' );
foreach( $result['locations'] as $location => $toggles )
{
$defaultLocations[$location][] = 'ad_view_number';
$defaultLocations[$location][] = 'ad_view_repeat';
}
}
if( isset( $result['settings'] ) )
{
$settingFields = $settingFields + $result['settings'];
}
}
$locations['_ad_custom_'] = array('p_locations_custom');
$locationValues = array();
$customLocations = array();
/* Add the locations to the form, and make sure the toggles get set properly */
$locations = array();
if ( $package->id )
{
$locationValues = explode( ',', $package->locations );
$customLocations = array_diff( $locationValues, array_keys( $locations ) );
if ( !empty( $customLocations ) )
{
$locationValues[] = '_ad_custom_';
}
$locationValues = array_intersect( $locationValues, array_keys( $locations ) );
$locations = $package->locations ? explode( ',', $package->locations ) : [];
$locations = array_intersect( $locations, array_keys( $defaultLocations ) );
}
$return['package_settings']['p_locations'] = new \IPS\Helpers\Form\CheckboxSet( 'p_locations', $locationValues, TRUE, array( 'options' => array_combine( array_keys( $locations ), array_keys( $locations ) ), 'toggles' => $locations, 'userSuppliedInput' => '_ad_custom_' ) );
$return['package_settings']['p_locations_custom'] = new \IPS\Helpers\Form\Stack( 'p_locations_custom', $customLocations, FALSE, array(), NULL, NULL, NULL, 'p_locations_custom' );
$return['package_settings']['p_exempt'] = new \IPS\Helpers\Form\CheckboxSet( 'p_exempt', $package->id ? ( $package->exempt == '*' ? '*' : explode( ',', $package->exempt ) ) : '*', FALSE, array( 'options' => \IPS\Member\Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ) );
/* Make locations optional so that we can have ads for widgets only */
$return['package_settings']['p_locations'] = new CheckboxSet( 'p_locations',
$locations,
false,
array(
'options' => array_combine( array_keys( $defaultLocations ), array_keys( $defaultLocations ) ),
'toggles' => $defaultLocations,
'noDefault' => true
),
NULL,
NULL,
NULL,
'p_locations'
);
foreach( $settingFields as $settingField )
{
$return['package_settings'][ $settingField->name ] = $settingField;
}
$return['package_settings']['p_exempt'] = new CheckboxSet( 'p_exempt', ( $package->id and $package->exempt ) ? ( $package->exempt == '*' ? '*' : explode( ',', $package->exempt ) ) : '*', FALSE, array( 'options' => Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ) );
$return['package_settings']['p_expire'] = new \IPS\Helpers\Form\Custom( 'p_expire', array( 'value' => ( $package->id ) ? $package->expire : -1, 'type' => ( $package->id ) ? $package->expire_unit : 'i' ), FALSE, array(
$return['package_settings']['p_expire'] = new Custom( 'p_expire', array( 'value' => ( $package->id and $package->expire ) ? $package->expire : -1, 'type' => ( $package->id ) ? $package->expire_unit : 'i' ), FALSE, array(
'getHtml' => function( $element )
{
return \IPS\Theme::i()->getTemplate( 'promotion', 'core' )->imageMaximums( $element->name, $element->value['value'], $element->value['type'] );
return Theme::i()->getTemplate( 'promotion', 'core' )->imageMaximums( $element->name, $element->value['value'], $element->value['type'] );
},
'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' );
}
@@ -105,7 +184,7 @@ class _Ad extends \IPS\nexus\Package
if ( !$custom )
{
$return['package_settings']['p_max_dims'] = new \IPS\Helpers\Form\WidthHeight( 'p_max_dims', array( $package->max_width, $package->max_height ), FALSE, array( 'unlimited' => array( 0, 0 ), 'resizableDiv' => FALSE ) );
$return['package_settings']['p_max_dims'] = new WidthHeight( 'p_max_dims', ( $package->id and $package->width ) ? array( $package->max_width, $package->max_height ) : null, FALSE, array( 'unlimited' => array( 0, 0 ), 'resizableDiv' => FALSE ) );
}
}
@@ -118,16 +197,16 @@ class _Ad extends \IPS\nexus\Package
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
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'] );
}
@@ -141,16 +220,49 @@ class _Ad extends \IPS\nexus\Package
if ( isset( $values['p_locations'] ) )
{
$locations = $values['p_locations'];
$customKey = array_search( '_ad_custom_', $locations );
if ( $customKey !== FALSE )
$values['p_locations'] = is_array( $values['p_locations'] ) ? implode( ',', $values['p_locations'] ) : '';
}
$additionalSettings = array(
'ad_apps' => ( isset( $values['ad_apps'] ) AND $values['ad_apps'] != 0 ) ? array_keys( $values['ad_apps'] ) : 0
);
foreach ( Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension )
{
/* @var AdvertisementLocationsAbstract $extension */
if( $extension::$listView )
{
unset( $locations[ $customKey ] );
$locations = array_merge( $locations, $values['p_locations_custom'] );
$additionalSettings['ad_view_number'] = $values['ad_view_number'] ?? 1;
$additionalSettings['ad_view_repeat'] = $values['ad_view_repeat'] ?? 0;
}
$values['p_locations'] = implode( ',', $locations );
$settings = $extension->parseSettings( $values );
$additionalSettings = array_merge( $additionalSettings, $settings );
/* Unset any elements that were added */
$result = $extension->getSettings( $values );
if( isset( $result['settings'] ) )
{
foreach( $result['settings'] as $settingField )
{
if( isset( $values[ $settingField->name ] ) )
{
unset( $values[ $settingField->name ] );
}
}
}
}
$values['p_settings'] = json_encode( $additionalSettings );
foreach( array( 'ad_apps', 'ad_view_number', 'ad_view_repeat' ) as $field )
{
if( isset( $values[ $field ] ) )
{
unset( $values[ $field ] );
}
}
unset( $values['p_locations_custom'] );
return parent::formatFormValues( $values );
}
@@ -160,7 +272,7 @@ class _Ad extends \IPS\nexus\Package
*
* @return array
*/
public static function updateableFields()
public static function updateableFields() : array
{
return array_merge( parent::updateableFields(), array(
'locations',
@@ -173,22 +285,23 @@ class _Ad extends \IPS\nexus\Package
/**
* Update existing purchases
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param array $changes The old values
* @param bool $cancelBillingAgreementIfNecessary If making changes to renewal terms, TRUE will cancel associated billing agreements. FALSE will skip that change
* @return void
* @param Purchase $purchase The purchase
* @param array $changes The old values
* @param bool $cancelBillingAgreementIfNecessary If making changes to renewal terms, TRUE will cancel associated billing agreements. FALSE will skip that change
* @return void
*/
public function updatePurchase( \IPS\nexus\Purchase $purchase, $changes, $cancelBillingAgreementIfNecessary=FALSE )
public function updatePurchase(Purchase $purchase, array $changes, bool $cancelBillingAgreementIfNecessary=FALSE ): void
{
if ( $purchase->extra['ad'] )
{
try
{
$ad = \IPS\Db::i()->select( '*','core_advertisements', array( 'ad_id=?', $purchase->extra['ad'] ) )->first();
$ad = Db::i()->select( '*','core_advertisements', array( 'ad_id=?', $purchase->extra['ad'] ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
return parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
return;
}
$update = array();
@@ -212,7 +325,7 @@ class _Ad extends \IPS\nexus\Package
break;
}
if ( $ad[ $i ] == $changes[ $k ] )
if ( isset( $i ) AND $ad[ $i ] == $changes[ $k ] )
{
$update[ $i ] = $this->$k;
}
@@ -220,11 +333,11 @@ class _Ad extends \IPS\nexus\Package
}
if ( !empty( $update ) )
{
\IPS\Db::i()->update( 'core_advertisements', $update, array( 'ad_id=?', $purchase->extra['ad'] ) );
Db::i()->update( 'core_advertisements', $update, array( 'ad_id=?', $purchase->extra['ad'] ) );
}
}
return parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
parent::updatePurchase( $purchase, $changes, $cancelBillingAgreementIfNecessary );
}
/* !Store */
@@ -232,13 +345,13 @@ class _Ad extends \IPS\nexus\Package
/**
* Store Form
*
* @param \IPS\Helpers\Form $form The form
* @param string $memberCurrency The currency being used
* @return void
* @param Form $form The form
* @param string $memberCurrency The currency being used
* @return void
*/
public function storeForm( \IPS\Helpers\Form $form, $memberCurrency )
public function storeForm(Form $form, string $memberCurrency ): void
{
$form->add( new \IPS\Helpers\Form\Url( 'advertisement_url', NULL, TRUE ) );
$form->add( new Form\Url( 'advertisement_url', NULL, TRUE ) );
$maxDims = TRUE;
if ( $this->max_height or $this->max_width )
@@ -254,41 +367,42 @@ class _Ad extends \IPS\nexus\Package
}
}
if ( !isset( \IPS\Request::i()->stockCheck ) ) // The stock check will attempt to save the upload which we don't want to do until the form is actually submitted
if ( !isset( Request::i()->stockCheck ) ) // The stock check will attempt to save the upload which we don't want to do until the form is actually submitted
{
$form->add( new \IPS\Helpers\Form\Upload( 'advertisement_image', NULL, TRUE, array( 'storageExtension' => 'nexus_Ads', 'image' => $maxDims ) ) );
$form->add( new Upload( 'advertisement_image', NULL, TRUE, array( 'storageExtension' => 'nexus_Ads', 'image' => $maxDims ) ) );
}
if ( $this->max_height and $this->max_width )
{
\IPS\Member::loggedIn()->language()->words['advertisement_image_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'advertisement_image_max_wh', FALSE, array( 'sprintf' => array( $this->max_width, $this->max_height ) ) );
Member::loggedIn()->language()->words['advertisement_image_desc'] = Member::loggedIn()->language()->addToStack( 'advertisement_image_max_wh', FALSE, array( 'sprintf' => array( $this->max_width, $this->max_height ) ) );
}
elseif ( $this->max_height )
{
\IPS\Member::loggedIn()->language()->words['advertisement_image_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'advertisement_image_max_h', FALSE, array( 'sprintf' => array( $this->max_height ) ) );
Member::loggedIn()->language()->words['advertisement_image_desc'] = Member::loggedIn()->language()->addToStack( 'advertisement_image_max_h', FALSE, array( 'sprintf' => array( $this->max_height ) ) );
}
elseif ( $this->max_width )
{
\IPS\Member::loggedIn()->language()->words['advertisement_image_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'advertisement_image_max_w', FALSE, array( 'sprintf' => array( $this->max_width ) ) );
Member::loggedIn()->language()->words['advertisement_image_desc'] = Member::loggedIn()->language()->addToStack( 'advertisement_image_max_w', FALSE, array( 'sprintf' => array( $this->max_width ) ) );
}
$form->add( new \IPS\Helpers\Form\YesNo( 'ad_image_more', FALSE, FALSE, array( 'togglesOn' => array( 'ad_image_small', 'ad_image_medium' ) ), NULL, NULL, NULL, 'ad_image_more' ) );
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image_small', NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_small' ) );
$form->add( new \IPS\Helpers\Form\Upload( 'ad_image_medium', NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_medium' ) );
$form->add( new YesNo( 'ad_image_more', FALSE, FALSE, array( 'togglesOn' => array( 'ad_image_small', 'ad_image_medium' ) ), NULL, NULL, NULL, 'ad_image_more' ) );
$form->add( new Upload( 'ad_image_small', NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_small' ) );
$form->add( new Upload( 'ad_image_medium', NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_medium' ) );
}
/**
* Add To Cart
*
* @param \IPS\nexus\extensions\nexus\Item\Package $item The item
* @param \IPS\nexus\Invoice\Item $item The item
* @param array $values Values from form
* @param string $memberCurrency The currency being used
* @return array Additional items to add
* @param string $memberCurrency The currency being used
* @return array Additional items to add
*/
public function addToCart( \IPS\nexus\extensions\nexus\Item\Package $item, array $values, $memberCurrency )
public function addToCart(\IPS\nexus\Invoice\Item $item, array $values, string $memberCurrency ): array
{
$item->extra['image'] = json_encode( array( 'large' => (string) $values['advertisement_image'], 'medium' => (string) $values['ad_image_medium'], 'small' => (string) $values['ad_image_small'] ) );
$item->extra['link'] = (string) $values['advertisement_url'];
return parent::addToCart( $item, $values, $memberCurrency );
}
/* !Client Area */
@@ -298,7 +412,7 @@ class _Ad extends \IPS\nexus\Package
*
* @return bool
*/
public function showPurchaseRecord()
public function showPurchaseRecord(): bool
{
return TRUE;
}
@@ -306,23 +420,23 @@ class _Ad extends \IPS\nexus\Package
/**
* Get Client Area Page HTML
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param Purchase $purchase The purchase
* @return array( 'packageInfo' => '...', 'purchaseInfo' => '...' )
*/
public function clientAreaPage( \IPS\nexus\Purchase $purchase )
public function clientAreaPage( Purchase $purchase ) : array
{
$parent = parent::clientAreaPage( $purchase );
try
{
$advertisement = \IPS\core\Advertisement::load( $purchase->extra['ad'] );
$advertisement = Advertisement::load( $purchase->extra['ad'] );
return array(
'packageInfo' => $parent['packageInfo'],
'purchaseInfo' => $parent['purchaseInfo'] . \IPS\Theme::i()->getTemplate('purchases')->advertisement( $purchase, $advertisement ),
'purchaseInfo' => $parent['purchaseInfo'] . Theme::i()->getTemplate('purchases')->advertisement( $purchase, $advertisement ),
);
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
return $parent;
}
@@ -333,44 +447,44 @@ class _Ad extends \IPS\nexus\Package
/**
* ACP Generate Invoice Form
*
* @param \IPS\Helpers\Form $form The form
* @param string $k The key to add to the field names
* @return void
* @param Form $form The form
* @param string $k The key to add to the field names
* @return void
*/
public function generateInvoiceForm( \IPS\Helpers\Form $form, $k )
public function generateInvoiceForm(Form $form, string $k ): void
{
$form->attributes['data-bypassValidation'] = true;
$field = new \IPS\Helpers\Form\Url( 'advertisement_url' . $k, NULL, TRUE );
$field->label = \IPS\Member::loggedIn()->language()->addToStack('advertisement_url');
$field = new Form\Url( 'advertisement_url' . $k, NULL, TRUE );
$field->label = Member::loggedIn()->language()->addToStack('advertisement_url');
$form->add( $field );
$field = new \IPS\Helpers\Form\Upload( 'ad_image' . $k, NULL, TRUE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ) );
$field->label = \IPS\Member::loggedIn()->language()->addToStack('ad_image');
$field = new Upload( 'ad_image' . $k, NULL, TRUE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ) );
$field->label = Member::loggedIn()->language()->addToStack('ad_image');
$form->add( $field );
$field = new \IPS\Helpers\Form\YesNo( 'ad_image_more' . $k, FALSE, FALSE, array( 'togglesOn' => array( 'ad_image_small' . $k, 'ad_image_medium' . $k ) ) );
$field->label = \IPS\Member::loggedIn()->language()->addToStack('ad_image_more');
$field = new YesNo( 'ad_image_more' . $k, FALSE, FALSE, array( 'togglesOn' => array( 'ad_image_small' . $k, 'ad_image_medium' . $k ) ) );
$field->label = Member::loggedIn()->language()->addToStack('ad_image_more');
$form->add( $field );
$field = new \IPS\Helpers\Form\Upload( 'ad_image_small' . $k, NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_small' . $k );
$field->label = \IPS\Member::loggedIn()->language()->addToStack('ad_image_small');
$field = new Upload( 'ad_image_small' . $k, NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_small' . $k );
$field->label = Member::loggedIn()->language()->addToStack('ad_image_small');
$form->add( $field );
$field = new \IPS\Helpers\Form\Upload( 'ad_image_medium' . $k, NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_medium' . $k );
$field->label = \IPS\Member::loggedIn()->language()->addToStack('ad_image_medium');
$field = new Upload( 'ad_image_medium' . $k, NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'nexus_Ads' ), NULL, NULL, NULL, 'ad_image_medium' . $k );
$field->label = Member::loggedIn()->language()->addToStack('ad_image_medium');
$form->add( $field );
}
/**
* ACP Add to invoice
*
* @param \IPS\nexus\extensions\nexus\Item\Package $item The item
* @param \IPS\nexus\Invoice\Item $item The item
* @param array $values Values from form
* @param string $k The key to add to the field names
* @param \IPS\nexus\Invoice $invoice The invoice
* @return void
* @param string $k The key to add to the field names
* @param Invoice $invoice The invoice
* @return void
*/
public function acpAddToInvoice( \IPS\nexus\extensions\nexus\Item\Package $item, array $values, $k, \IPS\nexus\Invoice $invoice )
public function acpAddToInvoice(\IPS\nexus\Invoice\Item $item, array $values, string $k, Invoice $invoice ): void
{
$item->extra['image'] = json_encode( array( 'large' => (string) $values[ 'ad_image' . $k ], 'medium' => (string) $values[ 'ad_image_medium' . $k ], 'small' => (string) $values[ 'ad_image_small' . $k ] ) );
$item->extra['link'] = (string) $values[ 'advertisement_url' . $k ];
@@ -379,35 +493,38 @@ class _Ad extends \IPS\nexus\Package
/**
* Get ACP Page HTML
*
* @param \IPS\nexus\Purchase $purchase Purchase record
* @return string
* @param Purchase $purchase Purchase record
* @return string
*/
public function acpPage( \IPS\nexus\Purchase $purchase )
public function acpPage( Purchase $purchase ): string
{
try
{
return \IPS\Theme::i()->getTemplate( 'purchases' )->advertisement( $purchase, \IPS\core\Advertisement::load( $purchase->extra['ad'] ) );
return Theme::i()->getTemplate( 'purchases' )->advertisement( $purchase, Advertisement::load( $purchase->extra['ad'] ) );
}
catch ( OutOfRangeException )
{
return '';
}
catch ( \OutOfRangeException $e ) { }
}
/**
* Get ACP Page Buttons
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param \IPS\Http\Url $url The page URL
* @return array
* @param Purchase $purchase The purchase
* @param Url $url The page URL
* @return array
*/
public function acpButtons( \IPS\nexus\Purchase $purchase, $url )
public function acpButtons(Purchase $purchase, Url $url ): array
{
$return = parent::acpButtons( $purchase, $url );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_edit' ) and isset( $purchase->extra['ad'] ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'promotion', 'advertisements_edit' ) and isset( $purchase->extra['ad'] ) )
{
$return['edit_advertisement'] = array(
'icon' => 'list-alt',
'title' => 'edit_advertisement',
'link' => \IPS\Http\Url::internal( 'app=core&module=promotion&controller=advertisements&do=form&id=' . $purchase->extra['ad'] ),
'link' => Url::internal( 'app=core&module=promotion&controller=advertisements&do=form&id=' . $purchase->extra['ad'] ),
);
}
@@ -419,13 +536,13 @@ class _Ad extends \IPS\nexus\Package
/**
* On Purchase Generated
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param \IPS\nexus\Invoice $invoice The invoice
* @return void
* @param Purchase $purchase The purchase
* @param Invoice $invoice The invoice
* @return void
*/
public function onPurchaseGenerated( \IPS\nexus\Purchase $purchase, \IPS\nexus\Invoice $invoice )
public function onPurchaseGenerated(Purchase $purchase, Invoice $invoice ): void
{
$insertId = \IPS\Db::i()->insert( 'core_advertisements', array(
$insertId = Db::i()->insert( 'core_advertisements', array(
'ad_location' => $this->locations,
'ad_html' => NULL,
'ad_images' => $purchase->extra['image'],
@@ -439,10 +556,10 @@ class _Ad extends \IPS\nexus\Package
'ad_end' => $purchase->expire ? $purchase->expire->getTimestamp() : 0,
'ad_maximum_value' => $this->expire,
'ad_maximum_unit' => $this->expire_unit,
'ad_additional_settings'=> json_encode( array() ),
'ad_additional_settings'=> $this->settings,
'ad_html_https_set' => 0,
'ad_member' => $purchase->member->member_id,
'ad_type' => \IPS\core\Advertisement::AD_IMAGES,
'ad_type' => Advertisement::AD_IMAGES,
) );
$extra = $purchase->extra;
@@ -450,7 +567,7 @@ class _Ad extends \IPS\nexus\Package
$purchase->extra = $extra;
$purchase->save();
\IPS\core\AdminNotification::send( 'nexus', 'Advertisement', NULL, TRUE, $purchase );
AdminNotification::send( 'nexus', 'Advertisement', NULL, TRUE, $purchase );
parent::onPurchaseGenerated( $purchase, $invoice );
}
@@ -458,14 +575,14 @@ class _Ad extends \IPS\nexus\Package
/**
* On Expiration Date Change
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @return void
* @param Purchase $purchase The purchase
* @return void
*/
public function onExpirationDateChange( \IPS\nexus\Purchase $purchase )
public function onExpirationDateChange( Purchase $purchase ): void
{
try
{
$ad = \IPS\core\Advertisement::load( $purchase->extra['ad'] );
$ad = Advertisement::load( $purchase->extra['ad'] );
$ad->end = $purchase->expire ? $purchase->expire->getTimestamp() : 0;
if ( ( !$ad->end or $ad->end > time() ) )
@@ -507,7 +624,7 @@ class _Ad extends \IPS\nexus\Package
$ad->save();
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
parent::onExpirationDateChange( $purchase );
}
@@ -515,18 +632,18 @@ class _Ad extends \IPS\nexus\Package
/**
* On Purchase Expired
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @return void
* @param Purchase $purchase The purchase
* @return void
*/
public function onExpire( \IPS\nexus\Purchase $purchase )
public function onExpire( Purchase $purchase ): void
{
try
{
$ad = \IPS\core\Advertisement::load( $purchase->extra['ad'] );
$ad = Advertisement::load( $purchase->extra['ad'] );
$ad->active = 0;
$ad->save();
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
parent::onExpire( $purchase );
}
@@ -534,18 +651,18 @@ class _Ad extends \IPS\nexus\Package
/**
* On Purchase Canceled
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @return void
* @param Purchase $purchase The purchase
* @return void
*/
public function onCancel( \IPS\nexus\Purchase $purchase )
public function onCancel( Purchase $purchase ): void
{
try
{
$ad = \IPS\core\Advertisement::load( $purchase->extra['ad'] );
$ad = Advertisement::load( $purchase->extra['ad'] );
$ad->active = 0;
$ad->save();
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
parent::onCancel( $purchase );
}
@@ -553,16 +670,16 @@ class _Ad extends \IPS\nexus\Package
/**
* On Purchase Deleted
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @return void
* @param Purchase $purchase The purchase
* @return void
*/
public function onDelete( \IPS\nexus\Purchase $purchase )
public function onDelete( Purchase $purchase ): void
{
try
{
\IPS\core\Advertisement::load( $purchase->extra['ad'] )->delete();
Advertisement::load( $purchase->extra['ad'] )->delete();
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
parent::onDelete( $purchase );
}
@@ -570,10 +687,10 @@ class _Ad extends \IPS\nexus\Package
/**
* On Purchase Reactivated (renewed after being expired or reactivated after being canceled)
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @return void
* @param Purchase $purchase The purchase
* @return void
*/
public function onReactivate( \IPS\nexus\Purchase $purchase )
public function onReactivate( Purchase $purchase ): void
{
$this->onExpirationDateChange( $purchase );
@@ -583,19 +700,19 @@ class _Ad extends \IPS\nexus\Package
/**
* On Transfer (is ran before transferring)
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param \IPS\Member $newCustomer New Customer
* @return void
* @param Purchase $purchase The purchase
* @param Member $newCustomer New Customer
* @return void
*/
public function onTransfer( \IPS\nexus\Purchase $purchase, \IPS\Member $newCustomer )
public function onTransfer( Purchase $purchase, Member $newCustomer ): void
{
try
{
$ad = \IPS\core\Advertisement::load( $purchase->extra['ad'] );
$ad->member = $newCustomer->member_id;
$ad = Advertisement::load( $purchase->extra['ad'] );
$ad->member = $newCustomer->member_id;
$ad->save();
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
parent::onTransfer( $purchase, $newCustomer );
}
@@ -603,23 +720,23 @@ class _Ad extends \IPS\nexus\Package
/**
* On Upgrade/Downgrade
*
* @param \IPS\nexus\Purchase $purchase The purchase
* @param \IPS\nexus\Package $newPackage The package to upgrade to
* @param int|NULL|\IPS\nexus\Purchase\RenewalTerm $chosenRenewalOption The chosen renewal option
* @return void
* @param Purchase $purchase The purchase
* @param Package $newPackage The package to upgrade to
* @param int|RenewalTerm|NULL $chosenRenewalOption The chosen renewal option
* @return void
*/
public function onChange( \IPS\nexus\Purchase $purchase, \IPS\nexus\Package $newPackage, $chosenRenewalOption = NULL )
public function onChange(Purchase $purchase, Package $newPackage, RenewalTerm|int|null $chosenRenewalOption = NULL ): void
{
try
{
$ad = \IPS\core\Advertisement::load( $purchase->extra['ad'] );
$ad = Advertisement::load( $purchase->extra['ad'] );
$ad->location = $newPackage->locations;
$ad->exempt = $newPackage->exempt === '*' ? '*' : json_encode( explode( ',', $newPackage->exempt ) );
$ad->maximum_value = $newPackage->expire;
$ad->maximum_unit = $newPackage->expire_unit;
$ad->save();
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException ) { }
parent::onChange( $purchase, $newPackage );
}