Router.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace ColdTrick\BlogTools;
  3. /**
  4. * Router handling
  5. *
  6. * @package ColdTrick
  7. * @subpackage BlogTools
  8. */
  9. class Router {
  10. /**
  11. * Listen to the blog page handler, to takeover some pages
  12. *
  13. * @param string $hook "route"
  14. * @param string $type "blog"
  15. * @param array $return_value the current page_handler params
  16. * @param null $params null
  17. *
  18. * @return array|bool
  19. */
  20. public static function blog($hook, $type, $return_value, $params) {
  21. if (empty($return_value) || !is_array($return_value)) {
  22. // someone else had a route hook
  23. return $return_value;
  24. }
  25. $page = elgg_extract("segments", $return_value);
  26. if (empty($page)) {
  27. return $return_value;
  28. }
  29. $pages_path = elgg_get_plugins_path() . "blog_tools/pages/";
  30. switch ($page[0]) {
  31. case "owner":
  32. $user = get_user_by_username($page[1]);
  33. if (!empty($user)) {
  34. $return_value = false;
  35. // push all blogs breadcrumb
  36. elgg_push_breadcrumb(elgg_echo("blog:blogs"), "blog/all");
  37. set_input("owner_guid", $user->guid);
  38. include($pages_path . "owner.php");
  39. }
  40. break;
  41. case "read": // Elgg 1.7 compatibility
  42. case "view":
  43. if (!elgg_is_logged_in()) {
  44. $setting = elgg_get_plugin_setting("advanced_gatekeeper", "blog_tools");
  45. if ($setting != "no") {
  46. if (isset($page[1]) && !get_entity($page[1])) {
  47. elgg_gatekeeper();
  48. }
  49. }
  50. }
  51. set_input("guid", $page[1]); // to be used in the blog_tools/full/related view
  52. break;
  53. case "add":
  54. case "edit":
  55. $return_value = false;
  56. // push all blogs breadcrumb
  57. elgg_push_breadcrumb(elgg_echo("blog:blogs"), "blog/all");
  58. set_input("page_type", $page[0]);
  59. if (isset($page[1])) {
  60. set_input("guid", $page[1]);
  61. }
  62. if (isset($page[2])) {
  63. set_input("revision", $page[2]);
  64. }
  65. include($pages_path . "edit.php");
  66. break;
  67. case "featured":
  68. $return_value = false;
  69. include($pages_path . "featured.php");
  70. break;
  71. }
  72. return $return_value;
  73. }
  74. }