- deleted test plugin
- added FML Library
This commit is contained in:
		
							
								
								
									
										206
									
								
								application/FML/Script/Script.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								application/FML/Script/Script.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,206 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script; | ||||
|  | ||||
| use FML\Controls\Control; | ||||
| use FML\Script\Sections\Constants; | ||||
| use FML\Script\Sections\Functions; | ||||
| use FML\Script\Sections\Globals; | ||||
| use FML\Script\Sections\Includes; | ||||
| use FML\Script\Sections\Labels; | ||||
|  | ||||
| /** | ||||
|  * Class reprenting the manialink script | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| class Script { | ||||
| 	/** | ||||
| 	 * Protected properties | ||||
| 	 */ | ||||
| 	protected $features = array(); | ||||
|  | ||||
| 	/** | ||||
| 	 * Add a script feature | ||||
| 	 * | ||||
| 	 * @param ScriptFeature $scriptFeature        	 | ||||
| 	 * @return \FML\Script\Script | ||||
| 	 */ | ||||
| 	public function addFeature(ScriptFeature $scriptFeature) { | ||||
| 		array_push($this->features, $scriptFeature); | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Remove all script features | ||||
| 	 * | ||||
| 	 * @return \FML\Script\Script | ||||
| 	 */ | ||||
| 	public function removeFeatures() { | ||||
| 		$this->features = array(); | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Create the script xml tag | ||||
| 	 * | ||||
| 	 * @param \DOMDocument $domDocument        	 | ||||
| 	 * @return DOMElement | ||||
| 	 */ | ||||
| 	public function render(\DOMDocument $domDocument) { | ||||
| 		$scriptXml = $domDocument->createElement('script'); | ||||
| 		$scriptText = $this->buildScriptText(); | ||||
| 		$scriptComment = $domDocument->createComment($scriptText); | ||||
| 		$scriptXml->appendChild($scriptComment); | ||||
| 		return $scriptXml; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Build the complete script text based on all script items | ||||
| 	 * | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function buildScriptText() { | ||||
| 		$scriptText = ""; | ||||
| 		$scriptText = $this->addIncludesPart($scriptText); | ||||
| 		$scriptText = $this->addConstantsPart($scriptText); | ||||
| 		$scriptText = $this->addLabelsPart($scriptText); | ||||
| 		$scriptText = $this->addFunctionsPart($scriptText); | ||||
| 		$scriptText = $this->addMainPart($scriptText); | ||||
| 		return $scriptText; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Add the includes to the script | ||||
| 	 * | ||||
| 	 * @param string $scriptText        	 | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function addIncludesPart($scriptText) { | ||||
| 		$includes = array(); | ||||
| 		foreach ($this->features as $feature) { | ||||
| 			if (!($feature instanceof Includes)) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			$featureIncludes = $feature->getIncludes(); | ||||
| 			foreach ($featureIncludes as $namespace => $fileName) { | ||||
| 				$includes[$namespace] = $fileName; | ||||
| 			} | ||||
| 		} | ||||
| 		$includesPart = PHP_EOL; | ||||
| 		foreach ($includes as $namespace => $fileName) { | ||||
| 			$includesPart .= "#Include \"{$fileName}\" as {$namespace}" . PHP_EOL; | ||||
| 		} | ||||
| 		return $scriptText . $includesPart; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Add the declared constants to the script | ||||
| 	 * | ||||
| 	 * @param string $scriptText        	 | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function addConstantsPart($scriptText) { | ||||
| 		$constants = array(); | ||||
| 		foreach ($this->features as $feature) { | ||||
| 			if (!($feature instanceof Constants)) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			$featureConstants = $feature->getConstants(); | ||||
| 			foreach ($featureConstants as $name => $value) { | ||||
| 				$constants[$name] = $value; | ||||
| 			} | ||||
| 		} | ||||
| 		$constantsPart = PHP_EOL; | ||||
| 		foreach ($constants as $name => $value) { | ||||
| 			$constantsPart .= "#Const {$name} {$value}" . PHP_EOL; | ||||
| 		} | ||||
| 		return $scriptText . $constantsPart; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Add the declared global variables to the script | ||||
| 	 * | ||||
| 	 * @param string $scriptText        	 | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function addGlobalsPart($scriptText) { | ||||
| 		$globals = array(); | ||||
| 		foreach ($this->features as $feature) { | ||||
| 			if (!($feature instanceof Globals)) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			$featureGlobals = $feature->getGlobals(); | ||||
| 			foreach ($featureGlobals as $name => $type) { | ||||
| 				$globals[$name] = $type; | ||||
| 			} | ||||
| 		} | ||||
| 		$globalsPart = PHP_EOL; | ||||
| 		foreach ($globals as $name => $type) { | ||||
| 			$globalsPart .= "declare {$type} {$name};" . PHP_EOL; | ||||
| 		} | ||||
| 		return $scriptText . $globalsPart; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Add the implemented labels to the script | ||||
| 	 * | ||||
| 	 * @param string $scriptText        	 | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function addLabelsPart($scriptText) { | ||||
| 		$labels = array(); | ||||
| 		foreach ($this->features as $feature) { | ||||
| 			if (!($feature instanceof Labels)) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			$featureLabels = $feature->getLabels(); | ||||
| 			foreach ($featureLabels as $name => $implementation) { | ||||
| 				$label = array($name, $implementation); | ||||
| 				array_push($labels, $label); | ||||
| 			} | ||||
| 		} | ||||
| 		$labelsPart = PHP_EOL; | ||||
| 		foreach ($labels as $label) { | ||||
| 			$labelsPart .= '***' . $label[0] . '***' . PHP_EOL . '***' . PHP_EOL . $label[1] . PHP_EOL . '***' . PHP_EOL; | ||||
| 		} | ||||
| 		return $scriptText . $labelsPart; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Add the declared functions to the script | ||||
| 	 * | ||||
| 	 * @param string $scriptText        	 | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function addFunctionsPart($scriptText) { | ||||
| 		$functions = array(); | ||||
| 		foreach ($this->features as $feature) { | ||||
| 			if (!($feature instanceof Functions)) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			$featureFunctions = $feature->getFunctions(); | ||||
| 			foreach ($featureFunctions as $signature => $implementation) { | ||||
| 				$functions[$signature] = $implementation; | ||||
| 			} | ||||
| 		} | ||||
| 		$functionsPart = PHP_EOL; | ||||
| 		foreach ($functions as $signature => $implementation) { | ||||
| 			$functionsPart .= $signature . '{' . PHP_EOL . $implementation . PHP_EOL . '}' . PHP_EOL; | ||||
| 		} | ||||
| 		return $scriptText . $functionsPart; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Add the main function to the script | ||||
| 	 * | ||||
| 	 * @param string $scriptText        	 | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	private function addMainPart($scriptText) { | ||||
| 		$mainPart = file_get_contents(__DIR__ . '/Templates/Main.txt'); | ||||
| 		return $scriptText . $mainPart; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										13
									
								
								application/FML/Script/ScriptFeature.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								application/FML/Script/ScriptFeature.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script; | ||||
|  | ||||
| /** | ||||
|  * Interface representing a script feature | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| interface ScriptFeature { | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										18
									
								
								application/FML/Script/Sections/Constants.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								application/FML/Script/Sections/Constants.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Sections; | ||||
|  | ||||
| /** | ||||
|  * Script feature using constants | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| interface Constants { | ||||
|  | ||||
| 	/** | ||||
| 	 * Return array of constant values with names as keys | ||||
| 	 */ | ||||
| 	public function getConstants(); | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										20
									
								
								application/FML/Script/Sections/Functions.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								application/FML/Script/Sections/Functions.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Sections; | ||||
|  | ||||
| /** | ||||
|  * Script feature using functions | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| interface Functions { | ||||
|  | ||||
| 	/** | ||||
| 	 * Return array of function implementations and signatures as keys | ||||
| 	 * | ||||
| 	 * @return array | ||||
| 	 */ | ||||
| 	public function getFunctions(); | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										20
									
								
								application/FML/Script/Sections/Globals.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								application/FML/Script/Sections/Globals.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Sections; | ||||
|  | ||||
| /** | ||||
|  * Script feature using globals | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| interface Globals { | ||||
|  | ||||
| 	/** | ||||
| 	 * Return array with global variable types with variable names as keys | ||||
| 	 * | ||||
| 	 * @return array | ||||
| 	 */ | ||||
| 	public function getGlobals(); | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										20
									
								
								application/FML/Script/Sections/Includes.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								application/FML/Script/Sections/Includes.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Sections; | ||||
|  | ||||
| /** | ||||
|  * Script feature using includes | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| interface Includes { | ||||
|  | ||||
| 	/** | ||||
| 	 * Return array of included files with namespaces as keys | ||||
| 	 * | ||||
| 	 * @return array | ||||
| 	 */ | ||||
| 	public function getIncludes(); | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										30
									
								
								application/FML/Script/Sections/Labels.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								application/FML/Script/Sections/Labels.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script\Sections; | ||||
|  | ||||
| /** | ||||
|  * Script feature using labels | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| interface Labels { | ||||
| 	/** | ||||
| 	 * Constants | ||||
| 	 */ | ||||
| 	const ENTRYSUBMIT = 'EntrySubmit'; | ||||
| 	const KEYPRESS = 'KeyPress'; | ||||
| 	const LOOP = 'Loop'; | ||||
| 	const MOUSECLICK = 'MouseClick'; | ||||
| 	const MOUSEOUT = 'MouseOut'; | ||||
| 	const MOUSEOVER = 'MouseOver'; | ||||
| 	const ONINIT = 'OnInit'; | ||||
|  | ||||
| 	/** | ||||
| 	 * Return array of label implementations with label names as keys | ||||
| 	 * | ||||
| 	 * @return array | ||||
| 	 */ | ||||
| 	public function getLabels(); | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										27
									
								
								application/FML/Script/Templates/Main.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								application/FML/Script/Templates/Main.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
|  | ||||
| main() { | ||||
| 	+++OnInit+++ | ||||
| 	while (True) { | ||||
| 		yield; | ||||
| 		foreach (Event in PendingEvents) { | ||||
| 			switch (Event.Type) { | ||||
| 				case CMlEvent::Type::EntrySubmit: { | ||||
| 					+++EntrySubmit+++ | ||||
| 				} | ||||
| 				case CMlEvent::Type::KeyPress: { | ||||
| 					+++KeyPress+++ | ||||
| 				} | ||||
| 				case CMlEvent::Type::MouseClick: { | ||||
| 					+++MouseClick+++ | ||||
| 				} | ||||
| 				case CMlEvent::Type::MouseOut: { | ||||
| 					+++MouseOut+++ | ||||
| 				} | ||||
| 				case CMlEvent::Type::MouseOver: { | ||||
| 					+++MouseOver+++ | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		+++Loop+++ | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										6
									
								
								application/FML/Script/Templates/TooltipMouseOut.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								application/FML/Script/Templates/TooltipMouseOut.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| if (C_FML_TooltipIds.existskey(Event.ControlId)) { | ||||
| 	declare TooltipControl <=> Page.GetFirstChild(C_FML_TooltipIds[Event.ControlId]); | ||||
| 	if (TooltipControl != Null) { | ||||
| 		TooltipControl.Hide(); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										6
									
								
								application/FML/Script/Templates/TooltipMouseOver.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								application/FML/Script/Templates/TooltipMouseOver.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| if (C_FML_TooltipIds.existskey(Event.ControlId)) { | ||||
| 	declare TooltipControl <=> Page.GetFirstChild(C_FML_TooltipIds[Event.ControlId]); | ||||
| 	if (TooltipControl != Null) { | ||||
| 		TooltipControl.Show(); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										71
									
								
								application/FML/Script/Tooltips.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								application/FML/Script/Tooltips.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| <?php | ||||
|  | ||||
| namespace FML\Script; | ||||
|  | ||||
| use FML\Controls\Control; | ||||
| use FML\Script\Sections\Constants; | ||||
| use FML\Script\Sections\Labels; | ||||
|  | ||||
| /** | ||||
|  * ScriptFeature class offering tooltip behaviors | ||||
|  * | ||||
|  * @author steeffeen | ||||
|  */ | ||||
| class Tooltips implements Constants, Labels, ScriptFeature { | ||||
| 	/** | ||||
| 	 * Constants | ||||
| 	 */ | ||||
| 	const C_TOOLTIPIDS = 'C_FML_TooltipIds'; | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Protected properties | ||||
| 	 */ | ||||
| 	protected $tooltips = array(); | ||||
|  | ||||
| 	/** | ||||
| 	 * Add a tooltip behavior showing the tooltipControl while hovering over the hoverControl | ||||
| 	 * | ||||
| 	 * @param Control $hoverControl        	 | ||||
| 	 * @param Control $tooltipControl        	 | ||||
| 	 * @return \FML\Script\Tooltips | ||||
| 	 */ | ||||
| 	public function add(Control $hoverControl, Control $tooltipControl) { | ||||
| 		$hoverControl->assignId(); | ||||
| 		$tooltipControl->assignId(); | ||||
| 		$this->tooltips[$hoverControl->getId()] = $tooltipControl->getId(); | ||||
| 		return $this; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * | ||||
| 	 * @see \FML\Script\Sections\Constants::getConstants() | ||||
| 	 */ | ||||
| 	public function getConstants() { | ||||
| 		$constant = '['; | ||||
| 		foreach ($this->tooltips as $hoverId => $tooltipId) { | ||||
| 			$constant .= '"' . $hoverId . '" => "' . $tooltipId . '"'; | ||||
| 			if ($index < count($this->tooltips) - 1) { | ||||
| 				$constant .= ','; | ||||
| 			} | ||||
| 		} | ||||
| 		$constant .= ']'; | ||||
| 		$constants = array(); | ||||
| 		$constants[self::C_TOOLTIPIDS] = $constant; | ||||
| 		return $constants; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * | ||||
| 	 * @see \FML\Script\Sections\Labels::getLabels() | ||||
| 	 */ | ||||
| 	public function getLabels() { | ||||
| 		$labels = array(); | ||||
| 		$labelMouseOut = file_get_contents(__DIR__ . '/Templates/TooltipMouseOut.txt'); | ||||
| 		$labels[Labels::MOUSEOUT] = $labelMouseOut; | ||||
| 		$labelMouseOver = file_get_contents(__DIR__ . '/Templates/TooltipMouseOver.txt'); | ||||
| 		$labels[Labels::MOUSEOVER] = $labelMouseOver; | ||||
| 		return $labels; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| ?> | ||||
		Reference in New Issue
	
	Block a user