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

@@ -11,66 +11,88 @@
namespace IPS\core\ShareLinks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\Content;
use IPS\Content\ShareServices;
use IPS\Data\Store;
use IPS\Db;
use IPS\GeoLocation;
use IPS\Helpers\Form;
use IPS\Helpers\Form\CheckboxSet;
use IPS\Helpers\Form\Text;
use IPS\Http\Url;
use IPS\Login;
use IPS\Member;
use IPS\Member\Group;
use IPS\Node\Model;
use IPS\Settings;
use LogicException;
use function count;
use function defined;
use function in_array;
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;
}
/**
* Share Link Node
*/
class _Service extends \IPS\Node\Model
class Service extends Model
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'core_share_links';
public static ?string $databaseTable = 'core_share_links';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'share_';
public static string $databasePrefix = 'share_';
/**
* @brief [ActiveRecord] ID Database Column
*/
public static $databaseColumnId = 'id';
public static string $databaseColumnId = 'id';
/**
* @brief [ActiveRecord] Database ID Fields
*/
protected static $databaseIdFields = array( 'share_key' );
protected static array $databaseIdFields = array( 'share_key' );
/**
* @brief [ActiveRecord] Multiton Map
*/
protected static $multitonMap = array();
protected static array $multitonMap = array();
/**
* @brief [Node] Order Database Column
*/
public static $databaseColumnOrder = 'position';
public static ?string $databaseColumnOrder = 'position';
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'sharelinks';
public static string $nodeTitle = 'sharelinks';
/**
* @brief [Node] Show forms modally?
*/
public static $modalForms = TRUE;
public static bool $modalForms = TRUE;
/**
* @brief [Node] ACP Restrictions
*/
protected static $restrictions = array(
protected static ?array $restrictions = array(
'app' => 'core',
'module' => 'settings',
'prefix' => 'sharelinks_',
@@ -81,7 +103,7 @@ class _Service extends \IPS\Node\Model
*
* @return void
*/
public static function resetRootResult()
public static function resetRootResult() : void
{
static::$rootsResult = NULL;
}
@@ -89,14 +111,14 @@ class _Service extends \IPS\Node\Model
/**
* @brief Cached sharelinks
*/
protected static $cachedShareLinks = NULL;
protected static ?array $cachedShareLinks = NULL;
/**
* Fetch All Nodes
*
* @return array
*/
public static function shareLinks()
public static function shareLinks() : array
{
if( static::$cachedShareLinks === NULL )
{
@@ -115,30 +137,30 @@ class _Service extends \IPS\Node\Model
*
* @return array
*/
public static function getStore()
public static function getStore(): array
{
if ( !isset( \IPS\Data\Store::i()->shareLinks ) )
if ( !isset( Store::i()->shareLinks ) )
{
\IPS\Data\Store::i()->shareLinks = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, static::$databasePrefix . static::$databaseColumnOrder ) );
Store::i()->shareLinks = iterator_to_array( Db::i()->select( '*', static::$databaseTable, NULL, static::$databasePrefix . static::$databaseColumnOrder ) );
}
return \IPS\Data\Store::i()->shareLinks;
return Store::i()->shareLinks;
}
/**
* Fetch All Share Services
*
* @param \IPS\Http\Url $url URL to the content [optional - if omitted, some services will figure out on their own]
* @param Url $url URL to the content [optional - if omitted, some services will figure out on their own]
* @param string $title Default text for the content, usually the title [optional - if omitted, some services will figure out on their own]
* @param \IPS\Member|NULL $member Member the links will display to or NULL for currently logged in member
* @param \IPS\Content|NULL $item Content item (or comment) to share
* @param Member|NULL $member Member the links will display to or NULL for currently logged in member
* @param Content|NULL $item Content item (or comment) to share
* @return array
*/
public static function getAllServices( \IPS\Http\Url $url, $title, \IPS\Member $member = NULL, \IPS\Content $item = NULL )
public static function getAllServices(Url $url, string $title, ?Member $member = NULL, ?Content $item = NULL ) : array
{
$member = $member ?: \IPS\Member::loggedIn();
$member = $member ?: Member::loggedIn();
if( \IPS\Settings::i()->ref_on )
if( Settings::i()->ref_on )
{
$url = $url->setQueryString( array( '_rid' => $member->member_id ) );
}
@@ -152,30 +174,31 @@ class _Service extends \IPS\Node\Model
{
$services[ $node->key ] = $node->getService( $url, $title, $item );
}
catch ( \LogicException $e ) { }
catch ( LogicException $e ) { }
}
}
return $services;
}
/**
* Get \IPS\Content\ShareServices class
*
* @param \IPS\Http\Url $url URL to the content [optional - if omitted, some services will figure out on their own]
* @param string $title Default text for the content, usually the title [optional - if omitted, some services will figure out on their own]
* @return array
* @param Url $url URL to the content [optional - if omitted, some services will figure out on their own]
* @param string $title Default text for the content, usually the title [optional - if omitted, some services will figure out on their own]
* @param Content|null $item
* @return ShareServices
*/
public function getService( \IPS\Http\Url $url, $title, $item )
public function getService( Url $url, string $title, ?Content $item ) : ShareServices
{
try
{
$className = \IPS\Content\ShareServices::getClassByKey( $this->key );
$className = ShareServices::getClassByKey( $this->key );
return new $className( $url, $title, $item );
}
catch ( \InvalidArgumentException $e )
catch ( InvalidArgumentException $e )
{
throw new \LogicException;
throw new LogicException;
}
}
@@ -184,21 +207,21 @@ class _Service extends \IPS\Node\Model
* 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
);
* 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 Url $url Base URL
* @param bool $subnode Is this a subnode?
* @return array
*/
public function getButtons( $url, $subnode=FALSE )
public function getButtons( Url $url, bool $subnode=FALSE ):array
{
$buttons = array();
@@ -213,7 +236,7 @@ class _Service extends \IPS\Node\Model
'icon' => 'pencil',
'title' => 'edit',
'link' => $url->setQueryString( array( 'do' => 'form', 'id' => $this->_id ) ),
'data' => ( static::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit') ) : array() ),
'data' => ( static::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('edit') ) : array() ),
'hotkey'=> 'e return'
);
}
@@ -224,18 +247,19 @@ class _Service extends \IPS\Node\Model
/**
* [Node] Add/Edit Form
*
* @param \IPS\Helpers\Form $form The form
* @param Form $form The form
* @return void
*/
public function form( &$form )
public function form( Form &$form ) : void
{
$form->add( new \IPS\Helpers\Form\Text( 'share_title', $this->title, TRUE ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'share_groups', ( $this->groups != '*' ) ? explode( ",", $this->groups ) : $this->groups, FALSE, array( 'options' => \IPS\Member\Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ) ) );
$form->add( new Text( 'share_title', $this->title, TRUE ) );
$form->add( new CheckboxSet( 'share_groups', ( $this->groups != '*' ) ? explode( ",", $this->groups ) : $this->groups, FALSE, array( 'options' => Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone', 'impliedUnlimited' => TRUE ) ) );
/* Find the service and see if it has any additional settings... */
$services = \IPS\Content\ShareServices::services();
$services = ShareServices::services();
$className = $services[ ucwords( $this->key ) ];
/* @var ShareServices $className */
$className::modifyForm( $form, $this );
}
@@ -245,16 +269,16 @@ class _Service extends \IPS\Node\Model
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
if( \count( $values ) )
if( count( $values ) )
{
if ( isset( $values[ 'share_autoshare_' . ucwords( $this->key ) ] ) )
{
$values['share_autoshare'] = $values[ 'share_autoshare_' . ucwords( $this->key ) ];
unset( $values[ 'share_autoshare_' . ucwords( $this->key ) ] );
$loginHandlers = \IPS\Login::getStore();
$loginHandlers = Login::getStore();
foreach( $loginHandlers as $handler )
{
@@ -273,13 +297,13 @@ class _Service extends \IPS\Node\Model
$settingsToUpdate = array();
foreach ( $values as $k => $v )
{
if( !\in_array( $k, array( 'share_title', 'share_groups', 'share_autoshare' ) ) )
if( !in_array( $k, array( 'share_title', 'share_groups', 'share_autoshare' ) ) )
{
if ( $v instanceof \IPS\GeoLocation )
if ( $v instanceof GeoLocation )
{
$v = json_encode( $v );
}
if ( \is_array( $v ) )
if ( is_array( $v ) )
{
$v = implode( ',', $v );
}
@@ -289,7 +313,7 @@ class _Service extends \IPS\Node\Model
}
}
\IPS\Settings::i()->changeValues( $settingsToUpdate );
Settings::i()->changeValues( $settingsToUpdate );
/* Remove prefix */
$_values = $values;
@@ -315,7 +339,7 @@ class _Service extends \IPS\Node\Model
*
* @return string
*/
protected function get__title()
protected function get__title(): string
{
if ( !$this->id )
{
@@ -331,9 +355,9 @@ class _Service extends \IPS\Node\Model
* @note Return value NULL indicates the node cannot be enabled/disabled
* @return bool|null
*/
protected function get__enabled()
protected function get__enabled(): ?bool
{
return ( $this->enabled ) ? TRUE : FALSE;
return (bool)$this->enabled;
}
/**
@@ -342,7 +366,7 @@ class _Service extends \IPS\Node\Model
* @param bool|int $enabled Whether to set it enabled or disabled
* @return void
*/
protected function set__enabled( $enabled )
protected function set__enabled( bool|int $enabled ) : void
{
$this->enabled = $enabled;
}
@@ -352,7 +376,7 @@ class _Service extends \IPS\Node\Model
*
* @return bool
*/
public function canAdd()
public function canAdd(): bool
{
return FALSE;
}
@@ -362,7 +386,7 @@ class _Service extends \IPS\Node\Model
*
* @return bool
*/
public function canCopy()
public function canCopy(): bool
{
return FALSE;
}
@@ -372,7 +396,7 @@ class _Service extends \IPS\Node\Model
*
* @return bool
*/
public function canManagePermissions()
public function canManagePermissions(): bool
{
return FALSE;
}
@@ -380,9 +404,9 @@ class _Service extends \IPS\Node\Model
/**
* [Node] Does the currently logged in user have permission to delete this node?
*
* @return bool
* @return bool
*/
public function canDelete()
public function canDelete(): bool
{
return FALSE;
}
@@ -396,7 +420,7 @@ class _Service extends \IPS\Node\Model
* @param mixed $where Where clause
* @return array
*/
public static function search( $column, $query, $order=NULL, $where=array() )
public static function search( string $column, string $query, string $order=NULL, mixed $where=array() ): array
{
if ( $column === '_title' )
{
@@ -413,5 +437,5 @@ class _Service extends \IPS\Node\Model
* @brief [ActiveRecord] Caches
* @note Defined cache keys will be cleared automatically as needed
*/
protected $caches = array( 'shareLinks' );
protected array $caches = array( 'shareLinks' );
}