Now we can use smarty template when creating chamilo plugins

skala
Julio Montoya 13 years ago
parent c149cd9004
commit ff71f46162
  1. 5
      main/admin/settings.lib.php
  2. 1
      main/inc/lib/main_api.lib.php
  3. 94
      main/inc/lib/plugin.lib.php
  4. 33
      main/inc/lib/template.lib.php

@ -62,13 +62,12 @@ function handle_plugins() {
echo '</th>';
echo '</tr>';
//$usedplugins = $plugin_obj->get_installed_plugins();
$usedplugins = $plugin_obj->get_installed_plugins();
$usedplugins = $plugin_obj->get_installed_plugins_by_block();
/* We display all the possible plugins and the checkboxes */
$plugin_list = array();
$my_plugin_list = $plugin_obj->get_plugin_list();
$my_plugin_list = $plugin_obj->get_plugin_blocks();
foreach($my_plugin_list as $plugin_item) {
$plugin_list[$plugin_item] = $plugin_item;
}

@ -3378,6 +3378,7 @@ function api_number_of_plugins($location) {
/**
* Including the necessary plugins.
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @deprecated use AppPlugin::get_all_plugin_contents_by_block function
*/
function api_plugin($location) {
global $_plugins;

@ -1,7 +1,7 @@
<?php
/* See license terms in /license.txt */
class AppPlugin {
var $plugin_list = array (
var $plugin_blocks = array (
// 'loginpage_main',
'login',
'menu',
@ -50,7 +50,8 @@ class AppPlugin {
return $possible_plugins;
}
function get_installed_plugins() {
function get_installed_plugins_by_block(){
$usedplugins = array();
/* We retrieve all the active plugins. */
$result = api_get_settings('Plugins');
@ -60,6 +61,18 @@ class AppPlugin {
return $usedplugins;
}
function get_installed_plugins() {
$installed_plugins = array();
$result = api_get_settings('Plugins');
if (!empty($result)) {
foreach ($result as $row) {
$installed_plugins[$row['selected_value']] = true;
}
$installed_plugins = array_keys($installed_plugins);
}
return $installed_plugins;
}
function get_areas_by_plugin($plugin_name) {
$result = api_get_settings('Plugins');
$areas = array();
@ -84,8 +97,79 @@ class AppPlugin {
return false;
}
function get_plugin_list() {
sort($this->plugin_list);
return $this->plugin_list;
function get_plugin_blocks() {
sort($this->plugin_blocks);
return $this->plugin_blocks;
}
function load_block($block, $main_template) {
ob_start();
$this->get_all_plugin_contents_by_block($block, $main_template);
$block_content = ob_get_contents();
ob_end_clean();
return $block_content;
}
function get_all_plugin_contents_by_block($block, $main_template) {
global $_plugins;
if (isset($_plugins[$block]) && is_array($_plugins[$block])) {
foreach ($_plugins[$block] as $plugin_name) {
//Load the plugin information
//
//The plugin_info variable is available inside the plugin index
$plugin_info = $this->get_plugin_info($plugin_name);
//We also where the plugin is
$plugin_info['current_block'] = $block;
// Loading the plugin/XXX/index.php file
include api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php";
//Loading the smarty template files if exists
$template_list = array();
if (isset($plugin_info) && isset($plugin_info['templates'])) {
$template_list = $plugin_info['templates'];
}
//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);
}
}
if (!empty($template_list)) {
foreach($template_list as $plugin_tpl) {
if (!empty($plugin_tpl)) {
$template_plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/$plugin_tpl";
$main_template->display($template_plugin_file);
}
}
}
}
}
return false;
}
function get_plugin_info($plugin_name) {
static $plugin_data = array();
if (isset($plugin_data[$plugin_name])) {
return $plugin_data[$plugin_name];
} else {
$plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/plugin.php";
$plugin_info = array();
if (file_exists($plugin_file)) {
require $plugin_file;
}
$plugin_data[$plugin_name] = $plugin_info;
return $plugin_data;
}
}
function get_templates_list($plugin_name) {
$plugin_info = $this->get_plugin_info($plugin_name);
if (isset($plugin_info) && isset($plugin_info['templates'])) {
return $plugin_info['templates'];
} else {
return false;
}
}
}

@ -22,7 +22,8 @@ class Template extends Smarty {
var $show_footer;
var $help;
var $menu_navigation = array();
var $show_learnpath = false;
var $show_learnpath = false;
var $plugin = null;
function __construct($title = '', $show_header = true, $show_footer = true, $show_learnpath = false) {
parent::__construct();
@ -72,10 +73,14 @@ class Template extends Smarty {
$this->assign('style', $this->style);
//Chamilo plugins
$plugin = new AppPlugin();
foreach($plugin->plugin_list as $plugin) {
$this->set_plugin($plugin);
$this->plugin = new AppPlugin();
$plugin_blocks = $this->plugin->get_plugin_blocks();
foreach ($plugin_blocks as $block) {
$this->set_plugin_block($block);
}
$this->load_plugin_template();
}
function set_help($help_input = null) {
@ -550,17 +555,17 @@ class Template extends Smarty {
}
/* Sets the plugin content in a Smarty variable */
function set_plugin($plugin_name) {
if (!empty($plugin_name)) {
if (api_number_of_plugins($plugin_name) > 0) {
ob_start();
api_plugin($plugin_name);
$plugin_content = ob_get_contents();
ob_end_clean();
}
$this->assign('plugin_'.$plugin_name, $plugin_content);
//return $plugin_content;
function set_plugin_block($plugin_block) {
if (!empty($plugin_block)) {
$block_content = $this->plugin->load_block($plugin_block, $this);
//Assigning the plugin with the smarty template
$this->assign('plugin_'.$plugin_block, $block_content);
}
return null;
}
function load_plugin_template() {
}
}
Loading…
Cancel
Save