-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmygurukool.php
80 lines (74 loc) · 2.55 KB
/
mygurukool.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
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
// you want to allow, and if so:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 1000');
header("X-Frame-Options: SAMEORIGIN");
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
// may also be using PUT, PATCH, HEAD etc
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header("X-Frame-Options: SAMEORIGIN");
}
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
header("Access-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization");
}
exit(0);
}
$entityBody = file_get_contents('php://input');
$result = json_decode($entityBody);
$dom = new DOMDocument();
@$dom->loadHTML($result->data);
//$dom->loadHTML($result->data);
$file_youtube_link = '';
$array = [];
$array['instructions'] = '';
$instructions = '';
$submissionDate = '';
foreach ($dom->getElementsByTagName('p') as $item) {
if(isset($item->firstChild->tagName) && $item->firstChild->tagName !== 'a') {
if (stripos($item->nodeValue, 'date') !== false){
$submissionDate = $item->nodeValue;
} else {
$instructions.= "<li>".$item->nodeValue."</li>";
}
}
if(isset($item->firstChild->wholeText)){
if (stripos($item->firstChild->wholeText, 'date') !== false){
$submissionDate = $item->firstChild->wholeText;
} else {
$instructions.= "<li>".$item->firstChild->wholeText."</li>";
}
}
if(isset($item->firstChild->tagName) && $item->firstChild->tagName == 'a') {
$file_youtube_link = $item->firstChild;
foreach($file_youtube_link->attributes as $attr){
if(strpos($attr->value,"youtu")!== false){
$array['youtubelink'] = $attr->value;
}
else {
$array['filelink'] = $attr->value;
$array['filename'] = $file_youtube_link->nodeValue;
}
}
}
}
if(!empty($dom->getElementsByTagName('object'))){
foreach ($dom->getElementsByTagName('object') as $item) {
foreach($item->attributes as $attr){
if($attr->name == 'data-attachment') {
$array['filename'] = $attr->value;
} else if($attr->name == 'type') {
$array['filetype'] = $attr->value;
} else if($attr->name == 'data') {
$array['fileObject'] = str_replace("siteCollections","sites",$attr->value);
}
}
}
}
$array['instructions'] = $instructions;
$array['submissionDate'] = $submissionDate;
echo json_encode($array);