52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
class WikiImport
|
|
{
|
|
const SUFFIX = "?action=content&mimetype=text/html";
|
|
const PREFIX = "https://wiki.dsv.su.se/dmc/Status/";
|
|
|
|
private $cu = null;
|
|
private $tags_to_strip = null;
|
|
|
|
public function __construct() {
|
|
$this->cu = curl_init();
|
|
|
|
curl_setopt($this->cu, CURLOPT_FOLLOWLOCATION, true);
|
|
curl_setopt($this->cu, CURLOPT_MAXREDIRS, 1);
|
|
curl_setopt($this->cu, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$this->tags_to_strip = array(
|
|
'%<span class="anchor" id="bottom"></span></div>%',
|
|
'%<div dir="ltr" id="content" lang="en">%',
|
|
'%<span class="anchor" id="[^"]+"></span>%',
|
|
);
|
|
}
|
|
|
|
public function getPage($page) {
|
|
curl_setopt($this->cu,
|
|
CURLOPT_URL,
|
|
self::PREFIX.rawurlencode($page).self::SUFFIX);
|
|
return curl_exec($this->cu);
|
|
}
|
|
|
|
public function get_roomlist() {
|
|
$listpage = explode('</h4>', $this->getPage(''))[1];
|
|
|
|
$rooms = array();
|
|
preg_match_all('%<a href=[^>]+>/([^<]+)</a>%i', $listpage, $rooms);
|
|
return $rooms[1];
|
|
}
|
|
|
|
public function get_roomdata($room) {
|
|
return $this->getPage($room);
|
|
}
|
|
|
|
public function has_contents($roomdata) {
|
|
return trim(preg_replace('/<[^>]+>/', '', $roomdata));
|
|
}
|
|
|
|
public function trim_extra_tags($roomdata) {
|
|
return trim(preg_replace($this->tags_to_strip, '', $roomdata));
|
|
}
|
|
}
|