custom pages clean up: remove unnecessary requires

skala
Laurent Opprecht 14 years ago
parent 9c962b3354
commit 21683bf5ed
  1. 1
      custompages/first_login.php
  2. 7
      index.php
  3. 14
      main/auth/inscription.php
  4. 13
      main/auth/lostPassword.php
  5. 2
      main/inc/lib/autoload.class.php
  6. 2
      main/inc/lib/conditional_login.class.php
  7. 5
      main/inc/lib/conditionallogin.lib.php
  8. 82
      main/inc/lib/custom_pages.class.php
  9. 37
      main/inc/lib/custompages.lib.php
  10. 25
      main/inc/lib/login.lib.php
  11. 5
      main/inc/lib/login_redirection.class.php
  12. 7
      main/inc/lib/loginredirection.lib.php
  13. 6
      main/inc/lib/main_api.lib.php
  14. 1
      main/inc/local.inc.php

@ -1,7 +1,6 @@
<?php <?php
require_once('language.php'); require_once('language.php');
require_once(dirname(__FILE__).'/../main/inc/global.inc.php'); require_once(dirname(__FILE__).'/../main/inc/global.inc.php');
//require_once (api_get_path(LIBRARY_PATH).'conditionallogin.lib.php'); moved to autologin
require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php'); require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
if (! isset($_SESSION['conditional_login']['uid'])) if (! isset($_SESSION['conditional_login']['uid']))

@ -79,16 +79,15 @@ if (api_get_setting('allow_terms_conditions') == 'true') {
unset($_SESSION['info_current_user']); unset($_SESSION['info_current_user']);
} }
//If we are not logged in and customapages activated //If we are not logged in and customapages activated
if (!api_get_user_id() && api_get_setting('use_custom_pages') == 'true' ) if (!api_get_user_id() && CustomPages::enabled())
{ {
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';
if(Request::get('loggedout')) if(Request::get('loggedout'))
{ {
CustomPages::displayPage('loggedout'); CustomPages::display(CustomPages::LOGGED_OUT);
} }
else else
{ {
CustomPages::displayPage('index-unlogged'); CustomPages::display(CustomPages::INDEX_UNLOGGED);
} }
} }

