diff --git a/library/robots.php b/library/robots.php new file mode 100644 index 0000000..4f321c9 --- /dev/null +++ b/library/robots.php @@ -0,0 +1,83 @@ +_index[$this->_regex(trim($part[1]))] = true; + } + + if (false !== strpos($part[0], 'disallow')) { + $this->_index[$this->_regex(trim($part[1]))] = false; + } + } + } + + // User-agent * end + if ($read && preg_match('!^user-agent:!', $row)) { + break; + } + } + } + + public function indexURL(string $url) { + + // Unify case match + $url = strtolower(trim($url)); + + // Convert to URI + $url = str_replace(parse_url($url, PHP_URL_SCHEME) . '://' . + parse_url($url, PHP_URL_HOST) . + parse_url($url, PHP_URL_PORT), + '', $url); + + // Index by default + $result = true; + + // Begin index rules by ASC priority + foreach ($this->_index as $rule => $index) { + + if (preg_match('!^' . $rule . '!', $url)) { + + $result = $index; + } + } + + return $result; + } + + private function _regex(string $string) { + + return str_replace( + [ + '*', + '?' + ], + [ + '.*', + '\?' + ], + $string + ); + } +} \ No newline at end of file