2013-11-10 03:07:45 +01:00
|
|
|
<?php
|
|
|
|
|
2013-11-12 15:48:25 +01:00
|
|
|
namespace ManiaControl\Manialinks;
|
2013-11-10 17:38:54 +01:00
|
|
|
|
2013-11-25 19:46:29 +01:00
|
|
|
require_once __DIR__ . '/../FML/autoload.php';
|
2013-11-25 00:02:07 +01:00
|
|
|
|
2013-11-10 03:07:45 +01:00
|
|
|
/**
|
|
|
|
* Manialink utility class
|
|
|
|
*
|
2013-11-10 17:38:54 +01:00
|
|
|
* @author steeffeen & kremsy
|
2013-11-10 03:07:45 +01:00
|
|
|
*/
|
2013-11-28 01:12:52 +01:00
|
|
|
abstract class ManialinkUtil {
|
2013-11-10 03:07:45 +01:00
|
|
|
|
2013-11-10 13:58:08 +01:00
|
|
|
/**
|
|
|
|
* Send the given manialink to players
|
|
|
|
*
|
2013-11-10 20:09:08 +01:00
|
|
|
* @param \IXR_ClientMulticall_Gbx $client
|
2013-11-10 13:58:08 +01:00
|
|
|
* @param string $manialink
|
2013-11-28 01:12:52 +01:00
|
|
|
* @param mixed $logins
|
2013-11-10 20:09:08 +01:00
|
|
|
* @param int $timeout
|
|
|
|
* @param bool $hideOnClick
|
2013-11-10 13:58:08 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2013-11-28 01:12:52 +01:00
|
|
|
public static function sendManialinkPage(\IXR_ClientMulticall_Gbx $client, $manialinkText, $logins = null, $timeout = 0,
|
2013-11-10 20:09:08 +01:00
|
|
|
$hideOnClick = false) {
|
2013-11-10 13:58:08 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-10 03:07:45 +01:00
|
|
|
/**
|
|
|
|
* Build new simple xml element
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $id
|
2013-11-10 20:09:08 +01:00
|
|
|
* @return \SimpleXMLElement
|
2013-11-10 03:07:45 +01:00
|
|
|
*/
|
|
|
|
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
|
2013-11-10 03:07:45 +01:00
|
|
|
* @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
|
2013-11-10 03:07:45 +01:00
|
|
|
* @param bool $translate
|
|
|
|
*/
|
|
|
|
public static function addTranslate(\SimpleXMLElement $xml, $translate = true) {
|
|
|
|
if (!property_exists($xml, 'translate')) {
|
|
|
|
$xml->addAttribute('translate', ($translate ? 1 : 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|