<?php

//////////////////////////////////////////////////////////////
//===========================================================
// mods.php(For individual softwares)
//===========================================================
// SOFTACULOUS 
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       10th Jan 2009
// Time:       21:00 hrs
// Site:       http://www.softaculous.com/ (SOFTACULOUS)
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.softaculous.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Inc.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('SOFTACULOUS')){

	die('Hacking Attempt');

}


/**
 * This function will allow you to modify the XML that is being passed.
 * You can modify it here and Softaculous will parse it as it parses the XML of install.xml of packages.
 *
 * @package      softaculous
 * @subpackage   scripts
 * @author       Pulkit Gupta
 * @param        string $str The key of the Language string array.
 * @return       string The parsed string if there was a equivalent language key otherwise the key itself if no key was defined.
 * @since     	 1.0
 */
/*function __wp_mod_install_xml($xml){
	
	global $__settings, $settings, $error, $software, $globals, $softpanel, $notes, $adv_software;
	
}*/

/**
 * This function will parse your mod_install.xml and shows an option of choose plugin to users 
 *
 * @package      softaculous
 * @subpackage   scripts
 * @author       Pulkit Gupta
 * @param        string $str The key of the Language string array.
 * @return       string The parsed string if there was a equivalent language key otherwise the key itself if no key was defined.
 * @since     	 1.0
 */
function __wp_mod_settings(){
	
	global $__settings, $settings, $error, $software, $globals, $softpanel, $notes, $adv_software;
	
	$install = @implode(file($globals['path'].'/conf/mods/'.$software['softname'].'/mod_install.xml'));
	
	$install = parselanguages($install);
	
	$tmp_settings = array();
	
	if(preg_match('/<softinstall (.*?)>(.*?)<\/softinstall>/is', $install)){
		
		$tmp_settings = load_settings($install, $adv_software, 1);
	}
	
	$key = parselanguages('{{select_plugins}}');
		
	$settings[$key] = array_merge($settings[$key], $tmp_settings[$key]);
	
}

/**
 * If anything is needed to be execute before the installation procedure starts than it should be done here.
 *
 * @package      softaculous
 * @subpackage   scripts
 * @author       Pulkit Gupta
 * @param        string $str The key of the Language string array.
 * @return       string The parsed string if there was a equivalent language key otherwise the key itself if no key was defined.
 * @since     	 1.0
 */
function __pre_mod_install(){
	
	global $__settings, $settings, $error, $software, $globals, $softpanel, $notes, $adv_software;
	
}

/**
 * If anything is needed to be execute after the installation procedure starts than it should be done here.
 *
 * @package      softaculous
 * @subpackage   scripts
 * @author       Pulkit Gupta
 * @param        string $str The key of the Language string array.
 * @return       string The parsed string if there was a equivalent language key otherwise the key itself if no key was defined.
 * @since     	 1.0
 */
function __post_mod_install(){
	
	global $__settings, $settings, $error, $software, $globals, $softpanel, $notes, $adv_software;
	
	$__settings['active_plugins'] = array();
	
	// First get the active plugin list 
	$query = "SELECT option_value FROM ".$__settings['dbprefix']."options WHERE option_name = 'active_plugins';";
	$result = sdb_query($query, $__settings['softdbhost'], $__settings['softdbuser'], $__settings['softdbpass'], $__settings['softdb']);
	
	$__settings['active_plugins'] = _unserialize($result[0]['option_value']);
	
	// Check which plugin is checked for instllation
	if(!empty($__settings['wordfence'])||!empty($__settings['automatic-plugin-updates'])||!empty($__settings['anti-spam'])){
		
		// Do the file related changes here :)
		if(file_exists($globals['path'].'/conf/mods/'.$software['softname'].'/wordfence.zip')){
			if(!sunzip($globals['path'].'/conf/mods/'.$software['softname'].'/wordfence.zip', $__settings['softpath'].'/wp-content/plugins/')){
				$error[] = 'Could not unzip the plugin files - wordfence.zip';
			}
		}

		// Do the file related changes here :)
                if(file_exists($globals['path'].'/conf/mods/'.$software['softname'].'/automatic-plugin-updates.zip')){
                        if(!sunzip($globals['path'].'/conf/mods/'.$software['softname'].'/automatic-plugin-updates.zip', $__settings['softpath'].'/wp-content/plugins/')){
                                $error[] = 'Could not unzip the plugin files - automatic-plugin-updates.zip';
                        }
                }
		
		// Do the file related changes here :)
                if(file_exists($globals['path'].'/conf/mods/'.$software['softname'].'/anti-spam.zip')){
                        if(!sunzip($globals['path'].'/conf/mods/'.$software['softname'].'/anti-spam.zip', $__settings['softpath'].'/wp-content/plugins/')){
                                $error[] = 'Could not unzip the plugin files - anti-spam.zip';
                        }
                }
		
		// MKDIR some files (If needed uncomment the following line and change the directory name as per your requirement)
		//@smkdir($__settings['softpath'].'/wp-content/uploads/', $globals['odc']);
	
		// CHMOD some files (If needed uncomment the following line and change the directory name as per your requirement)
		//@schmod($__settings['softpath'].'/wp-content/uploads/', $globals['odc']);
		
		if(!empty($__settings['wordfence']))
			$__settings['active_plugins'][] = 'wordfence/wordfence.php';
		if(!empty($__settings['automatic-plugin-updates']))
			$__settings['active_plugins'][] = 'automatic-plugin-updates/automatic-plugin-updates.php';		
		if(!empty($__settings['anti-spam']))
			$__settings['active_plugins'][] = 'anti-spam/anti-spam.php';

		// Now make the SQL related changes (If required)
		$query = "CREATE TABLE IF NOT EXISTS `".$__settings['dbprefix']."smart_maintenance_mode` (
				  `rid` int(10) NOT NULL AUTO_INCREMENT,
				  `start` bigint(20) NOT NULL,
				  `end` bigint(20) NOT NULL,
				  `status` tinyint(2) NOT NULL DEFAULT '1',
				  `date` int(10) NOT NULL,
				  PRIMARY KEY (`rid`)
				) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
				
		//$result = sdb_query($query, $__settings['softdbhost'], $__settings['softdbuser'], $__settings['softdbpass'], $__settings['softdb']);
		
		$query = "INSERT INTO ".$__settings['dbprefix']."options (option_name, option_value) VALUES ('smm_version', '1.3.1'), ('disable_smm', '0');";
		//$result = sdb_query($query, $__settings['softdbhost'], $__settings['softdbuser'], $__settings['softdbpass'], $__settings['softdb']);
		
	}
	
	// This should be at the end (As there may be many plugins)
	$__settings['active_plugins'] = serialize($__settings['active_plugins']);
	
	$query = "UPDATE ".$__settings['dbprefix']."options
			SET option_value = '".$__settings['active_plugins']."' 
			WHERE option_name = 'active_plugins';";
	$result = sdb_query($query, $__settings['softdbhost'], $__settings['softdbuser'], $__settings['softdbpass'], $__settings['softdb']);
	
}

?>
