class plugin_utility
{
private $CI;
private $name;
public function __construct($name) {
$this->CI =& get_instance();
$this->name=$name;
if($this->checklang())
{
$this->CI->lang->plg_load($name,$name);
}
}
public function install_db($options)
{
$this->CI->load->dbforge();
if(is_array($options['tables']) && count($options['tables']>0))
{
foreach($options['tables'] as $key=>$table)
{
$this->CI->dbforge->add_field($table['fields']);
if(is_array($table['keys']))
{
foreach($table['keys'] as $k)
{
$this->CI->dbforge->add_key($k, TRUE);
}
}else{
$this->CI->dbforge->add_key($table['keys'], TRUE);
}
if($this->CI->dbforge->create_table($key, TRUE))
{
insert_plugin_headers($this->name);
//enable_plugin($this->name);
$result = array("result" => "ok", "result_message" => "<ul><li>".$this->CI->lang->line('success_plugin_installation')."</li></ul>");
}else{
$result = array("result" => "null", "result_message" => "<ul><li>".$this->CI->lang->line('failure_plugin_installation')."</li></ul>");
}
return $result;
}
}
}
public function uninstall_db($options)
{
$this->CI->load->dbforge();
if(is_array($options['tables']) && count($options['tables']>0))
{
foreach($options['tables'] as $table)
{
if($this->dbforge->drop_table($table,TRUE))
{
$result = array("result" => "ok", "result_message" => "<ul><li>".$this->CI->lang->line('success_plugin_uninstallation')."</li></ul>");
}else{
$result = array("result" => "null", "result_message" => "<ul><li>".$this->CI->lang->line('failure_plugin_uninstallation')."</li></ul>");
}
return $result;
}
}
}
public function copy_controllers()
{
$path=PLUGINPATH.$this->name.'/core/controllers';
$dest_path=FCPATH.'store/controllers';
if(is_dir($path) && is_dir($dest_path))
{
copy_r($path,$dest_path);
}
}
public function delete_controllers()
{
$this->CI->load->helper('directory');
$this->CI->load->helper('directory');
$path=PLUGINPATH.$this->name.'/core/controllers';
$dest_path=FCPATH.'store/controllers';
if(is_dir($path) && is_dir($dest_path))
{
$map = directory_map($path);
foreach($map as $folder=>$file)
{
if(is_array($file))
{
foreach($file as $k=>$v)
{
if(file_exists($dest_path.DIRECTORY_SEPARATOR.$folder.$v))
@unlink($dest_path.DIRECTORY_SEPARATOR.$folder.$v);
}
}else{
if(file_exists($dest_path.DIRECTORY_SEPARATOR.$file))
@unlink($dest_path.DIRECTORY_SEPARATOR.$file);
}
}
}
}
private function checklang()
{
$path=PLUGINPATH.$this->name.'/core/language';
if(is_dir($path))
{
return true;
}
return false;
}
}