67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
namespace Source;
|
|
|
|
use \PHPHtmlParser\Dom;
|
|
use \Game;
|
|
|
|
abstract class Source {
|
|
public $title;
|
|
protected $dom;
|
|
protected $period;
|
|
protected $output;
|
|
public function __construct() {
|
|
$this->dom = new Dom;
|
|
$this->period = strtotime("1 week ago");
|
|
$this->output = '';
|
|
}
|
|
/**
|
|
* Function to start the section.
|
|
* @param whether to return or print the text
|
|
*/
|
|
protected function startSection($return = false) {
|
|
if (FORMAT === 'MARKDOWN') {
|
|
$text = "\n#### ".$this->title."\n";
|
|
}
|
|
if (FORMAT === 'HTML') {
|
|
$text = "\n<spoiler title='".$this->title."'><h4>".$this->title."</h4>\n<ul>";
|
|
}
|
|
if ($return) {
|
|
return $text;
|
|
}
|
|
$this->output .= $text;
|
|
}
|
|
protected function endSection() {
|
|
if (FORMAT === 'HTML') {
|
|
$text = "</ul></spoiler>\n";
|
|
}
|
|
$this->output .= $text;
|
|
}
|
|
abstract protected function parse();
|
|
public function print() {
|
|
$this->startSection();
|
|
$this->parse();
|
|
$this->endSection();
|
|
if ($this->output === $this->startSection(true)) // nothing to print
|
|
return;
|
|
echo $this->output;
|
|
}
|
|
protected function get_text($url) {
|
|
$curl = curl_init();
|
|
curl_setopt_array($curl, array(
|
|
CURLOPT_RETURNTRANSFER => 1,
|
|
CURLOPT_URL => $url,
|
|
));
|
|
$resp = curl_exec($curl);
|
|
curl_close($curl);
|
|
return $resp;
|
|
}
|
|
public function check() {
|
|
try {
|
|
$this->print();
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage();
|
|
echo $e->getTraceAsString();
|
|
}
|
|
}
|
|
}
|