parent
8417e2bf0f
commit
f46721c0ea
@ -0,0 +1,9 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Set up the Chamilo autoload stack. Can be called several time if needed also |
||||
* better to avoid it. |
||||
*/ |
||||
|
||||
require_once dirname(__FILE__) . '/lib/autoload.class.php'; |
||||
Autoload::register(); |
||||
@ -0,0 +1,54 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Description of chamilo |
||||
* |
||||
* @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 Chamilo |
||||
{ |
||||
|
||||
/** |
||||
* 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); |
||||
} |
||||
|
||||
/** |
||||
* 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 path($path = '') |
||||
{ |
||||
$root = self::root(); |
||||
if(empty($path)) |
||||
{ |
||||
return $root; |
||||
} |
||||
return $root . $path; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,31 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Header utility functions. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Header |
||||
{ |
||||
|
||||
public static function content_type($mime_type) |
||||
{ |
||||
if (empty($mime_type)) |
||||
{ |
||||
return; |
||||
} |
||||
header('Content-type: ' . $mime_type); |
||||
} |
||||
|
||||
public static function content_type_xml() |
||||
{ |
||||
header('Content-type: text/xml'); |
||||
} |
||||
|
||||
public static function content_type_javascript() |
||||
{ |
||||
header('Content-type: application/javascript'); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,188 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Provides access to the $_SERVER variable. Useful to have autocompletion working. |
||||
* Access through the Request class. |
||||
* |
||||
* Example: |
||||
* |
||||
* Request :: server()-> request_uri() |
||||
* |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class RequestServer |
||||
{ |
||||
|
||||
public static function instance() |
||||
{ |
||||
static $result = null; |
||||
if (empty($result)) |
||||
{ |
||||
$result = new self(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
function get($key, $default = null) |
||||
{ |
||||
return isset($_SERVER[$key]) ? $_SERVER[$key] : null; |
||||
} |
||||
|
||||
function request_time() |
||||
{ |
||||
return isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : null; |
||||
} |
||||
|
||||
function http_host() |
||||
{ |
||||
return isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
||||
} |
||||
|
||||
function http_user_agent() |
||||
{ |
||||
return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
||||
} |
||||
|
||||
function http_accept() |
||||
{ |
||||
return isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; |
||||
} |
||||
|
||||
function http_accept_language() |
||||
{ |
||||
return isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; |
||||
} |
||||
|
||||
function http_accept_encoding() |
||||
{ |
||||
return isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : null; |
||||
} |
||||
|
||||
function http_connection() |
||||
{ |
||||
return isset($_SERVER['HTTP_CONNECTION']) ? $_SERVER['HTTP_CONNECTION'] : null; |
||||
} |
||||
|
||||
function http_cookie() |
||||
{ |
||||
return isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : null; |
||||
} |
||||
|
||||
function http_cache_control() |
||||
{ |
||||
return isset($_SERVER['HTTP_CACHE_CONTROL']) ? $_SERVER['HTTP_CACHE_CONTROL'] : null; |
||||
} |
||||
|
||||
function path() |
||||
{ |
||||
return isset($_SERVER['PATH']) ? $_SERVER['PATH'] : null; |
||||
} |
||||
|
||||
function systemroot() |
||||
{ |
||||
return isset($_SERVER['SystemRoot']) ? $_SERVER['SystemRoot'] : null; |
||||
} |
||||
|
||||
function comspec() |
||||
{ |
||||
return isset($_SERVER['COMSPEC']) ? $_SERVER['COMSPEC'] : null; |
||||
} |
||||
|
||||
function pathext() |
||||
{ |
||||
return isset($_SERVER['PATHEXT']) ? $_SERVER['PATHEXT'] : null; |
||||
} |
||||
|
||||
function windir() |
||||
{ |
||||
return isset($_SERVER['WINDIR']) ? $_SERVER['WINDIR'] : null; |
||||
} |
||||
|
||||
function server_signature() |
||||
{ |
||||
return isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER['SERVER_SIGNATURE'] : null; |
||||
} |
||||
|
||||
function server_software() |
||||
{ |
||||
return isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null; |
||||
} |
||||
|
||||
function server_name() |
||||
{ |
||||
return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
||||
} |
||||
|
||||
function server_addr() |
||||
{ |
||||
return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null; |
||||
} |
||||
|
||||
function server_port() |
||||
{ |
||||
return isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
||||
} |
||||
|
||||
function remote_addr() |
||||
{ |
||||
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
||||
} |
||||
|
||||
function document_root() |
||||
{ |
||||
return isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : null; |
||||
} |
||||
|
||||
function server_admin() |
||||
{ |
||||
return isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : null; |
||||
} |
||||
|
||||
function script_filename() |
||||
{ |
||||
return isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : null; |
||||
} |
||||
|
||||
function remote_port() |
||||
{ |
||||
return isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : null; |
||||
} |
||||
|
||||
function gateway_interface() |
||||
{ |
||||
return isset($_SERVER['GATEWAY_INTERFACE']) ? $_SERVER['GATEWAY_INTERFACE'] : null; |
||||
} |
||||
|
||||
function server_protocol() |
||||
{ |
||||
return isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null; |
||||
} |
||||
|
||||
function request_method() |
||||
{ |
||||
return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; |
||||
} |
||||
|
||||
function query_string() |
||||
{ |
||||
return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; |
||||
} |
||||
|
||||
function request_uri() |
||||
{ |
||||
return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; |
||||
} |
||||
|
||||
function script_name() |
||||
{ |
||||
return isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null; |
||||
} |
||||
|
||||
function php_self() |
||||
{ |
||||
return isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : null; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,90 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Utility functions to manage uris/urls. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Uri |
||||
{ |
||||
|
||||
public static function chamilo() |
||||
{ |
||||
return 'http://chamilo.org/'; |
||||
} |
||||
|
||||
/** |
||||
* Application web root |
||||
*/ |
||||
public static function www() |
||||
{ |
||||
static $result = false; |
||||
if (empty($result)) |
||||
{ |
||||
$result = api_get_path(WEB_PATH); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* 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) |
||||
{ |
||||
$result = $path; |
||||
if (strpos($result, 'http') !== 0) |
||||
{ |
||||
$result = ltrim($result, '/'); |
||||
$result = self::www() . $result; |
||||
} |
||||
if ($params) |
||||
{ |
||||
|
||||
$result = rtrim($result, '?'); |
||||
$result = $result . '?' . self::params($params, $html); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Format url parameters |
||||
* |
||||
* @param array $params |
||||
* @return string |
||||
*/ |
||||
public static function params($params = array(), $html = true) |
||||
{ |
||||
$result = array(); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
$result[] = $key . '=' . urlencode($value); |
||||
} |
||||
$result = implode($html ? '&' : '&', $result); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Returns the course parameters. If null default to the current user parameters. |
||||
* |
||||
* @param string $course_code |
||||
* @param string|int $session_id |
||||
* @param string|int $group_id |
||||
* @return type |
||||
*/ |
||||
public static function course_params($course_code = null, $session_id = null, $group_id = null) |
||||
{ |
||||
$course_code = is_null($course_code) ? api_get_course_id() : $course_code; |
||||
$session_id = is_null($session_id) ? api_get_session_id() : $session_id; |
||||
$session_id = $session_id ? $session_id : '0'; |
||||
$group_id = is_null($group_id) ? '' : $group_id; |
||||
$group_id = $group_id ? $group_id : '0'; |
||||
return array('cidReq' => $course_code, 'id_session' => $session_id, 'gidReq' => $group_id); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue