3 * SimplePie |
3 * SimplePie |
4 * |
4 * |
5 * A PHP-Based RSS and Atom Feed Framework. |
5 * A PHP-Based RSS and Atom Feed Framework. |
6 * Takes the hard work out of managing a complete RSS/Atom solution. |
6 * Takes the hard work out of managing a complete RSS/Atom solution. |
7 * |
7 * |
8 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors |
8 * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors |
9 * All rights reserved. |
9 * All rights reserved. |
10 * |
10 * |
11 * Redistribution and use in source and binary forms, with or without modification, are |
11 * Redistribution and use in source and binary forms, with or without modification, are |
12 * permitted provided that the following conditions are met: |
12 * permitted provided that the following conditions are met: |
13 * |
13 * |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33 * POSSIBILITY OF SUCH DAMAGE. |
33 * POSSIBILITY OF SUCH DAMAGE. |
34 * |
34 * |
35 * @package SimplePie |
35 * @package SimplePie |
36 * @version 1.3.1 |
36 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue |
37 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue |
|
38 * @author Ryan Parman |
37 * @author Ryan Parman |
39 * @author Geoffrey Sneddon |
38 * @author Sam Sneddon |
40 * @author Ryan McCue |
39 * @author Ryan McCue |
41 * @link http://simplepie.org/ SimplePie |
40 * @link http://simplepie.org/ SimplePie |
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
43 */ |
42 */ |
44 |
43 |
45 /** |
44 /** |
46 * IRI parser/serialiser/normaliser |
45 * IRI parser/serialiser/normaliser |
47 * |
46 * |
48 * @package SimplePie |
47 * @package SimplePie |
49 * @subpackage HTTP |
48 * @subpackage HTTP |
50 * @author Geoffrey Sneddon |
49 * @author Sam Sneddon |
51 * @author Steve Minutillo |
50 * @author Steve Minutillo |
52 * @author Ryan McCue |
51 * @author Ryan McCue |
53 * @copyright 2007-2012 Geoffrey Sneddon, Steve Minutillo, Ryan McCue |
52 * @copyright 2007-2012 Sam Sneddon, Steve Minutillo, Ryan McCue |
54 * @license http://www.opensource.org/licenses/bsd-license.php |
53 * @license http://www.opensource.org/licenses/bsd-license.php |
55 */ |
54 */ |
56 class SimplePie_IRI |
55 class SimplePie_IRI |
57 { |
56 { |
58 /** |
57 /** |
210 |
209 |
211 if ($return === null && isset($this->normalization[$this->scheme][$name])) |
210 if ($return === null && isset($this->normalization[$this->scheme][$name])) |
212 { |
211 { |
213 return $this->normalization[$this->scheme][$name]; |
212 return $this->normalization[$this->scheme][$name]; |
214 } |
213 } |
215 else |
214 |
216 { |
215 return $return; |
217 return $return; |
|
218 } |
|
219 } |
216 } |
220 |
217 |
221 /** |
218 /** |
222 * Overload __isset() to provide access via properties |
219 * Overload __isset() to provide access via properties |
223 * |
220 * |
224 * @param string $name Property name |
221 * @param string $name Property name |
225 * @return bool |
222 * @return bool |
226 */ |
223 */ |
227 public function __isset($name) |
224 public function __isset($name) |
228 { |
225 { |
229 if (method_exists($this, 'get_' . $name) || isset($this->$name)) |
226 return method_exists($this, 'get_' . $name) || isset($this->$name); |
230 { |
|
231 return true; |
|
232 } |
|
233 else |
|
234 { |
|
235 return false; |
|
236 } |
|
237 } |
227 } |
238 |
228 |
239 /** |
229 /** |
240 * Overload __unset() to provide access via properties |
230 * Overload __unset() to provide access via properties |
241 * |
231 * |
255 * @param string $iri |
245 * @param string $iri |
256 */ |
246 */ |
257 public function __construct($iri = null) |
247 public function __construct($iri = null) |
258 { |
248 { |
259 $this->set_iri($iri); |
249 $this->set_iri($iri); |
|
250 } |
|
251 |
|
252 /** |
|
253 * Clean up |
|
254 */ |
|
255 public function __destruct() { |
|
256 $this->set_iri(null, true); |
|
257 $this->set_path(null, true); |
|
258 $this->set_authority(null, true); |
260 } |
259 } |
261 |
260 |
262 /** |
261 /** |
263 * Create a new IRI object by resolving a relative IRI |
262 * Create a new IRI object by resolving a relative IRI |
264 * |
263 * |
766 * |
761 * |
767 * @return bool |
762 * @return bool |
768 */ |
763 */ |
769 public function is_valid() |
764 public function is_valid() |
770 { |
765 { |
771 $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null; |
766 if ($this->ipath === '') return true; |
772 if ($this->ipath !== '' && |
767 |
773 ( |
768 $isauthority = $this->iuserinfo !== null || $this->ihost !== null || |
774 $isauthority && ( |
769 $this->port !== null; |
775 $this->ipath[0] !== '/' || |
770 if ($isauthority && $this->ipath[0] === '/') return true; |
776 substr($this->ipath, 0, 2) === '//' |
771 |
777 ) || |
772 if (!$isauthority && (substr($this->ipath, 0, 2) === '//')) return false; |
778 ( |
773 |
779 $this->scheme === null && |
774 // Relative urls cannot have a colon in the first path segment (and the |
780 !$isauthority && |
775 // slashes themselves are not included so skip the first character). |
781 strpos($this->ipath, ':') !== false && |
776 if (!$this->scheme && !$isauthority && |
782 (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/')) |
777 strpos($this->ipath, ':') !== false && |
783 ) |
778 strpos($this->ipath, '/', 1) !== false && |
784 ) |
779 strpos($this->ipath, ':') < strpos($this->ipath, '/', 1)) return false; |
785 ) |
|
786 { |
|
787 return false; |
|
788 } |
|
789 |
780 |
790 return true; |
781 return true; |
791 } |
782 } |
792 |
783 |
793 /** |
784 /** |
819 $this->iquery, |
815 $this->iquery, |
820 $this->ifragment, |
816 $this->ifragment, |
821 $return) = $cache[$iri]; |
817 $return) = $cache[$iri]; |
822 return $return; |
818 return $return; |
823 } |
819 } |
824 else |
820 |
825 { |
821 $parsed = $this->parse_iri((string) $iri); |
826 $parsed = $this->parse_iri((string) $iri); |
822 if (!$parsed) |
827 if (!$parsed) |
823 { |
828 { |
824 return false; |
829 return false; |
825 } |
830 } |
826 |
831 |
827 $return = $this->set_scheme($parsed['scheme']) |
832 $return = $this->set_scheme($parsed['scheme']) |
828 && $this->set_authority($parsed['authority']) |
833 && $this->set_authority($parsed['authority']) |
829 && $this->set_path($parsed['path']) |
834 && $this->set_path($parsed['path']) |
830 && $this->set_query($parsed['query']) |
835 && $this->set_query($parsed['query']) |
831 && $this->set_fragment($parsed['fragment']); |
836 && $this->set_fragment($parsed['fragment']); |
832 |
837 |
833 $cache[$iri] = array($this->scheme, |
838 $cache[$iri] = array($this->scheme, |
834 $this->iuserinfo, |
839 $this->iuserinfo, |
835 $this->ihost, |
840 $this->ihost, |
836 $this->port, |
841 $this->port, |
837 $this->ipath, |
842 $this->ipath, |
838 $this->iquery, |
843 $this->iquery, |
839 $this->ifragment, |
844 $this->ifragment, |
840 $return); |
845 $return); |
841 return $return; |
846 return $return; |
|
847 } |
|
848 } |
842 } |
849 |
843 |
850 /** |
844 /** |
851 * Set the scheme. Returns true on success, false on failure (if there are |
845 * Set the scheme. Returns true on success, false on failure (if there are |
852 * any invalid characters). |
846 * any invalid characters). |
899 $this->port, |
898 $this->port, |
900 $return) = $cache[$authority]; |
899 $return) = $cache[$authority]; |
901 |
900 |
902 return $return; |
901 return $return; |
903 } |
902 } |
|
903 |
|
904 $remaining = $authority; |
|
905 if (($iuserinfo_end = strrpos($remaining, '@')) !== false) |
|
906 { |
|
907 $iuserinfo = substr($remaining, 0, $iuserinfo_end); |
|
908 $remaining = substr($remaining, $iuserinfo_end + 1); |
|
909 } |
904 else |
910 else |
905 { |
911 { |
906 $remaining = $authority; |
912 $iuserinfo = null; |
907 if (($iuserinfo_end = strrpos($remaining, '@')) !== false) |
913 } |
908 { |
914 if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) |
909 $iuserinfo = substr($remaining, 0, $iuserinfo_end); |
915 { |
910 $remaining = substr($remaining, $iuserinfo_end + 1); |
916 if (($port = substr($remaining, $port_start + 1)) === false) |
911 } |
|
912 else |
|
913 { |
|
914 $iuserinfo = null; |
|
915 } |
|
916 if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) |
|
917 { |
|
918 if (($port = substr($remaining, $port_start + 1)) === false) |
|
919 { |
|
920 $port = null; |
|
921 } |
|
922 $remaining = substr($remaining, 0, $port_start); |
|
923 } |
|
924 else |
|
925 { |
917 { |
926 $port = null; |
918 $port = null; |
927 } |
919 } |
928 |
920 $remaining = substr($remaining, 0, $port_start); |
929 $return = $this->set_userinfo($iuserinfo) && |
921 } |
930 $this->set_host($remaining) && |
922 else |
931 $this->set_port($port); |
923 { |
932 |
924 $port = null; |
933 $cache[$authority] = array($this->iuserinfo, |
925 } |
934 $this->ihost, |
926 |
935 $this->port, |
927 $return = $this->set_userinfo($iuserinfo) && |
936 $return); |
928 $this->set_host($remaining) && |
937 |
929 $this->set_port($port); |
938 return $return; |
930 |
939 } |
931 $cache[$authority] = array($this->iuserinfo, |
|
932 $this->ihost, |
|
933 $this->port, |
|
934 $return); |
|
935 |
|
936 return $return; |
940 } |
937 } |
941 |
938 |
942 /** |
939 /** |
943 * Set the iuserinfo. |
940 * Set the iuserinfo. |
944 * |
941 * |
1164 } |
1164 } |
1165 if ($this->ipath !== '') |
1165 if ($this->ipath !== '') |
1166 { |
1166 { |
1167 $iri .= $this->ipath; |
1167 $iri .= $this->ipath; |
1168 } |
1168 } |
1169 elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '') |
1169 elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '') |
1170 { |
1170 { |
1171 $iri .= $this->normalization[$this->scheme]['ipath']; |
1171 $iri .= $this->normalization[$this->scheme]['ipath']; |
1172 } |
1172 } |
1173 if ($this->iquery !== null) |
1173 if ($this->iquery !== null) |
1174 { |
1174 { |