PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/oauth/provider/inc/library/store/OAuthStoreAbstract.class.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 148 lines | 76 code | 18 blank | 54 comment | 5 complexity | e6eb091620ee091c256a464a60086869 MD5 | raw file
  1. <?php
  2. /**
  3. * Abstract base class for OAuthStore implementations
  4. *
  5. * @version $Id$
  6. * @author Marc Worrell <marcw@pobox.com>
  7. *
  8. * The MIT License
  9. *
  10. * Copyright (c) 2007-2008 Mediamatic Lab
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a copy
  13. * of this software and associated documentation files (the "Software"), to deal
  14. * in the Software without restriction, including without limitation the rights
  15. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. * copies of the Software, and to permit persons to whom the Software is
  17. * furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included in
  20. * all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28. * THE SOFTWARE.
  29. */
  30. abstract class OAuthStoreAbstract
  31. {
  32. abstract public function getSecretsForVerify ( $consumer_key, $token, $token_type = 'access' );
  33. abstract public function getSecretsForSignature ( $uri, $user_id );
  34. abstract public function getServerTokenSecrets ( $consumer_key, $token, $token_type, $user_id );
  35. abstract public function addServerToken ( $consumer_key, $token_type, $token, $token_secret, $user_id );
  36. abstract public function deleteServer ( $consumer_key, $user_id, $user_is_admin = false );
  37. abstract public function getServer( $consumer_key, $user_id, $user_is_admin = false );
  38. abstract public function getServerForUri ( $uri, $user_id );
  39. abstract public function listServerTokens ( $user_id );
  40. abstract public function countServerTokens ( $consumer_key );
  41. abstract public function getServerToken ( $consumer_key, $token, $user_id );
  42. abstract public function deleteServerToken ( $consumer_key, $token, $user_id, $user_is_admin = false );
  43. abstract public function listServers ( $q = '', $user_id );
  44. abstract public function updateServer ( $server, $user_id, $user_is_admin = false );
  45. abstract public function updateConsumer ( $consumer, $user_id, $user_is_admin = false );
  46. abstract public function deleteConsumer ( $consumer_key, $user_id, $user_is_admin = false );
  47. abstract public function getConsumer ( $consumer_key, $user_id, $user_is_admin = false );
  48. abstract public function getConsumerStatic ();
  49. abstract public function addConsumerRequestToken ( $consumer_key );
  50. abstract public function getConsumerRequestToken ( $token );
  51. abstract public function deleteConsumerRequestToken ( $token );
  52. abstract public function authorizeConsumerRequestToken ( $token, $user_id, $referrer_host = '' );
  53. abstract public function countConsumerAccessTokens ( $consumer_key );
  54. abstract public function exchangeConsumerRequestForAccessToken ( $token );
  55. abstract public function getConsumerAccessToken ( $token, $user_id );
  56. abstract public function deleteConsumerAccessToken ( $token, $user_id, $user_is_admin = false );
  57. abstract public function listConsumers ( $user_id );
  58. abstract public function listConsumerTokens ( $user_id );
  59. abstract public function checkServerNonce ( $consumer_key, $token, $timestamp, $nonce );
  60. abstract public function addLog ( $keys, $received, $sent, $base_string, $notes, $user_id = null );
  61. abstract public function listLog ( $options, $user_id );
  62. abstract public function install ();
  63. /**
  64. * Fetch the current static consumer key for this site, create it when it was not found.
  65. * The consumer secret for the consumer key is always empty.
  66. *
  67. * @return string consumer key
  68. */
  69. /* ** Some handy utility functions ** */
  70. /**
  71. * Generate a unique key
  72. *
  73. * @param boolean unique force the key to be unique
  74. * @return string
  75. */
  76. public function generateKey ( $unique = false )
  77. {
  78. $key = md5(uniqid(rand(), true));
  79. if ($unique)
  80. {
  81. list($usec,$sec) = explode(' ',microtime());
  82. $key .= dechex($usec).dechex($sec);
  83. }
  84. return $key;
  85. }
  86. /**
  87. * Check to see if a string is valid utf8
  88. *
  89. * @param string $s
  90. * @return boolean
  91. */
  92. protected function isUTF8 ( $s )
  93. {
  94. return preg_match('%(?:
  95. [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  96. |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  97. |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  98. |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  99. |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  100. |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  101. |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  102. )+%xs', $s);
  103. }
  104. /**
  105. * Make a string utf8, replacing all non-utf8 chars with a '.'
  106. *
  107. * @param string
  108. * @return string
  109. */
  110. protected function makeUTF8 ( $s )
  111. {
  112. if (function_exists('iconv'))
  113. {
  114. do
  115. {
  116. $ok = true;
  117. $text = @iconv('UTF-8', 'UTF-8//TRANSLIT', $s);
  118. if (strlen($text) != strlen($s))
  119. {
  120. // Remove the offending character...
  121. $s = $text . '.' . substr($s, strlen($text) + 1);
  122. $ok = false;
  123. }
  124. }
  125. while (!$ok);
  126. }
  127. return $s;
  128. }
  129. }
  130. ?>