@ -14,7 +14,7 @@ require_once '../inc/global.inc.php';
require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php'; require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'legal.lib.php'; require_once api_get_path(LIBRARY_PATH).'legal.lib.php';
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; //require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload
if (!empty($_SESSION['user_language_choice'])) { if (!empty($_SESSION['user_language_choice'])) {
$user_selected_language = $_SESSION['user_language_choice']; $user_selected_language = $_SESSION['user_language_choice'];
@ -277,7 +277,7 @@ if (is_array($extra_data)) {
$form->setDefaults($defaults); $form->setDefaults($defaults);
if (api_get_setting('use_custom_pages') != 'true') { if (!CustomPages::enabled()) {
// Load terms & conditions from the current lang // Load terms & conditions from the current lang
if (api_get_setting('allow_terms_conditions') == 'true') { if (api_get_setting('allow_terms_conditions') == 'true') {
$get = array_keys($_GET); $get = array_keys($_GET);
@ -528,7 +528,7 @@ if ($form->validate()) {
// 3. exit the page // 3. exit the page
unset($user_id); unset($user_id);
if (api_get_setting('use_custom_pages') != 'true') { if (!CustomPages::enabled()) {
Display :: display_footer(); Display :: display_footer();
} }
exit; exit;
@ -610,14 +610,14 @@ if ($form->validate()) {
// ?uidReset=true&uidReq=$_user['user_id'] // ?uidReset=true&uidReq=$_user['user_id']
$display_text .= '<form action="'. $action_url. '" method="post">'. "\n". '<button type="submit" class="next" name="next" value="'. get_lang('Next',null,$_user['language']). '" validationmsg=" '. get_lang('Next',null,$_user['language']). ' ">'. $button_text. '</button>'. "\n". '</form><br />'. "\n"; $display_text .= '<form action="'. $action_url. '" method="post">'. "\n". '<button type="submit" class="next" name="next" value="'. get_lang('Next',null,$_user['language']). '" validationmsg=" '. get_lang('Next',null,$_user['language']). ' ">'. $button_text. '</button>'. "\n". '</form><br />'. "\n";
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
CustomPages::displayPage('registration-feedback', array('info' => $display_text)); CustomPages::display(CustomPages::REGISTRATION_FEEDBACK, array('info' => $display_text));
} }
echo $display_text; echo $display_text;
} else { } else {
// Custom pages // Custom pages
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
CustomPages::displayPage('registration', array('form' => $form)); CustomPages::display(CustomPages::REGISTRATION, array('form' => $form));
} else { } else {
$form->display(); $form->display();
} }

@ -23,19 +23,18 @@ $language_file = array('registration', 'index');
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'login.lib.php'; require_once api_get_path(LIBRARY_PATH).'login.lib.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; //require_once api_get_path(LIBRARY_PATH).'custompages.lib.php';moved to autoload
// Custom pages // Custom pages
// Had to move the form handling in here, because otherwise there would // Had to move the form handling in here, because otherwise there would
// already be some display output. // already be some display output.
global $_configuration; global $_configuration;
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
//Reset Password when user goes to the link //Reset Password when user goes to the link
if ($_GET['reset'] && $_GET['id']){ if ($_GET['reset'] && $_GET['id']){
$mesg = Login::reset_password($_GET["reset"], $_GET["id"], true); $mesg = Login::reset_password($_GET["reset"], $_GET["id"], true);
CustomPages::displayPage('index-unlogged', array('info' => $mesg)); CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => $mesg));
} }
//Check email/username and do the right thing //Check email/username and do the right thing
@ -75,12 +74,12 @@ if (api_get_setting('use_custom_pages') == 'true') {
Login::send_password_to_user($user, $by_username); Login::send_password_to_user($user, $by_username);
} }
} else { } else {
CustomPages::displayPage('lostpassword',array('error' => get_lang('NoUserAccountWithThisEmailAddress'))); CustomPages::display(CustomPages::LOST_PASSWORD, array('error' => get_lang('NoUserAccountWithThisEmailAddress')));
} }
} else { } else {
CustomPages::displayPage('lostpassword'); CustomPages::display(CustomPages::LOGGED_OUT);
} }
CustomPages::displayPage('index-unlogged', array('info' => get_lang('YourPasswordHasBeenEmailed'))); CustomPages::display(CustomPages::INDEX_UNLOGGED, array('info' => get_lang('YourPasswordHasBeenEmailed')));
} }
$tool_name = get_lang('LostPassword'); $tool_name = get_lang('LostPassword');

@ -119,7 +119,7 @@ class Autoload
$result['CourseSession'] = '/main/coursecopy/classes/CourseSession.class.php'; $result['CourseSession'] = '/main/coursecopy/classes/CourseSession.class.php';
$result['CsvReader'] = '/main/inc/lib/system/io/csv_reader.class.php'; $result['CsvReader'] = '/main/inc/lib/system/io/csv_reader.class.php';
$result['CsvWriter'] = '/main/inc/lib/system/io/csv_writer.class.php'; $result['CsvWriter'] = '/main/inc/lib/system/io/csv_writer.class.php';
$result['CustomPages'] = '/main/inc/lib/custompages.lib.php'; $result['CustomPages'] = '/main/inc/lib/custom_pages.class.php';
$result['DashboardManager'] = '/main/inc/lib/dashboard.lib.php'; $result['DashboardManager'] = '/main/inc/lib/dashboard.lib.php';
$result['DataForm'] = '/main/gradebook/lib/fe/dataform.class.php'; $result['DataForm'] = '/main/gradebook/lib/fe/dataform.class.php';
$result['Debug'] = '/main/inc/lib/debug.lib.php'; $result['Debug'] = '/main/inc/lib/debug.lib.php';

@ -22,9 +22,7 @@ class ConditionalLogin {
} }
public static function login() { public static function login() {
//require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin
$_SESSION['conditional_login']['can_login'] = true; $_SESSION['conditional_login']['can_login'] = true;
LoginRedirection::redirect(); LoginRedirection::redirect();
exit();
} }
} }

