/** * This function allows easy activating and inactivating of plugins * @todo: a similar function needs to be written to activate or inactivate additional tools. * @author Patrick Cool <*****@*****.**>, Ghent University * @author Julio Montoya <*****@*****.**> Beeznest 2012 */ function handle_plugins() { $plugin_obj = new AppPlugin(); $token = Security::get_token(); if (isset($_POST['submit_plugins'])) { store_plugins(); // Add event to the system log. $user_id = api_get_user_id(); $category = $_GET['category']; Event::addEvent(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id); Display::display_confirmation_message(get_lang('SettingsStored')); } $all_plugins = $plugin_obj->read_plugins_from_path(); $installed_plugins = $plugin_obj->get_installed_plugins(); //Plugins NOT installed echo Display::page_subheader(get_lang('Plugins')); echo '<form class="form-horizontal" name="plugins" method="post" action="' . api_get_self() . '?category=' . Security::remove_XSS($_GET['category']) . '&sec_token=' . $token . '">'; echo '<table class="data_table">'; echo '<tr>'; echo '<th width="20px">'; echo get_lang('Action'); echo '</th><th>'; echo get_lang('Description'); echo '</th>'; echo '</tr>'; $plugin_list = array(); $my_plugin_list = $plugin_obj->get_plugin_regions(); foreach ($my_plugin_list as $plugin_item) { $plugin_list[$plugin_item] = $plugin_item; } foreach ($all_plugins as $plugin) { $plugin_info_file = api_get_path(SYS_PLUGIN_PATH) . $plugin . '/plugin.php'; if (file_exists($plugin_info_file)) { $plugin_info = array(); require $plugin_info_file; if (in_array($plugin, $installed_plugins)) { echo '<tr class="row_selected">'; } else { echo '<tr>'; } echo '<td>'; //Checkbox if (in_array($plugin, $installed_plugins)) { echo '<input type="checkbox" name="plugin_' . $plugin . '[]" checked="checked">'; } else { echo '<input type="checkbox" name="plugin_' . $plugin . '[]">'; } echo '</td><td>'; echo '<h4>' . $plugin_info['title'] . ' <small>v ' . $plugin_info['version'] . '</small></h4>'; echo '<p>' . $plugin_info['comment'] . '</p>'; echo '<p>' . get_lang('Author') . ': ' . $plugin_info['author'] . '</p>'; echo '<div class="btn-group">'; if (in_array($plugin, $installed_plugins)) { echo Display::url('<em class="fa fa-cogs"></em> ' . get_lang('Configure'), 'configure_plugin.php?name=' . $plugin, array('class' => 'btn btn-default')); echo Display::url('<em class="fa fa-th-large"></em> ' . get_lang('Regions'), 'settings.php?category=Regions&name=' . $plugin, array('class' => 'btn btn-default')); } if (file_exists(api_get_path(SYS_PLUGIN_PATH) . $plugin . '/readme.txt')) { echo Display::url("<em class='fa fa-file-text-o'></em> readme.txt", api_get_path(WEB_PLUGIN_PATH) . $plugin . "/readme.txt", ['class' => 'btn btn-default ajax', 'data-title' => $plugin_info['title'], 'data-size' => 'lg', '_target' => '_blank']); } echo '</div>'; echo '</td></tr>'; } } echo '</table>'; echo '<div class="form-actions bottom_actions">'; echo '<button class="btn btn-success" type="submit" name="submit_plugins">' . get_lang('EnablePlugins') . '</button>'; echo '</div>'; echo '</form>'; }
/** * This function allows easy activating and inactivating of plugins * @todo: a similar function needs to be written to activate or inactivate additional tools. * @author Patrick Cool <*****@*****.**>, Ghent University */ function handle_plugins() { global $SettingsStored; $userplugins = array(); $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); if (isset($_POST['submit_plugins'])) { store_plugins(); Display::display_normal_message($SettingsStored); } echo get_lang('AvailablePlugins') . "<br/><br/>"; /* We scan the plugin directory. Each folder is a potential plugin. */ $pluginpath = api_get_path(SYS_PLUGIN_PATH); $handle = @opendir($pluginpath); while (false !== ($file = readdir($handle))) { if ($file != '.' and $file != '..' and is_dir(api_get_path(SYS_PLUGIN_PATH) . $file)) { $possibleplugins[] = $file; } } @closedir($handle); /* for each of the possible plugin dirs we check if a file plugin.php (that contains all the needed information about this plugin) can be found in the dir. this plugin.php file looks like $plugin_info['title']='The title of the plugin'; // $plugin_info['comment']="Some comment about the plugin"; $plugin_info['location']=array("loginpage_menu", "campushomepage_menu","banner"); // the possible locations where the plugins can be used $plugin_info['version']='0.1 alpha'; // The version number of the plugin $plugin_info['author']='Patrick Cool'; // The author of the plugin */ echo '<form name="plugins" method="post" action="' . api_get_self() . '?category=' . $_GET['category'] . '">'; echo "<table class=\"data_table\">\n"; echo "\t<tr>\n"; echo "\t\t<th>\n"; echo get_lang('Plugin'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('LoginPageMainArea'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('LoginPageMenu'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('CampusHomepageMainArea'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('CampusHomepageMenu'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('MyCoursesMainArea'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('MyCoursesMenu'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('Header'); echo "\t\t</th>\n"; echo "\t\t<th>\n"; echo get_lang('Footer'); echo "\t\t</th>\n"; echo "\t</tr>\n"; /* We retrieve all the active plugins. */ //$sql = "SELECT * FROM $table_settings_current WHERE category='Plugins'"; //$result = api_sql_query($sql); $result = api_get_settings('Plugins'); //while ($row = mysql_fetch_array($result)) foreach ($result as $row) { $usedplugins[$row['variable']][] = $row['selected_value']; } /* We display all the possible plugins and the checkboxes */ foreach ($possibleplugins as $testplugin) { $plugin_info_file = api_get_path(SYS_PLUGIN_PATH) . $testplugin . "/plugin.php"; if (file_exists($plugin_info_file)) { $plugin_info = array(); include $plugin_info_file; echo "\t<tr>\n"; echo "\t\t<td>\n"; foreach ($plugin_info as $key => $value) { if ($key != 'location') { if ($key == 'title') { $value = '<strong>' . $value . '</strong>'; } echo get_lang(ucwords($key)) . ': ' . $value . '<br />'; } } if (file_exists(api_get_path(SYS_PLUGIN_PATH) . $testplugin . '/readme.txt')) { echo "<a href='" . api_get_path(WEB_PLUGIN_PATH) . $testplugin . "/readme.txt'>readme.txt</a>"; } echo "\t\t</td>\n"; // column: LoginPageMainArea if (empty($usedplugins)) { $usedplugins = array(); } display_plugin_cell('loginpage_main', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('loginpage_menu', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('campushomepage_main', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('campushomepage_menu', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('mycourses_main', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('mycourses_menu', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('header', $plugin_info, $testplugin, $usedplugins); display_plugin_cell('footer', $plugin_info, $testplugin, $usedplugins); echo "\t</tr>\n"; } } echo '</table>'; echo '<button class="save" type="submit" name="submit_plugins">' . get_lang('EnablePlugins') . '</button></form>'; }