moved Libs out of core folder

This commit is contained in:
Steffen Schröder
2014-08-03 13:02:02 +02:00
parent 4d3dc92ad5
commit d517c2d561
180 changed files with 5 additions and 4 deletions

View File

@ -0,0 +1,266 @@
<?php
namespace FML\Elements;
/**
* Dictionary Element
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Dico {
/**
* Czech language
*
* @var string
*/
const LANG_CZECH = 'cz';
/**
* Danish language
*
* @var string
*/
const LANG_DANISH = 'da';
/**
* German language
*
* @var string
*/
const LANG_GERMAN = 'de';
/**
* English language
*
* @var string
*/
const LANG_ENGLISH = 'en';
/**
* Spanish language
*
* @var string
*/
const LANG_SPANISH = 'es';
/**
* French language
*
* @var string
*/
const LANG_FRENCH = 'fr';
/**
* Hungarian language
*
* @var string
*/
const LANG_HUNGARIAN = 'hu';
/**
* Italian language
*
* @var string
*/
const LANG_ITALIAN = 'it';
/**
* Japanese language
*
* @var string
*/
const LANG_JAPANESE = 'jp';
/**
* Korean language
*
* @var string
*/
const LANG_KOREAN = 'kr';
/**
* Norwegian language
*
* @var string
*/
const LANG_NORWEGIAN = 'nb';
/**
* Dutch language
*
* @var string
*/
const LANG_DUTCH = 'nl';
/**
* Polish language
*
* @var string
*/
const LANG_POLISH = 'pl';
/**
* Portuguese language
*
* @var string
*/
const LANG_PORTUGUESE = 'pt';
/**
* Brazilian Portuguese language
*
* @var string
*/
const LANG_BRAZILIAN_PORTUGUESE = 'pt_BR';
/**
* Romanian language
*
* @var string
*/
const LANG_ROMANIAN = 'ro';
/**
* Russian language
*
* @var string
*/
const LANG_RUSSIAN = 'ru';
/**
* Slovak language
*
* @var string
*/
const LANG_SLOVAK = 'sk';
/**
* Turkish language
*
* @var string
*/
const LANG_TURKISH = 'tr';
/**
* Chinese language
*
* @var string
*/
const LANG_CHINESE = 'zh';
/*
* Protected properties
*/
protected $tagName = 'dico';
protected $entries = array();
/**
* Create a new Dictionary object
*
* @return static
*/
public static function create() {
return new static();
}
/**
* Set the translatable entry for the specific language
*
* @param string $language Language id
* @param string $entryId Entry id
* @param string $entryValue Translated entry value
* @return static
*/
public function setEntry($language, $entryId, $entryValue) {
$language = (string)$language;
$entryId = (string)$entryId;
$entryValue = (string)$entryValue;
if (!isset($this->entries[$language]) && $entryValue) {
$this->entries[$language] = array();
}
if ($entryValue) {
$this->entries[$language][$entryId] = $entryValue;
} else {
if (isset($this->entries[$language][$entryId])) {
unset($this->entries[$language][$entryId]);
}
}
return $this;
}
/**
* Remove entries of the given id
*
* @param string $entryId Entry id that should be removed
* @param string $language (optional) Only remove entries of the given language
* @return static
*/
public function removeEntry($entryId, $language = null) {
$entryId = (string)$entryId;
if ($language) {
$language = (string)$language;
if (isset($this->entries[$language])) {
unset($this->entries[$language][$entryId]);
}
} else {
foreach ($this->entries as $language => $entries) {
if (isset($entries[$entryId])) {
unset($entries[$language][$entryId]);
}
}
}
return $this;
}
/**
* Remove entries of the given language
*
* @param string $language Language which entries should be removed
* @param string $entryId (optional) Only remove the given entry id
* @return static
*/
public function removeLanguage($language, $entryId = null) {
$language = (string)$language;
if (isset($this->entries[$language])) {
if ($entryId) {
$entryId = (string)$entryId;
unset($this->entries[$language][$entryId]);
} else {
unset($this->entries[$language]);
}
}
return $this;
}
/**
* Remove all entries from the Dictionary
*
* @return static
*/
public function removeEntries() {
$this->entries = array();
return $this;
}
/**
* Render the Dico XML element
*
* @param \DOMDocument $domDocument DOMDocument for which the Dico XML element should be rendered
* @return \DOMElement
*/
public function render(\DOMDocument $domDocument) {
$xmlElement = $domDocument->createElement($this->tagName);
foreach ($this->entries as $language => $entries) {
$languageElement = $domDocument->createElement('language');
$languageElement->setAttribute('id', $language);
foreach ($entries as $entryId => $entryValue) {
$entryElement = $domDocument->createElement($entryId, $entryValue);
$languageElement->appendChild($entryElement);
}
$xmlElement->appendChild($languageElement);
}
return $xmlElement;
}
}

