From 6e37411fc49b4e547a756c6d904494a56afa50a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Tue, 15 Apr 2014 15:47:57 +0200 Subject: [PATCH] fml update --- application/core/Libs/FML/ManiaCode.php | 15 +++ .../Libs/FML/ManiaCode/InstallMacroblock.php | 98 +++++++++++++++++++ .../core/Libs/FML/ManiaCode/InstallPack.php | 6 +- application/core/Libs/FML/Script/Script.php | 62 +++++++----- application/core/Libs/FML/autoload.php | 61 ++++++++++-- 5 files changed, 209 insertions(+), 33 deletions(-) create mode 100644 application/core/Libs/FML/ManiaCode/InstallMacroblock.php diff --git a/application/core/Libs/FML/ManiaCode.php b/application/core/Libs/FML/ManiaCode.php index 9e5a706f..3ecf50e4 100644 --- a/application/core/Libs/FML/ManiaCode.php +++ b/application/core/Libs/FML/ManiaCode.php @@ -18,6 +18,7 @@ use FML\ManiaCode\PlayMap; use FML\ManiaCode\PlayReplay; use FML\ManiaCode\ShowMessage; use FML\ManiaCode\ViewReplay; +use FML\ManiaCode\InstallMacroblock; /** * Class representing a ManiaCode @@ -85,6 +86,20 @@ class ManiaCode { return $this; } + /** + * Install a Macroblock + * + * @param string $name Macroblock Name + * @param string $file Macroblock File + * @param string $url Macroblock Url + * @return \FML\ManiaCode + */ + public function addInstallMacroblock($name, $file, $url) { + $macroblockElement = new InstallMacroblock($name, $file, $url); + $this->addElement($macroblockElement); + return $this; + } + /** * Install a Map * diff --git a/application/core/Libs/FML/ManiaCode/InstallMacroblock.php b/application/core/Libs/FML/ManiaCode/InstallMacroblock.php new file mode 100644 index 00000000..04978d10 --- /dev/null +++ b/application/core/Libs/FML/ManiaCode/InstallMacroblock.php @@ -0,0 +1,98 @@ +setName($name); + } + if ($file !== null) { + $this->setFile($file); + } + if ($url !== null) { + $this->setUrl($url); + } + } + + /** + * Set the Name of the Macroblock + * + * @param string $name Macroblock Name + * @return \FML\ManiaCode\InstallMacroblock + */ + public function setName($name) { + $this->name = (string) $name; + return $this; + } + + /** + * Set the File of the Macroblock + * + * @param string $file Macroblock File + * @return \FML\ManiaCode\InstallMacroblock + */ + public function setFile($file) { + $this->file = (string) $file; + return $this; + } + + /** + * Set the Url of the Macroblock + * + * @param string $url Macroblock Url + * @return \FML\ManiaCode\InstallMacroblock + */ + public function setUrl($url) { + $this->url = (string) $url; + return $this; + } + + /** + * + * @see \FML\ManiaCode\Element::render() + */ + public function render(\DOMDocument $domDocument) { + $xmlElement = $domDocument->createElement($this->tagName); + $nameElement = $domDocument->createElement('name', $this->name); + $xmlElement->appendChild($nameElement); + $fileElement = $domDocument->createElement('file', $this->file); + $xmlElement->appendChild($fileElement); + $urlElement = $domDocument->createElement('url', $this->url); + $xmlElement->appendChild($urlElement); + return $xmlElement; + } +} diff --git a/application/core/Libs/FML/ManiaCode/InstallPack.php b/application/core/Libs/FML/ManiaCode/InstallPack.php index c47b9543..f1ac098e 100644 --- a/application/core/Libs/FML/ManiaCode/InstallPack.php +++ b/application/core/Libs/FML/ManiaCode/InstallPack.php @@ -51,7 +51,7 @@ class InstallPack implements Element { } /** - * Set the Name of the Script + * Set the Name of the Pack * * @param string $name Pack Name * @return \FML\ManiaCode\InstallPack @@ -62,7 +62,7 @@ class InstallPack implements Element { } /** - * Set the File of the Script + * Set the File of the Pack * * @param string $file Pack File * @return \FML\ManiaCode\InstallPack @@ -73,7 +73,7 @@ class InstallPack implements Element { } /** - * Set the Url of the Script + * Set the Url of the Pack * * @param string $url Pack Url * @return \FML\ManiaCode\InstallPack diff --git a/application/core/Libs/FML/Script/Script.php b/application/core/Libs/FML/Script/Script.php index 3de3cd84..67c2e9e4 100644 --- a/application/core/Libs/FML/Script/Script.php +++ b/application/core/Libs/FML/Script/Script.php @@ -693,7 +693,43 @@ if (Event.Control.HasClass(\"" . self::CLASS_MENUBUTTON . "\")) { $this->setInclude('TextLib', 'TextLib'); $pagesNumberPrefix = self::CLASS_PAGE . '-P'; $pagesNumberPrefixLength = strlen($pagesNumberPrefix); - $pagesScript = " + + $pagesInitScript = " +declare PageLabelControls = CMlControl[]; +Page.GetClassChildren(\"" . self::CLASS_PAGELABEL . "\", Page.MainFrame, True); +foreach (PageLabelControl in Page.GetClassChildren_Result) { + declare Temp = PageLabelControl; + PageLabelControls.add(Temp); +} +declare FML_MinPageNumber for This = Integer[Text]; +declare FML_MaxPageNumber for This = Integer[Text]; +declare FML_PageNumber for This = Integer[Text]; +foreach (PageLabelControl in PageLabelControls) { + foreach (ControlClass in PageLabelControl.ControlClasses) { + Page.GetClassChildren(ControlClass, Page.MainFrame, True); + foreach (PageControl in Page.GetClassChildren_Result) { + if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; + foreach (PageControlClass in PageControl.ControlClasses) { + if (TextLib::SubText(PageControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue; + declare PageNumber = TextLib::ToInteger(TextLib::SubText(PageControlClass, {$pagesNumberPrefixLength}, TextLib::Length(PageControlClass))); + if (!FML_MinPageNumber.existskey(ControlClass) || PageNumber < FML_MinPageNumber[ControlClass]) { + FML_MinPageNumber[ControlClass] = PageNumber; + } + if (!FML_MaxPageNumber.existskey(ControlClass) || PageNumber > FML_MaxPageNumber[ControlClass]) { + FML_MaxPageNumber[ControlClass] = PageNumber; + } + break; + } + } + if (FML_MinPageNumber.existskey(ControlClass)) { + FML_PageNumber[ControlClass] = FML_MinPageNumber[ControlClass]; + declare PageLabel <=> (PageLabelControl as CMlLabel); + PageLabel.Value = FML_PageNumber[ControlClass]^\"/\"^FML_MaxPageNumber[ControlClass]; + } + } +}"; + + $pagesClickScript = " if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) { declare Text PagesId; declare Integer PagingAction; @@ -710,28 +746,9 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) { } } } - declare FML_PagesLastScriptStart for This = FML_ScriptStart; declare FML_MinPageNumber for This = Integer[Text]; declare FML_MaxPageNumber for This = Integer[Text]; declare FML_PageNumber for This = Integer[Text]; - if (FML_PagesLastScriptStart != FML_ScriptStart || !FML_PageNumber.existskey(PagesId) || !FML_MinPageNumber.existskey(PagesId) || !FML_MaxPageNumber.existskey(PagesId)) { - Page.GetClassChildren(PagesId, Page.MainFrame, True); - foreach (PageControl in Page.GetClassChildren_Result) { - if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; - foreach (ControlClass in PageControl.ControlClasses) { - if (TextLib::SubText(ControlClass, 0, {$pagesNumberPrefixLength}) != \"{$pagesNumberPrefix}\") continue; - declare PageNumber = TextLib::ToInteger(TextLib::SubText(ControlClass, {$pagesNumberPrefixLength}, TextLib::Length(ControlClass))); - if (!FML_MinPageNumber.existskey(PagesId) || PageNumber < FML_MinPageNumber[PagesId]) { - FML_MinPageNumber[PagesId] = PageNumber; - } - if (!FML_MaxPageNumber.existskey(PagesId) || PageNumber > FML_MaxPageNumber[PagesId]) { - FML_MaxPageNumber[PagesId] = PageNumber; - } - break; - } - } - FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId]; - } FML_PageNumber[PagesId] += PagingAction; if (FML_PageNumber[PagesId] < FML_MinPageNumber[PagesId]) { FML_PageNumber[PagesId] = FML_MinPageNumber[PagesId]; @@ -739,7 +756,6 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) { if (FML_PageNumber[PagesId] > FML_MaxPageNumber[PagesId]) { FML_PageNumber[PagesId] = FML_MaxPageNumber[PagesId]; } - FML_PagesLastScriptStart = FML_ScriptStart; Page.GetClassChildren(PagesId, Page.MainFrame, True); foreach (PageControl in Page.GetClassChildren_Result) { if (!PageControl.HasClass(\"" . self::CLASS_PAGE . "\")) continue; @@ -758,7 +774,9 @@ if (Event.Control.HasClass(\"" . self::CLASS_PAGER . "\")) { PageLabel.Value = FML_PageNumber[PagesId]^\"/\"^FML_MaxPageNumber[PagesId]; } }"; - $pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesScript); + + $pagesLabels = Builder::getLabelImplementationBlock(self::LABEL_ONINIT, $pagesInitScript); + $pagesLabels .= Builder::getLabelImplementationBlock(self::LABEL_MOUSECLICK, $pagesClickScript); return $pagesLabels; } diff --git a/application/core/Libs/FML/autoload.php b/application/core/Libs/FML/autoload.php index 715d6c3d..f67907db 100644 --- a/application/core/Libs/FML/autoload.php +++ b/application/core/Libs/FML/autoload.php @@ -9,20 +9,65 @@ * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 */ if (!defined('FML_PATH')) { - define('FML_PATH', __DIR__ . '/../'); + define('FML_PATH', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR); } if (!defined('FML_VERSION')) { define('FML_VERSION', 1.0); } +if (!defined('FML_SIMPLE_CLASSES')) { + define('FML_SIMPLE_CLASSES', false); +} /* * Autoload Function that loads FML Class Files on Demand */ -spl_autoload_register( - function ($className) { - $classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className); - $filePath = FML_PATH . DIRECTORY_SEPARATOR . $classPath . '.php'; - if (file_exists($filePath)) { - require_once $filePath; +if (!defined('FML_AUTOLOAD_DEFINED')) { + define('FML_AUTOLOAD_DEFINED', true); + spl_autoload_register(function ($className) { + $classPath = str_replace('\\', DIRECTORY_SEPARATOR, $className); + $filePath = FML_PATH . $classPath . '.php'; + if (file_exists($filePath)) { + // Load with FML namespace + require_once $filePath; + } + else if (FML_SIMPLE_CLASSES) { + // Load as simple class name + if (!function_exists('loadSimpleClass')) { + + function loadSimpleClass($className, $directory, $excludes, $baseNamespace) { + if ($dirHandle = opendir($directory)) { + $classParts = explode('\\', $className); + $simpleClassName = end($classParts); + $classFileName = $simpleClassName . '.php'; + while ($fileName = readdir($dirHandle)) { + if (in_array($fileName, $excludes)) { + continue; + } + $filePath = $directory . $fileName; + if (is_dir($filePath)) { + $subDirectory = $filePath . DIRECTORY_SEPARATOR; + $namespace = $baseNamespace . $fileName . '\\'; + $success = loadSimpleClass($className, $subDirectory, $excludes, $namespace); + if ($success) return true; + continue; + } + if (is_file($filePath)) { + if ($fileName == $classFileName) { + require_once $filePath; + class_alias($baseNamespace . $simpleClassName, $className, false); + return true; + } + continue; + } + } + closedir($dirHandle); + } + return false; + } } - }); + $excludes = array('.', '..'); + $baseNamespace = 'FML\\'; + loadSimpleClass($className, FML_PATH . 'FML' . DIRECTORY_SEPARATOR, $excludes, $baseNamespace); + } + }); +}