@@ -34,14 +34,12 @@ class XRobotsTagParser
3434 const DIRECTIVE_NO_TRANSLATE = 'notranslate ' ;
3535 const DIRECTIVE_UNAVAILABLE_AFTER = 'unavailable_after ' ;
3636
37- // TODO: Shuld be RFC-850, but disabled due to an rule parsing bug
3837 const DATE_FORMAT_DEFAULT = 'd M Y H:i:s T ' ;
3938
4039 private $ supportedDateFormats = [
4140 self ::DATE_FORMAT_DEFAULT ,
42- DATE_RFC1123 ,
43- DATE_RFC850 ,
44- 'd M Y H:i:s T '
41+ DATE_RFC850 , // from Google specification
42+ 'd M Y H:i:s T ' // from Google examples
4543 ];
4644
4745 private $ strict = false ;
@@ -137,7 +135,7 @@ private function detectDirectives()
137135 }
138136 if (in_array ($ pair [0 ], $ this ->directiveArray ())) {
139137 $ this ->currentDirective = $ pair [0 ];
140- $ this ->currentValue = isset ($ pair [1 ]) ? $ pair [1 ] : null ;
138+ $ this ->currentValue = isset ($ pair [1 ]) ? $ pair [1 ] : '' ;
141139 $ this ->addRule ();
142140 }
143141 }
@@ -173,6 +171,16 @@ protected function directiveArray()
173171 private function addRule ()
174172 {
175173 switch ($ this ->currentDirective ) {
174+ case self ::DIRECTIVE_ALL :
175+ if (!$ this ->strict ) break ;
176+ $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_ALL ] = true ;
177+ break ;
178+ case self ::DIRECTIVE_NONE :
179+ $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NONE ] = true ;
180+ if ($ this ->strict ) break ;
181+ $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NO_INDEX ] = true ;
182+ $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NO_FOLLOW ] = true ;
183+ break ;
176184 case self ::DIRECTIVE_NO_ARCHIVE :
177185 case self ::DIRECTIVE_NO_FOLLOW :
178186 case self ::DIRECTIVE_NO_IMAGE_INDEX :
@@ -182,18 +190,12 @@ private function addRule()
182190 case self ::DIRECTIVE_NO_TRANSLATE :
183191 $ this ->rules [$ this ->currentUserAgent ][$ this ->currentDirective ] = true ;
184192 break ;
185- case self ::DIRECTIVE_NONE :
186- $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NONE ] = true ;
187- if ($ this ->strict ) break ;
188- $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NO_INDEX ] = true ;
189- $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NO_FOLLOW ] = true ;
190- break ;
191193 case self ::DIRECTIVE_UNAVAILABLE_AFTER :
192194 if ($ this ->strict ) $ this ->supportedDateFormats = [self ::DATE_FORMAT_DEFAULT ];
193195 foreach (array_unique ($ this ->supportedDateFormats ) as $ format ) {
194196 $ dateTime = date_create_from_format ($ format , $ this ->currentValue );
195197 if ($ dateTime === false ) continue ;
196- $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_UNAVAILABLE_AFTER ] = $ dateTime ->format (self :: DATE_FORMAT_DEFAULT );
198+ $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_UNAVAILABLE_AFTER ] = $ dateTime ->format (DATE_RFC850 );
197199 if ($ this ->strict ) break ;
198200 if (time () >= $ dateTime ->getTimestamp ()) {
199201 $ this ->rules [$ this ->currentUserAgent ][self ::DIRECTIVE_NO_INDEX ] = true ;
@@ -205,7 +207,7 @@ private function addRule()
205207 }
206208
207209 /**
208- * CleanUp before next rule read
210+ * Cleanup before next rule is read
209211 *
210212 * @return void
211213 */
0 commit comments