status/include/Formatter.php

74 lines
2.2 KiB
PHP

<?php
require_once("functions.php");
require_once("WikiImport.php");
class Formatter {
private $import;
public function __construct($htmlfile) {
$this->template = get_fragments($htmlfile);
$this->import = new WikiImport();
}
public function format_oneroom($room) {
$rooms = $this->import->get_roomlist();
if(!in_array($room, $rooms)) {
return replace(array('status' => 'warning',
'statustext' => 'Not a room',
'visibility' => 'hidden',
'roomdata' => ''),
$this->template['thinroom']);
}
$roomdata = $this->import->get_roomdata($room);
$status = 'warning';
$statustext = 'Known problems';
$visibility = '';
if (!$this->import->has_contents($roomdata)) {
$status = 'safe';
$statustext = "No known problems";
$visibility = 'hidden';
}
return replace(array('status' => $status,
'statustext' => $statustext,
'visibility' => $visibility,
'roomdata' => $roomdata),
$this->template['thinroom']);
}
public function format_allrooms() {
$rooms = $this->import->get_roomlist();
$roomlist = '';
foreach ($rooms as $room) {
$roomlist .= $this->room_fragment($room);
}
return replace(array('roomlist' => $roomlist),
$this->template['fullpage']);
}
private function room_fragment($room) {
$roomdata = $this->import->get_roomdata($room);
if ($this->import->has_contents($roomdata)) {
$indicator = 'warning';
$state = '';
} else {
$indicator = 'safe';
$roomdata = '<p>No known problems!</p>';
$state = 'collapsed';
}
return replace(array('roomname' => $room,
'roomdata' => $roomdata,
'indicator'=> $indicator,
'state' => $state),
$this->template['room']);
}
}
?>