@ -1,5 +0,0 @@
<?php
/**
* Added to autologin
* moved to conditional_login.class.php
*/

@ -0,0 +1,82 @@
<?php
/**
* Used to implement the loading of custom pages
*
* @license see /license.txt
* @author 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
class CustomPages
{
const INDEX_LOGGED = 'index-logged';
const INDEX_UNLOGGED = 'index-unlogged';
const LOGGED_OUT = 'loggedout';
const REGISTRATION_FEEDBACK = 'registration-feedback';
const REGISTRATION = 'registration';
const LOST_PASSWORD = 'lostpassword';
/**
* Returns true if custom pages are enabled. False otherwise.
* @return bool
*/
public static function enabled()
{
return api_get_setting('use_custom_pages') == 'true';
}
/**
* Returns the path to a custom page.
*
* @param string $name
* @return string
*/
public static function path($name = '')
{
return api_get_path(SYS_PATH) . 'custompages/' . $name;
}
/**
* If enabled display a custom page and exist. Otherwise log error and returns.
*
* @param string $page_name
* @param array $content used to path data to the custom page
*/
public static function display($page_name, $content = array())
{
if (!self::enabled()) {
return false;
}
$file = self::path($page_name . '.php');
if (file_exists($file)) {
include($file);
exit;
} else {
error_log('CustomPages::displayPage : could not read file ' . $file_name);
}
}
/**
* Does not look like this function is being used is being used
*
* @param type $url_id
* @return string
*/
public static function getURLImages($url_id = null)
{
if (is_null($url_id)) {
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
$url_id = UrlManager::get_url_id($url);
}
$url_images_dir = api_get_path(SYS_PATH) . 'custompages/url-images/';
$images = array();
for ($img_id = 1; $img_id <= 3; $img_id++) {
if (file_exists($url_images_dir . $url_id . '_url_image_' . $img_id . '.png')) {
$images[] = api_get_path(WEB_PATH) . 'custompages/url-images/' . $url_id . '_url_image_' . $img_id . '.png';
}
}
return $images;
}
}

