includes/http.php
author Dan
Tue, 29 Jan 2008 23:15:44 -0500
changeset 391 85f91037cd4f
parent 387 92664d2efab8
child 411 d1a95497b68f
permissions -rw-r--r--
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
328
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     1
<?php
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     2
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     3
/*
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
387
92664d2efab8 Rebranded source code as 1.1.1; added TinyMCE ACL rule as per Vadi's request: http://forum.enanocms.org/viewtopic.php?f=7&t=54
Dan
parents: 354
diff changeset
     5
 * Version 1.1.1 (Caoineag alpha 1)
328
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     7
 * class_http.php - Pure PHP HTTP client library
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     8
 *
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
     9
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    10
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    11
 *
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    13
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    14
 */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    15
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    16
//
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    17
// HTTP status codes
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    18
//
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    19
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    20
// Informational
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    21
define('HTTP_CONTINUE', 100);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    22
define('HTTP_SWITCHING_PROTOCOLS', 101);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    23
define('HTTP_PROCESSING', 102);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    24
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    25
// Success
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    26
define('HTTP_OK', 200);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    27
define('HTTP_CREATED', 201);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    28
define('HTTP_ACCEPTED', 202);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    29
define('HTTP_NON_AUTHORITATIVE', 203);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    30
define('HTTP_NO_CONTENT', 204);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    31
define('HTTP_RESET_CONTENT', 205);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    32
define('HTTP_PARTIAL_CONTENT', 206);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    33
define('HTTP_MULTI_STATUS', 207);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    34
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    35
// Redirection
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    36
define('HTTP_MULTIPLE_CHOICES', 300);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    37
define('HTTP_MOVED_PERMANENTLY', 301);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    38
define('HTTP_FOUND', 302);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    39
define('HTTP_SEE_OTHER', 303);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    40
define('HTTP_NOT_MODIFIED', 304);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    41
define('HTTP_USE_PROXY', 305);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    42
define('HTTP_SWITCH_PROXY', 306);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    43
define('HTTP_TEMPORARY_REDIRECT', 307);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    44
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    45
// Client Error
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    46
define('HTTP_BAD_REQUEST', 400);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    47
define('HTTP_UNAUTHORIZED', 401);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    48
define('HTTP_PAYMENT_REQUIRED', 402);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    49
define('HTTP_FORBIDDEN', 403);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    50
define('HTTP_NOT_FOUND', 404);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    51
define('HTTP_METHOD_NOT_ALLOWED', 405);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    52
define('HTTP_NOT_ACCEPTABLE', 406);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    53
define('HTTP_PROXY_AUTHENTICATION_REQUIRED', 407);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    54
define('HTTP_REQUEST_TIMEOUT', 408);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    55
define('HTTP_CONFLICT', 409);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    56
define('HTTP_GONE', 410);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    57
define('HTTP_LENGTH_REQUIRED', 411);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    58
define('HTTP_PRECONDITION_FAILED', 412);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    59
define('HTTP_REQUEST_ENTITY_TOO_LARGE', 413);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    60
define('HTTP_REQUEST_URI_TOO_LONG', 414);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    61
define('HTTP_UNSUPPORTED_MEDIA_TYPE', 415);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    62
define('HTTP_REQUESTED_RANGE_NOT_SATISFIABLE', 416);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    63
define('HTTP_EXPECTATION_FAILED', 417);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    64
define('HTTP_UNPROCESSABLE_ENTITY', 422);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    65
define('HTTP_LOCKED', 423);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    66
define('HTTP_FAILED_DEPENDENCY', 424);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    67
define('HTTP_UNORDERED_COLLECTION', 425);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    68
define('HTTP_UPGRADE_REQUIRED', 426);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    69
define('HTTP_RETRY_WITH', 449);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    70
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    71
// Server error
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    72
define('HTTP_INTERNAL_SERVER_ERROR', 500);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    73
define('HTTP_NOT_IMPLEMENTED', 501);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    74
define('HTTP_BAD_GATEWAY', 502);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    75
define('HTTP_SERVICE_TEMPORARILY_UNAVAILABLE', 503);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    76
define('HTTP_GATEWAY_TIMEOUT', 504);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    77
define('HTTP_HTTP_VERSION_NOT_SUPPORTED', 505);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    78
define('HTTP_VARIANT_ALSO_NEGOTIATES', 506);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    79
define('HTTP_INSUFFICIENT_STORAGE', 507);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    80
define('HTTP_BANDWIDTH_LIMIT_EXCEEDED', 509);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    81
define('HTTP_NOT_EXTENDED', 510);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    82
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    83
/**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    84
 * Class for making HTTP requests. This can do GET and POST, and when used properly it consumes under a meg of memory, even with huge files.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    85
 * @package Enano
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    86
 * @subpackage Backend functions
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    87
 * @copyright 2007 Dan Fuhry
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    88
 */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    89
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    90
class Request_HTTP
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    91
{
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    92
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    93
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    94
   * Switch to enable or disable debugging. You want this off on production sites.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    95
   * @var bool
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    96
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    97
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    98
  var $debug = false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
    99
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   100
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   101
   * The host the request will be sent to.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   102
   * @var string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   103
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   104
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   105
  var $host = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   106
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   107
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   108
   * The TCP port our connection is (will be) on.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   109
   * @var int
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   110
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   111
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   112
  var $port = 80;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   113
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   114
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   115
   * The request method. Can be GET or POST, defaults to GET.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   116
   * @var string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   117
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   118
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   119
  var $method = 'GET';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   120
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   121
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   122
   * The URI to the remote script.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   123
   * @var string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   124
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   125
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   126
  var $uri = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   127
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   128
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   129
   * The parameters to be sent on GET.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   130
   * @var array (associative)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   131
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   132
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   133
  var $parms_get = array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   134
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   135
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   136
   * The parameters to be sent on POST. Ignored if $this->method == GET.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   137
   * @var array (associative)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   138
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   139
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   140
  var $parms_post = array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   141
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   142
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   143
   * The list of cookies that will be sent.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   144
   * @var array (associative)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   145
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   146
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   147
  var $cookies_out = array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   148
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   149
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   150
   * Additional request headers.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   151
   * @var array (associative)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   152
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   153
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   154
  var $headers = array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   155
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   156
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   157
   * Cached response.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   158
   * @var string, or bool:false if the request hasn't been sent yet
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   159
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   160
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   161
  var $response = false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   162
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   163
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   164
   * Cached response code
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   165
   * @var int set to -1 if request hasn't been sent yet
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   166
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   167
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   168
  var $response_code = -1;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   169
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   170
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   171
   * Cached response code string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   172
   * @var string or bool:false if the request hasn't been sent yet
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   173
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   174
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   175
  var $response_string = false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   176
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   177
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   178
   * Resource for the socket. False if a connection currently isn't going.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   179
   * @var resource
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   180
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   181
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   182
  var $socket = false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   183
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   184
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   185
   * The state of our request. 0 means it hasn't been made yet. 1 means the socket is open, 2 means the socket is open and the request has been written, 3 means the headers have been fetched, and 4 means the request is completed.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   186
   * @var int
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   187
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   188
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   189
  var $state = 0;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   190
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   191
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   192
   * Constructor.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   193
   * @param string Hostname to send to
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   194
   * @param string URI (/index.php)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   195
   * @param string Request method - GET or POST.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   196
   * @param int Optional. The port to open the request on. Defaults to 80.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   197
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   198
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   199
  function Request_HTTP($host, $uri, $method = 'GET', $port = 80)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   200
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   201
    if ( !preg_match('/^(([a-z0-9-]+\.)*?)([a-z0-9-]+)$/', $host) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   202
      die(__CLASS__ . ': Invalid hostname');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   203
    $this->host = $host;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   204
    $this->uri = $uri;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   205
    if ( is_int($port) && $port >= 1 && $port <= 65535 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   206
      $this->port = $port;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   207
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   208
      die(__CLASS__ . ': Invalid port');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   209
    $method = strtoupper($method);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   210
    if ( $method == 'GET' || $method == 'POST' )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   211
      $this->method = $method;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   212
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   213
      die(__CLASS__ . ': Invalid request method');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   214
      
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   215
    $newline = "\r\n";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   216
    $php_ver = PHP_VERSION;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   217
    $this->add_header('User-Agent', "PHP/$php_ver (Server: {$_SERVER['SERVER_SOFTWARE']}; automated bot request)");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   218
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   219
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   220
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   221
   * Sets one or more cookies to be sent to the server.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   222
   * @param string or array If a string, the cookie name. If an array, associative array in the form of cookiename => cookievalue
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   223
   * @param string or bool If a string, the cookie value. If boolean, defaults to false, param 1 should be an array, and this should not be passed.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   224
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   225
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   226
  function add_cookie($cookiename, $cookievalue = false)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   227
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   228
    if ( is_array($cookiename) && !$cookievalue )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   229
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   230
      foreach ( $cookiename as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   231
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   232
        $this->cookies_out[$name] = $value;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   233
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   234
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   235
    else if ( is_string($cookiename) && is_string($cookievalue) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   236
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   237
      $this->cookies_out[$cookiename] = $cookievalue;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   238
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   239
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   240
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   241
      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   242
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   243
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   244
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   245
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   246
   * Sets one or more request header values.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   247
   * @param string or array If a string, the header name. If an array, associative array in the form of headername => headervalue
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   248
   * @param string or bool If a string, the header value. If boolean, defaults to false, param 1 should be an array, and this should not be passed.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   249
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   250
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   251
  function add_header($headername, $headervalue = false)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   252
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   253
    if ( is_array($headername) && !$headervalue )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   254
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   255
      foreach ( $headername as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   256
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   257
        $this->headers[$name] = $value;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   258
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   259
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   260
    else if ( is_string($headername) && is_string($headervalue) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   261
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   262
      $this->headers[$headername] = $headervalue;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   263
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   264
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   265
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   266
      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   267
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   268
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   269
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   270
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   271
   * Adds one or more values to be passed on GET.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   272
   * @param string or array If a string, the parameter name. If an array, associative array in the form of parametername => parametervalue
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   273
   * @param string or bool If a string, the parameter value. If boolean, defaults to false, param 1 should be an array, and this should not be passed.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   274
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   275
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   276
  function add_get($getname, $getvalue = false)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   277
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   278
    if ( is_array($getname) && !$getvalue )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   279
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   280
      foreach ( $getname as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   281
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   282
        $this->parms_get[$name] = $value;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   283
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   284
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   285
    else if ( is_string($getname) && is_string($getvalue) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   286
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   287
      $this->parms_get[$getname] = $getvalue;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   288
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   289
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   290
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   291
      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   292
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   293
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   294
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   295
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   296
   * Adds one or more values to be passed on POST.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   297
   * @param string or array If a string, the header name. If an array, associative array in the form of headername => headervalue
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   298
   * @param string or bool If a string, the header value. If boolean, defaults to false, param 1 should be an array, and this should not be passed.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   299
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   300
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   301
  function add_post($postname, $postvalue = false)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   302
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   303
    if ( is_array($postname) && !$postvalue )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   304
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   305
      foreach ( $postname as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   306
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   307
        $this->parms_post[$name] = $value;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   308
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   309
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   310
    else if ( is_string($postname) && is_string($postvalue) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   311
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   312
      $this->parms_post[$postname] = $postvalue;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   313
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   314
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   315
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   316
      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   317
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   318
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   319
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   320
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   321
   * Internal function to open up the socket.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   322
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   323
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   324
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   325
  function _sock_open(&$connection)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   326
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   327
    // Open connection
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   328
    $connection = fsockopen($this->host, $this->port);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   329
    if ( !$connection )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   330
      die(__CLASS__ . '::' . __METHOD__ . ': Could not make connection');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   331
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   332
    // 1 = socket open
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   333
    $this->state = 1;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   334
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   335
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   336
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   337
   * Internal function to actually write the request into the socket.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   338
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   339
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   340
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   341
  function _write_request(&$connection, &$headers, &$cookies, &$get, &$post)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   342
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   343
    $newline = "\r\n";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   344
    
349
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   345
    if ( $this->debug )
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   346
      echo '<p>Connection opened. Writing main request to socket. Raw socket data follows.</p><pre>';
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   347
    
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   348
    if ( $this->debug )
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   349
    {
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   350
      echo '<hr /><div style="white-space: nowrap;">';
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   351
      echo '<p><b>' . __CLASS__ . ': Sending request</b></p><p>Request parameters:</p>';
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   352
      echo "<p><b>Headers:</b></p><pre>$headers</pre>";
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   353
      echo "<p><b>Cookies:</b> $cookies</p>";
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   354
      echo "<p><b>GET URI:</b> " . htmlspecialchars($this->uri . $get) . "</p>";
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   355
      echo "<p><b>POST DATA:</b> " . htmlspecialchars($post) . "</p>";
354
979d99a0b00e A few more installer tweaks / fixes. Initted upgrade script. Added migration schema from 1.0 to 1.1.
Dan
parents: 349
diff changeset
   356
      echo "<pre>";
349
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   357
    }
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   358
    
328
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   359
    $this->_fputs($connection, "{$this->method} {$this->uri}{$get} HTTP/1.1{$newline}");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   360
    $this->_fputs($connection, "Host: {$this->host}{$newline}");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   361
    $this->_fputs($connection, $headers);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   362
    $this->_fputs($connection, $cookies);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   363
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   364
    if ( $this->method == 'POST' )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   365
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   366
      // POST-specific parameters
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   367
      $post_length = strlen($post);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   368
      $this->_fputs($connection, "Content-type: application/x-www-form-urlencoded{$newline}");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   369
      $this->_fputs($connection, "Content-length: {$post_length}{$newline}");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   370
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   371
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   372
    $this->_fputs($connection, "Connection: close{$newline}");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   373
    $this->_fputs($connection, "{$newline}");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   374
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   375
    if ( $this->method == 'POST' )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   376
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   377
      $this->_fputs($connection, $post);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   378
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   379
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   380
    if ( $this->debug )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   381
      echo '</pre><p>Request written. Fetching response.</p>';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   382
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   383
    // 2 = request written
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   384
    $this->state = 2;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   385
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   386
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   387
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   388
   * Wrap up and close the socket. Nothing more than a call to fsockclose() except in debug mode.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   389
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   390
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   391
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   392
  function sock_close(&$connection)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   393
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   394
    if ( $this->debug )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   395
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   396
      echo '<p>Response fetched. Closing connection. Response text follows.</p><pre>';
349
fdaf9070566c More progress on the installer. At this point it can install and import the language, but does not rename config files. Still much work to be done, most notably localization and creation of MySQL users and databases.
Dan
parents: 328
diff changeset
   397
      echo htmlspecialchars($this->response);
328
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   398
      echo '</pre></div><hr />';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   399
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   400
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   401
    fclose($connection);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   402
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   403
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   404
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   405
   * Internal function to grab the response code and status string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   406
   * @access string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   407
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   408
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   409
  function _parse_response_code($buffer)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   410
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   411
    // Retrieve response code and status
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   412
    $pos_newline = strpos($buffer, "\n");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   413
    $pos_carriage_return = strpos($buffer, "\r");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   414
    $pos_end_first_line = ( $pos_carriage_return < $pos_newline && $pos_carriage_return > 0 ) ? $pos_carriage_return : $pos_newline;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   415
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   416
    // First line is in format of:
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   417
    // HTTP/1.1 ### Blah blah blah(\r?)\n
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   418
    $response_code = substr($buffer, 9, 3);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   419
    $response_string = substr($buffer, 13, ( $pos_end_first_line - 13 ) );
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   420
    $this->response_code = intval($response_code);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   421
    $this->response_string = $response_string;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   422
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   423
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   424
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   425
   * Internal function to send the request.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   426
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   427
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   428
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   429
  function _send_request()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   430
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   431
    $this->concat_headers($headers, $cookies, $get, $post);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   432
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   433
    if ( $this->state < 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   434
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   435
      $this->_sock_open($this->socket);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   436
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   437
    if ( $this->state < 2 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   438
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   439
      $this->_write_request($this->socket, $headers, $cookies, $get, $post);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   440
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   441
    if ( $this->state == 2 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   442
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   443
      $buffer = $this->_read_until_newlines($this->socket);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   444
      $this->state = 3;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   445
      $this->_parse_response_code($buffer);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   446
      $this->response = $buffer;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   447
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   448
    if ( $this->state == 3 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   449
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   450
      // Determine transfer encoding
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   451
      $is_chunked = preg_match("/Transfer-Encoding: (chunked)\r?\n/", $this->response);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   452
      
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   453
      $buffer = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   454
      while ( !feof($this->socket) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   455
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   456
        $part = fgets($this->socket, 1024);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   457
        if ( $is_chunked && preg_match("/^([a-f0-9]+)\x0D\x0A$/", $part, $match) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   458
        {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   459
          $chunklen = hexdec($match[1]);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   460
          $part = ( $chunklen > 0 ) ? fread($this->socket, $chunklen) : '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   461
          // remove the last newline from $part
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   462
          $part = preg_replace("/\r?\n\$/m", "", $part);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   463
        }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   464
        $buffer .= $part;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   465
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   466
      $this->response .= $buffer;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   467
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   468
    $this->state = 4;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   469
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   470
    $this->sock_close($this->socket);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   471
    $this->socket = false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   472
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   473
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   474
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   475
   * Internal function to send the request but only fetch the headers. Leaves a connection open for a finish-up function.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   476
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   477
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   478
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   479
  function _send_request_headers_only()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   480
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   481
    $this->concat_headers($headers, $cookies, $get, $post);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   482
    
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   483
    if ( $this->state < 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   484
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   485
      $this->_sock_open($this->socket);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   486
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   487
    if ( $this->state < 2 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   488
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   489
      $this->_write_request($this->socket, $headers, $cookies, $get, $post);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   490
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   491
    if ( $this->state == 2 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   492
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   493
      $buffer = $this->_read_until_newlines($this->socket);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   494
      $this->state = 3;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   495
      $this->_parse_response_code($buffer);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   496
      $this->response = $buffer;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   497
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   498
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   499
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   500
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   501
   * Internal function to read from a socket until two consecutive newlines are hit.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   502
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   503
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   504
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   505
  function _read_until_newlines($sock)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   506
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   507
    $prev_char = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   508
    $prev1_char = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   509
    $prev2_char = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   510
    $buf = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   511
    while ( !feof($sock) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   512
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   513
      $chr = fread($sock, 1);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   514
      $buf .= $chr;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   515
      if ( ( $chr == "\n" && $prev_char == "\n" ) ||
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   516
           ( $chr == "\n" && $prev_char == "\r" && $prev1_char == "\n" && $prev2_char == "\r" ) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   517
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   518
        return $buf;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   519
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   520
      $prev2_char = $prev1_char;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   521
      $prev1_char = $prev_char;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   522
      $prev_char = $chr;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   523
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   524
    return $buf;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   525
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   526
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   527
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   528
   * Returns the response text. If the request hasn't been sent, it will be sent here.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   529
   * @return string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   530
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   531
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   532
  function get_response()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   533
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   534
    if ( $this->state == 4 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   535
      return $this->response;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   536
    $this->_send_request();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   537
    return $this->response;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   538
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   539
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   540
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   541
   * Writes the response body to a file. This is good for conserving memory when downloading large files. If the file already exists it will be overwritten.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   542
   * @param string File to write to
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   543
   * @param int Chunk size in KB to read from the socket. Optional and should only be needed in circumstances when extreme memory conservation is needed. Defaults to 768.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   544
   * @param int Maximum file size. Defaults to 0, which means no limit.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   545
   * @return bool True on success, false on failure
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   546
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   547
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   548
  function write_response_to_file($file, $chunklen = 768, $max_file_size = 0)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   549
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   550
    if ( !is_writeable( dirname($file) ) || !file_exists( dirname($file) ) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   551
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   552
      return false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   553
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   554
    $handle = @fopen($file, 'w');
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   555
    if ( !$handle )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   556
      return false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   557
    $chunklen = intval($chunklen);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   558
    if ( $chunklen < 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   559
      return false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   560
    if ( $this->state == 4 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   561
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   562
      // we already have the response, so cheat
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   563
      $response = $this->get_response_body();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   564
      fwrite($handle, $response);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   565
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   566
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   567
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   568
      // read data from the socket, write it immediately, and unset to free memory
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   569
      $headers = $this->get_response_headers();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   570
      $transferred_bytes = 0;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   571
      $bandwidth_exceeded = false;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   572
      // if transfer-encoding is chunked, read using chunk sizes the server specifies
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   573
      $is_chunked = preg_match("/Transfer-Encoding: (chunked)\r?\n/", $this->response);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   574
      if ( $is_chunked )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   575
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   576
        $buffer = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   577
        while ( !feof($this->socket) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   578
        {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   579
          $part = fgets($this->socket, ( 1024 * $chunklen ));
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   580
          // Theoretically if the encoding is really chunked then this should always match.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   581
          if ( $is_chunked && preg_match("/^([a-f0-9]+)\x0D\x0A$/", $part, $match) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   582
          {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   583
            $chunk_length = hexdec($match[1]);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   584
            $part = ( $chunk_length > 0 ) ? fread($this->socket, $chunk_length) : '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   585
            // remove the last newline from $part
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   586
            $part = preg_replace("/\r?\n\$/m", "", $part);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   587
          }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   588
          
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   589
          $transferred_bytes += strlen($part);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   590
          if ( $max_file_size && $transferred_bytes > $max_file_size )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   591
          {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   592
            // truncate output to $max_file_size bytes
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   593
            $partlen = $max_file_size - ( $transferred_bytes - strlen($part) );
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   594
            $part = substr($part, 0, $partlen);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   595
            $bandwidth_exceeded = true;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   596
          }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   597
          fwrite($handle, $part);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   598
          if ( $bandwidth_exceeded )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   599
          {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   600
            break;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   601
          }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   602
        }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   603
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   604
      else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   605
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   606
        $first_chunk = fread($this->socket, ( 1024 * $chunklen ));
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   607
        fwrite($handle, $first_chunk);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   608
        while ( !feof($this->socket) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   609
        {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   610
          $chunk = fread($this->socket, ( 1024 * $chunklen ));
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   611
          
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   612
          $transferred_bytes += strlen($chunk);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   613
          if ( $max_file_size && $transferred_bytes > $max_file_size )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   614
          {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   615
            // truncate output to $max_file_size bytes
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   616
            $partlen = $max_file_size - ( $transferred_bytes - strlen($chunk) );
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   617
            $chunk = substr($chunk, 0, $partlen);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   618
            $bandwidth_exceeded = true;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   619
          }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   620
          
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   621
          fwrite($handle, $chunk);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   622
          unset($chunk);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   623
          
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   624
          if ( $bandwidth_exceeded )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   625
          {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   626
            break;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   627
          }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   628
        }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   629
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   630
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   631
    fclose($handle);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   632
    // close socket and reset state, since we haven't cached the response
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   633
    $this->sock_close($this->socket);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   634
    $this->state = 0;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   635
    return ($bandwidth_exceeded) ? false : true;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   636
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   637
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   638
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   639
   * Returns only the response headers.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   640
   * @return string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   641
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   642
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   643
  function get_response_headers()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   644
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   645
    if ( $this->state == 3 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   646
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   647
      return $this->response;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   648
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   649
    else if ( $this->state == 4 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   650
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   651
      $pos_end = strpos($this->response, "\r\n\r\n");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   652
      $data = substr($this->response, 0, $pos_start);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   653
      return $data;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   654
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   655
    else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   656
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   657
      $this->_send_request_headers_only();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   658
      return $this->response;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   659
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   660
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   661
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   662
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   663
   * Returns only the response headers, as an associative array.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   664
   * @return array
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   665
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   666
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   667
  function get_response_headers_array()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   668
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   669
    $data = $this->get_response_headers();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   670
    preg_match_all("/(^|\n)([A-z0-9_-]+?): (.+?)(\r|\n|\$)/", $data, $matches);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   671
    $headers = array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   672
    for ( $i = 0; $i < count($matches[0]); $i++ )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   673
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   674
      $headers[ $matches[2][$i] ] = $matches[3][$i];
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   675
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   676
    return $headers;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   677
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   678
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   679
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   680
   * Returns only the body (not the headers) of the response. If the request hasn't been sent, it will be sent here.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   681
   * @return string
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   682
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   683
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   684
  function get_response_body()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   685
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   686
    $data = $this->get_response();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   687
    $pos_start = strpos($data, "\r\n\r\n") + 4;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   688
    $data = substr($data, $pos_start);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   689
    return $data;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   690
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   691
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   692
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   693
   * Returns all cookies requested to be set by the server as an associative array. If the request hasn't been sent, it will be sent here.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   694
   * @return array
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   695
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   696
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   697
  function get_cookies()
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   698
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   699
    $data = $this->get_response();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   700
    $data = str_replace("\r\n", "\n", $data);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   701
    $pos = strpos($data, "\n\n");
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   702
    $headers = substr($data, 0, $pos);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   703
    preg_match_all("/Set-Cookie: ([a-z0-9_]+)=([^;]+);( expires=([^;]+);)?( path=(.*?))?\n/", $headers, $cookiematch);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   704
    if ( count($cookiematch[0]) < 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   705
      return array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   706
    $cookies = array();
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   707
    foreach ( $cookiematch[0] as $i => $cookie )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   708
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   709
      $cookies[$cookiematch[1][$i]] = $cookiematch[2][$i];
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   710
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   711
    return $cookies;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   712
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   713
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   714
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   715
   * Internal method to write data to a socket with debugging possibility.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   716
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   717
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   718
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   719
  function _fputs($socket, $data)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   720
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   721
    if ( $this->debug )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   722
      echo htmlspecialchars($data);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   723
    return fputs($socket, $data);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   724
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   725
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   726
  /**
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   727
   * Internal function to stringify cookies, headers, get, and post.
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   728
   * @access private
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   729
   */
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   730
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   731
  function concat_headers(&$headers, &$cookies, &$get, &$post)
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   732
  {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   733
    $headers = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   734
    $cookies = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   735
    foreach ( $this->headers as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   736
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   737
      $value = str_replace('\\n', '\\\\n', $value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   738
      $value = str_replace("\n", '\\n', $value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   739
      $headers .= "$name: $value\r\n";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   740
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   741
    unset($value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   742
    if ( count($this->cookies_out) > 0 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   743
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   744
      $i = 0;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   745
      $cookie_header = 'Cookie: ';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   746
      foreach ( $this->cookies_out as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   747
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   748
        $i++;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   749
        if ( $i > 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   750
          $cookie_header .= '; ';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   751
        $value = str_replace(';', rawurlencode(';'), $value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   752
        $value = str_replace('\\n', '\\\\n', $value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   753
        $value = str_replace("\n", '\\n', $value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   754
        $cookie_header .= "$name=$value";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   755
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   756
      $cookie_header .= "\r\n";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   757
      $cookies = $cookie_header;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   758
      unset($value, $cookie_header);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   759
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   760
    if ( count($this->parms_get) > 0 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   761
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   762
      $get = '?';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   763
      $i = 0;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   764
      foreach ( $this->parms_get as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   765
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   766
        $i++;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   767
        if ( $i > 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   768
          $get .= '&';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   769
        $value = urlencode($value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   770
        if ( !empty($value) )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   771
          $get .= "$name=$value";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   772
        else
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   773
          $get .= "$name";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   774
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   775
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   776
    if ( count($this->parms_post) > 0 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   777
    {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   778
      $post = '';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   779
      $i = 0;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   780
      foreach ( $this->parms_post as $name => $value )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   781
      {
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   782
        $i++;
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   783
        if ( $i > 1 )
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   784
          $post .= '&';
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   785
        $value = urlencode($value);
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   786
        $post .= "$name=$value";
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   787
      }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   788
    }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   789
  }
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   790
  
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   791
}
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   792
dc838fd61a06 Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
parents:
diff changeset
   793
?>