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) |
||
80 | |||
81 | /** |
||
82 | * Detect directives in rule |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | protected function detectDirectives() |
||
102 | |||
103 | /** |
||
104 | * Array of directives and their class names |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | protected function directiveClasses() |
||
123 | |||
124 | /** |
||
125 | * Add rule |
||
126 | * |
||
127 | * @param string $directive |
||
128 | * @return void |
||
129 | * @throws XRobotsTagParserException |
||
130 | */ |
||
131 | protected function addRule($directive) |
||
143 | |||
144 | /** |
||
145 | * Cleanup before next rule is read |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | protected function cleanup() |
||
154 | |||
155 | /** |
||
156 | * Return all applicable rules |
||
157 | * |
||
158 | * @param bool $raw |
||
159 | * @return array |
||
160 | */ |
||
161 | public function getRules($raw = false) |
||
179 | |||
180 | /** |
||
181 | * Export all rules for all UserAgents |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | public function export() |
||
189 | |||
190 | /** |
||
191 | * Get the meaning of an Directive |
||
192 | * |
||
193 | * @param string $directive |
||
194 | * @return string |
||
195 | * @throws XRobotsTagParserException |
||
196 | */ |
||
197 | public function getDirectiveMeaning($directive) |
||
209 | } |
||
210 |