custom_pages.class.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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('platform.use_custom_pages') == 'true';
  25. }
  26. /**
  27. * Returns the path to a custom page.
  28. *
  29. * @param string $name
  30. *
  31. * @return string
  32. */
  33. public static function path($name = '')
  34. {
  35. return api_get_path(SYS_PATH) . 'custompages/' . $name;
  36. }
  37. /**
  38. * If enabled display a custom page and exist. Otherwise log error and returns.
  39. *
  40. * @param string $page_name
  41. * @param array $content used to path data to the custom page
  42. */
  43. public static function display($page_name, $content = array())
  44. {
  45. if (!self::enabled()) {
  46. return false;
  47. }
  48. $file = self::path($page_name . '.php');
  49. if (file_exists($file)) {
  50. include($file);
  51. exit;
  52. } else {
  53. error_log('CustomPages::displayPage : could not read file ' . $file);
  54. }
  55. }
  56. /**
  57. * Does not look like this function is being used is being used
  58. *
  59. * @param int $url_id
  60. *
  61. * @return string
  62. */
  63. public static function getURLImages($url_id = null)
  64. {
  65. if (is_null($url_id)) {
  66. $url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
  67. $url_id = UrlManager::get_url_id($url);
  68. }
  69. $url_images_dir = api_get_path(SYS_PATH) . 'custompages/url-images/';
  70. $images = array();
  71. for ($img_id = 1; $img_id <= 3; $img_id++) {
  72. if (file_exists($url_images_dir . $url_id . '_url_image_' . $img_id . '.png')) {
  73. $images[] = api_get_path(WEB_PATH) . 'custompages/url-images/' . $url_id . '_url_image_' . $img_id . '.png';
  74. }
  75. }
  76. return $images;
  77. }
  78. /**
  79. * Check if exists the file for custom page
  80. * @param string $pageName The name of custom page
  81. * @return boolean
  82. */
  83. public static function exists($pageName)
  84. {
  85. $fileName = self::path("$pageName.php");
  86. return file_exists($fileName);
  87. }
  88. }