1 | <?php |
||
19 | class Search extends SEOstats |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Returns array, containing detailed results for any Google search. |
||
24 | * |
||
25 | * @param string $query String, containing the search query. |
||
26 | * @param string $tld String, containing the desired Google top level domain. |
||
|
|||
27 | * @return array Returns array, containing the keys 'URL', 'Title' and 'Description'. |
||
28 | */ |
||
29 | 12 | public static function getSerps($query, $maxResults = 100, $domain = false) |
|
30 | { |
||
31 | 12 | $q = rawurlencode($query); |
|
32 | 12 | $maxPage = ceil(($maxResults / 10) - 1); |
|
33 | 12 | $result = new Helper\ArrayHandle (); |
|
34 | 12 | $pages = 1; |
|
35 | 12 | $delay = 0; |
|
36 | |||
37 | 12 | $domainRexExp = static::getDomainFilter($domain); |
|
38 | |||
39 | 12 | for ($start = 0; $start < $pages; $start++) { |
|
40 | |||
41 | 12 | $haveNextPage = static::makeRequest($start, $q, $result, $domainRexExp); |
|
42 | 12 | if (!$haveNextPage) { |
|
43 | 9 | $pages -= 1; |
|
44 | 9 | } else { |
|
45 | 5 | $pages += 1; |
|
46 | 5 | $delay += 200000; |
|
47 | 5 | usleep($delay); |
|
48 | } |
||
49 | |||
50 | 12 | if ($start == $maxPage) { |
|
51 | 9 | $pages -= 1; |
|
52 | 9 | } |
|
53 | 12 | } // for ($start=0; $start<$pages; $start++) |
|
54 | |||
55 | 12 | return $result->toArray(); |
|
56 | } |
||
57 | |||
58 | 12 | protected static function makeRequest($start, $query, $result, $domainRexExp) |
|
59 | { |
||
60 | 12 | $ref = static::getReference($start, $query); |
|
61 | 12 | $nextSerp = static::getNextSerp($start, $query); |
|
62 | |||
63 | 12 | $curledSerp = utf8_decode(static::gCurl($nextSerp, $ref)); |
|
64 | |||
65 | 12 | static::guardNoCaptcha($curledSerp); |
|
66 | |||
67 | 12 | $matches = array(); |
|
68 | 12 | preg_match_all('#<h3 class="?r"?>(.*?)</h3>#', $curledSerp, $matches); |
|
69 | |||
70 | 12 | if (empty($matches[1])) { |
|
71 | // No [@id="rso"]/li/h3 on currect page |
||
72 | 8 | return false; |
|
73 | } |
||
74 | |||
75 | 6 | static::parseResults($matches, $domainRexExp, $start * 10, $result); |
|
76 | |||
77 | 6 | if (preg_match('#id="?pnnext"?#', $curledSerp)) { |
|
78 | // Found 'Next'-link on currect page |
||
79 | 5 | return true; |
|
80 | } |
||
81 | |||
82 | // No 'Next'-link on currect page |
||
83 | 1 | return false; |
|
84 | } |
||
85 | |||
86 | 12 | protected static function getReference($start, $query) |
|
92 | |||
93 | 12 | protected static function getDomainFilter($domain) |
|
99 | |||
100 | 12 | protected static function getNextSerp($start, $query) |
|
106 | |||
107 | 12 | protected static function guardNoCaptcha($response) |
|
114 | |||
115 | 6 | protected static function parseResults($matches, $domainRexExp, $start, $result) |
|
116 | { |
||
117 | 6 | $c = 0; |
|
118 | |||
119 | 6 | foreach ($matches[1] as $link) { |
|
120 | 6 | $match = static::parseLink($link); |
|
121 | |||
122 | 6 | $c++; |
|
123 | 6 | $resCnt = $start + $c; |
|
124 | 6 | if (!$domainRexExp) { |
|
125 | 3 | $result->setElement($resCnt, array( |
|
126 | 3 | 'url' => $match[1], |
|
127 | 3 | 'headline' => trim(strip_tags($match[2])) |
|
128 | 3 | )); |
|
129 | 6 | } elseif (preg_match($domainRexExp, $match[1])) { |
|
130 | 3 | $result->push(array( |
|
131 | 3 | 'position' => $resCnt, |
|
132 | 3 | 'url' => $match[1], |
|
133 | 3 | 'headline' => trim(strip_tags($match[2])) |
|
134 | 3 | )); |
|
135 | 3 | } |
|
136 | 6 | } // foreach ($matches[1] as $link) |
|
137 | 6 | } |
|
138 | |||
139 | 6 | protected static function parseLink($link) |
|
148 | |||
149 | 6 | protected static function isAGoogleWebmasterLink($url) |
|
153 | |||
154 | 2 | protected static function gCurl($path, $ref, $useCookie = null) |
|
155 | { |
||
156 | 2 | if (!$useCookie) { |
|
195 | } |
||
196 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.