File indexing completed on 2025-01-19 05:21:07
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Feed_Pubsubhubbub 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Http_Client 0024 */ 0025 // require_once 'Zend/Http/Client.php'; 0026 0027 /** 0028 * @see Zend_Uri 0029 */ 0030 // require_once 'Zend/Uri.php'; 0031 0032 /** 0033 * @see Zend_Version 0034 */ 0035 // require_once 'Zend/Version.php'; 0036 0037 /** 0038 * @see Zend_Feed_Reader 0039 */ 0040 // require_once 'Zend/Feed/Reader.php'; 0041 0042 /** 0043 * @see Zend_Feed_Abstract 0044 */ 0045 // require_once 'Zend/Feed/Abstract.php'; 0046 0047 /** 0048 * @category Zend 0049 * @package Zend_Feed_Pubsubhubbub 0050 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0051 * @license http://framework.zend.com/license/new-bsd New BSD License 0052 */ 0053 class Zend_Feed_Pubsubhubbub 0054 { 0055 /** 0056 * Verification Modes 0057 */ 0058 const VERIFICATION_MODE_SYNC = 'sync'; 0059 const VERIFICATION_MODE_ASYNC = 'async'; 0060 0061 /** 0062 * Subscription States 0063 */ 0064 const SUBSCRIPTION_VERIFIED = 'verified'; 0065 const SUBSCRIPTION_NOTVERIFIED = 'not_verified'; 0066 const SUBSCRIPTION_TODELETE = 'to_delete'; 0067 0068 /** 0069 * Singleton instance if required of the HTTP client 0070 * 0071 * @var Zend_Http_Client 0072 */ 0073 protected static $httpClient = null; 0074 0075 /** 0076 * Simple utility function which imports any feed URL and 0077 * determines the existence of Hub Server endpoints. This works 0078 * best if directly given an instance of Zend_Feed_Reader_Atom|Rss 0079 * to leverage off. 0080 * 0081 * @param Zend_Feed_Reader_FeedAbstract|Zend_Feed_Abstract|string $source 0082 * @return array 0083 */ 0084 public static function detectHubs($source) 0085 { 0086 if (is_string($source)) { 0087 $feed = Zend_Feed_Reader::import($source); 0088 } elseif (is_object($source) && $source instanceof Zend_Feed_Reader_FeedAbstract) { 0089 $feed = $source; 0090 } elseif (is_object($source) && $source instanceof Zend_Feed_Abstract) { 0091 $feed = Zend_Feed_Reader::importFeed($source); 0092 } else { 0093 // require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; 0094 throw new Zend_Feed_Pubsubhubbub_Exception('The source parameter was' 0095 . ' invalid, i.e. not a URL string or an instance of type' 0096 . ' Zend_Feed_Reader_FeedAbstract or Zend_Feed_Abstract'); 0097 } 0098 return $feed->getHubs(); 0099 } 0100 0101 /** 0102 * Allows the external environment to make Zend_Oauth use a specific 0103 * Client instance. 0104 * 0105 * @param Zend_Http_Client $httpClient 0106 * @return void 0107 */ 0108 public static function setHttpClient(Zend_Http_Client $httpClient) 0109 { 0110 self::$httpClient = $httpClient; 0111 } 0112 0113 /** 0114 * Return the singleton instance of the HTTP Client. Note that 0115 * the instance is reset and cleared of previous parameters GET/POST. 0116 * Headers are NOT reset but handled by this component if applicable. 0117 * 0118 * @return Zend_Http_Client 0119 */ 0120 public static function getHttpClient() 0121 { 0122 if (!isset(self::$httpClient)): 0123 self::$httpClient = new Zend_Http_Client; 0124 else: 0125 self::$httpClient->resetParameters(); 0126 endif; 0127 return self::$httpClient; 0128 } 0129 0130 /** 0131 * Simple mechanism to delete the entire singleton HTTP Client instance 0132 * which forces an new instantiation for subsequent requests. 0133 * 0134 * @return void 0135 */ 0136 public static function clearHttpClient() 0137 { 0138 self::$httpClient = null; 0139 } 0140 0141 /** 0142 * RFC 3986 safe url encoding method 0143 * 0144 * @param string $string 0145 * @return string 0146 */ 0147 public static function urlencode($string) 0148 { 0149 $rawencoded = rawurlencode($string); 0150 $rfcencoded = str_replace('%7E', '~', $rawencoded); 0151 return $rfcencoded; 0152 } 0153 }