2014-01-12 00:51:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FML;
|
|
|
|
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\ManiaCode\AddBuddy;
|
|
|
|
use FML\ManiaCode\AddFavorite;
|
2014-01-12 00:51:46 +01:00
|
|
|
use FML\ManiaCode\Element;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\ManiaCode\GetSkin;
|
|
|
|
use FML\ManiaCode\Go_To;
|
2014-05-14 23:24:00 +02:00
|
|
|
use FML\ManiaCode\InstallMacroblock;
|
2014-01-12 00:51:46 +01:00
|
|
|
use FML\ManiaCode\InstallMap;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\ManiaCode\InstallPack;
|
2014-01-12 00:51:46 +01:00
|
|
|
use FML\ManiaCode\InstallReplay;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\ManiaCode\InstallScript;
|
2014-01-12 00:51:46 +01:00
|
|
|
use FML\ManiaCode\InstallSkin;
|
|
|
|
use FML\ManiaCode\JoinServer;
|
2014-01-19 19:30:21 +01:00
|
|
|
use FML\ManiaCode\PlayMap;
|
|
|
|
use FML\ManiaCode\PlayReplay;
|
|
|
|
use FML\ManiaCode\ShowMessage;
|
|
|
|
use FML\ManiaCode\ViewReplay;
|
2014-01-12 00:51:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class representing a ManiaCode
|
|
|
|
*
|
2014-05-20 15:44:45 +02:00
|
|
|
* @author steeffeen <mail@steeffeen.com>
|
2014-04-13 18:21:40 +02:00
|
|
|
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
|
2014-05-14 23:24:00 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
class ManiaCode {
|
2014-01-21 20:30:40 +01:00
|
|
|
/*
|
2014-06-21 03:18:21 +02:00
|
|
|
* Protected properties
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
protected $encoding = 'utf-8';
|
|
|
|
protected $tagName = 'maniacode';
|
|
|
|
protected $noConfirmation = null;
|
2014-06-21 03:18:21 +02:00
|
|
|
/** @var Element[] $elements */
|
2014-01-12 00:51:46 +01:00
|
|
|
protected $elements = array();
|
|
|
|
|
2014-01-19 19:30:21 +01:00
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Create a new ManiaCode object
|
2014-01-19 19:30:21 +01:00
|
|
|
*
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-19 19:30:21 +01:00
|
|
|
*/
|
|
|
|
public static function create() {
|
2014-06-21 03:18:21 +02:00
|
|
|
return new static();
|
2014-01-19 19:30:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Set XML encoding
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $encoding XML encoding
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function setXmlEncoding($encoding) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$this->encoding = (string)$encoding;
|
2014-01-12 00:51:46 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Disable the showing of the confirmation at the end of the ManiaCode
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param bool $disable Whether the confirmation should be shown
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function disableConfirmation($disable) {
|
|
|
|
$this->noConfirmation = ($disable ? 1 : 0);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Show a message
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $message Message text
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addShowMessage($message) {
|
|
|
|
$messageElement = new ShowMessage($message);
|
|
|
|
$this->addElement($messageElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-15 15:47:57 +02:00
|
|
|
/**
|
|
|
|
* Install a Macroblock
|
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Macroblock name
|
|
|
|
* @param string $file Macroblock file
|
|
|
|
* @param string $url Macroblock url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-04-15 15:47:57 +02:00
|
|
|
*/
|
|
|
|
public function addInstallMacroblock($name, $file, $url) {
|
|
|
|
$macroblockElement = new InstallMacroblock($name, $file, $url);
|
|
|
|
$this->addElement($macroblockElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-01-12 00:51:46 +01:00
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Install a map
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Map name
|
|
|
|
* @param string $url Map url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addInstallMap($name, $url) {
|
|
|
|
$mapElement = new InstallMap($name, $url);
|
|
|
|
$this->addElement($mapElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Play a map
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Map name
|
|
|
|
* @param string $url Map url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addPlayMap($name, $url) {
|
|
|
|
$mapElement = new PlayMap($name, $url);
|
|
|
|
$this->addElement($mapElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Install a replay
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Replay name
|
|
|
|
* @param string $url Replay url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addInstallReplay($name, $url) {
|
|
|
|
$replayElement = new InstallReplay($name, $url);
|
|
|
|
$this->addElement($replayElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* View a replay
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Replay name
|
|
|
|
* @param string $url Replay url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addViewReplay($name, $url) {
|
|
|
|
$replayElement = new ViewReplay($name, $url);
|
|
|
|
$this->addElement($replayElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Play a replay
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Replay name
|
|
|
|
* @param string $url Replay url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addPlayReplay($name, $url) {
|
|
|
|
$replayElement = new PlayReplay($name, $url);
|
|
|
|
$this->addElement($replayElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Install a skin
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Skin name
|
|
|
|
* @param string $file Skin file
|
|
|
|
* @param string $url Skin url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addInstallSkin($name, $file, $url) {
|
|
|
|
$skinElement = new InstallSkin($name, $file, $url);
|
|
|
|
$this->addElement($skinElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Get a skin
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Skin name
|
|
|
|
* @param string $file Skin file
|
|
|
|
* @param string $url Skin url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addGetSkin($name, $file, $url) {
|
|
|
|
$skinElement = new GetSkin($name, $file, $url);
|
|
|
|
$this->addElement($skinElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Add a buddy
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $login Buddy login
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addAddBuddy($login) {
|
|
|
|
$buddyElement = new AddBuddy($login);
|
|
|
|
$this->addElement($buddyElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Go to a link
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $link Goto link
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addGoto($link) {
|
|
|
|
$gotoElement = new Go_To($link);
|
|
|
|
$this->addElement($gotoElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Join a server
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $login Server login
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addJoinServer($login) {
|
|
|
|
$serverElement = new JoinServer($login);
|
|
|
|
$this->addElement($serverElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Add a server as favorite
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $login Server login
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addAddFavorite($login) {
|
|
|
|
$favoriteElement = new AddFavorite($login);
|
|
|
|
$this->addElement($favoriteElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Install a script
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Script name
|
|
|
|
* @param string $file Script file
|
|
|
|
* @param string $url Script url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addInstallScript($name, $file, $url) {
|
|
|
|
$scriptElement = new InstallScript($name, $file, $url);
|
|
|
|
$this->addElement($scriptElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Install a title pack
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param string $name Pack name
|
|
|
|
* @param string $file Pack file
|
|
|
|
* @param string $url Pack url
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addInstallPack($name, $file, $url) {
|
|
|
|
$packElement = new InstallPack($name, $file, $url);
|
|
|
|
$this->addElement($packElement);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Add a ManiaCode element
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param Element $element Element to add
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function addElement(Element $element) {
|
|
|
|
array_push($this->elements, $element);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Remove all elements from the ManiaCode
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-07-03 22:34:47 +02:00
|
|
|
* @return static
|
2014-01-12 00:51:46 +01:00
|
|
|
*/
|
|
|
|
public function removeElements() {
|
|
|
|
$this->elements = array();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Render the XML document
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
2014-06-21 03:18:21 +02:00
|
|
|
* @param bool $echo (optional) Whether the XML text should be echoed and the Content-Type header should be set
|
2014-01-12 00:51:46 +01:00
|
|
|
* @return \DOMDocument
|
|
|
|
*/
|
|
|
|
public function render($echo = false) {
|
2014-05-14 23:24:00 +02:00
|
|
|
$domDocument = new \DOMDocument('1.0', $this->encoding);
|
2014-01-19 19:30:21 +01:00
|
|
|
$domDocument->xmlStandalone = true;
|
2014-05-14 23:24:00 +02:00
|
|
|
$maniaCode = $domDocument->createElement($this->tagName);
|
2014-01-12 00:51:46 +01:00
|
|
|
$domDocument->appendChild($maniaCode);
|
|
|
|
if ($this->noConfirmation) {
|
|
|
|
$maniaCode->setAttribute('noconfirmation', $this->noConfirmation);
|
|
|
|
}
|
|
|
|
foreach ($this->elements as $element) {
|
|
|
|
$xmlElement = $element->render($domDocument);
|
|
|
|
$maniaCode->appendChild($xmlElement);
|
|
|
|
}
|
|
|
|
if ($echo) {
|
2014-01-19 19:30:21 +01:00
|
|
|
header('Content-Type: application/xml; charset=utf-8;');
|
2014-01-12 00:51:46 +01:00
|
|
|
echo $domDocument->saveXML();
|
|
|
|
}
|
|
|
|
return $domDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-21 03:18:21 +02:00
|
|
|
* Get string representation
|
2014-01-12 00:51:46 +01:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function __toString() {
|
2014-06-21 03:18:21 +02:00
|
|
|
return $this->render()->saveXML();
|
2014-01-12 00:51:46 +01:00
|
|
|
}
|
|
|
|
}
|