forked from serphacker/serposcope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
433 lines (382 loc) · 16.1 KB
/
view.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
/**
* Serposcope - An open source rank checker for SEO
* http://serphacker.com/serposcope/
*
* @link http://serphacker.com/serposcope Serposcope
* @author SERP Hacker <[email protected]>
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode CC-BY-NC-SA
*
* Redistributions of files must retain the above notice.
*/
if(!file_exists('inc/config.php')){
header("Location: install/",TRUE,302);
die();
}
require('inc/config.php');
include('inc/define.php');
include('inc/common.php');
$render = $options['general']['rendering'];
$group = null;
$keywords = array();
$sites = array();
if (isset($_GET['idGroup'])) {
$qGroup = "SELECT * FROM `".SQL_PREFIX."group` WHERE idGroup = " . intval($_GET['idGroup']);
$resGroup = $db->query($qGroup);
if (($group = mysql_fetch_assoc($resGroup))) {
// if(isset($_COOKIE[$group['idGroup']])){
// if($_COOKIE[$group['idGroup']] == "h"){
// $render = "highcharts";
// }else if($_COOKIE[$group['idGroup']] == "t"){
// $render = "table";
// }
// }
if(isset($serposcopeCookie['r_h'])){
if(in_array($group['idGroup'],$serposcopeCookie['r_h'])){
$render = "highcharts";
}
}
if(isset($serposcopeCookie['r_t'])){
if(in_array($group['idGroup'],$serposcopeCookie['r_t'])){
$render = "table";
}
}
if($render == "table"){
$nDay = RENDER_TABLE_NDAY;
}else{
$nDay = RENDER_HIGHCHARTS_NDAY;
}
$startDate = strtotime("now") - (24*3600*$nDay);
if(isset($_GET['startdate']) ){
$dateArr = explode("/", $_GET['startdate']);
if(is_array($dateArr) && count($dateArr) == 3 && checkdate($dateArr[1], $dateArr[0], $dateArr[2])){
$startDate = strtotime($dateArr[0]."-".$dateArr[1]."-".$dateArr[2]);
}
}
$endDate = strtotime("now");
if(isset($_GET['enddate']) ){
$dateArr = explode("/", $_GET['enddate']);
if(is_array($dateArr) && count($dateArr) == 3 && checkdate($dateArr[1], $dateArr[0], $dateArr[2])){
$endDate = strtotime($dateArr[0]."-".$dateArr[1]."-".$dateArr[2]);
}
}
$qKeyword = "SELECT idKeyword,name FROM `".SQL_PREFIX."keyword` WHERE idGroup = " . intval($_GET['idGroup']);
$resKeyword = $db->query($qKeyword);
while ($keyword = mysql_fetch_assoc($resKeyword)) {
$keywords[$keyword['idKeyword']] = $keyword['name'];
}
$qSite = "SELECT idTarget,name FROM `".SQL_PREFIX."target` WHERE idGroup = " . intval($_GET['idGroup']);
$resSite = $db->query($qSite);
while ($site = mysql_fetch_assoc($resSite)) {
$sites[$site['idTarget']] = $site['name'];
}
$rank = array();
$qCheck = "SELECT * FROM `".SQL_PREFIX."check` WHERE idGroup = " . intval($_GET['idGroup']) .
" AND date(`date`) >= '".date( 'Y-m-d',$startDate)."' ".
" AND date(`date`) <= '".date( 'Y-m-d',$endDate)."' ORDER BY `date`";
$resCheck = $db->query($qCheck);
while ($check = mysql_fetch_assoc($resCheck)) {
$rank[$check['idCheck']]['date'] = $check['date'];
$qRank = "select `".SQL_PREFIX."rank`.idTarget, `".SQL_PREFIX."target`.name tname, ".
"`".SQL_PREFIX."keyword`.name kname, position, url ".
"FROM `".SQL_PREFIX."rank` ".
"JOIN `".SQL_PREFIX."target` USING (idTarget) ".
"JOIN `".SQL_PREFIX."keyword` USING(idKeyword) ".
"WHERE idCheck= " . intval($check['idCheck']);
$resRank = $db->query($qRank);
while ($positions = mysql_fetch_assoc($resRank)) {
$rank[$check['idCheck']][$positions['tname']][$positions['kname']][0] = $positions['position'];
$rank[$check['idCheck']][$positions['tname']][$positions['kname']][1] = $positions['url'];
}
$qEvent = "SELECT name,idEvent,event FROM `".SQL_PREFIX."event` ".
"JOIN `".SQL_PREFIX."target` USING(idTarget) " .
"WHERE `date` = DATE('" . addslashes($rank[$check['idCheck']]['date']) . "') " .
"AND idTarget IN(" . implode(",", array_keys($sites)) . ")";
$resEvent = $db->query($qEvent);
while ($resEvent && $event = mysql_fetch_assoc($resEvent)) {
if (!isset($rank[$check['idCheck']]['__event'][$event['name']][$event['event']])) {
$rank[$check['idCheck']]['__event'][$event['name']][$event['idEvent']] = $event['event'];
}
}
}
}
}
if($group == NULL){
header("Location: index.php?error=Can't find group");
die();
}
if(isset($_GET['export'])){
include('renders/csv.php');
render($rank, $sites, $keywords);
die();
}
include("inc/header.php");
include('renders/'.$render.'.php');
?>
<h2><?php echo ($group != null && isset($group['name']) ? h8($group['name']) : ""); ?></h2>
<div>
<input class="datepicker datepicker-group" id="startdate" name="startdate" type="text" />
<input class="datepicker datepicker-group" id="enddate" name="enddate" type="text" />
<a type="button" class="btn" id="btn-date-scope" >Refresh</a>
<a type="button" class='btn' id="btn-export" >Export</a>
<a href='edit.php?idGroup=<?php echo $group['idGroup']; ?>' class='btn' >Edit</a>
<a id=btn-del-group class='btn btn-danger' >Delete</a>
<a href='#' id='btn-force-run' class='btn btn-warning' >Force run</a>
<div style='float:right;' >
<span rel="tooltip" title="highcharts" >
<input type=radio name=radio-render class=radio-render value=highcharts
<?php echo $render === "highcharts" ? "checked" : "" ?>
>
<i class='icon-signal' ></i>
</span>
<span rel="tooltip" title="table" >
<input type=radio name=radio-render class=radio-render value=table
<?php echo $render !== "highcharts" ? "checked" : "" ?>
>
<i class='icon-th' ></i>
</span>
</div>
</div>
<br/>
<script>
$(function() {
$( ".datepicker" ).datepicker({format : 'dd/mm/yyyy'});
$( ".event-date" ).datepicker('setValue', Date());
$( "#startdate" ).datepicker('setValue', '<?php echo date('d/m/Y', $startDate); ?>');
$( "#enddate" ).datepicker('setValue', '<?php echo date('d/m/Y', $endDate); ?>');
$('#btn-force-run').click(function(){
var canRun=false;
// check if a run is already launched
$.ajax({
type: "POST",
url: "ajax.php",
data: {
action: "is_running"
}
}).done(function(rawdata){
data = JSON.parse(rawdata);
if(data !== null){
if(data.running !== undefined){
if(!data.running){
canRun=true;
}
}else{
alert("unknow error [2]");
}
}else{
alert("unknow error [1]");
}
if(!canRun){
alert("A job is already running");
document.location.href = "index.php";
return;
}
if(!confirm("Warning, run should be done from COMMAND LINE or via cron, continue ?")){
return;
}
var imgRun = new Image();
imgRun.src = "cron.php?idGroup=<?php echo $group['idGroup']; ?>";
// lock everything for 3 sec
$.blockUI({ message: '<h1>Launching run...</h1>' });
setTimeout(function(){
document.location.href = "logs.php?id=last";
}, 2000);
});
});
$('#btn-date-scope').click(function(){
var url = "view.php?idGroup=<?php echo $group['idGroup']; ?>" +
"&startdate=" + $('#startdate').val() +
"&enddate="+ $('#enddate').val();
window.location = url;
});
$('#btn-export').click(function(){
var url = "view.php?idGroup=<?php echo $group['idGroup']; ?>" +
"&export=true" +
"&startdate=" + $('#startdate').val() +
"&enddate="+ $('#enddate').val();
window.location = url;
});
$('#btn-del-group').click(function(){
if(confirm("Are you sure to delete current group ?")){
$.ajax({
type: "POST",
url: "ajax.php",
data: {
action: "delGroup",
idGroup: <?php echo $group['idGroup']; ?>
}
}).done(function(rawdata){
data = JSON.parse(rawdata);
if(data != null){
if(data.success != undefined){
window.location = "index.php";
}else if(data.error != undefined){
alert(data.error);
}else{
alert("unknow error [2]");
}
}else{
alert("unknow error [1]");
}
});
}
});
$('.group-btn-calendar').click(function(){
var id = $(this).attr('data-id');
$('#event-table-' + id).toggle(250,'swing',
function(it){
$('#event-table-' + id ).animate({
scrollTop: $('#event-table-' + id ).get(0).scrollHeight
}, 250);
}
);
});
$('.del-event').click(function(){
$.ajax({
type: "POST",
url: "ajax.php",
data: {
action: "delEvent",
idEvent: $(this).attr('data-id')
}
}).done(function(rawdata){
data = JSON.parse(rawdata);
if(data != null){
if(data.success != undefined){
window.location = window.location.pathname + window.location.search;
}else if(data.error != undefined){
alert(data.error);
}else{
alert("unknow error [2]");
}
}else{
alert("unknow error [1]");
}
});
});
$('.event-add').click(function(){
$.ajax({
type: "POST",
url: "ajax.php",
data: $('#event-form-' + $(this).attr('data-id')).serialize()
}).done(function(rawdata){
data = JSON.parse(rawdata);
if(data != null){
if(data.success != undefined){
window.location = window.location.pathname + window.location.search;
}else if(data.error != undefined){
alert(data.error);
}else{
alert("unknow error [2]");
}
}else{
alert("unknow error [1]");
}
});
});
$('.group-btn-info').click(function(){
var idSite = $(this).attr('data-id');
$.ajax({
type: "POST",
url: "ajax.php",
data: "action=getSiteInfo&target=" + idSite
}).done(function(rawdata){
data = JSON.parse(rawdata);
if(data != null){
if(data.info != undefined && data.info != null){
domodal('Website info', data.info,onSaveGroupInfo,idSite);
}else{
domodal('Website info', '',onSaveGroupInfo,idSite);
}
}else{
alert("unknow error [1]");
}
});
});
$('.radio-render').click(function(){
var idGroup = <?php echo $group['idGroup']; ?>;
var key = idGroup;
var cookie = readCookie("serposcope");
var render = $(this).val();
if(cookie !== null){
cookie = JSON.parse(cookie);
}
if(cookie === null){
cookie = {};
}
if( cookie.r_h === undefined){
cookie.r_h = [];
}
if( cookie.r_t === undefined){
cookie.r_t = [];
}
if(cookie.r_h.indexOf(key) !== -1){
cookie.r_h.splice(cookie.r_h.indexOf(key),1);
}
if(cookie.r_t.indexOf(key) !== -1){
cookie.r_t.splice(cookie.r_t.indexOf(key),1);
}
if(render === "table"){
cookie.r_t.push(key);
}else if(render === "highcharts"){
cookie.r_h.push(key);
}else{
return;
}
setCookie("serposcope", JSON.stringify(cookie), 365);
document.location.reload(true);
});
});
</script>
<?php
foreach ($sites as $idSite => $site) {
echo "<a class=linkdiv id='" . h8($site) . "' href='' ></a>";
echo "<div>\n";
echo "<div class='row group-head' >".
"<div id='event-bar-$idSite' data-id='$idSite' class='group-title' >" .h8($site) . "</div>".
"<div class='group-action-btn' >".
"<span data-id='$idSite' class='btn group-btn-info' > info </span> ".
"<span data-id='$idSite' class='btn group-btn-calendar' > calendar </span> ".
"</div>".
"</div>";
?>
<div id="event-table-<?php echo $idSite; ?>" class="table-event-container" >
<form id="event-form-<?php echo $idSite; ?>" class="form-event" action="ajax.php" >
<input type="hidden" name="action" value="addEvent" />
<input type="hidden" name="target" value="<?php echo $idSite; ?>" />
<table class='table table-bordered table-striped table-event'>
<tr><th style='width:80px'>Date</th><th>Event</th><th style='width:8px'>#</th></tr>
<?php
if (isset($_GET['idGroup'])) {
$qEvent = "SELECT idEvent,date_format(`date`,'%d/%m/%Y') `dateF`,event,name ".
"FROM `".SQL_PREFIX."event` ".
"JOIN `".SQL_PREFIX."target` USING (idTarget) ".
"WHERE idTarget = $idSite ORDER BY `date` ASC ";
$resEvent = $db->query($qEvent);
while ($event = mysql_fetch_assoc($resEvent)) {
$diff = date_diff(date_create_from_format('d/m/Y', $event['dateF']),date_create());
echo "<tr>" .
'<td rel="tooltip" title="'.$event['dateF'].'" style="pointeur: cursor" > ' .
($diff->format("%m") > 0 ? $diff->format("%m mois ") : "") .
$diff->format("%d jours").
"</td>" .
"<td>" . ($event['event']) . "</td>" .
"<td><img class=del-event data-id=" . $event['idEvent'] . " src='img/trash.png' /></td>" .
"</tr>";
}
}
?>
<tr>
<td><input class="datepicker event-date" name="date" type="text" style="width:80px" ></td>
<td><textarea class="event-data" name="note" ></textarea></td>
<td><img src="img/add.png" class=event-add data-id=<?php echo $idSite; ?> /></td>
</tr>
</table>
</form>
</div>
<?php
render($rank, $site, $keywords);
echo "</div>\n";
}
include('inc/footer.php');
?>