-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_sitdinner.php
68 lines (40 loc) · 1.58 KB
/
block_sitdinner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once($CFG->libdir . '/pagelib.php');
class block_sitdinner extends block_base {
private $jsWorkerLoaded = false;
public function init() {
GLOBAL $PAGE;
$this->title = get_string('sitdinner', 'block_sitdinner');
}
public function applicable_formats() {
return array('all' => true);
}
public function get_content() {
global $CFG, $OUTPUT, $USER, $DB, $PAGE;
//loading js file, while preventing moodle catching. probably a better way somewhere...
if(!$this->jsWorkerLoaded){
$this->jsWorkerLoaded = true;
$PAGE->requires->js('/blocks/sitdinner/main.js?'.rand());
}
//not working way
//$this->page->require->requiresjs('/blocks/sitdinner/main.js');
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
//$this->content->text = 'The content of our sitdinner block!';
//first element with no .=, just =
$this->content->text = "<br><b>Todays Dinner:</b> <br>";
$data = file_get_contents('https://www.sit.no/gjovik/mat');
$tagNameStart = "dishes__single-day";
$tagPosStart = strpos ($data, $tagNameStart);
$tagPosStart += strlen($tagNameStart) + 2; //+2 for removing rest of tag
$tagNameEnd = "dishes__week-link";
$tagPosEnd = strpos ($data, $tagNameEnd);
$tagPosEnd -= strlen($tagNameEnd) - 7;//-7 for removing rest of tag
$subPart = substr($data, $tagPosStart, $tagPosEnd - $tagPosStart);
$this->content->text .= $subPart;
$this->content->footer = '';
return $this->content;
}
}