1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
<?php
namespace MatthiasWeb\RealMediaLibrary\base;
use MatthiasWeb\RealMediaLibrary\general;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
require_once(RML_INC . 'base/Base.class.php');
abstract class Core extends Base {
const COMPOSER_AUTOLOAD = 'vendor/autoload.php';
private $plugin_data;
private $activator;
private $assets;
protected function __construct() {
define('RML_TD', $this->getPluginData("TextDomain"));
define('RML_VERSION', $this->getPluginData("Version"));
spl_autoload_register(array($this, 'autoloadRegister'));
$composer_path = path_join(RML_PATH, Core::COMPOSER_AUTOLOAD);
if (file_exists($composer_path)) {
include_once($composer_path);
}
$this->activator = new general\Activator();
$this->assets = new general\Assets();
add_action('plugins_loaded', array($this, 'i18n'));
add_action('init', array($this, 'init'));
register_activation_hook(RML_FILE, array($this->getActivator(), 'activate'));
register_deactivation_hook(RML_FILE, array($this->getActivator(), 'deactivate'));
}
public function autoloadRegister($className) {
$namespace = RML_NS . "\\";
if (0 === strpos($className, $namespace)) {
$name = substr($className, strlen($namespace));
$last = explode("\\", $name);
$isInterface = substr($last[count($last) - 1], 0, 1) === "I";
$filename = RML_INC . str_replace('\\', '/', $name) . '.' . ($isInterface ? 'interface' : 'class') . '.php';
if (file_exists($filename)) {
require_once($filename);
}
}
}
public function i18n() {
load_plugin_textdomain( RML_TD, FALSE, RML_PATH . $this->getPluginData("DomainPath") );
}
public function updateDbCheck() {
$installed = get_option( RML_OPT_PREFIX . '_db_version' );
if ($installed != RML_VERSION) {
$this->debug("(Re)install the database tables", __FUNCTION__);
$this->getActivator()->install();
}
}
public function getPluginData($key = null) {
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
$data = isset($this->plugin_data) ? $this->plugin_data : $this->plugin_data = get_plugin_data(RML_FILE, true, false);
return $key === null ? $data : $data[$key];
}
public function getActivator() {
return $this->activator;
}
public function getAssets() {
return $this->assets;
}
}