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

+126
View File
@@ -0,0 +1,126 @@
<?php
namespace IPS\Helpers\Menu;
use IPS\Http\Url;
use IPS\Member;
use IPS\Theme;
class Link extends MenuItem
{
/**
* Target
*
* @var Url|string
*/
public Url|string $url = '';
public string $extraHtml = '';
public string $identifier = '';
public string $notificationIcon = '';
public array $dataAttributes = [];
public array $wrapperDataAttributes = [];
public ?string $id = null;
public ?string $css = null;
/**
* Add an attribute to the link
*
* @param string $key
* @param string $value
* @return $this
*/
public function addAttribute( string $key, string $value = '' ): self
{
$this->dataAttributes[ $key ] = $value;
return $this;
}
/**
* Adds all necessary attributes for a confirmation box
* @param $desc
* @return $this
*/
public function requiresConfirm( $desc ): self
{
$this->addAttribute( 'data-confirm');
$this->addAttribute( 'data_confirmSubmessage', Member::loggedIn()->language()->addToStack( $desc ) );
return $this;
}
/**
* Adds all necessary attributes for a dialog
*
* @param string|NULL $title
* @param string $size
* @param bool $destruct
* @param string|NULL $contentSelector
* @param bool $remoteSubmit
* @return $this
*/
public function opensDialog( string $title = NULL, string $size = 'medium', bool $destruct = FALSE, string $contentSelector = NULL, bool $remoteSubmit = FALSE ): self
{
$this->addAttribute( 'data-ipsDialog')
->addAttribute( 'data-ipsDialog-size', $size )
->addAttribute( 'data-ipsDialog-title', Member::loggedIn()->language()->addToStack( $title ?? $this->title ) );
if( $contentSelector )
{
$this->addAttribute( 'data-ipsDialog-content', $contentSelector );
}
if( $destruct )
{
$this->addAttribute( 'data-ipsDialog-destructOnClose', 'true' );
}
if( $remoteSubmit )
{
$this->addAttribute( 'data-ipsDialog-remoteSubmit', 'true' );
}
return $this;
}
/**
* @param Url|string $url
* @param string $languageString
* @param string $css
* @param array $dataAttributes
* @param bool $opensDialog
* @param string|null $icon
* @param string|NULL $id
* @param string $identifier
*/
public function __construct( Url|string $url, string $languageString, string $css ='ipsMenu_item', array $dataAttributes = [], bool $opensDialog = FALSE, ?string $icon = NULL, string $id = NULL, string $identifier = '' )
{
$this->url = $url;
$this->title = $languageString;
$this->css = $css;
$this->dataAttributes = $dataAttributes;
$this->icon = $icon;
$this->menuItem = $identifier ?: $languageString;
if( !$id )
{
$id = 'menuLink_' . md5($languageString ) . '_' . $this->identifier;
}
$this->id = $id;
if( $opensDialog )
{
$this->opensDialog();
}
$this->addAttribute( 'data-menuItem', $languageString);
}
/**
* Return the parsed element
*
* @return string
*/
function __toString(): string
{
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->row( $this );
}
}
+281
View File
@@ -0,0 +1,281 @@
<?php
namespace IPS\Helpers;
use IPS\Helpers\Menu\MenuItem;
use IPS\Helpers\Menu\Separator;
use IPS\Helpers\Menu\TitleField;
use IPS\Member;
use IPS\Theme;
class Menu
{
/**
* Menu ID
* @var string
*/
public string $id;
/**
* Menu Icon
*
* @var string|null
*/
public ?string $icon;
/**
* Menu Name
*
* @var string
*/
public string $name;
/**
* Menu Elements(items)
*
* @var array
*/
public array $elements = [];
/**
* additional CSS CLasses
*
* @var string
*/
public string $css = '';
/**
* WHere should the menu appear
*
* @var string|mixed|null
*/
public ?string $appendTo = NULL;
/**
* Menu size - auto|normal|narrow
* @var string
*/
public string $menuType = 'auto';
/**
* @var string Extra HTML to add before the menu
*/
public string $extraHtmlBeforeLinks = '';
/**
* @var string Extra HTML to add after the menu
*/
public string $extraHtmlAfterLinks = '';
/**
* @var string Override the default menu button content with custom HTML
*/
public string $customLinkHtml = '';
/**
* Show the menu caret icon
*
* @var false|string|void
*/
public bool $showCaret = TRUE;
/**
* @var string|null
*/
public ?string $tooltip = NULL;
/**
* @breif If this is true, menus with only one element will show as a button
* @var bool
*/
public bool $shrinkToButton = true;
/**
* @param string $name
* @param string|null $icon
* @param string $css
* @param null $appendTo
* @param string|null $tooltip
*/
public function __construct( string $name, ?string $icon = NULL, string $css = 'ipsButton ipsButton--text', $appendTo = NULL, ?string $tooltip = NULL )
{
$this->elements = [];
$this->icon = $icon;
$this->name = $name;
$this->id = 'el' . $name;
$this->css = $css;
$this->appendTo = $appendTo;
$this->tooltip = $tooltip;
}
/**
* Add a menu item to the stack
*
* @param MenuItem $link
* @param string|null $after
* @return $this
*/
public function add( MenuItem $link, ?string $after=null ): self
{
$inserted = false;
$after = $after ?? $link->position;
if( $after !== null )
{
$elements = [];
foreach( $this->elements as $key => $element )
{
/* @var MenuItem $element */
$elements[ $key ] = $element;
if( $element->menuItem == $after )
{
$elements[ $link->menuItem ] = $link;
$inserted = true;
}
}
$this->elements = $elements;
}
/* Just in case the key did not exist */
if( !$inserted )
{
$this->elements[ $link->menuItem ] = $link;
}
return $this;
}
/**
* Getter
*
* @param $key
* @return string|void
*/
public function __get( $key )
{
if ( $key == 'title' )
{
return Member::loggedIn()->language()->addToStack( $this->name );
}
}
/**
* Adds a seperator element to the stack
*
* @return $this
*/
public function addSeparator(): self
{
$this->elements[] = new Separator;
return $this;
}
/**
* Adds a title field to the stack
*
* @param string $title
* @return $this
*/
public function addTitleField( string $title ): self
{
$this->elements[] = new TitleField( $title );
return $this;
}
/**
* Adds HTML code to the stack
* @param string $html
* @return $this
*/
public function addHtml(string $html ): self
{
$this->elements[] = $html;
return $this;
}
/**
* Returns all menu elements
*
* @return array
*/
public function getLinks(): array
{
return $this->elements;
}
/**
* Returns a row wrapper which can contain custom HTML code
* @param string $content
* @return string
*/
public function rowWrapper( string $content ): string
{
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->rowWrapper( $content );
}
/**
* Returns the link
*
* @return string
*/
public function linkHtml(): string
{
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->link( $this );
}
/**
* Returns the parsed menu content
*
* @return string
*/
public function contentHtml(): string
{
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->content( $this );
}
/**
* Returns the parsed menu
* @return string
*/
public function __toString(): string
{
/* If we have no elements, show nothing */
if( !$this->hasContent() )
{
return '';
}
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->menu( $this );
}
/*
* Do we have any elements in this menu?
*/
public function hasContent(): bool
{
return count( $this->elements ) > 0;
}
/**
* Move an item to the top of the menu
*
* @param $item
* @return void
*/
public function moveToStart( $item ): void
{
$currentElements = $this->elements;
$newElements = [];
foreach( $currentElements as $key => $row )
{
if( $row instanceof Menu\Link and $item->id == $row->id )
{
$newElements[ $key ] = $item;
unset( $currentElements[ $key ] );
}
}
$this->elements = array_merge( $newElements, $currentElements );
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace IPS\Helpers\Menu;
abstract class MenuItem
{
public string $title = '';
public ?string $icon = null;
public string $menuItem = '';
public ?string $position = null;
abstract function __toString(): string;
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace IPS\Helpers\Menu;
use IPS\Theme;
class Separator extends MenuItem
{
public function __toString(): string
{
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->separator( );
}
}
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace IPS\Helpers\Menu;
use IPS\Theme;
class TitleField extends MenuItem
{
/**
* Sets the title
*
* @param string $title
*/
public function __construct( string $title )
{
$this->title = $title;
}
public function __toString(): string
{
return Theme::i()->getTemplate( 'menu', 'core', 'front' )->titleField( $this );
}
}