="message collapsing has-emoji"> d01d7cf85d first commit лет назад: 4 https-migration.php d01d7cf85d first commit лет назад: 4 kses.php d01d7cf85d first commit лет назад: 4 l10n.php d01d7cf85d first commit лет назад: 4 link-template.php d01d7cf85d first commit лет назад: 4 load.php d01d7cf85d first commit лет назад: 4 locale.php d01d7cf85d first commit лет назад: 4 media-template.php d01d7cf85d first commit лет назад: 4 media.php d01d7cf85d first commit лет назад: 4 meta.php d01d7cf85d first commit лет назад: 4 ms-blogs.php d01d7cf85d first commit лет назад: 4 ms-default-constants.php d01d7cf85d first commit лет назад: 4 ms-default-filters.php d01d7cf85d first commit лет назад: 4 ms-deprecated.php d01d7cf85d first commit лет назад: 4 ms-files.php d01d7cf85d first commit лет назад: 4 ms-functions.php d01d7cf85d first commit лет назад: 4 ms-load.php d01d7cf85d first commit лет назад: 4 ms-network.php d01d7cf85d first commit лет назад: 4 ms-settings.php d01d7cf85d first commit лет назад: 4 ms-site.php d01d7cf85d first commit лет назад: 4 nav-menu-template.php d01d7cf85d first commit лет назад: 4 nav-menu.php d01d7cf85d first commit лет назад: 4 option.php d01d7cf85d first commit лет назад: 4 pluggable-deprecated.php d01d7cf85d first commit лет назад: 4 pluggable.php d01d7cf85d first commit лет назад: 4 plugin.php d01d7cf85d first commit лет назад: 4 post-formats.php d01d7cf85d first commit лет назад: 4 post-template.php d01d7cf85d first commit лет назад: 4 post-thumbnail-template.php d01d7cf85d first commit лет назад: 4 post.php d01d7cf85d first commit лет назад: 4 query.php d01d7cf85d first commit лет назад: 4 registration-functions.php d01d7cf85d first commit лет назад: 4 registration.php d01d7cf85d first commit лет назад: 4 rest-api.php d01d7cf85d first commit лет назад: 4 revision.php d01d7cf85d first commit лет назад: 4 rewrite.php d01d7cf85d first commit лет назад: 4 robots-template.php d01d7cf85d first commit лет назад: 4 rss-functions.php d01d7cf85d first commit лет назад: 4 rss.php d01d7cf85d first commit лет назад: 4 script-loader.php d01d7cf85d first commit лет назад: 4 session.php d01d7cf85d first commit лет назад: 4 shortcodes.php d01d7cf85d first commit лет назад: 4 sitemaps.php d01d7cf85d first commit лет назад: 4 spl-autoload-compat.php d01d7cf85d first commit лет назад: 4 taxonomy.php d01d7cf85d first commit лет назад: 4 template-canvas.php d01d7cf85d first commit лет назад: 4 template-loader.php d01d7cf85d first commit лет назад: 4 template.php d01d7cf85d first commit лет назад: 4 theme-i18n.json d01d7cf85d first commit лет назад: 4 theme-templates.php d01d7cf85d first commit лет назад: 4 theme.json d01d7cf85d first commit лет назад: 4 theme.php d01d7cf85d first commit лет назад: 4 update.php d01d7cf85d first commit лет назад: 4 user.php d01d7cf85d first commit лет назад: 4 vars.php d01d7cf85d first commit лет назад: 4 version.php d01d7cf85d first commit лет назад: 4 widgets.php d01d7cf85d first commit лет назад: 4 wlwmanifest.xml d01d7cf85d first commit лет назад: 4 wp-db.php d01d7cf85d first commit лет назад: 4 wp-diff.php d01d7cf85d first commit лет назад: 4 tum/whitesports - Gogs: Simplico Git Service

説明なし

Basic.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Basic Authentication provider
  4. *
  5. * @package Requests
  6. * @subpackage Authentication
  7. */
  8. /**
  9. * Basic Authentication provider
  10. *
  11. * Provides a handler for Basic HTTP authentication via the Authorization
  12. * header.
  13. *
  14. * @package Requests
  15. * @subpackage Authentication
  16. */
  17. class Requests_Auth_Basic implements Requests_Auth {
  18. /**
  19. * Username
  20. *
  21. * @var string
  22. */
  23. public $user;
  24. /**
  25. * Password
  26. *
  27. * @var string
  28. */
  29. public $pass;
  30. /**
  31. * Constructor
  32. *
  33. * @throws Requests_Exception On incorrect number of arguments (`authbasicbadargs`)
  34. * @param array|null $args Array of user and password. Must have exactly two elements
  35. */
  36. public function __construct($args = null) {
  37. if (is_array($args)) {
  38. if (count($args) !== 2) {
  39. throw new Requests_Exception('Invalid number of arguments', 'authbasicbadargs');
  40. }
  41. list($this->user, $this->pass) = $args;
  42. }
  43. }
  44. /**
  45. * Register the necessary callbacks
  46. *
  47. * @see curl_before_send
  48. * @see fsockopen_header
  49. * @param Requests_Hooks $hooks Hook system
  50. */
  51. public function register(Requests_Hooks $hooks) {
  52. $hooks->register('curl.before_send', array($this, 'curl_before_send'));
  53. $hooks->register('fsockopen.after_headers', array($this, 'fsockopen_header'));
  54. }
  55. /**
  56. * Set cURL parameters before the data is sent
  57. *
  58. * @param resource $handle cURL resource
  59. */
  60. public function curl_before_send(&$handle) {
  61. curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  62. curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString());
  63. }
  64. /**
  65. * Add extra headers to the request before sending
  66. *
  67. * @param string $out HTTP header string
  68. */
  69. public function fsockopen_header(&$out) {
  70. $out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString()));
  71. }
  72. /**
  73. * Get the authentication string (user:pass)
  74. *
  75. * @return string
  76. */
  77. public function getAuthString() {
  78. return $this->user . ':' . $this->pass;
  79. }
  80. }