1 | <?php |
||
22 | class XRobotsTagParser |
||
23 | { |
||
24 | const HEADER_RULE_IDENTIFIER = 'X-Robots-Tag'; |
||
25 | |||
26 | const DIRECTIVE_ALL = 'all'; |
||
27 | const DIRECTIVE_NONE = 'none'; |
||
28 | const DIRECTIVE_NO_ARCHIVE = 'noarchive'; |
||
29 | const DIRECTIVE_NO_FOLLOW = 'nofollow'; |
||
30 | const DIRECTIVE_NO_IMAGE_INDEX = 'noimageindex'; |
||
31 | const DIRECTIVE_NO_INDEX = 'noindex'; |
||
32 | const DIRECTIVE_NO_ODP = 'noodp'; |
||
33 | const DIRECTIVE_NO_SNIPPET = 'nosnippet'; |
||
34 | const DIRECTIVE_NO_TRANSLATE = 'notranslate'; |
||
35 | const DIRECTIVE_UNAVAILABLE_AFTER = 'unavailable_after'; |
||
36 | |||
37 | protected $userAgent = ''; |
||
38 | protected $userAgentMatch = ''; |
||
39 | |||
40 | protected $currentRule = ''; |
||
41 | protected $currentUserAgent; |
||
42 | |||
43 | protected $rules = []; |
||
44 | |||
45 | /** |
||
46 | * Constructor |
||
47 | * |
||
48 | * @param string $userAgent |
||
49 | * @param array $headers |
||
50 | */ |
||
51 | public function __construct($userAgent = '', $headers = null) |
||
58 | |||
59 | /** |
||
60 | * Parse HTTP headers |
||
61 | * |
||
62 | * @param array $headers |
||
63 | * @return void |
||
64 | */ |
||
65 | public function parse(array $headers) |
||
78 | |||
79 | /** |
||
80 | * Detect directives in rule |
||
81 | * |
||
82 | * @return void |
||
83 | */ |
||
84 | protected function detectDirectives() |
||
100 | |||
101 | /** |
||
102 | * Array of directives and their class names |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | protected function directiveClasses() |
||
121 | |||
122 | /** |
||
123 | * Add rule |
||
124 | * |
||
125 | * @param string $directive |
||
126 | * @return void |
||
127 | * @throws XRobotsTagParserException |
||
128 | */ |
||
129 | protected function addRule($directive) |
||
141 | |||
142 | /** |
||
143 | * Cleanup before next rule is read |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | protected function cleanup() |
||
152 | |||
153 | /** |
||
154 | * Find the most rule-matching User-Agent |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | protected function matchUserAgent() |
||
165 | |||
166 | /** |
||
167 | * Return all applicable rules |
||
168 | * |
||
169 | * @param bool $raw |
||
170 | * @return array |
||
171 | */ |
||
172 | public function getRules($raw = false) |
||
190 | |||
191 | /** |
||
192 | * Export all rules for all UserAgents |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | public function export() |
||
200 | |||
201 | /** |
||
202 | * Get the meaning of an Directive |
||
203 | * |
||
204 | * @param string $directive |
||
205 | * @return string |
||
206 | * @throws XRobotsTagParserException |
||
207 | */ |
||
208 | public function getDirectiveMeaning($directive) |
||
220 | } |
||
221 |