From 7bb899d5c6a8b4ba2eed1ac484d63114419ead2d Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 18 Jul 2015 18:36:23 +0300 Subject: [PATCH] cleanup --- ipf/http/request.php | 12 ++-- ipf/http/response.php | 127 ++++++++++++++------------------- ipf/http/response/json.php | 7 +- ipf/http/response/redirect.php | 2 +- ipf/{ => image}/image.php | 28 ++++---- 5 files changed, 80 insertions(+), 96 deletions(-) rename ipf/{ => image}/image.php (93%) diff --git a/ipf/http/request.php b/ipf/http/request.php index 14082e0..d6395eb 100644 --- a/ipf/http/request.php +++ b/ipf/http/request.php @@ -18,10 +18,10 @@ class IPF_HTTP_Request public function __construct() { - $this->POST =& $_POST; - $this->GET =& $_GET; - $this->REQUEST =& $_REQUEST; - $this->COOKIE =& $_COOKIE; + $this->POST = $_POST; + $this->GET = $_GET; + $this->REQUEST = $_REQUEST; + $this->COOKIE = $_COOKIE; $this->FILES = self::saneFiles($_FILES); $this->method = $_SERVER['REQUEST_METHOD']; $this->uri = $_SERVER['REQUEST_URI']; @@ -42,8 +42,8 @@ class IPF_HTTP_Request $this->path_info = $_SERVER['PATH_INFO']; else $this->path_info = '/'; - - $this->SERVER =& $_SERVER; + + $this->SERVER = $_SERVER; $this->is_secure = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; } diff --git a/ipf/http/response.php b/ipf/http/response.php index 429a652..3ae3576 100644 --- a/ipf/http/response.php +++ b/ipf/http/response.php @@ -8,57 +8,53 @@ class IPF_HTTP_Response public $status_code = 200; public $cookies = array(); public $status_code_list = array( - '100' => 'CONTINUE', - '101' => 'SWITCHING PROTOCOLS', - '200' => 'OK', - '201' => 'CREATED', - '202' => 'ACCEPTED', - '203' => 'NON-AUTHORITATIVE INFORMATION', - '204' => 'NO CONTENT', - '205' => 'RESET CONTENT', - '206' => 'PARTIAL CONTENT', - '300' => 'MULTIPLE CHOICES', - '301' => 'MOVED PERMANENTLY', - '302' => 'FOUND', - '303' => 'SEE OTHER', - '304' => 'NOT MODIFIED', - '305' => 'USE PROXY', - '306' => 'RESERVED', - '307' => 'TEMPORARY REDIRECT', - '400' => 'BAD REQUEST', - '401' => 'UNAUTHORIZED', - '402' => 'PAYMENT REQUIRED', - '403' => 'FORBIDDEN', - '404' => 'NOT FOUND', - '405' => 'METHOD NOT ALLOWED', - '406' => 'NOT ACCEPTABLE', - '407' => 'PROXY AUTHENTICATION REQUIRED', - '408' => 'REQUEST TIMEOUT', - '409' => 'CONFLICT', - '410' => 'GONE', - '411' => 'LENGTH REQUIRED', - '412' => 'PRECONDITION FAILED', - '413' => 'REQUEST ENTITY TOO LARGE', - '414' => 'REQUEST-URI TOO LONG', - '415' => 'UNSUPPORTED MEDIA TYPE', - '416' => 'REQUESTED RANGE NOT SATISFIABLE', - '417' => 'EXPECTATION FAILED', - '500' => 'INTERNAL SERVER ERROR', - '501' => 'NOT IMPLEMENTED', - '502' => 'BAD GATEWAY', - '503' => 'SERVICE UNAVAILABLE', - '504' => 'GATEWAY TIMEOUT', - '505' => 'HTTP VERSION NOT SUPPORTED' - ); + '100' => 'CONTINUE', + '101' => 'SWITCHING PROTOCOLS', + '200' => 'OK', + '201' => 'CREATED', + '202' => 'ACCEPTED', + '203' => 'NON-AUTHORITATIVE INFORMATION', + '204' => 'NO CONTENT', + '205' => 'RESET CONTENT', + '206' => 'PARTIAL CONTENT', + '300' => 'MULTIPLE CHOICES', + '301' => 'MOVED PERMANENTLY', + '302' => 'FOUND', + '303' => 'SEE OTHER', + '304' => 'NOT MODIFIED', + '305' => 'USE PROXY', + '306' => 'RESERVED', + '307' => 'TEMPORARY REDIRECT', + '400' => 'BAD REQUEST', + '401' => 'UNAUTHORIZED', + '402' => 'PAYMENT REQUIRED', + '403' => 'FORBIDDEN', + '404' => 'NOT FOUND', + '405' => 'METHOD NOT ALLOWED', + '406' => 'NOT ACCEPTABLE', + '407' => 'PROXY AUTHENTICATION REQUIRED', + '408' => 'REQUEST TIMEOUT', + '409' => 'CONFLICT', + '410' => 'GONE', + '411' => 'LENGTH REQUIRED', + '412' => 'PRECONDITION FAILED', + '413' => 'REQUEST ENTITY TOO LARGE', + '414' => 'REQUEST-URI TOO LONG', + '415' => 'UNSUPPORTED MEDIA TYPE', + '416' => 'REQUESTED RANGE NOT SATISFIABLE', + '417' => 'EXPECTATION FAILED', + '500' => 'INTERNAL SERVER ERROR', + '501' => 'NOT IMPLEMENTED', + '502' => 'BAD GATEWAY', + '503' => 'SERVICE UNAVAILABLE', + '504' => 'GATEWAY TIMEOUT', + '505' => 'HTTP VERSION NOT SUPPORTED', + ); - function __construct($content='', $mimetype=null) + function __construct($content='', $mimetype='text/html; charset=utf-8') { - if (is_null($mimetype)) { - $mimetype = IPF::get('mimetype', 'text/html').'; charset=utf-8'; - } $this->content = $content; $this->headers['Content-Type'] = $mimetype; - $this->headers['X-Powered-By'] = 'IPF - http://ipf.icmconsulting.com/'; $this->status_code = 200; $this->cookies = array(); } @@ -80,31 +76,18 @@ class IPF_HTTP_Response function outputHeaders() { - if (!defined('IN_UNIT_TESTS')) { - header('HTTP/1.1 '.$this->status_code.' ' - .$this->status_code_list[$this->status_code], - true, $this->status_code); - foreach ($this->headers as $header => $ch) { - header($header.': '.$ch); - } - if ($this->short_session) - $exp = 0; - else - $exp = time()+31536000; - foreach ($this->cookies as $cookie => $data) { - // name, data, expiration, path, domain, secure, http only - setcookie($cookie, $data, - $exp, - IPF::get('cookie_path', '/'), - IPF::get('cookie_domain', null), - IPF::get('cookie_secure', false), - IPF::get('cookie_httponly', true)); - } - } else { - $_COOKIE = array(); - foreach ($this->cookies as $cookie => $data) { - $_COOKIE[$cookie] = $data; - } + header('HTTP/1.1 '.$this->status_code.' ' + .$this->status_code_list[$this->status_code], + true, $this->status_code); + foreach ($this->headers as $header => $ch) { + header($header.': '.$ch); + } + foreach ($this->cookies as $cookie => $data) { + setcookie($cookie, $data, time() + 31536000, + IPF::get('cookie_path', '/'), + IPF::get('cookie_domain', null), + IPF::get('cookie_secure', false), + IPF::get('cookie_httponly', true)); } } diff --git a/ipf/http/response/json.php b/ipf/http/response/json.php index 8d0a89c..97fddf9 100644 --- a/ipf/http/response/json.php +++ b/ipf/http/response/json.php @@ -1,8 +1,9 @@ Please, click here to be redirected.'), $url); + $content = sprintf('%s', $url, __('Please, click here to be redirected.')); parent::__construct($content); $this->headers['Location'] = $url; $this->status_code = 302; diff --git a/ipf/image.php b/ipf/image/image.php similarity index 93% rename from ipf/image.php rename to ipf/image/image.php index 56f9b1e..df7895b 100644 --- a/ipf/image.php +++ b/ipf/image/image.php @@ -236,24 +236,24 @@ class IPF_Image public function replaceColor($from, $to, $colorOnly=true) { - $from = $this->color($from); - $to = $this->color($to); + $from = $this->color($from); + $to = $this->color($to); if ($colorOnly) { $from = $from & 0xFFFFFF; $to = $to & 0xFFFFFF; - } - for ($y = 0; $y < $this->height; ++$y) { - for ($x = 0; $x < $this->width; ++$x) { - $at = imagecolorat($this->image, $x, $y); + } + for ($y = 0; $y < $this->height; ++$y) { + for ($x = 0; $x < $this->width; ++$x) { + $at = imagecolorat($this->image, $x, $y); if ($colorOnly) { - if (($at & 0xFFFFFF) === $from) - imagesetpixel($this->image, $x, $y, $to | ($at & 0x7F000000)); - } else { - if ($at === $from) - imagesetpixel($this->image, $x, $y, $to); - } - } - } + if (($at & 0xFFFFFF) === $from) + imagesetpixel($this->image, $x, $y, $to | ($at & 0x7F000000)); + } else { + if ($at === $from) + imagesetpixel($this->image, $x, $y, $to); + } + } + } } } -- 2.49.0