-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
197 lines (104 loc) · 3 KB
/
functions.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
<?php
function enter_keywords_into_urls($url_id,$keywords)
{
global $mysqli;
$result = $mysqli->query("UPDATE e_commerce_sites_list SET meta_keywords = '$keywords' WHERE id=$url_id");
}
function get_keywords($url)
{
$tags = get_meta_tags($url);
return $tags['keywords'];
}
function fixUrl($url,$part=NULL){
//lowercase
$url = strtolower($url);
//add http if absent
if (!(preg_match("#^http.*#", $url))){
$url = "http://" . $url;
}
//remove www
$url = str_replace("www.", "", $url);
//check URL is valid
if (!isValidUrl($url)){
return false;
}
//parse URL
$parts = parse_url($url);
//check that URL was parsed correctly
if (!(is_array($parts))){
return false;
}
if($part==NULL){
$part = "default";
}
switch($part){
case "default":
return ($parts['scheme'] ."://". $parts['host'] . $parts['path']);
break;
case "domain":
return $parts['host'];
break;
case "domain,path":
return $parts['host'] . $parts['path'];
break;
case "path":
return $parts['path'];
break;
case "full":
return $parts;
break;
}
}
function isValidURL($url){
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
function enter_domain($domain)
{
global $mysqli;
$domain = trim($domain);
$mysqli->query("INSERT INTO smb_domains (domain) VALUES ('$domain')");
}
function get_domain_id($domain)
{
global $mysqli;
if ($result = $mysqli->query("SELECT * FROM smb_domains WHERE domain='$domain'")) {
$domain = $result->fetch_object();
$result->close();
return $domain->id;
}
else return false;
}
function enter_domain_id_into_url($domain_id,$url_id)
{
global $mysqli;
$result = $mysqli->query("UPDATE e_commerce_sites_list SET domain_id = $domain_id WHERE id=$url_id");
}
// =================================================
function enter_keyword($keyword)
{
global $mysqli;
$keyword = trim($keyword);
$result = $mysqli->query("INSERT INTO smb_keywords (keyword) VALUES ('$keyword')");
}
function get_keyword_id($keyword)
{
global $mysqli;
if ($result = $mysqli->query("SELECT * FROM smb_keywords WHERE keyword='$keyword'"))
{
$keyword = $result->fetch_object();
$result->close();
return $keyword->id;
}
else return false;
}
function enter_url_id_keyword_id($url_id,$keyword_id)
{
global $mysqli;
$result = $mysqli->query("INSERT INTO smb_urls_keywords (url_id,keyword_id) VALUES ($url_id,$keyword_id)");
}
function set_keywords_count($url_id,$count)
{
global $mysqli;
$result = $mysqli->query("UPDATE e_commerce_sites_list SET keywords_count = $count WHERE id=$url_id");
}
?>