Repository navigation
Expand file tree
/
Copy pathdb.php
More file actions
164 lines (116 loc) · 3.88 KB
/
Copy pathdb.php
File metadata and controls
164 lines (116 loc) · 3.88 KB
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
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<link rel="stylesheet" href="css/card.css">
</head>
<body>
<?php
try{
//$output=$_POST["output"];
$fromDate=$_POST["fromDate"];
$toDate=$_POST["toDate"];
// Declaring Base URL for API EndPoint
$url = "http://localhost:8000/";
// Determining final end point and concatenating data as needed
if (!empty($fromDate) and !empty($toDate)) {
$url .= "feeds/between?startDate=$fromDate&endDate=$toDate";
} else {
$url .= "feeds";
}
// Opening a curl request
$apiRequest = curl_init();
// Setting Request URL to the opened curl request
curl_setopt($apiRequest, CURLOPT_URL, $url);
// Telling curl to return results to var instead of printing to the screen
curl_setopt($apiRequest, CURLOPT_RETURNTRANSFER, 1);
// Executing and storing returns from the curl request
$result = curl_exec($apiRequest);
// Closing curl request
curl_close($apiRequest);
// Converting JSON Return to a array Object
$result = json_decode($result, true);
include "chartsScript.php";
?>
<?php
// Data being fetched from db for charts
$urlExists=array();
$iurlExists=0;
foreach ($result['data'] as $index => $item) {
if (in_array($item["item_url"], $urlExists))
{
continue;
}
else
{
$adate = date_create($item["item_date"]);
date_sub($adate, date_interval_create_from_date_string('1 month'));
$urlExists[$iurlExists]=$item["item_url"];
$iurlExists++;
$table .= '{';
$table .= 'x:Date.UTC(';
$table .= date_format($adate, 'Y,m,d').'),';
$table .= 'y:';
$table .= $item["total"].',';
$table .= 'z:';
$table .= $item["total"].',';
$table .= 'heading:';
$table .= '\'';
$table .= addcslashes($item["item_title"], "'");
$table .= '\''.',';
$table .= 'url:';
$table .= '\'';
$table .= $item["item_url"];
$table .= '\'';
$table.='}';
$table.=',';
}
}
echo $table;
?>
// Highcharts code termination
]
}]
});
</script>
<?php
// Data being fetched for cards
$table = '<div class="row">';
$urlExists=array();
$iurlExists=0;
foreach ($result['data'] as $index => $item) {
if (in_array($item["item_url"], $urlExists))
{
continue;
}
else
{
$urlExists[$iurlExists]=$item["item_url"];
$iurlExists++;
$table .= '<div class="column"><div class="card">';
$table .='<div class="center-image" style="background-image: url('.$item["image"].');" style="width:320px"></div>';
$table .= '<h2 class="block-with-text">'.$item["item_title"].'</h2>';
$table .='<div class="container">';
$table .= '<span class="date">'.$item["item_date"].'</span>';
$table .= '<div class="meta"><div class="meta-item"><p class="label">Total Popularity:</p><p>';
$table .= $item["total"];
$table .= '</p></div><div class="meta-item"><p class="label">Search Engine Popularity:</p><p>';
$table .= $item["pa"];
$table .= '</p></div><div class="meta-item"><p class="label">Facebook Shares</p><p>';
$table .= $item["shares"];
$table .= '</p></div><div class="meta-item"><p class="label">Facebook Likes:</p><p>';
$table .= $item["likes"];
$table .= '</p></div></div><p class="description">';
$table .= $item["item_content"];
$table .= '</p>';
$table .= '<a target="_blank" href="'.$item["item_url"].'" >Read more</a>';
$table.='</div></div></div>' ;
}
}
$table.='</div>';
echo $table;
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
</body>