Adding some commets + using get_lang and other examples in the show user info plugin see #4450

skala
Julio Montoya 14 years ago
parent 7743980b2f
commit 44c220b1a6
  1. 21
      main/admin/settings.lib.php
  2. 32
      main/inc/lib/plugin.lib.php
  3. 2
      main/template/default/layout/layout_1_col.tpl
  4. 4
      main/template/default/layout/layout_2_col.tpl
  5. 18
      plugin/show_user_info/index.php
  6. 2
      plugin/show_user_info/plugin.php
  7. 33
      plugin/show_user_info/template.tpl

@ -38,7 +38,7 @@ function handle_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="300px">'; 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('PluginArea').'';
@ -62,8 +62,6 @@ function handle_plugins() {
echo '</th>'; echo '</th>';
echo '</tr>'; echo '</tr>';
$usedplugins = $plugin_obj->get_installed_plugins_by_block();
/* We display all the possible plugins and the checkboxes */ /* We display all the possible plugins and the checkboxes */
$plugin_list = array(); $plugin_list = array();
@ -87,22 +85,11 @@ function handle_plugins() {
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'>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);
echo Display::select('plugin_'.$plugin.'[]', $plugin_list, $selected_plugins, array('multiple' => 'multiple', 'style' => 'width:500px')); echo Display::select('plugin_'.$plugin.'[]', $plugin_list, $selected_plugins, array('multiple' => 'multiple', 'style' => 'width:500px'));
/* display_plugin_cell('loginpage_main', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('loginpage_menu', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('campushomepage_main', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('campushomepage_menu', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('mycourses_main', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('mycourses_menu', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('header', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('footer', $plugin_info, $plugin, $usedplugins);
display_plugin_cell('course_tool_plugin', $plugin_info, $plugin, $usedplugins);*/
echo '</td></tr>'; echo '</td></tr>';
} }
} }

@ -110,6 +110,13 @@ class AppPlugin {
return $block_content; return $block_content;
} }
/**
*
*
* @param string $block
* @param smarty obj
* @todo improve this function
*/
function get_all_plugin_contents_by_block($block, $main_template) { function get_all_plugin_contents_by_block($block, $main_template) {
global $_plugins; global $_plugins;
if (isset($_plugins[$block]) && is_array($_plugins[$block])) { if (isset($_plugins[$block]) && is_array($_plugins[$block])) {
@ -119,27 +126,30 @@ class AppPlugin {
//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_block'] = $block;
// Loading the plugin/XXX/index.php file // Loading the plugin/XXX/index.php file
include api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php"; require api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php";
//We set the $template variable in order to use smarty
if (isset($_template) && !empty($_template)) {
foreach($_template as $key =>$value) {
$main_template->assign($key, $value);
}
}
//Loading the smarty template files if exists //Loading the smarty template files if exists
$template_list = array(); $template_list = array();
if (isset($plugin_info) && isset($plugin_info['templates'])) { if (isset($plugin_info) && isset($plugin_info['templates'])) {
$template_list = $plugin_info['templates']; $template_list = $plugin_info['templates'];
} }
//We set the $template variable in order to use smarty //var_dump($plugin_info);
if (isset($_template) && !empty($_template)) {
foreach($_template as $key =>$value) {
$main_template->assign($key, $value);
}
}
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); $main_template->display($template_plugin_file);
} }
} }
@ -160,7 +170,7 @@ class AppPlugin {
require $plugin_file; require $plugin_file;
} }
$plugin_data[$plugin_name] = $plugin_info; $plugin_data[$plugin_name] = $plugin_info;
return $plugin_data; return $plugin_info;
} }
} }

@ -20,7 +20,7 @@
</section> </section>
{if !empty($plugin_content_bottom)} {if !empty($plugin_content_bottom)}
<div class="clear"></div> <div class="clear"></div>
<div id="plugin_content_bottom"> <div id="plugin_content_bottom" class="span12">
{$plugin_content_bottom} {$plugin_content_bottom}
</div> </div>
{/if} {/if}

@ -50,8 +50,8 @@
&nbsp; &nbsp;
</section> </section>
{if !empty($plugin_content_bottom)} {if !empty($plugin_content_bottom)}
<div id="plugin_content_bottom"> <div id="plugin_content_bottom" class="span12">
{$plugin_content_bottom} {$plugin_content_bottom}
</div> </div>
{/if} {/if}

@ -1,22 +1,18 @@
<?php <?php
//A user must be logged in //A user must be logged in
$_template['show_message'] = false;
if (!api_is_anonymous()) { if (!api_is_anonymous()) {
$_template['show_message'] = true;
//Getting the current user id //Getting the current user id
$user_id = api_get_user_id(); $user_id = api_get_user_id();
//Getting the current user info //Getting the current user info
$user_info = api_get_user_info($user_id); $user_info = api_get_user_info($user_id);
//Showing the complete name (that means the firstname and lastname depending of the language)
echo 'This is a simple echo';
//If you want to see more data you can do a var_dump($user_info);
//You can also change the style
echo '<h4>This is an echo with style :)</h4>';
//You can also use smarty setting variables in the special variable called template //You can also use smarty setting variables in the special variable called template
$_template['user_info'] = $user_info; $_template['my_user_info'] = $user_info;
$_template['user_email'] = $user_info['mail']; $_template['my_username'] = $user_info['username'];
} }

@ -12,7 +12,7 @@
//the plugin title //the plugin title
$plugin_info['title'] = 'Show user information'; $plugin_info['title'] = 'Show user information';
//the comments that go with the plugin //the comments that go with the plugin
$plugin_info['comment'] = "Shows the user information"; $plugin_info['comment'] = "Shows a welcome message, (this is an example to uses smarty)";
//the plugin version //the plugin version
$plugin_info['version'] = '1.0'; $plugin_info['version'] = '1.0';
//the plugin author //the plugin author

@ -1,4 +1,33 @@
This is a chamilo plugin using smarty {*
This is a Chamilo plugin using Smarty you can use handy shorcuts like:
1. Shortcuts
$_p = url chamilo paths
$_u = user information of the current user
2. i18n
You can use i18n variables just use this syntax:
{"HelloWorld"|get_lang}
Now you can add your variables in the main/lang/english/ or main/lang/spanish/ for example in spanish:
$HelloWorld = "Hola Mundo";
3. Portal settings
You can access the portal settings using:
{"siteName"|api_get_setting}
For more settings check the settings_current database
4. Read more
You can also see more examples in the the main/template/default/layout files
*}
{if $show_message}
<div class="well"> <div class="well">
Welcome, {$user_info.complete_name} {"Welcome"|get_lang} {$my_user_info.complete_name} ({$my_username})
<br />
The administrator - {"siteName"|api_get_setting}
</div> </div>
{/if}
Loading…
Cancel
Save