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 getServerSoftware() { $server = "unknown"; if (!empty($_SERVER['SERVER_SOFTWARE'])) { $serverSoftware = strtolower($_SERVER['SERVER_SOFTWARE']); } else { $serverSoftware = ""; } if (strpos($serverSoftware, "apache") !== false) { $server = "apache"; } if (strpos($serverSoftware, "nginx") !== false) { $server = "nginx"; } if (strpos($serverSoftware, "microsoft") !== false) { $server = "microsoft"; } return $server; } function getNginxMsg() { $data = 'location / { try_files $uri $uri/ /index.php?q=$request_uri; }'; return "

You are running on nginx. You may have to edit your config file after enabling Permalinks. Please see Nginx instructions. In most cases, all you have to do is to add this to your location block:

$data
"; } function getMSMsg() { return "

You are running on a Microsoft server. Please enable and configure Permalinks. Here is how to do it."; } function getApacheMsg() { return "

You are running on an Apache or a generic server. Please enable and configure Permalinks. Add the standard WordPress directives to your .htaccess file or equivalent."; } function checkPerma() { $permaStructure = get_option('permalink_structure'); if (!empty($permaStructure)) { return; } $server = $this->getServerSoftware(); $msg = ""; switch ($server) { case "nginx": return $this->getNginxMsg(); case "microsoft": return $this->getMSMsg(); default: $msg = "

Depending on your server, follow the steps below.

"; $msg .= $this->getNginxMsg(); $msg .= $this->getMSMsg(); $msg .= $this->getApacheMsg(); case "apache": $file = ABSPATH . ".htaccess"; if (empty($this->wpRoot)) { $wpRoot = "/"; } else { $wpRoot = $this->wpRoot; } $data = " # BEGIN WordPress: Inserted by $this->name RewriteEngine On RewriteBase $wpRoot RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . {$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 "$msg

You already have an .htaccess file ($file) with these contents:

$currentData

Please edit it and add the standard WordPress directives (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 "$msg

A default .htaccess has been created for you.

"; } } } else { // Cannot create a new one. $data = htmlspecialchars($data); return "$msg

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 standard WordPress directives (pointing all missing files to index.php). Here is what you need to add:

$data
"; } break; } } 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); } static function getDB() { if (empty(self::$db)) { require_once 'DbHelper.php'; self::$db = new DbHelper(); } return self::$db; } function printAdminPage() { ?>

Loading  Loading... Please wait!

checkPerma(); $permalink = admin_url('options-permalink.php'); if (!empty($permaMsg)) { ?> key-last-src"); $lastTarget = $this->plgDir . "/admin/" . str_replace('.ezp', '.php', $lastSrc); if (!empty($_REQUEST['target'])) { $src = "{$this->endPoint}/admin/{$_REQUEST['target']}"; } else if (!empty($lastSrc) && file_exists($lastTarget)) { $src = "{$this->endPoint}/admin/$lastSrc"; } else { $src = "{$this->endPoint}/admin/index.ezp"; } ?> "; } 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; $target = preg_replace("/\.ezp$/", ".php", $target, 1); if (file_exists($target)) { chdir(dirname($target)); $ext = pathinfo($target, PATHINFO_EXTENSION); 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.ezp"; 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