Replacing main_api.lib.php with api.lib.php

skala
Julio Montoya 13 years ago
parent d76b6cc817
commit 9ac706a206
  1. 6
      main/auth/shibboleth/app/shibboleth.class.php
  2. 2
      main/conference/get_translation.lib.php
  3. 4
      main/coursecopy/classes/Resource.class.php
  4. 6
      main/inc/global.inc.php
  5. 72
      main/inc/lib/api.lib.php
  6. 2
      main/install/index.php
  7. 4
      main/upload/index.php
  8. 6
      main/upload/upload.document.php
  9. 4
      main/upload/upload.php
  10. 2
      src/ChamiloLMS/Command/Database/InstallCommand.php
  11. 2
      tests/phpunit/classes/AccessurleditcoursestourlTest.lib.php
  12. 2
      tests/phpunit/classes/AccessurledituserstourlTest.lib.php
  13. 4
      tests/test_manager.inc.php
  14. 16
      tests/wipe-out.php

@ -97,13 +97,13 @@ class Shibboleth
/*
* Tests if the user tried to login directly in a protected course before to come here
* (this variable could be set in the modified code of /chamilo/inc/lib/main_api.lib.php)
* (this variable could be set in the modified code of /chamilo/inc/lib/api.lib.php)
*
* Note:
* this part was added to give the possibility to access Chamilo directly on a course URL from a link diplayed in a portal.
* This is not a direct Shibboleth related functionnality, but this could be used in a shibbolethized
* Dokeos installation, mainly if you have a SSO system in your network.
* Please note that the file /claroline/inc/lib/main_api.lib.php must be adapted to your Shibboleth settings
* Please note that the file /claroline/inc/lib/api.lib.php must be adapted to your Shibboleth settings
* If any interest or question, please contact Nicolas.Rod_at_adm.unige.ch
*
*/
@ -262,4 +262,4 @@ EOT;
return (bool) $result;
}
}
}

@ -2,7 +2,7 @@
/* See license terms in /license.txt */
/**
* Library for language translation from Chamilo language files to XML for videoconference
* @uses main_api.lib.php for api_get_path()
* @uses api.lib.php for api_get_path()
*/
/**
* This function reads a Chamilo language file and transforms it into XML,

@ -137,7 +137,7 @@ class Resource
* Get the constant which defines the tool of this resource. This is
* used in the item_properties table.
* @param bool $for_item_property_table (optional) Added by Ivan, 29-AUG-2009: A parameter for resolving differencies between defined TOOL_* constants and hardcoded strings that are stored in the database.
* Example: The constant TOOL_THREAD is defined in the main_api.lib.php with the value 'thread', but the "Forums" tool records in the field 'tool' in the item property table the hardcoded value 'forum_thread'.
* Example: The constant TOOL_THREAD is defined in the api.lib.php with the value 'thread', but the "Forums" tool records in the field 'tool' in the item property table the hardcoded value 'forum_thread'.
* @todo once the RESOURCE_* constants are replaced by the globally
* defined TOOL_* constants, this function will be replaced by get_type()
*/
@ -157,7 +157,7 @@ class Resource
case RESOURCE_ANNOUNCEMENT:
return TOOL_ANNOUNCEMENT;
case RESOURCE_FORUMCATEGORY:
return 'forum_category'; // Ivan, 29-AUG-2009: A constant like TOOL_FORUM_CATEGORY is missing in main_api.lib.php. Such a constant has been defined in the forum tool for local needs.
return 'forum_category'; // Ivan, 29-AUG-2009: A constant like TOOL_FORUM_CATEGORY is missing in api.lib.php. Such a constant has been defined in the forum tool for local needs.
case RESOURCE_FORUM:
return TOOL_FORUM;
case RESOURCE_FORUMTOPIC:

