Widgets.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace ColdTrick\BlogTools;
  3. /**
  4. * Widget releated functions
  5. *
  6. * @package ColdTrick
  7. * @subpackage BlogTools
  8. */
  9. class Widgets {
  10. /**
  11. * Support widget urls for Widget Manager
  12. *
  13. * @param string $hook 'widget_url'
  14. * @param string $type 'widget_manager'
  15. * @param string $return_value the current widget url
  16. * @param array $params supplied params
  17. *
  18. * @return string
  19. */
  20. public static function widgetUrl($hook, $type, $return_value, $params) {
  21. if (!empty($return_value)) {
  22. return $return_value;
  23. }
  24. if (empty($params) || !is_array($params)) {
  25. return $return_value;
  26. }
  27. $widget = elgg_extract("entity", $params);
  28. if (empty($widget) || !elgg_instanceof($widget, "object", "widget")) {
  29. return $return_value;
  30. }
  31. switch ($widget->handler) {
  32. case "index_blog":
  33. $return_value = "blog/all";
  34. break;
  35. case "blog":
  36. $owner = $widget->getOwnerEntity();
  37. if (elgg_instanceof($owner, "user")) {
  38. $return_value = "blog/owner/" . $owner->username;
  39. } elseif (elgg_instanceof($owner, "group")) {
  40. $return_value = "blog/group/" . $owner->getGUID() . "/all";
  41. }
  42. break;
  43. }
  44. return $return_value;
  45. }
  46. /**
  47. * Add or remove widgets based on the group tool option
  48. *
  49. * @param string $hook 'group_tool_widgets'
  50. * @param string $type 'widget_manager'
  51. * @param array $return_value current enable/disable widget handlers
  52. * @param array $params supplied params
  53. *
  54. * @return array
  55. */
  56. public static function groupTools($hook, $type, $return_value, $params) {
  57. if (empty($params) || is_array($params)) {
  58. return $return_value;
  59. }
  60. $entity = elgg_extract("entity", $params);
  61. if (empty($entity) || !elgg_instanceof($entity, "group")) {
  62. return $return_value;
  63. }
  64. if (!is_array($return_value)) {
  65. $return_value = array();
  66. }
  67. if (!isset($return_value["enable"])) {
  68. $return_value["enable"] = array();
  69. }
  70. if (!isset($return_value["disable"])) {
  71. $return_value["disable"] = array();
  72. }
  73. // check different group tools for which we supply widgets
  74. if ($entity->blog_enable == "yes") {
  75. $return_value["enable"][] = "blog";
  76. } else {
  77. $return_value["disable"][] = "blog";
  78. }
  79. return $return_value;
  80. }
  81. }