TrackManiaControl/application/core/Manialinks/ManialinkUtil.php

94 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace ManiaControl\Manialinks;
2013-11-10 17:38:54 +01:00
require_once __DIR__ . '/../FML/autoload.php';
/**
* Manialink utility class
*
2013-11-10 17:38:54 +01:00
* @author steeffeen & kremsy
*/
abstract class ManialinkUtil {
/**
* Send the given manialink to players
*
2013-11-10 20:09:08 +01:00
* @param \IXR_ClientMulticall_Gbx $client
* @param string $manialink
* @param mixed $logins
2013-11-10 20:09:08 +01:00
* @param int $timeout
* @param bool $hideOnClick
* @return bool
*/
public static function sendManialinkPage(\IXR_ClientMulticall_Gbx $client, $manialinkText, $logins = null, $timeout = 0,
2013-11-10 20:09:08 +01:00
$hideOnClick = false) {
if (!$client || !$manialinkText) {
return false;
}
if (!$logins) {
return $client->query('SendDisplayManialinkPage', $manialinkText, $timeout, $hideOnClick);
}
if (is_string($logins)) {
return $client->query('SendDisplayManialinkPageToLogin', $logins, $manialinkText, $timeout, $hideOnClick);
}
if (is_array($logins)) {
$success = true;
foreach ($logins as $login) {
$subSuccess = $client->query('SendDisplayManialinkPageToLogin', $login, $manialinkText, $timeout, $hideOnClick);
if (!$subSuccess) {
$success = false;
}
}
return $success;
}
return false;
}
/**
* Build new simple xml element
*
* @param string $name
* @param string $id
2013-11-10 20:09:08 +01:00
* @return \SimpleXMLElement
*/
public static function newManialinkXml($id = null) {
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><manialink/>');
$xml->addAttribute('version', '1');
if ($id) {
$xml->addAttribute('id', $id);
}
return $xml;
}
/**
* Add alignment attributes to an xml element
*
2013-11-10 20:09:08 +01:00
* @param \SimpleXMLElement $xml
* @param string $halign
* @param string $valign
*/
public static function addAlignment(\SimpleXMLElement $xml, $halign = 'center', $valign = 'center2') {
if (!property_exists($xml, 'halign')) {
$xml->addAttribute('halign', $halign);
}
if (!property_exists($xml, 'valign')) {
$xml->addAttribute('valign', $valign);
}
}
/**
* Add translate attribute to an xml element
*
2013-11-10 20:09:08 +01:00
* @param \SimpleXMLElement $xml
* @param bool $translate
*/
public static function addTranslate(\SimpleXMLElement $xml, $translate = true) {
if (!property_exists($xml, 'translate')) {
$xml->addAttribute('translate', ($translate ? 1 : 0));
}
}
}
?>