custom_pages.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. *
  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. }