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

59 lines
1.3 KiB
PHP
Raw Normal View History

2017-01-23 09:00:42 +02:00
<?php
2017-01-23 09:15:26 +02:00
namespace Source;
use \PHPHtmlParser\Dom;
use \Game;
2017-01-23 09:00:42 +02:00
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) {
2017-07-13 10:49:49 +03:00
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;
2017-01-23 09:00:42 +02:00
}
2017-07-13 10:49:49 +03:00
protected function endSection() {
if (FORMAT === 'HTML') {
$text = "</ul></spoiler>\n";
}
$this->output .= $text;
}
2017-01-23 09:00:42 +02:00
abstract protected function parse();
public function print() {
$this->startSection();
$this->parse();
$this->endSection();
if ($this->output === $this->startSection(true)) // nothing to print
2017-01-23 09:00:42 +02:00
return;
2017-02-08 06:11:07 +02:00
echo $this->output;
2017-01-23 09:00:42 +02:00
}
2017-02-17 08:45:38 +02:00
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;
}
2017-01-23 09:00:42 +02:00
}