<?php
/**
* remoteCP 4
* ütf-8 release
*
* @package remoteCP
* @author hal.sascha
* @copyright (c) 2006-2008
* @version 4.0.2.7
*/
define('ML_STATIC' , 3);
define('ML_MAXIMIZED', 2);
define('ML_MINIMIZED', 1);
define('ML_CLOSED' , 0);
class rcp_maniafwk
{
public $hidden;
public $windows;
public $httppath;
public $time;
public $colors;
private $customui;
public function __construct($httppath, $time, $colors)
{
$this->hidden = false;
$this->windows = array();
$this->colors = $colors;
$this->httppath = $httppath;
$this->updateTime();
$this->customui = array(
'notice' => 'true',
'challenge_info' => 'true',
'chat' => 'true',
'checkpoint_list' => 'true',
'round_scores' => 'true',
'scoretable' => 'true',
'global' => 'true'
);
}
public function __destruct()
{
foreach($this->windows AS $key => $window)
{
$this->windows[$key]->__destruct();
$this->windows[$key] = NULL;
unset($this->windows[$key]);
}
}
/**
* Updates framework time
*
* @author hal.sascha
*/
public function updateTime()
{
$this->time = time();
}
/**
* Returns the xml of the whole framework
*
* @author hal.sascha
*/
public function getXml()
{
if($this->hidden)
{
return false;
}
if(empty($this->windows))
{
return false;
}
$this->updateTime();
$body = '';
foreach($this->windows AS $key => $window)
{
$xml = $window->getXml();
if($xml)
{
$body .= $xml;
}
}
if($body) return "<?xml version='1.0' encoding='utf-8' ?><manialinks>".$this->parseColors($body).$this->getCustomUi()."</manialinks>";
return false;
}
/**
* Adds a new Window to the framework
*
* This method will return a window-object if successfull
* @param string $name
* @param string $title
* @param int $posx
* @param int $posy
* @param int $width
* @author hal.sascha
*/
public function addWindow($name, $title, $posx, $posy, $width)
{
if(!array_key_exists($name, $this->windows))
{
$this->windows[$name] = new rcp_maniawindow($this, count($this->windows)+1, $name, $title, $posx, $posy, $width);
return $this->getWindow($name);
}
return false;
}
/**
* Returns a window-object for the specified windowname
*
* @param string $name
* @author hal.sascha
*/
public function getWindow($name)
{
if(array_key_exists($name, $this->windows))
{
if(is_object($this->windows[$name]))
{
return $this->windows[$name];
}
}
return false;
}
/**
* Gets an array of callbacks if the submitted action was available
*
* @param int $action
* @author hal.sascha
*/
public function getAction($action)
{
if(empty($this->windows))
{
return false;
}
foreach($this->windows AS $key => $window)
{
$result = $window->getAction($action);
if($result)
{
$window->Close(true);
return $result;
}
}
return false;
}
/**
* Closes all windows respecting it's closestatus
*
* If $id is specified the window with this id will be remain as open
* @param int $id
* @author hal.sascha
*/
public function closeWindows($id)
{
if(!empty($this->windows))
{
foreach($this->windows AS $key => $window)
{
if($window->id != $id && $window->status == ML_MAXIMIZED)
{
$window->Close();
}
}
}
}
/**
* Changes the status of the tm custom_ui
*
* @param string $element
* @param boolean $value
*/
public function setCustomUi($element, $value = true)
{
if(!array_key_exists($element, $this->customui)) return false;
$this->customui[$element] = $value ? 'true' : 'false';
return true;
}
/**
* Returns xml for the tm custom_ui
*
*/
public function getCustomUi()
{
return "<custom_ui>
<notice visible='{$this->customui['notice']}'/>
<challenge_info visible='{$this->customui['challenge_info']}'/>
<chat visible='{$this->customui['chat']}'/>
<checkpoint_list visible='{$this->customui['checkpoint_list']}'/>
<round_scores visible='{$this->customui['round_scores']}'/>
<scoretable visible='{$this->customui['scoretable']}'/>
<global visible='{$this->customui['global']}'/>
</custom_ui>";
}
/**
* Parses all framework related colors
*
* @param string $string
* @author hal.sascha
*/
private function parseColors($string)
{
$string = str_replace('!df!', (string) $this->colors->chat->default, $string);
$string = str_replace('!hl!', (string) $this->colors->chat->highlight, $string);
$string = str_replace('!si!', (string) $this->colors->chat->subitem, $string);
$string = str_replace('!fhl!', (string) $this->colors->ml->fonts->highlight, $string);
$string = str_replace('!fsi!', (string) $this->colors->ml->fonts->subitem, $string);
return $string;
}
}
class rcp_maniawindow
{
private $base;
public $id;
public $name;
public $status;
private $title;
private $posx;
private $posy;
private $width;
private $margin;
private $actions;
private $header;
private $bg;
private $static;
private $close;
private $timeout;
private $timeoutt;
private $options;
private $icon;
private $rendered;
private $lheight;
private $frames;
private $cframe;
private $cline;
private $styleregions;
public function __construct(&$base, $id, $name, $title, $posx, $posy, $width)
{
$this->base =& $base;
$this->id = $id;
$this->name = $name;
$this->title = $title;
$this->posx = $posx;
$this->posy = $posy;
$this->width = $width;
$this->margin = 0.5;
$this->frames = NULL;
$this->cframe = 0;
$this->cline = 0;
$this->styleregions = array(
'label' => array('halign', 'valign', 'textid', 'url', 'autonewline', 'textcolor', 'textsize'),
'quad' => array('bgcolor', 'image', 'imagefocus', 'style', 'substyle', 'url', 'manialink', 'maniazone', 'addplayerid'),
'entry' => array('textsize', 'halign', 'valign', 'name', 'default'),
'fileentry' => array('textsize', 'halign', 'valign', 'name', 'default'),
'audio' => array('data', 'play', 'looping'),
'music' => array('data'),
'include' => array('url')
);
// Default options
$this->status = ML_CLOSED;
$this->icon = 'Forever';
$this->actions = array();
$this->header = true;
$this->bg = 'main';
$this->static = false;
$this->close = true;
$this->timeout = false;
$this->timeoutt = false;
$this->rendered = true;
$this->options = array('icon', 'title', 'timeout', 'static', 'close', 'header', 'bg', 'width', 'posx', 'posy', 'lineheight');
$this->lheight = 0;
$this->lineheight = 3;
}
public function __destruct()
{
$this->base = NULL;
unset($this->base);
}
/**
* Changes the specified window option to a new value
*
* It's not possible to add new window options with this function
* @param string $option
* @param mixed $value
* @author hal.sascha
*/
public function setOption($option, $value)
{
if(in_array($option, $this->options) && isset($this->{$option}))
{
$this->{$option} = $value;
return true;
}
return false;
}
/**
* Refreshes the window
*
* @author hal.sascha
*/
public function Refresh()
{
//mark as "has to be rendered" oO
$this->rendered = false;
//window is static (possibly with timeout) or maximized
if($this->static || $this->timeout)
{
$this->setStatus(ML_STATIC);
}
else
{
$this->setStatus(ML_MAXIMIZED);
}
//Timeout time
$this->timeoutt = $this->timeout ? $this->base->time + $this->timeout : false;
//Close other window(s)
if($this->status == ML_MAXIMIZED)
{
$this->base->closeWindows($this->id);
}
}
/**
* Resets and refreshes the window
*
* @author hal.sascha
*/
public function Reset()
{
$this->xml = '';
$this->frames = NULL;
$this->frames = array();
$this->cframe = 0;
$this->cline = 0;
$this->Refresh();
}
/**
* Sets the status of the window
*
* @author hal.sascha
*/
private function setStatus($status)
{
$this->status = $status;
}
/**
* Checks the window for timeout
*
* @author hal.sascha
*/
private function getTimeout()
{
if(!$this->timeout || !$this->timeoutt) return false;
return ($this->timeoutt < $this->base->time) ? true : false;
}
/**
* Returns an array of actions or executes the default closeaction
*
* @author hal.sascha
*/
public function getAction($action)
{
if(array_key_exists($action, $this->actions))
{
if($this->actions[$action]['call'] == 'on'.$this->name.'Close')
{
return $this->Close();
}
else
{
return $this->actions[$action];
}
}
return false;
}
/**
* Creates a new unique actionid
*
* @author hal.sascha
*/
private function createActionId()
{
return $this->id.count($this->actions);
}
/**
* Flags the window as closed
*
* This window will respect the close-option.
* @param boolean $behavior
* @author hal.sascha
*/
public function Close($behavior = false)
{
if($behavior && $this->close || !$behavior)
{
$this->timeoutt = false;
$this->rendered = false;
$this->setStatus(ML_MINIMIZED);
return true;
}
return false;
}
/**
* Returns the xml for this window
*
* @author hal.sascha
*/
public function getXml()
{
if($this->rendered)
{
if($this->getTimeout())
{
$this->Close();
}
else
{
return false;
}
}
if($this->status == ML_CLOSED)
{
return false;
}
elseif($this->status == ML_MINIMIZED)
{
$this->setStatus(ML_CLOSED);
$this->rendered = true;
return "<manialink id='{$this->id}'></manialink>";
}
//Send predefined xml
if($this->xml)
{
$this->rendered = true;
return $this->xml;
}
//Send generated xml
if(empty($this->frames))
{
$this->Close();
return false;
}
$this->xml = "<manialink id='{$this->id}'><type>default</type>";
$this->xml .= "<frame posn='{$this->posx} {$this->posy} 0'><format". $this->applyStyles('format') ." />";
$this->xml .= $this->getHeader();
$this->xml .= $this->getFrames();
$this->xml .= $this->getBg();
$this->xml .= "</frame>";
$this->xml .= "</manialink>";
//Parse actions
$this->actions = array();
$matches = array();
preg_match_all('!\{ca:(.[^\}]*),pl:(.[^\}]*),pa:(.[^\}]*)\}!is', $this->xml, $matches, PREG_SET_ORDER);
foreach($matches as $match)
{
$id = $this->createActionId();
$params = explode('|-|', $match[3]);
$this->actions[$id] = array(
'call' => ($match[2]) ? array($match[1], $match[2]) : $match[1],
'param' => (count($params) < 2) ? $params[0] : $params
);
$this->xml = str_replace('{ca:'.$match[1].',pl:'.$match[2].',pa:'.$match[3].'}', $id, $this->xml);
}
$this->rendered = true;
return $this->xml;
}
/**
* Returns the background-xml for this window if bg-option available
*
* @author hal.sascha
*/
private function getBg()
{
if(!$this->bg) return '';
return "<frame posn='0 0 0'><quad posn='-{$this->margin} 0 0' sizen='". ($this->width + ($this->margin*2)) ." ". (abs($this->lheight)+$this->margin) ."'". $this->applyStyles($this->bg, 'quad') ." /></frame>";
}
/**
* Returns the header-xml for this window if header-option available
*
* @author hal.sascha
*/
private function getHeader()
{
if(!$this->header) return '';
$xml = "<frame posn='0 0 9'>";
$xml .= "<quad posn='-{$this->margin} 0 0' sizen='". ($this->width + ($this->margin*2)) ." 3'". $this->applyStyles('header', 'quad') ." />";
$xml .= "<quad posn='-0.25 -0.3 1' sizen='2.5 2.5' style='Icons128x128_1' substyle='{$this->icon}' action='{ca:on{$this->name}Close,pl:0,pa:0}' />";
$xml .= "<quad posn='". ($this->width-2) ." -0.4 1' sizen='2 2' style='Icons64x64_1' substyle='Close' action='{ca:on{$this->name}Close,pl:0,pa:0}' />";
$xml .= "<label posn='2.5 -1.25 1' sizen='{$this->width} 0' text='{$this->title}'". $this->applyStyles('header') ." />";
$xml .= "</frame>";
return $xml;
}
/**
* Opens a new frame
*
* @param string $name
*/
public function Frame($posx = false, $posy = false, $width = false, $styles = false, $mla = false)
{
$this->cframe = count($this->frames) + 1;
$this->frames[$this->cframe] = array(
'posx' => ($posx) ? $posx : 0,
'posy' => ($posy) ? $posy : 0,
'width' => ($width) ? $width : $this->width,
'lines' => array(),
'styles' => $styles,
'action' => $this->getActionAttribute($mla)
);
}
/**
* Adds a new line to the window
*
* @param array $line
* @author hal.sascha
*/
public function Line($styles = false, $mla = false)
{
//Check if at least default frame is available, else create it
if(!$this->cframe) $this->Frame();
$this->cline = count($this->frames[$this->cframe]['lines']) + 1;
$this->frames[$this->cframe]['lines'][$this->cline] = array(
'cells' => array(),
'customxml' => false,
'styles' => $styles,
'action' => $this->getActionAttribute($mla)
);
}
/**
* Adds a new cell to a line
*
* Cell($text, $width/$height[as array if height specified], $action/$param[as array if param specified], $attributes[as array]);
* @param array $cell
* @author hal.sascha
*/
public function Cell($text, $size, $mla = false, $attributes = false)
{
$this->frames[$this->cframe]['lines'][$this->cline]['cells'][] = array(
'text' => specialchars($text),
'size' => $size,
'action' => $this->getActionAttribute($mla),
'attributes' => $attributes
);
}
/**
* Adds custom XML code to the window
*
* If height isset, the system will respect the height and each later line will be use the new position offset
* @param string $xml
* @param int $height
* @author hal.sascha
*/
public function CustomXML($xml, $height = false)
{
$this->frames[$this->cframe]['lines'][$this->cline]['customxml'] = array($xml, $height);
}
/**
* Returns the xml for the window frames
*
* @author hal.sascha
*/
private function getFrames()
{
//Get Frames
$fxml = '';
foreach($this->frames AS $keyf => $frame)
{
$fx = $frame['posx'];
$fy = $frame['posy'];
$fw = $frame['width'];
$fh = 0;
//Get Lines
$lxml = '';
$lx = 0;
$ly = $this->header ? -$this->lineheight : -0.5;
$lw = $fw;
$lh = $this->lineheight;
foreach($frame['lines'] AS $keyl => $line)
{
//Get Cells
$cxml = '';
$cx = 0;
$cy = 0;
$cw = 0;
$ch = 0;
$hch = 0;
if(is_array($line['customxml']))
{
$cxml = $line['customxml'][0];
$ch = ($line['customxml'][1] !== false) ? $line['customxml'][1] : 0;
}
foreach($line['cells'] AS $keyc => $cell)
{
//Calc size
if(is_array($cell['size']))
{
$cw = !empty($cell['size'][0]) ? $lw/100*$cell['size'][0] : 0;
$ch = !empty($cell['size'][1]) ? $cell['size'][1] : $lh;
}
else
{
$cw = !empty($cell['size']) ? $lw/100*$cell['size'] : 0;
$ch = $lh;
}
$ch = ($hch < $ch) ? $ch : $hch;
//Set Defaults
$cell['attributes']['valign'] = !empty($cell['attributes']['valign']) ? $cell['attributes']['valign'] : 'center';
//Create quad attributes
$attributes = $this->applyStyles(true, 'quad', $cell['attributes']);
if($attributes || !empty($cell['action']))
{
$cxml .= "<quad posn='{$cx} 0 1' sizen='{$cw} {$ch}'{$cell['action']}". implode('', $attributes) ." />";
}
//Element attributes
switch($cell['attributes']['tagtype'])
{
default:
if(!empty($cell['text']))
{
$attributes = $this->applyStyles(true, 'label', $cell['attributes']);
$nx = $this->getPosX($cx, $cw, $cell['attributes']['halign']);
$ny = $this->getPosY(0, $ch, $cell['attributes']['valign']);
$cxml .= "<label posn='{$nx} {$ny} 1' sizen='{$cw} {$ch}' text=' {$cell['text']} '". implode('', $attributes) ." />";
}
break;
case 'entry':
$attributes = $this->applyStyles(true, 'entry', $cell['attributes']);
$nx = $this->getPosX($cx, $cw, $cell['attributes']['halign']);
$ny = $this->getPosY(0, $ch, 0);
$cxml .= "<entry posn='{$nx} {$ny} 1' sizen='{$cw} {$ch}'". implode('', $attributes) ." />";
break;
case 'fileentry':
$attributes = $this->applyStyles(true, 'fileentry', $cell['attributes']);
$nx = $this->getPosX($cx, $c, $cell['attributes']['halign']);
$ny = $this->getPosY(0, $ch, 0);
$cxml .= "<fileentry posn='{$nx} {$ny} 1' sizen='{$cw} {$ch}'". implode('', $attributes) ." />";
break;
case 'audio':
$attributes = $this->applyStyles(true, 'audio', $cell['attributes']);
$ny = $this->getPosY(0, $ch, 'center');
$cxml .= "<audio posn='{$cx} {$ny} 1' sizen='{$cw} {$ch}'". implode('', $attributes) ." />";
break;
case 'music':
$attributes = $this->applyStyles(true, 'music', $cell['attributes']);
$cxml .= "<music". implode('', $attributes) ." />";
break;
case 'include':
$attributes = $this->applyStyles(true, 'include', $cell['attributes']);
$cxml .= "<include". implode('', $attributes) ." />";
break;
}
//Next cell position
$cx = $cx + $cw;
$hch = $ch;
}
//Cells XML generated
//Generate Line XML
$lh = $hch;
if(is_array($line['styles']) || !empty($line['action']))
{
$attributes = $this->applyStyles(true, 'quad', $line['styles']);
$cxml .= "<quad posn='0 0 0' sizen='{$lw} {$lh}'{$line['action']}". implode('', $attributes) ." />";
}
$lxml .= "<frame posn='0 {$ly} 1'>{$cxml}</frame>";
//Next line position
$ly = $ly - $lh;
}
//Lines XML generated
//Generate Frame XML
$fh = abs($ly-$this->margin);
$this->lheight = $ly;
if(is_array($frame['styles']) || !empty($frame['action']))
{
$attributes = $this->applyStyles(true, 'quad', $frame['styles']);
$lxml .= "<quad posn='0 0 0' sizen='{$fw} {$fh}'{$frame['action']}". implode('', $attributes) ." />";
}
$fxml .= "<frame posn='{$fx} {$fy} 1'>{$lxml}</frame>";
}
//Frames XML generated
//Return Frames XML
return $fxml;
}
/**
* Returns a parsable action attribute string
*
* @param mixed $mla
* @author hal.sascha
*/
private function getActionAttribute($mla)
{
//Check if action has params
if(is_array($mla))
{
if(is_array($mla[0]))
{
$action = $mla[0][0];
$plugin = $mla[0][1];
}
else
{
$action = $mla[0];
$plugin = 0;
}
$params = is_array($mla[1])? implode('|-|', $mla[1]) : $mla[1];
}
else
{
$action = $mla;
$plugin = 0;
$params = 0;
}
$params = empty($params) ? 0 : $params;
return !empty($action) ? " action='{ca:{$action},pl:{$plugin},pa:{$params}}'" : '';
}
/**
* Returns the x position for a label respecting it's align
*
* @param int $posx
* @param int $width
* @param string $align
* @author hal.sascha
*/
private function getPosX($posx, $width, $align)
{
if(!empty($align))
{
if($align == 'center')
{
return $posx + ($width / 2);
}
elseif($align == 'right')
{
return $posx + $width;
}
}
return $posx;
}
/**
* Returns the y position for a label respecting it's align
*
* @param int $posy
* @param int $height
* @param string $align
* @author hal.sascha
*/
private function getPosY($posy, $height, $align, $offset = 0.20)
{
if(!empty($align))
{
if($align == 'center')
{
return $posy - ($height / 2) + $offset;
}
elseif($align == 'bottom')
{
return $posy - $height + $offset;
}
}
return $posy;
}
/**
* Returns a style definition from live.xml setting file
*
* @param string $name
* @author hal.sascha
*/
private function applyStyles($name, $region = 'label', &$attributes = false)
{
$return = array();
if(is_string($name))
{
//applies all styles from a styleset
if(array_key_exists($region, $this->styleregions))
{
foreach($this->styleregions[$region] AS $attribute)
{
$value = $this->getStyle($name, $attribute);
if($value)
{
$return[$attribute] = " {$attribute}='{$value}'";
$attributes[$attribute] = $value;
}
}
}
return implode('', $return);
}
else
{
//applies all styles from a styleset + the delivered external styles and overwrite the class
if(is_array($attributes) && array_key_exists($region, $this->styleregions))
{
foreach($this->styleregions[$region] AS $attribute)
{
if(array_key_exists($attribute, $attributes))
{
$return[$attribute] = " {$attribute}='{$attributes[$attribute]}'";
continue; //jumps over class check, it's like overwriting the class value
}
if(!empty($attributes['class']))
{
$value = $this->getStyle($attributes['class'], $attribute);
if($value)
{
$return[$attribute] = " {$attribute}='{$value}'";
$attributes[$attribute] = $value;
}
}
}
}
return $return;
}
}
/**
* Returns a style string by class and attribute
*
* @param string $name
* @param string $attribute
* @author hal.sascha
*/
private function getStyle($name, $attribute)
{
return isset($this->base->colors->ml->styles->{$name}[$attribute]) ? (string) $this->base->colors->ml->styles->{$name}[$attribute] : false;
}
}
?>
Das steht da drin, bei Zeile 272 ist nur nen Array.
Mfg Paddy
Powered by vBulletin® Version 4.2.5 Copyright ©2024 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.