Skip to content

Commit f91b642

Browse files
committed
Merge branch 'develop' into enhance/testing
2 parents 8f7cd91 + d8ec4a5 commit f91b642

File tree

25 files changed

+776
-363
lines changed

25 files changed

+776
-363
lines changed

application/Filters/Honeypot.php

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
1-
<?php namespace App\Filters;
1+
<?php
2+
3+
namespace App\Filters;
24

35
use CodeIgniter\Filters\FilterInterface;
46
use CodeIgniter\HTTP\RequestInterface;
57
use CodeIgniter\HTTP\ResponseInterface;
68
use Config\Services;
79
use CodeIgniter\Honeypot\Exceptions\HoneypotException;
10+
use CodeIgniter\Honeypot\Honeypot;
811

9-
class Honeypot implements FilterInterface
12+
class Honeypot implements FilterInterface
1013
{
1114

12-
/**
13-
* Checks if Honeypot field is empty, if so
14-
* then the requester is a bot,show a blank
15-
* page
15+
/**
16+
* Checks if Honeypot field is empty; if not
17+
* then the requester is a bot
1618
*
17-
* @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
19+
* @param CodeIgniter\HTTP\RequestInterface $request
1820
*
1921
* @return mixed
2022
*/
23+
public function before(RequestInterface $request)
24+
{
25+
$honeypot = new Honeypot(new \Config\Honeypot());
26+
if ($honeypot->hasContent($request))
27+
{
28+
throw HoneypotException::isBot();
29+
}
30+
}
2131

22-
public function before (RequestInterface $request)
23-
{
24-
25-
// Checks honeypot field if value was entered then show blank if so.
26-
27-
$honeypot = Services::honeypot(new \Config\Honeypot());
28-
if($honeypot->hasContent($request))
29-
{
30-
throw HoneypotException::isBot();
31-
}
32-
33-
}
34-
35-
/**
36-
* Checks if Honeypot field is empty, if so
37-
* then the requester is a bot,show a blank
38-
* page
32+
/**
33+
* Attach a honypot to the current response.
3934
*
40-
* @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request
41-
* @param ResponseInterface|\CodeIgniter\HTTP\Response $response
35+
* @param CodeIgniter\HTTP\RequestInterface $request
36+
* @param CodeIgniter\HTTP\ResponseInterface $response
4237
* @return mixed
4338
*/
39+
public function after(RequestInterface $request, ResponseInterface $response)
40+
{
41+
$honeypot = new Honeypot(new \Config\Honeypot());
42+
$honeypot->attachHoneypot($response);
43+
}
4444

45-
public function after (RequestInterface $request, ResponseInterface $response)
46-
{
47-
48-
$honeypot = Services::honeypot(new \Config\Honeypot());
49-
$honeypot->attachHoneypot($response);
50-
}
5145
}

system/API/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected function format($data = null)
346346

347347
// Determine correct response type through content negotiation
348348
$config = new Format();
349-
$format = $this->request->negotiate('media', $config->supportedResponseFormats, true);
349+
$format = $this->request->negotiate('media', $config->supportedResponseFormats, false);
350350

351351
$this->response->setContentType($format);
352352

system/Database/BaseResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function getCustomRowObject($n, string $className)
344344

345345
if ($n !== $this->currentRow && isset($this->customResultObject[$className][$n]))
346346
{
347-
$this->current_row = $n;
347+
$this->currentRow = $n;
348348
}
349349

350350
return $this->customResultObject[$className][$this->currentRow];

system/Database/BaseUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function getXMLFromResult(ResultInterface $query, $params = [])
301301
extract($params);
302302

303303
// Load the xml helper
304-
// get_instance()->load->helper('xml');
304+
helper('xml');
305305
// Generate the result
306306
$xml = '<' . $root . '>' . $newline;
307307
while ($row = $query->getUnbufferedRow())

system/Database/MySQLi/Utils.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php namespace CodeIgniter\Database\MySQLi;
2+
3+
/**
4+
* CodeIgniter
5+
*
6+
* An open source application development framework for PHP
7+
*
8+
* This content is released under the MIT License (MIT)
9+
*
10+
* Copyright (c) 2014-2018 British Columbia Institute of Technology
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining a copy
13+
* of this software and associated documentation files (the "Software"), to deal
14+
* in the Software without restriction, including without limitation the rights
15+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
* copies of the Software, and to permit persons to whom the Software is
17+
* furnished to do so, subject to the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be included in
20+
* all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28+
* THE SOFTWARE.
29+
*
30+
* @package CodeIgniter
31+
* @author CodeIgniter Dev Team
32+
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
33+
* @license https://opensource.org/licenses/MIT MIT License
34+
* @link https://codeigniter.com
35+
* @since Version 3.0.0
36+
* @filesource
37+
*/
38+
39+
/**
40+
* Utils for MySQLi
41+
*/
42+
class Utils extends \CodeIgniter\Database\BaseUtils
43+
{
44+
45+
/**
46+
* List databases statement
47+
*
48+
* @var string
49+
*/
50+
protected $listDatabases = 'SHOW DATABASES';
51+
52+
/**
53+
* OPTIMIZE TABLE statement
54+
*
55+
* @var string
56+
*/
57+
protected $optimizeTable = 'OPTIMIZE TABLE %s';
58+
59+
//--------------------------------------------------------------------
60+
61+
/**
62+
* Platform dependent version of the backup function.
63+
*
64+
* @param array|null $prefs
65+
*
66+
* @return mixed
67+
*/
68+
public function _backup(array $prefs = null)
69+
{
70+
throw new DatabaseException('Unsupported feature of the database platform you are using.');
71+
}
72+
73+
//--------------------------------------------------------------------
74+
}

