Adding handfull function api_get_plugin_setting(), adding new "main_top" and "main_bottom" plugins zones, adding new plugin "before_login" see BT#6939

1.9.x
Julio Montoya 12 years ago
parent 9cc50c5124
commit e84ef79420
  1. 12
      index.php
  2. 18
      main/inc/lib/main_api.lib.php
  3. 2
      main/inc/lib/plugin.lib.php
  4. 16
      main/template/default/layout/layout_1_col.tpl
  5. 56
      main/template/default/layout/layout_2_col.tpl
  6. 35
      main/template/default/layout/login_form.tpl
  7. 4
      main/template/default/layout/main.tpl
  8. 69
      plugin/before_login/index.php
  9. 47
      plugin/before_login/plugin.php
  10. 12
      plugin/before_login/template.tpl

@ -137,8 +137,18 @@ if (api_get_setting('display_categories_on_homepage') == 'true') {
if (api_is_facebook_auth_activated() && !api_get_user_id()) { if (api_is_facebook_auth_activated() && !api_get_user_id()) {
facebook_connect(); facebook_connect();
} }
$showLoginForm = true;
if (api_is_anonymous()) {
if (!isset($_SESSION['before_login_accepted'])) {
if (in_array('before_login', $controller->tpl->plugin->get_installed_plugins())) {
$showLoginForm = false;
}
}
}
$controller->set_login_form(); if ($showLoginForm) {
$controller->set_login_form();
}
//@todo move this inside the IndexManager //@todo move this inside the IndexManager
if (!api_is_anonymous()) { if (!api_is_anonymous()) {

@ -2097,7 +2097,8 @@ function api_get_coachs_from_course($session_id=0,$course_code='') {
* @author René Haentjens * @author René Haentjens
* @author Bart Mollet * @author Bart Mollet
*/ */
function api_get_setting($variable, $key = null) { function api_get_setting($variable, $key = null)
{
global $_setting; global $_setting;
if ($variable == 'header_extra_content') { if ($variable == 'header_extra_content') {
$filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt'; $filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
@ -2128,6 +2129,21 @@ function api_get_setting($variable, $key = null) {
return $value; return $value;
} }
/**
* @param string $plugin
* @param string $variable
* @return string
*/
function api_get_plugin_setting($plugin, $variable)
{
$variableName = $plugin.'_'.$variable;
$result = api_get_setting($variableName);
if (isset($result[$plugin])) {
return $result[$plugin];
}
return null;
}
/** /**
* Returns the value of a setting from the web-adjustable admin config settings. * Returns the value of a setting from the web-adjustable admin config settings.
**/ **/

@ -4,6 +4,8 @@
class AppPlugin class AppPlugin
{ {
public $plugin_regions = array( public $plugin_regions = array(
'main_top',
'main_bottom',
'login_top', 'login_top',
'login_bottom', 'login_bottom',
'menu_top', 'menu_top',

@ -3,10 +3,17 @@
{# 1 column #} {# 1 column #}
{% block body %} {% block body %}
{# Plugin main top #}
{% if plugin_main_top %}
<div id="plugin_main_top" class="span12">
{{ plugin_main_top }}
</div>
{% endif %}
{# Plugin top #} {# Plugin top #}
{% if plugin_content_top %} {% if plugin_content_top %}
<div id="plugin_content_top" class="span12"> <div id="plugin_content_top" class="span12">
{{ plugin_content_top}} {{ plugin_content_top }}
</div> </div>
{% endif %} {% endif %}
@ -29,4 +36,11 @@
{{ plugin_content_bottom }} {{ plugin_content_bottom }}
</div> </div>
{% endif %} {% endif %}
{# Plugin main bottom #}
{% if plugin_main_bottom %}
<div id="plugin_main_bottom" class="span12">
{{ plugin_main_bottom }}
</div>
{% endif %}
{% endblock %} {% endblock %}

@ -3,7 +3,14 @@
{% block body %} {% block body %}
{# Main content #} {# Main content #}
{# Right column #} {# Plugin main top #}
{% if plugin_main_top %}
<div id="plugin_main_top" class="span12">
{{ plugin_main_top }}
</div>
{% endif %}
{# Right column #}
<div class="span3 menu-column"> <div class="span3 menu-column">
{% if plugin_menu_top %} {% if plugin_menu_top %}
<div id="plugin_menu_top"> <div id="plugin_menu_top">
@ -16,41 +23,41 @@
{% include "default/layout/login_form.tpl" %} {% include "default/layout/login_form.tpl" %}
{% endif %} {% endif %}
{# User picture #} {# User picture #}
{{ user_image_block }} {{ user_image_block }}
{# User Profile links #} {# User Profile links #}
{{ profile_block }} {{ profile_block }}
{# Course block - admin #} {# Course block - admin #}
{{ course_block }} {{ course_block }}
{# Course block - teacher #} {# Course block - teacher #}
{{ teacher_block }} {{ teacher_block }}
{# Notice #} {# Notice #}
{{ notice_block }} {{ notice_block }}
{# Help #} {# Help #}
{{ help_block }} {{ help_block }}
{# Links that are not added in the tabs #} {# Links that are not added in the tabs #}
{{ navigation_course_links }} {{ navigation_course_links }}
{# Reservation block #} {# Reservation block #}
{{ reservation_block }} {{ reservation_block }}
{# Search (xapian) #} {# Search (xapian) #}
{{ search_block }} {{ search_block }}
{# Classes #} {# Classes #}
{{ classes_block }} {{ classes_block }}
{# Skills #} {# Skills #}
{{ skills_block }} {{ skills_block }}
{# Plugin courses sidebar #} {# Plugin courses sidebar #}
{# Plugins for footer section #} {# Plugins for footer section #}
{% if plugin_menu_bottom %} {% if plugin_menu_bottom %}
<div id="plugin_menu_bottom"> <div id="plugin_menu_bottom">
@ -58,16 +65,16 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
<div class="span9 content-column">
{# Plugin bottom #} <div class="span9 content-column">
{# Plugin bottom #}
{% if plugin_content_top %} {% if plugin_content_top %}
<div id="plugin_content_top"> <div id="plugin_content_top">
{{ plugin_content_top }} {{ plugin_content_top }}
</div> </div>
{% endif %} {% endif %}
{# Portal homepage #} {# Portal homepage #}
{% if home_page_block %} {% if home_page_block %}
<section id="homepage"> <section id="homepage">
<div class="row"> <div class="row">
@ -83,7 +90,7 @@
{% include "default/layout/page_body.tpl" %} {% include "default/layout/page_body.tpl" %}
{# Welcome to course block #} {# Welcome to course block #}
{% if welcome_to_course_block %} {% if welcome_to_course_block %}
<section id="welcome_to_course"> <section id="welcome_to_course">
{{ welcome_to_course_block }} {{ welcome_to_course_block }}
@ -96,7 +103,7 @@
</section> </section>
{% endif %} {% endif %}
{# Announcements #} {# Announcements #}
{% if announcements_block %} {% if announcements_block %}
<section id="announcements"> <section id="announcements">
{{ announcements_block }} {{ announcements_block }}
@ -114,10 +121,10 @@
</section> </section>
{% endif %} {% endif %}
{# Hot courses template #} {# Hot courses template #}
{% include "default/layout/hot_courses.tpl" %} {% include "default/layout/hot_courses.tpl" %}
{# Content bottom #} {# Content bottom #}
{% if plugin_content_bottom %} {% if plugin_content_bottom %}
<div id="plugin_content_bottom"> <div id="plugin_content_bottom">
{{plugin_content_bottom}} {{plugin_content_bottom}}
@ -126,4 +133,11 @@
&nbsp; &nbsp;
</div> </div>
{# Plugin main bottom #}
{% if plugin_main_bottom %}
<div id="plugin_main_bottom" class="span12">
{{ plugin_main_bottom }}
</div>
{% endif %}
{% endblock %} {% endblock %}

@ -1,22 +1,25 @@
<div id="login_block" class="well sidebar-nav"> {% if login_language_form %}
{{ login_language_form }} <div id="login_block" class="well sidebar-nav">
{% if plugin_login_top is not null %} {{ login_language_form }}
<div id="plugin_login_top">
{{ plugin_login_top }}
</div>
{% endif %}
{{login_failed}} {% if plugin_login_top is not null %}
<div id="plugin_login_top">
{{ plugin_login_top }}
</div>
{% endif %}
{{login_form}} {{ login_failed }}
{{login_options}} {{ login_form }}
{% if plugin_login_bottom is not null %} {{ login_options }}
<div id="plugin_login_bottom">
{{ plugin_login_bottom }} {% if plugin_login_bottom is not null %}
</div> <div id="plugin_login_bottom">
{% endif %} {{ plugin_login_bottom }}
</div> </div>
{% endif %}
</div>
{% endif %}

@ -1,5 +1,5 @@
{% block header %} {% block header %}
{% include "default/layout/main_header.tpl" %} {% include "default/layout/main_header.tpl" %}
{% endblock %} {% endblock %}
{% block body %} {% block body %}
@ -16,5 +16,5 @@
<div class="push"></div> <div class="push"></div>
</div> <!-- end of #wrapper section --> </div> <!-- end of #wrapper section -->
{% endif %} {% endif %}
{% include "default/layout/main_footer.tpl" %} {% include "default/layout/main_footer.tpl" %}
{% endblock %} {% endblock %}

@ -0,0 +1,69 @@
<?php
/**
* @package chamilo.plugin.before_login
*/
if (api_is_anonymous()) {
// Only available in the index.php page
$loginAccepted = isset($_SESSION['before_login_accepted']) ? $_SESSION['before_login_accepted'] : null;
$currentPage = str_replace('index.php', '', $_SERVER['REQUEST_URI']);
//var_dump(api_get_path(REL_PATH), $currentPage);
if (api_get_path(REL_PATH) !== $currentPage) {
return null;
}
if ($loginAccepted) {
return null;
}
$option1 = api_get_plugin_setting('before_login', 'option1');
$urlOption1 = api_get_plugin_setting('before_login', 'option1_url');
$option2 = api_get_plugin_setting('before_login', 'option2');
$urlOption2 = api_get_plugin_setting('before_login', 'option2_url');
$form = new FormValidator('form');
$renderer =& $form->defaultRenderer();
$renderer->setHeaderTemplate('');
$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
$renderer->setElementTemplate('<tr><td>{element}</td></tr>');
$form->addElement('header', $option1);
$form->addElement('checkbox', 'left', null, get_lang('Yes'));
$form->addElement('button', 'submit', get_lang('Send'));
if ($form->validate()) {
$result = $form->getSubmitValues();
if (isset($result['left']) && $result['left']) {
$_SESSION['before_login_accepted'] = 1;
header('Location: '.$urlOption1);
exit;
}
}
$form2 = new FormValidator('form');
$renderer =& $form2->defaultRenderer();
$renderer->setHeaderTemplate('');
$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
$renderer->setElementTemplate('<tr><td>{element}</td></tr>');
$form->addElement('header', $option2);
$form2->addElement('checkbox', 'right', null, get_lang('Yes'));
$form2->addElement('button', 'submit', get_lang('Send'));
if ($form2->validate()) {
$result = $form2->getSubmitValues();
if (isset($result['right']) && $result['right']) {
header('Location: '.$urlOption2);
exit;
}
}
$_template['option1'] = api_get_plugin_setting('before_login', 'option1');
$_template['option2'] = api_get_plugin_setting('before_login', 'option2');
$_template['form_option1'] = $form->return_form();
$_template['form_option2'] = $form2->return_form();
}

@ -0,0 +1,47 @@
<?php
/**
* This script is a configuration file for the add_this plugin.
* These settings will be used in the administration interface for plugins
* (Chamilo configuration settings->Plugins)
* @package chamilo.plugin
* @author Julio Montoya <gugli100@gmail.com>
*/
/* Plugin config */
// The plugin title.
$plugin_info['title'] = 'Show HTML before login';
// The comments that go with the plugin.
$plugin_info['comment'] = "Show a content before loading the login page.";
// The plugin version.
$plugin_info['version'] = '1.0';
// The plugin author.
$plugin_info['author'] = 'Julio Montoya';
// The plugin configuration.
$form = new FormValidator('form');
$form->addElement('header', 'Option 1');
$form->addElement('textarea', 'option1', 'Description');
$form->addElement('text', 'option1_url', 'Redirect to');
$form->addElement('header', 'Option 2');
$form->addElement('textarea', 'option2', 'Description');
$form->addElement('text', 'option2_url', 'Redirect to');
$form->addElement('button', 'submit_button', get_lang('Save'));
// Get default value for form
$defaults = array();
$defaults['option1'] = api_get_plugin_setting('before_login', 'option1');
$defaults['option2'] = api_get_plugin_setting('before_login', 'option2');
$defaults['option1_url'] = api_get_plugin_setting('before_login', 'option1_url');
$defaults['option2_url'] = api_get_plugin_setting('before_login', 'option2_url');
$plugin_info['templates'] = array('template.tpl');
$form->setDefaults($defaults);
// Display form
$plugin_info['settings_form'] = $form;

@ -0,0 +1,12 @@
<div class="span12">
<div class="row">
<div class="span6">
{{ before_login.option1 }}
{{ before_login.form_option1 }}
</div>
<div class="span6">
{{ before_login.option2 }}
{{ before_login.form_option2 }}
</div>
</div>
</div>
Loading…
Cancel
Save