| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Give Readme Parser |
| 5 |
* |
| 6 |
* @package Give |
| 7 |
* @since 2.1.4 |
| 8 |
* @copyright Copyright (c) 2018, GiveWP |
| 9 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 10 |
* @subpackage Admin/Readme_Parser |
| 11 |
*/ |
| 12 |
class Give_Readme_Parser |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Readme file url |
| 16 |
* |
| 17 |
* @since 2.1.4 |
| 18 |
* @access private |
| 19 |
* @var |
| 20 |
*/ |
| 21 |
private $file_url; |
| 22 |
|
| 23 |
/** |
| 24 |
* Give_Readme_Parser constructor. |
| 25 |
* |
| 26 |
* @param string $file_url |
| 27 |
*/ |
| 28 |
public function __construct(string $file_url) |
| 29 |
{ |
| 30 |
$this->file_url = $file_url; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get required Give core minimum version for addon |
| 35 |
* |
| 36 |
* @since 2.1.4 |
| 37 |
* @access public |
| 38 |
* |
| 39 |
* @return string |
| 40 |
*/ |
| 41 |
public function requires_at_least() |
| 42 |
{ |
| 43 |
// Regex to extract Give core minimum version from the readme.txt file. |
| 44 |
preg_match('/Requires (Give|GiveWP):(.*)/i', $this->get_readme_file_content(), $_requires_at_least); |
| 45 |
|
| 46 |
if (is_array($_requires_at_least) && 3 === count($_requires_at_least)) { |
| 47 |
$_requires_at_least = trim($_requires_at_least[2]); |
| 48 |
} else { |
| 49 |
$_requires_at_least = null; |
| 50 |
} |
| 51 |
|
| 52 |
return $_requires_at_least; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @since 2.21.0 |
| 57 |
*/ |
| 58 |
protected function get_readme_file_content(): string |
| 59 |
{ |
| 60 |
return wp_remote_retrieve_body(wp_remote_get($this->file_url)); |
| 61 |
} |
| 62 |
} |
| 63 |
|