-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
138 lines (138 loc) · 4.35 KB
/
index.php
File metadata and controls
138 lines (138 loc) · 4.35 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
<?php
require('functions.php');
$search = '';
$page = 1;
$num = 10;
if(isset($_GET['search'])) $search = $_GET['search'];
if(isset($_GET['page'])) $page = $_GET['page'];
function on_request_done($content, $url, $ch, $searchk)
{
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode !== 200) {
return;
}
$url = urldecode($url);
$read = $content;
$read = preg_replace('/<script.*?>.*?<\/script.*?>/si', ' ', $read);
$read = preg_replace('/<style.*?>.*?<\/style.*?>/si', ' ', $read);
$title = '';
$regex = '/<title.*?>(.*?)<\/title>/si';
if(preg_match_all($regex, $read, $mat)) $title = preg_replace('/&.*?;/si',' ',$mat[1][0]);
$description = '';
$regex = '/<meta\s+.*?name\s*=\s*[\'"]description[\'"].*?content\s*=\s*[\'"](.*?)[\'"].*?>/si';
if(preg_match_all($regex, $read, $mat)) $description = $mat[1][0];
else
{
$regex = '/<meta\s+.*?content\s*=\s*[\'"](.*?)[\'"].*?name\s*=\s*[\'"]description[\'"].*?>/si';
if(preg_match_all($regex, $read, $mat)) $description = $mat[1][0];
}
$r = preg_replace('/<title.*?>.*?<\/title>/si', " ", $read);
$r = preg_replace('/&.*?;/si',' ', preg_replace('/<[^>]*>/',' ',$r));
$r = trim($r);
$description .= ' '.$r;
$description = trim($description);
$ltitle = strtolower($title);
$ldescription = strtolower($description);
$ar_des = explode(' ', $description);
$ar_title = explode(' ', $title);
$lar_des = explode(' ', $ldescription);
$lar_title = explode(' ', $ltitle);
$keys_title = array();
$keys_des = array();
foreach($searchk as $ind)
{
$ind = strtolower($ind);
$keys_title = array_merge($keys_title, array_keys($lar_title, $ind));
$keys_des = array_merge($keys_des, array_keys($lar_des, $ind));
}
sort($keys_title);
sort($keys_des);
?><div>
<a class="result" href="<?php echo $url ?>">
<?php echo show($keys_title, $ar_title) ?>
</a>
</div>
<div>
<?php echo show($keys_des, $ar_des) ?>
</div>
<div style="color: green; direction: ltr; float: right;">
<?php
echo $show_url = substr($url, 0, 70);
if($show_url!=$url) echo '...';
?>
</div>
<br>
<?php
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title><?php if(trim($search) != '') echo $search.' - جستجوی '; ?><?php echo $main_title; ?></title>
<meta name="description" content="موتور جستجوی فارسی میهن جو یک جستجوگر ایرانی است که دارای بخش های جستجوی وب ، عکس ها ، آهنگ ها و فیلم ها می باشد" />
<meta name="keywords" content="موتور جستجو, جستجو, جستجوگر, میهن جو, میهن, جو, ایران, ایرانی, فارسی, جستجوگر ایرانی, جستجوی فارسی" />
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" href="/images/favicon.ico" />
<script type="text/javascript" src="js.js"></script>
</head>
<body onLoad='ajaxFunction();'>
<?php
menu('/', $search);
if(trim($search) != '')
{
?><div class="body"><?php
$d = array();
$searchk = preg_split('/[\s,\-\.]+/si', $search);
$query = "select * from keywords where ";
$n = 0;
foreach($searchk as $index)
{
if(trim($index) != "")
{
if($n == 0)
{
$query .= "keyword = '$index' ";
$n++;
}
else
{
$query .= "or keyword = '$index' ";
}
}
}
$query .= "order by density Desc";
$result = mysqli_query($db, $query);
$count = mysqli_num_rows($result);
if($count == 0)
echo 'نتیجه ای یافت نشد';
else
{
echo $count.' نتیجه';
$i = 1;
while($i <= ($num * $page) && $i <= $count)
{
$row = mysqli_fetch_row($result);
$url = $row[0];
$density = $row[2];
@ $d[$url] += $density;
$i++;
}
arsort($d);
$parallel_curl = new ParallelCurl($num);
$i = 1;
foreach($d as $index => $value)
{
if($i<=$page*$num && $i>($page-1)*$num)
$parallel_curl->startRequest($index, 'on_request_done', $searchk);
$i++;
}
$parallel_curl->finishAllRequests();
page($search, $page, $count, $num);
}
?></div><?php
}
@ mysqli_close($db);
foot();
?>
</body>
</html>