Browse files

moved the default widgets titles to a fallback hook

  • Loading branch information...
1 parent 20df439 commit 51595facee91546b3f26cf974f75271ba1356288 @jdalsem jdalsem committed May 1, 2012
Showing with 62 additions and 25 deletions.
  1. +3 −24 lib/functions.php
  2. +56 −0 lib/hooks.php
  3. +3 −1 start.php
View
27 lib/functions.php
@@ -98,30 +98,9 @@ function widget_manager_widget_url_handler($widget){
if(empty($result)){
$handler = $widget->handler;
- // configures some widget titles for non widgetmanager widgets
- $widget_titles = array(
- "thewire" => "[BASEURL]thewire/owner/[USERNAME]",
- "friends" => "[BASEURL]friends/[USERNAME]",
- "album_view" => "[BASEURL]photos/owner/[USERNAME]",
- "latest" => "[BASEURL]photos/owner/[USERNAME]",
- "latest_photos" => "[BASEURL]photos/owner/[USERNAME]",
- "messageboard" => "[BASEURL]messageboard/[USERNAME]",
- "a_users_groups" => "[BASEURL]groups/member/[USERNAME]",
- "event_calendar" => "[BASEURL]event_calendar/",
- "filerepo" => "[BASEURL]file/owner/[USERNAME]",
- "pages" => "[BASEURL]pages/owner/[USERNAME]",
- "bookmarks" => "[BASEURL]bookmarks/owner/[USERNAME]",
- "izap_videos" => "[BASEURL]izap_videos/[USERNAME]",
- "river_widget" => "[BASEURL]activity/",
- "blog" => "[BASEURL]blog/owner/[USERNAME]");
-
- if(array_key_exists($handler, $widget_titles)){
- $link = $widget_titles[$handler];
- } else {
- $widgettypes = elgg_get_config("widgets");
- if(isset($widgettypes->handlers[$handler]->link)) {
- $link = $widgettypes->handlers[$handler]->link;
- }
+ $widgettypes = elgg_get_config("widgets");
+ if(isset($widgettypes->handlers[$handler]->link)) {
+ $link = $widgettypes->handlers[$handler]->link;
}
if (!empty($link)) {
View
56 lib/hooks.php
@@ -194,4 +194,60 @@ function widget_manager_widget_layout_permissions_check($hook_name, $entity_type
}
return $return;
+ }
+
+ /**
+ * Fallback widget title urls for non widget manager widgets
+ *
+ * @param unknown_type $hook_name
+ * @param unknown_type $entity_type
+ * @param unknown_type $return_value
+ * @param unknown_type $params
+ * @return Ambigous <string, unknown>
+ */
+ function widget_manager_widgets_url($hook_name, $entity_type, $return_value, $params){
+ $result = $return_value;
+ $widget = $params["entity"];
+
+ if(empty($result) && ($widget instanceof ElggWidget)){
+ $owner = $widget->getOwnerEntity();
+ switch($widget->handler){
+ case "friends":
+ $result = "/friends/" . $owner->username;
+ break;
+ case "album_view":
+ if($owner instanceof ElggGroup){
+ $result = "/photos/group/" . $owner->getGUID() . "/all";
+ } else {
+ $result = "/photos/owner/" . $owner->username;
+ }
+ break;
+ case "latest":
+ $result = "/photos/owner/" . $owner->username;
+ break;
+ case "latest_photos":
+ $result = "/photos/owner/" . $owner->username;
+ break;
+ case "messageboard":
+ $result = "/messageboard/" . $owner->username;
+ break;
+ case "event_calendar":
+ $result = "/event_calendar";
+ break;
+ case "izap_videos":
+ $result = "/izap_videos/" . $owner->username;
+ break;
+ case "river_widget":
+ $result = "/activity";
+ break;
+ case "bookmarks":
+ if($owner instanceof ElggGroup){
+ $result = "/bookmarks/group/" . $owner->getGUID() . "/all";
+ } else {
+ $result = "/bookmarks/owner/" . $owner->username;
+ }
+ break;
+ }
+ }
+ return $result;
}
View
4 start.php
@@ -168,14 +168,16 @@ function widget_manager_reset_widget_context(){
elgg_register_event_handler("init", "system", "widget_manager_init");
elgg_register_event_handler("init", "system", "widget_manager_reset_widget_context",9999); // needs to be last
elgg_register_event_handler("pagesetup", "system", "widget_manager_pagesetup");
- elgg_register_event_handler("all", "object", "widget_manager_update_widget");
+ elgg_register_event_handler("all", "object", "widget_manager_update_widget", 1000); // is only a fallback
// register plugin hooks
elgg_register_plugin_hook_handler("access:collections:write", "user", "widget_manager_write_access_hook");
elgg_register_plugin_hook_handler("access:collections:read", "user", "widget_manager_read_access_hook");
elgg_register_plugin_hook_handler("action", "widgets/save", "widget_manager_widgets_save_hook");
elgg_register_plugin_hook_handler('index', 'system', 'widget_manager_custom_index', 50); // must be very early
+ elgg_register_plugin_hook_handler('widget_url', 'widget_manager', "widget_manager_widgets_url");
+
elgg_register_plugin_hook_handler('register', 'menu:widget', 'widget_manager_register_widget_menu');
elgg_register_plugin_hook_handler('prepare', 'menu:widget', 'widget_manager_prepare_widget_menu');

0 comments on commit 51595fa

Please sign in to comment.