custom_pages.class.php 2.3 KB

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