start.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Plugin for creating web pages for your site
  4. */
  5. elgg_register_event_handler('init', 'system', 'expages_init');
  6. function expages_init() {
  7. // Register a page handler, so we can have nice URLs
  8. elgg_register_page_handler('about', 'expages_page_handler');
  9. elgg_register_page_handler('terms', 'expages_page_handler');
  10. elgg_register_page_handler('privacy', 'expages_page_handler');
  11. elgg_register_page_handler('expages', 'expages_page_handler');
  12. // Register public external pages
  13. elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'expages_public');
  14. elgg_register_plugin_hook_handler('register', 'menu:expages', 'expages_menu_register_hook');
  15. // add a menu item for the admin edit page
  16. elgg_register_admin_menu_item('configure', 'expages', 'appearance');
  17. // add footer links
  18. expages_setup_footer_menu();
  19. // register action
  20. $actions_base = elgg_get_plugins_path() . 'externalpages/actions';
  21. elgg_register_action("expages/edit", "$actions_base/edit.php", 'admin');
  22. }
  23. /**
  24. * Extend the public pages range
  25. *
  26. */
  27. function expages_public($hook, $handler, $return, $params){
  28. $pages = array('about', 'terms', 'privacy');
  29. return array_merge($pages, $return);
  30. }
  31. /**
  32. * Setup the links to site pages
  33. */
  34. function expages_setup_footer_menu() {
  35. $pages = array('about', 'terms', 'privacy');
  36. foreach ($pages as $page) {
  37. $url = "$page";
  38. $wg_item = new ElggMenuItem($page, elgg_echo("expages:$page"), $url);
  39. elgg_register_menu_item('walled_garden', $wg_item);
  40. $footer_item = clone $wg_item;
  41. elgg_register_menu_item('footer', $footer_item);
  42. }
  43. }
  44. /**
  45. * External pages page handler
  46. *
  47. * @param array $page URL segements
  48. * @param string $handler Handler identifier
  49. * @return bool
  50. */
  51. function expages_page_handler($page, $handler) {
  52. if ($handler == 'expages') {
  53. expages_url_forwarder($page[1]);
  54. }
  55. $type = strtolower($handler);
  56. $title = elgg_echo("expages:$type");
  57. $header = elgg_view_title($title);
  58. $object = elgg_get_entities(array(
  59. 'type' => 'object',
  60. 'subtype' => $type,
  61. 'limit' => 1,
  62. ));
  63. if ($object) {
  64. $content .= elgg_view('output/longtext', array('value' => $object[0]->description));
  65. } else {
  66. $content .= elgg_echo("expages:notset");
  67. }
  68. $content = elgg_view('expages/wrapper', array('content' => $content));
  69. if (elgg_is_admin_logged_in()) {
  70. elgg_register_menu_item('title', array(
  71. 'name' => 'edit',
  72. 'text' => elgg_echo('edit'),
  73. 'href' => "admin/appearance/expages?type=$type",
  74. 'link_class' => 'elgg-button elgg-button-action',
  75. ));
  76. }
  77. if (elgg_is_logged_in() || !elgg_get_config('walled_garden')) {
  78. $body = elgg_view_layout('one_column', array('title' => $title, 'content' => $content));
  79. echo elgg_view_page($title, $body);
  80. } else {
  81. elgg_load_css('elgg.walled_garden');
  82. $body = elgg_view_layout('walled_garden', array('content' => $header . $content));
  83. echo elgg_view_page($title, $body, 'walled_garden');
  84. }
  85. return true;
  86. }
  87. /**
  88. * Adds menu items to the expages edit form
  89. *
  90. * @param string $hook 'register'
  91. * @param string $type 'menu:expages'
  92. * @param array $return current menu items
  93. * @param array $params parameters
  94. *
  95. * @return array
  96. */
  97. function expages_menu_register_hook($hook, $type, $return, $params) {
  98. $type = elgg_extract('type', $params);
  99. $pages = array('about', 'terms', 'privacy');
  100. foreach ($pages as $page) {
  101. $return[] = ElggMenuItem::factory(array(
  102. 'name' => $page,
  103. 'text' => elgg_echo("expages:$page"),
  104. 'href' => "admin/appearance/expages?type=$page",
  105. 'selected' => $page === $type,
  106. ));
  107. }
  108. return $return;
  109. }
  110. /**
  111. * Forward to the new style of URLs
  112. *
  113. * @param string $page
  114. */
  115. function expages_url_forwarder($page) {
  116. global $CONFIG;
  117. $url = "{$CONFIG->wwwroot}{$page}";
  118. forward($url);
  119. }