Adding language support to plugins see #4557

skala
Julio Montoya 13 years ago
parent 0739035eb4
commit be9d1b8856
  1. 9
      main/inc/lib/plugin.class.php
  2. 56
      main/inc/lib/plugin.lib.php
  3. 31
      main/inc/lib/template.lib.php
  4. 31
      plugin/bbb/bbb.lib.php
  5. 40
      plugin/bbb/bbb_api.php
  6. 6
      plugin/bbb/config.php
  7. 7
      plugin/bbb/index.php
  8. 18
      plugin/bbb/lang/english.php
  9. 2
      plugin/bbb/lang/spanish.php
  10. 13
      plugin/bbb/lib/bbb_plugin.class.php
  11. 12
      plugin/bbb/listing.php
  12. 102
      plugin/bbb/listing.tpl
  13. 24
      plugin/bbb/plugin.php
  14. 17
      plugin/bbb/uninstall.php
  15. 4
      plugin/hello_world/index.php
  16. 9
      plugin/hello_world/lang/english.php
  17. 3
      plugin/hello_world/lang/french.php
  18. 3
      plugin/hello_world/lang/spanish.php
  19. 3
      plugin/show_user_info/lang/english.php
  20. 3
      plugin/show_user_info/lang/spanish.php
  21. 2
      plugin/show_user_info/plugin.php
  22. 8
      plugin/show_user_info/template.tpl