@ -132,7 +132,7 @@ if ($alreadyInstalled) {
/** End loading config files */
/** Including legacy libs */
require_once $includePath.'/lib/main_api.lib.php';
require_once $includePath.'/lib/api.lib.php';
// Setting $_configuration['url_append']
$urlInfo = isset($_configuration['root_web']) ? parse_url($_configuration['root_web']) : null;
@ -154,7 +154,7 @@ require_once $libPath.'events.lib.inc.php';
require_once $libPath.'formvalidator/Rule/allowed_tags.inc.php';
// Ensure that _configuration is in the global scope before loading
// main_api.lib.php. This is particularly helpful for unit tests
// api.lib.php. This is particularly helpful for unit tests
// @todo do not use $GLOBALS
/*if (!isset($GLOBALS['_configuration'])) {
$GLOBALS['_configuration'] = $_configuration;
@ -594,7 +594,7 @@ if (!isset($_SESSION['login_as']) && isset($_user)) {
// is the latest logout_date still relevant?
$sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id = $i_id_last_connection";
$q_logout_date = Database::query($sql_logout_date);
$res_logout_date = convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
$res_logout_date = api_convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
if ($res_logout_date < time() - $app['configuration']['session_lifetime']) {
// now that it's created, we can get its ID and carry on

@ -586,7 +586,7 @@ function api_get_path($path_type, $path = null) {
$load_new_config = false;
// To avoid that the api_get_access_url() function fails since global.inc.php also calls the main_api.lib.php
// To avoid that the api_get_access_url() function fails since global.inc.php also calls the api.lib.php
if ($path_type == WEB_PATH) {
if (isset($_configuration['access_url']) && $_configuration['access_url'] != 1) {
//we look into the DB the function api_get_access_url
@ -1204,7 +1204,7 @@ function api_get_user_courses($userid, $fetch_session = true) {
*
* @return array user info
*/
function _api_format_user($user, $add_password = false) {
function api_format_user($user, $add_password = false) {
$result = array();
//If user is anonymous we don't have anything to provide
@ -1337,7 +1337,7 @@ function _api_format_user($user, $add_password = false) {
function api_get_user_info($user_id = '', $check_if_user_is_online = false, $show_password = false, $add_extra_values = false) {
if (empty($user_id)) {
$_user = Session::read('_user');
return _api_format_user($_user);
return api_format_user($_user);
}
$sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE user_id = '".Database::escape_string($user_id)."'";
$result = Database::query($sql);
@ -1357,7 +1357,7 @@ function api_get_user_info($user_id = '', $check_if_user_is_online = false, $sho
}
$result_array['user_is_online_in_chat'] = $user_online_in_chat;
}
$user = _api_format_user($result_array, $show_password);
$user = api_format_user($result_array, $show_password);
if ($add_extra_values) {
$extra_field_values = new ExtraField('user');
@ -1380,7 +1380,7 @@ function api_get_user_info_from_username($username = '') {
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$result_array = Database::fetch_array($result);
return _api_format_user($result_array);
return api_format_user($result_array);
}
return false;
}
@ -1788,7 +1788,7 @@ function api_clear_anonymous($db_check = false) {
* @author Noel Dieschburg
* @param the int status code
*/
function get_status_from_code($status_code) {
function api_get_status_from_code($status_code) {
switch ($status_code) {
case STUDENT:
return get_lang('Student', '');
@ -3106,7 +3106,7 @@ function api_not_allowed($print_headers = false, $message = null) {
* @version October 2003
* @desc convert sql date to unix timestamp
*/
function convert_sql_date($last_post_datetime) {
function api_convert_sql_date($last_post_datetime) {
list ($last_post_date, $last_post_time) = explode(' ', $last_post_datetime);
list ($year, $month, $day) = explode('-', $last_post_date);
list ($hour, $min, $sec) = explode(':', $last_post_time);
@ -3824,7 +3824,7 @@ function api_max_sort_value($user_course_category, $user_id) {
* @return boolean true or false
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
*/
function string_2_boolean($string) {
function api_string_2_boolean($string) {
if ($string == 'true') {
return true;
}
@ -3948,7 +3948,7 @@ function api_get_permissions_for_new_files() {
* @author Yannick Warnier, adaptation for the Chamilo LMS, April, 2008
* @author Ivan Tcholakov, a sanity check about Directory class creation has been added, September, 2009
*/
function rmdirr($dirname, $delete_only_content_in_folder = false) {
function api_rmdirr($dirname, $delete_only_content_in_folder = false) {
$res = true;
// A sanity check.
@ -3977,7 +3977,7 @@ function rmdirr($dirname, $delete_only_content_in_folder = false) {
}
// Recurse.
rmdirr("$dirname/$entry");
api_rmdirr("$dirname/$entry");
}
}
@ -4004,7 +4004,7 @@ function rmdirr($dirname, $delete_only_content_in_folder = false) {
* @param an array of excluded file_name (without extension)
* @param copied_files the returned array of copied files
*/
function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
function api_copyr($source, $dest, $exclude = array(), $copied_files = array()) {
if (empty($dest)) { return false; }
// Simple copy for a file
if (is_file($source)) {
@ -4033,7 +4033,7 @@ function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
// Deep copy directories.
if ($dest !== "$source/$entry") {
$files = copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
$files = api_copyr("$source/$entry", "$dest/$entry", $exclude, $copied_files);
}
}
// Clean up.
@ -4042,7 +4042,7 @@ function copyr($source, $dest, $exclude = array(), $copied_files = array()) {
}
// TODO: Using DIRECTORY_SEPARATOR is not recommended, this is an obsolete approach. Documentation header to be added here.
function copy_folder_course_session($pathname, $base_path_document, $session_id, $course_info, $document, $source_course_id) {
function api_copy_folder_course_session($pathname, $base_path_document, $session_id, $course_info, $document, $source_course_id) {
$table = Database :: get_course_table(TABLE_DOCUMENT);
$session_id = intval($session_id);
$source_course_id = intval($source_course_id);
@ -4054,7 +4054,7 @@ function copy_folder_course_session($pathname, $base_path_document, $session_id,
// Ensure that a file with the same name does not already exist.
if (is_file($pathname)) {
trigger_error('copy_folder_course_session(): File exists', E_USER_WARNING);
trigger_error('api_copy_folder_course_session(): File exists', E_USER_WARNING);
return false;
}
@ -4185,7 +4185,7 @@ function api_chmod_R($path, $filemode) {
* @return
* The info array.
*/
function parse_info_file($filename) {
function api_parse_info_file($filename) {
$info = array();
if (!file_exists($filename)) {
@ -4992,7 +4992,7 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null) {
* @return string The cleaned filename.
*/
function replace_dangerous_char($filename, $strict = 'loose') {
function api_replace_dangerous_char($filename, $strict = 'loose') {
// Safe replacements for some non-letter characters.
static $search = array("\0", ' ', "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
static $replace = array('', '_', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
@ -5435,7 +5435,7 @@ function api_get_tool_information_by_name($name) {
/* DEPRECATED FUNCTIONS */
/**
* deprecated: use api_is_allowed_to_edit() instead
* @deprecated: use api_is_allowed_to_edit() instead
*/
function is_allowed_to_edit() {
return api_is_allowed_to_edit();
@ -5719,7 +5719,7 @@ function api_get_jqgrid_js() {
return api_get_jquery_libraries_js(array('jqgrid'));
}
function get_available_jquery_ui_languages() {
function api_get_available_jquery_ui_languages() {
//see http://jqueryui.com/demos/datepicker/#localization
return array(
'af',//Afrikaans
@ -5809,7 +5809,7 @@ function api_get_jquery_libraries_js($libraries) {
if (in_array('jquery-ui-i18n', $libraries)) {
$js .= api_get_js('jquery-ui/jquery-ui-i18n.min.js');
if (!in_array($isocode, get_available_jquery_ui_languages())) {
if (!in_array($isocode, api_get_available_jquery_ui_languages())) {
$isocode = 'en';
}
if ($isocode == 'en') {
@ -5908,7 +5908,7 @@ function api_get_home_path() {
if (api_get_multiple_access_url() && $access_url_id != -1) {
$url_info = api_get_current_access_url_info();
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
$clean_url = replace_dangerous_char($url);
$clean_url = api_replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
// if $clean_url == "localhost/" means that the multiple URL was not well configured we don't rename the $home variable
@ -6264,7 +6264,7 @@ function api_get_roles_to_string($roles) {
$role_names = array();
if (!empty($roles)) {
foreach ($roles as $role) {
$role_names[] = get_status_from_code($role);
$role_names[] = api_get_status_from_code($role);
}
}
if (!empty($role_names)) {
@ -6273,22 +6273,6 @@ function api_get_roles_to_string($roles) {
return null;
}
function role_actions() {
return array(
'course' => array(
'create',
'read',
'edit',
'delete'
),
'admin' => array(
'create',
'read',
'edit',
'delete'
)
);
}
function api_coach_can_edit_view_results($courseId = null, $session_id = null) {
$user_id = api_get_user_id();
@ -6846,9 +6830,6 @@ function api_get_language_interface()
return $language_interface;
}
function getConfigurationArray($confPath) {
}
function api_get_default_course_document()
{
return api_get_path(SYS_PATH).'app/data/default_course_document/';
@ -6859,11 +6840,6 @@ function api_get_web_default_course_document()
return api_get_path(WEB_PATH).'app/data/default_course_document/';
}
function load_translations($app)
{
}
/**
* Get user roles
@ -6871,14 +6847,14 @@ function load_translations($app)
*/
function api_get_user_roles()
{
/*global $app;
$em = $app['orm.ems']['db_write'];
global $app;
$em = $app['orm.ems']['db_read'];
$roles = $em->getRepository('Entity\Role')->findAll();
$userRoles = array();
foreach ($roles as $role) {
$userRoles[$role->getId()] = $role->getName();
}
return $userRoles;*/
return $userRoles;
// Status
$status = array();

@ -13,7 +13,7 @@ set_time_limit(0);
require_once __DIR__.'/../../vendor/autoload.php';
require_once 'install.lib.php';
require_once '../inc/lib/main_api.lib.php';
require_once '../inc/lib/api.lib.php';
error_reporting(-1);

@ -26,7 +26,7 @@ $language_file[] = "scormdocument";
$language_file[] = "learnpath";
// global settings initialisation
// also provides access to main api (inc/lib/main_api.lib.php)
// also provides access to main api (inc/lib/api.lib.php)
require_once '../inc/global.inc.php';
$htmlHeadXtra[] =
@ -115,4 +115,4 @@ switch ($my_tool) {
default:
require('form.document.php');
break;
}
}

@ -16,7 +16,7 @@
Libraries
*/
//many useful functions in main_api.lib.php, by default included
//many useful functions in api.lib.php, by default included
if (!function_exists('api_get_path')) {
header('location: upload.php');
die;
@ -146,7 +146,7 @@ if (isset($_POST['submit_image'])) {
//they want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
$added_slash = ($path == '/') ? '' : '/';
$dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']);
$dir_name = $path.$added_slash.api_replace_dangerous_char($_POST['dirname']);
$created_dir = FileManager::create_unexisting_directory(
$_course,
$_user['user_id'],
@ -250,4 +250,4 @@ if (isset($_GET['createdir'])) {
href="document.php?curdirpath=<?php echo $path; ?>"><?php echo (get_lang('DocumentsOverview'));?></a></p>
<?php
Display::display_footer();
Display::display_footer();

@ -14,7 +14,7 @@ $language_file[] = 'document';
$language_file[] = 'scorm';
//the document file is loaded because most of the upload vocab relates to the document tool
// global settings initialisation
// also provides access to main api (inc/lib/main_api.lib.php)
// also provides access to main api (inc/lib/api.lib.php)
require_once '../inc/global.inc.php';
// return to index if no tool is set
@ -41,4 +41,4 @@ switch($_SESSION['my_tool']){
default:
require 'upload.document.php';
break;
}
}

@ -245,7 +245,7 @@ class InstallCommand extends CommonCommand
if ($result) {
require_once $this->getRootSys().'main/inc/lib/database.constants.inc.php';
require_once $this->getRootSys().'main/inc/lib/main_api.lib.php';
require_once $this->getRootSys().'main/inc/lib/api.lib.php';
// In order to use the Database class
$database = new \Database($this->getHelper('db')->getConnection(), null);

@ -17,7 +17,7 @@ class AccessurleditcoursestourlTest extends PHPUnit_Framework_TestCase
{
ob_start();
require_once dirname(__FILE__).'/../../../main/inc/lib/access_url_edit_courses_to_url_functions.lib.php';
require_once dirname(__FILE__).'/../../../main/inc/lib/main_api.lib.php';
require_once dirname(__FILE__).'/../../../main/inc/lib/api.lib.php';
$this->object = new Accessurleditcoursestourl;
}

@ -17,7 +17,7 @@ class AccessurledituserstourlTest extends PHPUnit_Framework_TestCase
{
ob_start();
require_once dirname(__FILE__).'/../../../main/inc/lib/access_url_edit_users_to_url_functions.lib.php';
require_once dirname(__FILE__).'/../../../main/inc/lib/main_api.lib.php';
require_once dirname(__FILE__).'/../../../main/inc/lib/api.lib.php';
$this->object = new Accessurledituserstourl;
}

@ -79,7 +79,7 @@ require_once $libdir.'notebook.lib.php';
/**This files need be inside a buffering to clean the objects*/
ob_start();
require_once $libdir.'main_api.lib.php';
require_once $libdir.'api.lib.php';
require_once $libdir.'add_course.lib.inc.php';
require_once $libdir.'geometry.lib.php';
ob_end_clean();
@ -203,7 +203,7 @@ class TestManager
while (false !== ($file = readdir($handle))) {
if (strpos($file, $course_code) !== false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
api_rmdirr($path.'/'.$file);
}
}
}

@ -5,7 +5,7 @@
* courses directories, configuration files and all other temp directories.
* It only works when launched from the command line and requires Chamilo to
* be installed (otherwise it will not find the references as to the paths and
* databases to delete). It only wipes out stuff and directories it knows are
* databases to delete). It only wipes out stuff and directories it knows are
* created by Chamilo though, so don't worry about your own files if you didn't
* store them in variable Chamilo directories.
* Requires Chamilo LMS 1.9 or greater
@ -32,7 +32,7 @@ if (!file_exists(dirname(__FILE__).'/../main/inc/global.inc.php')) {
}
if (!is_file(dirname(__FILE__).'/../main/inc/conf/configuration.php')) {
echo " This script will only work on an already installed version of Chamilo. The \n", "main/inc/conf/configuration.php file could not be found, which is understood\n", "as Chamilo not being installed.\n";
echo " This script will only work on an already installed version of Chamilo. The \n", "main/inc/conf/configuration.php file could not be found, which is understood\n", "as Chamilo not being installed.\n";
exit;
}
@ -51,8 +51,8 @@ $homepath = api_get_path(SYS_PATH).'home';
$clean_dirs = array(
api_get_path(SYS_COURSE_PATH), //courses
api_get_path(SYS_CODE_PATH).'inc/conf/',
api_get_path(SYS_CODE_PATH).'upload/users/',
api_get_path(SYS_CODE_PATH).'inc/conf/',
api_get_path(SYS_CODE_PATH).'upload/users/',
api_get_path(SYS_ARCHIVE_PATH)
);
// With all this, we will still be missing custom languages and CSS dirs
@ -68,15 +68,15 @@ foreach ($clean_dirs as $dir) {
if (substr($entry,0,1) == '.' or strcmp($entry,'htaccess')===0 or strcmp($entry,'index.html')===0 or substr($entry,-9,9)=='.dist.php') {
//skip files that are part of the Chamilo installation
} else {
if ($dir == $homepath and
((is_dir($homepath.$entry) and $entry == 'default_platform_document')
if ($dir == $homepath and
((is_dir($homepath.$entry) and $entry == 'default_platform_document')
or (!is_dir($homepath.$entry) and substr($entry,-5)=='.html') and strlen($entry)<=17)
) {
//skip
} else {
} else {
if (is_dir($dir.$entry)) {
//echo "Removing ".$dir.$entry."\n";
rmdirr($dir.$entry);
api_rmdirr($dir.$entry);
} else {
//echo "Removing ".$dir.$entry."\n";
unlink($dir.$entry);

Loading…
Cancel
Save