custom_pages.class.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Used to implement the loading of custom pages
  5. *
  6. * @license see /license.txt
  7. * @author 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
  8. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  9. */
  10. class CustomPages
  11. {
  12. const INDEX_LOGGED = 'index-logged';
  13. const INDEX_UNLOGGED = 'index-unlogged';
  14. const LOGGED_OUT = 'loggedout';
  15. const REGISTRATION_FEEDBACK = 'registration-feedback';
  16. const REGISTRATION = 'registration';
  17. const LOST_PASSWORD = 'lostpassword';
  18. /**
  19. * Returns true if custom pages are enabled. False otherwise.
  20. * @return bool
  21. */
  22. public static function enabled()
  23. {
  24. return api_get_setting('use_custom_pages') == 'true';
  25. }
  26. /**
  27. * Returns the path to a custom page.
  28. *
  29. * @param string $name
  30. * @return string
  31. */
  32. public static function path($name = '')
  33. {
  34. return api_get_path(SYS_PATH) . 'custompages/' . $name;
  35. }
  36. /**
  37. * If enabled display a custom page and exist. Otherwise log error and returns.
  38. *
  39. * @param string $page_name
  40. * @param array $content used to path data to the custom page
  41. */
  42. public static function display($page_name, $content = array())
  43. {
  44. if (!self::enabled()) {
  45. return false;
  46. }
  47. $file = self::path($page_name . '.php');
  48. if (file_exists($file)) {
  49. include($file);
  50. exit;
  51. } else {
  52. error_log('CustomPages::displayPage : could not read file ' . $file);
  53. }
  54. }
  55. /**
  56. * Does not look like this function is being used is being used
  57. *
  58. * @param type $url_id
  59. * @return string
  60. */
  61. public static function getURLImages($url_id = null)
  62. {
  63. if (is_null($url_id)) {
  64. $url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
  65. $url_id = UrlManager::get_url_id($url);
  66. }
  67. $url_images_dir = api_get_path(SYS_PATH) . 'custompages/url-images/';
  68. $images = array();
  69. for ($img_id = 1; $img_id <= 3; $img_id++) {
  70. if (file_exists($url_images_dir . $url_id . '_url_image_' . $img_id . '.png')) {
  71. $images[] = api_get_path(WEB_PATH) . 'custompages/url-images/' . $url_id . '_url_image_' . $img_id . '.png';
  72. }
  73. }
  74. return $images;
  75. }
  76. }