- subfolders for different classes
- Improved file and class naming - "handler"-> "listener" (callbacks, commands)
This commit is contained in:
31
application/core/Manialinks/ManialinkIdHandler.php
Normal file
31
application/core/Manialinks/ManialinkIdHandler.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
/**
|
||||
* Handler for manialink ids
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class ManialinkIdHandler {
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaLinkIdCount = 0;
|
||||
|
||||
/**
|
||||
* Reserve manialink ids
|
||||
*
|
||||
* @param int $count
|
||||
* @return array with manialink Ids
|
||||
*/
|
||||
public function reserveManiaLinkIds($count) {
|
||||
$mlIds = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
array_push($mlIds, ++$this->maniaLinkIdCount);
|
||||
}
|
||||
return $mlIds;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
91
application/core/Manialinks/ManialinkUtil.php
Normal file
91
application/core/Manialinks/ManialinkUtil.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
/**
|
||||
* Manialink utility class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class ManialinkUtil {
|
||||
|
||||
/**
|
||||
* Send the given manialink to players
|
||||
*
|
||||
* @param \IXR_ClientMulticall_Gbx $client
|
||||
* @param string $manialink
|
||||
* @param array $logins
|
||||
* @param int $timeout
|
||||
* @param bool $hideOnClick
|
||||
* @return bool
|
||||
*/
|
||||
public static function sendManialinkPage(\IXR_ClientMulticall_Gbx $client, $manialinkText, array $logins = null, $timeout = 0,
|
||||
$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
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user