@ -1,37 +0,0 @@
<?php
// Custom Pages lib
// Used to implement the loading of custom pages
// 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
class CustomPages {
public static function displayPage($page_name, $content=array()) {
$pages_dir = api_get_path(SYS_PATH).'custompages/';
$file_name = $pages_dir.$page_name.'.php';
if (file_exists($file_name)) {
include($file_name);
exit;
}
else {
error_log('CustomPages::displayPage : could not read file '.$file_name);
}
}
public static function getURLImages($url_id = null) {
if (is_null($url_id)) {
$url = 'http://'.$_SERVER['HTTP_HOST'].'/';
$url_id = UrlManager::get_url_id($url);
}
$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
$images = array();
for ($img_id = 1; $img_id <= 3; $img_id++) {
if (file_exists($url_images_dir.$url_id.'_url_image_'.$img_id.'.png')) {
$images[] = api_get_path(WEB_PATH).'custompages/url-images/'.$url_id.'_url_image_'.$img_id.'.png';
}
}
return $images;
}
}
?>

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Code library for login process * Code library for login process
@ -7,12 +8,14 @@
* @author Julio Montoya <gugli100@gmail.com> * @author Julio Montoya <gugli100@gmail.com>
* @package chamilo.login * @package chamilo.login
*/ */
/** /**
* Class * Class
* @package chamilo.login * @package chamilo.login
*/ */
class Login class Login
{ {
/** /**
* Get user account list * Get user account list
* *
@ -21,7 +24,8 @@ class Login
* @param boolean $by_username * @param boolean $by_username
* @return unknown * @return unknown
*/ */
public static function get_user_account_list($user, $reset = false, $by_username = false) { public static function get_user_account_list($user, $reset = false, $by_username = false)
{
global $_configuration; global $_configuration;
//$portal_url = $_configuration['root_web']; //$portal_url = $_configuration['root_web'];
$portal_url = api_get_path(WEB_PATH); $portal_url = api_get_path(WEB_PATH);
@ -77,7 +81,8 @@ class Login
* @param unknown_type $user * @param unknown_type $user
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/ */
public static function send_password_to_user($user, $by_username = false) { public static function send_password_to_user($user, $by_username = false)
{
global $_configuration; global $_configuration;
$email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT
@ -118,7 +123,8 @@ class Login
* *
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/ */
public static function handle_encrypted_password($user, $by_username = false) { public static function handle_encrypted_password($user, $by_username = false)
{
global $_configuration; global $_configuration;
$email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT $email_subject = "[" . api_get_setting('siteName') . "] " . get_lang('LoginRequest'); // SUBJECT
@ -142,14 +148,14 @@ class Login
if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) { if (@api_mail('', $email_to, $email_subject, $email_body, $sender_name, $email_admin) == 1) {
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
return get_lang('YourPasswordHasBeenEmailed'); return get_lang('YourPasswordHasBeenEmailed');
} else { } else {
Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed')); Display::display_confirmation_message(get_lang('YourPasswordHasBeenEmailed'));
} }
} else { } else {
$message = get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".</p>"; $message = get_lang('SystemUnableToSendEmailContact') . ' ' . Display :: encrypted_mailto_link(api_get_setting('emailAdministrator'), get_lang('PlatformAdmin')) . ".</p>";
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
return $message; return $message;
} else { } else {
Display::display_error_message($message, false); Display::display_error_message($message, false);
@ -161,7 +167,8 @@ class Login
* Gets the secret word * Gets the secret word
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/ */
public static function get_secret_word($add) { public static function get_secret_word($add)
{
global $_configuration; global $_configuration;
return $secret_word = md5($_configuration['security_key'] . $add); return $secret_word = md5($_configuration['security_key'] . $add);
} }
@ -170,7 +177,8 @@ class Login
* Resets a password * Resets a password
* @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University * @author Olivier Cauberghe <olivier.cauberghe@UGent.be>, Ghent University
*/ */
public static function reset_password($secret, $id, $by_username = false) { public static function reset_password($secret, $id, $by_username = false)
{
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$id = intval($id); $id = intval($id);
$sql = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email FROM " . $tbl_user . " WHERE user_id=$id"; $sql = "SELECT user_id AS uid, lastname AS lastName, firstname AS firstName, username AS loginName, password, email FROM " . $tbl_user . " WHERE user_id=$id";
@ -194,4 +202,7 @@ class Login
return get_lang('NotAllowed'); return get_lang('NotAllowed');
} }
} }
} }

@ -52,9 +52,8 @@ Class LoginRedirection {
} }
// Custom pages // Custom pages
if (api_get_setting('use_custom_pages') == 'true') { if (CustomPages::enabled()) {
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; CustomPages::display(CustomPages::INDEX_LOGGED);
CustomPages::displayPage('index-logged');
} }
header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param); header('location: '.api_get_path(WEB_PATH).api_get_setting('page_after_login').$param);
exit(); exit();

@ -1,7 +0,0 @@
<?php
/**
* Added to autologin
* @see login_redirection.class.php
*
*/

@ -2636,11 +2636,9 @@ function api_not_allowed($print_headers = false, $message = null) {
$course = api_get_course_id(); $course = api_get_course_id();
global $this_section; global $this_section;
if (api_get_setting('use_custom_pages') == 'true' && !isset($_SESSION['_user']['user_id'])) { if (CustomPages::enabled() && !isset($_SESSION['_user']['user_id'])) {
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI']; $_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
require_once api_get_path(LIBRARY_PATH).'custompages.lib.php'; CustomPages::display(CustomPages::INDEX_UNLOGGED);
CustomPages::displayPage('index-unlogged');
exit;
} }
$origin = isset($_GET['origin']) ? $_GET['origin'] : ''; $origin = isset($_GET['origin']) ? $_GET['origin'] : '';

@ -670,7 +670,6 @@ if (isset($uidReset) && $uidReset) { // session data refresh requested
//If we just want to reset info without redirecting user //If we just want to reset info without redirecting user
unset($_SESSION['noredirection']); unset($_SESSION['noredirection']);
} else { } else {
//require_once api_get_path(LIBRARY_PATH).'loginredirection.lib.php'; moved to autologin
LoginRedirection::redirect(); LoginRedirection::redirect();
} }
} }

Loading…
Cancel
Save