Archived
1
0
Fork 0
This repository has been archived on 2020-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
news-script/Source.php
2017-04-27 14:27:25 +07:00

49 lines
1.1 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) {
$text = "\n#### ".$this->title."\n";
if ($return) {
return $text;
}
$this->output .= $text;
}
protected function endSection() {}
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;
}
}