file = $file;
$this->plgDir = dirname($file);
$this->plgURL = plugin_dir_url($file);
$this->siteUrl = site_url();
$this->wpRoot = parse_url($this->siteUrl, PHP_URL_PATH);
if (empty($this->wpRoot) || $this->wpRoot == DIRECTORY_SEPARATOR) {
$this->wpRoot = "";
}
else {
$this->wpRoot .= DIRECTORY_SEPARATOR;
}
$this->siteUrl .= '/';
$this->keyEp = $this->key . '-ep';
$this->endPoint = $this->siteUrl . $this->keyEp;
$this->isPro = file_exists("{$this->plgDir}/admin/options-advanced.php");
}
if ($this->isPro) {
$this->strPro = 'Pro';
}
else {
$this->strPro = 'Lite';
}
}
static function isEmptyHtaccess($data) {
if (empty($data)) {
return true;
}
$lines = explode("\n", $data);
foreach ($lines as $l) {
$l = trim($l);
if (empty($l)) {
continue;
}
if ($l[0] == '#') {
continue;
}
return false;
}
return true;
}
function mkHtaccess() {
$file = ABSPATH . ".htaccess";
$data = "
# BEGIN WordPress: Inserted by $this->name
RewriteEngine On
RewriteBase $this->wpRoot
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . {$this->wpRoot}index.php [L]
# END WordPress: Inserted by $this->name
";
if (file_exists($file)) {
// Dangerous to create
$currentData = file_get_contents($file);
if (!self::isEmptyHtaccess($currentData)) {
$currentData = htmlspecialchars($currentData);
$data = htmlspecialchars($data);
return "
You already have an .htaccess file ($file) with these contents:
$currentData
Please edit it and add the (pointing all missing files to index.php). Here is what you need to add:
$data
";
}
}
// No htaccess or it is empty. Safe to create a default one.
$url = wp_nonce_url('plugin-install.php', 'plugin-install');
$creds = request_filesystem_credentials($url, '', false, false, ABSPATH);
if ($creds !== false) {
WP_Filesystem($creds);
global $wp_filesystem;
if (!empty($wp_filesystem)) {
$abspath = trailingslashit($wp_filesystem->abspath());
$file = "{$abspath}.htaccess";
if ($wp_filesystem->put_contents($file, "$currentData\n$data")) {
return "A default .htaccess has been created for you.";
}
}
}
else {
// Cannot create a new one.
$data = htmlspecialchars($data);
return "You do not have an .htaccess file and it does not look like I can create one for you. Please create $file and add the (pointing all missing files to index.php). Here is what you need to add:
$data
";
}
}
static function install($dir, $mOptions) {
$ezOptions = get_option($mOptions);
if (empty($ezOptions)) {
// create the necessary tables
$GLOBALS['isInstallingWP'] = true;
chdir($dir . '/admin');
require_once('dbSetup.php');
$ezOptions['isSetup'] = true;
}
update_option($mOptions, $ezOptions);
}
static function uninstall($mOptions) {
delete_option($mOptions);
}
function printAdminPage() {
?>
Loading... Please wait!
mkHtaccess();
$permalink = admin_url('options-permalink.php');
?>
Permalinks are not enabled on your blog, which this plugin needs. Please enable a permalink structure for your blog from Settings → Permalinks. Any structure (other than the ugly default structure using /?p=123) will do. Note that you may need to manually update your .htaccess file in certain installations.
AdBlock: This plugin loads its admin pages in an iFrame, which may look like an ad to some browser-side ad blockers. If you are running AdBlock or similar extensions on your browser, please disable it for your blog domain so that the admin page is not blocked. Looks like your browser is preventing the admin pages from being displayed.
If you think this message is in error, and would like the plugin to try to open the admin page any way, please click the button below:
Note that if the plugin still cannot load the admin page after forcing it, you may see a blank or error page here upon reload. If that happens, please deactivate and delete the plugin. It is not compatible with your blog setup.
endPoint}/admin/{$_REQUEST['target']}";
}
else if (!empty($lastSrc)) {
$src = "{$this->endPoint}/admin/$lastSrc";
}
else {
$src = "{$this->endPoint}/admin/index.php";
}
?>
";
}
function parseRequest(&$wp) {
if (strpos($_SERVER['REQUEST_URI'], $this->keyEp) === false) {
return;
}
$request = $_SERVER['REQUEST_URI'];
if (!empty($this->wpRoot)) {
$request = str_replace($this->wpRoot, "", $_SERVER['REQUEST_URI']);
}
$request = trim($request, DIRECTORY_SEPARATOR);
if (strpos($request, $this->keyEp) !== 0) {
return;
}
$request = preg_replace('/\?.*/', '', $request);
$request = preg_replace("/$this->keyEp/", basename($this->plgDir), $request, 1);
$target = WP_PLUGIN_DIR . "/" . $request;
if (file_exists($target)) {
chdir(dirname($target));
$ext = substr($target, -3);
if ($ext == 'php') {
include $target;
}
else {
$url = str_replace(ABSPATH, $this->siteUrl, $target);
header("location: $url");
}
exit();
}
else {
setcookie('ez-last-request', $request, time() + 30);
$url = "$this->siteUrl$this->keyEp/admin/index.php";
header("location: $url");
exit();
}
}
function pluginActionLinks($links, $file) {
if ($file == plugin_basename($this->file)) {
$settings_link = "Settings";
array_unshift($links, $settings_link);
}
return $links;
}
function adminMenu() {
$mName = "$this->name $this->strPro";
add_options_page($mName, $mName, 'activate_plugins', basename($this->file), array($this, 'printAdminPage'));
}
function init() {
add_action('parse_request', array($this, 'parseRequest'));
add_action('admin_menu', array($this, 'adminMenu'));
add_filter('plugin_action_links', array($this, 'pluginActionLinks'), -10, 2);
register_activation_hook($this->file, array($this->class, 'install'));
register_deactivation_hook($this->file, array($this->class, 'uninstall'));
}
}
} //End Class EzPlugin