View File

@ -0,0 +1,123 @@
<?php
namespace FML\Elements;
use FML\Types\BgColorable;
use FML\Types\Renderable;
use FML\Types\Styleable;
use FML\Types\TextFormatable;
/**
* Format Element
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Format implements BgColorable, Renderable, Styleable, TextFormatable {
/*
* Protected properties
*/
protected $tagName = 'format';
protected $bgColor = null;
protected $style = null;
protected $textSize = -1;
protected $textFont = null;
protected $textColor = null;
protected $focusAreaColor1 = null;
protected $focusAreaColor2 = null;
/**
* Create a new Format Element
*
* @return static
*/
public static function create() {
return new static();
}
/**
* @see \FML\Types\BgColorable::setBgColor()
*/
public function setBgColor($bgColor) {
$this->bgColor = (string)$bgColor;
return $this;
}
/**
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
$this->style = (string)$style;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextSize()
*/
public function setTextSize($textSize) {
$this->textSize = (int)$textSize;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextFont()
*/
public function setTextFont($textFont) {
$this->textFont = (string)$textFont;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setTextColor()
*/
public function setTextColor($textColor) {
$this->textColor = (string)$textColor;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaColor()
*/
public function setAreaColor($areaColor) {
$this->focusAreaColor1 = (string)$areaColor;
return $this;
}
/**
* @see \FML\Types\TextFormatable::setAreaFocusColor()
*/
public function setAreaFocusColor($areaFocusColor) {
$this->focusAreaColor2 = (string)$areaFocusColor;
return $this;
}
/**
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$formatXmlElement = $domDocument->createElement($this->tagName);
if ($this->bgColor) {
$formatXmlElement->setAttribute('bgcolor', $this->bgColor);
}
if ($this->style) {
$formatXmlElement->setAttribute('style', $this->style);
}
if ($this->textSize >= 0) {
$formatXmlElement->setAttribute('textsize', $this->textSize);
}
if ($this->textFont) {
$formatXmlElement->setAttribute('textfont', $this->textFont);
}
if ($this->textColor) {
$formatXmlElement->setAttribute('textcolor', $this->textColor);
}
if ($this->focusAreaColor1) {
$formatXmlElement->setAttribute('focusareacolor1', $this->focusAreaColor1);
}
if ($this->focusAreaColor2) {
$formatXmlElement->setAttribute('focusareacolor2', $this->focusAreaColor2);
}
return $formatXmlElement;
}
}

View File

@ -0,0 +1,112 @@
<?php
namespace FML\Elements;
use FML\Types\Container;
use FML\Types\Renderable;
use FML\UniqueID;
/**
* Class representing a Frame Model
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class FrameModel implements Container, Renderable {
/*
* Protected properties
*/
protected $tagName = 'framemodel';
protected $modelId = null;
/** @var Renderable[] $children */
protected $children = array();
/** @var Format $format */
protected $format = null;
/**
* Set Model id
*
* @param string $modelId Model id
* @return static
*/
public function setId($modelId) {
$this->modelId = (string)$modelId;
return $this;
}
/**
* Get Model id
*
* @return string
*/
public function getId() {
return $this->modelId;
}
/**
* Assign an id if necessary
*
* @return string
*/
public function checkId() {
if (!$this->modelId) {
$this->setId(UniqueID::create());
}
return $this;
}
/**
* @see \FML\Types\Container::add()
*/
public function add(Renderable $childElement) {
if (!in_array($childElement, $this->children, true)) {
array_push($this->children, $childElement);
}
return $this;
}
/**
* @see \FML\Types\Container::removeChildren()
*/
public function removeChildren() {
$this->children = array();
return $this;
}
/**
* @see \FML\Types\Container::setFormat()
*/
public function setFormat(Format $format) {
$this->format = $format;
return $this;
}
/**
* @see \FML\Types\Container::getFormat()
*/
public function getFormat($createIfEmpty = true) {
if (!$this->format && $createIfEmpty) {
$this->setFormat(new Format());
}
return $this->format;
}
/**
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$xmlElement = $domDocument->createElement($this->tagName);
$this->checkId();
$xmlElement->setAttribute('id', $this->getId());
if ($this->format) {
$formatXml = $this->format->render($domDocument);
$xmlElement->appendChild($formatXml);
}
foreach ($this->children as $child) {
$childElement = $child->render($domDocument);
$xmlElement->appendChild($childElement);
}
return $xmlElement;
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace FML\Elements;
use FML\Types\Renderable;
/**
* Include Element
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Including implements Renderable {
/*
* Protected properties
*/
protected $tagName = 'include';
protected $url = null;
/**
* Create a new Include object
*
* @param string $url (optional) Include url
* @return static
*/
public static function create($url = null) {
return new static($url);
}
/**
* Construct a new Include object
*
* @param string $url (optional) Include url
*/
public function __construct($url = null) {
if (!is_null($url)) {
$this->setUrl($url);
}
}
/**
* Set url
*
* @param string $url Include url
* @return static
*/
public function setUrl($url) {
$this->url = (string)$url;
return $this;
}
/**
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$xmlElement = $domDocument->createElement($this->tagName);
if ($this->url) {
$xmlElement->setAttribute('url', $this->url);
}
return $xmlElement;
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace FML\Elements;
use FML\Types\Renderable;
/**
* Music Element
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Music implements Renderable {
/*
* Protected properties
*/
protected $tagName = 'music';
protected $data = null;
/**
* Create a new Music object
*
* @param string $data (optional) Media url
* @return static
*/
public static function create($data = null) {
return new static($data);
}
/**
* Construct a new Music object
*
* @param string $data (optional) Media url
*/
public function __construct($data = null) {
if (!is_null($data)) {
$this->setData($data);
}
}
/**
* Set data url
*
* @param string $data Data url
* @return static
*/
public function setData($data) {
$this->data = (string)$data;
return $this;
}
/**
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$xmlElement = $domDocument->createElement($this->tagName);
if ($this->data) {
$xmlElement->setAttribute('data', $this->data);
}
return $xmlElement;
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace FML\Elements;
use FML\Types\Renderable;
/**
* Class representing a ManiaLink script tag with a simple script text
*
* @author steeffeen <mail@steeffeen.com>
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class SimpleScript implements Renderable {
/*
* Protected properties
*/
protected $tagName = 'script';
protected $text = null;
/**
* Create a new SimpleScript object
*
* @param string $text (optional) Script text
* @return static
*/
public static function create($text = null) {
return new static($text);
}
/**
* Construct a new SimpleScript object
*
* @param string $text (optional) Script text
*/
public function __construct($text = null) {
if (!is_null($text)) {
$this->setText($text);
}
}
/**
* Set script text
*
* @param string $text Complete script text
* @return static
*/
public function setText($text) {
$this->text = (string)$text;
return $this;
}
/**
* @see \FML\Types\Renderable::render()
*/
public function render(\DOMDocument $domDocument) {
$xmlElement = $domDocument->createElement($this->tagName);
if ($this->text) {
$scriptComment = $domDocument->createComment($this->text);
$xmlElement->appendChild($scriptComment);
}
return $xmlElement;
}
}