-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhen.php
executable file
·176 lines (146 loc) · 4.64 KB
/
When.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
namespace Nrwtaylor\StackAgentThing;
// TODO
// http://www.lightandmatter.com/when/when.html
// Determine stack when response.
class When extends Agent
{
public $var = 'hello';
function init()
{
$this->initWhen();
}
public function initWhen() {
$this->preferences_location = null;
if (
isset(
$this->thing->container['api']['when']['preferences_location']
)
) {
$preferences =
$this->thing->container['api']['when']['preferences_location'];
}
$this->calendar_location = null;
if (
isset(
$this->thing->container['api']['when']['calendar_location']
)
) {
$this->calendar_location =
$this->thing->container['api']['when']['calendar_location'];
}
$this->calendar_contents = file_get_contents($this->calendar_location);
}
function run()
{
$this->doWhen();
}
public function doWhen()
{
// TODO
if (isset($this->file) and is_string($this->file)) {
$this->readWhen($this->file);
}
if ($this->agent_input == null) {
if (!isset($this->when_text)) {
$this->when_text = "No when text available.";
}
$this->when_message = $this->when_text; // mewsage?
} else {
$this->when_message = $this->agent_input;
}
}
public function respondResponse()
{
$this->thing->flagGreen();
$this->thing_report["info"] = "This is supportive of calendar.";
$this->thing_report["help"] = "This is about seeing Events.";
//$this->thing_report['sms'] = $this->sms_message;
$this->thing_report['message'] = $this->sms_message;
//$this->thing_report['txt'] = $this->sms_message;
$message_thing = new Message($this->thing, $this->thing_report);
$thing_report['info'] = $message_thing->thing_report['info'];
return $this->thing_report;
}
function makeWeb()
{
$time_agent = new Time($this->thing, "time");
$web = '</div>No calendar information available from when.</div>';
if (isset($this->events)) {
$web = "";
foreach ($this->events as $event) {
$web .=
'<div>' .
$time_agent->textTime($event->dtstart) .
" " .
$time_agent->textTime($event->dtend) .
" " .
$event->summary .
" " .
$event->description .
" " .
$event->location .
"</div>";
}
}
$this->web = $web;
$this->thing_report['web'] = $this->web;
}
function makeSMS()
{
$this->sms_message =
"WHEN " . $this->response;
$this->thing_report['sms'] = $this->sms_message;
}
public function makeTXT() {
$text = $this->calendar_contents;
$this->txt = $text;
$this->thing_report['txt'] = $text;
}
function makeChoices()
{
$choices = false;
$this->thing_report['choices'] = $choices;
}
public function readWhen($file)
{
if ($file == "") {return true;}
$contents = file_get_contents($file);
// TODO - Read When file.
}
public function readSubject()
{
$input = $this->subject;
if (isset($this->agent_input) and $this->agent_input != "") {
$input = $this->agent_input;
}
if ($input == 'when') {
$input = $this->subject;
}
// https://stackoverflow.com/questions/9598665/php-replace-first-occurrence-of-string->
$string = $input;
$str_pattern = 'when';
$str_replacement = '';
if (strpos($string, $str_pattern) !== false) {
$occurrence = strpos($string, $str_pattern);
$filtered_input = substr_replace(
$string,
$str_replacement,
strpos($string, $str_pattern),
strlen($str_pattern)
);
}
$filtered_input = trim($filtered_input);
//var_dump($filtered_input);
//$googlecalendar_agent = new Googlecalendar($this->thing, "calendar");
//$ics_file = $googlecalendar_agent->icsGooglecalendar("nrwtaylor");
//var_dump($ics_file);
//$calendar_agent = new Calendar($this->thing, "calendar");
//$text = $calendar_agent->readCalendar($ics_file);
//var_dump($text);
//exit();
//var_dump($calendar_agent->thing_report['sms']);
// $this->file = $filtered_input;
return false;
}
}