| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package RSFirewall! |
| 4 |
* @copyright (c) 2018 RSJoomla! |
| 5 |
* @link https://www.rsjoomla.com |
| 6 |
* @license GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'WPINC' ) ) { |
| 10 |
die; |
| 11 |
} |
| 12 |
|
| 13 |
class RSFirewall_Model |
| 14 |
{ |
| 15 |
/** |
| 16 |
* Holds extended class filename (eg. RSFirewall_Model_Configuration => configuration) |
| 17 |
*/ |
| 18 |
protected $filename; |
| 19 |
|
| 20 |
/** |
| 21 |
* Holds form properties |
| 22 |
*/ |
| 23 |
public $form; |
| 24 |
|
| 25 |
/** |
| 26 |
* Holds the rsfirewall version |
| 27 |
*/ |
| 28 |
protected $version; |
| 29 |
|
| 30 |
/** |
| 31 |
* Holds the post types prefix |
| 32 |
*/ |
| 33 |
protected $prefix = RSFIREWALL_POSTS_PREFIX; |
| 34 |
|
| 35 |
public function __construct() |
| 36 |
{ |
| 37 |
// Get filename |
| 38 |
$this->filename = str_ireplace('RSFirewall_Model_', '', strtolower(get_class($this))); |
| 39 |
|
| 40 |
// Sanitize filename |
| 41 |
$this->filename = preg_replace('/[^a-z0-9_]/', '', $this->filename); |
| 42 |
|
| 43 |
// Remove the Pro part if any |
| 44 |
$this->filename = RSFirewall_Helper::removeProPart($this->filename); |
| 45 |
|
| 46 |
// Load the version number |
| 47 |
$this->version = RSFirewall::get_instance()->get_version(); |
| 48 |
|
| 49 |
/** |
| 50 |
* Load form |
| 51 |
*/ |
| 52 |
$path = RSFIREWALL_BASE . 'models/' . $this->filename . '.xml'; |
| 53 |
$pro_path = RSFIREWALL_BASE . 'proversion/models/' . $this->filename . '.xml'; |
| 54 |
|
| 55 |
// Load the Pro one, if exists |
| 56 |
if (file_exists($pro_path)) |
| 57 |
{ |
| 58 |
$this->form = new RSFirewall_Form($pro_path); |
| 59 |
} else if (file_exists($path)) |
| 60 |
{ |
| 61 |
$this->form = new RSFirewall_Form($path); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Gets an instance to the requested model |
| 67 |
* |
| 68 |
* @return RSFirewall_Model |
| 69 |
*/ |
| 70 |
public static function get_instance() |
| 71 |
{ |
| 72 |
static $instances = array(); |
| 73 |
|
| 74 |
$class = get_called_class(); |
| 75 |
|
| 76 |
if ( empty($instances[$class]) ) |
| 77 |
{ |
| 78 |
$instances[$class] = new $class; |
| 79 |
} |
| 80 |
|
| 81 |
return $instances[$class]; |
| 82 |
} |
| 83 |
} |