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

@@ -12,48 +12,54 @@
namespace IPS\nexus\extensions\core\EditorLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\Content;
use IPS\Db;
use IPS\Extensions\EditorLocationsAbstract;
use IPS\Helpers\Form\Editor;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Customer;
use IPS\nexus\extensions\nexus\Item\Package;
use IPS\nexus\Package\Item;
use IPS\nexus\Purchase;
use IPS\Node\Model;
use IPS\Request;
use IPS\Settings;
use IPS\Text\Parser;
use LogicException;
use OutOfRangeException;
use function count;
use function defined;
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;
}
/**
* Editor Extension: Admin
*/
class _Admin
class Admin extends EditorLocationsAbstract
{
/**
* Can we use HTML in this editor?
*
* @param \IPS\Member $member The member
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canUseHtml( $member )
{
return NULL;
}
/**
* Can we use attachments in this editor?
*
* @param \IPS\Member $member The member
* @param \IPS\Helpers\Form\Editor $field The editor field
* @param Member $member The member
* @param Editor $field The editor field
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canAttach( $member, $field )
public function canAttach( Member $member, Editor $field ): ?bool
{
if ( mb_substr( $field->options['autoSaveKey'], -6 ) == '-email' )
{
return FALSE;
}
return NULL;
}
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
@@ -61,7 +67,7 @@ class _Admin
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
public function attachmentPermissionCheck( Member $member, ?int $id1, ?int $id2, ?string $id3, array $attachment, bool $viewOnly=FALSE ): bool
{
try
{
@@ -70,28 +76,39 @@ class _Admin
case 'pkg':
case 'pkg-assoc':
case 'pkg-email':
return \IPS\nexus\Package\Item::load( $id1 )->canView( $member );
return Item::load( $id1 )->canView( $member );
case 'custom-pg':
try
{
$package = \IPS\nexus\Package::load( $id1 );
return $package->custom == $member->member_id;
}
catch( OutOfRangeException )
{
throw new LogicException;
}
case 'pkg-pg':
$customer = \IPS\nexus\Customer::load( $member->member_id );
if ( \count( \IPS\nexus\extensions\nexus\Item\Package::getPurchases( $customer, $id1, FALSE ) ) )
$customer = Customer::load( $member->member_id );
if ( count( Package::getPurchases( $customer, $id1, FALSE ) ) )
{
$options = array( 'type' => 'attach', 'id' => $attachment['attach_id'], 'name' => $attachment['attach_file'] );
if ( \IPS\Request::i()->referrer() )
if ( Request::i()->referrer() )
{
try
{
$purchase = \IPS\nexus\Purchase::loadFromUrl( \IPS\Request::i()->referrer() );
$purchase = Purchase::loadFromUrl( Request::i()->referrer() );
if( !$purchase->can( 'view', $member ) )
{
throw new \LogicException;
throw new LogicException;
}
$options['ps_id'] = $purchase->id;
$options['ps_name'] = $purchase->name;
}
catch ( \LogicException $e ) { }
catch ( LogicException ) { }
}
$customer->log( 'download', $options );
@@ -108,10 +125,10 @@ class _Admin
return TRUE;
case 'network_status_text':
return (bool) \IPS\Settings::i()->network_status;
};
return (bool) Settings::i()->network_status;
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
return FALSE;
}
@@ -125,10 +142,10 @@ class _Admin
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @return \IPS\Http\Url|\IPS\Content|\IPS\Node\Model
* @throws \LogicException
* @return Url|Content|Model|Member|null
* @throws LogicException
*/
public function attachmentLookup( $id1, $id2, $id3 )
public function attachmentLookup( int $id1=NULL, int $id2=NULL, string $id3=NULL ): Model|Content|Url|Member|null
{
switch ( $id3 )
{
@@ -136,35 +153,19 @@ class _Admin
case 'pkg-assoc':
case 'pkg-pg':
case 'pkg-email':
return \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&subnode=1&do=form&id={$id1}", 'admin' );
return Url::internal( "app=nexus&module=store&controller=packages&subnode=1&do=form&id={$id1}", 'admin' );
case 'pgroup':
return \IPS\Http\Url::internal( "app=nexus&module=store&controller=packages&do=form&id={$id1}", 'admin' );
return Url::internal( "app=nexus&module=store&controller=packages&do=form&id={$id1}", 'admin' );
case 'invoice-header';
case 'invoice-footer':
return \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=invoices&do=settings', 'admin' );
};
}
return Url::internal( 'app=nexus&module=payments&controller=invoices&do=settings', 'admin' );
}
/**
* Rebuild attachment images in non-content item areas
*
* @param int|null $offset Offset to start from
* @param int|null $max Maximum to parse
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildAttachmentImages( $offset, $max )
{
return $this->performRebuild( $offset, $max, array( 'IPS\Text\Parser', 'rebuildAttachmentUrls' ) );
throw new LogicException;
}
/**
* @brief Use the cached image URL instead of the original URL
*/
protected $proxyUrl = FALSE;
/**
* Rebuild content to add or remove image proxy
*
@@ -174,44 +175,25 @@ class _Admin
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildImageProxy( $offset, $max, $proxyUrl = FALSE )
public function rebuildImageProxy( ?int $offset, ?int $max, bool $proxyUrl = FALSE ): int
{
$this->proxyUrl = $proxyUrl;
return $this->performRebuild( $offset, $max, 'parseImageProxy' );
$callback = function( $value ) use ( $proxyUrl ) {
return Parser::removeImageProxy( $value, $proxyUrl );
};
return $this->performRebuild( $offset, $max, $callback );
}
/**
* Rebuild content post-upgrade
*
* @param int|null $offset Offset to start from
* @param int|null $max Maximum to parse
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildContent( $offset, $max )
{
return $this->performRebuild( $offset, $max, array( 'IPS\Text\LegacyParser', 'parseStatic' ) );
}
/**
* @brief Store lazy loading status ( true = enabled )
*/
protected $_lazyLoadStatus = null;
/**
* Rebuild content to add or remove lazy loading
*
* @param int|null $offset Offset to start from
* @param int|null $max Maximum to parse
* @param bool $status Enable/Disable lazy loading
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildLazyLoad( $offset, $max, $status=TRUE )
public function rebuildLazyLoad( ?int $offset, ?int $max ): int
{
$this->_lazyLoadStatus = $status;
return $this->performRebuild( $offset, $max, 'parseLazyLoad' );
return $this->performRebuild( $offset, $max, [ 'IPS\Text\Parser', 'parseLazyLoad' ] );
}
/**
@@ -222,30 +204,23 @@ class _Admin
* @param callable $callback Method to call to rebuild content
* @return int Number completed
*/
protected function performRebuild( $offset, $max, $callback )
protected function performRebuild( ?int $offset, ?int $max, callable $callback ): int
{
/* We will do everything except pages first */
if( !$offset )
{
/* Language bits */
foreach( \IPS\Db::i()->select( '*', 'core_sys_lang_words', \IPS\Db::i()->in( 'word_key', array( 'nexus_com_rules_val', 'network_status_text_val' ) ) . " OR word_key LIKE 'nexus_donategoal_%_desc' OR word_key LIKE 'nexus_gateway_%_ins' OR word_key LIKE 'nexus_pgroup_%_desc' OR word_key LIKE 'nexus_package_%_desc' OR word_key LIKE 'nexus_package_%_page' OR word_key LIKE 'nexus_department_%_desc'", 'word_id ASC', array( $offset, $max ) ) as $word )
foreach( Db::i()->select( '*', 'core_sys_lang_words', Db::i()->in( 'word_key', array( 'nexus_com_rules_val', 'network_status_text_val' ) ) . " OR word_key LIKE 'nexus_donategoal_%_desc' OR word_key LIKE 'nexus_gateway_%_ins' OR word_key LIKE 'nexus_pgroup_%_desc' OR word_key LIKE 'nexus_package_%_desc' OR word_key LIKE 'nexus_package_%_page' OR word_key LIKE 'nexus_department_%_desc'", 'word_id ASC', array( $offset, $max ) ) as $word )
{
$rebuilt = FALSE;
try
{
if( $callback == 'parseImageProxy' )
{
$rebuilt = \IPS\Text\Parser::removeImageProxy( $word['word_custom'], $this->proxyUrl );
}
elseif( $callback == 'parseLazyLoad' )
{
$rebuilt = \IPS\Text\Parser::parseLazyLoad( $word['word_custom'], $this->_lazyLoadStatus );
}
else
if( !empty( $word['word_custom'] ) )
{
$rebuilt = $callback( $word['word_custom'] );
}
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
if( $callback[1] == 'parseStatic' AND $e->getcode() == 103014 )
{
@@ -259,33 +234,26 @@ class _Admin
if( $rebuilt !== FALSE )
{
\IPS\Db::i()->update( 'core_sys_lang_words', array( 'word_custom' => $rebuilt ), 'word_id=' . $word['word_id'] );
Db::i()->update( 'core_sys_lang_words', array( 'word_custom' => $rebuilt ), 'word_id=' . $word['word_id'] );
}
}
/* Settings */
foreach ( array( 'nexus_invoice_header', 'nexus_invoice_footer' ) as $k )
{
$newMessage = FALSE;
try
{
if( $callback == 'parseImageProxy' )
if( !empty( Settings::i()->$k ) )
{
$newMessage = \IPS\Text\Parser::removeImageProxy( \IPS\Settings::i()->$k );
}
elseif( $callback == 'parseLazyLoad' )
{
$newMessage = \IPS\Text\Parser::parseLazyLoad( \IPS\Settings::i()->$k, $this->_lazyLoadStatus );
}
else
{
$newMessage = $callback( \IPS\Settings::i()->$k );
$newMessage = $callback( Settings::i()->$k );
}
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
if( $callback[1] == 'parseStatic' AND $e->getcode() == 103014 )
{
$newMessage = preg_replace( "#\[/?([^\]]+?)\]#", '', \IPS\Settings::i()->$k );
$newMessage = preg_replace( "#\[/?([^\]]+?)\]#", '', Settings::i()->$k );
}
else
{
@@ -295,7 +263,7 @@ class _Admin
if( $newMessage !== FALSE )
{
\IPS\Settings::i()->changeValues( array( $k => $newMessage ) );
Settings::i()->changeValues( array( $k => $newMessage ) );
}
}
}
@@ -303,27 +271,24 @@ class _Admin
/* Now do packages */
$did = 0;
foreach( \IPS\Db::i()->select( '*', 'nexus_packages', null, 'p_id ASC', array( $offset, $max ) ) as $package )
foreach( Db::i()->select( '*', 'nexus_packages', null, 'p_id ASC', array( $offset, $max ) ) as $package )
{
$did++;
$rebuilt = FALSE;
/* Update */
try
{
if( $callback == 'parseImageProxy' )
{
$rebuilt = \IPS\Text\Parser::removeImageProxy( $package['p_page'] );
}
elseif( $callback == 'parseLazyLoad' )
{
$rebuilt = \IPS\Text\Parser::parseLazyLoad( $package['p_page'], $this->_lazyLoadStatus );
}
else
if( is_string( $package['p_page'] ) AND $callback[1] == 'parseStatic' )
{
$rebuilt = $callback( $package['p_page'], NULL, FALSE, 'nexus_Admin', $package['p_id'], NULL, 'pkg-pg' );
}
elseif( is_string( $package['p_page'] ) )
{
$rebuilt = $callback( $package['p_page'] );
}
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
if( $callback[1] == 'parseStatic' AND $e->getcode() == 103014 )
{
@@ -337,7 +302,7 @@ class _Admin
if( $rebuilt !== FALSE )
{
\IPS\Db::i()->update( 'nexus_packages', array( 'p_page' => $rebuilt ), array( 'p_id=?', $package['p_id'] ) );
Db::i()->update( 'nexus_packages', array( 'p_page' => $rebuilt ), array( 'p_id=?', $package['p_id'] ) );
}
}
@@ -349,13 +314,13 @@ class _Admin
*
* @return int Total Count
*/
public function contentCount()
public function contentCount(): int
{
$count = 2;
$count += \IPS\Db::i()->select( 'COUNT(*) as count', 'core_sys_lang_words', \IPS\Db::i()->in( 'word_key', array( 'nexus_com_rules_val', 'network_status_text_val' ) ) . " OR word_key LIKE 'nexus_donategoal_%_desc' OR word_key LIKE 'nexus_gateway_%_ins' OR word_key LIKE 'nexus_pgroup_%_desc' OR word_key LIKE 'nexus_package_%_desc' OR word_key LIKE 'nexus_package_%_page' OR word_key LIKE 'nexus_department_%_desc'" )->first();
$count += Db::i()->select( 'COUNT(*) as count', 'core_sys_lang_words', Db::i()->in( 'word_key', array( 'nexus_com_rules_val', 'network_status_text_val' ) ) . " OR word_key LIKE 'nexus_donategoal_%_desc' OR word_key LIKE 'nexus_gateway_%_ins' OR word_key LIKE 'nexus_pgroup_%_desc' OR word_key LIKE 'nexus_package_%_desc' OR word_key LIKE 'nexus_package_%_page' OR word_key LIKE 'nexus_department_%_desc'" )->first();
$count += \IPS\Db::i()->select( 'COUNT(*) as count', 'nexus_packages' )->first();
$count += Db::i()->select( 'COUNT(*) as count', 'nexus_packages' )->first();
return $count;
}
@@ -12,38 +12,43 @@
namespace IPS\nexus\extensions\core\EditorLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\Content;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Extensions\EditorLocationsAbstract;
use IPS\Helpers\Form\Editor;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Customer as NexusCustomer;
use IPS\Node\Model;
use IPS\Text\Parser;
use LogicException;
use function count;
use function defined;
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;
}
/**
* Editor Extension: Customer Fields
*/
class _Customer
class Customer extends EditorLocationsAbstract
{
/**
* Can we use HTML in this editor?
*
* @param \IPS\Member $member The member
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canUseHtml( $member )
{
return NULL;
}
/**
* Can we use attachments in this editor?
*
* @param \IPS\Member $member The member
* @param \IPS\Helpers\Form\Editor $editor The editor instance
* @param Member $member The member
* @param Editor $field The editor instance
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canAttach( $member, $editor )
public function canAttach( Member $member, Editor $field ): ?bool
{
if( !$editor->options['allowAttachments'] )
if( !$field->options['allowAttachments'] )
{
return FALSE;
}
@@ -54,7 +59,7 @@ class _Customer
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
@@ -62,7 +67,7 @@ class _Customer
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
public function attachmentPermissionCheck( Member $member, ?int $id1, ?int $id2, ?string $id3, array $attachment, bool $viewOnly=FALSE ): bool
{
if ( ( $id3 !== 'note' and $member->member_id == $id1 ) or $member->hasAcpRestriction( 'nexus', 'customers', 'customers_view' ) )
{
@@ -77,33 +82,21 @@ class _Customer
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @return \IPS\Http\Url|\IPS\Content|\IPS\Node\Model
* @throws \LogicException
* @return Url|Content|Model|Member|null
* @throws LogicException
*/
public function attachmentLookup( $id1, $id2, $id3 )
public function attachmentLookup( int $id1=NULL, int $id2=NULL, string $id3=NULL ): Model|Content|Url|Member|null
{
if ( \IPS\Dispatcher::i()->controllerLocation === 'admin' )
if ( Dispatcher::i()->controllerLocation === 'admin' )
{
return \IPS\nexus\Customer::load( $id1 )->acpUrl();
return NexusCustomer::load( $id1 )->acpUrl();
}
else
{
return \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=info', 'front', 'clientsinfo' );
return Url::internal( 'app=nexus&module=clients&controller=info', 'front', 'clientsinfo' );
}
}
/**
* Rebuild attachment images in non-content item areas
*
* @param int|null $offset Offset to start from
* @param int|null $max Maximum to parse
* @return int Number completed
*/
public function rebuildAttachmentImages( $offset, $max )
{
return $this->performRebuild( $offset, $max, array( 'IPS\Text\Parser', 'rebuildAttachmentUrls' ) );
}
/**
* Rebuild content post-upgrade
*
@@ -112,16 +105,11 @@ class _Customer
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildContent( $offset, $max )
public function rebuildContent( ?int $offset, ?int $max ): int
{
return $this->performRebuild( $offset, $max, array( 'IPS\Text\LegacyParser', 'parseStatic' ) );
}
/**
* @brief Use the cached image URL instead of the original URL
*/
protected $proxyUrl = FALSE;
/**
* Rebuild content to add or remove image proxy
*
@@ -131,31 +119,25 @@ class _Customer
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildImageProxy( $offset, $max, $proxyUrl = FALSE )
public function rebuildImageProxy( ?int $offset, ?int $max, bool $proxyUrl = FALSE ): int
{
$this->proxyUrl = $proxyUrl;
return $this->performRebuild( $offset, $max, 'parseImageProxy' );
$callback = function( $value ) use ( $proxyUrl ) {
return Parser::removeImageProxy( $value, $proxyUrl );
};
return $this->performRebuild( $offset, $max, $callback );
}
/**
* @brief Store lazy loading status ( true = enabled )
*/
protected $_lazyLoadStatus = null;
/**
* Rebuild content to add or remove lazy loading
*
* @param int|null $offset Offset to start from
* @param int|null $max Maximum to parse
* @param bool $status Enable/Disable lazy loading
* @return int Number completed
* @note This method is optional and will only be called if it exists
*/
public function rebuildLazyLoad( $offset, $max, $status=TRUE )
public function rebuildLazyLoad( ?int $offset, ?int $max ): int
{
$this->_lazyLoadStatus = $status;
return $this->performRebuild( $offset, $max, 'parseLazyLoad' );
return $this->performRebuild( $offset, $max, [ 'IPS\Text\Parser', 'parseLazyLoad' ] );
}
/**
@@ -166,25 +148,25 @@ class _Customer
* @param callable $callback Method to call to rebuild content
* @return int Number completed
*/
protected function performRebuild( $offset, $max, $callback )
protected function performRebuild( ?int $offset, ?int $max, callable $callback ): int
{
$did = 0;
/* Get editor fields */
$editorFields = array();
foreach( \IPS\Db::i()->select( '*', 'nexus_customer_fields', "f_type='Editor'" ) as $field )
foreach( Db::i()->select( '*', 'nexus_customer_fields', "f_type='Editor'" ) as $field )
{
$editorFields[] = 'field_' . $field['f_id'];
}
if( !\count( $editorFields ) )
if( !count( $editorFields ) )
{
return $did;
}
/* Now update the content */
foreach( \IPS\Db::i()->select( '*', 'nexus_customers', implode( " IS NOT NULL OR ", $editorFields ) . " IS NOT NULL", 'member_id ASC', array( $offset, $max ) ) as $member )
foreach( Db::i()->select( '*', 'nexus_customers', implode( " IS NOT NULL OR ", $editorFields ) . " IS NOT NULL", 'member_id ASC', array( $offset, $max ) ) as $member )
{
$did++;
@@ -193,22 +175,19 @@ class _Customer
foreach( $editorFields as $fieldId )
{
$rebuilt = FALSE;
try
{
if( $callback == 'parseImageProxy' )
if( $callback[1] == 'parseStatic' )
{
$rebuilt = \IPS\Text\Parser::removeImageProxy( $member[ $fieldId ], $this->proxyUrl );
}
elseif( $callback == 'parseLazyLoad' )
{
$rebuilt = \IPS\Text\Parser::parseLazyLoad( $member[ $fieldId ], $this->_lazyLoadStatus );
$rebuilt = $callback( $member[ $fieldId ], Member::load( $member['member_id'] ) );
}
else
{
$rebuilt = $callback( $member[ $fieldId ], \IPS\Member::load( $member['member_id'] ) );
$rebuilt = $callback( $member[ $fieldId ] );
}
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
if( $callback[1] == 'parseStatic' AND $e->getcode() == 103014 )
{
@@ -226,9 +205,9 @@ class _Customer
}
}
if( \count( $toUpdate ) )
if( count( $toUpdate ) )
{
\IPS\Db::i()->update( 'nexus_customers', $toUpdate, array( 'member_id=?', $member['member_id'] ) );
Db::i()->update( 'nexus_customers', $toUpdate, array( 'member_id=?', $member['member_id'] ) );
}
}
@@ -240,21 +219,21 @@ class _Customer
*
* @return int Total Count
*/
public function contentCount()
public function contentCount(): int
{
/* Get editor fields */
$editorFields = array();
foreach( \IPS\Db::i()->select( '*', 'nexus_customer_fields', "f_type='Editor'" ) as $field )
foreach( Db::i()->select( '*', 'nexus_customer_fields', "f_type='Editor'" ) as $field )
{
$editorFields[] = 'field_' . $field['f_id'];
}
if( !\count( $editorFields ) )
if( !count( $editorFields ) )
{
return 0;
}
return \IPS\Db::i()->select( 'COUNT(*) as count', 'nexus_customers', implode( " IS NOT NULL OR ", $editorFields ) . " IS NOT NULL" )->first();
return Db::i()->select( 'COUNT(*) as count', 'nexus_customers', implode( " IS NOT NULL OR ", $editorFields ) . " IS NOT NULL" )->first();
}
}
@@ -12,36 +12,40 @@
namespace IPS\nexus\extensions\core\EditorLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content;
use IPS\Dispatcher;
use IPS\Extensions\EditorLocationsAbstract;
use IPS\Helpers\Form\Editor;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Invoice;
use IPS\nexus\Purchase;
use IPS\Node\Model;
use LogicException;
use OutOfRangeException;
use function defined;
use function intval;
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;
}
/**
* Editor Extension: Support
* Editor Extension: Purchases
*/
class _Purchases
class Purchases extends EditorLocationsAbstract
{
/**
* Can we use HTML in this editor?
*
* @param \IPS\Member $member The member
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canUseHtml( $member )
{
return NULL;
}
/**
* Can we use attachments in this editor?
*
* @param \IPS\Member $member The member
* @param \IPS\Helpers\Form\Editor $field The editor field
* @param Member $member The member
* @param Editor $field The editor field
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canAttach( $member, $field )
public function canAttach( Member $member, Editor $field ): ?bool
{
return NULL;
}
@@ -49,7 +53,7 @@ class _Purchases
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
@@ -57,7 +61,7 @@ class _Purchases
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
public function attachmentPermissionCheck( Member $member, ?int $id1, ?int $id2, ?string $id3, array $attachment, bool $viewOnly=FALSE ): bool
{
try
{
@@ -72,19 +76,19 @@ class _Purchases
/* If it's in an invoice, we can check that */
if ( mb_substr( $id3, 0, 7 ) == 'invoice' )
{
return \IPS\nexus\Invoice::load( \intval( mb_substr( $id3, 7 ) ) )->canView( $member );
return Invoice::load( intval( mb_substr( $id3, 7 ) ) )->canView( $member );
}
/* If it's in an purchase, we can link to that */
if ( $id3 == 'purchase' )
{
return \IPS\nexus\Purchase::load( $id1 )->canView( $member );
return Purchase::load( $id1 )->canView( $member );
}
/* Still here? Return false */
return FALSE;
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
return FALSE;
}
@@ -96,31 +100,31 @@ class _Purchases
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @return \IPS\Http\Url|\IPS\Content|\IPS\Node\Model
* @throws \LogicException
* @return Url|Content|Model|Member|null
* @throws LogicException
*/
public function attachmentLookup( $id1, $id2, $id3 )
public function attachmentLookup( int $id1=NULL, int $id2=NULL, string $id3=NULL ): Model|Content|Url|Member|null
{
/* If it's in the cart, wer obviously can't link to that */
if ( $id3 == 'cart' )
{
throw new \LogicException;
throw new LogicException;
}
/* If it's in an invoice, we can link to that */
if ( mb_substr( $id3, 0, 8 ) == 'invoice-' )
{
$invoice = \IPS\nexus\Invoice::load( \intval( mb_substr( $id3, 8 ) ) );
return \IPS\Dispatcher::i()->controllerLocation == 'admin' ? $invoice->acpUrl() : $invoice->url();
$invoice = Invoice::load( intval( mb_substr( $id3, 8 ) ) );
return Dispatcher::i()->controllerLocation == 'admin' ? $invoice->acpUrl() : $invoice->url();
}
/* If it's in an purchase, we can link to that */
if ( $id3 == 'purchase' )
{
return \IPS\nexus\Purchase::load( $id1 );
return Purchase::load( $id1 );
}
/* Still here? No idea */
throw new \LogicException;
throw new LogicException;
}
}
@@ -12,36 +12,39 @@
namespace IPS\nexus\extensions\core\EditorLocations;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content;
use IPS\Extensions\EditorLocationsAbstract;
use IPS\Helpers\Form\Editor;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Package\Item;
use IPS\nexus\Package\Review;
use IPS\Node\Model;
use LogicException;
use OutOfRangeException;
use RuntimeException;
use function defined;
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;
}
/**
* Editor Extension: Product Reviews
*/
class _Store
class Store extends EditorLocationsAbstract
{
/**
* Can we use HTML in this editor?
*
* @param \IPS\Member $member The member
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canUseHtml( $member )
{
return NULL;
}
/**
* Can we use attachments in this editor?
*
* @param \IPS\Member $member The member
* @param \IPS\Helpers\Form\Editor $field The editor field
* @param Member $member The member
* @param Editor $field The editor field
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canAttach( $member, $field )
public function canAttach( Member $member, Editor $field ): ?bool
{
return NULL;
}
@@ -50,11 +53,11 @@ class _Store
* Can whatever is posted in this editor be moderated?
* If this returns TRUE, we must ensure the content is ran through word, link and image filters
*
* @param \IPS\Member $member The member
* @param \IPS\Helpers\Form\Editor $field The editor field
* @param Member $member The member
* @param Editor $field The editor field
* @return bool
*/
public function canBeModerated( $member, $field )
public function canBeModerated( Member $member, Editor $field ): bool
{
/* Creating/editing a review */
if ( preg_match( '/^(?:editComment|review)\-nexus\/store\-\d+/', $field->options['autoSaveKey'] ) )
@@ -66,16 +69,17 @@ class _Store
{
if ( \IPS\IN_DEV )
{
throw new \RuntimeException( 'Unknown canBeModerated: ' . $field->options['autoSaveKey'] );
throw new RuntimeException( 'Unknown canBeModerated: ' . $field->options['autoSaveKey'] );
}
return FALSE;
return parent::canBeModerated( $member, $field );
}
}
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
@@ -83,13 +87,13 @@ class _Store
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
public function attachmentPermissionCheck( Member $member, ?int $id1, ?int $id2, ?string $id3, array $attachment, bool $viewOnly=FALSE ): bool
{
try
{
return \IPS\nexus\Package\Item::load( $id1 )->canView( $member );
return Item::load( $id1 )->canView( $member );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
return FALSE;
}
@@ -101,12 +105,12 @@ class _Store
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @return \IPS\Http\Url|\IPS\Content|\IPS\Node\Model
* @throws \LogicException
* @return Url|Content|Model|Member|null
* @throws LogicException
*/
public function attachmentLookup( $id1, $id2, $id3 )
public function attachmentLookup( int $id1=NULL, int $id2=NULL, string $id3=NULL ): Model|Content|Url|Member|null
{
return \IPS\nexus\Package\Review::load( $id2 );
return Review::load( $id2 );
}
}
@@ -1,95 +0,0 @@
<?php
/**
* @brief Editor Extension: Support
* @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 09 Apr 2014
*/
namespace IPS\nexus\extensions\core\EditorLocations;
/* 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;
}
/**
* Editor Extension: Support
*/
class _Support
{
/**
* Can we use HTML in this editor?
*
* @param \IPS\Member $member The member
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canUseHtml( $member )
{
return NULL;
}
/**
* Can we use attachments in this editor?
*
* @param \IPS\Member $member The member
* @param \IPS\Helpers\Form\Editor $field The editor field
* @return bool|null NULL will cause the default value (based on the member's permissions) to be used, and is recommended in most cases. A boolean value will override that.
*/
public function canAttach( $member, $field )
{
if ( $field->options['autoSaveKey'] == 'default_content' )
{
return FALSE;
}
if( !$field->options['allowAttachments'] )
{
return FALSE;
}
return NULL;
}
/**
* Permission check for attachments
*
* @param \IPS\Member $member The member
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @param array $attachment The attachment data
* @param bool $viewOnly If true, just check if the user can see the attachment rather than download it
* @return bool
*/
public function attachmentPermissionCheck( $member, $id1, $id2, $id3, $attachment, $viewOnly=FALSE )
{
try
{
return \IPS\nexus\Support\Request::load( $id1 )->canView( $member );
}
catch ( \OutOfRangeException $e )
{
return FALSE;
}
}
/**
* Attachment lookup
*
* @param int|null $id1 Primary ID
* @param int|null $id2 Secondary ID
* @param string|null $id3 Arbitrary data
* @return \IPS\Http\Url|\IPS\Content|\IPS\Node\Model
* @throws \LogicException
*/
public function attachmentLookup( $id1, $id2, $id3 )
{
return \IPS\nexus\Support\Reply::load( $id2 );
}
}