system/HTTP/Files/UploadedFile.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,5 +373,26 @@ public function isValid(): bool
373373
return is_uploaded_file($this->path) && $this->error === UPLOAD_ERR_OK;
374374
}
375375

376+
/**
377+
* Save the uploaded file to a new location.
378+
*
379+
* By default.upload files are saved in writable/uploads directory. the YYYYMMDD folder
380+
* and random file name will be created.
381+
*
382+
* @param string $folderName the folder name to writable/uploads directory.
383+
* @param string $fileName the name to rename the file to.
384+
* @return string file full path
385+
*/
386+
public function store($folderName = null, $fileName = null) : string
387+
{
388+
$folderName = $folderName ?? date('Ymd');
389+
$fileName = $fileName ?? $this->getRandomName();
390+
391+
// Move the uploaded file to a new location.
392+
if ($this->move(WRITEPATH . 'uploads/' . $folderName, $fileName)) {
393+
return $folderName . DIRECTORY_SEPARATOR . $this->name;
394+
}
395+
}
396+
376397
//--------------------------------------------------------------------
377398
}

system/HTTP/RedirectResponse.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,30 +139,6 @@ public function withInput()
139139
return $this;
140140
}
141141

142-
/**
143-
* Makes it so that the URL used for the redirect will include
144-
* the Query variables in the current request.
145-
*
146-
* Using the $options array, can specify either only certain
147-
* keys, or all except some vars.
148-
*
149-
* NOTE: Should be called after either to() or route()
150-
*
151-
* @param array $options
152-
*
153-
* @return \CodeIgniter\HTTP\RedirectResponse
154-
*/
155-
public function withQuery(array $options = [])
156-
{
157-
$queryVars = service('request')->uri->getQuery($options);
158-
159-
$url = $this->getHeaderLine('Location');
160-
161-
$this->setHeader('Location', $url.'?'.$queryVars);
162-
163-
return $this;
164-
}
165-
166142
/**
167143
* Adds a key and message to the session as Flashdata.
168144
*

system/Helpers/form_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s
9292
{
9393
foreach ($hidden as $name => $value)
9494
{
95-
$form .= '<input type="hidden" name="' . $name . '" value="' . $value . '" style="display: none;" />' . "\n";
95+
$form .= '<input type="hidden" name="' . $name . '" value="' . esc($value,'html') . '" style="display: none;" />' . "\n";
9696
}
9797
}
9898

@@ -171,7 +171,7 @@ function form_hidden($name, $value = '', bool $recursing = false): string
171171

172172
if ( ! is_array($value))
173173
{
174-
$form .= '<input type="hidden" name="' . $name . '" value="' . $value . "\" />\n";
174+
$form .= '<input type="hidden" name="' . $name . '" value="' . esc($value,'html') . "\" />\n";
175175
}
176176
else
177177
{

system/Helpers/url_helper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ function prep_url($str = ''): string
575575
* human-friendly URL string with a "separator" string
576576
* as the word separator.
577577
*
578-
* @todo Remove old 'dash' and 'underscore' usage in 3.1+.
579578
* @param string $str Input string
580579
* @param string $separator Word separator (usually '-' or '_')
581580
* @param bool $lowercase Whether to transform the output string to lowercase

system/Helpers/xml_helper.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* CodeIgniter
4+
*
5+
* An open source application development framework for PHP
6+
*
7+
* This content is released under the MIT License (MIT)
8+
*
9+
* Copyright (c) 2014-2018 British Columbia Institute of Technology
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining a copy
12+
* of this software and associated documentation files (the "Software"), to deal
13+
* in the Software without restriction, including without limitation the rights
14+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
* copies of the Software, and to permit persons to whom the Software is
16+
* furnished to do so, subject to the following conditions:
17+
*
18+
* The above copyright notice and this permission notice shall be included in
19+
* all copies or substantial portions of the Software.
20+
*
21+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
* THE SOFTWARE.
28+
*
29+
* @package CodeIgniter
30+
* @author CodeIgniter Dev Team
31+
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
32+
* @license https://opensource.org/licenses/MIT MIT License
33+
* @link https://codeigniter.com
34+
* @since Version 1.0.0
35+
* @filesource
36+
*/
37+
if ( ! function_exists('xml_convert'))
38+
{
39+
/**
40+
* Convert Reserved XML characters to Entities
41+
*
42+
* @param string
43+
* @param bool
44+
* @return string
45+
*/
46+
function xml_convert(string $str, $protect_all = FALSE): string
47+
{
48+
$temp = '__TEMP_AMPERSANDS__';
49+
50+
// Replace entities to temporary markers so that
51+
// ampersands won't get messed up
52+
$str = preg_replace('/&#(\d+);/', $temp.'\\1;', $str);
53+
54+
if ($protect_all === TRUE)
55+
{
56+
$str = preg_replace('/&(\w+);/', $temp.'\\1;', $str);
57+
}
58+
59+
$str = str_replace(
60+
['&', '<', '>', '"', "'", '-'],
61+
['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'],
62+
$str
63+
);
64+
65+
// Decode the temp markers back to entities
66+
$str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str);
67+
68+
if ($protect_all === TRUE)
69+
{
70+
return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str);
71+
}
72+
73+
return $str;
74+
}
75+
}

0 commit comments

Comments
 (0)