an error occured! You may not be able to access this plugin via direct URL...';
exit();
}
else if (!defined('ABSPATH'))
{
echo '
an error occured! You may not be able to access this plugin via direct URL...
';
exit();
}
/**/
if (!class_exists('wpjsloadbymdz_admin'))
{
class wpjsloadbymdz_admin
{
//Props
private static $instance;
//constructor
public function __Construct()
{
//$is_active = get_option('wpjsloadbymdz_activate');
//var_dump($is_active);
//activate & deactivate hooks
register_activation_hook(WPJSLOADBYMDZ_PLG, array($this, 'onactivate'));
register_deactivation_hook(WPJSLOADBYMDZ_PLG, array($this, 'ondeactivate'));
$this->checkfirstredirect(); //redirect on first time activation
$this->deactivationConfirmation(); //Confirm to empty or not the data
//Check plugin verison
$version = get_option('wpjsloader_plg_version');
if(!$version || $version == false || empty($version)){
$version = '1.0.00';
update_option('wpjsloader_plg_version', WPJSLOADBYMDZ_VER, false);
}
//$this->write_to_file($this->logger, '$version is: '.$version);//TMP
if(version_compare($version, WPJSLOADBYMDZ_VER, '<') && !empty($version)) {//Just runs after an update
update_option('wpjsloader_plg_version', WPJSLOADBYMDZ_VER, false);
//remove & renew mu-plg contents
$this->create_mu_plg(2, 'admin-class version-compare');
$this->create_mu_plg(1, 'admin-class version-compare');
/***/
}
/***/
//add menue
add_action('admin_menu', array($this, 'addmenue'));
}
//METHODS
public static function get_instance()
{
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
public function onactivate()
{
add_option('wpjsloadbymdz_empty_onDeactivate', 0, false);
add_option('wpjsloadbymdz_redirect_onActivate', 1, false);
//First-Time-Load Enhancer
$use_ftl_enhancer = get_option('wpjsloader_use_ftl');
if($use_ftl_enhancer == 1){
$this->create_mu_plg(1, 'onactivate method');//adds the mu-plg!
}
/***/
//Enable the plugin for the first-time!
$is_active = get_option('wpjsloadbymdz_activate', '__NOT_EXISTS__');
if($is_active === '__NOT_EXISTS__'){
update_option('wpjsloadbymdz_activate', 1);
}
/***/
}
public function ondeactivate()
{
update_option('wpjsloadbymdz_redirect_onActivate', 1, false);
$this->create_mu_plg(2, 'ondeactivate method');//remove the mu-plg!
}
//checks to do redirect on activation or not
public function checkfirstredirect()
{
global $pagenow;
$do_redirect = get_option('wpjsloadbymdz_redirect_onActivate');
if ($pagenow == 'plugins.php' && $do_redirect == '1'){
add_action('admin_footer', array($this, 'doredirect'));
}
}
//do redirect
public function doredirect()
{
?>
has_plg('ajax-loader-bymdez.php') && defined('WPJSLOADBYMDZ_VER')){
return true;
}else return false;
break;
case '2':
case 2:
return get_option('wpjsloadbymdz_activate');
break;
case '3':
case 3:
if(get_option('wpjsloadbymdz_activate') == 1){
return false;
}else return true;
break;
case '4':
case 4:
if($this->has_plg('ajax-loader-pro-bymdez.php') && defined('WPJSLOADBPROYMDZ_VER')){
return 3;
}else return 4;
break;
case '5':
case 5:
if(is_user_logged_in()){
return false;
}else return true;
break;
case '6':
case 6:
if($this->has_plg('ajax-loader-pro-bymdez.php') && defined('WPJSLOADBPROYMDZ_VER')){
return 15;
}else return true;
break;
default:
break;
}
}
//Set Options Autoload off (no)
private function set_autoload_off($option)
{
$tmp_option_val = get_option($option);
delete_option($option);
add_option($option, $tmp_option_val, '', false);
}
//Mu-Plugins
private function create_mu_plg($mode=1, $where='default')
{
/**
* mode-1 => Creates the mu-php file
* mode-2 => Removes the mu-php file
*/
$logger_file = WPJSLOADBYMDZ_PATH.DIRECTORY_SEPARATOR.'log.txt';
$this->write_to_file($logger_file, 'MTD: `create_mu_plg` Runned form the: '.$where.' with mode: '.$mode.' On: '.date("Y/m/d H:i:s"));
$php_file = 'wpjsloadbymdz-waitingpage.php';
$mu_plgs_dir = trailingslashit(ABSPATH.DIRECTORY_SEPARATOR.'wp-content'.DIRECTORY_SEPARATOR.'mu-plugins');
$php_file_dir = $mu_plgs_dir.$php_file;
switch($mode){
case '1':
case 1:
if (!is_dir($mu_plgs_dir)) {
mkdir($mu_plgs_dir, 0755, true); // Make directory recursive
}
//remove the old-file is is exist
if(file_exists($php_file_dir)){
$file_rem_res = unlink($php_file_dir);
if(!$file_rem_res){
$this->write_to_file($logger_file, 'Unable to remove the mu-plugin php file!! error: '.$error);
}else $this->write_to_file($logger_file, 'mu-plugin php file removed successfully!');
}
/***/
$new_file = fopen($php_file_dir, 'w');
if($new_file === false){
$error = error_get_last();
$this->write_to_file($logger_file, 'Unable to create our own php-file (mu-plugin)! error: '.$error);
}else {
$php_tmp_file = WPJSLOADBYMDZ_PATH.'mu-plugins'.DIRECTORY_SEPARATOR.'wpjsloadbymdz-waitingpage-php.txt';
if(is_file($php_tmp_file) && file_exists($php_tmp_file)){
$php_conts = file_get_contents($php_tmp_file);
if(!empty($php_conts)){
$this->write_to_file($php_file_dir , $php_conts, 1);
}else $this->write_to_file($logger_file, 'Unable to write php codes into the mu-plg php file cause of empty contents!');
}
}
break;
case '2':
case 2:
//Delete mu-plugin
if(is_file($php_file_dir) && file_exists($php_file_dir)){
unlink($php_file_dir);
}
/***/
break;
}
}
/***/
//file-writer
public function write_to_file($file, $contents, $new=0)
{
if(is_file($file) && file_exists($file)){
if($new == 0){
$last_conts = file_get_contents($file);
$new_conts = $last_conts."\n".$contents;
}else $new_conts = $contents;
$res = file_put_contents($file, $new_conts);
return $res;
}
return 'error-file-not-found';
}
}
}
//init
wpjsloadbymdz_admin::get_instance();
//close the PHP tag to reduce the blank spaces ?>