diff --git a/plugin.php b/plugin.php deleted file mode 100644 index 2cf0ec9..0000000 --- a/plugin.php +++ /dev/null @@ -1,115 +0,0 @@ - 'SOC Case Management', - 'version' => PLUGIN_SOC_VERSION, - 'author' => 'Tips-Of-Mine', - 'license' => 'GPL-3.0+', - 'homepage' => 'https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management/', - 'requirements' => [ - 'glpi' => [ - 'min' => PLUGIN_SOC_MIN_GLPI, - 'max' => PLUGIN_SOC_MAX_GLPI, - ], - 'php' => [ - 'min' => '7.4.0', - ] - ] - ]; -} - -/** - * Check plugin prerequisites before installation - * - * @return boolean - */ -function plugin_soc_check_prerequisites() { - if (version_compare(GLPI_VERSION, PLUGIN_SOC_MIN_GLPI, 'lt') || version_compare(GLPI_VERSION, PLUGIN_SOC_MAX_GLPI, 'gt')) { - echo "This plugin requires GLPI >= " . PLUGIN_SOC_MIN_GLPI . " and < " . PLUGIN_SOC_MAX_GLPI; - return false; - } - return true; -} - -/** - * Check if plugin configuration is compatible with current GLPI status - * - * @return boolean - */ -function plugin_soc_check_config() { - return true; -} - -/** - * Plugin initialization - * - * @global array $PLUGIN_HOOKS - * @return void - */ -function plugin_init_soc() { - global $PLUGIN_HOOKS; - - $PLUGIN_HOOKS['csrf_compliant']['soc'] = true; - $PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase']; - $PLUGIN_HOOKS['javascript']['soc'] = ['/plugins/soc/js/soc.js']; - $PLUGIN_HOOKS['add_css']['soc'] = ['/plugins/soc/css/soc.css']; - - // Initialize translations - $PLUGIN_HOOKS['init_translations']['soc'] = 'plugin_init_soc_translations'; - - if (Session::haveRight('plugin_soc_case', READ)) { - $PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase']; - } - - // Add a tab to Changes - if (Session::haveRight('change', READ)) { - Plugin::registerClass('PluginSocCase', [ - 'addtabtypes' => ['Change'] - ]); - } - - // Add a tab to Tickets - if (Session::haveRight('ticket', READ)) { - Plugin::registerClass('PluginSocCase', [ - 'addtabtypes' => ['Ticket'] - ]); - } - - // Add config page - if (Session::haveRight('config', UPDATE)) { - $PLUGIN_HOOKS['config_page']['soc'] = 'front/config.form.php'; - } -} - -/** - * Initialize plugin translations - * - * @return void - */ -function plugin_init_soc_translations() { - global $CFG_GLPI; - - $domain = 'soc'; - $locale_dir = GLPI_ROOT . '/plugins/soc/locales/'; - - if (file_exists($locale_dir)) { - // Load plugin translations - $GLOBALS['LANG']->addTranslationFile('gettext', $locale_dir, $domain, $_SESSION['glpilanguage']); - } -} \ No newline at end of file diff --git a/setup.php b/setup.php index 83d516a..f906b63 100644 --- a/setup.php +++ b/setup.php @@ -1,133 +1,103 @@ authors) && isset($xml->authors->author)) { - foreach ($xml->authors->author as $author) { - $authors[] = (string)$author->name . (isset($author->email) ? ' <' . (string)$author->email . '>' : ''); - } - } - - $versions = []; - if (isset($xml->versions) && isset($xml->versions->version)) { - foreach ($xml->versions->version as $version) { - $versions[] = [ - 'num' => (string)$version->num, - 'minGlpiVersion' => (string)$version->compatibility, // GLPI expects minGlpiVersion - ]; - } - } - - $langs = []; - if (isset($xml->langs) && isset($xml->langs->lang)) { - foreach ($xml->langs->lang as $lang) { - $langs[] = (string)$lang; - } - } - - $tags = []; - if (isset($xml->tags)) { - foreach ($xml->tags->children() as $lang_code => $tag_list) { - $current_tags = []; - foreach ($tag_list->tag as $tag) { - $current_tags[] = (string)$tag; - } - $tags[$lang_code] = $current_tags; - } - } - - - return [ - 'name' => (string)$xml->name, - 'key' => (string)$xml->key, - 'state' => (string)$xml->state, - 'logo' => (string)$xml->logo, - 'shortdesc' => (string)$xml->description_short, // GLPI expects shortdesc - 'longdesc' => (string)$xml->description_long, // GLPI expects longdesc - 'homepage' => (string)$xml->homepage, - 'download' => (string)$xml->download, - 'issues_tracker' => (string)$xml->issues, // GLPI expects issues_tracker - 'readme' => (string)$xml->readme, - 'authors' => $authors, - 'versions' => $versions, - 'langs' => $langs, - 'license' => (string)$xml->license, - 'tags' => $tags, - 'minGlpiVersion' => !empty($versions) ? $versions[count($versions)-1]['minGlpiVersion'] : '' // Default to last version's compatibility - ]; +function plugin_version_soc() { + return [ + 'name' => 'SOC Case Management', + 'version' => PLUGIN_SOC_VERSION, + 'author' => 'Tips-Of-Mine', + 'license' => 'GPL-3.0+', + 'homepage' => 'https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management/', + 'requirements' => [ + 'glpi' => [ + 'min' => PLUGIN_SOC_MIN_GLPI, + 'max' => PLUGIN_SOC_MAX_GLPI, + ], + 'php' => [ + 'min' => '7.4.0', + ] + ] + ]; } /** - * Initialize plugin options - * - * @return array - */ -function plugin_init_options() { - return [ - 'name' => __('SOC Case Management', 'soc'), - 'key' => 'soc', - 'tooltip' => __('SOC Case Management integration plugin for security teams.', 'soc'), - ]; -} - -/** - * Check plugin prerequisites. + * Check plugin prerequisites before installation * * @return boolean */ -function plugin_check_prerequisites() { - // For now, always return true - return true; +function plugin_soc_check_prerequisites() { + if (version_compare(GLPI_VERSION, PLUGIN_SOC_MIN_GLPI, 'lt') || version_compare(GLPI_VERSION, PLUGIN_SOC_MAX_GLPI, 'gt')) { + echo "This plugin requires GLPI >= " . PLUGIN_SOC_MIN_GLPI . " and < " . PLUGIN_SOC_MAX_GLPI; + return false; + } + return true; } /** - * Check plugin configuration. - * - * @param boolean $verbose Enable verbose mode (default false) + * Check if plugin configuration is compatible with current GLPI status * * @return boolean */ -function plugin_check_config($verbose = false) { - // For now, always return true - return true; +function plugin_soc_check_config() { + return true; } /** - * Display plugin configuration page. + * Plugin initialization * + * @global array $PLUGIN_HOOKS * @return void */ -function plugin_display_config() { - // Currently does nothing +function plugin_init_soc() { + global $PLUGIN_HOOKS; + + $PLUGIN_HOOKS['csrf_compliant']['soc'] = true; + $PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase']; + $PLUGIN_HOOKS['javascript']['soc'] = ['plugins/soc/js/soc.js']; + $PLUGIN_HOOKS['add_css']['soc'] = ['plugins/soc/css/soc.css']; + + // Initialize translations + Plugin::registerClass('PluginSocCase'); + + if (Session::haveRight('plugin_soc_case', READ)) { + $PLUGIN_HOOKS['menu_toadd']['soc'] = ['management' => 'PluginSocCase']; + } + + // Add a tab to Changes + if (Session::haveRight('change', READ)) { + Plugin::registerClass('PluginSocCase', [ + 'addtabtypes' => ['Change'] + ]); + } + + // Add a tab to Tickets + if (Session::haveRight('ticket', READ)) { + Plugin::registerClass('PluginSocCase', [ + 'addtabtypes' => ['Ticket'] + ]); + } + + // Add config page + if (Session::haveRight('config', UPDATE)) { + $PLUGIN_HOOKS['config_page']['soc'] = 'front/config.form.php'; + } } /** - * Init the hooks of the plugin + * Install all necessary elements for the plugin * - * @return void + * @return boolean */ function plugin_soc_install() { global $DB; @@ -228,63 +198,4 @@ function plugin_soc_uninstall() { PluginSocConfig::uninstall(); return true; -} - -/** - * Define database relations - */ -function plugin_soc_getDatabaseRelations() { - return [ - 'glpi_entities' => [ - 'glpi_plugin_soc_cases' => 'entities_id' - ], - 'glpi_users' => [ - 'glpi_plugin_soc_cases' => 'users_id_tech' - ], - 'glpi_groups' => [ - 'glpi_plugin_soc_cases' => 'groups_id_tech' - ], - 'glpi_tickets' => [ - 'glpi_plugin_soc_case_tickets' => 'tickets_id' - ], - 'glpi_changes' => [ - 'glpi_plugin_soc_case_changes' => 'changes_id' - ], - 'glpi_plugin_soc_cases' => [ - 'glpi_plugin_soc_case_tickets' => 'plugin_soc_cases_id', - 'glpi_plugin_soc_case_changes' => 'plugin_soc_cases_id' - ] - ]; -} - -/** - * Define display preferences - */ -function plugin_soc_getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - $tabs = []; - - if ($item->getType() == 'Ticket' && Session::haveRight("plugin_soc_case", READ)) { - $tabs[1] = __('SOC Cases', 'soc'); - } - - if ($item->getType() == 'Change' && Session::haveRight("plugin_soc_case", READ)) { - $tabs[1] = __('SOC Cases', 'soc'); - } - - return $tabs; -} - -/** - * Define right names - */ -function plugin_soc_getRights($itemtype = '') { - $rights = [ - [ - 'itemtype' => 'PluginSocCase', - 'label' => __('SOC Case', 'soc'), - 'field' => 'plugin_soc_case' - ] - ]; - - return $rights; -} +} \ No newline at end of file