Commits

Ahmed Youssef committed 67ea779

moving to more modules

Comments (0)

Files changed (122)

application/config/autoload.php

 |	$autoload['libraries'] = array('database', 'session', 'xmlrpc');
 */
 
-$autoload['libraries'] = array('database', 'session', 'xmlrpc');
+$autoload['libraries'] = array('database', 'session', 'xmlrpc', 'template');
 
 
 /*

application/config/config.php

 | path to your installation.
 |
 */
-$config['base_url']	= "http://127.0.0.1/hewarforum2";
+$config['base_url']	= "http://127.0.0.1/hewarforum3";
 
 /*
 |--------------------------------------------------------------------------

application/config/template.php

+<?php defined('BASEPATH') OR exit('No direct script access allowed');
+
+/*
+|--------------------------------------------------------------------------
+| Parser Enabled
+|--------------------------------------------------------------------------
+|
+| Should the Parser library be used for the entire page?
+|
+| Can be overridden with $this->template->enable_parser(TRUE/FALSE);
+|
+|   Default: TRUE
+|
+*/
+
+$config['parser_enabled'] = TRUE;
+
+/*
+|--------------------------------------------------------------------------
+| Parser Enabled for Body
+|--------------------------------------------------------------------------
+|
+| If the parser is enabled, do you want it to parse the body or not?
+|
+| Can be overridden with $this->template->enable_parser(TRUE/FALSE);
+|
+|   Default: FALSE
+|
+*/
+
+$config['parser_body_enabled'] = FALSE;
+
+/*
+|--------------------------------------------------------------------------
+| Title Separator
+|--------------------------------------------------------------------------
+|
+| What string should be used to separate title segments sent via $this->template->title('Foo', 'Bar');
+|
+|   Default: ' | '
+|
+*/
+
+$config['title_separator'] = ' | ';
+
+/*
+|--------------------------------------------------------------------------
+| Theme
+|--------------------------------------------------------------------------
+|
+| Which layout file should be used? When combined with theme it will be a layout file in that theme
+|
+| Change to 'main' to get /application/views/main.php
+|
+|   Default: FALSE
+|
+*/
+
+$config['layout'] = FALSE;
+
+/*
+|--------------------------------------------------------------------------
+| Theme
+|--------------------------------------------------------------------------
+|
+| Which theme to use by default?
+|
+| Can be overriden with $this->template->set_theme('foo');
+|
+|   Default: ''
+|
+*/
+
+$config['theme'] = '';
+
+/*
+|--------------------------------------------------------------------------
+| Theme
+|--------------------------------------------------------------------------
+|
+| Where should we expect to see themes?
+|
+|	Default: array(APPPATH.'themes/' => '../themes/')
+|
+*/
+
+$config['theme_locations'] = array(
+	APPPATH.'themes/'
+);

application/core/MY_Controller.php

 	class Controller extends CI_Controller {}
 }
 
