Remove unused libs and code.

1.10.x
Julio Montoya 11 years ago
parent 6d32affd79
commit 941828be0b
  1. 24
      main/inc/lib/AnnouncementManager.php
  2. 1
      main/inc/lib/api.lib.php
  3. 118
      main/inc/lib/chamilo.class.php
  4. 103
      main/inc/lib/chamilo_session.class.php
  5. 28
      main/inc/lib/course.lib.php
  6. 9
      main/inc/lib/internationalization.lib.php
  7. 136
      main/inc/lib/portfolio.class.php
  8. 3
      main/inc/lib/redirect.class.php
  9. 12
      main/inc/lib/rights.lib.php
  10. 164
      main/inc/lib/system/io/temp.class.php
  11. 71
      main/inc/lib/system/web/header.class.php
  12. 25
      main/inc/lib/system/web/request.class.php

@ -1013,30 +1013,6 @@ class AnnouncementManager
</script>";
}
/**
* returns all the javascript that is required for easily
* setting the target people/groups
* this goes into the $htmlHeadXtra[] array
*/
public static function to_javascript()
{
$www = api_get_path(WEB_PATH);
/*
* Do not allow this kind of behaviour. js minifieds should be manage by the template class or assetic or whatever see #4757 for more info
if (api_get_setting('server_type') == 'test') {
$src = $www . 'main/announcements/resources/js/main.js';
} else {
$src = $www . 'main/announcements/resources/js/main.min.js';
}*/
$src = $www . 'main/announcements/resources/js/main.js';
$result = Javascript::tag($src);
$root = Chamilo::url();
$code = "var www = '$root';\n";
$code .= Javascript::get_lang('FieldRequired', 'Send2All', 'AddAnAttachment', 'Everybody');
$result .= Javascript::tag_code($code);
return $result;
}
/**
* constructs the form to display all the groups and users the message has been sent to
* input: $sent_to_array is a 2 dimensional array containing the groups and the users

@ -3273,7 +3273,6 @@ function api_not_allowed($print_headers = false, $message = null)
$osso->logout();
}
}
Header::response_code(403);
$home_url = api_get_path(WEB_PATH);
$user_id = api_get_user_id();
$course = api_get_course_id();

@ -17,23 +17,6 @@ function session()
*/
class Chamilo
{
public static function name()
{
//@todo: add version
return 'chamilo';
}
static function is_test_server()
{
return api_get_setting('server_type') == 'test';
}
static function is_production_server()
{
return api_get_setting('server_type') == 'production';
}
/**
*
* @return ChamiloSession
@ -42,103 +25,4 @@ class Chamilo
{
return ChamiloSession::instance();
}
/**
*
* @return CurrentUser
*/
static function user()
{
return ChamiloSession::instance()->user();
}
/**
* Returns a full url from local/absolute path and parameters.
* Append the root as required for relative urls.
*
* @param string $path
* @param array $params
* @return string
*/
public static function url($path = '', $params = array(), $html = true)
{
return Uri::url($path, $params, $html);
}
public static function here($params = array(), $html = true)
{
return Uri::here($params, $html);
}
/**
* Application web root
*/
public static function www()
{
return Uri::www();
}
/**
* File system root for Chamilo
*
* @return string
*/
public static function root()
{
return api_get_path(SYS_PATH);
}
public static function root_courses()
{
return api_get_path(SYS_COURSE_PATH);
}
/**
* Returns a temporary file - one that is automatically deleted at the end
* of the script.
*
* @param string $ext
* @return Temp
*/
public static function temp_file($ext = '')
{
$ext = $ext ? '.' . $ext : '';
Temp::set_temp_root(api_get_path(SYS_ARCHIVE_PATH) . 'temp');
$path = Temp::get_temporary_name() . $ext;
return Temp::create($path);
}
/**
* Returns a temporary directory - one that is automatically deleted at the end
* of the script.
*
* @param string $ext
* @return Temp
*/
public static function temp_dir()
{
$ext = $ext ? '.' . $ext : '';
Temp::set_temp_root(api_get_path(SYS_ARCHIVE_PATH) . 'temp');
$path = Temp::get_temporary_name() . $ext;
return Temp::dir($path);
}
/**
*
* @return Zip
*/
public static function temp_zip()
{
return Zip::create(self::temp_file('zip'));
}
public static function path($path = '')
{
$root = self::root();
if (empty($path)) {
return $root;
}
return $root . $path;
}
}
}

