custom_pages.class.php 2.7 KB

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