/Zend/Feed/Pubsubhubbub.php

https://github.com/MontmereLimited/ZendFramework-v1 · PHP · 153 lines · 48 code · 13 blank · 92 comment · 5 complexity · ffc908514688cbb8ac4d4d997d18ff96 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Feed_Pubsubhubbub
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Pubsubhubbub.php 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Http_Client
  23. */
  24. // // // // // // // // // // require_once 'Zend/Http/Client.php';
  25. /**
  26. * @see Zend_Uri
  27. */
  28. // // // // // // // // // // require_once 'Zend/Uri.php';
  29. /**
  30. * @see Zend_Version
  31. */
  32. // // // // // // // // // // require_once 'Zend/Version.php';
  33. /**
  34. * @see Zend_Feed_Reader
  35. */
  36. // // // // // // // // // // require_once 'Zend/Feed/Reader.php';
  37. /**
  38. * @see Zend_Feed_Abstract
  39. */
  40. // // // // // // // // // // require_once 'Zend/Feed/Abstract.php';
  41. /**
  42. * @category Zend
  43. * @package Zend_Feed_Pubsubhubbub
  44. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  45. * @license http://framework.zend.com/license/new-bsd New BSD License
  46. */
  47. class Zend_Feed_Pubsubhubbub
  48. {
  49. /**
  50. * Verification Modes
  51. */
  52. const VERIFICATION_MODE_SYNC = 'sync';
  53. const VERIFICATION_MODE_ASYNC = 'async';
  54. /**
  55. * Subscription States
  56. */
  57. const SUBSCRIPTION_VERIFIED = 'verified';
  58. const SUBSCRIPTION_NOTVERIFIED = 'not_verified';
  59. const SUBSCRIPTION_TODELETE = 'to_delete';
  60. /**
  61. * Singleton instance if required of the HTTP client
  62. *
  63. * @var Zend_Http_Client
  64. */
  65. protected static $httpClient = null;
  66. /**
  67. * Simple utility function which imports any feed URL and
  68. * determines the existence of Hub Server endpoints. This works
  69. * best if directly given an instance of Zend_Feed_Reader_Atom|Rss
  70. * to leverage off.
  71. *
  72. * @param Zend_Feed_Reader_FeedAbstract|Zend_Feed_Abstract|string $source
  73. * @return array
  74. */
  75. public static function detectHubs($source)
  76. {
  77. if (is_string($source)) {
  78. $feed = Zend_Feed_Reader::import($source);
  79. } elseif (is_object($source) && $source instanceof Zend_Feed_Reader_FeedAbstract) {
  80. $feed = $source;
  81. } elseif (is_object($source) && $source instanceof Zend_Feed_Abstract) {
  82. $feed = Zend_Feed_Reader::importFeed($source);
  83. } else {
  84. // // // // // // // // // // require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
  85. throw new Zend_Feed_Pubsubhubbub_Exception('The source parameter was'
  86. . ' invalid, i.e. not a URL string or an instance of type'
  87. . ' Zend_Feed_Reader_FeedAbstract or Zend_Feed_Abstract');
  88. }
  89. return $feed->getHubs();
  90. }
  91. /**
  92. * Allows the external environment to make Zend_Oauth use a specific
  93. * Client instance.
  94. *
  95. * @param Zend_Http_Client $httpClient
  96. * @return void
  97. */
  98. public static function setHttpClient(Zend_Http_Client $httpClient)
  99. {
  100. self::$httpClient = $httpClient;
  101. }
  102. /**
  103. * Return the singleton instance of the HTTP Client. Note that
  104. * the instance is reset and cleared of previous parameters GET/POST.
  105. * Headers are NOT reset but handled by this component if applicable.
  106. *
  107. * @return Zend_Http_Client
  108. */
  109. public static function getHttpClient()
  110. {
  111. if (!isset(self::$httpClient)):
  112. self::$httpClient = new Zend_Http_Client;
  113. else:
  114. self::$httpClient->resetParameters();
  115. endif;
  116. return self::$httpClient;
  117. }
  118. /**
  119. * Simple mechanism to delete the entire singleton HTTP Client instance
  120. * which forces an new instantiation for subsequent requests.
  121. *
  122. * @return void
  123. */
  124. public static function clearHttpClient()
  125. {
  126. self::$httpClient = null;
  127. }
  128. /**
  129. * RFC 3986 safe url encoding method
  130. *
  131. * @param string $string
  132. * @return string
  133. */
  134. public static function urlencode($string)
  135. {
  136. $rawencoded = rawurlencode($string);
  137. $rfcencoded = str_replace('%7E', '~', $rawencoded);
  138. return $rfcencoded;
  139. }
  140. }