Improving plugin system see #4450 adding new parameters in order to install a plugin

skala
jmontoya 14 years ago
parent c9ca73aede
commit 8996ea90b1
  1. 5
      main/admin/configure_extensions.php
  2. 58
      main/admin/configure_plugin.php
  3. 3
      main/admin/index.php
  4. 201
      main/admin/settings.lib.php
  5. 4
      main/admin/settings.php
  6. 8
      main/inc/lib/database.lib.php
  7. 34
      main/inc/lib/main_api.lib.php
  8. 95
      main/inc/lib/plugin.lib.php
  9. 2
      main/inc/lib/template.lib.php
  10. 11
      plugin/hello_world/index.php
  11. 12
      plugin/hello_world/plugin.php
  12. 5
      plugin/show_regions/index.php
  13. 5
      plugin/show_regions/plugin.php
  14. 0
      plugin/show_regions/readme.txt

@ -1,5 +1,5 @@
<?php // $Id: configure_homepage.php 9246 2006-09-25 13:24:53 +0000 (lun., 25 sept. 2006) bmol $ <?php
/* For licensing terms, see /chamilo_license.txt */ /* For licensing terms, see /license.txt */
// name of the language file that needs to be included // name of the language file that needs to be included
$language_file='admin'; $language_file='admin';
@ -244,6 +244,7 @@ Display::display_header($nameTool);
- please fill free to improve the global display of the document - please fill free to improve the global display of the document
--> -->
<!-- VISIOCONFERENCE --> <!-- VISIOCONFERENCE -->
<div id="main_visio"> <div id="main_visio">
<div id="extension_header_visio" class="accordion_header"> <div id="extension_header_visio" class="accordion_header">
<a href="#"><?php echo get_lang('Visioconf') ?></a> <a href="#"><?php echo get_lang('Visioconf') ?></a>

