/** * Load addon Information from readme.txt file * * @param string addon name * @param string addon type * @param array default meta data * @return array */ public static function meta_data($addon, $type, $defaults = array()) { $base = $type == 'plugin' ? PLUGINPATH : THEMEPATH; // Determine if readme.txt (Case Insensitive) exists $file = $base . $addon . "/readme.txt"; if (file::file_exists_i($file, $file)) { $fp = fopen($file, 'r'); // Pull only the first 8kiB of the file in. $file_data = fread($fp, 8192); fclose($fp); preg_match_all('/^(.*):(.*)$/mU', $file_data, $matches, PREG_PATTERN_ORDER); $meta_data = array_combine(array_map('trim', $matches[1]), array_map('trim', $matches[2])); foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) { if (file_exists($base . $addon . "/screenshot.{$ext}")) { $meta_data['Screenshot'] = "screenshot.{$ext}"; break; } } return arr::merge($defaults, $meta_data); } return false; }
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('mysql_real_escape_string', Kohana::config('plugins.hide_from_list')); $filter .= ' AND plugin_name NOT IN (\'' . implode("','", $hide_from_list) . '\')'; } $db = new Database(); // Update the plugin list in the database $d = dir(PLUGINPATH); $directories = array(); while (($entry = $d->read()) !== FALSE) { // Set the plugin to not enabled by default // Don't include hidden folders if ($entry[0] != '.') { $directories[$entry] = FALSE; } } // Sync the folder with the database foreach ($directories as $dir => $found) { // Only include the plugin if it contains readme.txt $file = PLUGINPATH . $dir . "/readme.txt"; if (file::file_exists_i($file) and !count($db->from('plugin')->where('plugin_name', $dir)->limit(1)->get())) { $plugin = ORM::factory('plugin'); $plugin->plugin_name = $dir; $plugin->save(); } } // Remove Any Plugins not found in the plugins folder from the database foreach (ORM::factory('plugin')->find_all() as $plugin) { $file = PLUGINPATH . $plugin->plugin_name . "/readme.txt"; if (!array_key_exists($plugin->plugin_name, $directories) or !file::file_exists_i($file)) { $plugin->delete(); } } // 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('comment_id.*', 'required', 'numeric'); if ($post->validate()) { if ($post->action == 'a') { // Activate Action foreach ($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 = $this->_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 = $this->_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->template->js = new View('admin/addons/addons_js'); }
/** * Discover Plugin Settings Controller * * @param string plugin name * @return mixed Plugin settings page on success, FALSE otherwise */ public static function settings($plugin = NULL) { // Determine if readme.txt (Case Insensitive) exists $file = PLUGINPATH . $plugin . "/controllers/admin/" . $plugin . "_settings.php"; if (file::file_exists_i($file)) { return $plugin . "_settings"; } else { return FALSE; } }
/** * Find plugin install file * Using this function because someone somewhere will name this file wrong!!! * @param string $plugin */ public static function find_install($plugin, $type = 'plugin') { $base = $type == 'plugin' ? PLUGINPATH : THEMEPATH; // Determine if readme.txt (Case Insensitive) exists $file = $base . "{$plugin}/libraries/{$plugin}_install.php"; $real_path = null; if (file::file_exists_i($file, $real_path)) { return $real_path; } else { return FALSE; } }