-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewStream.php
164 lines (127 loc) · 4.64 KB
/
viewStream.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
<?php
$mode = 1;
$count = -1;
$postCount = 0;
$maxCount = 0;
$currentCount = 0;
$toggleMode = 1;
$timeStamp = 0;
//If the add author button was pressed at the addauthor web page has already been displayed and submitted
if(isset($_POST['streamList'])) {
//Split the list of streams into array elements
$result2 = explode(",",$_POST['streamList']);
$commandLine = './addauthor ';
//If the user is to be removed from the stream(s)
if ($_POST['authorMode'] == ' Remove Author') {
$commandLine = $commandLine.' '.'"-r" "';
}
else {
$commandLine = $commandLine.'"" "';
}
//Create command that will be used to call the addauthor executable
foreach ($result2 as $argument) {
$commandLine = $commandLine.''.trim($argument).',';
}
if (!empty($_POST['userID2'])) {
$commandLine = $commandLine.'" "'.$_POST['userID2'].'"';
exec($commandLine, $result3);
//Print any response messages to the browser (success, failure, etc)
foreach ($result3 as $text) {
echo $text."\n";
}
}
$command = escapeshellcmd('./getReadPostNum.py "'.$_POST['stream'].'" "'.$_POST['userID'].'" "'.$timeStamp.'"');
$postInfo = shell_exec($command);
$list = explode(PHP_EOL, $postInfo);
$_POST['maxCount'] = $list[1];
}
//If this is the first time this webpage is being loaded
if (isset($_POST['firstTime'])) {
date_default_timezone_set("America/Toronto");
$timeStamp = date("YmdHis");
//Determine how many posts are in the stream and how many have already been read
$command = escapeshellcmd('./getReadPostNum.py "'.$_POST['stream'].'" "'.$_POST['userID'].'" "'.$timeStamp.'"');
$postInfo = shell_exec($command);
$list = explode(PHP_EOL, $postInfo);
$currentCount = $list[0];
$maxCount = $list[1];
$toggleMode = 1;
}
else if (!isset($_POST['firstTime'])) {
$currentCount = $_POST['postCount'];
$maxCount = $_POST['maxCount'];
$toggleMode = $_POST['toggleMode'];
$timeStamp = $_POST['timeStamp'];
}
//If the post button was pressed and a post was submitted
if (isset($_POST['messageContent'])) {
$commandLine = './post "'.$_POST['userID'].'" "'.$_POST['stream'].'" "'.$_POST['messageContent']."\n".'"';
exec($commandLine, $result);
}
//Go to the previous post
if (isset($_POST['Previous_Page']) && $currentCount - 1 > -1) {
$currentCount = $currentCount - 1;
}
//Go to the next post
else if (isset($_POST['Next_Page']) && $currentCount < $maxCount) {
$currentCount = $currentCount + 1;
}
//Mark all posts in the stream as read
else if (isset($_POST['Mark_All'])) {
$command = escapeshellcmd('./markAllPosts.py "'.$_POST['stream'].'" "'.$_POST['userID'].'" "'.$maxCount.'"');
$postInfo = shell_exec($command);
}
//If the order of the posts should be changed
else if (isset($_POST['Toggle_Order'])) {
if ($toggleMode == 1) {
$toggleMode = 2;
}
else {
$toggleMode = 1;
}
$currentCount = 0;
}
//Check for new posts in the stream
else if (isset($_POST['Check_For_New'])) {
date_default_timezone_set("America/Toronto");
$timeStamp = date("YmdHis");
$command = escapeshellcmd('./getReadPostNum.py "'.$_POST['stream'].'" "'.$_POST['userID'].'" "'.$timeStamp.'"');
$postInfo = shell_exec($command);
$list = explode(PHP_EOL, $postInfo);
$currentCount = $list[0];
$maxCount = $list[1];
$toggleMode = 1;
}
if ($toggleMode == 1) {
echo "<p>Messages currently sorted by date</p>\n<hr>\n";
}
else {
echo "<p>Messages currently sorted by name</p>\n<hr>\n";
}
//Load webpage
exec('./a3 viewStream.wpml "'.$_POST['userID'].'" "'.$_POST['stream'].'" "'.$currentCount.'" "'.$toggleMode.'" "'.$maxCount.'" "'.$timeStamp.'"', $result);
foreach($result as $text) {
//Add any values that will need to be passed between webpages
if ($text == "</form>") {
echo "<input type=\"hidden\" name=\"userID\" value=\"".$_POST['userID']."\"/>\n";
echo "<input type=\"hidden\" name=\"stream\" value=\"".$_POST['stream']."\"/>\n";
echo "<input type=\"hidden\" name=\"postCount\" value=\"".$currentCount."\"/>\n";
echo "<input type=\"hidden\" name=\"maxCount\" value=\"".$maxCount."\"/>\n";
echo "<input type=\"hidden\" name=\"toggleMode\" value=\"".$toggleMode."\"/>\n";
echo "<input type=\"hidden\" name=\"timeStamp\" value=\"".$timeStamp."\"/>\n";
}
//Run getPosts.py
if (substr($text, 0, 13) == '---EXECUTE---') {
$executable = substr($text, 15);
//Create command and execute
$command = escapeshellcmd($executable.' "'.$_POST['userID'].'" "'.$_POST['stream'].'" "'.$currentCount.'" "'.$toggleMode.'" "'.$maxCount.'" "'.$timeStamp.'"');
$result2 = shell_exec($command);
//Print post
echo $result2;
echo "</body>\n</html>";
}
else {
echo $text."\n";
}
}
?>