From dd0572d7b2896bd90224af7562a8606c4afe4c16 Mon Sep 17 00:00:00 2001 From: kremsy Date: Wed, 21 Jun 2017 19:43:38 +0200 Subject: [PATCH] updated FML --- core/Manialinks/ManialinkManager.php | 7 + libs/FML/Components/CheckBox.php | 14 +- libs/FML/Components/ValuePicker.php | 1 - libs/FML/Controls/Control.php | 78 ++ libs/FML/Controls/Graph.php | 35 +- libs/FML/Controls/Label.php | 4 +- libs/FML/Controls/Quad.php | 4 +- .../FML/Controls/Quads/Quad_Icons128x32_1.php | 7 +- libs/FML/CustomUI.php | 10 +- libs/FML/Script/Builder.php | 29 +- libs/FML/Script/Features/GraphCurve.php | 18 +- libs/FML/Script/Features/Paging.php | 858 +++++++++--------- libs/FML/Script/Features/ScriptFeature.php | 36 +- .../Script/Features/ValuePickerFeature.php | 8 +- libs/FML/Script/Script.php | 11 +- libs/FML/Script/ScriptLabel.php | 1 + 16 files changed, 649 insertions(+), 472 deletions(-) diff --git a/core/Manialinks/ManialinkManager.php b/core/Manialinks/ManialinkManager.php index 8deae608..0ef84d34 100644 --- a/core/Manialinks/ManialinkManager.php +++ b/core/Manialinks/ManialinkManager.php @@ -233,6 +233,13 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener, * @return bool */ public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) { + //Add Toggle Feature + if($manialinkText instanceof ManiaLink){ + /*$toggleInterfaceF9 = new \FML\Script\Features\ToggleInterface("F9"); + $manialinkText->getScript() + ->addFeature($toggleInterfaceF9); (not working yet) */ + } + $manialinkText = (string) $manialinkText; if (!$manialinkText) { diff --git a/libs/FML/Components/CheckBox.php b/libs/FML/Components/CheckBox.php index 3955d9a7..a5ca4fdc 100644 --- a/libs/FML/Components/CheckBox.php +++ b/libs/FML/Components/CheckBox.php @@ -13,7 +13,6 @@ use FML\Types\ScriptFeatureable; /** * CheckBox Component * - * @uses Quad * @author steeffeen * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 @@ -74,6 +73,8 @@ class CheckBox implements Renderable, ScriptFeatureable public function setName($name) { $this->name = (string)$name; + $this->getEntry() + ->setName($this->name); return $this; } @@ -221,6 +222,7 @@ class CheckBox implements Renderable, ScriptFeatureable * * @param Entry $entry Hidden Entry * @return static + * @deprecated */ public function setEntry(Entry $entry) { @@ -236,9 +238,11 @@ class CheckBox implements Renderable, ScriptFeatureable protected function createEntry() { $entry = new Entry(); - $entry->setVisible(false) - ->setName($this->name); - $this->setEntry($entry); + $entry->setVisible(false); + if ($this->name) { + $entry->setName($this->name); + } + $this->feature->setEntry($entry); return $entry; } @@ -247,7 +251,7 @@ class CheckBox implements Renderable, ScriptFeatureable */ public function getScriptFeatures() { - return ScriptFeature::collect($this->feature, $this->getQuad(), $this->feature->getEntry()); + return ScriptFeature::collect($this->feature, $this->getQuad(), $this->getEntry()); } /** diff --git a/libs/FML/Components/ValuePicker.php b/libs/FML/Components/ValuePicker.php index 0a9e4df2..149536e7 100644 --- a/libs/FML/Components/ValuePicker.php +++ b/libs/FML/Components/ValuePicker.php @@ -13,7 +13,6 @@ use FML\Types\ScriptFeatureable; /** * ValuePicker Component * - * @uses Entry * @author steeffeen * @copyright FancyManiaLinks Copyright © 2017 Steffen Schröder * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 diff --git a/libs/FML/Controls/Control.php b/libs/FML/Controls/Control.php index e1793851..d1fc3f07 100644 --- a/libs/FML/Controls/Control.php +++ b/libs/FML/Controls/Control.php @@ -67,11 +67,21 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable */ protected $height = 0.; + /** + * @var string $defaultHorizontalAlign Default horizontal alignment + */ + static protected $defaultHorizontalAlign = self::CENTER; + /** * @var string $horizontalAlign Horizontal alignment */ protected $horizontalAlign = self::CENTER; + /** + * @var string $defaultVerticalAlign Default vertical alignment + */ + static protected $defaultVerticalAlign = self::CENTER2; + /** * @var string $verticalAlign Vertical alignment */ @@ -130,6 +140,8 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable if ($controlId) { $this->setId($controlId); } + $this->setHorizontalAlign(static::$defaultHorizontalAlign); + $this->setVerticalAlign(static::$defaultVerticalAlign); } /** @@ -310,6 +322,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable ->setHeight($height); } + /** + * Get the default horizontal alignment + * + * @api + * @return string + */ + public static function getDefaultHorizontalAlign() + { + return static::$defaultHorizontalAlign; + } + /** * Get the horizontal alignment * @@ -321,6 +344,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable return $this->horizontalAlign; } + /** + * Set the default horizontal alignment + * + * @api + * @param string $defaultHorizontalAlignment Default horizontal alignment + */ + public static function setDefaultHorizontalAlign($defaultHorizontalAlignment) + { + static::$defaultHorizontalAlign = (string)$defaultHorizontalAlignment; + } + /** * Set the horizontal alignment * @@ -348,6 +382,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable return $this; } + /** + * Get the default vertical alignment + * + * @api + * @return string + */ + public static function getDefaultVerticalAlign() + { + return static::$defaultVerticalAlign; + } + /** * Get the vertical alignment * @@ -359,6 +404,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable return $this->verticalAlign; } + /** + * Set the default vertical alignment + * + * @api + * @param string $defaultVerticalAlignment Default vertical alignment + */ + public static function setDefaultVerticalAlign($defaultVerticalAlignment) + { + static::$defaultVerticalAlign = (string)$defaultVerticalAlignment; + } + /** * Set the vertical alignment * @@ -400,6 +456,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable ->setVerticalAlign($verticalAlign); } + /** + * Center the default alignment + * + * @api + */ + public static function centerDefaultAlign() + { + static::$defaultHorizontalAlign = static::CENTER; + static::$defaultVerticalAlign = static::CENTER2; + } + /** * Center the alignment * @@ -424,6 +491,17 @@ abstract class Control implements Identifiable, Renderable, ScriptFeatureable return $this->clearAlign(); } + /** + * Clear the default alignment + * + * @api + */ + public static function clearDefaultAlign() + { + static::$defaultHorizontalAlign = null; + static::$defaultVerticalAlign = null; + } + /** * Clear the alignment * diff --git a/libs/FML/Controls/Graph.php b/libs/FML/Controls/Graph.php index 6d84b5de..64e3f319 100644 --- a/libs/FML/Controls/Graph.php +++ b/libs/FML/Controls/Graph.php @@ -3,8 +3,8 @@ namespace FML\Controls; use FML\Script\Features\GraphCurve; - -// TODO: check CoordsMin & CoordsMax properties of CMlGraph +use FML\Script\Features\GraphSettings; +use FML\Script\Features\ScriptFeature; /** * Graph Control @@ -17,11 +17,42 @@ use FML\Script\Features\GraphCurve; class Graph extends Control { + /** + * @var GraphSettings $graphSettings Graph settings + */ + protected $graphSettings = null; + /** * @var GraphCurve[] $curves Curves */ protected $curves = array(); + /** + * Get the graph settings + * + * @api + * @return GraphSettings + */ + public function getSettings() + { + if (!$this->graphSettings) { + $this->createSettings(); + } + return $this->graphSettings; + } + + /** + * Create new graph settings + * + * @return GraphSettings + */ + protected function createSettings() + { + $this->graphSettings = new GraphSettings($this); + $this->addScriptFeature($this->graphSettings); + return $this->graphSettings; + } + /** * Get curves * diff --git a/libs/FML/Controls/Label.php b/libs/FML/Controls/Label.php index 0462ba28..61b50043 100644 --- a/libs/FML/Controls/Label.php +++ b/libs/FML/Controls/Label.php @@ -65,7 +65,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL /** * @var int $actionKey Action key */ - protected $actionKey = -1; + protected $actionKey = null; /** * @var string $url Url @@ -651,7 +651,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL if ($this->action) { $domElement->setAttribute("action", $this->action); } - if ($this->actionKey >= 0) { + if ($this->actionKey) { $domElement->setAttribute("actionkey", $this->actionKey); } if ($this->url) { diff --git a/libs/FML/Controls/Quad.php b/libs/FML/Controls/Quad.php index 96de66e6..c0fecc6a 100644 --- a/libs/FML/Controls/Quad.php +++ b/libs/FML/Controls/Quad.php @@ -98,7 +98,7 @@ class Quad extends Control implements Actionable, BackgroundColorable, BgColorab /** * @var int $actionKey Action key */ - protected $actionKey = -1; + protected $actionKey = null; /** * @var string $url Link url @@ -676,6 +676,8 @@ class Quad extends Control implements Actionable, BackgroundColorable, BgColorab * @api * @param CheckBoxDesign $checkBoxDesign CheckBox Design * @return static + * @deprecated Use CheckBoxDesign::applyToQuad() + * @see CheckBoxDesign::applyToQuad() */ public function applyCheckBoxDesign(CheckBoxDesign $checkBoxDesign) { diff --git a/libs/FML/Controls/Quads/Quad_Icons128x32_1.php b/libs/FML/Controls/Quads/Quad_Icons128x32_1.php index eadf34d8..f690080e 100644 --- a/libs/FML/Controls/Quads/Quad_Icons128x32_1.php +++ b/libs/FML/Controls/Quads/Quad_Icons128x32_1.php @@ -17,10 +17,9 @@ class Quad_Icons128x32_1 extends Quad /* * Constants */ - const STYLE = 'Icons128x32_1'; - const SUBSTYLE_ArrowUp = 'ArrowUp'; - const SUBSTYLE_BgQuadWhite = 'BgQuadWhite'; - // TODO: validate existence of 'close' + const STYLE = 'Icons128x32_1'; + const SUBSTYLE_ArrowUp = 'ArrowUp'; + const SUBSTYLE_BgQuadWhite = 'BgQuadWhite'; const SUBSTYLE_Close = 'Close'; const SUBSTYLE_Empty = 'Empty'; const SUBSTYLE_ManiaLinkHome = 'ManiaLinkHome'; diff --git a/libs/FML/CustomUI.php b/libs/FML/CustomUI.php index 831b8678..acee89cb 100644 --- a/libs/FML/CustomUI.php +++ b/libs/FML/CustomUI.php @@ -53,7 +53,7 @@ class CustomUI protected $scoretableVisible = null; /** - * Create a new CustomUI + * Create a new Custom UI * * @api * @return static @@ -256,7 +256,7 @@ class CustomUI } /** - * Render the CustomUI standalone + * Render the Custom UI standalone * * @return \DOMDocument */ @@ -272,9 +272,9 @@ class CustomUI } /** - * Render the CustomUI + * Render the Custom UI * - * @param \DOMDocument $domDocument DOMDocument for which the CustomUI should be rendered + * @param \DOMDocument $domDocument DOMDocument for which the Custom UI should be rendered * @return \DOMElement */ public function render(\DOMDocument $domDocument) @@ -307,7 +307,7 @@ class CustomUI } /** - * Get associative array of all CustomUI settings + * Get associative array of all Custom UI settings * * @return array */ diff --git a/libs/FML/Script/Builder.php b/libs/FML/Script/Builder.php index 225370d2..54dbe370 100644 --- a/libs/FML/Script/Builder.php +++ b/libs/FML/Script/Builder.php @@ -69,6 +69,30 @@ abstract class Builder return static::escapeText($element->getId(), false); } + /** + * Get the 'Text' string representation of the given value + * + * @api + * @param string $value String value to convert to a ManiaScript 'Text' + * @return string + */ + public static function getText($value) + { + return '"' . (string)$value . '"'; + } + + /** + * Get the 'Integer' string representation of the given value + * + * @api + * @param int $value Int value to convert to a ManiaScript 'Integer' + * @return string + */ + public static function getInteger($value) + { + return (string)(int)$value; + } + /** * Get the 'Real' string representation of the given value * @@ -146,7 +170,7 @@ abstract class Builder * @param bool $associative (optional) Whether the array should be associative * @return string */ - public static function getArray(array $array, $associative = false) + public static function getArray(array $array, $associative = true) { $arrayText = "["; $index = 0; @@ -180,6 +204,9 @@ abstract class Builder if (is_bool($value)) { return static::getBoolean($value); } + if (is_array($value)) { + return static::getArray($value); + } return $value; } diff --git a/libs/FML/Script/Features/GraphCurve.php b/libs/FML/Script/Features/GraphCurve.php index 5dad1ab9..98831c63 100644 --- a/libs/FML/Script/Features/GraphCurve.php +++ b/libs/FML/Script/Features/GraphCurve.php @@ -45,7 +45,7 @@ class GraphCurve extends ScriptFeature /** * @var float $width Width */ - protected $width = -1.; + protected $width = null; /** * Construct a new Graph Curve @@ -275,26 +275,26 @@ if (Graph != Null) { declare GraphCurve <=> Graph.AddCurve(); "; foreach ($this->points as $point) { - $pointVec2 = Builder::getVec2($point); + $pointVec2 = Builder::getVec2($point); $scriptText .= " -GraphCurve.Points.add({$pointVec2});"; + GraphCurve.Points.add({$pointVec2});"; } if ($this->sortPoints) { $scriptText .= " -GraphCurve.SortPoints();"; + GraphCurve.SortPoints();"; } if ($this->color) { - $colorVec3 = Builder::getVec3($this->color); + $colorVec3 = Builder::getVec3($this->color); $scriptText .= " -GraphCurve.Color = {$colorVec3};"; + GraphCurve.Color = {$colorVec3};"; } if ($this->style) { $scriptText .= " -GraphCurve.Style = {$this->style};"; + GraphCurve.Style = {$this->style};"; } - if ($this->width > 0) { + if ($this->width) { $scriptText .= " -GraphCurve.Width = {$this->width};"; + GraphCurve.Width = {$this->width};"; } return $scriptText . " }"; diff --git a/libs/FML/Script/Features/Paging.php b/libs/FML/Script/Features/Paging.php index d8e197d5..bb4fb1a9 100644 --- a/libs/FML/Script/Features/Paging.php +++ b/libs/FML/Script/Features/Paging.php @@ -19,409 +19,409 @@ use FML\Script\ScriptLabel; class Paging extends ScriptFeature { - /* - * Constants - */ - const VAR_CURRENT_PAGE = "FML_Paging_CurrentPage"; - const FUNCTION_UPDATE_CURRENT_PAGE = "FML_UpdateCurrentPage"; + /* + * Constants + */ + const VAR_CURRENT_PAGE = "FML_Paging_CurrentPage"; + const FUNCTION_UPDATE_CURRENT_PAGE = "FML_UpdateCurrentPage"; - /** - * @var Label $label Page number Label - */ - protected $label = null; + /** + * @var Label $label Page number Label + */ + protected $label = null; - /** - * @var PagingPage[] $pages Pages - */ - protected $pages = array(); + /** + * @var PagingPage[] $pages Pages + */ + protected $pages = array(); - /** - * @var PagingButton[] $buttons Paging Buttons - */ - protected $buttons = array(); + /** + * @var PagingButton[] $buttons Paging Buttons + */ + protected $buttons = array(); - /** - * @var int $startPageNumber Start Page number - */ - protected $startPageNumber = null; + /** + * @var int $startPageNumber Start Page number + */ + protected $startPageNumber = null; - /** - * @var int $customMaxPageNumber Custom maximum page number - */ - protected $customMaxPageNumber = null; + /** + * @var int $customMaxPageNumber Custom maximum page number + */ + protected $customMaxPageNumber = null; - /** - * @var string $previousChunkAction Previous chunk action name - */ - protected $previousChunkAction = null; + /** + * @var string $previousChunkAction Previous chunk action name + */ + protected $previousChunkAction = null; - /** - * @var string $nextChunkAction Next chunk action name - */ - protected $nextChunkAction = null; + /** + * @var string $nextChunkAction Next chunk action name + */ + protected $nextChunkAction = null; - /** - * @var bool $chunkActionAppendsPageNumber Chunk action appended with Page number - */ - protected $chunkActionAppendsPageNumber = null; + /** + * @var bool $chunkActionAppendsPageNumber Chunk action appended with Page number + */ + protected $chunkActionAppendsPageNumber = null; - /** - * Construct a new Paging - * - * @api - * @param Label $label (optional) Page number Label - * @param PagingPage[] $pages (optional) Pages - * @param PagingButton[] $buttons (optional) Pageing Buttons - */ - public function __construct(Label $label = null, array $pages = null, array $buttons = null) - { - if ($label) { - $this->setLabel($label); - } - if ($pages) { - $this->setPages($pages); - } - if ($buttons) { - $this->setButtons($buttons); - } - } + /** + * Construct a new Paging + * + * @api + * @param Label $label (optional) Page number Label + * @param PagingPage[] $pages (optional) Pages + * @param PagingButton[] $buttons (optional) Pageing Buttons + */ + public function __construct(Label $label = null, array $pages = null, array $buttons = null) + { + if ($label) { + $this->setLabel($label); + } + if ($pages) { + $this->setPages($pages); + } + if ($buttons) { + $this->setButtons($buttons); + } + } - /** - * Get the Label showing the Page number - * - * @api - * @return Label - */ - public function getLabel() - { - return $this->label; - } + /** + * Get the Label showing the Page number + * + * @api + * @return Label + */ + public function getLabel() + { + return $this->label; + } - /** - * Set the Label showing the Page number - * - * @api - * @param Label $label Page number Label - * @return static - */ - public function setLabel(Label $label) - { - $label->checkId(); - $this->label = $label; - return $this; - } + /** + * Set the Label showing the Page number + * + * @api + * @param Label $label Page number Label + * @return static + */ + public function setLabel(Label $label) + { + $label->checkId(); + $this->label = $label; + return $this; + } - /** - * Get the Pages - * - * @api - * @return PagingPage[] - */ - public function getPages() - { - return $this->pages; - } + /** + * Get the Pages + * + * @api + * @return PagingPage[] + */ + public function getPages() + { + return $this->pages; + } - /** - * Add a new Page Control - * - * @api - * @param Control $pageControl Page Control - * @param string $pageNumber (optional) Page number - * @return static - */ - public function addPageControl(Control $pageControl, $pageNumber = null) - { - if ($pageNumber === null) { - $pageNumber = count($this->pages) + 1; - } - $page = new PagingPage($pageControl, $pageNumber); - return $this->addPage($page); - } + /** + * Add a new Page Control + * + * @api + * @param Control $pageControl Page Control + * @param string $pageNumber (optional) Page number + * @return static + */ + public function addPageControl(Control $pageControl, $pageNumber = null) + { + if ($pageNumber === null) { + $pageNumber = count($this->pages) + 1; + } + $page = new PagingPage($pageControl, $pageNumber); + return $this->addPage($page); + } - /** - * Add a new Page - * - * @api - * @param PagingPage $page Page - * @return static - */ - public function addPage(PagingPage $page) - { - if (!in_array($page, $this->pages, true)) { - array_push($this->pages, $page); - } - return $this; - } + /** + * Add a new Page + * + * @api + * @param PagingPage $page Page + * @return static + */ + public function addPage(PagingPage $page) + { + if (!in_array($page, $this->pages, true)) { + array_push($this->pages, $page); + } + return $this; + } - /** - * Add new Pages - * - * @api - * @param PagingPage[] $pages Pages - * @return static - */ - public function setPages(array $pages) - { - $this->pages = array(); - foreach ($pages as $page) { - $this->addPage($page); - } - return $this; - } + /** + * Add new Pages + * + * @api + * @param PagingPage[] $pages Pages + * @return static + */ + public function setPages(array $pages) + { + $this->pages = array(); + foreach ($pages as $page) { + $this->addPage($page); + } + return $this; + } - /** - * Get the Buttons - * - * @api - * @return PagingButton[] - */ - public function getButtons() - { - return $this->buttons; - } + /** + * Get the Buttons + * + * @api + * @return PagingButton[] + */ + public function getButtons() + { + return $this->buttons; + } - /** - * Add a new Button Control to browse through the Pages - * - * @api - * @param Control $buttonControl Button used for browsing - * @param int $browseAction (optional) Number of browsed Pages per click - * @return static - */ - public function addButtonControl(Control $buttonControl, $browseAction = null) - { - if ($browseAction === null) { - $buttonCount = count($this->buttons); - if ($buttonCount % 2 === 0) { - $browseAction = $buttonCount / 2 + 1; - } else { - $browseAction = $buttonCount / -2 - 1; - } - } - $button = new PagingButton($buttonControl, $browseAction); - return $this->addButton($button); - } + /** + * Add a new Button Control to browse through the Pages + * + * @api + * @param Control $buttonControl Button used for browsing + * @param int $browseAction (optional) Number of browsed Pages per click + * @return static + */ + public function addButtonControl(Control $buttonControl, $browseAction = null) + { + if ($browseAction === null) { + $buttonCount = count($this->buttons); + if ($buttonCount % 2 === 0) { + $browseAction = $buttonCount / 2 + 1; + } else { + $browseAction = $buttonCount / -2 - 1; + } + } + $button = new PagingButton($buttonControl, $browseAction); + return $this->addButton($button); + } - /** - * Add a new Button to browse through Pages - * - * @api - * @param PagingButton $button Paging Button - * @return static - */ - public function addButton(PagingButton $button) - { - if (!in_array($button, $this->buttons, true)) { - array_push($this->buttons, $button); - } - return $this; - } + /** + * Add a new Button to browse through Pages + * + * @api + * @param PagingButton $button Paging Button + * @return static + */ + public function addButton(PagingButton $button) + { + if (!in_array($button, $this->buttons, true)) { + array_push($this->buttons, $button); + } + return $this; + } - /** - * Set the Paging Buttons - * - * @api - * @param PagingButton[] $buttons Paging Buttons - * @return static - */ - public function setButtons(array $buttons) - { - $this->buttons = array(); - foreach ($buttons as $button) { - $this->addButton($button); - } - return $this; - } + /** + * Set the Paging Buttons + * + * @api + * @param PagingButton[] $buttons Paging Buttons + * @return static + */ + public function setButtons(array $buttons) + { + $this->buttons = array(); + foreach ($buttons as $button) { + $this->addButton($button); + } + return $this; + } - /** - * Get the start Page number - * - * @api - * @return int - */ - public function getStartPageNumber() - { - return $this->startPageNumber; - } + /** + * Get the start Page number + * + * @api + * @return int + */ + public function getStartPageNumber() + { + return $this->startPageNumber; + } - /** - * Set the start Page number - * - * @api - * @param int $startPageNumber Page number to start with - * @return static - */ - public function setStartPageNumber($startPageNumber) - { - $this->startPageNumber = (int)$startPageNumber; - return $this; - } + /** + * Set the start Page number + * + * @api + * @param int $startPageNumber Page number to start with + * @return static + */ + public function setStartPageNumber($startPageNumber) + { + $this->startPageNumber = (int)$startPageNumber; + return $this; + } - /** - * Get a custom maximum Page number for using chunks - * - * @api - * @return int - */ - public function getCustomMaxPageNumber() - { - return $this->customMaxPageNumber; - } + /** + * Get a custom maximum Page number for using chunks + * + * @api + * @return int + */ + public function getCustomMaxPageNumber() + { + return $this->customMaxPageNumber; + } - /** - * Set a custom maximum Page number for using chunks - * - * @api - * @param int $maxPageNumber Custom maximum Page number - * @return static - */ - public function setCustomMaxPageNumber($maxPageNumber) - { - $this->customMaxPageNumber = (int)$maxPageNumber; - return $this; - } + /** + * Set a custom maximum Page number for using chunks + * + * @api + * @param int $maxPageNumber Custom maximum Page number + * @return static + */ + public function setCustomMaxPageNumber($maxPageNumber) + { + $this->customMaxPageNumber = (int)$maxPageNumber; + return $this; + } - /** - * Get the action triggered when the previous chunk is needed - * - * @api - * @return string - */ - public function getPreviousChunkAction() - { - return $this->previousChunkAction; - } + /** + * Get the action triggered when the previous chunk is needed + * + * @api + * @return string + */ + public function getPreviousChunkAction() + { + return $this->previousChunkAction; + } - /** - * Set the action triggered when the previous chunk is needed - * - * @api - * @param string $previousChunkAction Triggered action - * @return static - */ - public function setPreviousChunkAction($previousChunkAction) - { - $this->previousChunkAction = (string)$previousChunkAction; - return $this; - } + /** + * Set the action triggered when the previous chunk is needed + * + * @api + * @param string $previousChunkAction Triggered action + * @return static + */ + public function setPreviousChunkAction($previousChunkAction) + { + $this->previousChunkAction = (string)$previousChunkAction; + return $this; + } - /** - * Get the action triggered when the next chunk is needed - * - * @api - * @return string - */ - public function getNextChunkAction() - { - return $this->nextChunkAction; - } + /** + * Get the action triggered when the next chunk is needed + * + * @api + * @return string + */ + public function getNextChunkAction() + { + return $this->nextChunkAction; + } - /** - * Set the action triggered when the next chunk is needed - * - * @api - * @param string $nextChunkAction Triggered action - * @return static - */ - public function setNextChunkAction($nextChunkAction) - { - $this->nextChunkAction = (string)$nextChunkAction; - return $this; - } + /** + * Set the action triggered when the next chunk is needed + * + * @api + * @param string $nextChunkAction Triggered action + * @return static + */ + public function setNextChunkAction($nextChunkAction) + { + $this->nextChunkAction = (string)$nextChunkAction; + return $this; + } - /** - * Set the actions triggered when another chunk is needed - * - * @api - * @param string $chunkAction Triggered action - * @return static - */ - public function setChunkActions($chunkAction) - { - return $this->setNextChunkAction($chunkAction) - ->setPreviousChunkAction($chunkAction); - } + /** + * Set the actions triggered when another chunk is needed + * + * @api + * @param string $chunkAction Triggered action + * @return static + */ + public function setChunkActions($chunkAction) + { + return $this->setNextChunkAction($chunkAction) + ->setPreviousChunkAction($chunkAction); + } - /** - * Get if the chunk action should append the needed Page number - * - * @api - * @return bool - */ - public function getChunkActionAppendsPageNumber() - { - return $this->chunkActionAppendsPageNumber; - } + /** + * Get if the chunk action should append the needed Page number + * + * @api + * @return bool + */ + public function getChunkActionAppendsPageNumber() + { + return $this->chunkActionAppendsPageNumber; + } - /** - * Set if the chunk action should append the needed Page number - * - * @api - * @param bool $appendPageNumber Append the needed Page number - * @return static - */ - public function setChunkActionAppendsPageNumber($appendPageNumber) - { - $this->chunkActionAppendsPageNumber = (bool)$appendPageNumber; - return $this; - } + /** + * Set if the chunk action should append the needed Page number + * + * @api + * @param bool $appendPageNumber Append the needed Page number + * @return static + */ + public function setChunkActionAppendsPageNumber($appendPageNumber) + { + $this->chunkActionAppendsPageNumber = (bool)$appendPageNumber; + return $this; + } - /** - * @see ScriptFeature::prepare() - */ - public function prepare(Script $script) - { - if (empty($this->pages)) { - return $this; - } - $script->setScriptInclude(ScriptInclude::TEXTLIB); + /** + * @see ScriptFeature::prepare() + */ + public function prepare(Script $script) + { + if (empty($this->pages)) { + return $this; + } + $script->setScriptInclude(ScriptInclude::TEXTLIB); - $currentPageVariable = self::VAR_CURRENT_PAGE; - $updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE; + $currentPageVariable = self::VAR_CURRENT_PAGE; + $updatePageFunction = self::FUNCTION_UPDATE_CURRENT_PAGE; - $minPageNumber = 1; - $startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber); - $maxPage = $this->getMaxPage(); - $maxPageNumber = $this->customMaxPageNumber; - if (!is_int($maxPageNumber)) { - $maxPageNumber = $maxPage->getPageNumber(); - } + $minPageNumber = 1; + $startPageNumber = (is_int($this->startPageNumber) ? $this->startPageNumber : $minPageNumber); + $maxPage = $this->getMaxPage(); + $maxPageNumber = $this->customMaxPageNumber; + if (!is_int($maxPageNumber)) { + $maxPageNumber = $maxPage->getPageNumber(); + } - $pagingId = $maxPage->getControl() - ->getId(true, true); - $pagingId = Builder::escapeText($maxPage->getControl() - ->getId()); - $pageLabelId = Builder::EMPTY_STRING; - if ($this->label) { - $pageLabelId = Builder::escapeText($this->label->getId()); - } + $pagingId = $maxPage->getControl() + ->getId(true, true); + $pagingId = Builder::escapeText($maxPage->getControl() + ->getId()); + $pageLabelId = Builder::EMPTY_STRING; + if ($this->label) { + $pageLabelId = Builder::escapeText($this->label->getId()); + } - $pagesArrayText = $this->getPagesArrayText(); - $pageButtonsArrayText = $this->getPageButtonsArrayText(); + $pagesArrayText = $this->getPagesArrayText(); + $pageButtonsArrayText = $this->getPageButtonsArrayText(); - $previousChunkAction = Builder::escapeText($this->previousChunkAction); - $nextChunkAction = Builder::escapeText($this->nextChunkAction); - $chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber); + $previousChunkAction = Builder::escapeText($this->previousChunkAction); + $nextChunkAction = Builder::escapeText($this->nextChunkAction); + $chunkActionAppendsPageNumber = Builder::getBoolean($this->chunkActionAppendsPageNumber); - // Init - $initScriptText = " + // Init + $initScriptText = " declare {$currentPageVariable} for This = Integer[Text]; {$currentPageVariable}[{$pagingId}] = {$startPageNumber}; {$updatePageFunction}({$pagingId}, {$pageLabelId}, 0, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber});"; - $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true); + $script->appendGenericScriptLabel(ScriptLabel::ONINIT, $initScriptText, true); - // MouseClick - $clickScriptText = " + // MouseClick + $clickScriptText = " declare PageButtons = {$pageButtonsArrayText}; if (PageButtons.existskey(Event.Control.ControlId)) { declare BrowseAction = PageButtons[Event.Control.ControlId]; {$updatePageFunction}({$pagingId}, {$pageLabelId}, BrowseAction, {$minPageNumber}, {$maxPageNumber}, {$pagesArrayText}, {$previousChunkAction}, {$nextChunkAction}, {$chunkActionAppendsPageNumber}); }"; - $script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true); + $script->appendGenericScriptLabel(ScriptLabel::MOUSECLICK, $clickScriptText, true); - // Update function - $functionText = " + // Update function + $functionText = " Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAction, Integer _MinPageNumber, Integer _MaxPageNumber, Text[Integer] _Pages, Text _PreviousChunkAction, Text _NextChunkAction, Boolean _ChunkActionAppendPageNumber) { declare {$currentPageVariable} for This = Integer[Text]; if (!{$currentPageVariable}.existskey(_PagingId)) return; @@ -454,82 +454,82 @@ Void {$updatePageFunction}(Text _PagingId, Text _PageLabelId, Integer _BrowseAct TriggerPageAction(ChunkAction); } }"; - $script->addScriptFunction($updatePageFunction, $functionText); - return $this; - } + $script->addScriptFunction($updatePageFunction, $functionText); + return $this; + } - /** - * Get the minimum Page - * - * @return PagingPage - */ - protected function getMinPage() - { - $minPageNumber = null; - $minPage = null; - foreach ($this->pages as $page) { - $pageNumber = $page->getPageNumber(); - if ($minPageNumber === null || $pageNumber < $minPageNumber) { - $minPageNumber = $pageNumber; - $minPage = $page; - } - } - return $minPage; - } + /** + * Get the minimum Page + * + * @return PagingPage + */ + protected function getMinPage() + { + $minPageNumber = null; + $minPage = null; + foreach ($this->pages as $page) { + $pageNumber = $page->getPageNumber(); + if ($minPageNumber === null || $pageNumber < $minPageNumber) { + $minPageNumber = $pageNumber; + $minPage = $page; + } + } + return $minPage; + } - /** - * Get the maximum Page - * - * @return PagingPage - */ - protected function getMaxPage() - { - $maxPageNumber = null; - $maxPage = null; - foreach ($this->pages as $page) { - $pageNumber = $page->getPageNumber(); - if ($maxPageNumber === null || $pageNumber > $maxPageNumber) { - $maxPageNumber = $pageNumber; - $maxPage = $page; - } - } - return $maxPage; - } + /** + * Get the maximum Page + * + * @return PagingPage + */ + protected function getMaxPage() + { + $maxPageNumber = null; + $maxPage = null; + foreach ($this->pages as $page) { + $pageNumber = $page->getPageNumber(); + if ($maxPageNumber === null || $pageNumber > $maxPageNumber) { + $maxPageNumber = $pageNumber; + $maxPage = $page; + } + } + return $maxPage; + } - /** - * Build the array text for the Pages - * - * @return string - */ - protected function getPagesArrayText() - { - if (empty($this->pages)) { - return Builder::getArray(array(0 => ''), true); - } - $pages = array(); - foreach ($this->pages as $page) { - $pages[$page->getPageNumber()] = $page->getControl() - ->getId(); - } - return Builder::getArray($pages, true); - } + /** + * Build the array text for the Pages + * + * @return string + */ + protected function getPagesArrayText() + { + if (empty($this->pages)) { + return Builder::getArray(array(0 => ''), true); + } + $pages = array(); + foreach ($this->pages as $page) { + $pages[$page->getPageNumber()] = $page->getControl() + ->getId(); + } + return Builder::getArray($pages, true); + } - /** - * Build the array text for the Page Buttons - * - * @return string - */ - protected function getPageButtonsArrayText() - { - if (empty($this->buttons)) { - return Builder::getArray(array('' => 0), true); - } - $pageButtons = array(); - foreach ($this->buttons as $pageButton) { - $pageButtons[$pageButton->getControl() - ->getId()] = $pageButton->getPagingCount(); - } - return Builder::getArray($pageButtons, true); - } + /** + * Build the array text for the Page Buttons + * + * @return string + */ + protected function getPageButtonsArrayText() + { + if (empty($this->buttons)) { + return Builder::getArray(array('' => 0), true); + } + $pageButtons = array(); + foreach ($this->buttons as $pageButton) { + $pageButtons[$pageButton->getControl() + ->getId()] = $pageButton->getPagingCount(); + } + return Builder::getArray($pageButtons, true); + } } diff --git a/libs/FML/Script/Features/ScriptFeature.php b/libs/FML/Script/Features/ScriptFeature.php index 9cf1dd7f..4fa46ad7 100644 --- a/libs/FML/Script/Features/ScriptFeature.php +++ b/libs/FML/Script/Features/ScriptFeature.php @@ -25,10 +25,38 @@ abstract class ScriptFeature $params = func_get_args(); $scriptFeatures = array(); foreach ($params as $object) { - if ($object instanceof ScriptFeatureable) { - $scriptFeatures = array_merge($scriptFeatures, $object->getScriptFeatures()); - } else if ($object instanceof ScriptFeature) { - array_push($scriptFeatures, $object); + if ($object instanceof ScriptFeature) { + $scriptFeatures = static::addScriptFeature($scriptFeatures, $object); + } else if ($object instanceof ScriptFeatureable) { + $scriptFeatures = static::addScriptFeature($scriptFeatures, $object->getScriptFeatures()); + } else if (is_array($object)) { + foreach ($object as $subObject) { + $scriptFeatures = static::addScriptFeature($scriptFeatures, static::collect($subObject)); + } + } + } + return $scriptFeatures; + } + + /** + * Add one or more Script Features to an Array of Features if they are not already contained + * + * @param array $scriptFeatures + * @param ScriptFeature||ScriptFeature[] $newScriptFeatures + * @return array + */ + public static function addScriptFeature(array $scriptFeatures, $newScriptFeatures) + { + if (!$newScriptFeatures) { + return $scriptFeatures; + } + if ($newScriptFeatures instanceof ScriptFeature) { + if (!in_array($newScriptFeatures, $scriptFeatures, true)) { + array_push($scriptFeatures, $newScriptFeatures); + } + } else if (is_array($newScriptFeatures)) { + foreach ($newScriptFeatures as $newScriptFeature) { + $scriptFeatures = static::addScriptFeature($scriptFeatures, $newScriptFeature); } } return $scriptFeatures; diff --git a/libs/FML/Script/Features/ValuePickerFeature.php b/libs/FML/Script/Features/ValuePickerFeature.php index eebe8be5..38c06d1d 100644 --- a/libs/FML/Script/Features/ValuePickerFeature.php +++ b/libs/FML/Script/Features/ValuePickerFeature.php @@ -219,7 +219,7 @@ class ValuePickerFeature extends ScriptFeature { return " Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) { - declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[]; + declare " . self::VAR_PICKER_VALUES . " as Values for _Label = Text[Integer]; declare NewValueIndex = -1; if (Values.exists(_Label.Value)) { declare ValueIndex = Values.keyof(_Label.Value); @@ -264,11 +264,11 @@ Void " . self::FUNCTION_UPDATE_PICKER_VALUE . "(CMlLabel _Label) { return " declare Label_Picker <=> (Page.GetFirstChild(\"{$labelId}\") as CMlLabel); -declare Text[] " . self::VAR_PICKER_VALUES . " as Values for Label_Picker; +declare " . self::VAR_PICKER_VALUES . " as Values for Label_Picker = Text[Integer]; Values = {$values}; -declare Text " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker; +declare " . self::VAR_PICKER_DEFAULT_VALUE . " as Default for Label_Picker = \"\"; Default = {$default}; -declare Text " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker; +declare " . self::VAR_PICKER_ENTRY_ID . " as EntryId for Label_Picker = \"\"; EntryId = \"{$entryId}\"; " . self::FUNCTION_UPDATE_PICKER_VALUE . "(Label_Picker); "; diff --git a/libs/FML/Script/Script.php b/libs/FML/Script/Script.php index 6498a897..57c1027c 100644 --- a/libs/FML/Script/Script.php +++ b/libs/FML/Script/Script.php @@ -265,14 +265,14 @@ class Script */ protected function getHeaderComment() { - $headerComment = '/**************************************************** -* FancyManiaLinks'; + $headerComment = '/************************************************** +* FancyManiaLinks'; if (defined('FML_VERSION')) { $headerComment .= ' v' . FML_VERSION; } - $headerComment .= ' by steeffeen * -* http://github.com/steeffeen/FancyManiaLinks * -****************************************************/ + $headerComment .= ' by steeffeen * +* http://github.com/steeffeen/FancyManiaLinks * +**************************************************/ '; return $headerComment; @@ -349,6 +349,7 @@ main() { } case CMlEvent::Type::MouseClick: { +++' . ScriptLabel::MOUSECLICK . '+++ + +++' . ScriptLabel::MOUSECLICK2 . '+++ } case CMlEvent::Type::MouseOut: { +++' . ScriptLabel::MOUSEOUT . '+++ diff --git a/libs/FML/Script/ScriptLabel.php b/libs/FML/Script/ScriptLabel.php index 689f749b..385e1382 100644 --- a/libs/FML/Script/ScriptLabel.php +++ b/libs/FML/Script/ScriptLabel.php @@ -21,6 +21,7 @@ class ScriptLabel const ENTRYSUBMIT = 'FML_EntrySubmit'; const KEYPRESS = 'FML_KeyPress'; const MOUSECLICK = 'FML_MouseClick'; + const MOUSECLICK2 = 'FML_MouseClick2'; const MOUSEOUT = 'FML_MouseOut'; const MOUSEOVER = 'FML_MouseOver';