lib changes for Rss

skala
Laurent Opprecht 14 years ago
parent 8417e2bf0f
commit f46721c0ea
  1. 9
      main/inc/autoload.inc.php
  2. 3
      main/inc/global.inc.php
  3. 39
      main/inc/lib/autoload.class.php
  4. 54
      main/inc/lib/chamilo.class.php
  5. 31
      main/inc/lib/header.class.php
  6. 2
      main/inc/lib/main_api.lib.php
  7. 7
      main/inc/lib/redirect.class.php
  8. 16
      main/inc/lib/request.class.php
  9. 188
      main/inc/lib/request_server.class.php
  10. 90
      main/inc/lib/uri.class.php

@ -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();

@ -92,8 +92,7 @@ ini_set('include_path', api_create_include_path_setting());
ini_set('auto_detect_line_endings', '1');
// Include the libraries that are necessary everywhere
require_once $lib_path.'autoload.class.php';
Autoload::register();
require_once dirname(__FILE__).'/autoload.inc.php';
require_once $lib_path.'database.lib.php';
require_once $lib_path.'template.lib.php';

@ -9,13 +9,28 @@
class Autoload
{
static private $is_registered = false;
/**
* Register the Chamilo autoloader on the stack.
* Will only do it once so this method is repeatable.
*/
static public function register()
{
if(self::is_registered())
{
return false;
}
$f = array(new self, 'load');
spl_autoload_register($f);
self::$is_registered = true;
return true;
}
static public function is_registered()
{
return self::$is_registered;
}
static public function map()
@ -27,15 +42,25 @@ class Autoload
return $result;
}
$dir = dirname(__FILE__);
$sys = api_get_path(SYS_CODE_PATH);
$dir = dirname(__FILE__) . '/';
$sys = $dir . '../../';
$result = array();
$result['Redirect'] = $dir . '/redirect.class.php';
$result['Request'] = $dir . '/request.class.php';
$result['AnnouncementEmail'] = $sys. 'announcements/announcement_email.class.php';
$result['Javascript'] = $dir . '/javascript.class.php';
$result['ClosureCompiler'] = $dir . '/closure_compiler.class.php';
$result['Chamilo'] = $dir . 'chamilo.class.php';
$result['Redirect'] = $dir . 'redirect.class.php';
$result['Request'] = $dir . 'request.class.php';
$result['RequestServer'] = $dir . 'request_server.class.php';
$result['AnnouncementEmail'] = $sys . 'announcements/announcement_email.class.php';
$result['Javascript'] = $dir . 'javascript.class.php';
$result['ClosureCompiler'] = $dir . 'closure_compiler.class.php';
$result['Uri'] = $dir . 'uri.class.php';
$result['GroupManager'] = $dir . 'groupmanager.lib.php';
$result['Header'] = $dir . 'header.class.php';
$result['Cache'] = $dir . 'cache.class.php';
$result['KeyAuth'] = $sys . 'auth/key/key_auth.class.php';
$result['CourseNoticeQuery'] = $sys . 'course_notice/course_notice_query.class.php';
$result['CourseNoticeController'] = $sys . 'course_notice/course_notice_controller.class.php';
$result['CourseNoticeRss'] = $sys . 'course_notice/course_notice_rss.class.php';
return $result;
}

@ -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');
}
}

@ -1138,6 +1138,8 @@ function api_get_anonymous_id() {
* Returns the cidreq parameter name + current course id taken from
* $GLOBALS['_cid'] and returns a string like 'cidReq=ABC&id_session=123
* @return string Course & session references to add to a URL
*
* @see Uri.course_params
*/
function api_get_cidreq() {
return empty($GLOBALS['_cid']) ? '' : 'cidReq='.htmlspecialchars($GLOBALS['_cid']).

@ -11,12 +11,7 @@ class Redirect
static function www()
{
static $result = false;
if (empty($result))
{
$result = api_get_path('WEB_PATH');
}
return $result;
Uri::www();
}
static function go($url = '')

@ -11,27 +11,31 @@ class Request
public static function get($key, $default = null)
{
return isset($_GET[$key]) ? isset($_GET[$key]) : $default;
return isset($_GET[$key]) ? $_GET[$key] : $default;
}
public static function post($key, $default = null)
{
return isset($_POST[$key]) ? isset($_POST[$key]) : $default;
return isset($_POST[$key]) ? $_POST[$key] : $default;
}
static function server($key, $default = null)
/**
*
* @return RequestServer
*/
static function server()
{
return isset($_SERVER[$key]) ? isset($_SERVER[$key]) : $default;
return RequestServer::instance();
}
static function file($key, $default = null)
{
return isset($_FILES[$key]) ? isset($_FILES[$key]) : $default;
return isset($_FILES[$key]) ? $_FILES[$key] : $default;
}
static function environment($key, $default = null)
{
return isset($_ENV[$key]) ? isset($_ENV[$key]) : $default;
return isset($_ENV[$key]) ? $_ENV[$key] : $default;
}
}

@ -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 ? '&amp;' : '&', $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…
Cancel
Save