chamilo.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. *
  4. * @return ChamiloSession
  5. */
  6. function session()
  7. {
  8. return Chamilo::session();
  9. }
  10. /**
  11. * Description of chamilo
  12. *
  13. * @license see /license.txt
  14. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  15. */
  16. class Chamilo
  17. {
  18. public static function name()
  19. {
  20. //@todo: add version
  21. return 'chamilo';
  22. }
  23. static function is_test_server()
  24. {
  25. return api_get_setting('server_type') == 'test';
  26. }
  27. static function is_production_server()
  28. {
  29. return api_get_setting('server_type') == 'production';
  30. }
  31. /**
  32. *
  33. * @return ChamiloSession
  34. */
  35. static function session()
  36. {
  37. return ChamiloSession::instance();
  38. }
  39. /**
  40. *
  41. * @return CurrentUser
  42. */
  43. static function user()
  44. {
  45. return ChamiloSession::instance()->user();
  46. }
  47. /**
  48. * Returns a full url from local/absolute path and parameters.
  49. * Append the root as required for relative urls.
  50. *
  51. * @param string $path
  52. * @param array $params
  53. * @return string
  54. */
  55. public static function url($path = '', $params = array(), $html = true)
  56. {
  57. return Uri::url($path, $params, $html);
  58. }
  59. public static function here($params = array(), $html = true)
  60. {
  61. return Uri::here($params, $html);
  62. }
  63. /**
  64. * Application web root
  65. */
  66. public static function www()
  67. {
  68. return Uri::www();
  69. }
  70. /**
  71. * File system root for Chamilo
  72. *
  73. * @return string
  74. */
  75. public static function root()
  76. {
  77. return api_get_path(SYS_PATH);
  78. }
  79. public static function root_courses()
  80. {
  81. return api_get_path(SYS_COURSE_PATH);
  82. }
  83. /**
  84. * Returns a temporary file - one that is automatically deleted at the end
  85. * of the script.
  86. *
  87. * @param string $ext
  88. * @return Temp
  89. */
  90. public static function temp_file($ext = '')
  91. {
  92. $ext = $ext ? '.' . $ext : '';
  93. Temp::set_temp_root(api_get_path(SYS_ARCHIVE_PATH) . 'temp');
  94. $path = Temp::get_temporary_name() . $ext;
  95. return Temp::create($path);
  96. }
  97. /**
  98. * Returns a temporary directory - one that is automatically deleted at the end
  99. * of the script.
  100. *
  101. * @param string $ext
  102. * @return Temp
  103. */
  104. public static function temp_dir()
  105. {
  106. $ext = $ext ? '.' . $ext : '';
  107. Temp::set_temp_root(api_get_path(SYS_ARCHIVE_PATH) . 'temp');
  108. $path = Temp::get_temporary_name() . $ext;
  109. return Temp::dir($path);
  110. }
  111. /**
  112. *
  113. * @return Zip
  114. */
  115. public static function temp_zip()
  116. {
  117. return Zip::create(self::temp_file('zip'));
  118. }
  119. public static function path($path = '')
  120. {
  121. $root = self::root();
  122. if (empty($path)) {
  123. return $root;
  124. }
  125. return $root . $path;
  126. }
  127. }