@ -0,0 +1,58 @@
<?php
/* For licensing terms, see /license.txt */
/**
@author Julio Montoya <gugli100@gmail.com> BeezNest 2012
* @package chamilo.admin
*/
// name of the language file that needs to be included
$language_file = array ('registration','admin');
$cidReset = true;
require_once '../inc/global.inc.php';
$plugin_name = $_GET['name'];
$plugin_obj = new AppPlugin();
$plugin_info = $plugin_obj->get_plugin_info($plugin_name, true);
if (empty($plugin_info)) {
api_not_allowed();
}
$installed_plugins = $plugin_obj->get_installed_plugins();
if (!in_array($plugin_name, $installed_plugins)) {
api_not_allowed();
}
global $_configuration;
$content = '';
if (isset($plugin_info['settings_form'])) {
$form = $plugin_info['settings_form'];
if (isset($form)) {
//We override the form attributes
$attributes = array('action'=>api_get_self().'?name='.$plugin_name, 'method'=>'POST');
$form->updateAttributes($attributes);
$content = $form->toHtml();
}
}
if ($form->validate()) {
$values = $form->exportValues();
//api_delete_category_settings_by_subkey($plugin_name);
$access_url_id = api_get_current_access_url_id();
api_delete_settings_params(array('category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' =>
array('Plugins', $access_url_id, $plugin_name, 'setting', "status")));
foreach ($values as $key => $value) {
$key = Database::escape_string($plugin_name.'_'.$key);
api_add_setting($value, $key, $plugin_name, 'setting', 'Plugins', $plugin_name, null, null, null, $_configuration['access_url'], 1);
}
}
$tpl = new Template($tool_name);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -128,7 +128,6 @@ if (api_is_platform_admin()) {
$blocks['platform']['icon'] = Display::return_icon('platform.png', get_lang('Platform'), array(), ICON_SIZE_MEDIUM, false); $blocks['platform']['icon'] = Display::return_icon('platform.png', get_lang('Platform'), array(), ICON_SIZE_MEDIUM, false);
$blocks['platform']['label'] = api_ucfirst(get_lang('Platform')); $blocks['platform']['label'] = api_ucfirst(get_lang('Platform'));
$search_form = ' <form method="get" action="settings.php" class="form-search"> $search_form = ' <form method="get" action="settings.php" class="form-search">
<input type="text" name="search_field" value="" > <input type="text" name="search_field" value="" >
<input type="hidden" value="search_setting" name="category"> <input type="hidden" value="search_setting" name="category">
@ -139,6 +138,8 @@ if (api_is_platform_admin()) {
$items = array(); $items = array();
$items[] = array('url'=>'settings.php', 'label' => get_lang('PlatformConfigSettings')); $items[] = array('url'=>'settings.php', 'label' => get_lang('PlatformConfigSettings'));
$items[] = array('url'=>'settings.php?category=Plugins','label' => get_lang('Plugins'));
$items[] = array('url'=>'settings.php?category=Regions','label' => get_lang('Regions'));
$items[] = array('url'=>'system_announcements.php', 'label' => get_lang('SystemAnnouncements')); $items[] = array('url'=>'system_announcements.php', 'label' => get_lang('SystemAnnouncements'));
$items[] = array('url'=>api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=admin', 'label' => get_lang('GlobalAgenda')); $items[] = array('url'=>api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=admin', 'label' => get_lang('GlobalAgenda'));
$items[] = array('url'=>'configure_homepage.php', 'label' => get_lang('ConfigureHomePage')); $items[] = array('url'=>'configure_homepage.php', 'label' => get_lang('ConfigureHomePage'));

@ -11,20 +11,14 @@
* @package chamilo.admin * @package chamilo.admin
*/ */
/** /**
* This function allows easy activating and inactivating of plugins * This function allows easy activating and inactivating of regions
* @todo: a similar function needs to be written to activate or inactivate additional tools. * @author Julio Montoya <gugli100@gmail.com> Beeznest 2012
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/ */
function handle_plugins() { function handle_regions() {
global $SettingsStored;
$userplugins = array();
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
if (isset($_POST['submit_plugins'])) { if (isset($_POST['submit_plugins'])) {
store_plugins(); store_regions();
// Add event to the system log. // Add event to the system log.
$user_id = api_get_user_id(); $user_id = api_get_user_id();
$category = $_GET['category']; $category = $_GET['category'];
@ -33,32 +27,22 @@ function handle_plugins() {
} }
$plugin_obj = new AppPlugin(); $plugin_obj = new AppPlugin();
$possible_plugins = $plugin_obj->read_plugins_from_path(); $possible_plugins = $plugin_obj->read_plugins_from_path();
$installed_plugins = $plugin_obj->get_installed_plugins();
if (!empty($installed_plugins)) {
$not_installed = array_diff($possible_plugins, $installed_plugins);
} else {
$not_installed = $possible_plugins;
}
echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">'; echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">';
echo '<table class="data_table">'; echo '<table class="data_table">';
echo '<tr>'; echo '<tr>';
echo '<th width="400px">'; echo '<th width="400px">';
echo get_lang('Plugin'); echo get_lang('Plugin');
echo '</th><th>'; echo '</th><th>';
echo get_lang('PluginArea').''; echo get_lang('Blocks');
echo '</th>'; echo '</th>';
/*
echo get_lang('LoginPageMenu').'<br />(loginpage_menu)';
echo '</th><th>';
echo get_lang('CampusHomepageMainArea').'<br />(campushomepage_main)';
echo '</th><th>';
echo get_lang('CampusHomepageMenu').'<br />(campushomepage_menu)';
echo '</th><th>';
echo get_lang('MyCoursesMainArea').'<br />(mycourses_main)';
echo '</th><th>';
echo get_lang('MyCoursesMenu').'<br />(mycourses_menu)';
echo '</th><th>';
echo get_lang('Header').'<br />(header)';
echo '</th><th>';
echo get_lang('Footer').'<br />(footer)';
echo '</th><th>';
echo get_lang('CourseTool').'';*/
echo '</th>'; echo '</th>';
echo '</tr>'; echo '</tr>';
@ -70,7 +54,7 @@ function handle_plugins() {
$plugin_list[$plugin_item] = $plugin_item; $plugin_list[$plugin_item] = $plugin_item;
} }
foreach ($possible_plugins as $plugin) { foreach ($installed_plugins as $plugin) {
$plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$plugin.'/plugin.php'; $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$plugin.'/plugin.php';
if (file_exists($plugin_info_file)) { if (file_exists($plugin_info_file)) {
@ -78,12 +62,12 @@ function handle_plugins() {
require $plugin_info_file; require $plugin_info_file;
echo '<tr>'; echo '<tr>';
echo '<td>'; echo '<td>';
echo '<h3>'.$plugin_info['title'].' <small>v '.$plugin_info['version'].'</small></h3>'; echo '<h4>'.$plugin_info['title'].' <small>v '.$plugin_info['version'].'</small></h4>';
echo '<p>'.$plugin_info['comment'].'</p>'; echo '<p>'.$plugin_info['comment'].'</p>';
echo '<p>'.get_lang('Author').': '.$plugin_info['author'].'</p>'; echo '<p>'.get_lang('Author').': '.$plugin_info['author'].'</p>';
if (file_exists(api_get_path(SYS_PLUGIN_PATH).$plugin.'/readme.txt')) { if (file_exists(api_get_path(SYS_PLUGIN_PATH).$plugin.'/readme.txt')) {
echo "<a href='".api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt'>readme.txt</a>"; echo "<a href='".api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt' class='ajax'>readme.txt</a>";
} }
echo '</td><td>'; echo '</td><td>';
$selected_plugins = $plugin_obj->get_areas_by_plugin($plugin); $selected_plugins = $plugin_obj->get_areas_by_plugin($plugin);
@ -97,21 +81,89 @@ function handle_plugins() {
echo '<br />'; echo '<br />';
echo '<button class="save" type="submit" name="submit_plugins">'.get_lang('EnablePlugins').'</button></form>'; echo '<button class="save" type="submit" name="submit_plugins">'.get_lang('EnablePlugins').'</button></form>';
echo '<br />'; echo '<br />';
} }
function display_plugin_cell($location, $plugin_info, $current_plugin, $active_plugins) { /**
echo '<td align="center">'; * This function allows easy activating and inactivating of plugins
if (in_array($location, $plugin_info['location'])) { * @todo: a similar function needs to be written to activate or inactivate additional tools.
if (isset($active_plugins[$location]) && is_array($active_plugins[$location]) * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
&& in_array($current_plugin, $active_plugins[$location])) { * @author Julio Montoya <gugli100@gmail.com> Beeznest 2012
$checked = 'checked'; */
} else { function handle_plugins() {
$checked = ''; $plugin_obj = new AppPlugin();
if (isset($_POST['submit_plugins'])) {
store_plugins();
// Add event to the system log.
$user_id = api_get_user_id();
$category = $_GET['category'];
event_system(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();
$not_installed = array_diff($all_plugins, $installed_plugins);
//Plugins NOT installed
echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">';
echo '<table class="data_table">';
echo '<tr>';
echo '<th width="20px">';
echo get_lang('Plugin');
echo '</th><th>';
echo get_lang('InstallPlugin');
echo '</th>';
echo '</th>';
echo '</tr>';
$plugin_list = array();
$my_plugin_list = $plugin_obj->get_plugin_blocks();
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;
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(get_lang('Configure'), 'configure_plugin.php?name='.$plugin, array('class' => 'btn'));
}
if (file_exists(api_get_path(SYS_PLUGIN_PATH).$plugin.'/readme.txt')) {
echo Display::url("readme.txt", api_get_path(WEB_PLUGIN_PATH).$plugin."/readme.txt", array('class' => 'btn ajax', '_target' => '_blank'));
}
echo '</div>';
echo '</td></tr>';
} }
echo '<input type="checkbox" name="'.$current_plugin.'-'.$location.'" value="true" '.$checked.'/>';
} }
echo "</td>"; echo '</table>';
echo '<br />';
echo '<button class="save" type="submit" name="submit_plugins">'.get_lang('EnablePlugins').'</button></form>';
echo '<br />';
} }
/** /**
@ -348,53 +400,60 @@ function upload_stylesheet($values, $picture) {
return $result; return $result;
} }
function store_regions() {
$plugin_obj = new AppPlugin();
// Get a list of all current 'Plugins' settings
$installed_plugins = $plugin_obj->get_installed_plugins();
$shortlist_installed = array();
foreach ($installed_plugins as $plugin) {
$shortlist_installed[] = $plugin['subkey'];
}
$shortlist_installed = array_flip(array_flip($shortlist_installed));
$plugin_list = $plugin_obj->read_plugins_from_path();
foreach ($plugin_list as $plugin) {
if (isset($_POST['plugin_'.$plugin])) {
$areas_to_installed = $_POST['plugin_'.$plugin];
$plugin_obj->remove_all_regions($plugin);
foreach ($areas_to_installed as $region) {
$plugin_obj->add_to_region($plugin, $region);
}
}
}
}
/** /**
* This function allows easy activating and inactivating of plugins * 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 <patrick.cool@UGent.be>, Ghent University * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/ */
function store_plugins() { function store_plugins() {
global $_configuration;
$plugin_obj = new AppPlugin(); $plugin_obj = new AppPlugin();
// Get a list of all current 'Plugins' settings // Get a list of all current 'Plugins' settings
$installed_plugins = api_get_settings('Plugins','list', $_configuration['access_url']);
$shortlist_installed = array();
foreach ($installed_plugins as $plugin) {
$shortlist_installed[] = $plugin['subkey'];
}
$shortlist_installed = array_flip(array_flip($shortlist_installed));
$r = api_delete_category_settings('Plugins', $_configuration['access_url']);
$plugin_list = $plugin_obj->read_plugins_from_path(); $plugin_list = $plugin_obj->read_plugins_from_path();
$installed_plugins = array();
foreach ($plugin_list as $plugin) { foreach ($plugin_list as $plugin) {
if (isset($_POST['plugin_'.$plugin])) { if (isset($_POST['plugin_'.$plugin])) {
$areas_to_installed = $_POST['plugin_'.$plugin]; $plugin_obj->install($plugin);
foreach ($areas_to_installed as $area) { $installed_plugins[] = $plugin;
api_add_setting($plugin, $area, $plugin, null, 'Plugins', $plugin, null, null, null, $_configuration['access_url'], 1);
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin.'/install.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the install procedure
require $pluginpath;
}
}
} }
} }
foreach ($shortlist_installed as $plugin) { if (!empty($installed_plugins)) {
// if one plugin was really deleted, execute the uninstall script $remove_plugins = array_diff($plugin_list, $installed_plugins);
if (!in_array($plugin,$shortlist_required)) { } else {
// check if there is an uninstall procedure $remove_plugins = $plugin_list;
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin.'/uninstall.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the uninstall procedure
require $pluginpath;
}
}
} }
foreach ($remove_plugins as $plugin) {
$plugin_obj->uninstall($plugin);
}
} }
@ -404,8 +463,6 @@ function store_plugins() {
*/ */
function store_stylesheets() { function store_stylesheets() {
global $_configuration; global $_configuration;
// Database table definitions.
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
// Insert the stylesheet. // Insert the stylesheet.
$style = Database::escape_string($_POST['style']); $style = Database::escape_string($_POST['style']);

@ -386,6 +386,9 @@ if (isset($form) && $form->validate()) {
if (!empty($_GET['category'])) { if (!empty($_GET['category'])) {
switch ($_GET['category']) { switch ($_GET['category']) {
case 'Regions':
handle_regions();
break;
case 'Plugins': case 'Plugins':
// Displaying the extensions: Plugins. // Displaying the extensions: Plugins.
// This will be available to all the sites (access_urls). // This will be available to all the sites (access_urls).
@ -401,7 +404,6 @@ if (!empty($_GET['category'])) {
} }
handle_plugins(); handle_plugins();
DashboardManager::handle_dashboard_plugins(); DashboardManager::handle_dashboard_plugins();
break; break;
case 'stylesheets': case 'stylesheets':
// Displaying the extensions: Stylesheets. // Displaying the extensions: Stylesheets.

@ -1141,7 +1141,10 @@ class Database {
/** /**
* Experimental useful database finder * Experimental useful database finder
* @todo lot of stuff to do here * @todo lot of stuff to do here
* @todo known issues, it doesn't work when using LIKE conditions example: array('where'=>array('course_code LIKE "?%"')) * @todo known issues, it doesn't work when using LIKE conditions
* @example array('where'=> array('course_code LIKE "?%"'))
* @example array('where'=> array('type = ? AND category = ?' => array('setting', 'Plugins'))
* @example array('where'=> array('name = "Julio" AND lastname = "montoya"))
*/ */
public static function select($columns, $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') { public static function select($columns, $table_name, $conditions = array(), $type_result = 'all', $option = 'ASSOC') {
@ -1196,6 +1199,7 @@ class Database {
$type_condition = strtolower($type_condition); $type_condition = strtolower($type_condition);
switch ($type_condition) { switch ($type_condition) {
case 'where': case 'where':
foreach ($condition_data as $condition => $value_array) { foreach ($condition_data as $condition => $value_array) {
if (is_array($value_array)) { if (is_array($value_array)) {
$clean_values = array(); $clean_values = array();
@ -1223,6 +1227,8 @@ class Database {
$where_return .= $condition; $where_return .= $condition;
} }
} }
if (!empty($where_return)) { if (!empty($where_return)) {
$return_value = " WHERE $where_return" ; $return_value = " WHERE $where_return" ;
} }

@ -1137,7 +1137,6 @@ function api_get_cidreq() {
*/ */
function api_get_course_info($course_code = null) { function api_get_course_info($course_code = null) {
if (!empty($course_code)) { if (!empty($course_code)) {
//global $_course;var_dump($_course);
$course_code = Database::escape_string($course_code); $course_code = Database::escape_string($course_code);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE); $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY); $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
@ -1913,6 +1912,25 @@ function api_get_setting($variable, $key = null) {
return $value; return $value;
} }
/**
* Returns the value of a setting from the web-adjustable admin config settings.
**/
function api_get_settings_params($params) {
$table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$result = Database::select('*', $table, array('where' => $params));
return $result;
}
/**
* Returns the value of a setting from the web-adjustable admin config settings.
**/
function api_delete_settings_params($params) {
$table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$result = Database::delete($table, $params);
return $result;
}
/** /**
* Returns an escaped version of $_SERVER['PHP_SELF'] to avoid XSS injection * Returns an escaped version of $_SERVER['PHP_SELF'] to avoid XSS injection
* @return string Escaped version of $_SERVER['PHP_SELF'] * @return string Escaped version of $_SERVER['PHP_SELF']
@ -4181,6 +4199,7 @@ function & api_get_settings_categories($exceptions = array(), $access_url = 1) {
* @param int Access URL * @param int Access URL
* @return boolean False on failure, true on success * @return boolean False on failure, true on success
*/ */
function api_delete_setting($v, $s = null, $a = 1) { function api_delete_setting($v, $s = null, $a = 1) {
if (empty($v)) { return false; } if (empty($v)) { return false; }
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
@ -4200,17 +4219,16 @@ function api_delete_setting($v, $s = null, $a = 1) {
/** /**
* Deletes all the settings from one category * Deletes all the settings from one category
* @param string Category * @param string Subkey
* @param int Access URL * @param int Access URL
* @return boolean False on failure, true on success * @return boolean False on failure, true on success
*/ */
function api_delete_category_settings($c, $a = 1) { function api_delete_category_settings_by_subkey($subkey, $access_url_id = 1) {
if (empty($c)) { return false; } if (empty($subkey)) { return false; }
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$c = Database::escape_string($c); $subkey = Database::escape_string($subkey);
$a = (int) $a; $access_url_id = intval($access_url_id);
if (empty($a)) { $a = 1; } $sql = "DELETE FROM $t_cs WHERE subkey = '$subkey' AND access_url = $access_url_id";
$sql = "DELETE FROM $t_cs WHERE category = '$c' AND access_url = $a";
$r = Database::query($sql); $r = Database::query($sql);
return $r; return $r;
} }

@ -50,7 +50,6 @@ class AppPlugin {
return $possible_plugins; return $possible_plugins;
} }
function get_installed_plugins_by_block(){ function get_installed_plugins_by_block(){
$usedplugins = array(); $usedplugins = array();
/* We retrieve all the active plugins. */ /* We retrieve all the active plugins. */
@ -63,16 +62,41 @@ class AppPlugin {
function get_installed_plugins() { function get_installed_plugins() {
$installed_plugins = array(); $installed_plugins = array();
$result = api_get_settings('Plugins'); $plugin_array = api_get_settings_params(array("variable = ? AND selected_value = ? AND category = ? " =>
if (!empty($result)) { array('status', 'installed', 'Plugins')));
foreach ($result as $row) {
$installed_plugins[$row['selected_value']] = true; if (!empty($plugin_array)) {
foreach ($plugin_array as $row) {
$installed_plugins[$row['subkey']] = true;
} }
$installed_plugins = array_keys($installed_plugins); $installed_plugins = array_keys($installed_plugins);
} }
return $installed_plugins; return $installed_plugins;
} }
function install($plugin_name, $access_url_id) {
$access_url_id = api_get_current_access_url_id();
api_add_setting('installed', 'status', $plugin_name, 'setting', 'Plugins', $plugin_name, null, null, null, $access_url_id, 1);
//api_add_setting($plugin, $area, $plugin, null, 'Plugins', $plugin, null, null, null, $_configuration['access_url'], 1);
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin_name.'/install.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the install procedure
require $pluginpath;
}
}
function uninstall($plugin_name) {
$access_url_id = api_get_current_access_url_id();
api_delete_settings_params(array('category = ? AND access_url = ? AND subkey = ? ' =>
array('Plugins', $access_url_id, $plugin_name)));
$pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin_name.'/uninstall.php';
if (is_file($pluginpath) && is_readable($pluginpath)) {
//execute the uninstall procedure
require $pluginpath;
}
}
function get_areas_by_plugin($plugin_name) { function get_areas_by_plugin($plugin_name) {
$result = api_get_settings('Plugins'); $result = api_get_settings('Plugins');
$areas = array(); $areas = array();
@ -117,16 +141,18 @@ class AppPlugin {
* @param smarty obj * @param smarty obj
* @todo improve this function * @todo improve this function
*/ */
function get_all_plugin_contents_by_block($block, $main_template) { function get_all_plugin_contents_by_block($block, $template) {
global $_plugins; global $_plugins;
if (isset($_plugins[$block]) && is_array($_plugins[$block])) { if (isset($_plugins[$block]) && is_array($_plugins[$block])) {
foreach ($_plugins[$block] as $plugin_name) { foreach ($_plugins[$block] as $plugin_name) {
//Load the plugin information //Load the plugin information
//
//The plugin_info variable is available inside the plugin index //The plugin_info variable is available inside the plugin index
$plugin_info = $this->get_plugin_info($plugin_name); $plugin_info = $this->get_plugin_info($plugin_name);
//We also where the plugin is //We also where the plugin is
$plugin_info['current_block'] = $block; $plugin_info['current_region'] = $block;
// Loading the plugin/XXX/index.php file // Loading the plugin/XXX/index.php file
require api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php"; require api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php";
@ -134,7 +160,7 @@ class AppPlugin {
//We set the $template variable in order to use smarty //We set the $template variable in order to use smarty
if (isset($_template) && !empty($_template)) { if (isset($_template) && !empty($_template)) {
foreach($_template as $key =>$value) { foreach($_template as $key =>$value) {
$main_template->assign($key, $value); $template->assign($key, $value);
} }
} }
@ -144,24 +170,31 @@ class AppPlugin {
$template_list = $plugin_info['templates']; $template_list = $plugin_info['templates'];
} }
//var_dump($plugin_info);
if (!empty($template_list)) { if (!empty($template_list)) {
foreach($template_list as $plugin_tpl) { foreach($template_list as $plugin_tpl) {
if (!empty($plugin_tpl)) { if (!empty($plugin_tpl)) {
$template_plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/$plugin_tpl"; $template_plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/$plugin_tpl";
$main_template->display($template_plugin_file); $template->display($template_plugin_file);
} }
} }
} }
} }
} }
return false; return true;
} }
function get_plugin_info($plugin_name) { /**
*
* Loads plugin info
* @staticvar array $plugin_data
* @param type $plugin_name
* @param type bool
* @todo filter setting_form
* @return array
*/
function get_plugin_info($plugin_name, $forced = false) {
static $plugin_data = array(); static $plugin_data = array();
if (isset($plugin_data[$plugin_name])) { if (isset($plugin_data[$plugin_name]) && $forced == false) {
return $plugin_data[$plugin_name]; return $plugin_data[$plugin_name];
} else { } else {
$plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/plugin.php"; $plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/plugin.php";
@ -170,10 +203,22 @@ class AppPlugin {
require $plugin_file; require $plugin_file;
} }
$plugin_data[$plugin_name] = $plugin_info; $plugin_data[$plugin_name] = $plugin_info;
//extra options
$plugin_settings = api_get_settings_params(array("subkey = ? AND category = ? AND type = ? " =>
array($plugin_name, 'Plugins','setting')));
$settings_filtered = array();
foreach ($plugin_settings as $item) {
$settings_filtered[$item['variable']] = $item['selected_value'];
}
$plugin_info['settings'] = $settings_filtered;
return $plugin_info; return $plugin_info;
} }
} }
/*
* Get the template list
*/
function get_templates_list($plugin_name) { function get_templates_list($plugin_name) {
$plugin_info = $this->get_plugin_info($plugin_name); $plugin_info = $this->get_plugin_info($plugin_name);
if (isset($plugin_info) && isset($plugin_info['templates'])) { if (isset($plugin_info) && isset($plugin_info['templates'])) {
@ -182,4 +227,24 @@ class AppPlugin {
return false; return false;
} }
} }
/* *
* Remove all regions of an specific plugin
*/
function remove_all_regions($plugin) {
$access_url_id = api_get_current_access_url_id();
if (!empty($plugin)) {
api_delete_settings_params(array('category = ? AND variable = ? AND access_url = ? AND subkey = ? ' =>
array('Plugins', 'region', $access_url_id, $plugin)));
}
}
/*
* Add a plugin to a region
*/
function add_to_region($plugin, $region) {
$access_url_id = api_get_current_access_url_id();
api_add_setting($plugin, $region, $plugin, 'region', 'Plugins', $plugin, null, null, null, $access_url_id, 1);
}
} }

@ -78,9 +78,7 @@ class Template extends Smarty {
foreach ($plugin_blocks as $block) { foreach ($plugin_blocks as $block) {
$this->set_plugin_block($block); $this->set_plugin_block($block);
} }
$this->load_plugin_template(); $this->load_plugin_template();
} }
function set_help($help_input = null) { function set_help($help_input = null) {

@ -3,7 +3,10 @@
* Controller for example date plugin * Controller for example date plugin
* @package chamilo.plugin.date * @package chamilo.plugin.date
*/ */
/**
* Code
*/ if (!empty($plugin_info['settings']['hello_world_show_type'])) {
echo "<h2>Hello world</h2>"; echo "<h2>".$plugin_info['settings']['hello_world_show_type']."</h2>";
} else {
echo "<h2>Hello worlds</h2>";
}

@ -17,3 +17,15 @@ $plugin_info['comment'] = "Shows a hello world message";
$plugin_info['version'] = '1.0'; $plugin_info['version'] = '1.0';
//the plugin author //the plugin author
$plugin_info['author'] = 'Julio Montoya'; $plugin_info['author'] = 'Julio Montoya';
//More complex options for the plugin (optional)
$form = new FormValidator();
//A simple select
$options = array('hello_world' => 'Hello World', 'hello' =>'Hello', 'hi' =>'Hi!');
$form->addElement('select', 'show_type', 'Hello world types', $options);
$form->addElement('style_submit_button', 'submit_button', get_lang('Save'));
$plugin_info['settings_form'] = $form;

@ -1,8 +1,9 @@
<?php <?php
//only show the block information if the admin is logged in
//only show the region information if the admin is logged in
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
echo '<div style="color:black;height:50px;width:200px;background-color:#FFE378">'; echo '<div style="color:black;height:50px;width:200px;background-color:#FFE378">';
//We can have access to the current block and the block information with the variable $plugin_info (see your plugin.php) //We can have access to the current block and the block information with the variable $plugin_info (see your plugin.php)
echo $plugin_info['current_block']; echo $plugin_info['current_region'];
echo '</div>'; echo '</div>';
} }

@ -10,10 +10,11 @@
*/ */
//the plugin title //the plugin title
$plugin_info['title'] = 'Show template blocks'; $plugin_info['title'] = 'Show regions';
//the comments that go with the plugin //the comments that go with the plugin
$plugin_info['comment'] = "This is useful when trying to find the blocks, (<strong>only the admin </strong>can view this plugin). You have to activate all the items in the Plugin area"; $plugin_info['comment'] = "This is useful when trying to find the Chamilo regions, (<strong>only the admin </strong>can view this plugin). You have to activate all the items in the Regions area";
//the plugin version //the plugin version
$plugin_info['version'] = '1.0'; $plugin_info['version'] = '1.0';
//the plugin author //the plugin author
$plugin_info['author'] = 'Julio Montoya'; $plugin_info['author'] = 'Julio Montoya';
Loading…
Cancel
Save