public function index() { $this->template->content = new View('admin/addons/plugins'); $this->template->content->title = 'Addons'; if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $_GET['status']; if (strtolower($status) == 'a') { $filter = 'plugin_active = 1'; } elseif (strtolower($status) == 'i') { $filter = 'plugin_active = 0'; } else { $status = "0"; $filter = '1=1'; } } else { $status = "0"; $filter = '1=1'; } // Add the hidden plugins to the list of plugins to filter out if (count(Kohana::config('plugins.hide_from_list')) != 0) { $hide_from_list = array_map(array(Database::instance(), 'escape'), Kohana::config('plugins.hide_from_list')); $filter .= ' AND plugin_name NOT IN (' . implode(",", $hide_from_list) . ')'; } $plugins = plugin::resync_plugins(); // check, has the form been submitted? $form_error = FALSE; $form_saved = FALSE; $form_action = ""; if ($_POST) { $post = Validation::factory($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('action', 'required', 'alpha', 'length[1,1]'); $post->add_rules('plugin_id.*', 'required', 'numeric'); if ($post->validate()) { if ($post->action == 'a') { // Activate Action foreach (array_unique($post->plugin_id) as $item) { $plugin = ORM::factory('plugin', $item); // Make sure we run the installer if it hasnt been installed yet. // Then mark it as installed if ($plugin->loaded and $plugin->plugin_name) { Kohana::config_set('core.modules', array_merge(Kohana::config('core.modules'), array(PLUGINPATH . $plugin->plugin_name))); // Name of the class (First letter of class should be capitalized) $class = ucfirst($plugin->plugin_name) . '_Install'; // Find the Library File $path = plugin::find_install($plugin->plugin_name); if ($path) { include $path; // Run the installer $install = new $class(); $install->run_install(); } // Mark as Active and Mark as Installed $plugin->plugin_active = 1; $plugin->plugin_installed = 1; $plugin->save(); } } } elseif ($post->action == 'i') { // Deactivate Action foreach ($post->plugin_id as $item) { $plugin = ORM::factory('plugin', $item); if ($plugin->loaded) { $plugin->plugin_active = 0; $plugin->save(); } } } elseif ($post->action == 'd') { // Delete Action foreach ($post->plugin_id as $item) { $plugin = ORM::factory('plugin', $item); if ($plugin->loaded and $plugin->plugin_name) { Kohana::config_set('core.modules', array_merge(Kohana::config('core.modules'), array(PLUGINPATH . $plugin->plugin_name))); // Name of the class (First letter of class should be capitalized) $class = ucfirst($plugin->plugin_name) . '_Install'; // Find the Library File $path = plugin::find_install($plugin->plugin_name); if ($path) { include $path; // Run the uninstaller $install = new $class(); $install->uninstall(); } // Mark as InActive and Mark as UnInstalled $plugin->plugin_active = 0; $plugin->plugin_installed = 0; $plugin->save(); } } } } else { $form_error = TRUE; } } $plugins = ORM::factory('plugin')->where($filter)->orderby('plugin_name', 'ASC')->find_all(); $this->template->content->plugins = $plugins; $this->template->content->total_items = $plugins->count(); $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; // Status Tab $this->template->content->status = $status; // Javascript Header $this->themes->js = new View('admin/addons/addons_js'); }