@ -1,16 +1,16 @@
<?php
/**
* Chamilo session (i.e. the session that maintains the connection open after usr login)
*
*
* Usage:
*
*
*
*
* use ChamiloSession as Session;
*
*
* Session::read('name');
*
*
* Or
*
*
* Chamilo::session()->...
* session()->...
*
@ -27,7 +27,7 @@ class ChamiloSession extends System\Session
/**
* Generate new session instance
* @return ChamiloSession
* @return ChamiloSession
*/
static function instance()
{
@ -74,54 +74,8 @@ class ChamiloSession extends System\Session
{
global $_configuration;
/* Causes too many problems and is not configurable dynamically.
if ($already_installed) {
$session_lifetime = 360000;
if (isset($_configuration['session_lifetime'])) {
$session_lifetime = $_configuration['session_lifetime'];
}
//session_set_cookie_params($session_lifetime,api_get_path(REL_PATH));
}
*/
if (isset($_configuration['session_stored_in_db']) &&
$_configuration['session_stored_in_db'] &&
function_exists('session_set_save_handler')
) {
$handler = new SessionHandlerDatabase();
@session_set_save_handler(
array($handler, 'open'),
array($handler, 'close'),
array($handler, 'read'),
array($handler, 'write'),
array($handler, 'destroy'),
array($handler, 'garbage')
);
}
// An alternative session handler, storing the session in memcache,
// and in the DB as backup for memcache server failure, can be used
// by defining specific configuration settings.
// This requires memcache or memcached and the php5-memcache module
// to be installed.
// See configuration.dist.php for greater details
if (isset($_configuration['session_stored_in_db_as_backup']) &&
$_configuration['session_stored_in_db_as_backup'] &&
function_exists('session_set_save_handler')
) {
$handler = new SessionHandlerMemcache();
session_set_save_handler(
array(&$handler, 'open'),
array(&$handler, 'close'),
array(&$handler, 'read'),
array(&$handler, 'write'),
array(&$handler, 'destroy'),
array(&$handler, 'gc')
);
}
/*
* Prevent Session fixation bug fixes
* Prevent Session fixation bug fixes
* See http://support.chamilo.org/issues/3600
* http://php.net/manual/en/session.configuration.php
* @todo use session_set_cookie_params with some custom admin parameters
@ -131,12 +85,12 @@ class ChamiloSession extends System\Session
//the session ID is only accepted from a cookie
ini_set('session.use_only_cookies', 1);
//HTTPS only if possible
//HTTPS only if possible
//ini_set('session.cookie_secure', 1);
//session ID in the cookie is only readable by the server
//session ID in the cookie is only readable by the server
ini_set('session.cookie_httponly', 1);
//Use entropy file
//Use entropy file
//session.entropy_file
//ini_set('session.entropy_length', 128);
//Do not include the identifier in the URL, and not to read the URL for
@ -198,39 +152,4 @@ class ChamiloSession extends System\Session
{
return $this->end_time() < time();
}
/**
* The current (logged in) user.
* @return CurrentUser The current user instance
*/
public function user()
{
static $result = null;
if (empty($result)) {
$result = CurrentUser::instance();
}
return $result;
}
/**
* Returns the current (active) course
* @return CurrentCourse The current course instance
*/
public function course()
{
static $result = null;
if (empty($result)) {
$result = CurrentCourse::instance();
}
return $result;
}
/**
* The current group for the current (logged in) user.
* @return int the current group id
*/
public function group_id()
{
return Session::read('_gid');
}
}

@ -4751,34 +4751,6 @@ class CourseManager
return $result;
}
/**
* @deprecated seems not to be used
*/
static function list_inactive_courses($ceiling, $visibility_level = COURSE_VISIBILITY_REGISTERED)
{
$ceiling = is_numeric($ceiling) ? (int)$ceiling : strtotime($ceiling);
$ceiling = date('Y-m-d H:i:s', $ceiling);
$visibility_level = $visibility_level ? $visibility_level : '0';
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$table_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT
c.*,
cat.name AS category
FROM
$table_course AS c
LEFT JOIN
$table_category AS cat
ON
c.category_code = cat.code
WHERE
c.visibility >= $visibility_level AND
c.last_visit<='$ceiling'
";
return ResultSet::create($sql);
}
/**
* Get courses count
* @param int Access URL ID (optional)

@ -11,6 +11,8 @@
* @package chamilo.library
*/
use Patchwork\Utf8;
/**
* Constants
*/
@ -3295,10 +3297,11 @@ function api_detect_encoding($string, $language = null) {
/**
* Checks a string for UTF-8 validity.
*
* @deprecated Use Encoding::utf8()->is_valid() instead
*/
function api_is_valid_utf8(&$string) {
return Encoding::utf8()->is_valid($string);
function api_is_valid_utf8(&$string)
{
return Utf8::isUtf8($string);
}
/**

@ -2,8 +2,8 @@
/* For licensing terms, see /license.txt */
/*
* This file contains several classes related to portfolios management to avoid
* having too much files under the lib/.
*
* having too much files under the lib/.
*
* Once external libraries are moved to their own directory it would be worth
* moving them to their own files under a common portfolio directory.
* @package chamilo.portfolio
@ -16,19 +16,19 @@ use Model\Course;
/**
* A portfolio is used to present content to other people. In most cases it is
* an external application.
*
* an external application.
*
* From the application point of view it is an end point to which the user can send
* content.
*
*
* Available portfolios are configured in /main/inc/config/portfolio.conf.php
*
*
* The Portfolio class serves as an entry point to other portfolio components:
*
*
* - portfolio controller
* - portfolio share button
* - portfolio action
*
*
* Note:
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
@ -38,7 +38,7 @@ class Portfolio
/**
* Returns all portfolios available
*
*
* @return array
*/
public static function all()
@ -53,7 +53,7 @@ class Portfolio
/**
* Returns a portfolio from its name.
*
*
* @param string $name
* @return Portfolio\Portfolio
*/
@ -70,8 +70,8 @@ class Portfolio
/**
* True if portfolios are enabled. False otherwise.
*
* @return boolean
*
* @return boolean
*/
public static function is_enabled()
{
@ -91,8 +91,8 @@ class Portfolio
/**
* The controller for portfolio.
*
* @return \PortfolioController
*
* @return \PortfolioController
*/
public static function controller()
{
@ -101,11 +101,11 @@ class Portfolio
/**
* Returns a share component/button.
*
*
* @param string $tool
* @param int $id
* @param array $attributes
* @return \PortfolioShare
* @return \PortfolioShare
*/
public static function share($tool, $id, $attributes = array())
{
@ -114,8 +114,8 @@ class Portfolio
/**
* Returns the list of actions.
*
* @return array
*
* @return array
*/
public static function actions()
{
@ -124,9 +124,9 @@ class Portfolio
/**
* Returns a temporary url to download files and/or folders.
*
*
* @param string|array $ids
* @return string
* @return string
*/
public static function download_url($ids, $tool)
{
@ -143,14 +143,14 @@ class Portfolio
/**
* The portfolio controller. Responsible to dispatch/process portfolio actions.
*
*
* Usage:
*
*
* if(Porfolio::contoller()->accept()){
* Portfolio::controller()->run();
* }
*
*
*
*
*/
class PortfolioController
{
@ -166,7 +166,7 @@ class PortfolioController
/**
*
* @return \PortfolioController
* @return \PortfolioController
*/
static function instance()
{
@ -181,7 +181,7 @@ class PortfolioController
protected function __construct()
{
}
public static function portfolios()
@ -190,9 +190,9 @@ class PortfolioController
}
/**
* List of actions for the SortableTable.
*
* @return array
* List of actions for the SortableTable.
*
* @return array
*/
public static function actions()
{
@ -216,10 +216,10 @@ class PortfolioController
}
/**
* Returns true if the controller accept to process the current request.
* Returns true if the controller accept to process the current request.
* Returns false otherwise.
*
* @return boolean
*
* @return boolean
*/
function accept()
{
@ -249,8 +249,8 @@ class PortfolioController
/**
* Returns the value of the current controller request parameters. That is
* the name of the controller which shall handle the current request.
*
* the name of the controller which shall handle the current request.
*
* @return string
*/
function get_controller()
@ -261,8 +261,8 @@ class PortfolioController
/**
* Returns the value of the action parameter. That is which action shall be
* performed. That is share to send an object to a portfolio.
*
* @return string
*
* @return string
*/
function get_action()
{
@ -272,7 +272,7 @@ class PortfolioController
/**
* Returns the value of the id parameter: id of object to send.
*
*
* @return int
*/
function get_id()
@ -282,7 +282,7 @@ class PortfolioController
/**
* The course code (id) to which the object belongs.
*
*
* @return string
*/
function course_code()
@ -292,8 +292,8 @@ class PortfolioController
/**
* The name of the porfolio where to send.
*
* @return type
*
* @return type
*/
function get_portfolio()
{
@ -302,9 +302,9 @@ class PortfolioController
/**
* Name of the tool: document, work, etc. Defaults to current_course_tool.
*
*
* @global string $current_course_tool
* @return string
* @return string
*/
function get_tool()
{
@ -322,12 +322,12 @@ class PortfolioController
}
/**
* Execute the controller action as required. If a registered action accept
* Execute the controller action as required. If a registered action accept
* the current request the controller calls it.
*
*
* If not action is accept the current request and current action is "share"
* the controller execute the "send to portfolio" action
*
*
* @return PortfolioController
*/
function run()
@ -373,28 +373,28 @@ class PortfolioController
/**
* This component is used to display a "send to portfolio" button for a specific
* object.
*
* Note that the component implement the __toString() magic method and can be
* object.
*
* Note that the component implement the __toString() magic method and can be
* therefore used in situation where a string is expected: for ex echo $button.
*
*
* Usage
*
*
* $button = Portfolio::share(...);
* echo $button;
*
*
*/
class PortfolioShare
{
/**
* Create a "send to portfolio" button
*
*
* @param string $tool The name of the tool: document, work.
* @param int $c_id The id of the course
* @param int $id The id of the object
* @param int $id The id of the object
* @param array $attributes Html attributes
* @return \PortfolioShare
* @return \PortfolioShare
*/
static function factory($tool, $id, $attributes = array())
{
@ -404,8 +404,8 @@ class PortfolioShare
/**
* Returns the current secuirty token. Used to avoid see surfing attacks.
*
* @return type
*
* @return type
*/
static function security_token()
{
@ -446,8 +446,8 @@ class PortfolioShare
}
/**
* Html attributes.
*
* Html attributes.
*
* @return array
*/
function get_attributes()
@ -457,7 +457,7 @@ class PortfolioShare
/**
* Name of the tool. I.e. the type of the id parameter. Can be document, work.
*
*
* @return string
*/
function get_tool()
@ -467,8 +467,8 @@ class PortfolioShare
/**
* Display the component.
*
* @return string
*
* @return string
*/
function display()
{
@ -503,7 +503,7 @@ class PortfolioShare
$parameters[PortfolioController::PARAM_TOOL] = $this->get_tool();
$parameters[PortfolioController::PARAM_ID] = $id;
$parameters[PortfolioController::PARAM_TOOL] = $tool;
$url = Chamilo::url('/main/portfolio/share.php', $parameters);
$url = api_get_path(WEB_CODE_PATH).'portfolio/share.php', $parameters);
$result[] = '<li>';
$result[] = '<a href="' . $url . '">' . $portfolio->get_title() . '</a>';
$result[] = '</li>';
@ -522,15 +522,15 @@ class PortfolioShare
}
/**
* A "send to this portfolio" action. Actions are used by the SortableTable to
* A "send to this portfolio" action. Actions are used by the SortableTable to
* perform actions on a set of objects. An action is composed of
*
*
* - a name
* - a title (displayed to the user)
* - code to execute
*
*
* Usage:
*
*
* $form_actions = array();
* $form_action['...'] = get_lang('...');
* $portfolio_actions = Portfolio::actions();
@ -538,7 +538,7 @@ class PortfolioShare
* $form_action[$action->get_name()] = $action->get_title();
* }
* $table->set_form_actions($form_action, 'path');
*
*
* @see SortableTable
*/
class PortfolioBulkAction
@ -560,7 +560,7 @@ class PortfolioBulkAction
/**
*
* @param \Portfolio\Portfolio $portfolio
* @param \Portfolio\Portfolio $portfolio
*/
public function __construct($portfolio)
{

@ -12,7 +12,7 @@ class Redirect
*/
public static function www()
{
return Uri::www();
return api_get_path(WEB_PATH);
}
/**
@ -141,7 +141,6 @@ class Redirect
*/
protected static function navigate($url)
{
//$url = Security::remove_XSS($url);
session_write_close(); //should not be neeeded
header("Location: $url");
exit;

@ -1,9 +1,13 @@
<?php
/**
* Class Rights
* @deprecated Don't use this class
*/
class Rights {
private static $rights_cache = array();
private static $rights = array (
'show_tabs:reports' =>
'show_tabs:reports' =>
array (
'type' => 'const',
'const' => 'true' )
@ -12,7 +16,7 @@ class Rights {
// warning the goal of this function is to enforce rights managment in Chamilo
// thus default return value is always true
public static function hasRight($handler) {
if (array_key_exists($handler, self::$rights_cache))
if (array_key_exists($handler, self::$rights_cache))
return self::$rights_cache[$handler];
if (!array_key_exists($handler, self::$rights))
@ -20,7 +24,7 @@ class Rights {
if (self::$rights[$handler]['type'] == 'sql') {
$result = Database::query(self::$rights[$handler]['sql']);
if (Database::num_rows($result) > 0)
if (Database::num_rows($result) > 0)
$result = true;
else
$result = false;
@ -33,7 +37,7 @@ class Rights {
self::$rights_cache[$handler] = $result;
return $result;
}
public static function hasRightClosePageWithError($handler) {
if (hasRight($handler) == false)
die("You are not allowed here"); //FIXME

@ -1,164 +0,0 @@
<?php
/**
* Temporary file/folder. The file/folder is automatically deleted at
* the end of the script/during garbage collection.
*
* The object implements __toString so it can be used as string variable.
*
* Usage
*
* $path = Temp::file();
* file_puts_content($path, $content);
*
* or
*
* $path = Temp::dir();
* ...
*
* @copyright (c) 2012 University of Geneva
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
* @author Laurent Opprecht <laurent@opprecht.info>
*/
class Temp
{
protected static $files = array();
/**
* Returns the list of temporary files opened by the script.
* This is mostly due to pin temporary files and prevent garbage collection.
* This ensure files are not unlinked while still using it to send data in
* an upload.
*
* @return array
*/
public static function files()
{
return self::$files;
}
/**
* Recursively delete files and/or folders.
*
* @param string $path
* @return boolean
*/
public static function delete($path)
{
if (!file_exists($path)) {
return false;
}
if (is_readable($path)) {
unlink($path);
return true;
}
if (is_dir($path)) {
$files = scandir($path);
$files = array_diff($files, array('.', '..'));
foreach ($files as $file) {
self::delete($file);
}
rmdir($path);
}
}
private static $temp_root = '';
/**
* Set the temp root directory. Temporary files are by default created in this directory.
* Defaults to sys_get_temp_dir().
*
* @param string $value
*/
public static function set_temp_root($value)
{
self::$temp_root = $value;
}
public static function get_temp_root()
{
if (empty(self::$temp_root)) {
self::$temp_root = sys_get_temp_dir();
}
return self::$temp_root;
}
/**
* Returns a path to a non-existing temporary file located under temp_dir.
*
* @return string
*/
public static function get_temporary_name()
{
$result = self::get_temp_root() . '/' . md5(uniqid('tmp', true));
while (file_exists($result)) {
$result = self::get_temp_root() . '/' . md5(uniqid('tmp', true));
}
return $result;
}
/**
*
* @param string $path
* @return Temp
*/
public static function file($path = '')
{
$path = $path ? $path : self::get_temporary_name();
return new self($path);
}
/**
*
* @param string $path
* @return Temp
*/
public static function dir($path = '')
{
$path = $path ? $path : self::get_temporary_name();
if (!file_exists($path)) {
mkdir($path, 0777, $true);
}
return new self($path);
}
/**
*
* @param string $path
* @return Temp
*/
public static function create($path = '')
{
$path = $path ? $path : self::get_temporary_name();
return new self($path);
}
protected $path = '';
function __construct($path = '')
{
self::$files[] = $this;
$this->path = $path;
}
function get_path()
{
return $this->path;
}
function __toString()
{
return $this->path;
}
function __destruct()
{
$path = $this->path;
self::delete($path);
}
}

@ -8,79 +8,14 @@
*/
class Header
{
public static function response_code($response_code)
{
if (function_exists('http_response_code')) {
http_response_code($response_code);
return;
}
switch ($response_code) {
case 400:
header("HTTP/1.0 $response_code Bad Request");
case 401:
header("HTTP/1.0 $response_code Unauthorized");
case 402:
header("HTTP/1.0 $response_code Payment Required");
case 403:
header("HTTP/1.0 $response_code Forbidden");
case 404:
header("HTTP/1.0 $response_code Not Found");
default:
header("HTTP/1.0 $response_code");
}
}
public static function content_type($mime_type, $charset = '')
{
if (empty($mime_type)) {
return;
}
$type = $charset ? "$mime_type;charset=$charset" : $mime_type;
header('Content-type: ' . $type);
}
public static function content_type_xml()
{
header('Content-type: text/xml');
}
public static function content_type_json()
{
header('Content-type: application/json');
}
public static function content_type_javascript()
{
header('Content-type: application/javascript');
}
/**
* Redirect the navigator to the specified url.
*
* @param string $url
*
* @param string $url
*/
public static function location($url)
{
header("Location: $url");
exit;
}
public static function expires($timestamp)
{
$value = gmdate('D, d M Y H:i:s \G\M\T', $timestamp);
header('Expires: ' . $value);
}
public static function cache_control($value)
{
header('Cache-Control: ' . $value);
}
public static function pragma($value)
{
header('Pragma: ' . $value);
}
}
}

@ -2,7 +2,7 @@
/**
* Provides access to various HTTP request elements: GET, POST, FILE, etc paramaters.
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
@ -13,14 +13,14 @@ class Request
{
return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default;
}
public static function has($key){
return isset($_REQUEST[$key]);
}
/**
* Returns true if the request is a GET request. False otherwise.
*
*
* @return bool
*/
public static function is_get()
@ -29,15 +29,15 @@ class Request
$method = strtoupper($method);
return $method == 'GET';
}
public static function post($key, $default = null)
{
return isset($_POST[$key]) ? $_POST[$key] : $default;
}
/**
* Returns true if the request is a POST request. False otherwise.
*
*
* @return bool
*/
public static function is_post()
@ -46,15 +46,6 @@ class Request
$method = strtoupper($method);
return $method == 'POST';
}
/**
*
* @return RequestServer
*/
static function server()
{
return RequestServer::instance();
}
static function file($key, $default = null)
{
@ -66,4 +57,4 @@ class Request
return isset($_ENV[$key]) ? $_ENV[$key] : $default;
}
}
}

Loading…
Cancel
Save