-class MY_Controller extends Controller {
+class MY_Controller extends MX_Controller {
 
     function __construct() {
         parent::__construct();
+        $this->controllername="MY";
         $this->load->library("tank_auth");
         $this->load->model('auth/users');
         $this->load->library('pagination');
         $this->load->library('parser');
 
         /* MS HACK */
-        $this->load->model('forums_model', 'Forums_model');
-        $this->load->model('groups_model', 'Groups_model');
-        $this->load->model('topics_model', 'Topics_model');
-        $this->load->model('bookmarks_model', 'Bookmarks_model');
+        $this->load->model('main/forums_model', 'Forums_model');
+        $this->load->model('main/groups_model', 'Groups_model');
+        $this->load->model('main/topics_model', 'Topics_model');
+        $this->load->model('main/bookmarks_model', 'Bookmarks_model');
         $this->load->model('settings_model', 'Settings_model');
-        $this->load->model('posts_model', 'Posts_model');
+        $this->load->model('main/posts_model', 'Posts_model');
         $this->load->model('pm_model', 'PM_model');
-        $this->load->model('attachments_model', 'Attachments_model');
-        $this->load->model('polls_model', 'Polls_model');
+        $this->load->model('main/attachments_model', 'Attachments_model');
+        $this->load->model('main/polls_model', 'Polls_model');
 
         $this->load->helper('download');
-
+    
         $this->basicdata = NULL;
         $this->_getBasicData(); // cacheit.
 
         $this->_checkClosed();
+        
+        $p=APPPATH."themes/";
+        $this->template->add_theme_location($p);
+        $default_theme= 'air';
+        $this->template->set_theme("air");
+        $this->template->set_layout("default");
+        $this->template->set_partial("header", "header");
+        $this->template->set_partial("footer", "footer");
+        
     }
     function loadpage_from_template($template, $data) {
+        
             $basic=$this->_getBasicData();
-            $default_theme=$basic['settings']['default_theme']."/";
+            
+    }
+    function loadpage($page=NULL, $data=array()) {
 
-            $d['header']=$this->parser->parse($default_theme.'header', $data, true);
-            $d['content']=$template;
-      
-            $d['footer']=$this->parser->parse($default_theme.'footer',$data, true);
-            $this->parser->parse($default_theme.'main', $d);
+        $d= array_merge($data, $this->_getBasicData());
+        //$this->template->set_layout("main");
+
+        $d['pagename']=$page;
+        $d['controllername']=$this->controllername;
+
+        $this->template->build($page, $d);
     }
-        function loadpage($page=NULL, $data=array()) {
-
-            /*
-            if (!$data){
-                $data=$this->_getBasicData();
-            }*/
-                $data = array_merge($data, $this->_getBasicData());
-
-                $default_theme=$data['settings']['default_theme']."/";
-
-                $d['header']=$this->parser->parse($default_theme.'header', $data, true);
-                $d['pagename']=$page;
-                $d['controllername']=$this->controllername;
-                $d['content']=$this->parser->parse($default_theme.$page,$data, true);
-                $d['footer']=$this->parser->parse($default_theme.'footer',$data, true);
-                $this->parser->parse($default_theme.'main', $d);
-
-        }
     function _getBasicData() {
         if (!isset($this->basicdata)) {
             $data = array();

application/core/MY_Loader.php

+<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
+
+/* load the MX_Loader class */
+require APPPATH."third_party/MX/Loader.php";
+
+class MY_Loader extends MX_Loader {}

application/core/MY_Router.php

+<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
+
+/* load the MX_Router class */
+require APPPATH."third_party/MX/Router.php";
+
+class MY_Router extends MX_Router {}

application/helpers/myhelpers/shoutbox_helper.php

     
 }
 add_private_funcs(array('last_msgs', 'sb_chat_view', 'shout'));
-register_func("beforeforumslist", 'sb_chat_view');
+//register_func("beforeforumslist", 'sb_chat_view');

application/libraries/Template.php

+<?php defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * CodeIgniter Template Class
+ *
+ * Build your CodeIgniter pages much easier with partials, breadcrumbs, layouts and themes
+ *
+ * @package			CodeIgniter
+ * @subpackage		Libraries
+ * @category		Libraries
+ * @author			Philip Sturgeon
+ * @license			http://philsturgeon.co.uk/code/dbad-license
+ * @link			http://philsturgeon.co.uk/code/codeigniter-template
+ */
+class Template
+{
+	private $_module = '';
+	private $_controller = '';
+	private $_method = '';
+
+	private $_theme = NULL;
+	private $_theme_path = NULL;
+	private $_layout = FALSE; // By default, dont wrap the view with anything
+	private $_layout_subdir = ''; // Layouts and partials will exist in views/layouts
+	// but can be set to views/foo/layouts with a subdirectory
+
+	private $_title = '';
+	private $_metadata = array();
+
+	private $_partials = array();
+
+	private $_breadcrumbs = array();
+
+	private $_title_separator = ' | ';
+
+	private $_parser_enabled = TRUE;
+	private $_parser_body_enabled = TRUE;
+
+	private $_theme_locations = array();
+
+	private $_is_mobile = FALSE;
+
+	// Seconds that cache will be alive for
+	private $cache_lifetime = 0;//7200;
+
+	private $_ci;
+
+	private $_data = array();
+
+	/**
+	 * Constructor - Sets Preferences
+	 *
+	 * The constructor can be passed an array of config values
+	 */
+	function __construct($config = array())
+	{
+		$this->_ci =& get_instance();
+
+		if ( ! empty($config))
+		{
+			$this->initialize($config);
+		}
+
+		log_message('debug', 'Template class Initialized');
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Initialize preferences
+	 *
+	 * @access	public
+	 * @param	array
+	 * @return	void
+	 */
+	function initialize($config = array())
+	{
+        //print_r($config);
+		foreach ($config as $key => $val)
+		{
+			if ($key == 'theme' AND $val != '')
+			{
+				$this->set_theme($val);
+				continue;
+			}
+
+			$this->{'_'.$key} = $val;
+		}
+
+		// No locations set in config?
+		if ($this->_theme_locations === array())
+		{
+			// Let's use this obvious default
+			$this->_theme_locations = array(APPPATH . 'themes/');
+		}
+
+		// If the parse is going to be used, best make sure it's loaded
+		if ($this->_parser_enabled === TRUE)
+		{
+			class_exists('CI_Parser') OR $this->_ci->load->library('parser');
+		}
+
+		// Modular Separation / Modular Extensions has been detected
+		if (method_exists( $this->_ci->router, 'fetch_module' ))
+		{
+			$this->_module 	= $this->_ci->router->fetch_module();
+		}
+
+		// What controllers or methods are in use
+		$this->_controller	= $this->_ci->router->fetch_class();
+		$this->_method 		= $this->_ci->router->fetch_method();
+
+		// Load user agent library if not loaded
+		class_exists('CI_User_agent') OR $this->_ci->load->library('user_agent');
+
+		// We'll want to know this later
+		$this->_is_mobile	= $this->_ci->agent->is_mobile();
+	}
+
+    function test($x){
+        return $x;
+    }
+	// --------------------------------------------------------------------
+
+	/**
+	 * Magic Get function to get data
+	 *
+	 * @access	public
+	 * @param	  string
+	 * @return	mixed
+	 */
+	public function __get($name)
+	{
+		return isset($this->_data[$name]) ? $this->_data[$name] : NULL;
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Magic Set function to set data
+	 *
+	 * @access	public
+	 * @param	  string
+	 * @return	mixed
+	 */
+	public function __set($name, $value)
+	{
+		$this->_data[$name] = $value;
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Set data using a chainable metod. Provide two strings or an array of data.
+	 *
+	 * @access	public
+	 * @param	  string
+	 * @return	mixed
+	 */
+	public function set($name, $value = NULL)
+	{
+		// Lots of things! Set them all
+		if (is_array($name) OR is_object($name))
+		{
+			foreach ($name as $item => $value)
+			{
+				$this->_data[$item] = $value;
+			}
+		}
+
+		// Just one thing, set that
+		else
+		{
+			$this->_data[$name] = $value;
+		}
+
+		return $this;
+	}
+
+	// --------------------------------------------------------------------
+
+	/**
+	 * Build the entire HTML output combining partials, layouts and views.
+	 *
+	 * @access	public
+	 * @param	string
+
+	 * @return	void
+	 */
+	public function build($view, $data = array(), $return = FALSE)
+	{
+		// Set whatever values are given. These will be available to all view files
+		is_array($data) OR $data = (array) $data;
+
+		// Merge in what we already have with the specific data
+		$this->_data = array_merge($this->_data, $data);
+
+		// We don't need you any more buddy
+		unset($data);
+
+		if (empty($this->_title))
+		{
+			$this->_title = $this->_guess_title();
+		}
+
+		// Output template variables to the template
+		$template['title']	= $this->_title;
+		$template['breadcrumbs'] = $this->_breadcrumbs;
+		$template['metadata']	= implode("\n\t\t", $this->_metadata);
+		$template['partials']	= array();
+
+		// Assign by reference, as all loaded views will need access to partials
+		$this->_data['template'] =& $template;
+
+		foreach( $this->_partials as $name => $partial )
+		{
+			// We can only work with data arrays
+			is_array($partial['data']) OR $partial['data'] = (array) $partial['data'];
+
+			// If it uses a view, load it
+			if (isset($partial['view']))
+			{
+				$template['partials'][$name] = $this->_find_view($partial['view'], $partial['data']);
+			}
+
+			// Otherwise the partial must be a string
+			else
+			{
+				if ($this->_parser_enabled === TRUE)
+				{
+					$partial['string'] = $this->_ci->parser->parse_string($partial['string'], $this->_data + $partial['data'], TRUE, TRUE);
+				}
+
+				$template['partials'][$name] = $partial['string'];
+			}
+		}
+
+		// Disable sodding IE7's constant cacheing!!
+		$this->_ci->output->set_header('Expires: Sat, 01 Jan 2000 00:00:01 GMT');
+		$this->_ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
+		$this->_ci->output->set_header('Cache-Control: post-check=0, pre-check=0, max-age=0');
+		$this->_ci->output->set_header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
+		$this->_ci->output->set_header('Pragma: no-cache');
+
+		// Let CI do the caching instead of the browser
+		$this->_ci->output->cache( $this->cache_lifetime );
+
+		// Test to see if this file
+		$this->_body = $this->_find_view( $view, array(), $this->_parser_body_enabled );
+
+		// Want this file wrapped with a layout file?
+		if ($this->_layout)
+		{
+			// Added to $this->_data['template'] by refference
+			$template['body'] = $this->_body;
+
+			// Find the main body and 3rd param means parse if its a theme view (only if parser is enabled)
+			$this->_body =  self::_load_view('layouts/'.$this->_layout, $this->_data, TRUE, self::_find_view_folder());
+		}
+
+		// Want it returned or output to browser?
+		if ( ! $return)
+		{
+			$this->_ci->output->set_output($this->_body);
+		}
+
+		return $this->_body;
+	}
+
+	/**
+	 * Set the title of the page
+	 *
+	 * @access	public
+	 * @param	string
+	 * @return	void
+	 */
+	public function title()
+	{
+		// If we have some segments passed
+		if ($title_segments =& func_get_args())
+		{
+			$this->_title = implode($this->_title_separator, $title_segments);
+		}
+
+		return $this;
+	}
+
+
+	/**
+	 * Put extra javascipt, css, meta tags, etc before all other head data
+	 *
+	 * @access	public
+	 * @param	 string	$line	The line being added to head
+	 * @return	void
+	 */
+	public function prepend_metadata($line)
+	{
+		array_unshift($this->_metadata, $line);
+		return $this;
+	}
+
+
+	/**
+	 * Put extra javascipt, css, meta tags, etc after other head data
+	 *
+	 * @access	public
+	 * @param	 string	$line	The line being added to head
+	 * @return	void
+	 */
+	public function append_metadata($line)
+	{
+		$this->_metadata[] = $line;
+		return $this;
+	}
+
+
+	/**
+	 * Set metadata for output later
+	 *
+	 * @access	public
+	 * @param	  string	$name		keywords, description, etc
+	 * @param	  string	$content	The content of meta data
+	 * @param	  string	$type		Meta-data comes in a few types, links for example
+	 * @return	void
+	 */
+	public function set_metadata($name, $content, $type = 'meta')
+	{
+		$name = htmlspecialchars(strip_tags($name));
+		$content = htmlspecialchars(strip_tags($content));
+
+		// Keywords with no comments? ARG! comment them
+		if ($name == 'keywords' AND ! strpos($content, ','))
+		{
+			$content = preg_replace('/[\s]+/', ', ', trim($content));
+		}
+
+		switch($type)
+		{
+			case 'meta':
+				$this->_metadata[$name] = '<meta name="'.$name.'" content="'.$content.'" />';
+			break;
+
+			case 'link':
+				$this->_metadata[$content] = '<link rel="'.$name.'" href="'.$content.'" />';
+			break;
+		}
+
+		return $this;
+	}
+
+
+	/**
+	 * Which theme are we using here?
+	 *
+	 * @access	public
+	 * @param	string	$theme	Set a theme for the template library to use
+	 * @return	void
+	 */
+	public function set_theme($theme = NULL)
+	{
+		$this->_theme = $theme;
+		foreach ($this->_theme_locations as $location)
+		{
+			if ($this->_theme AND file_exists($location.$this->_theme))
+			{
+				$this->_theme_path = rtrim($location.$this->_theme.'/');
+				break;
+			}
+		}
+
+		return $this;
+	}
+
+	/**
+	 * Get the current theme path
+	 *
+	 * @access	public
+	 * @return	string The current theme path
+	 */
+	public function get_theme_path()
+	{
+		return $this->_theme_path;
+	}
+
+
+	/**
+	 * Which theme layout should we using here?
+	 *
+	 * @access	public
+	 * @param	string	$view
+	 * @return	void
+	 */
+	public function set_layout($view, $_layout_subdir = '')
+	{
+		$this->_layout = $view;
+
+		$_layout_subdir AND $this->_layout_subdir = $_layout_subdir;
+
+		return $this;
+	}
+
+	/**
+	 * Set a view partial
+	 *
+	 * @access	public
+	 * @param	string
+	 * @param	string
+	 * @param	boolean
+	 * @return	void
+	 */
+	public function set_partial($name, $view, $data = array())
+	{
+		$this->_partials[$name] = array('view' => $view, 'data' => $data);
+		return $this;
+	}
+
+	/**
+	 * Set a view partial
+	 *
+	 * @access	public
+	 * @param	string
+	 * @param	string
+	 * @param	boolean
+	 * @return	void
+	 */
+	public function inject_partial($name, $string, $data = array())
+	{
+		$this->_partials[$name] = array('string' => $string, 'data' => $data);
+		return $this;
+	}
+
+
+	/**
+	 * Helps build custom breadcrumb trails
+	 *
+	 * @access	public
+	 * @param	string	$name		What will appear as the link text
+	 * @param	string	$url_ref	The URL segment
+	 * @return	void
+	 */
+	public function set_breadcrumb($name, $uri = '')
+	{
+		$this->_breadcrumbs[] = array('name' => $name, 'uri' => $uri );
+		return $this;
+	}
+
+	/**
+	 * Set a the cache lifetime
+	 *
+	 * @access	public
+	 * @param	string
+	 * @param	string
+	 * @param	boolean
+	 * @return	void
+	 */
+	public function set_cache($seconds = 0)
+	{
+		$this->cache_lifetime = $seconds;
+		return $this;
+	}
+
+
+	/**
+	 * enable_parser
+	 * Should be parser be used or the view files just loaded normally?
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	void
+	 */
+	public function enable_parser($bool)
+	{
+		$this->_parser_enabled = $bool;
+		return $this;
+	}
+
+	/**
+	 * enable_parser_body
+	 * Should be parser be used or the body view files just loaded normally?
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	void
+	 */
+	public function enable_parser_body($bool)
+	{
+		$this->_parser_body_enabled = $bool;
+		return $this;
+	}
+
+	/**
+	 * theme_locations
+	 * List the locations where themes may be stored
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	array
+	 */
+	public function theme_locations()
+	{
+		return $this->_theme_locations;
+	}
+
+	/**
+	 * add_theme_location
+	 * Set another location for themes to be looked in
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	array
+	 */
+	public function add_theme_location($location)
+	{
+		$this->_theme_locations[] = $location;
+	}
+
+	/**
+	 * theme_exists
+	 * Check if a theme exists
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	array
+	 */
+	public function theme_exists($theme = NULL)
+	{
+		$theme OR $theme = $this->_theme;
+
+		foreach ($this->_theme_locations as $location)
+		{
+			if (is_dir($location.$theme))
+			{
+				return TRUE;
+			}
+		}
+
+		return FALSE;
+	}
+
+	/**
+	 * get_layouts
+	 * Get all current layouts (if using a theme you'll get a list of theme layouts)
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	array
+	 */
+	public function get_layouts()
+	{
+		$layouts = array();
+        echo self::_find_view_folder().'layouts/';
+		foreach(glob(self::_find_view_folder().'layouts/*.*') as $layout)
+		{
+			$layouts[] = pathinfo($layout, PATHINFO_BASENAME);
+		}
+
+		return $layouts;
+	}
+
+
+	/**
+	 * get_layouts
+	 * Get all current layouts (if using a theme you'll get a list of theme layouts)
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	array
+	 */
+	public function get_theme_layouts($theme = NULL)
+	{
+		$theme OR $theme = $this->_theme;
+
+		$layouts = array();
+        /*
+        echo "LOACTIONS:";
+        print_r($this->_theme_locations);
+        echo "<br />";
+        */ 
+		foreach ($this->_theme_locations as $location)
+		{
+			// Get special web layouts
+			if( is_dir($location.$theme.'/views/web/layouts/') )
+			{
+				foreach(glob($location.$theme . '/views/web/layouts/*.*') as $layout)
+				{
+					$layouts[] = pathinfo($layout, PATHINFO_BASENAME);
+				}
+				break;
+			}
+
+			// So there are no web layouts, assume all layouts are web layouts
+            //echo "checking if is dir: ". $location.$theme.'/views/layouts/';
+			if(is_dir($location.$theme.'/views/layouts/'))
+			{
+                //echo "YES IS DIR::::";
+				foreach(glob($location.$theme . '/views/layouts/*.*') as $layout)
+				{
+					$layouts[] = pathinfo($layout, PATHINFO_BASENAME);
+				}
+				break;
+			}
+		}
+
+		return $layouts;
+	}
+
+	/**
+	 * layout_exists
+	 * Check if a theme layout exists
+	 *
+	 * @access	public
+	 * @param	 string	$view
+	 * @return	array
+	 */
+	public function layout_exists($layout)
+	{
+		// If there is a theme, check it exists in there
+		if ( ! empty($this->_theme) AND in_array($layout, self::get_theme_layouts()))
+		{
+			return TRUE;
+		}
+
+		// Otherwise look in the normal places
+		return file_exists(self::_find_view_folder().'layouts/' . $layout . self::_ext($layout));
+	}
+
+	// find layout files, they could be mobile or web
+	private function _find_view_folder()
+	{
+		if (isset($this->_ci->load->_ci_cached_vars['template_views']))
+		{
+			return $this->_ci->load->_ci_cached_vars['template_views'];
+		}
+
+		// Base view folder
+		$view_folder = APPPATH.'views/';
+
+		// Using a theme? Put the theme path in before the view folder
+		if ( ! empty($this->_theme))
+		{
+			$view_folder = $this->_theme_path.'views/';
+		}
+
+		// Would they like the mobile version?
+		if ($this->_is_mobile === TRUE AND is_dir($view_folder.'mobile/'))
+		{
+			// Use mobile as the base location for views
+			$view_folder .= 'mobile/';
+		}
+
+		// Use the web version
+		else if (is_dir($view_folder.'web/'))
+		{
+			$view_folder .= 'web/';
+		}
+
+		// Things like views/admin/web/view admin = subdir
+		if ($this->_layout_subdir)
+		{
+			$view_folder .= $this->_layout_subdir.'/';
+		}
+
+		// If using themes store this for later, available to all views
+		return $this->_ci->load->_ci_cached_vars['template_views'] = $view_folder;
+	}
+
+	// A module view file can be overriden in a theme
+	private function _find_view($view, array $data, $parse_view = TRUE)
+	{
+		// Only bother looking in themes if there is a theme
+		if ( ! empty($this->_theme))
+		{
+			foreach ($this->_theme_locations as $location)
+			{
+				$theme_views = array(
+					$this->_theme . '/views/modules/' . $this->_module . '/' . $view,
+					$this->_theme . '/views/' . $view
+				);
+
+				foreach ($theme_views as $theme_view)
+				{
+					if (file_exists($location . $theme_view . self::_ext($theme_view)))
+					{
+						return self::_load_view($theme_view, $this->_data + $data, $parse_view, $location);
+					}
+				}
+			}
+		}
+
+		// Not found it yet? Just load, its either in the module or root view
+		return self::_load_view($view, $this->_data + $data, $parse_view);
+	}
+
+	private function _load_view($view, array $data, $parse_view = TRUE, $override_view_path = NULL)
+	{
+		// Sevear hackery to load views from custom places AND maintain compatibility with Modular Extensions
+		if ($override_view_path !== NULL)
+		{
+			if ($this->_parser_enabled === TRUE AND $parse_view === TRUE)
+			{
+				// Load content and pass through the parser
+				$content = $this->_ci->parser->parse_string($this->_ci->load->_ci_load(array(
+					'_ci_path' => $override_view_path.$view.self::_ext($view),
+					'_ci_vars' => $data,
+					'_ci_return' => TRUE
+				)), $data, TRUE);
+			}
+
+			else
+			{
+				// Load it directly, bypassing $this->load->view() as ME resets _ci_view
+				$content = $this->_ci->load->_ci_load(array(
+					'_ci_path' => $override_view_path.$view.self::_ext($view),
+					'_ci_vars' => $data,
+					'_ci_return' => TRUE
+				));
+			}
+		}
+
+		// Can just run as usual
+		else
+		{
+			// Grab the content of the view (parsed or loaded)
+			$content = ($this->_parser_enabled === TRUE AND $parse_view === TRUE)
+
+				// Parse that bad boy
+				? $this->_ci->parser->parse($view, $data, TRUE )
+
+				// None of that fancy stuff for me!
+				: $this->_ci->load->view($view, $data, TRUE );
+		}
+        #echo "CONTENT<<: $content >>";
+		return $content;
+	}
+
+	private function _guess_title()
+	{
+		$this->_ci->load->helper('inflector');
+
+		// Obviously no title, lets get making one
+		$title_parts = array();
+
+		// If the method is something other than index, use that
+		if ($this->_method != 'index')
+		{
+			$title_parts[] = $this->_method;
+		}
+
+		// Make sure controller name is not the same as the method name
+		if ( ! in_array($this->_controller, $title_parts))
+		{
+			$title_parts[] = $this->_controller;
+		}
+
+		// Is there a module? Make sure it is not named the same as the method or controller
+		if ( ! empty($this->_module) AND !in_array($this->_module, $title_parts))
+		{
+			$title_parts[] = $this->_module;
+		}
+
+		// Glue the title pieces together using the title separator setting
+		$title = humanize(implode($this->_title_separator, $title_parts));
+
+		return $title;
+	}
+
+	private function _ext($file)
+	{
+		return pathinfo($file, PATHINFO_EXTENSION) ? '' : EXT;
+	}
+}
+
+// END Template class

application/modules/admin/controllers/admin.php

+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+
+/**
+* @property CI_Loader $load
+* @property CI_Form_validation $form_validation
+* @property CI_Input $input
+* @property CI_Email $email
+* @property CI_DB_active_record $db
+* @property CI_DB_forge $dbforge
+* @property CI_Table $table
+* @property CI_Session $session
+* @property CI_FTP $ftp
+ * 
+ */
+//TODO create a PRE_CONTROLLER HOOK FOR CHECKING IS_ADMIN.
+
+class Admin extends MY_Controller {
+
+    function __construct() {
+        parent::__construct();
+        $this->_checkAdmin();
+
+        $this->load->dbutil(); //database operations.
+        $this->load->helper('download');
+        $this->load->helper('file');
+    }
+    
+    function loadpage($page=NULL, $data=array()) {
+        $p=APPPATH."themes/";
+        $this->template->add_theme_location($p);
+
+        $this->template->set_theme("air");
+        /*echo $this->template->get_theme_path();
+        print_r($this->template->get_theme_layouts());*/
+        $this->template->set_layout("admin");
+        $this->template->set_partial("header", "header");
+        $this->template->set_partial("footer", "footer");
+        
+
+        $d= array_merge($data, $this->_getBasicData());
+
+        $d['pagename']=$page;
+        $d['controllername']=$this->controllername;
+
+
+        $d['showsidebar']=TRUE;
+        $this->template->set_partial('sidebar', 'admin/mainmenu');
+ 
+        $this->template->build($page, $d);
+
+    }
+    
+    /*
+    function loadpage_from_template($template, $data) {
+            $basic=$this->_getBasicData();
+            $default_theme=$basic['settings']['default_theme']."/";
+
+            $d['header']=$this->parser->parse($default_theme.'header', $data, true);
+            $d['content']=$template;
+            $d['controllername']='admin';
+            $d['adminnav']=$this->parser->parse($default_theme.'admin/mainmenu',$data, true);
+            $d['footer']=$this->parser->parse($default_theme.'footer',$data, true);
+            $this->parser->parse($default_theme.'admin/main', $d);
+    }
+    
+    
+    function loadpage($page=NULL, $data=array()) {
+            $basic=$this->_getBasicData();
+            $default_theme=$basic['settings']['default_theme']."/";
+
+            $d['header']=$this->parser->parse($default_theme.'header', $data, true);
+            $d['content']=$this->parser->parse($default_theme.$page,$data, true);
+            $d['pagename']=$page;
+            $d['controllername']='admin';
+            $d['adminnav']=$this->parser->parse($default_theme.'admin/mainmenu',$data, true);
+            $d['footer']=$this->parser->parse($default_theme.'footer',$data, true);
+            $this->parser->parse($default_theme.'admin/main', $d);
+
+    }*/
+    function _info($msg,  $msg_link=NULL, $msg_type='info') {
+        $this->session->set_flashdata('message', $msg);
+        $this->session->set_flashdata('msgtype', $msg_type);
+        if ($msg_link==NULL) {
+            $msg_link=site_url();
+        }
+        $this->session->set_flashdata('msg_link', $msg_link);
+
+        redirect('main/simpleinfo');
+    }
+
+    function index() {
+        redirect('admin/forums');
+    }
+
+    //Forums
+
+    function forums() {
+
+        $data=$this->_getBasicData();
+        $data['forums']=$this->Forums_model->getAllForums()->result();
+        $data['groups']=$this->Groups_model->getAllGroups()->result();
+        $this->loadpage("admin/forums", $data);
+
+    }
+    function create_forum() {
+
+        $config=array(
+                array(
+                        'field'=>'forum_name',
+                        'label'=> 'Forum name',
+                        'rules' => 'trim|required'
+                ),
+                array(
+                        'field'=>'forum_desc',
+                        'label'=> 'Forum description',
+                        'rules' => 'trim'
+                ),
+
+        );
+
+        $this->form_validation->set_rules($config);
+
+        if ($this->form_validation->run()==FALSE) {
+            $data=$this->_getBasicData();
+            $this->loadpage("admin/forums",$data );
+        }else {
+            $data=array();
+            $data['forum_name']=$this->input->post('forum_name');
+            $data['forum_desc']=$this->input->post('forum_desc');
+            $data['forum_slug']=$this->input->post("forum_slug");
+            $data['forum_parent']=$this->input->post('forum_parent');
+            $data['mod_group_id']=$this->input->post('mod_group_id');
+            $data['is_readonly']=$this->input->post("is_readonly")==TRUE;
+            $data['is_cat']=$this->input->post('is_cat')==TRUE;
+            $data['forum_img_url']=$this->input->post('forum_img_url');
+            $visible_to=$this->input->post('allowed_groups');
+            if ($visible_to){
+                $data['visible_to']=implode(',',$visible_to);
+            }
+
+            $this->Forums_model->createForum($data);
+
+            #$this->loadpage("admin/forum_created");
+            redirect('admin/forums');
+        }
+    }
+
+    function edit_forum($id) {
+        $data=$this->_getBasicData();
+        $f=$this->Forums_model->forumByID($id);
+        $data['forum']=$f;
+        $data['forums']=$this->Forums_model->getAllForums()->result();
+        $data['groups']=$this->Groups_model->getAllGroups()->result();
+        $data['visible_to_groups']=$this->Forums_model->getAllowedGroupsToViewForum($f->forum_id);
+        $data['subforumslist']=$this->Forums_model->getSubForumsOf($id);
+        $this->loadpage("admin/edit_forum", $data);
+    }
+    function edit_forum_done() {
+
+        $config=array(
+                array(
+                        'field'=>'forum_name',
+                        'label'=> 'Forum name',
+                        'rules' => 'trim|required'
+                ),
+                array(
+                        'field'=>'forum_desc',
+                        'label'=> 'Forum description',
+                        'rules' => 'trim'
+                ),
+
+        );
+
+        $this->form_validation->set_rules($config);
+
+        if ($this->form_validation->run()==FALSE) {
+            $this->loadpage("admin/edit_forum");
+        }else {
+            $data=array();
+            $forum_id=$this->input->post('fid');
+            $data['forum_name']=$this->input->post('forum_name');
+            $data['forum_desc']=$this->input->post('forum_desc');
+            $data['forum_slug']=$this->input->post("forum_slug");
+            $data['forum_parent']=$this->input->post('forum_parent');
+            $data['mod_group_id']=$this->input->post('mod_group_id');
+            $visible_to_groups=$this->input->post('allowed_groups');
+            if($visible_to_groups){
+                $data['visible_to']=implode(',', $visible_to_groups);
+            }
+            $data['forum_img_url']=$this->input->post('forum_img_url');
+            $data['is_readonly']=$this->input->post("is_readonly")==TRUE;
+            $data['is_cat']=$this->input->post('is_cat')==TRUE;
+
+            $this->Forums_model->updateForum($forum_id, $data);
+
+            redirect('admin/forums');
+        }
+    }
+    function edit_subforums_ordering_done(){
+        $ordering=$this->input->post("subforumsorder");
+        foreach($ordering as $fid => $order){
+            $order = trim($order);
+            if(! ($order == '' || preg_match('/[^0-9]/', $order))){
+                $order=0;
+            }
+            $this->Forums_model->updateForum($fid, array("forum_order"=>$order));
+        }
+        redirect('admin/forums');
+    }
+    function delete_forum($fid) {
+
+        $this->Forums_model->deleteForumAndChilds($fid);
+        redirect('admin/forums');
+    }
+
+    function groups() {
+        $data=$this->_getBasicData();
+        $data['groups']=$this->Groups_model->getAllGroups()->result();
+        $data['forums']=$this->Forums_model->getAllForums()->result();
+        $data['perms']=$this->Groups_model->permissionsList()->result();
+        $data['modperms']=$this->Groups_model->groupPermissions(3);
+
+        $this->loadpage('admin/groups', $data);
+    }
+
+    function create_group() {
+
+        $config=array(
+                array(
+                        'field'=>'groupname',
+                        'label'=> 'Group name',
+                        'rules' => 'trim|required'
+                ),
+
+        );
+
+        $this->form_validation->set_rules($config);
+
+        if ($this->form_validation->run()==FALSE) {
+            $this->loadpage("admin/groups");
+        }else {
+            $data=array();
+            $groupname=$this->input->post('groupname');
+            $perms=$this->input->post('perms');
+
+            $data['groupname']=$groupname;
+            $data['perms']=$perms;
+            $gid=$this->Groups_model->createGroup($data);
+
+            redirect('admin/index');
+
+        }
+
+
+    }
+
+    function delete_group($gid) {
+        $this->Groups_model->deleteGroup($gid);
+        redirect('admin/groups');
+    }
+    function edit_group($gid) {
+
+        $data=$this->_getBasicData();
+        $data['group']=$this->Groups_model->groupByID($gid);
+        $data['perms']=$this->Groups_model->permissionsList()->result();
+        $data['groupperms']=$this->Groups_model->groupPermissions($gid);
+        $this->loadpage('admin/edit_group', $data);
+    }
+
+    function edit_group_done() {
+
+        $config=array(
+                array(
+                        'field'=>'groupname',
+                        'label'=> 'Group name',
+                        'rules' => 'trim|required'
+                ),
+
+        );
+
+        $this->form_validation->set_rules($config);
+
+        if ($this->form_validation->run()==FALSE) {
+            $this->loadpage("admin/groups");
+        }else {
+            $groupname=$this->input->post('groupname');
+            $perms=$this->input->post('perms');
+            $group_id=$this->input->post('group_id');
+            
+            $this->Groups_model->updateGroupPerms($group_id, $perms);
+
+            redirect('admin/groups');
+
+        }
+
+    }
+
+
+    function users() {
+        $data=$this->_getBasicData();
+        $data['groups']=$this->Groups_model->getAllGroups()->result();
+        #to get paginated later...
+        $this->loadpage('admin/users', $data);
+    }
+    function create_user() {
+
+        $config=array(
+                array(
+                        'field'=>'username',
+                        'label'=> 'Username',
+                        'rules' => 'trim|required'
+                ),
+                array(
+                        'field'=>'email',
+                        'label'=>'Email',
+                        'rules'=>'trim|required|valid_email'
+
+                ),
+                array(
+                        'field'=>'password',
+                        'label'=>'password',
+                        'rules'=>'trim|required'
+                ),
+                array(
+                        'field'=>'confirm_password',
+                        'label'=> 'Password confirmation',
+                        'rules' => 'trim|required|matches[password]'
+                ),
+
+        );
+
+        $this->form_validation->set_rules($config);
+        ;
+        $data['groups']=$this->Groups_model->getAllGroups()->result();
+
+        if ($this->form_validation->run()==FALSE) {
+            $this->loadpage("admin/users", $data);
+        }else {
+
+            $username=$this->input->post('username');
+            $email=$this->input->post('email');
+            $password=$this->input->post("password");
+            $group_id=$this->input->post('group_id');
+            $d=$this->tank_auth->create_user($username, $email, $password, 0);
+            $this->users->move_user_to_group($d['user_id'], $group_id);
+            redirect("admin/users", 'refresh');
+
+        }
+    }
+
+
+    function list_banned(){
+        $data=$this->_getBasicData();
+        $this->load->library('pagination');
+        $config['base_url'] = base_url()."index.php/admin/list_users/";
+        $config['total_rows'] = $this->users->get_users_count();
+        $config['per_page'] = '20';
+
+        $users=$this->users->get_banned_users( $config['per_page'],$this->uri->segment(3) )->result();
+        $formatted=array();
+        foreach($users as $u) {
+            $acts=anchor(site_url().'/user/edit_user/'.$u->id, "Edit");
+            array_push($formatted, array('id'=>$u->id, 'username'=>"<a
+href=".base_url()."index.php?/user/view_user/".$u->id.">".$u->username."</a>", $acts));
+        }
+
+        $data['results']=$formatted;
+        $this->pagination->initialize($config);
+
+        $this->load->library('table');
+        $this->table->set_heading('ID', 'username', 'Actions');
+
+
+        $this->loadpage('admin/users_list', $data);
+
+
+    }
+    function list_users() {
+        $data=$this->_getBasicData();
+        $this->load->library('pagination');
+        $config['base_url'] = base_url()."index.php/admin/list_users/";
+        $config['total_rows'] = $this->users->get_users_count();
+        $config['per_page'] = '20';
+
+        $users=$this->users->get_users( $config['per_page'],$this->uri->segment(3) )->result();
+        $formatted=array();
+        foreach($users as $u) {
+            $acts=anchor(site_url().'/user/edit_user/'.$u->id, "Edit");
+            array_push($formatted, array('id'=>$u->id, 'username'=>"<a
+href=".base_url()."index.php?/user/view_user/".$u->id.">".$u->username."</a>", $acts));
+        }
+
+        $data['results']=$formatted;
+        $this->pagination->initialize($config);
+
+        $this->load->library('table');
+        $this->table->set_heading('ID', 'username', 'Actions');
+
+
+        $this->loadpage('admin/users_list', $data);
+
+    }
+    function find_user_done(){
+        $login=$this->input->post('login');
+        $u=FALSE;
+
+        $u=$this->users->get_user_by_login($login);
+        if($u){
+            redirect("/user/view_user/$u->id");
+        }else{
+            $this->_info("No such user",site_url()."/admin/users", 'info');
+        }
+
+    }
+    function maintenance() {
+        $data=$this->_getBasicData();
+        $this->loadpage('admin/maintenance', $data);
+    }
+
+    function dbops() {
+        $data=$this->_getBasicData();
+        $data['tables']=$this->db->list_tables();
+        $this->loadpage('admin/dbops', $data);
+    }
+
+    function db_op_done() {
+        $optimizetables=$this->input->post("optimizetables");
+        $repairtables=$this->input->post("repairtables");
+        $optimizedb=$this->input->post("optimizedb");
+
+        $reportmsgs=array();
+        if ($optimizedb) {
+            $result = $this->dbutil->optimize_database();
+
+            if ($result !== FALSE) {
+                $report[]="Database optimized.";
+            }
+        }
+        if (count($optimizetables)>0) {
+            $report[]="Optimize: ";
+            foreach($optimizetables as $table) {
+                if ($this->dbutil->optimize_table($table)) {
+                    $report[]="+".$table." optimized.";
+                }
+            }
+        }
+        if (count($repairtables)>0) {
+            $report[]="Repair: ";
+            foreach($repairtables as $table) {
+                if ($this->dbutil->repair_table($table)) {
+                    $report[]="+". $table." repaired.";
+                }
+            }
+
+        }
+
+        $reportstr=implode("<br />", $report);
+        echo $reportstr;
+    }
+
+    function backup() {
+        $data=$this->_getBasicData();
+        $data['tables']=$this->db->list_tables();
+        $this->loadpage('admin/backup', $data);
+    }
+
+    function get_backup() {
+
+        $tablestobackup=$this->input->post('backuptables');
+
+        //backup.
+        $fname= 'database-' . date('Y-m-d') . '.sql.zip';
+        $prefs = array(
+                'tables'      => $tablestobackup,
+                'filename'    => $fname,
+                'format'      => 'zip',
+                'add_drop'    => TRUE,
+                'add_insert'  => TRUE,
+                'newline'     => "\n"
+        );
+        $backup =& $this->dbutil->backup($prefs);
+        write_file($fname, $backup);
+        force_download($fname, $backup);
+
+    }
+
+    function _checkAdmin() {
+        if (!$this->tank_auth->is_admin()) {
+            echo "Not admin...";
+            redirect('main');
+            exit();
+        }
+    }
+
+    function settings() {
+        $data=$this->_getBasicData();
+        $dir=APPPATH."views/";
+        $themes=array();
+        if (is_dir($dir)) {
+            if ($dh = opendir($dir)) {
+                while (($file = readdir($dh)) !== false) {
+                    if (is_dir($dir.$file) && !(in_array($file, array(".", "..")))) {
+                        $themes[$file]=$file;
+                    }
+                }
+                closedir($dh);
+            }
+        }
+        $data['themes']=$themes;
+
+        $this->loadpage('admin/settings', $data);
+    }
+    function edit_settings_done() {
+        $data=$this->_getBasicData();
+
+        $site_title=$this->input->post('site_title');
+        $site_desc=$this->input->post('site_desc');
+        $forum_open=$this->input->post('forums_opened')?"yes":"no";
+        $items_per_page=$this->input->post('items_per_page');
+        $lock_post_editing_after=$this->input->post('lock_post_editing_after');
+        $posting_threshold=$this->input->post('posting_threshold');
+        $online_users_timeout=$this->input->post("online_users_timeout");
+        $show_avatars=$this->input->post('show_avatars')?"yes":"no";
+        $use_xml_rpc=$this->input->post('use_xml_rpc')?"yes":"no";
+        $default_theme=$this->input->post('default_theme');
+        $attachs_upload_path=$this->input->post('attachs_upload_path');
+        $allowed_types_to_attach=$this->input->post('allowed_types_to_attach');
+        $max_files_per_post=$this->input->post('max_files_per_post');
+        $max_attachment_size=$this->input->post('max_attachment_size');
+
+        $newsettings=array();
+        $newsettings['site_title']=$site_title;
+        $newsettings['site_desc']=$site_desc;
+        $newsettings['forum_open']=$forum_open;
+        $newsettings['items_per_page']=$items_per_page;
+        $newsettings['lock_post_editing_after']=$lock_post_editing_after;
+        $newsettings["show_avatars"]=$show_avatars;
+        $newsettings['use_xml_rpc']=$use_xml_rpc;
+        $newsettings['default_theme']=$default_theme;
+        $newsettings['attachs_upload_path']=$attachs_upload_path;
+        $newsettings['allowed_types_to_attach']=$allowed_types_to_attach;
+        $newsettings['max_files_per_post']=$max_files_per_post;
+        $newsettings['max_attachment_size']=$max_attachment_size;
+        $newsettings['posting_threshold']=$posting_threshold;
+        $newsettings["online_users_timeout"]=$online_users_timeout;
+
+        $this->Settings_model->updateSettings($newsettings);
+
+
+        $this->_info('Settings updated', "admin/settings/", 'info');
+        //redirect('admin/settings', 'refresh');
+
+    }
+    function phpstatus() {
+        $this->loadpage('admin/phpstatus', $this->_getBasicData());
+    }
+    function _getAllModules($p='modules/') {
+        $modules=array();
+
+        $dir=APPPATH.$p;
+        if (is_dir($dir)) {
+            if ($dh = opendir($dir)) {
+                while (($file = readdir($dh)) !== false) {
+                    if (is_dir($dir.$file) && !(in_array($file, array(".", "..")))) {
+                        $moduleinfo=simplexml_load_file($dir.$file."/$file.xml");
+                        $moduleinfo->is_installed=$this->Settings_model->isInstalledModule($file);
+                        $moduleinfo->is_active=$this->Settings_model->isActiveModule($file);
+                        $modules[$file]=$moduleinfo;
+                    }
+                }
+                closedir($dh);
+            }
+        }
+        return $modules;
+    }
+    function install_module($modulename) {
+
+        if (!$this->Settings_model->isInstalledModule($modulename)) {
+            include(APPPATH."/modules/$modulename/$modulename.php");
+            $sql=sql_for_install();
+            if ($sql) {
+                $this->db->query($sql);
+            }
+            $this->Settings_model->create_setting($modulename, "active_module");
+        }
+        redirect("admin/modules");
+    }
+    function activate_module($modulename) {
+        if($this->Settings_model->isInstalledModule($modulename)) {
+            $this->Settings_model->set_setting($modulename, "active_module");
+        }
+        redirect('admin/modules');
+    }
+
+    function deactivate_module($modulename) {
+
+        if($this->Settings_model->isActiveModule($modulename)) {
+            //echo rename(APPPATH."/modules/$modulename/controllers/$modulename.php", APPPATH."/modules/$modulename/controllers/"."$modulename"."_inactive.php")==TRUE;
+            $this->Settings_model->set_setting($modulename, "inactive_module");
+        }
+        redirect('admin/modules');
+    }
+    function uninstall_module($modulename) {
+        if ($this->Settings_model->isInstalledModule($modulename)) {
+            include(APPPATH."/modules/$modulename/$modulename.php");
+            $sql=sql_for_drop();
+            echo $sql;
+            if ($sql) {
+                $this->db->query($sql);
+                //remove the module directory manually.
+            }
+            $this->Settings_model->deleteSetting($modulename);
+        }
+        redirect('admin/modules');
+    }
+    function modules() {
+        $data=$this->_getBasicData();
+        $data['modules']=$this->_getAllModules();
+        $this->loadpage('admin/modules', $data);
+    }
+    function sqlman() {
+
+        $data=$this->_getBasicData();
+        $data['tables']=$this->db->list_tables();
+        $this->loadpage('admin/sqlman', $data);
+    }
+    function do_sql() {
+        $config=array(
+                array(
+                        'field'=>'sql',
+                        'label'=> 'SQL',
+                        'rules' => 'trim|required'
+                ),
+
+        );
+
+        $this->form_validation->set_rules($config);
+        $data=$this->_getBasicData();
+        if ($this->form_validation->run()==FALSE) {
+            $this->loadpage("admin/sqlman", $data);
+        }else{
+           ###NOTE: THIS PART MOSTLY TAKEN FROM FUDFORUM. http://fudforum.org
+           $sql=$this->input->post("sql");
+           $sqlfile = str_replace("\r","", $sql);
+           $sqlfile = explode(";\n", $sqlfile);
+
+           $qs=array();
+           foreach($sqlfile as $q){
+               if ($this->_securesql($q)){
+                   $q=$this->db->query($q);
+                   $qs[]=$q;
+               }
+           }
+
+           $data['qs']=$qs;
+           $data['tables']=$this->db->list_tables();
+           $this->loadpage('admin/sqlman', $data);
+           
+        }
+
+    }
+    function _securesql($sql) {
+        if (preg_match('/[a-zA-Z]/', $sql) and !preg_match('/^(#|--)/', $sql)) {
+            if (preg_match('/^\s*use\s+\w+\s*;?$/i', $sql)) {
+                return FALSE;
+            }
+        }
+        return TRUE;
+    }
+
+    function _getAllplugins($p='helpers/myhelpers/') {
+        $plugins=array();
+
+        $dir=APPPATH.$p;
+        if (is_dir($dir)) {
+            if ($dh = opendir($dir)) {
+                while (($file = readdir($dh)) !== false) {
+                    if(strstr($file, ".php")) {
+                        $pathinfo = pathinfo($file);
+                        $f=$pathinfo['filename'];
+                        $plugininfo=simplexml_load_file($dir.$f."_info.xml");
+                        $plugininfo->is_installed=$this->Settings_model->isInstalledPlugin($f);
+                        $plugininfo->is_active=$this->Settings_model->isActivePlugin($f);
+                        $plugins[$f]=$plugininfo;
+                    }
+                }
+                closedir($dh);
+            }
+        }
+        ksort($plugins);
+        return $plugins;
+    }
+    function install_plugin($pluginname) {
+        echo '1';
+        if (!$this->Settings_model->isInstalledplugin($pluginname)) {
+            include_once(APPPATH."/helpers/myhelpers/$pluginname.php");
+            $parts=explode("_", $pluginname);
+            $pname=$parts[0];
+            if(function_exists($pname."_sql_for_install")){
+                $sql=call_user_func($pname."_sql_for_install");
+                if ($sql!=FALSE) {
+                    $this->db->simple_query_file($sql);
+                }
+            }
+            if(function_exists($pname."_init_tables")){
+                   call_user_func($pname."_init_tables");
+            }
+
+            $this->Settings_model->create_setting($pluginname, "active_plugin");
+        }
+        redirect("admin/plugins");
+    }
+    function activate_plugin($pluginname) {
+        if($this->Settings_model->isInstalledplugin($pluginname)) {
+            $this->Settings_model->set_setting($pluginname, "active_plugin");
+        }
+        redirect('admin/plugins');
+    }
+
+    function deactivate_plugin($pluginname) {
+
+        if($this->Settings_model->isActiveplugin($pluginname)) {
+            //echo rename(APPPATH."/plugins/$pluginname/controllers/$pluginname.php", APPPATH."/plugins/$pluginname/controllers/"."$pluginname"."_inactive.php")==TRUE;
+            $this->Settings_model->set_setting($pluginname, "inactive_plugin");
+        }
+        redirect('admin/plugins');
+    }
+    function uninstall_plugin($pluginname) {
+        if ($this->Settings_model->isInstalledplugin($pluginname)) {
+            include_once(APPPATH."/helpers/myhelpers/$pluginname".".php");
+            $parts=explode("_", $pluginname);
+            $pname=$parts[0];
+            if(function_exists($pname."_sql_for_drop")){
+                $sql=call_user_func($pname."_sql_for_drop");
+                if ($sql!=FALSE) {
+
+                    $this->db->simple_query_file($sql);
+                    //remove the plugin directory manually.
+                }
+            }
+
+            $this->Settings_model->deleteSetting($pluginname);
+        }
+        redirect('admin/plugins');
+    }
+    function plugins() {
+        $data=$this->_getBasicData();
+        $data['plugins']=$this->_getAllplugins();
+        $this->loadpage('admin/plugins', $data);
+    }
+    function config_plugin($pluginname){
+        $data=$this->_getBasicData();
+        $temp=call_user_func($pluginname."_config");
+        $this->loadpage_from_template( $temp, $data);
+    }
+}

application/modules/auth/controllers/auth.php

+<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
+
+class Auth extends MY_Controller
+{
+
+	function __construct()
+	{
+		parent::__construct();
+
+		$this->load->helper(array('form', 'url'));
+		$this->load->library('form_validation');
+		$this->load->library('tank_auth');
+		$this->lang->load('tank_auth');
+                $this->controllername="pm";
+	}
+        function  _checkClosed() {
+            /*overriden.*/
+        }
+	function index()
+	{
+		redirect('/auth/login/');
+	}
+
+	/**
+	 * Login user on the site
+	 *
+	 * @return void
+	 */
+	function login()
+	{
+		if ($this->tank_auth->is_logged_in()) {									// logged in
+			redirect('');
+
+		} elseif ($this->tank_auth->is_logged_in(FALSE)) {						// logged in, not activated
+			redirect('/auth/send_again/');
+
+		} else {
+			$data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND
+					$this->config->item('use_username', 'tank_auth'));
+			$data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth');
+
+			$this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean');
+			$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
+			$this->form_validation->set_rules('remember', 'Remember me', 'integer');
+
+			// Get login for counting attempts to login
+			if ($this->config->item('login_count_attempts', 'tank_auth') AND
+					($login = $this->input->post('login'))) {
+				//$login = $this->input->xss_clean($login);
+			} else {
+				$login = '';
+			}
+
+			$data['use_recaptcha'] = $this->config->item('use_recaptcha', 'tank_auth');
+			if ($this->tank_auth->is_max_login_attempts_exceeded($login)) {
+				if ($data['use_recaptcha'])
+					$this->form_validation->set_rules('recaptcha_response_field', 'Confirmation Code', 'trim|xss_clean|required|callback__check_recaptcha');
+				else
+					$this->form_validation->set_rules('captcha', 'Confirmation Code', 'trim|xss_clean|required|callback__check_captcha');
+			}
+			$data['errors'] = array();
+
+			if ($this->form_validation->run()) {								// validation ok
+				if ($this->tank_auth->login(
+						$this->form_validation->set_value('login'),
+						$this->form_validation->set_value('password'),
+						$this->form_validation->set_value('remember'),
+						$data['login_by_username'],
+						$data['login_by_email'])) {								// success
+					redirect('');
+
+				} else {
+					$errors = $this->tank_auth->get_error_message();
+					if (isset($errors['banned'])) {								// banned user
+						$this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']);
+						return;