@ -128,17 +128,16 @@ class Plugin {
if (is_null($this->strings)) {
global $language_interface;
$root = api_get_path(SYS_PLUGIN_PATH);
$plugin_name = $this->get_name();
$language = $language_interface;
$path = "$root/$plugin_name/lang/$language.php";
$plugin_name = $this->get_name();
//1. Loading english if exists
$english_path = "$root/$plugin_name/lang/english.php";
$english_path = $root.$plugin_name."/lang/english.php";
if (is_readable($english_path)) {
include $english_path;
$this->strings = $strings;
}
$path = $root.$plugin_name."/lang/$language_interface.php";
//2. Loading the system language
if (is_readable($path)) {
include $path;

@ -27,17 +27,7 @@ class AppPlugin {
function __construct() {
}
/* For each of the possible plugin directories we check whether a file named "plugin.php" exists
(it contains all the needed information about this plugin).
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.
*/
function read_plugins_from_path() {
/* We scan the plugin directory. Each folder is a potential plugin. */
$pluginpath = api_get_path(SYS_PLUGIN_PATH);
@ -146,6 +136,40 @@ class AppPlugin {
return $content;
}
/**
* Loads the translation files inside a plugin if exists. It loads by default english see the hello world plugin
*
* @todo add caching
* @param string $plugin_name
*/
function load_plugin_lang_variables($plugin_name) {
global $language_interface;
$root = api_get_path(SYS_PLUGIN_PATH);
//1. Loading english if exists
$english_path = $root.$plugin_name."/lang/english.php";
if (is_readable($english_path)) {
include $english_path;
foreach ($strings as $key => $string) {
//$$key = $string;
$GLOBALS[$key] = $string;
}
}
//2. Loading the system language
$path = $root.$plugin_name."/lang/$language_interface.php";
if (is_readable($path)) {
include $path;
if (!empty($strings)) {
foreach ($strings as $key => $string) {
//$$key = $string;
$GLOBALS[$key] = $string;
}
}
}
}
/**
*
*
@ -163,18 +187,20 @@ class AppPlugin {
//The plugin_info variable is available inside the plugin index
$plugin_info = $this->get_plugin_info($plugin_name);
//We also where the plugin is
//We also know where the plugin is
$plugin_info['current_region'] = $region;
// Loading the plugin/XXX/index.php file
$plugin_file = api_get_path(SYS_PLUGIN_PATH)."$plugin_name/index.php";
if (file_exists($plugin_file)) {
//Loading the lang variables of the plugin if exists
self::load_plugin_lang_variables($plugin_name);
//Printing the plugin index.php file
require $plugin_file;
//If the variable $_template is set we assign those values to be accesible in Twig
if (isset($_template)) {
$_template['plugin_info'] = $plugin_info;
@ -191,7 +217,7 @@ class AppPlugin {
if (isset($plugin_info) && isset($plugin_info['templates'])) {
$template_list = $plugin_info['templates'];
}
if (!empty($template_list)) {
foreach ($template_list as $plugin_tpl) {
if (!empty($plugin_tpl)) {

@ -6,7 +6,7 @@
*
**/
require_once api_get_path(LIBRARY_PATH).'course_home.lib.php';
require_once api_get_path(LIBRARY_PATH).'course_home.lib.php';
require_once api_get_path(LIBRARY_PATH).'banner.lib.php';
require_once api_get_path(LIBRARY_PATH).'plugin.lib.php';
require_once api_get_path(LIBRARY_PATH).'symfony/Twig/Autoloader.php';
@ -30,8 +30,7 @@ class Template {
var $params = array();
function __construct($title = '', $show_header = true, $show_footer = true, $show_learnpath = false) {
//parent::__construct();
function __construct($title = '', $show_header = true, $show_footer = true, $show_learnpath = false) {
//Twig settings
Twig_Autoloader::register();
@ -50,14 +49,12 @@ class Template {
//'auto_reload' => true
//'optimizations' => 0 // turn on optimizations with -1
));
$debug = new Twig_Extension_Debug();
$this->twig->addExtension($debug);
$this->twig->addFilter('get_lang',new Twig_Filter_Function('get_lang'));
$this->twig->addFilter('get_path',new Twig_Filter_Function('api_get_path'));
$this->twig->addFilter('get_setting',new Twig_Filter_Function('api_get_setting'));
$this->twig->addFilter('var_dump',new Twig_Filter_Function('var_dump'));
$this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang'));
$this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path'));
$this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting'));
$this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
$this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate'));
/*
$lexer = new Twig_Lexer($this->twig, array(
@ -92,11 +89,21 @@ class Template {
//Chamilo plugins
if ($this->show_header) {
$this->plugin = new AppPlugin();
$plugin_regions = $this->plugin->get_plugin_regions();
//1. Showing installed plugins in regions
$plugin_regions = $this->plugin->get_plugin_regions();
foreach ($plugin_regions as $region) {
$this->set_plugin_region($region);
}
//2. Loading the course plugin info
global $course_plugin;
if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
//Load plugin get_langs
$this->plugin->load_plugin_lang_variables($course_plugin);
}
}
}

@ -73,10 +73,10 @@ class bbb {
// ??
$voiceBridge = 0;
$metadata = array('maxParticipants' => $max);
return $this->protocol.BigBlueButtonBN::createMeetingAndGetJoinURL($this->user_complete_name, $meeting_name, $id, $welcome_msg, $moderator_password, $attende_password,
$this->salt, $this->url, $this->logout_url, $record, $duration, $voiceBridge, $metadata);
//$id = Database::update($this->table, array('created_at' => ''));
return $this->protocol.BigBlueButtonBN::createMeetingAndGetJoinURL(
$this->user_complete_name, $meeting_name, $id, $welcome_msg, $moderator_password, $attende_password,
$this->salt, $this->url, $this->logout_url, $record, $duration, $voiceBridge, $metadata
);
}
}
@ -143,28 +143,32 @@ class bbb {
if ($meeting['record'] == 1) {
$records = BigBlueButtonBN::getRecordingsArray($meeting['id'], $this->url, $this->salt);
//var_dump($meeting['id']);
if (!empty($records)) {
if (!empty($records)) {
$count = 1;
foreach ($records as $record) {
if (is_array($record) && isset($record['recordID']) && isset($record['playbacks'])) {
//Fix the bbb timestamp
$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
//$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
//$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
//.' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime'])
foreach ($record['playbacks'] as $item) {
$url = Display::url(get_lang('ViewRecord'), $item['url'], array('target' => '_blank')).' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime']);
$url = Display::url(get_lang('ViewRecord').' #'.$count, $item['url'], array('target' => '_blank'));
//$url .= Display::url(get_lang('DeleteRecord'), api_get_self().'?action=delete_record&'.$record['recordID']);
$url .= Display::url(get_lang('CopyToLinkTool'), api_get_self().'?action=copy_record_to_link_tool&id='.$meeting['id'].'&record_id='.$record['recordID']);
//$url .= api_get_self().'?action=publish&id='.$record['recordID'];
$count++;
$record_array[] = $url;
}
}
}
}
$item_meeting['show_links'] = implode('<br />', $record_array);
}
$item_meeting['created_at'] = api_get_local_time($item_meeting['created_at']);
$item_meeting['created_at'] = api_convert_and_format_date($item_meeting['created_at']);
//created_at
$item_meeting['publish_url'] = api_get_self().'?action=publish&id='.$meeting['id'];
@ -246,7 +250,10 @@ class bbb {
}
}
}
return false;
return false;
}
function is_server_running() {
return BigBlueButtonBN::isServerRunning($this->url);
}
}

@ -734,26 +734,26 @@ class BigBlueButtonBN {
}
public function _wrap_simplexml_load_file($url){
if (extension_loaded('curl')) {
$ch = curl_init() or die ( curl_error() );
$timeout = 10;
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec( $ch );
curl_close( $ch );
if($data)
return (new SimpleXMLElement($data,LIBXML_NOCDATA));
else
return false;
}
return (simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA));
}
public function _wrap_simplexml_load_file($url){
if (extension_loaded('curl')) {
$ch = curl_init() or die ( curl_error() );
$timeout = 10;
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec( $ch );
curl_close( $ch );
if($data)
return (new SimpleXMLElement($data,LIBXML_NOCDATA));
else
return false;
}
return (simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA));
}
}

@ -1,9 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/* bbb parameters that will be registered in the course settings */
$variables = array( 'big_blue_button_meeting_name',
'big_blue_button_attendee_password',
'big_blue_button_moderator_password',
'big_blue_button_welcome_message',
'big_blue_button_max_students_allowed',
'big_blue_button_max_students_allowed'
);

@ -1,6 +1,3 @@
<?php
/**
* Placeholder file
* Should contain the code to access the plugin from outside a course
* @package chamilo.plugin.bigbluebutton
*/
?>

@ -0,0 +1,18 @@
<?php
/**
*
* @copyright (c) 2012 University of Geneva
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
* @author Laurent Opprecht <laurent@opprecht.info>
*/
//Needed in order to show the plugin title
$strings['plugin_title'] = "BigBlueButton";
$strings['plugin_comment'] = "Open Source Videoconference tool";
$strings['Videoconference'] = "Videoconference";
$strings['MeetingOpened'] = "Meeting opened";
$strings['StartConference'] = "Start conference";
$strings['RecordList'] = "Record list";
$strings['ServerIsNotRunning'] = "Server Is Not Running";

@ -0,0 +1,13 @@
<?php
class BBBPlugin extends Plugin
{
static function create() {
static $result = null;
return $result ? $result : $result = new self();
}
protected function __construct() {
parent::__construct('2.0', 'Julio Montoya, Yannick Warnier');
}
}

@ -7,7 +7,7 @@
* Initialization
*/
$language_file = array('videoconf');
$course_plugin = 'bbb';
require_once '../../main/inc/global.inc.php';
require_once 'bbb.lib.php';
@ -16,6 +16,7 @@ require_once 'bbb_api.php';
$bbb = new bbb();
$action = isset($_GET['action']) ? $_GET['action'] : null;
switch ($action) {
case 'copy_record_to_link_tool':
$result = $bbb->copy_record_to_link_tool($_GET['id'], $_GET['record_id']);
@ -40,10 +41,12 @@ switch ($action) {
break;
}
$meetings = $bbb->get_course_meetings();
$users_online = $bbb->get_users_online_in_current_room();
$meetings = $bbb->get_course_meetings();
$users_online = $bbb->get_users_online_in_current_room();
$status = $bbb->is_server_running();
$status = false;
$tool_name = get_lang('OrganisationSVideoconference');
$tool_name = get_lang('Videoconference');
$tpl = new Template($tool_name);
@ -51,6 +54,7 @@ $tpl->assign('meetings', $meetings);
$conference_url = api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.api_get_cidreq();
$tpl->assign('conference_url', $conference_url);
$tpl->assign('users_online', $users_online);
$tpl->assign('bbb_status', $status);
$tpl->assign('actions', $actions);
$tpl->assign('message', $message);

@ -1,52 +1,58 @@
<div class ="row">
<div class ="span12" style="text-align:center">
<a href="{{ conference_url }}" class="btn btn-primary btn-large">
{{ 'StartConference'|get_lang }}
</a>
<span id="users_online" class="label label-warning">{{ users_online }} user(s) online</span>
</div>
{% if bbb_status == true %}
<div class ="span12">
<div class="page-header">
<h2>{{ 'RecordList'|get_lang }}</h2>
</div>
<table class="table">
<tr>
<th>#</th>
<th>{{'Meeting'|get_lang}}</th>
<th>{{'Date'|get_lang}}</th>
<th>{{'Actions'|get_lang}}</th>
</tr>
{% for meeting in meetings %}
<tr>
<td>{{ meeting.id }}</td>
<td>{{ meeting.meeting_name }}</td>
<td>{{ meeting.created_at }}</td>
<td>
{% if meeting.record == 1 %}
{# Record list #}
{{ meeting.show_links }}
<!-- <a href="{{ meeting.publish_url}} "> Publish </a>
<a href="{{ meeting.unpublish_url}} "> UnPublish </a> -->
{% endif %}
<br />
{% if meeting.status == 1 %}
<span class="label label-success">{{'MeetingOpened'|get_lang}}</span>
<a class="btn" href="{{ meeting.end_url }} "> {{'CloseMeeting'|get_lang}} </a>
{% else %}
<span class="label label-info">{{'MeetingClosed'|get_lang}}</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</div>
<div class ="span12" style="text-align:center">
<a href="{{ conference_url }}" class="btn btn-primary btn-large">
{{ 'StartConference'|get_lang }}
</a>
<span id="users_online" class="label label-warning">{{ users_online }} user(s) online</span>
</div>
<div class ="span12">
<div class="page-header">
<h2>{{ 'RecordList'|get_lang }}</h2>
</div>
<table class="table">
<tr>
<th>#</th>
<th>{{'Meeting'|get_lang}}</th>
<th>{{'Date'|get_lang}}</th>
<th>{{'Actions'|get_lang}}</th>
</tr>
{% for meeting in meetings %}
<tr>
<td>{{ meeting.id }}</td>
<td>{{ meeting.meeting_name }}</td>
<td>{{ meeting.created_at }}</td>
<td>
{% if meeting.record == 1 %}
{# Record list #}
{{ meeting.show_links }}
<!-- <a href="{{ meeting.publish_url}} "> Publish </a>
<a href="{{ meeting.unpublish_url}} "> UnPublish </a> -->
{% endif %}
{% if meeting.status == 1 %}
<span class="label label-success">{{'MeetingOpened'|get_lang}}</span>
<a class="btn" href="{{ meeting.end_url }} "> {{'CloseMeeting'|get_lang}}</a>
{% else %}
<span class="label label-info">{{'MeetingClosed'|get_lang}}</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</div>
{% else %}
<div class ="span12" style="text-align:center">
{{ 'ServerIsNotRunning' | return_message('warning') }}
</div>
{% endif %}
</div>

@ -1,20 +1,6 @@
<?php
/**
* This script is a configuration file for the BigBlueButton plugin. You can use it as a master for other course plugins.
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins)
* @package chamilo.plugin
* @author Yannick Warnier <ywarnier@beeznest.org>
*/
/**
* Plugin details (must be present)
*/
//the plugin title
$plugin_info['title']='BigBlueButton';
//the comments that go with the plugin
$plugin_info['comment']="Open Source Videoconference tool";
//the locations where this plugin can be shown
$plugin_info['location']=array('course_tool_plugin');
//the plugin version
$plugin_info['version']='1.0';
//the plugin author
$plugin_info['author']='Julio Montoya & Yannick Warnier';
require_once api_get_path(LIBRARY_PATH) . '/plugin.class.php';
require_once dirname(__FILE__) . '/lib/bbb_plugin.class.php';
$plugin_info = BBBPlugin::create()->get_info();

@ -1,4 +1,5 @@
<?php
/**
* This script is included by main/admin/settings.lib.php when unselecting a plugin
* and is meant to remove things installed by the install.php script in both
@ -8,11 +9,10 @@
/**
* Queries
*/
require 'config.php';
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
$t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
$sql = "DELETE FROM $t_settings WHERE variable = 'bbb_plugin'";
Database::query($sql);
@ -30,14 +30,13 @@ $sql = "SELECT id, code FROM $t_courses ORDER BY id";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$t_course = Database::get_course_table(TABLE_COURSE_SETTING);
// $variables is loaded in the config.php file
foreach ($variables as $variable) {
$sql_course = "DELETE FROM $t_course WHERE c_id = ".$row['id']." AND variable = '$variable'";
$r = Database::query($sql_course);
$sql_course = "DELETE FROM $t_course WHERE c_id = " . $row['id'] . " AND variable = '$variable'";
$r = Database::query($sql_course);
}
$t_tool = Database::get_course_table(TABLE_TOOL_LIST);
$sql_course = "DELETE FROM $t_tool WHERE c_id = ".$row['id']." AND link = '../../plugin/bbb/start.php'";
$sql_course = "DELETE FROM $t_tool WHERE c_id = " . $row['id'] . " AND link = '../../plugin/bbb/start.php'";
$r = Database::query($sql_course);
}

@ -11,4 +11,8 @@ if (!empty($plugin_info['settings']['hello_world_show_type'])) {
} else {
echo "<h2>Hello world</h2>";
}
//Using get_lang inside a plugin
echo get_lang('HelloPlugin');
echo '</div>';

@ -0,0 +1,9 @@
<?php
/**
*
* @copyright (c) 2012 University of Geneva
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
* @author Laurent Opprecht <laurent@opprecht.info>
*/
$strings['HelloPlugin'] = "Hello!";

@ -0,0 +1,3 @@
<?php
$strings['HelloPlugin'] = "Salut!";

@ -0,0 +1,3 @@
<?php
$strings['HelloPlugin'] = "Hola chaval!";

@ -0,0 +1,3 @@
<?php
$strings['WelcomToChamiloUserX'] = "Welcome to Chamilo %s!";

@ -0,0 +1,3 @@
<?php
$strings['WelcomToChamiloUserX'] = "Bienvenido a Chamilo %s!";

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

@ -24,9 +24,7 @@
#}
{% if show_user_info.show_message is not null and _u.logged == 1 %}
<div class="well">
{{"Welcome"|get_lang}} {{show_user_info.user_info.complete_name}} ({{show_user_info.username}})
<br />
The administrator - {{"siteName"|get_setting}}
</div>
<div class="well">
{{ "WelcomToChamiloUserX" | get_lang | format(show_user_info.user_info.complete_name) }}
</div>
{% endif %}
Loading…
Cancel
Save