forked from serphacker/serposcope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.php
236 lines (216 loc) · 8.06 KB
/
new.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
<?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');
$error = "";
if(isset($_POST['name'])){
$keywords = array();
$sites= array();
$groupOptions=array();
if(empty($_POST['name'])){
$error .= "No group name.<br/>";
}
if(empty($error)){
if(!isset($_POST['module']) || !isset($modules[$_POST['module']])){
$error .= "Need a valid module.<br/>";
}else{
$groupDefaultOptions=$modules[$_POST['module']]->getGroupOptions();
foreach ($groupDefaultOptions as $option) {
if(!isset($_POST[$option[0]]))
$error .= "Missing group option ".$option[0].".<br/>";
else if(!preg_match($option[3], $_POST[$option[0]]))
$error .= "Invalid group option ".$option[0]." \"<strong>".h8($_POST[$option[0]])."</strong>\", doesn't match ".h8($option[3])." <br/>";
else
$groupOptions[$option[0]] = $_POST[$option[0]];
}
}
}
if(isset($_POST['keywords'])){
$_POST['keywords'] = explode("\n", $_POST['keywords']);
foreach ($_POST['keywords'] as $keyword) {
$keyword=trim($keyword);
if(!empty($keyword)){
if(!$modules[$_POST['module']]->validateKeyword($keyword)){
$error .= "Invalid target format ".$keyword;
break;
}else{
if(!in_array($keyword, $keywords)){
$keywords[] = $keyword;
}
}
}
}
}
if(isset($_POST['sites'])){
$_POST['sites'] = explode("\n", $_POST['sites']);
foreach ($_POST['sites'] as $site) {
$site=trim($site);
if(!empty($site)){
if(!$modules[$_POST['module']]->validateTarget($site)){
$error .= "Invalid target format ".$site;
break;
}else{
if(!in_array($site, $sites)){
$sites[] = $site;
}
}
}
}
}
if(empty($error)){
$q="INSERT INTO `".SQL_PREFIX."group`(`name`,`module`,`options`) VALUES(".
"'".addslashes($_POST['name'])."',".
"'".addslashes($_POST['module'])."',".
"'".addslashes(json_encode($groupOptions))."')";
if($db->query($q) !== true){
$error = "SQL Error #1";
}
}
if(empty($error)){
$id=mysql_insert_id();
$q="UPDATE `".SQL_PREFIX."group` SET position = ".intval($id)." WHERE idGroup = ".intval($id);
if($db->query($q) !== true){
$error = "SQL Error #2";
}
}
if(empty($error) && !empty($keywords)){
// insert the keywords
$qKW="INSERT INTO `".SQL_PREFIX."keyword`(`idGroup`,`name`) VALUES ";
for($i=0;$i<count($keywords);$i++){
$qKW .= "(".intval($id).",'".addslashes($keywords[$i])."')";
if($i < count($keywords)-1)
$qKW .= ",";
}
if($db->query($qKW) !== true){
$error = "SQL Error #3";
}
}
if(empty($error) && !empty($sites)){
// insert the sites
$qSite="INSERT INTO `".SQL_PREFIX."target`(`idGroup`,`name`) VALUES ";
for($i=0;$i<count($sites);$i++){
$qSite .= "(".intval($id).",'".addslashes($sites[$i])."')";
if($i < count($sites)-1)
$qSite .= ",";
}
if($db->query($qSite) !== true){
$error = "SQL Error #4";
}
}
if(empty($error) && $id > 0){
header("Location: view.php?idGroup=".$id);
}
}
include("inc/header.php");
?>
<h2>New group</h2>
<?php
if(!empty($error)){
echo "<div class='alert alert-error'>$error</div>\n";
}
?>
<div>
<form method="POST" class="well form-horizontal" >
<fieldset>
<div class="control-group">
<label class="control-label" for="name">Group name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="name" name="name" value="<?php echo isset($_POST['name']) ? h8($_POST['name']) : ""; ?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="keywords">Keywords</label>
<div class="controls keywords">
<textarea type="text" name="keywords" class="input-xlarge" placeholder="one keyword per line" ><?php
echo isset($_POST['keywords']) && !empty($_POST['keywords']) ? h8(implode("\n", $_POST['keywords'])) : "";
?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="sites">Domain</label>
<div class="controls sites">
<textarea type="text" name="sites" class="input-xlarge" placeholder="www.site.com or *.site.com" ><?php
echo isset($_POST['sites']) && !empty($_POST['sites']) ? h8(implode("\n", $_POST['sites'])) : "";
?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="module">Module</label>
<div class="controls">
<?php
foreach ($modules as $name => $module) {
echo
"<input type='radio' name='module' value='$name' class=itype >".
" <img src='modules/$name/icon.png' /> $name <i></i>".
"<br/>";
}
?>
</div>
</div>
<div id="groupopt" >
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" type="submit">Save</button>
</div>
</div>
</fieldset>
</form>
</div>
<script>
$(function(){
$('.itype').each(function(){
$(this).prop('checked', false);
});
$('.itype').click(function(){
$('#groupopt').empty();
// retrieve all the option for this group
$.ajax({
type: "POST",
url: "ajax.php",
data: {
action: "getGroupOptions",
module: $(this).val()
}
}).done(function(rawdata){
if(rawdata === ""){
return;
}
data = JSON.parse(rawdata);
if(data !== null){
var html = "";
$(data).each(function(i,option){
if(option.length === 5){
html += '<div class="control-group">\n';
html += '<label class="control-label" for="' + option[0] + '">' + option[0] + '</label>\n';
html += '<div class="controls">\n';
html += '<input type="text" class="input-xlarge" id="' + option[0] + '" name="' + option[0] + '" value="' + option[1] + '" >\n';
if(option[2] != "")
html += '<p class="help-block">' + option[2] + '</p>\n';
html += '</div>\n';
html += '</div>\n';
}
});
$('#groupopt').html(html);
}
});
});
});
</script>
<?php
include('inc/footer.php');
?>